diff --git a/CHANGES.md b/CHANGES.md index 15e4ec474a..5f63ba3c3c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,62 @@ twilio-java changelog ===================== +[2023-08-10] Version 9.10.0 +--------------------------- +**Insights** +- Normalize annotations parameters in list summary api to be prefixed + +**Numbers** +- Change Bulk_hosted_sid from BHR to BH prefix in HNO and dependent under version `/v2` API's. **(breaking change)** +- Added parameter target_account_sid to portability and account_sid to response body + +**Verify** +- Remove beta feature flag to list attempts API. +- Remove beta feature flag to verifications summary attempts API. + + +[2023-07-27] Version 9.9.1 +-------------------------- +**Api** +- Added `voice-intelligence`, `voice-intelligence-transcription` and `voice-intelligence-operators` to `usage_record` API. +- Added `tts-google` to `usage_record` API. + +**Lookups** +- Add new `disposable_phone_number_risk` package to the lookup response + +**Verify** +- Documentation of list attempts API was improved by correcting `date_created_after` and `date_created_before` expected date format. +- Documentation was improved by correcting `date_created_after` and `date_created_before` expected date format parameter on attempts summary API. +- Documentation was improved by adding `WHATSAPP` as optional valid parameter on attempts summary API. + +**Twiml** +- Added support for he-il inside of ssm_lang.json that was missing +- Added support for he-il language in say.json that was missing +- Add `statusCallback` and `statusCallbackMethod` attributes to ``. + + +[2023-07-14] Version 9.9.0 +-------------------------- +**Flex** +- Adding `interaction_context_sid` as optional parameter in Interactions API + +**Messaging** +- Making visiblity public for tollfree_verification API + +**Numbers** +- Remove Sms capability property from HNO creation under version `/v2` of HNO API. **(breaking change)** +- Update required properties in LOA creation under version `/v2` of Authorization document API. **(breaking change)** + +**Taskrouter** +- Add api to fetch task queue statistics for multiple TaskQueues + +**Verify** +- Add `RiskCheck` optional parameter on Verification creation. + +**Twiml** +- Add Google Voices and languages + + [2023-06-28] Version 9.8.0 -------------------------- **Library - Chore** diff --git a/pom.xml b/pom.xml index ec703d0ff5..c51f11712c 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ twilio jar twilio - 9.8.0 + 9.10.0 Twilio Java Helper Library https://www.twilio.com @@ -19,7 +19,7 @@ git@github.com:twilio/twilio-java.git scm:git:git@github.com:twilio/twilio-java.git scm:git:git@github.com:twilio/twilio-java.git - 9.8.0 + 9.10.0 diff --git a/src/main/java/com/twilio/Twilio.java b/src/main/java/com/twilio/Twilio.java index 643128cefc..0b3aeb1e9e 100644 --- a/src/main/java/com/twilio/Twilio.java +++ b/src/main/java/com/twilio/Twilio.java @@ -21,7 +21,7 @@ */ public class Twilio { - public static final String VERSION = "9.8.0"; + public static final String VERSION = "9.10.0"; 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"); diff --git a/src/main/java/com/twilio/rest/accounts/v1/AuthTokenPromotion.java b/src/main/java/com/twilio/rest/accounts/v1/AuthTokenPromotion.java index a9af0bb82d..b351cf2f6c 100644 --- a/src/main/java/com/twilio/rest/accounts/v1/AuthTokenPromotion.java +++ b/src/main/java/com/twilio/rest/accounts/v1/AuthTokenPromotion.java @@ -23,37 +23,36 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class AuthTokenPromotion extends Resource { + private static final long serialVersionUID = 77507843877589L; - public static AuthTokenPromotionUpdater updater(){ + public static AuthTokenPromotionUpdater updater() { return new AuthTokenPromotionUpdater(); } /** - * Converts a JSON String into a AuthTokenPromotion object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return AuthTokenPromotion object represented by the provided JSON - */ - public static AuthTokenPromotion fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a AuthTokenPromotion object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return AuthTokenPromotion object represented by the provided JSON + */ + public static AuthTokenPromotion fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, AuthTokenPromotion.class); @@ -65,14 +64,17 @@ public static AuthTokenPromotion fromJson(final String json, final ObjectMapper } /** - * Converts a JSON InputStream into a AuthTokenPromotion object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return AuthTokenPromotion object represented by the provided JSON - */ - public static AuthTokenPromotion fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a AuthTokenPromotion object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return AuthTokenPromotion object represented by the provided JSON + */ + public static AuthTokenPromotion fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, AuthTokenPromotion.class); @@ -91,20 +93,11 @@ public static AuthTokenPromotion fromJson(final InputStream json, final ObjectMa @JsonCreator private AuthTokenPromotion( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("auth_token") - final String authToken, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("auth_token") final String authToken, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url ) { this.accountSid = accountSid; this.authToken = authToken; @@ -113,25 +106,29 @@ private AuthTokenPromotion( this.url = url; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getAuthToken() { - return this.authToken; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getAuthToken() { + return this.authToken; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -141,13 +138,23 @@ public boolean equals(final Object o) { AuthTokenPromotion other = (AuthTokenPromotion) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(authToken, other.authToken) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(authToken, other.authToken) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, authToken, dateCreated, dateUpdated, url); + return Objects.hash( + accountSid, + authToken, + dateCreated, + dateUpdated, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/accounts/v1/AuthTokenPromotionUpdater.java b/src/main/java/com/twilio/rest/accounts/v1/AuthTokenPromotionUpdater.java index ae06380f76..862d324f31 100644 --- a/src/main/java/com/twilio/rest/accounts/v1/AuthTokenPromotionUpdater.java +++ b/src/main/java/com/twilio/rest/accounts/v1/AuthTokenPromotionUpdater.java @@ -24,20 +24,14 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class AuthTokenPromotionUpdater extends Updater { - - -public class AuthTokenPromotionUpdater extends Updater{ - - public AuthTokenPromotionUpdater(){ - } - + public AuthTokenPromotionUpdater() {} @Override - public AuthTokenPromotion update(final TwilioRestClient client){ + public AuthTokenPromotion update(final TwilioRestClient client) { String path = "/v1/AuthTokens/Promote"; - Request request = new Request( HttpMethod.POST, Domains.ACCOUNTS.toString(), @@ -45,15 +39,23 @@ public AuthTokenPromotion update(final TwilioRestClient client){ ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AuthTokenPromotion update failed: Unable to connect to server"); + throw new ApiConnectionException( + "AuthTokenPromotion update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return AuthTokenPromotion.fromJson(response.getStream(), client.getObjectMapper()); + return AuthTokenPromotion.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/accounts/v1/SecondaryAuthToken.java b/src/main/java/com/twilio/rest/accounts/v1/SecondaryAuthToken.java index b8df84c8db..0d6a66035f 100644 --- a/src/main/java/com/twilio/rest/accounts/v1/SecondaryAuthToken.java +++ b/src/main/java/com/twilio/rest/accounts/v1/SecondaryAuthToken.java @@ -23,41 +23,40 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class SecondaryAuthToken extends Resource { + private static final long serialVersionUID = 191219471550314L; - public static SecondaryAuthTokenCreator creator(){ + public static SecondaryAuthTokenCreator creator() { return new SecondaryAuthTokenCreator(); } - public static SecondaryAuthTokenDeleter deleter(){ + public static SecondaryAuthTokenDeleter deleter() { return new SecondaryAuthTokenDeleter(); } /** - * Converts a JSON String into a SecondaryAuthToken object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return SecondaryAuthToken object represented by the provided JSON - */ - public static SecondaryAuthToken fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a SecondaryAuthToken object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return SecondaryAuthToken object represented by the provided JSON + */ + public static SecondaryAuthToken fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SecondaryAuthToken.class); @@ -69,14 +68,17 @@ public static SecondaryAuthToken fromJson(final String json, final ObjectMapper } /** - * Converts a JSON InputStream into a SecondaryAuthToken object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return SecondaryAuthToken object represented by the provided JSON - */ - public static SecondaryAuthToken fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a SecondaryAuthToken object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return SecondaryAuthToken object represented by the provided JSON + */ + public static SecondaryAuthToken fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SecondaryAuthToken.class); @@ -95,20 +97,11 @@ public static SecondaryAuthToken fromJson(final InputStream json, final ObjectMa @JsonCreator private SecondaryAuthToken( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("secondary_auth_token") - final String secondaryAuthToken, - - @JsonProperty("url") - final URI url + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("secondary_auth_token") final String secondaryAuthToken, + @JsonProperty("url") final URI url ) { this.accountSid = accountSid; this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); @@ -117,25 +110,29 @@ private SecondaryAuthToken( this.url = url; } - public final String getAccountSid() { - return this.accountSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getSecondaryAuthToken() { - return this.secondaryAuthToken; - } - public final URI getUrl() { - return this.url; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getSecondaryAuthToken() { + return this.secondaryAuthToken; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -145,13 +142,23 @@ public boolean equals(final Object o) { SecondaryAuthToken other = (SecondaryAuthToken) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(secondaryAuthToken, other.secondaryAuthToken) && Objects.equals(url, other.url) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(secondaryAuthToken, other.secondaryAuthToken) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, dateCreated, dateUpdated, secondaryAuthToken, url); + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + secondaryAuthToken, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/accounts/v1/SecondaryAuthTokenCreator.java b/src/main/java/com/twilio/rest/accounts/v1/SecondaryAuthTokenCreator.java index aff21d5f0c..ecfcc6d282 100644 --- a/src/main/java/com/twilio/rest/accounts/v1/SecondaryAuthTokenCreator.java +++ b/src/main/java/com/twilio/rest/accounts/v1/SecondaryAuthTokenCreator.java @@ -24,20 +24,14 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class SecondaryAuthTokenCreator extends Creator { - - -public class SecondaryAuthTokenCreator extends Creator{ - - public SecondaryAuthTokenCreator() { - } - + public SecondaryAuthTokenCreator() {} @Override - public SecondaryAuthToken create(final TwilioRestClient client){ + public SecondaryAuthToken create(final TwilioRestClient client) { String path = "/v1/AuthTokens/Secondary"; - Request request = new Request( HttpMethod.POST, Domains.ACCOUNTS.toString(), @@ -45,15 +39,23 @@ public SecondaryAuthToken create(final TwilioRestClient client){ ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SecondaryAuthToken creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "SecondaryAuthToken creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return SecondaryAuthToken.fromJson(response.getStream(), client.getObjectMapper()); + return SecondaryAuthToken.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/accounts/v1/SecondaryAuthTokenDeleter.java b/src/main/java/com/twilio/rest/accounts/v1/SecondaryAuthTokenDeleter.java index d32ab49b3a..26b6b44f46 100644 --- a/src/main/java/com/twilio/rest/accounts/v1/SecondaryAuthTokenDeleter.java +++ b/src/main/java/com/twilio/rest/accounts/v1/SecondaryAuthTokenDeleter.java @@ -24,19 +24,14 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class SecondaryAuthTokenDeleter extends Deleter { - public SecondaryAuthTokenDeleter(){ - } - + public SecondaryAuthTokenDeleter() {} @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/AuthTokens/Secondary"; - Request request = new Request( HttpMethod.DELETE, Domains.ACCOUNTS.toString(), @@ -45,9 +40,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SecondaryAuthToken delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "SecondaryAuthToken delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/accounts/v1/credential/Aws.java b/src/main/java/com/twilio/rest/accounts/v1/credential/Aws.java index 726ede3466..7f6af0e434 100644 --- a/src/main/java/com/twilio/rest/accounts/v1/credential/Aws.java +++ b/src/main/java/com/twilio/rest/accounts/v1/credential/Aws.java @@ -23,53 +23,52 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Aws extends Resource { + private static final long serialVersionUID = 255841368009036L; - public static AwsCreator creator(final String credentials){ + public static AwsCreator creator(final String credentials) { return new AwsCreator(credentials); } - public static AwsDeleter deleter(final String pathSid){ + public static AwsDeleter deleter(final String pathSid) { return new AwsDeleter(pathSid); } - public static AwsFetcher fetcher(final String pathSid){ + public static AwsFetcher fetcher(final String pathSid) { return new AwsFetcher(pathSid); } - public static AwsReader reader(){ + public static AwsReader reader() { return new AwsReader(); } - public static AwsUpdater updater(final String pathSid){ + public static AwsUpdater updater(final String pathSid) { return new AwsUpdater(pathSid); } /** - * Converts a JSON String into a Aws object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Aws object represented by the provided JSON - */ - public static Aws fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Aws object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Aws object represented by the provided JSON + */ + public static Aws fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Aws.class); @@ -81,14 +80,17 @@ public static Aws fromJson(final String json, final ObjectMapper objectMapper) { } /** - * Converts a JSON InputStream into a Aws object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Aws object represented by the provided JSON - */ - public static Aws fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Aws object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Aws object represented by the provided JSON + */ + public static Aws fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Aws.class); @@ -108,23 +110,12 @@ public static Aws fromJson(final InputStream json, final ObjectMapper objectMapp @JsonCreator private Aws( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url ) { this.sid = sid; this.accountSid = accountSid; @@ -134,28 +125,33 @@ private Aws( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -165,13 +161,25 @@ public boolean equals(final Object o) { Aws other = (Aws) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, friendlyName, dateCreated, dateUpdated, url); + return Objects.hash( + sid, + accountSid, + friendlyName, + dateCreated, + dateUpdated, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/accounts/v1/credential/AwsCreator.java b/src/main/java/com/twilio/rest/accounts/v1/credential/AwsCreator.java index 8a8c4ddcff..f335d6bfd6 100644 --- a/src/main/java/com/twilio/rest/accounts/v1/credential/AwsCreator.java +++ b/src/main/java/com/twilio/rest/accounts/v1/credential/AwsCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.accounts.v1.credential; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class AwsCreator extends Creator { - - -public class AwsCreator extends Creator{ private String credentials; private String friendlyName; private String accountSid; @@ -36,36 +35,48 @@ public AwsCreator(final String credentials) { this.credentials = credentials; } - public AwsCreator setCredentials(final String credentials){ + public AwsCreator setCredentials(final String credentials) { this.credentials = credentials; return this; } - public AwsCreator setFriendlyName(final String friendlyName){ + + public AwsCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public AwsCreator setAccountSid(final String accountSid){ + + public AwsCreator setAccountSid(final String accountSid) { this.accountSid = accountSid; return this; } @Override - public Aws create(final TwilioRestClient client){ + public Aws create(final TwilioRestClient client) { String path = "/v1/Credentials/AWS"; - path = path.replace("{"+"Credentials"+"}", this.credentials.toString()); + path = + path.replace( + "{" + "Credentials" + "}", + this.credentials.toString() + ); Request request = new Request( HttpMethod.POST, Domains.ACCOUNTS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Aws creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Aws creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -74,18 +85,16 @@ public Aws create(final TwilioRestClient client){ return Aws.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (credentials != null) { request.addPostParam("Credentials", credentials); - } if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (accountSid != null) { request.addPostParam("AccountSid", accountSid); - } } } diff --git a/src/main/java/com/twilio/rest/accounts/v1/credential/AwsDeleter.java b/src/main/java/com/twilio/rest/accounts/v1/credential/AwsDeleter.java index a60ea69a34..6ce7ce88f2 100644 --- a/src/main/java/com/twilio/rest/accounts/v1/credential/AwsDeleter.java +++ b/src/main/java/com/twilio/rest/accounts/v1/credential/AwsDeleter.java @@ -24,21 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class AwsDeleter extends Deleter { + private String pathSid; - public AwsDeleter(final String pathSid){ + public AwsDeleter(final String pathSid) { this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Credentials/AWS/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -48,9 +46,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Aws delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Aws delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/accounts/v1/credential/AwsFetcher.java b/src/main/java/com/twilio/rest/accounts/v1/credential/AwsFetcher.java index ffbf475303..8b9979841b 100644 --- a/src/main/java/com/twilio/rest/accounts/v1/credential/AwsFetcher.java +++ b/src/main/java/com/twilio/rest/accounts/v1/credential/AwsFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class AwsFetcher extends Fetcher { + private String pathSid; - public AwsFetcher(final String pathSid){ + public AwsFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public Aws fetch(final TwilioRestClient client) { String path = "/v1/Credentials/AWS/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,9 +46,14 @@ public Aws fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Aws fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Aws fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/accounts/v1/credential/AwsReader.java b/src/main/java/com/twilio/rest/accounts/v1/credential/AwsReader.java index 668713da21..cd0a86b929 100644 --- a/src/main/java/com/twilio/rest/accounts/v1/credential/AwsReader.java +++ b/src/main/java/com/twilio/rest/accounts/v1/credential/AwsReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.accounts.v1.credential; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,17 +25,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class AwsReader extends Reader { + private Integer pageSize; - public AwsReader(){ - } + public AwsReader() {} - public AwsReader setPageSize(final Integer pageSize){ + public AwsReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -57,13 +55,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Aws read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Aws read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -79,7 +85,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request re } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.ACCOUNTS.toString()) @@ -87,9 +96,11 @@ public Page previousPage(final Page page, final TwilioRestClient clien return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.ACCOUNTS.toString()) @@ -98,21 +109,21 @@ public Page nextPage(final Page page, final TwilioRestClient client) { } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/accounts/v1/credential/AwsUpdater.java b/src/main/java/com/twilio/rest/accounts/v1/credential/AwsUpdater.java index 24bd7d340f..9473c3645d 100644 --- a/src/main/java/com/twilio/rest/accounts/v1/credential/AwsUpdater.java +++ b/src/main/java/com/twilio/rest/accounts/v1/credential/AwsUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.accounts.v1.credential; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,39 +25,43 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class AwsUpdater extends Updater { - - -public class AwsUpdater extends Updater{ private String pathSid; private String friendlyName; - public AwsUpdater(final String pathSid){ + public AwsUpdater(final String pathSid) { this.pathSid = pathSid; } - public AwsUpdater setFriendlyName(final String friendlyName){ + public AwsUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } @Override - public Aws update(final TwilioRestClient client){ + public Aws update(final TwilioRestClient client) { String path = "/v1/Credentials/AWS/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.ACCOUNTS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Aws update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Aws update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -65,10 +70,10 @@ public Aws update(final TwilioRestClient client){ return Aws.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } } } diff --git a/src/main/java/com/twilio/rest/accounts/v1/credential/PublicKey.java b/src/main/java/com/twilio/rest/accounts/v1/credential/PublicKey.java index 906893efa5..f77b6851d1 100644 --- a/src/main/java/com/twilio/rest/accounts/v1/credential/PublicKey.java +++ b/src/main/java/com/twilio/rest/accounts/v1/credential/PublicKey.java @@ -23,53 +23,52 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class PublicKey extends Resource { + private static final long serialVersionUID = 255841368009036L; - public static PublicKeyCreator creator(final String publicKey){ + public static PublicKeyCreator creator(final String publicKey) { return new PublicKeyCreator(publicKey); } - public static PublicKeyDeleter deleter(final String pathSid){ + public static PublicKeyDeleter deleter(final String pathSid) { return new PublicKeyDeleter(pathSid); } - public static PublicKeyFetcher fetcher(final String pathSid){ + public static PublicKeyFetcher fetcher(final String pathSid) { return new PublicKeyFetcher(pathSid); } - public static PublicKeyReader reader(){ + public static PublicKeyReader reader() { return new PublicKeyReader(); } - public static PublicKeyUpdater updater(final String pathSid){ + public static PublicKeyUpdater updater(final String pathSid) { return new PublicKeyUpdater(pathSid); } /** - * Converts a JSON String into a PublicKey object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return PublicKey object represented by the provided JSON - */ - public static PublicKey fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a PublicKey object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return PublicKey object represented by the provided JSON + */ + public static PublicKey fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, PublicKey.class); @@ -81,14 +80,17 @@ public static PublicKey fromJson(final String json, final ObjectMapper objectMap } /** - * Converts a JSON InputStream into a PublicKey object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return PublicKey object represented by the provided JSON - */ - public static PublicKey fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a PublicKey object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return PublicKey object represented by the provided JSON + */ + public static PublicKey fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, PublicKey.class); @@ -108,23 +110,12 @@ public static PublicKey fromJson(final InputStream json, final ObjectMapper obje @JsonCreator private PublicKey( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url ) { this.sid = sid; this.accountSid = accountSid; @@ -134,28 +125,33 @@ private PublicKey( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -165,13 +161,25 @@ public boolean equals(final Object o) { PublicKey other = (PublicKey) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, friendlyName, dateCreated, dateUpdated, url); + return Objects.hash( + sid, + accountSid, + friendlyName, + dateCreated, + dateUpdated, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/accounts/v1/credential/PublicKeyCreator.java b/src/main/java/com/twilio/rest/accounts/v1/credential/PublicKeyCreator.java index 0797698fcd..2214b4c08e 100644 --- a/src/main/java/com/twilio/rest/accounts/v1/credential/PublicKeyCreator.java +++ b/src/main/java/com/twilio/rest/accounts/v1/credential/PublicKeyCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.accounts.v1.credential; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class PublicKeyCreator extends Creator { - - -public class PublicKeyCreator extends Creator{ private String publicKey; private String friendlyName; private String accountSid; @@ -36,56 +35,65 @@ public PublicKeyCreator(final String publicKey) { this.publicKey = publicKey; } - public PublicKeyCreator setPublicKey(final String publicKey){ + public PublicKeyCreator setPublicKey(final String publicKey) { this.publicKey = publicKey; return this; } - public PublicKeyCreator setFriendlyName(final String friendlyName){ + + public PublicKeyCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public PublicKeyCreator setAccountSid(final String accountSid){ + + public PublicKeyCreator setAccountSid(final String accountSid) { this.accountSid = accountSid; return this; } @Override - public PublicKey create(final TwilioRestClient client){ + public PublicKey create(final TwilioRestClient client) { String path = "/v1/Credentials/PublicKeys"; - path = path.replace("{"+"PublicKey"+"}", this.publicKey.toString()); + path = path.replace("{" + "PublicKey" + "}", this.publicKey.toString()); Request request = new Request( HttpMethod.POST, Domains.ACCOUNTS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("PublicKey creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "PublicKey creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return PublicKey.fromJson(response.getStream(), client.getObjectMapper()); + return PublicKey.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (publicKey != null) { request.addPostParam("PublicKey", publicKey); - } if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (accountSid != null) { request.addPostParam("AccountSid", accountSid); - } } } diff --git a/src/main/java/com/twilio/rest/accounts/v1/credential/PublicKeyDeleter.java b/src/main/java/com/twilio/rest/accounts/v1/credential/PublicKeyDeleter.java index c09237ae3e..92a87569fb 100644 --- a/src/main/java/com/twilio/rest/accounts/v1/credential/PublicKeyDeleter.java +++ b/src/main/java/com/twilio/rest/accounts/v1/credential/PublicKeyDeleter.java @@ -24,21 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class PublicKeyDeleter extends Deleter { + private String pathSid; - public PublicKeyDeleter(final String pathSid){ + public PublicKeyDeleter(final String pathSid) { this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Credentials/PublicKeys/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -48,9 +46,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("PublicKey delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "PublicKey delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/accounts/v1/credential/PublicKeyFetcher.java b/src/main/java/com/twilio/rest/accounts/v1/credential/PublicKeyFetcher.java index 0e0e05526f..d8e5bafb06 100644 --- a/src/main/java/com/twilio/rest/accounts/v1/credential/PublicKeyFetcher.java +++ b/src/main/java/com/twilio/rest/accounts/v1/credential/PublicKeyFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class PublicKeyFetcher extends Fetcher { + private String pathSid; - public PublicKeyFetcher(final String pathSid){ + public PublicKeyFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public PublicKey fetch(final TwilioRestClient client) { String path = "/v1/Credentials/PublicKeys/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,15 +46,23 @@ public PublicKey fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("PublicKey fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "PublicKey fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return PublicKey.fromJson(response.getStream(), client.getObjectMapper()); + return PublicKey.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/accounts/v1/credential/PublicKeyReader.java b/src/main/java/com/twilio/rest/accounts/v1/credential/PublicKeyReader.java index 9f0da2bc2d..c0ec663864 100644 --- a/src/main/java/com/twilio/rest/accounts/v1/credential/PublicKeyReader.java +++ b/src/main/java/com/twilio/rest/accounts/v1/credential/PublicKeyReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.accounts.v1.credential; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,17 +25,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class PublicKeyReader extends Reader { + private Integer pageSize; - public PublicKeyReader(){ - } + public PublicKeyReader() {} - public PublicKeyReader setPageSize(final Integer pageSize){ + public PublicKeyReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -57,13 +55,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("PublicKey read failed: Unable to connect to server"); + throw new ApiConnectionException( + "PublicKey read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -79,7 +85,10 @@ private Page pageForRequest(final TwilioRestClient client, final Requ } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.ACCOUNTS.toString()) @@ -87,9 +96,11 @@ public Page previousPage(final Page page, final TwilioRest return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.ACCOUNTS.toString()) @@ -98,21 +109,21 @@ public Page nextPage(final Page page, final TwilioRestClie } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/accounts/v1/credential/PublicKeyUpdater.java b/src/main/java/com/twilio/rest/accounts/v1/credential/PublicKeyUpdater.java index 14488f8bcf..42e38f03a8 100644 --- a/src/main/java/com/twilio/rest/accounts/v1/credential/PublicKeyUpdater.java +++ b/src/main/java/com/twilio/rest/accounts/v1/credential/PublicKeyUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.accounts.v1.credential; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,51 +25,58 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class PublicKeyUpdater extends Updater { - - -public class PublicKeyUpdater extends Updater{ private String pathSid; private String friendlyName; - public PublicKeyUpdater(final String pathSid){ + public PublicKeyUpdater(final String pathSid) { this.pathSid = pathSid; } - public PublicKeyUpdater setFriendlyName(final String friendlyName){ + public PublicKeyUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } @Override - public PublicKey update(final TwilioRestClient client){ + public PublicKey update(final TwilioRestClient client) { String path = "/v1/Credentials/PublicKeys/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.ACCOUNTS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("PublicKey update failed: Unable to connect to server"); + throw new ApiConnectionException( + "PublicKey update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return PublicKey.fromJson(response.getStream(), client.getObjectMapper()); + return PublicKey.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/Account.java b/src/main/java/com/twilio/rest/api/v2010/Account.java index 0a09d41889..4d7d1ae79a 100644 --- a/src/main/java/com/twilio/rest/api/v2010/Account.java +++ b/src/main/java/com/twilio/rest/api/v2010/Account.java @@ -24,56 +24,57 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Account extends Resource { + private static final long serialVersionUID = 224328589339754L; - public static AccountCreator creator(){ + public static AccountCreator creator() { return new AccountCreator(); } - public static AccountFetcher fetcher(){ + public static AccountFetcher fetcher() { return new AccountFetcher(); } - public static AccountFetcher fetcher(final String pathSid){ + + public static AccountFetcher fetcher(final String pathSid) { return new AccountFetcher(pathSid); } - public static AccountReader reader(){ + public static AccountReader reader() { return new AccountReader(); } - public static AccountUpdater updater(){ + public static AccountUpdater updater() { return new AccountUpdater(); } - public static AccountUpdater updater(final String pathSid){ + + public static AccountUpdater updater(final String pathSid) { return new AccountUpdater(pathSid); } /** - * Converts a JSON String into a Account object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Account object represented by the provided JSON - */ - public static Account fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Account object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Account object represented by the provided JSON + */ + public static Account fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Account.class); @@ -85,14 +86,17 @@ public static Account fromJson(final String json, final ObjectMapper objectMappe } /** - * Converts a JSON InputStream into a Account object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Account object represented by the provided JSON - */ - public static Account fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Account object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Account object represented by the provided JSON + */ + public static Account fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Account.class); @@ -102,6 +106,7 @@ public static Account fromJson(final InputStream json, final ObjectMapper object throw new ApiConnectionException(e.getMessage(), e); } } + public enum Status { ACTIVE("active"), SUSPENDED("suspended"), @@ -122,6 +127,7 @@ public static Status forValue(final String value) { return Promoter.enumFromString(value, Status.values()); } } + public enum Type { TRIAL("Trial"), FULL("Full"); @@ -155,35 +161,18 @@ public static Type forValue(final String value) { @JsonCreator private Account( - @JsonProperty("auth_token") - final String authToken, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("owner_account_sid") - final String ownerAccountSid, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("status") - final Account.Status status, - - @JsonProperty("subresource_uris") - final Map subresourceUris, - - @JsonProperty("type") - final Account.Type type, - - @JsonProperty("uri") - final String uri + @JsonProperty("auth_token") final String authToken, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("owner_account_sid") final String ownerAccountSid, + @JsonProperty("sid") final String sid, + @JsonProperty("status") final Account.Status status, + @JsonProperty( + "subresource_uris" + ) final Map subresourceUris, + @JsonProperty("type") final Account.Type type, + @JsonProperty("uri") final String uri ) { this.authToken = authToken; this.dateCreated = DateConverter.rfc2822DateTimeFromString(dateCreated); @@ -197,40 +186,49 @@ private Account( this.uri = uri; } - public final String getAuthToken() { - return this.authToken; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getOwnerAccountSid() { - return this.ownerAccountSid; - } - public final String getSid() { - return this.sid; - } - public final Account.Status getStatus() { - return this.status; - } - public final Map getSubresourceUris() { - return this.subresourceUris; - } - public final Account.Type getType() { - return this.type; - } - public final String getUri() { - return this.uri; - } + public final String getAuthToken() { + return this.authToken; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getOwnerAccountSid() { + return this.ownerAccountSid; + } + + public final String getSid() { + return this.sid; + } + + public final Account.Status getStatus() { + return this.status; + } + + public final Map getSubresourceUris() { + return this.subresourceUris; + } + + public final Account.Type getType() { + return this.type; + } + + public final String getUri() { + return this.uri; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -240,13 +238,33 @@ public boolean equals(final Object o) { Account other = (Account) o; - return Objects.equals(authToken, other.authToken) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(ownerAccountSid, other.ownerAccountSid) && Objects.equals(sid, other.sid) && Objects.equals(status, other.status) && Objects.equals(subresourceUris, other.subresourceUris) && Objects.equals(type, other.type) && Objects.equals(uri, other.uri) ; + return ( + Objects.equals(authToken, other.authToken) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(ownerAccountSid, other.ownerAccountSid) && + Objects.equals(sid, other.sid) && + Objects.equals(status, other.status) && + Objects.equals(subresourceUris, other.subresourceUris) && + Objects.equals(type, other.type) && + Objects.equals(uri, other.uri) + ); } @Override public int hashCode() { - return Objects.hash(authToken, dateCreated, dateUpdated, friendlyName, ownerAccountSid, sid, status, subresourceUris, type, uri); + return Objects.hash( + authToken, + dateCreated, + dateUpdated, + friendlyName, + ownerAccountSid, + sid, + status, + subresourceUris, + type, + uri + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/AccountCreator.java b/src/main/java/com/twilio/rest/api/v2010/AccountCreator.java index 9b04a4c318..7d39d9d472 100644 --- a/src/main/java/com/twilio/rest/api/v2010/AccountCreator.java +++ b/src/main/java/com/twilio/rest/api/v2010/AccountCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,36 +25,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class AccountCreator extends Creator { - - -public class AccountCreator extends Creator{ private String friendlyName; - public AccountCreator() { - } + public AccountCreator() {} - public AccountCreator setFriendlyName(final String friendlyName){ + public AccountCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } @Override - public Account create(final TwilioRestClient client){ + public Account create(final TwilioRestClient client) { String path = "/2010-04-01/Accounts.json"; - Request request = new Request( HttpMethod.POST, Domains.API.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Account creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Account creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -62,10 +65,10 @@ public Account create(final TwilioRestClient client){ return Account.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/AccountFetcher.java b/src/main/java/com/twilio/rest/api/v2010/AccountFetcher.java index 87013b2c18..c4c7aad869 100644 --- a/src/main/java/com/twilio/rest/api/v2010/AccountFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/AccountFetcher.java @@ -24,25 +24,23 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class AccountFetcher extends Fetcher { + private String pathSid; - public AccountFetcher(){ - } - public AccountFetcher(final String pathSid){ + public AccountFetcher() {} + + public AccountFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public Account fetch(final TwilioRestClient client) { String path = "/2010-04-01/Accounts/{Sid}.json"; - this.pathSid = this.pathSid == null ? client.getAccountSid() : this.pathSid; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathSid = + this.pathSid == null ? client.getAccountSid() : this.pathSid; + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,9 +50,14 @@ public Account fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Account fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Account fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/api/v2010/AccountReader.java b/src/main/java/com/twilio/rest/api/v2010/AccountReader.java index 4577d0a338..2e391b22c8 100644 --- a/src/main/java/com/twilio/rest/api/v2010/AccountReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/AccountReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.api.v2010; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,27 +25,26 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class AccountReader extends Reader { + private String friendlyName; private Account.Status status; private Integer pageSize; - public AccountReader(){ - } + public AccountReader() {} - public AccountReader setFriendlyName(final String friendlyName){ + public AccountReader setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public AccountReader setStatus(final Account.Status status){ + + public AccountReader setStatus(final Account.Status status) { this.status = status; return this; } - public AccountReader setPageSize(final Integer pageSize){ + + public AccountReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -67,13 +67,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Account read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Account read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -89,7 +97,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reques } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.API.toString()) @@ -97,9 +108,11 @@ public Page previousPage(final Page page, final TwilioRestClie return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.API.toString()) @@ -108,29 +121,27 @@ public Page nextPage(final Page page, final TwilioRestClient c } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (friendlyName != null) { - request.addQueryParam("FriendlyName", friendlyName); } if (status != null) { - request.addQueryParam("Status", status.toString()); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/AccountUpdater.java b/src/main/java/com/twilio/rest/api/v2010/AccountUpdater.java index 339b08b1f0..2bf3c08a32 100644 --- a/src/main/java/com/twilio/rest/api/v2010/AccountUpdater.java +++ b/src/main/java/com/twilio/rest/api/v2010/AccountUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,47 +25,53 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class AccountUpdater extends Updater { - - -public class AccountUpdater extends Updater{ private String pathSid; private String friendlyName; private Account.Status status; - public AccountUpdater(){ - } - public AccountUpdater(final String pathSid){ + public AccountUpdater() {} + + public AccountUpdater(final String pathSid) { this.pathSid = pathSid; } - public AccountUpdater setFriendlyName(final String friendlyName){ + public AccountUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public AccountUpdater setStatus(final Account.Status status){ + + public AccountUpdater setStatus(final Account.Status status) { this.status = status; return this; } @Override - public Account update(final TwilioRestClient client){ + public Account update(final TwilioRestClient client) { String path = "/2010-04-01/Accounts/{Sid}.json"; - this.pathSid = this.pathSid == null ? client.getAccountSid() : this.pathSid; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathSid = + this.pathSid == null ? client.getAccountSid() : this.pathSid; + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.API.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Account update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Account update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -73,14 +80,13 @@ public Account update(final TwilioRestClient client){ return Account.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (status != null) { request.addPostParam("Status", status.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/Address.java b/src/main/java/com/twilio/rest/api/v2010/account/Address.java index b8dc4312c0..8a53321f3c 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/Address.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/Address.java @@ -23,67 +23,110 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Address extends Resource { + private static final long serialVersionUID = 73808189531379L; - public static AddressCreator creator(final String customerName, final String street, final String city, final String region, final String postalCode, final String isoCountry){ - return new AddressCreator(customerName, street, city, region, postalCode, isoCountry); + public static AddressCreator creator( + final String customerName, + final String street, + final String city, + final String region, + final String postalCode, + final String isoCountry + ) { + return new AddressCreator( + customerName, + street, + city, + region, + postalCode, + isoCountry + ); } - public static AddressCreator creator(final String pathAccountSid, final String customerName, final String street, final String city, final String region, final String postalCode, final String isoCountry){ - return new AddressCreator(pathAccountSid, customerName, street, city, region, postalCode, isoCountry); + + public static AddressCreator creator( + final String pathAccountSid, + final String customerName, + final String street, + final String city, + final String region, + final String postalCode, + final String isoCountry + ) { + return new AddressCreator( + pathAccountSid, + customerName, + street, + city, + region, + postalCode, + isoCountry + ); } - public static AddressDeleter deleter(final String pathSid){ + public static AddressDeleter deleter(final String pathSid) { return new AddressDeleter(pathSid); } - public static AddressDeleter deleter(final String pathAccountSid, final String pathSid){ + + public static AddressDeleter deleter( + final String pathAccountSid, + final String pathSid + ) { return new AddressDeleter(pathAccountSid, pathSid); } - public static AddressFetcher fetcher(final String pathSid){ + public static AddressFetcher fetcher(final String pathSid) { return new AddressFetcher(pathSid); } - public static AddressFetcher fetcher(final String pathAccountSid, final String pathSid){ + + public static AddressFetcher fetcher( + final String pathAccountSid, + final String pathSid + ) { return new AddressFetcher(pathAccountSid, pathSid); } - public static AddressReader reader(){ + public static AddressReader reader() { return new AddressReader(); } - public static AddressReader reader(final String pathAccountSid){ + + public static AddressReader reader(final String pathAccountSid) { return new AddressReader(pathAccountSid); } - public static AddressUpdater updater(final String pathSid){ + public static AddressUpdater updater(final String pathSid) { return new AddressUpdater(pathSid); } - public static AddressUpdater updater(final String pathAccountSid, final String pathSid){ + + public static AddressUpdater updater( + final String pathAccountSid, + final String pathSid + ) { return new AddressUpdater(pathAccountSid, pathSid); } /** - * Converts a JSON String into a Address object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Address object represented by the provided JSON - */ - public static Address fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Address object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Address object represented by the provided JSON + */ + public static Address fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Address.class); @@ -95,14 +138,17 @@ public static Address fromJson(final String json, final ObjectMapper objectMappe } /** - * Converts a JSON InputStream into a Address object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Address object represented by the provided JSON - */ - public static Address fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Address object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Address object represented by the provided JSON + */ + public static Address fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Address.class); @@ -132,53 +178,22 @@ public static Address fromJson(final InputStream json, final ObjectMapper object @JsonCreator private Address( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("city") - final String city, - - @JsonProperty("customer_name") - final String customerName, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("iso_country") - final String isoCountry, - - @JsonProperty("postal_code") - final String postalCode, - - @JsonProperty("region") - final String region, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("street") - final String street, - - @JsonProperty("uri") - final String uri, - - @JsonProperty("emergency_enabled") - final Boolean emergencyEnabled, - - @JsonProperty("validated") - final Boolean validated, - - @JsonProperty("verified") - final Boolean verified, - - @JsonProperty("street_secondary") - final String streetSecondary + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("city") final String city, + @JsonProperty("customer_name") final String customerName, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("iso_country") final String isoCountry, + @JsonProperty("postal_code") final String postalCode, + @JsonProperty("region") final String region, + @JsonProperty("sid") final String sid, + @JsonProperty("street") final String street, + @JsonProperty("uri") final String uri, + @JsonProperty("emergency_enabled") final Boolean emergencyEnabled, + @JsonProperty("validated") final Boolean validated, + @JsonProperty("verified") final Boolean verified, + @JsonProperty("street_secondary") final String streetSecondary ) { this.accountSid = accountSid; this.city = city; @@ -198,58 +213,73 @@ private Address( this.streetSecondary = streetSecondary; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getCity() { - return this.city; - } - public final String getCustomerName() { - return this.customerName; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getIsoCountry() { - return this.isoCountry; - } - public final String getPostalCode() { - return this.postalCode; - } - public final String getRegion() { - return this.region; - } - public final String getSid() { - return this.sid; - } - public final String getStreet() { - return this.street; - } - public final String getUri() { - return this.uri; - } - public final Boolean getEmergencyEnabled() { - return this.emergencyEnabled; - } - public final Boolean getValidated() { - return this.validated; - } - public final Boolean getVerified() { - return this.verified; - } - public final String getStreetSecondary() { - return this.streetSecondary; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getCity() { + return this.city; + } + + public final String getCustomerName() { + return this.customerName; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getIsoCountry() { + return this.isoCountry; + } + + public final String getPostalCode() { + return this.postalCode; + } + + public final String getRegion() { + return this.region; + } + + public final String getSid() { + return this.sid; + } + + public final String getStreet() { + return this.street; + } + + public final String getUri() { + return this.uri; + } + + public final Boolean getEmergencyEnabled() { + return this.emergencyEnabled; + } + + public final Boolean getValidated() { + return this.validated; + } + + public final Boolean getVerified() { + return this.verified; + } + + public final String getStreetSecondary() { + return this.streetSecondary; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -259,13 +289,45 @@ public boolean equals(final Object o) { Address other = (Address) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(city, other.city) && Objects.equals(customerName, other.customerName) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(isoCountry, other.isoCountry) && Objects.equals(postalCode, other.postalCode) && Objects.equals(region, other.region) && Objects.equals(sid, other.sid) && Objects.equals(street, other.street) && Objects.equals(uri, other.uri) && Objects.equals(emergencyEnabled, other.emergencyEnabled) && Objects.equals(validated, other.validated) && Objects.equals(verified, other.verified) && Objects.equals(streetSecondary, other.streetSecondary) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(city, other.city) && + Objects.equals(customerName, other.customerName) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(isoCountry, other.isoCountry) && + Objects.equals(postalCode, other.postalCode) && + Objects.equals(region, other.region) && + Objects.equals(sid, other.sid) && + Objects.equals(street, other.street) && + Objects.equals(uri, other.uri) && + Objects.equals(emergencyEnabled, other.emergencyEnabled) && + Objects.equals(validated, other.validated) && + Objects.equals(verified, other.verified) && + Objects.equals(streetSecondary, other.streetSecondary) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, city, customerName, dateCreated, dateUpdated, friendlyName, isoCountry, postalCode, region, sid, street, uri, emergencyEnabled, validated, verified, streetSecondary); + return Objects.hash( + accountSid, + city, + customerName, + dateCreated, + dateUpdated, + friendlyName, + isoCountry, + postalCode, + region, + sid, + street, + uri, + emergencyEnabled, + validated, + verified, + streetSecondary + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/AddressCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/AddressCreator.java index c2cbfd9164..e7a01b0dd2 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/AddressCreator.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/AddressCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010.account; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class AddressCreator extends Creator
{ - - -public class AddressCreator extends Creator
{ private String customerName; private String street; private String city; @@ -40,7 +39,14 @@ public class AddressCreator extends Creator
{ private Boolean autoCorrectAddress; private String streetSecondary; - public AddressCreator(final String customerName, final String street, final String city, final String region, final String postalCode, final String isoCountry) { + public AddressCreator( + final String customerName, + final String street, + final String city, + final String region, + final String postalCode, + final String isoCountry + ) { this.customerName = customerName; this.street = street; this.city = city; @@ -48,7 +54,16 @@ public AddressCreator(final String customerName, final String street, final Stri this.postalCode = postalCode; this.isoCountry = isoCountry; } - public AddressCreator(final String pathAccountSid, final String customerName, final String street, final String city, final String region, final String postalCode, final String isoCountry) { + + public AddressCreator( + final String pathAccountSid, + final String customerName, + final String street, + final String city, + final String region, + final String postalCode, + final String isoCountry + ) { this.pathAccountSid = pathAccountSid; this.customerName = customerName; this.street = street; @@ -58,71 +73,101 @@ public AddressCreator(final String pathAccountSid, final String customerName, fi this.isoCountry = isoCountry; } - public AddressCreator setCustomerName(final String customerName){ + public AddressCreator setCustomerName(final String customerName) { this.customerName = customerName; return this; } - public AddressCreator setStreet(final String street){ + + public AddressCreator setStreet(final String street) { this.street = street; return this; } - public AddressCreator setCity(final String city){ + + public AddressCreator setCity(final String city) { this.city = city; return this; } - public AddressCreator setRegion(final String region){ + + public AddressCreator setRegion(final String region) { this.region = region; return this; } - public AddressCreator setPostalCode(final String postalCode){ + + public AddressCreator setPostalCode(final String postalCode) { this.postalCode = postalCode; return this; } - public AddressCreator setIsoCountry(final String isoCountry){ + + public AddressCreator setIsoCountry(final String isoCountry) { this.isoCountry = isoCountry; return this; } - public AddressCreator setFriendlyName(final String friendlyName){ + + public AddressCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public AddressCreator setEmergencyEnabled(final Boolean emergencyEnabled){ + + public AddressCreator setEmergencyEnabled(final Boolean emergencyEnabled) { this.emergencyEnabled = emergencyEnabled; return this; } - public AddressCreator setAutoCorrectAddress(final Boolean autoCorrectAddress){ + + public AddressCreator setAutoCorrectAddress( + final Boolean autoCorrectAddress + ) { this.autoCorrectAddress = autoCorrectAddress; return this; } - public AddressCreator setStreetSecondary(final String streetSecondary){ + + public AddressCreator setStreetSecondary(final String streetSecondary) { this.streetSecondary = streetSecondary; return this; } @Override - public Address create(final TwilioRestClient client){ + public Address create(final TwilioRestClient client) { String path = "/2010-04-01/Accounts/{AccountSid}/Addresses.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"CustomerName"+"}", this.customerName.toString()); - path = path.replace("{"+"Street"+"}", this.street.toString()); - path = path.replace("{"+"City"+"}", this.city.toString()); - path = path.replace("{"+"Region"+"}", this.region.toString()); - path = path.replace("{"+"PostalCode"+"}", this.postalCode.toString()); - path = path.replace("{"+"IsoCountry"+"}", this.isoCountry.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "CustomerName" + "}", + this.customerName.toString() + ); + path = path.replace("{" + "Street" + "}", this.street.toString()); + path = path.replace("{" + "City" + "}", this.city.toString()); + path = path.replace("{" + "Region" + "}", this.region.toString()); + path = + path.replace("{" + "PostalCode" + "}", this.postalCode.toString()); + path = + path.replace("{" + "IsoCountry" + "}", this.isoCountry.toString()); Request request = new Request( HttpMethod.POST, Domains.API.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Address creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Address creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -131,46 +176,43 @@ public Address create(final TwilioRestClient client){ return Address.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (customerName != null) { request.addPostParam("CustomerName", customerName); - } if (street != null) { request.addPostParam("Street", street); - } if (city != null) { request.addPostParam("City", city); - } if (region != null) { request.addPostParam("Region", region); - } if (postalCode != null) { request.addPostParam("PostalCode", postalCode); - } if (isoCountry != null) { request.addPostParam("IsoCountry", isoCountry); - } if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (emergencyEnabled != null) { - request.addPostParam("EmergencyEnabled", emergencyEnabled.toString()); - + request.addPostParam( + "EmergencyEnabled", + emergencyEnabled.toString() + ); } if (autoCorrectAddress != null) { - request.addPostParam("AutoCorrectAddress", autoCorrectAddress.toString()); - + request.addPostParam( + "AutoCorrectAddress", + autoCorrectAddress.toString() + ); } if (streetSecondary != null) { request.addPostParam("StreetSecondary", streetSecondary); - } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/AddressDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/AddressDeleter.java index beb1c93f8f..d2e26d420a 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/AddressDeleter.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/AddressDeleter.java @@ -24,28 +24,34 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class AddressDeleter extends Deleter
{ + private String pathSid; private String pathAccountSid; - public AddressDeleter(final String pathSid){ + public AddressDeleter(final String pathSid) { this.pathSid = pathSid; } - public AddressDeleter(final String pathAccountSid, final String pathSid){ + + public AddressDeleter(final String pathAccountSid, final String pathSid) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/2010-04-01/Accounts/{AccountSid}/Addresses/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -55,9 +61,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Address delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Address delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/AddressFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/AddressFetcher.java index 419a8a19b1..5f3d8af90c 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/AddressFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/AddressFetcher.java @@ -24,29 +24,34 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class AddressFetcher extends Fetcher
{ + private String pathSid; private String pathAccountSid; - public AddressFetcher(final String pathSid){ + public AddressFetcher(final String pathSid) { this.pathSid = pathSid; } - public AddressFetcher(final String pathAccountSid, final String pathSid){ + + public AddressFetcher(final String pathAccountSid, final String pathSid) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - @Override public Address fetch(final TwilioRestClient client) { String path = "/2010-04-01/Accounts/{AccountSid}/Addresses/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -56,9 +61,14 @@ public Address fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Address fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Address fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/AddressReader.java b/src/main/java/com/twilio/rest/api/v2010/account/AddressReader.java index 2887a4f06f..0c28000667 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/AddressReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/AddressReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.api.v2010.account; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,36 +25,37 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class AddressReader extends Reader
{ + private String pathAccountSid; private String customerName; private String friendlyName; private String isoCountry; private Integer pageSize; - public AddressReader(){ - } - public AddressReader(final String pathAccountSid){ + public AddressReader() {} + + public AddressReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - public AddressReader setCustomerName(final String customerName){ + public AddressReader setCustomerName(final String customerName) { this.customerName = customerName; return this; } - public AddressReader setFriendlyName(final String friendlyName){ + + public AddressReader setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public AddressReader setIsoCountry(final String isoCountry){ + + public AddressReader setIsoCountry(final String isoCountry) { this.isoCountry = isoCountry; return this; } - public AddressReader setPageSize(final Integer pageSize){ + + public AddressReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -65,8 +67,15 @@ public ResourceSet
read(final TwilioRestClient client) { public Page
firstPage(final TwilioRestClient client) { String path = "/2010-04-01/Accounts/{AccountSid}/Addresses.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -78,13 +87,21 @@ public Page
firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page
pageForRequest(final TwilioRestClient client, final Request request) { + private Page
pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Address read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Address read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -100,7 +117,10 @@ private Page
pageForRequest(final TwilioRestClient client, final Reques } @Override - public Page
previousPage(final Page
page, final TwilioRestClient client) { + public Page
previousPage( + final Page
page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.API.toString()) @@ -108,9 +128,11 @@ public Page
previousPage(final Page
page, final TwilioRestClie return pageForRequest(client, request); } - @Override - public Page
nextPage(final Page
page, final TwilioRestClient client) { + public Page
nextPage( + final Page
page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.API.toString()) @@ -119,33 +141,30 @@ public Page
nextPage(final Page
page, final TwilioRestClient c } @Override - public Page
getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page
getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (customerName != null) { - request.addQueryParam("CustomerName", customerName); } if (friendlyName != null) { - request.addQueryParam("FriendlyName", friendlyName); } if (isoCountry != null) { - request.addQueryParam("IsoCountry", isoCountry); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/AddressUpdater.java b/src/main/java/com/twilio/rest/api/v2010/account/AddressUpdater.java index e1dec4191f..bb558bc282 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/AddressUpdater.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/AddressUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010.account; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class AddressUpdater extends Updater
{ - - -public class AddressUpdater extends Updater
{ private String pathSid; private String pathAccountSid; private String friendlyName; @@ -40,70 +39,94 @@ public class AddressUpdater extends Updater
{ private Boolean autoCorrectAddress; private String streetSecondary; - public AddressUpdater(final String pathSid){ + public AddressUpdater(final String pathSid) { this.pathSid = pathSid; } - public AddressUpdater(final String pathAccountSid, final String pathSid){ + + public AddressUpdater(final String pathAccountSid, final String pathSid) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - public AddressUpdater setFriendlyName(final String friendlyName){ + public AddressUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public AddressUpdater setCustomerName(final String customerName){ + + public AddressUpdater setCustomerName(final String customerName) { this.customerName = customerName; return this; } - public AddressUpdater setStreet(final String street){ + + public AddressUpdater setStreet(final String street) { this.street = street; return this; } - public AddressUpdater setCity(final String city){ + + public AddressUpdater setCity(final String city) { this.city = city; return this; } - public AddressUpdater setRegion(final String region){ + + public AddressUpdater setRegion(final String region) { this.region = region; return this; } - public AddressUpdater setPostalCode(final String postalCode){ + + public AddressUpdater setPostalCode(final String postalCode) { this.postalCode = postalCode; return this; } - public AddressUpdater setEmergencyEnabled(final Boolean emergencyEnabled){ + + public AddressUpdater setEmergencyEnabled(final Boolean emergencyEnabled) { this.emergencyEnabled = emergencyEnabled; return this; } - public AddressUpdater setAutoCorrectAddress(final Boolean autoCorrectAddress){ + + public AddressUpdater setAutoCorrectAddress( + final Boolean autoCorrectAddress + ) { this.autoCorrectAddress = autoCorrectAddress; return this; } - public AddressUpdater setStreetSecondary(final String streetSecondary){ + + public AddressUpdater setStreetSecondary(final String streetSecondary) { this.streetSecondary = streetSecondary; return this; } @Override - public Address update(final TwilioRestClient client){ + public Address update(final TwilioRestClient client) { String path = "/2010-04-01/Accounts/{AccountSid}/Addresses/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.API.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Address update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Address update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -112,42 +135,40 @@ public Address update(final TwilioRestClient client){ return Address.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (customerName != null) { request.addPostParam("CustomerName", customerName); - } if (street != null) { request.addPostParam("Street", street); - } if (city != null) { request.addPostParam("City", city); - } if (region != null) { request.addPostParam("Region", region); - } if (postalCode != null) { request.addPostParam("PostalCode", postalCode); - } if (emergencyEnabled != null) { - request.addPostParam("EmergencyEnabled", emergencyEnabled.toString()); - + request.addPostParam( + "EmergencyEnabled", + emergencyEnabled.toString() + ); } if (autoCorrectAddress != null) { - request.addPostParam("AutoCorrectAddress", autoCorrectAddress.toString()); - + request.addPostParam( + "AutoCorrectAddress", + autoCorrectAddress.toString() + ); } if (streetSecondary != null) { request.addPostParam("StreetSecondary", streetSecondary); - } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/Application.java b/src/main/java/com/twilio/rest/api/v2010/account/Application.java index 208f8be8c6..d9e76250e5 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/Application.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/Application.java @@ -23,69 +23,82 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; import com.twilio.http.HttpMethod; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Application extends Resource { + private static final long serialVersionUID = 38146741905668L; - public static ApplicationCreator creator(){ + public static ApplicationCreator creator() { return new ApplicationCreator(); } - public static ApplicationCreator creator(final String pathAccountSid){ + + public static ApplicationCreator creator(final String pathAccountSid) { return new ApplicationCreator(pathAccountSid); } - public static ApplicationDeleter deleter(final String pathSid){ + public static ApplicationDeleter deleter(final String pathSid) { return new ApplicationDeleter(pathSid); } - public static ApplicationDeleter deleter(final String pathAccountSid, final String pathSid){ + + public static ApplicationDeleter deleter( + final String pathAccountSid, + final String pathSid + ) { return new ApplicationDeleter(pathAccountSid, pathSid); } - public static ApplicationFetcher fetcher(final String pathSid){ + public static ApplicationFetcher fetcher(final String pathSid) { return new ApplicationFetcher(pathSid); } - public static ApplicationFetcher fetcher(final String pathAccountSid, final String pathSid){ + + public static ApplicationFetcher fetcher( + final String pathAccountSid, + final String pathSid + ) { return new ApplicationFetcher(pathAccountSid, pathSid); } - public static ApplicationReader reader(){ + public static ApplicationReader reader() { return new ApplicationReader(); } - public static ApplicationReader reader(final String pathAccountSid){ + + public static ApplicationReader reader(final String pathAccountSid) { return new ApplicationReader(pathAccountSid); } - public static ApplicationUpdater updater(final String pathSid){ + public static ApplicationUpdater updater(final String pathSid) { return new ApplicationUpdater(pathSid); } - public static ApplicationUpdater updater(final String pathAccountSid, final String pathSid){ + + public static ApplicationUpdater updater( + final String pathAccountSid, + final String pathSid + ) { return new ApplicationUpdater(pathAccountSid, pathSid); } /** - * Converts a JSON String into a Application object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Application object represented by the provided JSON - */ - public static Application fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Application object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Application object represented by the provided JSON + */ + public static Application fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Application.class); @@ -97,14 +110,17 @@ public static Application fromJson(final String json, final ObjectMapper objectM } /** - * Converts a JSON InputStream into a Application object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Application object represented by the provided JSON - */ - public static Application fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Application object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Application object represented by the provided JSON + */ + public static Application fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Application.class); @@ -139,68 +155,37 @@ public static Application fromJson(final InputStream json, final ObjectMapper ob @JsonCreator private Application( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("api_version") - final String apiVersion, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("message_status_callback") - final URI messageStatusCallback, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("sms_fallback_method") - final HttpMethod smsFallbackMethod, - - @JsonProperty("sms_fallback_url") - final URI smsFallbackUrl, - - @JsonProperty("sms_method") - final HttpMethod smsMethod, - - @JsonProperty("sms_status_callback") - final URI smsStatusCallback, - - @JsonProperty("sms_url") - final URI smsUrl, - - @JsonProperty("status_callback") - final URI statusCallback, - - @JsonProperty("status_callback_method") - final HttpMethod statusCallbackMethod, - - @JsonProperty("uri") - final String uri, - - @JsonProperty("voice_caller_id_lookup") - final Boolean voiceCallerIdLookup, - - @JsonProperty("voice_fallback_method") - final HttpMethod voiceFallbackMethod, - - @JsonProperty("voice_fallback_url") - final URI voiceFallbackUrl, - - @JsonProperty("voice_method") - final HttpMethod voiceMethod, - - @JsonProperty("voice_url") - final URI voiceUrl, - - @JsonProperty("public_application_connect_enabled") - final Boolean publicApplicationConnectEnabled + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("api_version") final String apiVersion, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty( + "message_status_callback" + ) final URI messageStatusCallback, + @JsonProperty("sid") final String sid, + @JsonProperty("sms_fallback_method") final HttpMethod smsFallbackMethod, + @JsonProperty("sms_fallback_url") final URI smsFallbackUrl, + @JsonProperty("sms_method") final HttpMethod smsMethod, + @JsonProperty("sms_status_callback") final URI smsStatusCallback, + @JsonProperty("sms_url") final URI smsUrl, + @JsonProperty("status_callback") final URI statusCallback, + @JsonProperty( + "status_callback_method" + ) final HttpMethod statusCallbackMethod, + @JsonProperty("uri") final String uri, + @JsonProperty( + "voice_caller_id_lookup" + ) final Boolean voiceCallerIdLookup, + @JsonProperty( + "voice_fallback_method" + ) final HttpMethod voiceFallbackMethod, + @JsonProperty("voice_fallback_url") final URI voiceFallbackUrl, + @JsonProperty("voice_method") final HttpMethod voiceMethod, + @JsonProperty("voice_url") final URI voiceUrl, + @JsonProperty( + "public_application_connect_enabled" + ) final Boolean publicApplicationConnectEnabled ) { this.accountSid = accountSid; this.apiVersion = apiVersion; @@ -225,73 +210,93 @@ private Application( this.publicApplicationConnectEnabled = publicApplicationConnectEnabled; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getApiVersion() { - return this.apiVersion; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final URI getMessageStatusCallback() { - return this.messageStatusCallback; - } - public final String getSid() { - return this.sid; - } - public final HttpMethod getSmsFallbackMethod() { - return this.smsFallbackMethod; - } - public final URI getSmsFallbackUrl() { - return this.smsFallbackUrl; - } - public final HttpMethod getSmsMethod() { - return this.smsMethod; - } - public final URI getSmsStatusCallback() { - return this.smsStatusCallback; - } - public final URI getSmsUrl() { - return this.smsUrl; - } - public final URI getStatusCallback() { - return this.statusCallback; - } - public final HttpMethod getStatusCallbackMethod() { - return this.statusCallbackMethod; - } - public final String getUri() { - return this.uri; - } - public final Boolean getVoiceCallerIdLookup() { - return this.voiceCallerIdLookup; - } - public final HttpMethod getVoiceFallbackMethod() { - return this.voiceFallbackMethod; - } - public final URI getVoiceFallbackUrl() { - return this.voiceFallbackUrl; - } - public final HttpMethod getVoiceMethod() { - return this.voiceMethod; - } - public final URI getVoiceUrl() { - return this.voiceUrl; - } - public final Boolean getPublicApplicationConnectEnabled() { - return this.publicApplicationConnectEnabled; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getApiVersion() { + return this.apiVersion; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final URI getMessageStatusCallback() { + return this.messageStatusCallback; + } + + public final String getSid() { + return this.sid; + } + + public final HttpMethod getSmsFallbackMethod() { + return this.smsFallbackMethod; + } + + public final URI getSmsFallbackUrl() { + return this.smsFallbackUrl; + } + + public final HttpMethod getSmsMethod() { + return this.smsMethod; + } + + public final URI getSmsStatusCallback() { + return this.smsStatusCallback; + } + + public final URI getSmsUrl() { + return this.smsUrl; + } + + public final URI getStatusCallback() { + return this.statusCallback; + } + + public final HttpMethod getStatusCallbackMethod() { + return this.statusCallbackMethod; + } + + public final String getUri() { + return this.uri; + } + + public final Boolean getVoiceCallerIdLookup() { + return this.voiceCallerIdLookup; + } + + public final HttpMethod getVoiceFallbackMethod() { + return this.voiceFallbackMethod; + } + + public final URI getVoiceFallbackUrl() { + return this.voiceFallbackUrl; + } + + public final HttpMethod getVoiceMethod() { + return this.voiceMethod; + } + + public final URI getVoiceUrl() { + return this.voiceUrl; + } + + public final Boolean getPublicApplicationConnectEnabled() { + return this.publicApplicationConnectEnabled; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -301,13 +306,61 @@ public boolean equals(final Object o) { Application other = (Application) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(apiVersion, other.apiVersion) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(messageStatusCallback, other.messageStatusCallback) && Objects.equals(sid, other.sid) && Objects.equals(smsFallbackMethod, other.smsFallbackMethod) && Objects.equals(smsFallbackUrl, other.smsFallbackUrl) && Objects.equals(smsMethod, other.smsMethod) && Objects.equals(smsStatusCallback, other.smsStatusCallback) && Objects.equals(smsUrl, other.smsUrl) && Objects.equals(statusCallback, other.statusCallback) && Objects.equals(statusCallbackMethod, other.statusCallbackMethod) && Objects.equals(uri, other.uri) && Objects.equals(voiceCallerIdLookup, other.voiceCallerIdLookup) && Objects.equals(voiceFallbackMethod, other.voiceFallbackMethod) && Objects.equals(voiceFallbackUrl, other.voiceFallbackUrl) && Objects.equals(voiceMethod, other.voiceMethod) && Objects.equals(voiceUrl, other.voiceUrl) && Objects.equals(publicApplicationConnectEnabled, other.publicApplicationConnectEnabled) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(apiVersion, other.apiVersion) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals( + messageStatusCallback, + other.messageStatusCallback + ) && + Objects.equals(sid, other.sid) && + Objects.equals(smsFallbackMethod, other.smsFallbackMethod) && + Objects.equals(smsFallbackUrl, other.smsFallbackUrl) && + Objects.equals(smsMethod, other.smsMethod) && + Objects.equals(smsStatusCallback, other.smsStatusCallback) && + Objects.equals(smsUrl, other.smsUrl) && + Objects.equals(statusCallback, other.statusCallback) && + Objects.equals(statusCallbackMethod, other.statusCallbackMethod) && + Objects.equals(uri, other.uri) && + Objects.equals(voiceCallerIdLookup, other.voiceCallerIdLookup) && + Objects.equals(voiceFallbackMethod, other.voiceFallbackMethod) && + Objects.equals(voiceFallbackUrl, other.voiceFallbackUrl) && + Objects.equals(voiceMethod, other.voiceMethod) && + Objects.equals(voiceUrl, other.voiceUrl) && + Objects.equals( + publicApplicationConnectEnabled, + other.publicApplicationConnectEnabled + ) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, apiVersion, dateCreated, dateUpdated, friendlyName, messageStatusCallback, sid, smsFallbackMethod, smsFallbackUrl, smsMethod, smsStatusCallback, smsUrl, statusCallback, statusCallbackMethod, uri, voiceCallerIdLookup, voiceFallbackMethod, voiceFallbackUrl, voiceMethod, voiceUrl, publicApplicationConnectEnabled); + return Objects.hash( + accountSid, + apiVersion, + dateCreated, + dateUpdated, + friendlyName, + messageStatusCallback, + sid, + smsFallbackMethod, + smsFallbackUrl, + smsMethod, + smsStatusCallback, + smsUrl, + statusCallback, + statusCallbackMethod, + uri, + voiceCallerIdLookup, + voiceFallbackMethod, + voiceFallbackUrl, + voiceMethod, + voiceUrl, + publicApplicationConnectEnabled + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/ApplicationCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/ApplicationCreator.java index f0ddfeaccf..e9299567cf 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/ApplicationCreator.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/ApplicationCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010.account; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -25,12 +26,10 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.net.URI; - - - import java.net.URI; -public class ApplicationCreator extends Creator{ +public class ApplicationCreator extends Creator { + private String pathAccountSid; private String apiVersion; private URI voiceUrl; @@ -49,195 +48,257 @@ public class ApplicationCreator extends Creator{ private String friendlyName; private Boolean publicApplicationConnectEnabled; - public ApplicationCreator() { - } + public ApplicationCreator() {} + public ApplicationCreator(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - public ApplicationCreator setApiVersion(final String apiVersion){ + public ApplicationCreator setApiVersion(final String apiVersion) { this.apiVersion = apiVersion; return this; } - public ApplicationCreator setVoiceUrl(final URI voiceUrl){ + + public ApplicationCreator setVoiceUrl(final URI voiceUrl) { this.voiceUrl = voiceUrl; return this; } - public ApplicationCreator setVoiceUrl(final String voiceUrl){ + public ApplicationCreator setVoiceUrl(final String voiceUrl) { return setVoiceUrl(Promoter.uriFromString(voiceUrl)); } - public ApplicationCreator setVoiceMethod(final HttpMethod voiceMethod){ + + public ApplicationCreator setVoiceMethod(final HttpMethod voiceMethod) { this.voiceMethod = voiceMethod; return this; } - public ApplicationCreator setVoiceFallbackUrl(final URI voiceFallbackUrl){ + + public ApplicationCreator setVoiceFallbackUrl(final URI voiceFallbackUrl) { this.voiceFallbackUrl = voiceFallbackUrl; return this; } - public ApplicationCreator setVoiceFallbackUrl(final String voiceFallbackUrl){ + public ApplicationCreator setVoiceFallbackUrl( + final String voiceFallbackUrl + ) { return setVoiceFallbackUrl(Promoter.uriFromString(voiceFallbackUrl)); } - public ApplicationCreator setVoiceFallbackMethod(final HttpMethod voiceFallbackMethod){ + + public ApplicationCreator setVoiceFallbackMethod( + final HttpMethod voiceFallbackMethod + ) { this.voiceFallbackMethod = voiceFallbackMethod; return this; } - public ApplicationCreator setStatusCallback(final URI statusCallback){ + + public ApplicationCreator setStatusCallback(final URI statusCallback) { this.statusCallback = statusCallback; return this; } - public ApplicationCreator setStatusCallback(final String statusCallback){ + public ApplicationCreator setStatusCallback(final String statusCallback) { return setStatusCallback(Promoter.uriFromString(statusCallback)); } - public ApplicationCreator setStatusCallbackMethod(final HttpMethod statusCallbackMethod){ + + public ApplicationCreator setStatusCallbackMethod( + final HttpMethod statusCallbackMethod + ) { this.statusCallbackMethod = statusCallbackMethod; return this; } - public ApplicationCreator setVoiceCallerIdLookup(final Boolean voiceCallerIdLookup){ + + public ApplicationCreator setVoiceCallerIdLookup( + final Boolean voiceCallerIdLookup + ) { this.voiceCallerIdLookup = voiceCallerIdLookup; return this; } - public ApplicationCreator setSmsUrl(final URI smsUrl){ + + public ApplicationCreator setSmsUrl(final URI smsUrl) { this.smsUrl = smsUrl; return this; } - public ApplicationCreator setSmsUrl(final String smsUrl){ + public ApplicationCreator setSmsUrl(final String smsUrl) { return setSmsUrl(Promoter.uriFromString(smsUrl)); } - public ApplicationCreator setSmsMethod(final HttpMethod smsMethod){ + + public ApplicationCreator setSmsMethod(final HttpMethod smsMethod) { this.smsMethod = smsMethod; return this; } - public ApplicationCreator setSmsFallbackUrl(final URI smsFallbackUrl){ + + public ApplicationCreator setSmsFallbackUrl(final URI smsFallbackUrl) { this.smsFallbackUrl = smsFallbackUrl; return this; } - public ApplicationCreator setSmsFallbackUrl(final String smsFallbackUrl){ + public ApplicationCreator setSmsFallbackUrl(final String smsFallbackUrl) { return setSmsFallbackUrl(Promoter.uriFromString(smsFallbackUrl)); } - public ApplicationCreator setSmsFallbackMethod(final HttpMethod smsFallbackMethod){ + + public ApplicationCreator setSmsFallbackMethod( + final HttpMethod smsFallbackMethod + ) { this.smsFallbackMethod = smsFallbackMethod; return this; } - public ApplicationCreator setSmsStatusCallback(final URI smsStatusCallback){ + + public ApplicationCreator setSmsStatusCallback( + final URI smsStatusCallback + ) { this.smsStatusCallback = smsStatusCallback; return this; } - public ApplicationCreator setSmsStatusCallback(final String smsStatusCallback){ + public ApplicationCreator setSmsStatusCallback( + final String smsStatusCallback + ) { return setSmsStatusCallback(Promoter.uriFromString(smsStatusCallback)); } - public ApplicationCreator setMessageStatusCallback(final URI messageStatusCallback){ + + public ApplicationCreator setMessageStatusCallback( + final URI messageStatusCallback + ) { this.messageStatusCallback = messageStatusCallback; return this; } - public ApplicationCreator setMessageStatusCallback(final String messageStatusCallback){ - return setMessageStatusCallback(Promoter.uriFromString(messageStatusCallback)); + public ApplicationCreator setMessageStatusCallback( + final String messageStatusCallback + ) { + return setMessageStatusCallback( + Promoter.uriFromString(messageStatusCallback) + ); } - public ApplicationCreator setFriendlyName(final String friendlyName){ + + public ApplicationCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public ApplicationCreator setPublicApplicationConnectEnabled(final Boolean publicApplicationConnectEnabled){ + + public ApplicationCreator setPublicApplicationConnectEnabled( + final Boolean publicApplicationConnectEnabled + ) { this.publicApplicationConnectEnabled = publicApplicationConnectEnabled; return this; } @Override - public Application create(final TwilioRestClient client){ + public Application create(final TwilioRestClient client) { String path = "/2010-04-01/Accounts/{AccountSid}/Applications.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.API.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Application creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Application creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Application.fromJson(response.getStream(), client.getObjectMapper()); + return Application.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (apiVersion != null) { request.addPostParam("ApiVersion", apiVersion); - } if (voiceUrl != null) { request.addPostParam("VoiceUrl", voiceUrl.toString()); - } if (voiceMethod != null) { request.addPostParam("VoiceMethod", voiceMethod.toString()); - } if (voiceFallbackUrl != null) { - request.addPostParam("VoiceFallbackUrl", voiceFallbackUrl.toString()); - + request.addPostParam( + "VoiceFallbackUrl", + voiceFallbackUrl.toString() + ); } if (voiceFallbackMethod != null) { - request.addPostParam("VoiceFallbackMethod", voiceFallbackMethod.toString()); - + request.addPostParam( + "VoiceFallbackMethod", + voiceFallbackMethod.toString() + ); } if (statusCallback != null) { request.addPostParam("StatusCallback", statusCallback.toString()); - } if (statusCallbackMethod != null) { - request.addPostParam("StatusCallbackMethod", statusCallbackMethod.toString()); - + request.addPostParam( + "StatusCallbackMethod", + statusCallbackMethod.toString() + ); } if (voiceCallerIdLookup != null) { - request.addPostParam("VoiceCallerIdLookup", voiceCallerIdLookup.toString()); - + request.addPostParam( + "VoiceCallerIdLookup", + voiceCallerIdLookup.toString() + ); } if (smsUrl != null) { request.addPostParam("SmsUrl", smsUrl.toString()); - } if (smsMethod != null) { request.addPostParam("SmsMethod", smsMethod.toString()); - } if (smsFallbackUrl != null) { request.addPostParam("SmsFallbackUrl", smsFallbackUrl.toString()); - } if (smsFallbackMethod != null) { - request.addPostParam("SmsFallbackMethod", smsFallbackMethod.toString()); - + request.addPostParam( + "SmsFallbackMethod", + smsFallbackMethod.toString() + ); } if (smsStatusCallback != null) { - request.addPostParam("SmsStatusCallback", smsStatusCallback.toString()); - + request.addPostParam( + "SmsStatusCallback", + smsStatusCallback.toString() + ); } if (messageStatusCallback != null) { - request.addPostParam("MessageStatusCallback", messageStatusCallback.toString()); - + request.addPostParam( + "MessageStatusCallback", + messageStatusCallback.toString() + ); } if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (publicApplicationConnectEnabled != null) { - request.addPostParam("PublicApplicationConnectEnabled", publicApplicationConnectEnabled.toString()); - + request.addPostParam( + "PublicApplicationConnectEnabled", + publicApplicationConnectEnabled.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/ApplicationDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/ApplicationDeleter.java index 21d950bce9..09d1b838b8 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/ApplicationDeleter.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/ApplicationDeleter.java @@ -24,28 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class ApplicationDeleter extends Deleter { + private String pathSid; private String pathAccountSid; - public ApplicationDeleter(final String pathSid){ + public ApplicationDeleter(final String pathSid) { this.pathSid = pathSid; } - public ApplicationDeleter(final String pathAccountSid, final String pathSid){ + + public ApplicationDeleter( + final String pathAccountSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/Applications/{Sid}.json"; + String path = + "/2010-04-01/Accounts/{AccountSid}/Applications/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -55,9 +65,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Application delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Application delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/ApplicationFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/ApplicationFetcher.java index 288a995f6e..c5c4c2b915 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/ApplicationFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/ApplicationFetcher.java @@ -24,29 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class ApplicationFetcher extends Fetcher { + private String pathSid; private String pathAccountSid; - public ApplicationFetcher(final String pathSid){ + public ApplicationFetcher(final String pathSid) { this.pathSid = pathSid; } - public ApplicationFetcher(final String pathAccountSid, final String pathSid){ + + public ApplicationFetcher( + final String pathAccountSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - @Override public Application fetch(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/Applications/{Sid}.json"; + String path = + "/2010-04-01/Accounts/{AccountSid}/Applications/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -56,15 +65,23 @@ public Application fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Application fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Application fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Application.fromJson(response.getStream(), client.getObjectMapper()); + return Application.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/ApplicationReader.java b/src/main/java/com/twilio/rest/api/v2010/account/ApplicationReader.java index 32faae9780..e9c8b0f35a 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/ApplicationReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/ApplicationReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.api.v2010.account; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,26 +25,25 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class ApplicationReader extends Reader { + private String pathAccountSid; private String friendlyName; private Integer pageSize; - public ApplicationReader(){ - } - public ApplicationReader(final String pathAccountSid){ + public ApplicationReader() {} + + public ApplicationReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - public ApplicationReader setFriendlyName(final String friendlyName){ + public ApplicationReader setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public ApplicationReader setPageSize(final Integer pageSize){ + + public ApplicationReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -55,8 +55,15 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/2010-04-01/Accounts/{AccountSid}/Applications.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -68,13 +75,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Application read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Application read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -90,7 +105,10 @@ private Page pageForRequest(final TwilioRestClient client, final Re } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.API.toString()) @@ -98,9 +116,11 @@ public Page previousPage(final Page page, final Twilio return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.API.toString()) @@ -109,25 +129,24 @@ public Page nextPage(final Page page, final TwilioRest } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (friendlyName != null) { - request.addQueryParam("FriendlyName", friendlyName); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/ApplicationUpdater.java b/src/main/java/com/twilio/rest/api/v2010/account/ApplicationUpdater.java index 0ea2b6a657..26c861d3da 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/ApplicationUpdater.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/ApplicationUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010.account; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -24,12 +25,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.net.URI; +public class ApplicationUpdater extends Updater { - -public class ApplicationUpdater extends Updater{ private String pathSid; private String pathAccountSid; private String friendlyName; @@ -49,198 +48,265 @@ public class ApplicationUpdater extends Updater{ private URI messageStatusCallback; private Boolean publicApplicationConnectEnabled; - public ApplicationUpdater(final String pathSid){ + public ApplicationUpdater(final String pathSid) { this.pathSid = pathSid; } - public ApplicationUpdater(final String pathAccountSid, final String pathSid){ + + public ApplicationUpdater( + final String pathAccountSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - public ApplicationUpdater setFriendlyName(final String friendlyName){ + public ApplicationUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public ApplicationUpdater setApiVersion(final String apiVersion){ + + public ApplicationUpdater setApiVersion(final String apiVersion) { this.apiVersion = apiVersion; return this; } - public ApplicationUpdater setVoiceUrl(final URI voiceUrl){ + + public ApplicationUpdater setVoiceUrl(final URI voiceUrl) { this.voiceUrl = voiceUrl; return this; } - public ApplicationUpdater setVoiceUrl(final String voiceUrl){ + public ApplicationUpdater setVoiceUrl(final String voiceUrl) { return setVoiceUrl(Promoter.uriFromString(voiceUrl)); } - public ApplicationUpdater setVoiceMethod(final HttpMethod voiceMethod){ + + public ApplicationUpdater setVoiceMethod(final HttpMethod voiceMethod) { this.voiceMethod = voiceMethod; return this; } - public ApplicationUpdater setVoiceFallbackUrl(final URI voiceFallbackUrl){ + + public ApplicationUpdater setVoiceFallbackUrl(final URI voiceFallbackUrl) { this.voiceFallbackUrl = voiceFallbackUrl; return this; } - public ApplicationUpdater setVoiceFallbackUrl(final String voiceFallbackUrl){ + public ApplicationUpdater setVoiceFallbackUrl( + final String voiceFallbackUrl + ) { return setVoiceFallbackUrl(Promoter.uriFromString(voiceFallbackUrl)); } - public ApplicationUpdater setVoiceFallbackMethod(final HttpMethod voiceFallbackMethod){ + + public ApplicationUpdater setVoiceFallbackMethod( + final HttpMethod voiceFallbackMethod + ) { this.voiceFallbackMethod = voiceFallbackMethod; return this; } - public ApplicationUpdater setStatusCallback(final URI statusCallback){ + + public ApplicationUpdater setStatusCallback(final URI statusCallback) { this.statusCallback = statusCallback; return this; } - public ApplicationUpdater setStatusCallback(final String statusCallback){ + public ApplicationUpdater setStatusCallback(final String statusCallback) { return setStatusCallback(Promoter.uriFromString(statusCallback)); } - public ApplicationUpdater setStatusCallbackMethod(final HttpMethod statusCallbackMethod){ + + public ApplicationUpdater setStatusCallbackMethod( + final HttpMethod statusCallbackMethod + ) { this.statusCallbackMethod = statusCallbackMethod; return this; } - public ApplicationUpdater setVoiceCallerIdLookup(final Boolean voiceCallerIdLookup){ + + public ApplicationUpdater setVoiceCallerIdLookup( + final Boolean voiceCallerIdLookup + ) { this.voiceCallerIdLookup = voiceCallerIdLookup; return this; } - public ApplicationUpdater setSmsUrl(final URI smsUrl){ + + public ApplicationUpdater setSmsUrl(final URI smsUrl) { this.smsUrl = smsUrl; return this; } - public ApplicationUpdater setSmsUrl(final String smsUrl){ + public ApplicationUpdater setSmsUrl(final String smsUrl) { return setSmsUrl(Promoter.uriFromString(smsUrl)); } - public ApplicationUpdater setSmsMethod(final HttpMethod smsMethod){ + + public ApplicationUpdater setSmsMethod(final HttpMethod smsMethod) { this.smsMethod = smsMethod; return this; } - public ApplicationUpdater setSmsFallbackUrl(final URI smsFallbackUrl){ + + public ApplicationUpdater setSmsFallbackUrl(final URI smsFallbackUrl) { this.smsFallbackUrl = smsFallbackUrl; return this; } - public ApplicationUpdater setSmsFallbackUrl(final String smsFallbackUrl){ + public ApplicationUpdater setSmsFallbackUrl(final String smsFallbackUrl) { return setSmsFallbackUrl(Promoter.uriFromString(smsFallbackUrl)); } - public ApplicationUpdater setSmsFallbackMethod(final HttpMethod smsFallbackMethod){ + + public ApplicationUpdater setSmsFallbackMethod( + final HttpMethod smsFallbackMethod + ) { this.smsFallbackMethod = smsFallbackMethod; return this; } - public ApplicationUpdater setSmsStatusCallback(final URI smsStatusCallback){ + + public ApplicationUpdater setSmsStatusCallback( + final URI smsStatusCallback + ) { this.smsStatusCallback = smsStatusCallback; return this; } - public ApplicationUpdater setSmsStatusCallback(final String smsStatusCallback){ + public ApplicationUpdater setSmsStatusCallback( + final String smsStatusCallback + ) { return setSmsStatusCallback(Promoter.uriFromString(smsStatusCallback)); } - public ApplicationUpdater setMessageStatusCallback(final URI messageStatusCallback){ + + public ApplicationUpdater setMessageStatusCallback( + final URI messageStatusCallback + ) { this.messageStatusCallback = messageStatusCallback; return this; } - public ApplicationUpdater setMessageStatusCallback(final String messageStatusCallback){ - return setMessageStatusCallback(Promoter.uriFromString(messageStatusCallback)); + public ApplicationUpdater setMessageStatusCallback( + final String messageStatusCallback + ) { + return setMessageStatusCallback( + Promoter.uriFromString(messageStatusCallback) + ); } - public ApplicationUpdater setPublicApplicationConnectEnabled(final Boolean publicApplicationConnectEnabled){ + + public ApplicationUpdater setPublicApplicationConnectEnabled( + final Boolean publicApplicationConnectEnabled + ) { this.publicApplicationConnectEnabled = publicApplicationConnectEnabled; return this; } @Override - public Application update(final TwilioRestClient client){ - String path = "/2010-04-01/Accounts/{AccountSid}/Applications/{Sid}.json"; + public Application update(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Applications/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.API.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Application update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Application update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Application.fromJson(response.getStream(), client.getObjectMapper()); + return Application.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (apiVersion != null) { request.addPostParam("ApiVersion", apiVersion); - } if (voiceUrl != null) { request.addPostParam("VoiceUrl", voiceUrl.toString()); - } if (voiceMethod != null) { request.addPostParam("VoiceMethod", voiceMethod.toString()); - } if (voiceFallbackUrl != null) { - request.addPostParam("VoiceFallbackUrl", voiceFallbackUrl.toString()); - + request.addPostParam( + "VoiceFallbackUrl", + voiceFallbackUrl.toString() + ); } if (voiceFallbackMethod != null) { - request.addPostParam("VoiceFallbackMethod", voiceFallbackMethod.toString()); - + request.addPostParam( + "VoiceFallbackMethod", + voiceFallbackMethod.toString() + ); } if (statusCallback != null) { request.addPostParam("StatusCallback", statusCallback.toString()); - } if (statusCallbackMethod != null) { - request.addPostParam("StatusCallbackMethod", statusCallbackMethod.toString()); - + request.addPostParam( + "StatusCallbackMethod", + statusCallbackMethod.toString() + ); } if (voiceCallerIdLookup != null) { - request.addPostParam("VoiceCallerIdLookup", voiceCallerIdLookup.toString()); - + request.addPostParam( + "VoiceCallerIdLookup", + voiceCallerIdLookup.toString() + ); } if (smsUrl != null) { request.addPostParam("SmsUrl", smsUrl.toString()); - } if (smsMethod != null) { request.addPostParam("SmsMethod", smsMethod.toString()); - } if (smsFallbackUrl != null) { request.addPostParam("SmsFallbackUrl", smsFallbackUrl.toString()); - } if (smsFallbackMethod != null) { - request.addPostParam("SmsFallbackMethod", smsFallbackMethod.toString()); - + request.addPostParam( + "SmsFallbackMethod", + smsFallbackMethod.toString() + ); } if (smsStatusCallback != null) { - request.addPostParam("SmsStatusCallback", smsStatusCallback.toString()); - + request.addPostParam( + "SmsStatusCallback", + smsStatusCallback.toString() + ); } if (messageStatusCallback != null) { - request.addPostParam("MessageStatusCallback", messageStatusCallback.toString()); - + request.addPostParam( + "MessageStatusCallback", + messageStatusCallback.toString() + ); } if (publicApplicationConnectEnabled != null) { - request.addPostParam("PublicApplicationConnectEnabled", publicApplicationConnectEnabled.toString()); - + request.addPostParam( + "PublicApplicationConnectEnabled", + publicApplicationConnectEnabled.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/AuthorizedConnectApp.java b/src/main/java/com/twilio/rest/api/v2010/account/AuthorizedConnectApp.java index 59bef10218..216e8ca982 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/AuthorizedConnectApp.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/AuthorizedConnectApp.java @@ -24,48 +24,59 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.List; import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class AuthorizedConnectApp extends Resource { + private static final long serialVersionUID = 15094155294983L; - public static AuthorizedConnectAppFetcher fetcher(final String pathConnectAppSid){ + public static AuthorizedConnectAppFetcher fetcher( + final String pathConnectAppSid + ) { return new AuthorizedConnectAppFetcher(pathConnectAppSid); } - public static AuthorizedConnectAppFetcher fetcher(final String pathAccountSid, final String pathConnectAppSid){ - return new AuthorizedConnectAppFetcher(pathAccountSid, pathConnectAppSid); + + public static AuthorizedConnectAppFetcher fetcher( + final String pathAccountSid, + final String pathConnectAppSid + ) { + return new AuthorizedConnectAppFetcher( + pathAccountSid, + pathConnectAppSid + ); } - public static AuthorizedConnectAppReader reader(){ + public static AuthorizedConnectAppReader reader() { return new AuthorizedConnectAppReader(); } - public static AuthorizedConnectAppReader reader(final String pathAccountSid){ + + public static AuthorizedConnectAppReader reader( + final String pathAccountSid + ) { return new AuthorizedConnectAppReader(pathAccountSid); } /** - * Converts a JSON String into a AuthorizedConnectApp object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return AuthorizedConnectApp object represented by the provided JSON - */ - public static AuthorizedConnectApp fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a AuthorizedConnectApp object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return AuthorizedConnectApp object represented by the provided JSON + */ + public static AuthorizedConnectApp fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, AuthorizedConnectApp.class); @@ -77,14 +88,17 @@ public static AuthorizedConnectApp fromJson(final String json, final ObjectMappe } /** - * Converts a JSON InputStream into a AuthorizedConnectApp object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return AuthorizedConnectApp object represented by the provided JSON - */ - public static AuthorizedConnectApp fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a AuthorizedConnectApp object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return AuthorizedConnectApp object represented by the provided JSON + */ + public static AuthorizedConnectApp fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, AuthorizedConnectApp.class); @@ -94,6 +108,7 @@ public static AuthorizedConnectApp fromJson(final InputStream json, final Object throw new ApiConnectionException(e.getMessage(), e); } } + public enum Permission { GET_ALL("get-all"), POST_ALL("post-all"); @@ -127,35 +142,26 @@ public static Permission forValue(final String value) { @JsonCreator private AuthorizedConnectApp( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("connect_app_company_name") - final String connectAppCompanyName, - - @JsonProperty("connect_app_description") - final String connectAppDescription, - - @JsonProperty("connect_app_friendly_name") - final String connectAppFriendlyName, - - @JsonProperty("connect_app_homepage_url") - final URI connectAppHomepageUrl, - - @JsonProperty("connect_app_sid") - final String connectAppSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("permissions") - final List permissions, - - @JsonProperty("uri") - final String uri + @JsonProperty("account_sid") final String accountSid, + @JsonProperty( + "connect_app_company_name" + ) final String connectAppCompanyName, + @JsonProperty( + "connect_app_description" + ) final String connectAppDescription, + @JsonProperty( + "connect_app_friendly_name" + ) final String connectAppFriendlyName, + @JsonProperty( + "connect_app_homepage_url" + ) final URI connectAppHomepageUrl, + @JsonProperty("connect_app_sid") final String connectAppSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty( + "permissions" + ) final List permissions, + @JsonProperty("uri") final String uri ) { this.accountSid = accountSid; this.connectAppCompanyName = connectAppCompanyName; @@ -169,40 +175,49 @@ private AuthorizedConnectApp( this.uri = uri; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getConnectAppCompanyName() { - return this.connectAppCompanyName; - } - public final String getConnectAppDescription() { - return this.connectAppDescription; - } - public final String getConnectAppFriendlyName() { - return this.connectAppFriendlyName; - } - public final URI getConnectAppHomepageUrl() { - return this.connectAppHomepageUrl; - } - public final String getConnectAppSid() { - return this.connectAppSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final List getPermissions() { - return this.permissions; - } - public final String getUri() { - return this.uri; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getConnectAppCompanyName() { + return this.connectAppCompanyName; + } + + public final String getConnectAppDescription() { + return this.connectAppDescription; + } + + public final String getConnectAppFriendlyName() { + return this.connectAppFriendlyName; + } + + public final URI getConnectAppHomepageUrl() { + return this.connectAppHomepageUrl; + } + + public final String getConnectAppSid() { + return this.connectAppSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final List getPermissions() { + return this.permissions; + } + + public final String getUri() { + return this.uri; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -212,13 +227,45 @@ public boolean equals(final Object o) { AuthorizedConnectApp other = (AuthorizedConnectApp) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(connectAppCompanyName, other.connectAppCompanyName) && Objects.equals(connectAppDescription, other.connectAppDescription) && Objects.equals(connectAppFriendlyName, other.connectAppFriendlyName) && Objects.equals(connectAppHomepageUrl, other.connectAppHomepageUrl) && Objects.equals(connectAppSid, other.connectAppSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(permissions, other.permissions) && Objects.equals(uri, other.uri) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals( + connectAppCompanyName, + other.connectAppCompanyName + ) && + Objects.equals( + connectAppDescription, + other.connectAppDescription + ) && + Objects.equals( + connectAppFriendlyName, + other.connectAppFriendlyName + ) && + Objects.equals( + connectAppHomepageUrl, + other.connectAppHomepageUrl + ) && + Objects.equals(connectAppSid, other.connectAppSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(permissions, other.permissions) && + Objects.equals(uri, other.uri) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, connectAppCompanyName, connectAppDescription, connectAppFriendlyName, connectAppHomepageUrl, connectAppSid, dateCreated, dateUpdated, permissions, uri); + return Objects.hash( + accountSid, + connectAppCompanyName, + connectAppDescription, + connectAppFriendlyName, + connectAppHomepageUrl, + connectAppSid, + dateCreated, + dateUpdated, + permissions, + uri + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/AuthorizedConnectAppFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/AuthorizedConnectAppFetcher.java index 52cab1ba2c..ceec991d0c 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/AuthorizedConnectAppFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/AuthorizedConnectAppFetcher.java @@ -24,29 +24,42 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class AuthorizedConnectAppFetcher extends Fetcher { + private String pathConnectAppSid; private String pathAccountSid; - public AuthorizedConnectAppFetcher(final String pathConnectAppSid){ + public AuthorizedConnectAppFetcher(final String pathConnectAppSid) { this.pathConnectAppSid = pathConnectAppSid; } - public AuthorizedConnectAppFetcher(final String pathAccountSid, final String pathConnectAppSid){ + + public AuthorizedConnectAppFetcher( + final String pathAccountSid, + final String pathConnectAppSid + ) { this.pathAccountSid = pathAccountSid; this.pathConnectAppSid = pathConnectAppSid; } - @Override public AuthorizedConnectApp fetch(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/AuthorizedConnectApps/{ConnectAppSid}.json"; + String path = + "/2010-04-01/Accounts/{AccountSid}/AuthorizedConnectApps/{ConnectAppSid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"ConnectAppSid"+"}", this.pathConnectAppSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "ConnectAppSid" + "}", + this.pathConnectAppSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -56,15 +69,23 @@ public AuthorizedConnectApp fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AuthorizedConnectApp fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "AuthorizedConnectApp fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return AuthorizedConnectApp.fromJson(response.getStream(), client.getObjectMapper()); + return AuthorizedConnectApp.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/AuthorizedConnectAppReader.java b/src/main/java/com/twilio/rest/api/v2010/account/AuthorizedConnectAppReader.java index 8a9689a949..f8b59cd029 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/AuthorizedConnectAppReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/AuthorizedConnectAppReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.api.v2010.account; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,34 +25,42 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class AuthorizedConnectAppReader extends Reader { + private String pathAccountSid; private Integer pageSize; - public AuthorizedConnectAppReader(){ - } - public AuthorizedConnectAppReader(final String pathAccountSid){ + public AuthorizedConnectAppReader() {} + + public AuthorizedConnectAppReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - public AuthorizedConnectAppReader setPageSize(final Integer pageSize){ + public AuthorizedConnectAppReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @Override - public ResourceSet read(final TwilioRestClient client) { + public ResourceSet read( + final TwilioRestClient client + ) { return new ResourceSet<>(this, client, firstPage(client)); } public Page firstPage(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/AuthorizedConnectApps.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); + String path = + "/2010-04-01/Accounts/{AccountSid}/AuthorizedConnectApps.json"; + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -63,13 +72,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AuthorizedConnectApp read failed: Unable to connect to server"); + throw new ApiConnectionException( + "AuthorizedConnectApp read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -85,7 +102,10 @@ private Page pageForRequest(final TwilioRestClient client, } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.API.toString()) @@ -93,9 +113,11 @@ public Page previousPage(final Page return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.API.toString()) @@ -104,21 +126,21 @@ public Page nextPage(final Page page } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/AvailablePhoneNumberCountry.java b/src/main/java/com/twilio/rest/api/v2010/account/AvailablePhoneNumberCountry.java index a00fa4be8b..87a578c8f0 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/AvailablePhoneNumberCountry.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/AvailablePhoneNumberCountry.java @@ -22,51 +22,65 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class AvailablePhoneNumberCountry extends Resource { + private static final long serialVersionUID = 173167903952303L; - public static AvailablePhoneNumberCountryFetcher fetcher(final String pathCountryCode){ + public static AvailablePhoneNumberCountryFetcher fetcher( + final String pathCountryCode + ) { return new AvailablePhoneNumberCountryFetcher(pathCountryCode); } - public static AvailablePhoneNumberCountryFetcher fetcher(final String pathAccountSid, final String pathCountryCode){ - return new AvailablePhoneNumberCountryFetcher(pathAccountSid, pathCountryCode); + + public static AvailablePhoneNumberCountryFetcher fetcher( + final String pathAccountSid, + final String pathCountryCode + ) { + return new AvailablePhoneNumberCountryFetcher( + pathAccountSid, + pathCountryCode + ); } - public static AvailablePhoneNumberCountryReader reader(){ + public static AvailablePhoneNumberCountryReader reader() { return new AvailablePhoneNumberCountryReader(); } - public static AvailablePhoneNumberCountryReader reader(final String pathAccountSid){ + + public static AvailablePhoneNumberCountryReader reader( + final String pathAccountSid + ) { return new AvailablePhoneNumberCountryReader(pathAccountSid); } /** - * Converts a JSON String into a AvailablePhoneNumberCountry object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return AvailablePhoneNumberCountry object represented by the provided JSON - */ - public static AvailablePhoneNumberCountry fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a AvailablePhoneNumberCountry object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return AvailablePhoneNumberCountry object represented by the provided JSON + */ + public static AvailablePhoneNumberCountry fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, AvailablePhoneNumberCountry.class); + return objectMapper.readValue( + json, + AvailablePhoneNumberCountry.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -75,17 +89,23 @@ public static AvailablePhoneNumberCountry fromJson(final String json, final Obje } /** - * Converts a JSON InputStream into a AvailablePhoneNumberCountry object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return AvailablePhoneNumberCountry object represented by the provided JSON - */ - public static AvailablePhoneNumberCountry fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a AvailablePhoneNumberCountry object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return AvailablePhoneNumberCountry object represented by the provided JSON + */ + public static AvailablePhoneNumberCountry fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, AvailablePhoneNumberCountry.class); + return objectMapper.readValue( + json, + AvailablePhoneNumberCountry.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -101,20 +121,13 @@ public static AvailablePhoneNumberCountry fromJson(final InputStream json, final @JsonCreator private AvailablePhoneNumberCountry( - @JsonProperty("country_code") - final String countryCode, - - @JsonProperty("country") - final String country, - - @JsonProperty("uri") - final URI uri, - - @JsonProperty("beta") - final Boolean beta, - - @JsonProperty("subresource_uris") - final Map subresourceUris + @JsonProperty("country_code") final String countryCode, + @JsonProperty("country") final String country, + @JsonProperty("uri") final URI uri, + @JsonProperty("beta") final Boolean beta, + @JsonProperty( + "subresource_uris" + ) final Map subresourceUris ) { this.countryCode = countryCode; this.country = country; @@ -123,25 +136,29 @@ private AvailablePhoneNumberCountry( this.subresourceUris = subresourceUris; } - public final String getCountryCode() { - return this.countryCode; - } - public final String getCountry() { - return this.country; - } - public final URI getUri() { - return this.uri; - } - public final Boolean getBeta() { - return this.beta; - } - public final Map getSubresourceUris() { - return this.subresourceUris; - } + public final String getCountryCode() { + return this.countryCode; + } + + public final String getCountry() { + return this.country; + } + + public final URI getUri() { + return this.uri; + } + + public final Boolean getBeta() { + return this.beta; + } + + public final Map getSubresourceUris() { + return this.subresourceUris; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -151,13 +168,17 @@ public boolean equals(final Object o) { AvailablePhoneNumberCountry other = (AvailablePhoneNumberCountry) o; - return Objects.equals(countryCode, other.countryCode) && Objects.equals(country, other.country) && Objects.equals(uri, other.uri) && Objects.equals(beta, other.beta) && Objects.equals(subresourceUris, other.subresourceUris) ; + return ( + Objects.equals(countryCode, other.countryCode) && + Objects.equals(country, other.country) && + Objects.equals(uri, other.uri) && + Objects.equals(beta, other.beta) && + Objects.equals(subresourceUris, other.subresourceUris) + ); } @Override public int hashCode() { return Objects.hash(countryCode, country, uri, beta, subresourceUris); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/AvailablePhoneNumberCountryFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/AvailablePhoneNumberCountryFetcher.java index 174a722f63..bad45393ae 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/AvailablePhoneNumberCountryFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/AvailablePhoneNumberCountryFetcher.java @@ -24,29 +24,43 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class AvailablePhoneNumberCountryFetcher + extends Fetcher { - - -public class AvailablePhoneNumberCountryFetcher extends Fetcher { private String pathCountryCode; private String pathAccountSid; - public AvailablePhoneNumberCountryFetcher(final String pathCountryCode){ + public AvailablePhoneNumberCountryFetcher(final String pathCountryCode) { this.pathCountryCode = pathCountryCode; } - public AvailablePhoneNumberCountryFetcher(final String pathAccountSid, final String pathCountryCode){ + + public AvailablePhoneNumberCountryFetcher( + final String pathAccountSid, + final String pathCountryCode + ) { this.pathAccountSid = pathAccountSid; this.pathCountryCode = pathCountryCode; } - @Override public AvailablePhoneNumberCountry fetch(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/AvailablePhoneNumbers/{CountryCode}.json"; + String path = + "/2010-04-01/Accounts/{AccountSid}/AvailablePhoneNumbers/{CountryCode}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"CountryCode"+"}", this.pathCountryCode.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "CountryCode" + "}", + this.pathCountryCode.toString() + ); Request request = new Request( HttpMethod.GET, @@ -56,15 +70,23 @@ public AvailablePhoneNumberCountry fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AvailablePhoneNumberCountry fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "AvailablePhoneNumberCountry fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return AvailablePhoneNumberCountry.fromJson(response.getStream(), client.getObjectMapper()); + return AvailablePhoneNumberCountry.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/AvailablePhoneNumberCountryReader.java b/src/main/java/com/twilio/rest/api/v2010/account/AvailablePhoneNumberCountryReader.java index 35ca49e4fd..48d6c41fae 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/AvailablePhoneNumberCountryReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/AvailablePhoneNumberCountryReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.api.v2010.account; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,34 +25,47 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - +public class AvailablePhoneNumberCountryReader + extends Reader { -public class AvailablePhoneNumberCountryReader extends Reader { private String pathAccountSid; private Integer pageSize; - public AvailablePhoneNumberCountryReader(){ - } - public AvailablePhoneNumberCountryReader(final String pathAccountSid){ + public AvailablePhoneNumberCountryReader() {} + + public AvailablePhoneNumberCountryReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - public AvailablePhoneNumberCountryReader setPageSize(final Integer pageSize){ + public AvailablePhoneNumberCountryReader setPageSize( + final Integer pageSize + ) { this.pageSize = pageSize; return this; } @Override - public ResourceSet read(final TwilioRestClient client) { + public ResourceSet read( + final TwilioRestClient client + ) { return new ResourceSet<>(this, client, firstPage(client)); } - public Page firstPage(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/AvailablePhoneNumbers.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); + public Page firstPage( + final TwilioRestClient client + ) { + String path = + "/2010-04-01/Accounts/{AccountSid}/AvailablePhoneNumbers.json"; + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -63,13 +77,21 @@ public Page firstPage(final TwilioRestClient client return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AvailablePhoneNumberCountry read failed: Unable to connect to server"); + throw new ApiConnectionException( + "AvailablePhoneNumberCountry read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -85,7 +107,10 @@ private Page pageForRequest(final TwilioRestClient } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.API.toString()) @@ -93,9 +118,11 @@ public Page previousPage(final Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.API.toString()) @@ -104,21 +131,21 @@ public Page nextPage(final Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/Balance.java b/src/main/java/com/twilio/rest/api/v2010/account/Balance.java index 6c39004801..5fb120031a 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/Balance.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/Balance.java @@ -22,38 +22,38 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Balance extends Resource { + private static final long serialVersionUID = 101388429668677L; - public static BalanceFetcher fetcher(){ + public static BalanceFetcher fetcher() { return new BalanceFetcher(); } - public static BalanceFetcher fetcher(final String pathAccountSid){ + + public static BalanceFetcher fetcher(final String pathAccountSid) { return new BalanceFetcher(pathAccountSid); } /** - * Converts a JSON String into a Balance object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Balance object represented by the provided JSON - */ - public static Balance fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Balance object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Balance object represented by the provided JSON + */ + public static Balance fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Balance.class); @@ -65,14 +65,17 @@ public static Balance fromJson(final String json, final ObjectMapper objectMappe } /** - * Converts a JSON InputStream into a Balance object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Balance object represented by the provided JSON - */ - public static Balance fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Balance object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Balance object represented by the provided JSON + */ + public static Balance fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Balance.class); @@ -89,33 +92,30 @@ public static Balance fromJson(final InputStream json, final ObjectMapper object @JsonCreator private Balance( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("balance") - final String balance, - - @JsonProperty("currency") - final String currency + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("balance") final String balance, + @JsonProperty("currency") final String currency ) { this.accountSid = accountSid; this.balance = balance; this.currency = currency; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getBalance() { - return this.balance; - } - public final String getCurrency() { - return this.currency; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getBalance() { + return this.balance; + } + + public final String getCurrency() { + return this.currency; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -125,13 +125,15 @@ public boolean equals(final Object o) { Balance other = (Balance) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(balance, other.balance) && Objects.equals(currency, other.currency) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(balance, other.balance) && + Objects.equals(currency, other.currency) + ); } @Override public int hashCode() { return Objects.hash(accountSid, balance, currency); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/BalanceFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/BalanceFetcher.java index 5bda0ea981..b5f87c80ec 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/BalanceFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/BalanceFetcher.java @@ -24,25 +24,29 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class BalanceFetcher extends Fetcher { + private String pathAccountSid; - public BalanceFetcher(){ - } - public BalanceFetcher(final String pathAccountSid){ + public BalanceFetcher() {} + + public BalanceFetcher(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - @Override public Balance fetch(final TwilioRestClient client) { String path = "/2010-04-01/Accounts/{AccountSid}/Balance.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -52,9 +56,14 @@ public Balance fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Balance fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Balance fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/Call.java b/src/main/java/com/twilio/rest/api/v2010/account/Call.java index 69ebce2825..b243168853 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/Call.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/Call.java @@ -20,89 +20,133 @@ import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.twilio.base.Resource; -import java.util.Currency; +import com.twilio.converter.CurrencyDeserializer; import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; -import com.twilio.converter.CurrencyDeserializer; import com.twilio.exception.ApiConnectionException; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - +import java.util.Currency; import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Call extends Resource { + private static final long serialVersionUID = 229062317637234L; - public static CallCreator creator(final com.twilio.type.Endpoint to, final com.twilio.type.Endpoint from, final URI url){ + public static CallCreator creator( + final com.twilio.type.Endpoint to, + final com.twilio.type.Endpoint from, + final URI url + ) { return new CallCreator(to, from, url); } - public static CallCreator creator(final String pathAccountSid, final com.twilio.type.Endpoint to, final com.twilio.type.Endpoint from, final URI url){ + + public static CallCreator creator( + final String pathAccountSid, + final com.twilio.type.Endpoint to, + final com.twilio.type.Endpoint from, + final URI url + ) { return new CallCreator(pathAccountSid, to, from, url); } - public static CallCreator creator(final com.twilio.type.Endpoint to, final com.twilio.type.Endpoint from, final com.twilio.type.Twiml twiml){ + + public static CallCreator creator( + final com.twilio.type.Endpoint to, + final com.twilio.type.Endpoint from, + final com.twilio.type.Twiml twiml + ) { return new CallCreator(to, from, twiml); } - public static CallCreator creator(final String pathAccountSid, final com.twilio.type.Endpoint to, final com.twilio.type.Endpoint from, final com.twilio.type.Twiml twiml){ + + public static CallCreator creator( + final String pathAccountSid, + final com.twilio.type.Endpoint to, + final com.twilio.type.Endpoint from, + final com.twilio.type.Twiml twiml + ) { return new CallCreator(pathAccountSid, to, from, twiml); } - public static CallCreator creator(final com.twilio.type.Endpoint to, final com.twilio.type.Endpoint from, final String applicationSid){ + + public static CallCreator creator( + final com.twilio.type.Endpoint to, + final com.twilio.type.Endpoint from, + final String applicationSid + ) { return new CallCreator(to, from, applicationSid); } - public static CallCreator creator(final String pathAccountSid, final com.twilio.type.Endpoint to, final com.twilio.type.Endpoint from, final String applicationSid){ + + public static CallCreator creator( + final String pathAccountSid, + final com.twilio.type.Endpoint to, + final com.twilio.type.Endpoint from, + final String applicationSid + ) { return new CallCreator(pathAccountSid, to, from, applicationSid); } - public static CallDeleter deleter(final String pathSid){ + public static CallDeleter deleter(final String pathSid) { return new CallDeleter(pathSid); } - public static CallDeleter deleter(final String pathAccountSid, final String pathSid){ + + public static CallDeleter deleter( + final String pathAccountSid, + final String pathSid + ) { return new CallDeleter(pathAccountSid, pathSid); } - public static CallFetcher fetcher(final String pathSid){ + public static CallFetcher fetcher(final String pathSid) { return new CallFetcher(pathSid); } - public static CallFetcher fetcher(final String pathAccountSid, final String pathSid){ + + public static CallFetcher fetcher( + final String pathAccountSid, + final String pathSid + ) { return new CallFetcher(pathAccountSid, pathSid); } - public static CallReader reader(){ + public static CallReader reader() { return new CallReader(); } - public static CallReader reader(final String pathAccountSid){ + + public static CallReader reader(final String pathAccountSid) { return new CallReader(pathAccountSid); } - public static CallUpdater updater(final String pathSid){ + public static CallUpdater updater(final String pathSid) { return new CallUpdater(pathSid); } - public static CallUpdater updater(final String pathAccountSid, final String pathSid){ + + public static CallUpdater updater( + final String pathAccountSid, + final String pathSid + ) { return new CallUpdater(pathAccountSid, pathSid); } /** - * Converts a JSON String into a Call object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Call object represented by the provided JSON - */ - public static Call fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Call object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Call object represented by the provided JSON + */ + public static Call fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Call.class); @@ -114,14 +158,17 @@ public static Call fromJson(final String json, final ObjectMapper objectMapper) } /** - * Converts a JSON InputStream into a Call object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Call object represented by the provided JSON - */ - public static Call fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Call object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Call object represented by the provided JSON + */ + public static Call fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Call.class); @@ -131,6 +178,7 @@ public static Call fromJson(final InputStream json, final ObjectMapper objectMap throw new ApiConnectionException(e.getMessage(), e); } } + public enum Status { QUEUED("queued"), RINGING("ringing"), @@ -156,6 +204,7 @@ public static Status forValue(final String value) { return Promoter.enumFromString(value, Status.values()); } } + public enum UpdateStatus { CANCELED("canceled"), COMPLETED("completed"); @@ -205,84 +254,36 @@ public static UpdateStatus forValue(final String value) { @JsonCreator private Call( - @JsonProperty("sid") - final String sid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("parent_call_sid") - final String parentCallSid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("to") - final String to, - - @JsonProperty("to_formatted") - final String toFormatted, - - @JsonProperty("from") - final String from, - - @JsonProperty("from_formatted") - final String fromFormatted, - - @JsonProperty("phone_number_sid") - final String phoneNumberSid, - - @JsonProperty("status") - final Call.Status status, - - @JsonProperty("start_time") - final String startTime, - - @JsonProperty("end_time") - final String endTime, - - @JsonProperty("duration") - final String duration, - - @JsonProperty("price") - final String price, - - @JsonProperty("price_unit") - @JsonDeserialize(using = com.twilio.converter.CurrencyDeserializer.class) - final Currency priceUnit, - - @JsonProperty("direction") - final String direction, - - @JsonProperty("answered_by") - final String answeredBy, - - @JsonProperty("api_version") - final String apiVersion, - - @JsonProperty("forwarded_from") - final String forwardedFrom, - - @JsonProperty("group_sid") - final String groupSid, - - @JsonProperty("caller_name") - final String callerName, - - @JsonProperty("queue_time") - final String queueTime, - - @JsonProperty("trunk_sid") - final String trunkSid, - - @JsonProperty("uri") - final String uri, - - @JsonProperty("subresource_uris") - final Map subresourceUris + @JsonProperty("sid") final String sid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("parent_call_sid") final String parentCallSid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("to") final String to, + @JsonProperty("to_formatted") final String toFormatted, + @JsonProperty("from") final String from, + @JsonProperty("from_formatted") final String fromFormatted, + @JsonProperty("phone_number_sid") final String phoneNumberSid, + @JsonProperty("status") final Call.Status status, + @JsonProperty("start_time") final String startTime, + @JsonProperty("end_time") final String endTime, + @JsonProperty("duration") final String duration, + @JsonProperty("price") final String price, + @JsonProperty("price_unit") @JsonDeserialize( + using = com.twilio.converter.CurrencyDeserializer.class + ) final Currency priceUnit, + @JsonProperty("direction") final String direction, + @JsonProperty("answered_by") final String answeredBy, + @JsonProperty("api_version") final String apiVersion, + @JsonProperty("forwarded_from") final String forwardedFrom, + @JsonProperty("group_sid") final String groupSid, + @JsonProperty("caller_name") final String callerName, + @JsonProperty("queue_time") final String queueTime, + @JsonProperty("trunk_sid") final String trunkSid, + @JsonProperty("uri") final String uri, + @JsonProperty( + "subresource_uris" + ) final Map subresourceUris ) { this.sid = sid; this.dateCreated = DateConverter.rfc2822DateTimeFromString(dateCreated); @@ -312,88 +313,113 @@ private Call( this.subresourceUris = subresourceUris; } - public final String getSid() { - return this.sid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getParentCallSid() { - return this.parentCallSid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getTo() { - return this.to; - } - public final String getToFormatted() { - return this.toFormatted; - } - public final String getFrom() { - return this.from; - } - public final String getFromFormatted() { - return this.fromFormatted; - } - public final String getPhoneNumberSid() { - return this.phoneNumberSid; - } - public final Call.Status getStatus() { - return this.status; - } - public final ZonedDateTime getStartTime() { - return this.startTime; - } - public final ZonedDateTime getEndTime() { - return this.endTime; - } - public final String getDuration() { - return this.duration; - } - public final String getPrice() { - return this.price; - } - public final Currency getPriceUnit() { - return this.priceUnit; - } - public final String getDirection() { - return this.direction; - } - public final String getAnsweredBy() { - return this.answeredBy; - } - public final String getApiVersion() { - return this.apiVersion; - } - public final String getForwardedFrom() { - return this.forwardedFrom; - } - public final String getGroupSid() { - return this.groupSid; - } - public final String getCallerName() { - return this.callerName; - } - public final String getQueueTime() { - return this.queueTime; - } - public final String getTrunkSid() { - return this.trunkSid; - } - public final String getUri() { - return this.uri; - } - public final Map getSubresourceUris() { - return this.subresourceUris; - } + public final String getSid() { + return this.sid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getParentCallSid() { + return this.parentCallSid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getTo() { + return this.to; + } + + public final String getToFormatted() { + return this.toFormatted; + } + + public final String getFrom() { + return this.from; + } + + public final String getFromFormatted() { + return this.fromFormatted; + } + + public final String getPhoneNumberSid() { + return this.phoneNumberSid; + } + + public final Call.Status getStatus() { + return this.status; + } + + public final ZonedDateTime getStartTime() { + return this.startTime; + } + + public final ZonedDateTime getEndTime() { + return this.endTime; + } + + public final String getDuration() { + return this.duration; + } + + public final String getPrice() { + return this.price; + } + + public final Currency getPriceUnit() { + return this.priceUnit; + } + + public final String getDirection() { + return this.direction; + } + + public final String getAnsweredBy() { + return this.answeredBy; + } + + public final String getApiVersion() { + return this.apiVersion; + } + + public final String getForwardedFrom() { + return this.forwardedFrom; + } + + public final String getGroupSid() { + return this.groupSid; + } + + public final String getCallerName() { + return this.callerName; + } + + public final String getQueueTime() { + return this.queueTime; + } + + public final String getTrunkSid() { + return this.trunkSid; + } + + public final String getUri() { + return this.uri; + } + + public final Map getSubresourceUris() { + return this.subresourceUris; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -403,13 +429,65 @@ public boolean equals(final Object o) { Call other = (Call) o; - return Objects.equals(sid, other.sid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(parentCallSid, other.parentCallSid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(to, other.to) && Objects.equals(toFormatted, other.toFormatted) && Objects.equals(from, other.from) && Objects.equals(fromFormatted, other.fromFormatted) && Objects.equals(phoneNumberSid, other.phoneNumberSid) && Objects.equals(status, other.status) && Objects.equals(startTime, other.startTime) && Objects.equals(endTime, other.endTime) && Objects.equals(duration, other.duration) && Objects.equals(price, other.price) && Objects.equals(priceUnit, other.priceUnit) && Objects.equals(direction, other.direction) && Objects.equals(answeredBy, other.answeredBy) && Objects.equals(apiVersion, other.apiVersion) && Objects.equals(forwardedFrom, other.forwardedFrom) && Objects.equals(groupSid, other.groupSid) && Objects.equals(callerName, other.callerName) && Objects.equals(queueTime, other.queueTime) && Objects.equals(trunkSid, other.trunkSid) && Objects.equals(uri, other.uri) && Objects.equals(subresourceUris, other.subresourceUris) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(parentCallSid, other.parentCallSid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(to, other.to) && + Objects.equals(toFormatted, other.toFormatted) && + Objects.equals(from, other.from) && + Objects.equals(fromFormatted, other.fromFormatted) && + Objects.equals(phoneNumberSid, other.phoneNumberSid) && + Objects.equals(status, other.status) && + Objects.equals(startTime, other.startTime) && + Objects.equals(endTime, other.endTime) && + Objects.equals(duration, other.duration) && + Objects.equals(price, other.price) && + Objects.equals(priceUnit, other.priceUnit) && + Objects.equals(direction, other.direction) && + Objects.equals(answeredBy, other.answeredBy) && + Objects.equals(apiVersion, other.apiVersion) && + Objects.equals(forwardedFrom, other.forwardedFrom) && + Objects.equals(groupSid, other.groupSid) && + Objects.equals(callerName, other.callerName) && + Objects.equals(queueTime, other.queueTime) && + Objects.equals(trunkSid, other.trunkSid) && + Objects.equals(uri, other.uri) && + Objects.equals(subresourceUris, other.subresourceUris) + ); } @Override public int hashCode() { - return Objects.hash(sid, dateCreated, dateUpdated, parentCallSid, accountSid, to, toFormatted, from, fromFormatted, phoneNumberSid, status, startTime, endTime, duration, price, priceUnit, direction, answeredBy, apiVersion, forwardedFrom, groupSid, callerName, queueTime, trunkSid, uri, subresourceUris); + return Objects.hash( + sid, + dateCreated, + dateUpdated, + parentCallSid, + accountSid, + to, + toFormatted, + from, + fromFormatted, + phoneNumberSid, + status, + startTime, + endTime, + duration, + price, + priceUnit, + direction, + answeredBy, + apiVersion, + forwardedFrom, + groupSid, + callerName, + queueTime, + trunkSid, + uri, + subresourceUris + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/CallCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/CallCreator.java index 555c8b58fa..960c0abf50 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/CallCreator.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/CallCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010.account; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -24,15 +25,13 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import java.util.List; import java.net.URI; - +import java.net.URI; +import java.util.List; import java.util.List; +public class CallCreator extends Creator { -import java.net.URI; - -public class CallCreator extends Creator{ private com.twilio.type.Endpoint to; private com.twilio.type.Endpoint from; private String pathAccountSid; @@ -70,227 +69,341 @@ public class CallCreator extends Creator{ private com.twilio.type.Twiml twiml; private String applicationSid; - public CallCreator(final com.twilio.type.Endpoint to, final com.twilio.type.Endpoint from, final URI url) { + public CallCreator( + final com.twilio.type.Endpoint to, + final com.twilio.type.Endpoint from, + final URI url + ) { this.to = to; this.from = from; this.url = url; } - public CallCreator(final String pathAccountSid, final com.twilio.type.Endpoint to, final com.twilio.type.Endpoint from, final URI url) { + + public CallCreator( + final String pathAccountSid, + final com.twilio.type.Endpoint to, + final com.twilio.type.Endpoint from, + final URI url + ) { this.pathAccountSid = pathAccountSid; this.to = to; this.from = from; this.url = url; } - public CallCreator(final com.twilio.type.Endpoint to, final com.twilio.type.Endpoint from, final com.twilio.type.Twiml twiml) { + + public CallCreator( + final com.twilio.type.Endpoint to, + final com.twilio.type.Endpoint from, + final com.twilio.type.Twiml twiml + ) { this.to = to; this.from = from; this.twiml = twiml; } - public CallCreator(final String pathAccountSid, final com.twilio.type.Endpoint to, final com.twilio.type.Endpoint from, final com.twilio.type.Twiml twiml) { + + public CallCreator( + final String pathAccountSid, + final com.twilio.type.Endpoint to, + final com.twilio.type.Endpoint from, + final com.twilio.type.Twiml twiml + ) { this.pathAccountSid = pathAccountSid; this.to = to; this.from = from; this.twiml = twiml; } - public CallCreator(final com.twilio.type.Endpoint to, final com.twilio.type.Endpoint from, final String applicationSid) { + + public CallCreator( + final com.twilio.type.Endpoint to, + final com.twilio.type.Endpoint from, + final String applicationSid + ) { this.to = to; this.from = from; this.applicationSid = applicationSid; } - public CallCreator(final String pathAccountSid, final com.twilio.type.Endpoint to, final com.twilio.type.Endpoint from, final String applicationSid) { + + public CallCreator( + final String pathAccountSid, + final com.twilio.type.Endpoint to, + final com.twilio.type.Endpoint from, + final String applicationSid + ) { this.pathAccountSid = pathAccountSid; this.to = to; this.from = from; this.applicationSid = applicationSid; } - public CallCreator setTo(final com.twilio.type.Endpoint to){ + public CallCreator setTo(final com.twilio.type.Endpoint to) { this.to = to; return this; } - public CallCreator setFrom(final com.twilio.type.Endpoint from){ + + public CallCreator setFrom(final com.twilio.type.Endpoint from) { this.from = from; return this; } - public CallCreator setMethod(final HttpMethod method){ + + public CallCreator setMethod(final HttpMethod method) { this.method = method; return this; } - public CallCreator setFallbackUrl(final URI fallbackUrl){ + + public CallCreator setFallbackUrl(final URI fallbackUrl) { this.fallbackUrl = fallbackUrl; return this; } - public CallCreator setFallbackUrl(final String fallbackUrl){ + public CallCreator setFallbackUrl(final String fallbackUrl) { return setFallbackUrl(Promoter.uriFromString(fallbackUrl)); } - public CallCreator setFallbackMethod(final HttpMethod fallbackMethod){ + + public CallCreator setFallbackMethod(final HttpMethod fallbackMethod) { this.fallbackMethod = fallbackMethod; return this; } - public CallCreator setStatusCallback(final URI statusCallback){ + + public CallCreator setStatusCallback(final URI statusCallback) { this.statusCallback = statusCallback; return this; } - public CallCreator setStatusCallback(final String statusCallback){ + public CallCreator setStatusCallback(final String statusCallback) { return setStatusCallback(Promoter.uriFromString(statusCallback)); } - public CallCreator setStatusCallbackEvent(final List statusCallbackEvent){ + + public CallCreator setStatusCallbackEvent( + final List statusCallbackEvent + ) { this.statusCallbackEvent = statusCallbackEvent; return this; } - public CallCreator setStatusCallbackEvent(final String statusCallbackEvent){ + + public CallCreator setStatusCallbackEvent( + final String statusCallbackEvent + ) { return setStatusCallbackEvent(Promoter.listOfOne(statusCallbackEvent)); } - public CallCreator setStatusCallbackMethod(final HttpMethod statusCallbackMethod){ + + public CallCreator setStatusCallbackMethod( + final HttpMethod statusCallbackMethod + ) { this.statusCallbackMethod = statusCallbackMethod; return this; } - public CallCreator setSendDigits(final String sendDigits){ + + public CallCreator setSendDigits(final String sendDigits) { this.sendDigits = sendDigits; return this; } - public CallCreator setTimeout(final Integer timeout){ + + public CallCreator setTimeout(final Integer timeout) { this.timeout = timeout; return this; } - public CallCreator setRecord(final Boolean record){ + + public CallCreator setRecord(final Boolean record) { this.record = record; return this; } - public CallCreator setRecordingChannels(final String recordingChannels){ + + public CallCreator setRecordingChannels(final String recordingChannels) { this.recordingChannels = recordingChannels; return this; } - public CallCreator setRecordingStatusCallback(final String recordingStatusCallback){ + + public CallCreator setRecordingStatusCallback( + final String recordingStatusCallback + ) { this.recordingStatusCallback = recordingStatusCallback; return this; } - public CallCreator setRecordingStatusCallbackMethod(final HttpMethod recordingStatusCallbackMethod){ + + public CallCreator setRecordingStatusCallbackMethod( + final HttpMethod recordingStatusCallbackMethod + ) { this.recordingStatusCallbackMethod = recordingStatusCallbackMethod; return this; } - public CallCreator setSipAuthUsername(final String sipAuthUsername){ + + public CallCreator setSipAuthUsername(final String sipAuthUsername) { this.sipAuthUsername = sipAuthUsername; return this; } - public CallCreator setSipAuthPassword(final String sipAuthPassword){ + + public CallCreator setSipAuthPassword(final String sipAuthPassword) { this.sipAuthPassword = sipAuthPassword; return this; } - public CallCreator setMachineDetection(final String machineDetection){ + + public CallCreator setMachineDetection(final String machineDetection) { this.machineDetection = machineDetection; return this; } - public CallCreator setMachineDetectionTimeout(final Integer machineDetectionTimeout){ + + public CallCreator setMachineDetectionTimeout( + final Integer machineDetectionTimeout + ) { this.machineDetectionTimeout = machineDetectionTimeout; return this; } - public CallCreator setRecordingStatusCallbackEvent(final List recordingStatusCallbackEvent){ + + public CallCreator setRecordingStatusCallbackEvent( + final List recordingStatusCallbackEvent + ) { this.recordingStatusCallbackEvent = recordingStatusCallbackEvent; return this; } - public CallCreator setRecordingStatusCallbackEvent(final String recordingStatusCallbackEvent){ - return setRecordingStatusCallbackEvent(Promoter.listOfOne(recordingStatusCallbackEvent)); + + public CallCreator setRecordingStatusCallbackEvent( + final String recordingStatusCallbackEvent + ) { + return setRecordingStatusCallbackEvent( + Promoter.listOfOne(recordingStatusCallbackEvent) + ); } - public CallCreator setTrim(final String trim){ + + public CallCreator setTrim(final String trim) { this.trim = trim; return this; } - public CallCreator setCallerId(final String callerId){ + + public CallCreator setCallerId(final String callerId) { this.callerId = callerId; return this; } - public CallCreator setMachineDetectionSpeechThreshold(final Integer machineDetectionSpeechThreshold){ + + public CallCreator setMachineDetectionSpeechThreshold( + final Integer machineDetectionSpeechThreshold + ) { this.machineDetectionSpeechThreshold = machineDetectionSpeechThreshold; return this; } - public CallCreator setMachineDetectionSpeechEndThreshold(final Integer machineDetectionSpeechEndThreshold){ - this.machineDetectionSpeechEndThreshold = machineDetectionSpeechEndThreshold; + + public CallCreator setMachineDetectionSpeechEndThreshold( + final Integer machineDetectionSpeechEndThreshold + ) { + this.machineDetectionSpeechEndThreshold = + machineDetectionSpeechEndThreshold; return this; } - public CallCreator setMachineDetectionSilenceTimeout(final Integer machineDetectionSilenceTimeout){ + + public CallCreator setMachineDetectionSilenceTimeout( + final Integer machineDetectionSilenceTimeout + ) { this.machineDetectionSilenceTimeout = machineDetectionSilenceTimeout; return this; } - public CallCreator setAsyncAmd(final String asyncAmd){ + + public CallCreator setAsyncAmd(final String asyncAmd) { this.asyncAmd = asyncAmd; return this; } - public CallCreator setAsyncAmdStatusCallback(final URI asyncAmdStatusCallback){ + + public CallCreator setAsyncAmdStatusCallback( + final URI asyncAmdStatusCallback + ) { this.asyncAmdStatusCallback = asyncAmdStatusCallback; return this; } - public CallCreator setAsyncAmdStatusCallback(final String asyncAmdStatusCallback){ - return setAsyncAmdStatusCallback(Promoter.uriFromString(asyncAmdStatusCallback)); + public CallCreator setAsyncAmdStatusCallback( + final String asyncAmdStatusCallback + ) { + return setAsyncAmdStatusCallback( + Promoter.uriFromString(asyncAmdStatusCallback) + ); } - public CallCreator setAsyncAmdStatusCallbackMethod(final HttpMethod asyncAmdStatusCallbackMethod){ + + public CallCreator setAsyncAmdStatusCallbackMethod( + final HttpMethod asyncAmdStatusCallbackMethod + ) { this.asyncAmdStatusCallbackMethod = asyncAmdStatusCallbackMethod; return this; } - public CallCreator setByoc(final String byoc){ + + public CallCreator setByoc(final String byoc) { this.byoc = byoc; return this; } - public CallCreator setCallReason(final String callReason){ + + public CallCreator setCallReason(final String callReason) { this.callReason = callReason; return this; } - public CallCreator setCallToken(final String callToken){ + + public CallCreator setCallToken(final String callToken) { this.callToken = callToken; return this; } - public CallCreator setRecordingTrack(final String recordingTrack){ + + public CallCreator setRecordingTrack(final String recordingTrack) { this.recordingTrack = recordingTrack; return this; } - public CallCreator setTimeLimit(final Integer timeLimit){ + + public CallCreator setTimeLimit(final Integer timeLimit) { this.timeLimit = timeLimit; return this; } - public CallCreator setUrl(final URI url){ + + public CallCreator setUrl(final URI url) { this.url = url; return this; } - public CallCreator setUrl(final String url){ + public CallCreator setUrl(final String url) { return setUrl(Promoter.uriFromString(url)); } - public CallCreator setTwiml(final com.twilio.type.Twiml twiml){ + + public CallCreator setTwiml(final com.twilio.type.Twiml twiml) { this.twiml = twiml; return this; } - public CallCreator setTwiml(final String twiml){ + public CallCreator setTwiml(final String twiml) { return setTwiml(Promoter.twimlFromString(twiml)); } - public CallCreator setApplicationSid(final String applicationSid){ + + public CallCreator setApplicationSid(final String applicationSid) { this.applicationSid = applicationSid; return this; } @Override - public Call create(final TwilioRestClient client){ + public Call create(final TwilioRestClient client) { String path = "/2010-04-01/Accounts/{AccountSid}/Calls.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"To"+"}", this.to.toString()); - path = path.replace("{"+"From"+"}", this.from.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "To" + "}", this.to.toString()); + path = path.replace("{" + "From" + "}", this.from.toString()); Request request = new Request( HttpMethod.POST, Domains.API.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Call creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Call creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -299,150 +412,143 @@ public Call create(final TwilioRestClient client){ return Call.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (to != null) { request.addPostParam("To", to.toString()); - } if (from != null) { request.addPostParam("From", from.toString()); - } if (method != null) { request.addPostParam("Method", method.toString()); - } if (fallbackUrl != null) { request.addPostParam("FallbackUrl", fallbackUrl.toString()); - } if (fallbackMethod != null) { request.addPostParam("FallbackMethod", fallbackMethod.toString()); - } if (statusCallback != null) { request.addPostParam("StatusCallback", statusCallback.toString()); - } if (statusCallbackEvent != null) { for (String prop : statusCallbackEvent) { request.addPostParam("StatusCallbackEvent", prop); } - } if (statusCallbackMethod != null) { - request.addPostParam("StatusCallbackMethod", statusCallbackMethod.toString()); - + request.addPostParam( + "StatusCallbackMethod", + statusCallbackMethod.toString() + ); } if (sendDigits != null) { request.addPostParam("SendDigits", sendDigits); - } if (timeout != null) { request.addPostParam("Timeout", timeout.toString()); - } if (record != null) { request.addPostParam("Record", record.toString()); - } if (recordingChannels != null) { request.addPostParam("RecordingChannels", recordingChannels); - } if (recordingStatusCallback != null) { - request.addPostParam("RecordingStatusCallback", recordingStatusCallback); - + request.addPostParam( + "RecordingStatusCallback", + recordingStatusCallback + ); } if (recordingStatusCallbackMethod != null) { - request.addPostParam("RecordingStatusCallbackMethod", recordingStatusCallbackMethod.toString()); - + request.addPostParam( + "RecordingStatusCallbackMethod", + recordingStatusCallbackMethod.toString() + ); } if (sipAuthUsername != null) { request.addPostParam("SipAuthUsername", sipAuthUsername); - } if (sipAuthPassword != null) { request.addPostParam("SipAuthPassword", sipAuthPassword); - } if (machineDetection != null) { request.addPostParam("MachineDetection", machineDetection); - } if (machineDetectionTimeout != null) { - request.addPostParam("MachineDetectionTimeout", machineDetectionTimeout.toString()); - + request.addPostParam( + "MachineDetectionTimeout", + machineDetectionTimeout.toString() + ); } if (recordingStatusCallbackEvent != null) { for (String prop : recordingStatusCallbackEvent) { request.addPostParam("RecordingStatusCallbackEvent", prop); } - } if (trim != null) { request.addPostParam("Trim", trim); - } if (callerId != null) { request.addPostParam("CallerId", callerId); - } if (machineDetectionSpeechThreshold != null) { - request.addPostParam("MachineDetectionSpeechThreshold", machineDetectionSpeechThreshold.toString()); - + request.addPostParam( + "MachineDetectionSpeechThreshold", + machineDetectionSpeechThreshold.toString() + ); } if (machineDetectionSpeechEndThreshold != null) { - request.addPostParam("MachineDetectionSpeechEndThreshold", machineDetectionSpeechEndThreshold.toString()); - + request.addPostParam( + "MachineDetectionSpeechEndThreshold", + machineDetectionSpeechEndThreshold.toString() + ); } if (machineDetectionSilenceTimeout != null) { - request.addPostParam("MachineDetectionSilenceTimeout", machineDetectionSilenceTimeout.toString()); - + request.addPostParam( + "MachineDetectionSilenceTimeout", + machineDetectionSilenceTimeout.toString() + ); } if (asyncAmd != null) { request.addPostParam("AsyncAmd", asyncAmd); - } if (asyncAmdStatusCallback != null) { - request.addPostParam("AsyncAmdStatusCallback", asyncAmdStatusCallback.toString()); - + request.addPostParam( + "AsyncAmdStatusCallback", + asyncAmdStatusCallback.toString() + ); } if (asyncAmdStatusCallbackMethod != null) { - request.addPostParam("AsyncAmdStatusCallbackMethod", asyncAmdStatusCallbackMethod.toString()); - + request.addPostParam( + "AsyncAmdStatusCallbackMethod", + asyncAmdStatusCallbackMethod.toString() + ); } if (byoc != null) { request.addPostParam("Byoc", byoc); - } if (callReason != null) { request.addPostParam("CallReason", callReason); - } if (callToken != null) { request.addPostParam("CallToken", callToken); - } if (recordingTrack != null) { request.addPostParam("RecordingTrack", recordingTrack); - } if (timeLimit != null) { request.addPostParam("TimeLimit", timeLimit.toString()); - } if (url != null) { request.addPostParam("Url", url.toString()); - } if (twiml != null) { request.addPostParam("Twiml", twiml.toString()); - } if (applicationSid != null) { request.addPostParam("ApplicationSid", applicationSid); - } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/CallDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/CallDeleter.java index f054872cec..e96d45ca2f 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/CallDeleter.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/CallDeleter.java @@ -24,28 +24,34 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class CallDeleter extends Deleter { + private String pathSid; private String pathAccountSid; - public CallDeleter(final String pathSid){ + public CallDeleter(final String pathSid) { this.pathSid = pathSid; } - public CallDeleter(final String pathAccountSid, final String pathSid){ + + public CallDeleter(final String pathAccountSid, final String pathSid) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/2010-04-01/Accounts/{AccountSid}/Calls/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -55,9 +61,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Call delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Call delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/CallFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/CallFetcher.java index 1e9c3b11a1..dd8aebe7da 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/CallFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/CallFetcher.java @@ -24,29 +24,34 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class CallFetcher extends Fetcher { + private String pathSid; private String pathAccountSid; - public CallFetcher(final String pathSid){ + public CallFetcher(final String pathSid) { this.pathSid = pathSid; } - public CallFetcher(final String pathAccountSid, final String pathSid){ + + public CallFetcher(final String pathAccountSid, final String pathSid) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - @Override public Call fetch(final TwilioRestClient client) { String path = "/2010-04-01/Accounts/{AccountSid}/Calls/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -56,9 +61,14 @@ public Call fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Call fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Call fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/CallReader.java b/src/main/java/com/twilio/rest/api/v2010/account/CallReader.java index 6be5efc9c8..25b0dea568 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/CallReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/CallReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.api.v2010.account; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.converter.Promoter; @@ -25,13 +26,11 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; - - public class CallReader extends Reader { + private String pathAccountSid; private com.twilio.type.PhoneNumber to; private com.twilio.type.PhoneNumber from; @@ -45,61 +44,71 @@ public class CallReader extends Reader { private ZonedDateTime endTimeAfter; private Integer pageSize; - public CallReader(){ - } - public CallReader(final String pathAccountSid){ + public CallReader() {} + + public CallReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - public CallReader setTo(final com.twilio.type.PhoneNumber to){ + public CallReader setTo(final com.twilio.type.PhoneNumber to) { this.to = to; return this; } - public CallReader setTo(final String to){ + public CallReader setTo(final String to) { return setTo(Promoter.phoneNumberFromString(to)); } - public CallReader setFrom(final com.twilio.type.PhoneNumber from){ + + public CallReader setFrom(final com.twilio.type.PhoneNumber from) { this.from = from; return this; } - public CallReader setFrom(final String from){ + public CallReader setFrom(final String from) { return setFrom(Promoter.phoneNumberFromString(from)); } - public CallReader setParentCallSid(final String parentCallSid){ + + public CallReader setParentCallSid(final String parentCallSid) { this.parentCallSid = parentCallSid; return this; } - public CallReader setStatus(final Call.Status status){ + + public CallReader setStatus(final Call.Status status) { this.status = status; return this; } - public CallReader setStartTime(final ZonedDateTime startTime){ + + public CallReader setStartTime(final ZonedDateTime startTime) { this.startTime = startTime; return this; } - public CallReader setStartTimeBefore(final ZonedDateTime startTimeBefore){ + + public CallReader setStartTimeBefore(final ZonedDateTime startTimeBefore) { this.startTimeBefore = startTimeBefore; return this; } - public CallReader setStartTimeAfter(final ZonedDateTime startTimeAfter){ + + public CallReader setStartTimeAfter(final ZonedDateTime startTimeAfter) { this.startTimeAfter = startTimeAfter; return this; } - public CallReader setEndTime(final ZonedDateTime endTime){ + + public CallReader setEndTime(final ZonedDateTime endTime) { this.endTime = endTime; return this; } - public CallReader setEndTimeBefore(final ZonedDateTime endTimeBefore){ + + public CallReader setEndTimeBefore(final ZonedDateTime endTimeBefore) { this.endTimeBefore = endTimeBefore; return this; } - public CallReader setEndTimeAfter(final ZonedDateTime endTimeAfter){ + + public CallReader setEndTimeAfter(final ZonedDateTime endTimeAfter) { this.endTimeAfter = endTimeAfter; return this; } - public CallReader setPageSize(final Integer pageSize){ + + public CallReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -111,8 +120,15 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/2010-04-01/Accounts/{AccountSid}/Calls.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -124,13 +140,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Call read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Call read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -146,7 +170,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request r } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.API.toString()) @@ -154,9 +181,11 @@ public Page previousPage(final Page page, final TwilioRestClient cli return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.API.toString()) @@ -165,49 +194,65 @@ public Page nextPage(final Page page, final TwilioRestClient client) } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (to != null) { - request.addQueryParam("To", to.toString()); } if (from != null) { - request.addQueryParam("From", from.toString()); } if (parentCallSid != null) { - request.addQueryParam("ParentCallSid", parentCallSid); } if (status != null) { - request.addQueryParam("Status", status.toString()); } if (startTime != null) { - request.addQueryParam("StartTime", startTime.format(DateTimeFormatter.ofPattern(Request.QUERY_STRING_DATE_TIME_FORMAT))); - } - else if (startTimeAfter != null || startTimeBefore != null) { - request.addQueryDateTimeRange("StartTime", startTimeAfter, startTimeBefore); + request.addQueryParam( + "StartTime", + startTime.format( + DateTimeFormatter.ofPattern( + Request.QUERY_STRING_DATE_TIME_FORMAT + ) + ) + ); + } else if (startTimeAfter != null || startTimeBefore != null) { + request.addQueryDateTimeRange( + "StartTime", + startTimeAfter, + startTimeBefore + ); } if (endTime != null) { - request.addQueryParam("EndTime", endTime.format(DateTimeFormatter.ofPattern(Request.QUERY_STRING_DATE_TIME_FORMAT))); - } - else if (endTimeAfter != null || endTimeBefore != null) { - request.addQueryDateTimeRange("EndTime", endTimeAfter, endTimeBefore); + request.addQueryParam( + "EndTime", + endTime.format( + DateTimeFormatter.ofPattern( + Request.QUERY_STRING_DATE_TIME_FORMAT + ) + ) + ); + } else if (endTimeAfter != null || endTimeBefore != null) { + request.addQueryDateTimeRange( + "EndTime", + endTimeAfter, + endTimeBefore + ); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/CallUpdater.java b/src/main/java/com/twilio/rest/api/v2010/account/CallUpdater.java index b478d265df..e6a191b7a4 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/CallUpdater.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/CallUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010.account; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -24,12 +25,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.net.URI; +public class CallUpdater extends Updater { - -public class CallUpdater extends Updater{ private String pathSid; private String pathAccountSid; private URI url; @@ -42,86 +41,110 @@ public class CallUpdater extends Updater{ private com.twilio.type.Twiml twiml; private Integer timeLimit; - public CallUpdater(final String pathSid){ + public CallUpdater(final String pathSid) { this.pathSid = pathSid; } - public CallUpdater(final String pathAccountSid, final String pathSid){ + + public CallUpdater(final String pathAccountSid, final String pathSid) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - public CallUpdater setUrl(final URI url){ + public CallUpdater setUrl(final URI url) { this.url = url; return this; } - public CallUpdater setUrl(final String url){ + public CallUpdater setUrl(final String url) { return setUrl(Promoter.uriFromString(url)); } - public CallUpdater setMethod(final HttpMethod method){ + + public CallUpdater setMethod(final HttpMethod method) { this.method = method; return this; } - public CallUpdater setStatus(final Call.UpdateStatus status){ + + public CallUpdater setStatus(final Call.UpdateStatus status) { this.status = status; return this; } - public CallUpdater setFallbackUrl(final URI fallbackUrl){ + + public CallUpdater setFallbackUrl(final URI fallbackUrl) { this.fallbackUrl = fallbackUrl; return this; } - public CallUpdater setFallbackUrl(final String fallbackUrl){ + public CallUpdater setFallbackUrl(final String fallbackUrl) { return setFallbackUrl(Promoter.uriFromString(fallbackUrl)); } - public CallUpdater setFallbackMethod(final HttpMethod fallbackMethod){ + + public CallUpdater setFallbackMethod(final HttpMethod fallbackMethod) { this.fallbackMethod = fallbackMethod; return this; } - public CallUpdater setStatusCallback(final URI statusCallback){ + + public CallUpdater setStatusCallback(final URI statusCallback) { this.statusCallback = statusCallback; return this; } - public CallUpdater setStatusCallback(final String statusCallback){ + public CallUpdater setStatusCallback(final String statusCallback) { return setStatusCallback(Promoter.uriFromString(statusCallback)); } - public CallUpdater setStatusCallbackMethod(final HttpMethod statusCallbackMethod){ + + public CallUpdater setStatusCallbackMethod( + final HttpMethod statusCallbackMethod + ) { this.statusCallbackMethod = statusCallbackMethod; return this; } - public CallUpdater setTwiml(final com.twilio.type.Twiml twiml){ + + public CallUpdater setTwiml(final com.twilio.type.Twiml twiml) { this.twiml = twiml; return this; } - public CallUpdater setTwiml(final String twiml){ + public CallUpdater setTwiml(final String twiml) { return setTwiml(Promoter.twimlFromString(twiml)); } - public CallUpdater setTimeLimit(final Integer timeLimit){ + + public CallUpdater setTimeLimit(final Integer timeLimit) { this.timeLimit = timeLimit; return this; } @Override - public Call update(final TwilioRestClient client){ + public Call update(final TwilioRestClient client) { String path = "/2010-04-01/Accounts/{AccountSid}/Calls/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.API.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Call update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Call update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -130,42 +153,37 @@ public Call update(final TwilioRestClient client){ return Call.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (url != null) { request.addPostParam("Url", url.toString()); - } if (method != null) { request.addPostParam("Method", method.toString()); - } if (status != null) { request.addPostParam("Status", status.toString()); - } if (fallbackUrl != null) { request.addPostParam("FallbackUrl", fallbackUrl.toString()); - } if (fallbackMethod != null) { request.addPostParam("FallbackMethod", fallbackMethod.toString()); - } if (statusCallback != null) { request.addPostParam("StatusCallback", statusCallback.toString()); - } if (statusCallbackMethod != null) { - request.addPostParam("StatusCallbackMethod", statusCallbackMethod.toString()); - + request.addPostParam( + "StatusCallbackMethod", + statusCallbackMethod.toString() + ); } if (twiml != null) { request.addPostParam("Twiml", twiml.toString()); - } if (timeLimit != null) { request.addPostParam("TimeLimit", timeLimit.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/Conference.java b/src/main/java/com/twilio/rest/api/v2010/account/Conference.java index 0e97c45326..ba62416af8 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/Conference.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/Conference.java @@ -24,55 +24,63 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Conference extends Resource { + private static final long serialVersionUID = 143481327355997L; - public static ConferenceFetcher fetcher(final String pathSid){ + public static ConferenceFetcher fetcher(final String pathSid) { return new ConferenceFetcher(pathSid); } - public static ConferenceFetcher fetcher(final String pathAccountSid, final String pathSid){ + + public static ConferenceFetcher fetcher( + final String pathAccountSid, + final String pathSid + ) { return new ConferenceFetcher(pathAccountSid, pathSid); } - public static ConferenceReader reader(){ + public static ConferenceReader reader() { return new ConferenceReader(); } - public static ConferenceReader reader(final String pathAccountSid){ + + public static ConferenceReader reader(final String pathAccountSid) { return new ConferenceReader(pathAccountSid); } - public static ConferenceUpdater updater(final String pathSid){ + public static ConferenceUpdater updater(final String pathSid) { return new ConferenceUpdater(pathSid); } - public static ConferenceUpdater updater(final String pathAccountSid, final String pathSid){ + + public static ConferenceUpdater updater( + final String pathAccountSid, + final String pathSid + ) { return new ConferenceUpdater(pathAccountSid, pathSid); } /** - * Converts a JSON String into a Conference object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Conference object represented by the provided JSON - */ - public static Conference fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Conference object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Conference object represented by the provided JSON + */ + public static Conference fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Conference.class); @@ -84,14 +92,17 @@ public static Conference fromJson(final String json, final ObjectMapper objectMa } /** - * Converts a JSON InputStream into a Conference object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Conference object represented by the provided JSON - */ - public static Conference fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Conference object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Conference object represented by the provided JSON + */ + public static Conference fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Conference.class); @@ -101,10 +112,15 @@ public static Conference fromJson(final InputStream json, final ObjectMapper obj throw new ApiConnectionException(e.getMessage(), e); } } + public enum ReasonConferenceEnded { CONFERENCE_ENDED_VIA_API("conference-ended-via-api"), - PARTICIPANT_WITH_END_CONFERENCE_ON_EXIT_LEFT("participant-with-end-conference-on-exit-left"), - PARTICIPANT_WITH_END_CONFERENCE_ON_EXIT_KICKED("participant-with-end-conference-on-exit-kicked"), + PARTICIPANT_WITH_END_CONFERENCE_ON_EXIT_LEFT( + "participant-with-end-conference-on-exit-left" + ), + PARTICIPANT_WITH_END_CONFERENCE_ON_EXIT_KICKED( + "participant-with-end-conference-on-exit-kicked" + ), LAST_PARTICIPANT_KICKED("last-participant-kicked"), LAST_PARTICIPANT_LEFT("last-participant-left"); @@ -120,9 +136,13 @@ public String toString() { @JsonCreator public static ReasonConferenceEnded forValue(final String value) { - return Promoter.enumFromString(value, ReasonConferenceEnded.values()); + return Promoter.enumFromString( + value, + ReasonConferenceEnded.values() + ); } } + public enum Status { INIT("init"), IN_PROGRESS("in-progress"), @@ -143,6 +163,7 @@ public static Status forValue(final String value) { return Promoter.enumFromString(value, Status.values()); } } + public enum UpdateStatus { COMPLETED("completed"); @@ -177,41 +198,24 @@ public static UpdateStatus forValue(final String value) { @JsonCreator private Conference( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("api_version") - final String apiVersion, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("region") - final String region, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("status") - final Conference.Status status, - - @JsonProperty("uri") - final String uri, - - @JsonProperty("subresource_uris") - final Map subresourceUris, - - @JsonProperty("reason_conference_ended") - final Conference.ReasonConferenceEnded reasonConferenceEnded, - - @JsonProperty("call_sid_ending_conference") - final String callSidEndingConference + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("api_version") final String apiVersion, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("region") final String region, + @JsonProperty("sid") final String sid, + @JsonProperty("status") final Conference.Status status, + @JsonProperty("uri") final String uri, + @JsonProperty( + "subresource_uris" + ) final Map subresourceUris, + @JsonProperty( + "reason_conference_ended" + ) final Conference.ReasonConferenceEnded reasonConferenceEnded, + @JsonProperty( + "call_sid_ending_conference" + ) final String callSidEndingConference ) { this.accountSid = accountSid; this.dateCreated = DateConverter.rfc2822DateTimeFromString(dateCreated); @@ -227,46 +231,57 @@ private Conference( this.callSidEndingConference = callSidEndingConference; } - public final String getAccountSid() { - return this.accountSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getApiVersion() { - return this.apiVersion; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getRegion() { - return this.region; - } - public final String getSid() { - return this.sid; - } - public final Conference.Status getStatus() { - return this.status; - } - public final String getUri() { - return this.uri; - } - public final Map getSubresourceUris() { - return this.subresourceUris; - } - public final Conference.ReasonConferenceEnded getReasonConferenceEnded() { - return this.reasonConferenceEnded; - } - public final String getCallSidEndingConference() { - return this.callSidEndingConference; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getApiVersion() { + return this.apiVersion; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getRegion() { + return this.region; + } + + public final String getSid() { + return this.sid; + } + + public final Conference.Status getStatus() { + return this.status; + } + + public final String getUri() { + return this.uri; + } + + public final Map getSubresourceUris() { + return this.subresourceUris; + } + + public final Conference.ReasonConferenceEnded getReasonConferenceEnded() { + return this.reasonConferenceEnded; + } + + public final String getCallSidEndingConference() { + return this.callSidEndingConference; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -276,13 +291,43 @@ public boolean equals(final Object o) { Conference other = (Conference) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(apiVersion, other.apiVersion) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(region, other.region) && Objects.equals(sid, other.sid) && Objects.equals(status, other.status) && Objects.equals(uri, other.uri) && Objects.equals(subresourceUris, other.subresourceUris) && Objects.equals(reasonConferenceEnded, other.reasonConferenceEnded) && Objects.equals(callSidEndingConference, other.callSidEndingConference) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(apiVersion, other.apiVersion) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(region, other.region) && + Objects.equals(sid, other.sid) && + Objects.equals(status, other.status) && + Objects.equals(uri, other.uri) && + Objects.equals(subresourceUris, other.subresourceUris) && + Objects.equals( + reasonConferenceEnded, + other.reasonConferenceEnded + ) && + Objects.equals( + callSidEndingConference, + other.callSidEndingConference + ) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, dateCreated, dateUpdated, apiVersion, friendlyName, region, sid, status, uri, subresourceUris, reasonConferenceEnded, callSidEndingConference); + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + apiVersion, + friendlyName, + region, + sid, + status, + uri, + subresourceUris, + reasonConferenceEnded, + callSidEndingConference + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/ConferenceFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/ConferenceFetcher.java index d54a43b50c..fa81b532f9 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/ConferenceFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/ConferenceFetcher.java @@ -24,29 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class ConferenceFetcher extends Fetcher { + private String pathSid; private String pathAccountSid; - public ConferenceFetcher(final String pathSid){ + public ConferenceFetcher(final String pathSid) { this.pathSid = pathSid; } - public ConferenceFetcher(final String pathAccountSid, final String pathSid){ + + public ConferenceFetcher( + final String pathAccountSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - @Override public Conference fetch(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/Conferences/{Sid}.json"; + String path = + "/2010-04-01/Accounts/{AccountSid}/Conferences/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -56,15 +65,23 @@ public Conference fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Conference fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Conference fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Conference.fromJson(response.getStream(), client.getObjectMapper()); + return Conference.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/ConferenceReader.java b/src/main/java/com/twilio/rest/api/v2010/account/ConferenceReader.java index a30c6df034..d5f3f76113 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/ConferenceReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/ConferenceReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.api.v2010.account; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,13 +25,11 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; import java.time.LocalDate; import java.time.format.DateTimeFormatter; - - public class ConferenceReader extends Reader { + private String pathAccountSid; private LocalDate dateCreated; private LocalDate dateCreatedBefore; @@ -42,45 +41,61 @@ public class ConferenceReader extends Reader { private Conference.Status status; private Integer pageSize; - public ConferenceReader(){ - } - public ConferenceReader(final String pathAccountSid){ + public ConferenceReader() {} + + public ConferenceReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - public ConferenceReader setDateCreated(final LocalDate dateCreated){ + public ConferenceReader setDateCreated(final LocalDate dateCreated) { this.dateCreated = dateCreated; return this; } - public ConferenceReader setDateCreatedBefore(final LocalDate dateCreatedBefore){ + + public ConferenceReader setDateCreatedBefore( + final LocalDate dateCreatedBefore + ) { this.dateCreatedBefore = dateCreatedBefore; return this; } - public ConferenceReader setDateCreatedAfter(final LocalDate dateCreatedAfter){ + + public ConferenceReader setDateCreatedAfter( + final LocalDate dateCreatedAfter + ) { this.dateCreatedAfter = dateCreatedAfter; return this; } - public ConferenceReader setDateUpdated(final LocalDate dateUpdated){ + + public ConferenceReader setDateUpdated(final LocalDate dateUpdated) { this.dateUpdated = dateUpdated; return this; } - public ConferenceReader setDateUpdatedBefore(final LocalDate dateUpdatedBefore){ + + public ConferenceReader setDateUpdatedBefore( + final LocalDate dateUpdatedBefore + ) { this.dateUpdatedBefore = dateUpdatedBefore; return this; } - public ConferenceReader setDateUpdatedAfter(final LocalDate dateUpdatedAfter){ + + public ConferenceReader setDateUpdatedAfter( + final LocalDate dateUpdatedAfter + ) { this.dateUpdatedAfter = dateUpdatedAfter; return this; } - public ConferenceReader setFriendlyName(final String friendlyName){ + + public ConferenceReader setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public ConferenceReader setStatus(final Conference.Status status){ + + public ConferenceReader setStatus(final Conference.Status status) { this.status = status; return this; } - public ConferenceReader setPageSize(final Integer pageSize){ + + public ConferenceReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -92,8 +107,15 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/2010-04-01/Accounts/{AccountSid}/Conferences.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -105,13 +127,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Conference read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Conference read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -127,7 +157,10 @@ private Page pageForRequest(final TwilioRestClient client, final Req } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.API.toString()) @@ -135,9 +168,11 @@ public Page previousPage(final Page page, final TwilioRe return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.API.toString()) @@ -146,41 +181,59 @@ public Page nextPage(final Page page, final TwilioRestCl } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (dateCreated != null) { - request.addQueryParam("DateCreated", dateCreated.format(DateTimeFormatter.ofPattern(Request.QUERY_STRING_DATE_TIME_FORMAT))); - } - else if (dateCreatedAfter != null || dateCreatedBefore != null) { - request.addQueryDateRange("DateCreated", dateCreatedAfter, dateCreatedBefore); + request.addQueryParam( + "DateCreated", + dateCreated.format( + DateTimeFormatter.ofPattern( + Request.QUERY_STRING_DATE_FORMAT + ) + ) + ); + } else if (dateCreatedAfter != null || dateCreatedBefore != null) { + request.addQueryDateRange( + "DateCreated", + dateCreatedAfter, + dateCreatedBefore + ); } if (dateUpdated != null) { - request.addQueryParam("DateUpdated", dateUpdated.format(DateTimeFormatter.ofPattern(Request.QUERY_STRING_DATE_TIME_FORMAT))); - } - else if (dateUpdatedAfter != null || dateUpdatedBefore != null) { - request.addQueryDateRange("DateUpdated", dateUpdatedAfter, dateUpdatedBefore); + request.addQueryParam( + "DateUpdated", + dateUpdated.format( + DateTimeFormatter.ofPattern( + Request.QUERY_STRING_DATE_FORMAT + ) + ) + ); + } else if (dateUpdatedAfter != null || dateUpdatedBefore != null) { + request.addQueryDateRange( + "DateUpdated", + dateUpdatedAfter, + dateUpdatedBefore + ); } if (friendlyName != null) { - request.addQueryParam("FriendlyName", friendlyName); } if (status != null) { - request.addQueryParam("Status", status.toString()); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/ConferenceUpdater.java b/src/main/java/com/twilio/rest/api/v2010/account/ConferenceUpdater.java index ea4ac07ce7..19b9ae6108 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/ConferenceUpdater.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/ConferenceUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010.account; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -24,82 +25,103 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.net.URI; +public class ConferenceUpdater extends Updater { - -public class ConferenceUpdater extends Updater{ private String pathSid; private String pathAccountSid; private Conference.UpdateStatus status; private URI announceUrl; private HttpMethod announceMethod; - public ConferenceUpdater(final String pathSid){ + public ConferenceUpdater(final String pathSid) { this.pathSid = pathSid; } - public ConferenceUpdater(final String pathAccountSid, final String pathSid){ + + public ConferenceUpdater( + final String pathAccountSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - public ConferenceUpdater setStatus(final Conference.UpdateStatus status){ + public ConferenceUpdater setStatus(final Conference.UpdateStatus status) { this.status = status; return this; } - public ConferenceUpdater setAnnounceUrl(final URI announceUrl){ + + public ConferenceUpdater setAnnounceUrl(final URI announceUrl) { this.announceUrl = announceUrl; return this; } - public ConferenceUpdater setAnnounceUrl(final String announceUrl){ + public ConferenceUpdater setAnnounceUrl(final String announceUrl) { return setAnnounceUrl(Promoter.uriFromString(announceUrl)); } - public ConferenceUpdater setAnnounceMethod(final HttpMethod announceMethod){ + + public ConferenceUpdater setAnnounceMethod( + final HttpMethod announceMethod + ) { this.announceMethod = announceMethod; return this; } @Override - public Conference update(final TwilioRestClient client){ - String path = "/2010-04-01/Accounts/{AccountSid}/Conferences/{Sid}.json"; + public Conference update(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Conferences/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.API.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Conference update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Conference update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Conference.fromJson(response.getStream(), client.getObjectMapper()); + return Conference.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (status != null) { request.addPostParam("Status", status.toString()); - } if (announceUrl != null) { request.addPostParam("AnnounceUrl", announceUrl.toString()); - } if (announceMethod != null) { request.addPostParam("AnnounceMethod", announceMethod.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/ConnectApp.java b/src/main/java/com/twilio/rest/api/v2010/account/ConnectApp.java index cdf948197c..68dca1af0f 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/ConnectApp.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/ConnectApp.java @@ -23,62 +23,74 @@ import com.twilio.base.Resource; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; import com.twilio.http.HttpMethod; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.List; import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class ConnectApp extends Resource { + private static final long serialVersionUID = 203118827948403L; - public static ConnectAppDeleter deleter(final String pathSid){ + public static ConnectAppDeleter deleter(final String pathSid) { return new ConnectAppDeleter(pathSid); } - public static ConnectAppDeleter deleter(final String pathAccountSid, final String pathSid){ + + public static ConnectAppDeleter deleter( + final String pathAccountSid, + final String pathSid + ) { return new ConnectAppDeleter(pathAccountSid, pathSid); } - public static ConnectAppFetcher fetcher(final String pathSid){ + public static ConnectAppFetcher fetcher(final String pathSid) { return new ConnectAppFetcher(pathSid); } - public static ConnectAppFetcher fetcher(final String pathAccountSid, final String pathSid){ + + public static ConnectAppFetcher fetcher( + final String pathAccountSid, + final String pathSid + ) { return new ConnectAppFetcher(pathAccountSid, pathSid); } - public static ConnectAppReader reader(){ + public static ConnectAppReader reader() { return new ConnectAppReader(); } - public static ConnectAppReader reader(final String pathAccountSid){ + + public static ConnectAppReader reader(final String pathAccountSid) { return new ConnectAppReader(pathAccountSid); } - public static ConnectAppUpdater updater(final String pathSid){ + public static ConnectAppUpdater updater(final String pathSid) { return new ConnectAppUpdater(pathSid); } - public static ConnectAppUpdater updater(final String pathAccountSid, final String pathSid){ + + public static ConnectAppUpdater updater( + final String pathAccountSid, + final String pathSid + ) { return new ConnectAppUpdater(pathAccountSid, pathSid); } /** - * Converts a JSON String into a ConnectApp object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return ConnectApp object represented by the provided JSON - */ - public static ConnectApp fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a ConnectApp object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return ConnectApp object represented by the provided JSON + */ + public static ConnectApp fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, ConnectApp.class); @@ -90,14 +102,17 @@ public static ConnectApp fromJson(final String json, final ObjectMapper objectMa } /** - * Converts a JSON InputStream into a ConnectApp object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return ConnectApp object represented by the provided JSON - */ - public static ConnectApp fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a ConnectApp object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return ConnectApp object represented by the provided JSON + */ + public static ConnectApp fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, ConnectApp.class); @@ -107,6 +122,7 @@ public static ConnectApp fromJson(final InputStream json, final ObjectMapper obj throw new ApiConnectionException(e.getMessage(), e); } } + public enum Permission { GET_ALL("get-all"), POST_ALL("post-all"); @@ -141,38 +157,23 @@ public static Permission forValue(final String value) { @JsonCreator private ConnectApp( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("authorize_redirect_url") - final URI authorizeRedirectUrl, - - @JsonProperty("company_name") - final String companyName, - - @JsonProperty("deauthorize_callback_method") - final HttpMethod deauthorizeCallbackMethod, - - @JsonProperty("deauthorize_callback_url") - final URI deauthorizeCallbackUrl, - - @JsonProperty("description") - final String description, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("homepage_url") - final URI homepageUrl, - - @JsonProperty("permissions") - final List permissions, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("uri") - final String uri + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("authorize_redirect_url") final URI authorizeRedirectUrl, + @JsonProperty("company_name") final String companyName, + @JsonProperty( + "deauthorize_callback_method" + ) final HttpMethod deauthorizeCallbackMethod, + @JsonProperty( + "deauthorize_callback_url" + ) final URI deauthorizeCallbackUrl, + @JsonProperty("description") final String description, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("homepage_url") final URI homepageUrl, + @JsonProperty( + "permissions" + ) final List permissions, + @JsonProperty("sid") final String sid, + @JsonProperty("uri") final String uri ) { this.accountSid = accountSid; this.authorizeRedirectUrl = authorizeRedirectUrl; @@ -187,43 +188,53 @@ private ConnectApp( this.uri = uri; } - public final String getAccountSid() { - return this.accountSid; - } - public final URI getAuthorizeRedirectUrl() { - return this.authorizeRedirectUrl; - } - public final String getCompanyName() { - return this.companyName; - } - public final HttpMethod getDeauthorizeCallbackMethod() { - return this.deauthorizeCallbackMethod; - } - public final URI getDeauthorizeCallbackUrl() { - return this.deauthorizeCallbackUrl; - } - public final String getDescription() { - return this.description; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final URI getHomepageUrl() { - return this.homepageUrl; - } - public final List getPermissions() { - return this.permissions; - } - public final String getSid() { - return this.sid; - } - public final String getUri() { - return this.uri; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final URI getAuthorizeRedirectUrl() { + return this.authorizeRedirectUrl; + } + + public final String getCompanyName() { + return this.companyName; + } + + public final HttpMethod getDeauthorizeCallbackMethod() { + return this.deauthorizeCallbackMethod; + } + + public final URI getDeauthorizeCallbackUrl() { + return this.deauthorizeCallbackUrl; + } + + public final String getDescription() { + return this.description; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final URI getHomepageUrl() { + return this.homepageUrl; + } + + public final List getPermissions() { + return this.permissions; + } + + public final String getSid() { + return this.sid; + } + + public final String getUri() { + return this.uri; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -233,13 +244,41 @@ public boolean equals(final Object o) { ConnectApp other = (ConnectApp) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(authorizeRedirectUrl, other.authorizeRedirectUrl) && Objects.equals(companyName, other.companyName) && Objects.equals(deauthorizeCallbackMethod, other.deauthorizeCallbackMethod) && Objects.equals(deauthorizeCallbackUrl, other.deauthorizeCallbackUrl) && Objects.equals(description, other.description) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(homepageUrl, other.homepageUrl) && Objects.equals(permissions, other.permissions) && Objects.equals(sid, other.sid) && Objects.equals(uri, other.uri) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(authorizeRedirectUrl, other.authorizeRedirectUrl) && + Objects.equals(companyName, other.companyName) && + Objects.equals( + deauthorizeCallbackMethod, + other.deauthorizeCallbackMethod + ) && + Objects.equals( + deauthorizeCallbackUrl, + other.deauthorizeCallbackUrl + ) && + Objects.equals(description, other.description) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(homepageUrl, other.homepageUrl) && + Objects.equals(permissions, other.permissions) && + Objects.equals(sid, other.sid) && + Objects.equals(uri, other.uri) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, authorizeRedirectUrl, companyName, deauthorizeCallbackMethod, deauthorizeCallbackUrl, description, friendlyName, homepageUrl, permissions, sid, uri); + return Objects.hash( + accountSid, + authorizeRedirectUrl, + companyName, + deauthorizeCallbackMethod, + deauthorizeCallbackUrl, + description, + friendlyName, + homepageUrl, + permissions, + sid, + uri + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/ConnectAppDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/ConnectAppDeleter.java index da432d7bc4..03fa1b398d 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/ConnectAppDeleter.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/ConnectAppDeleter.java @@ -24,28 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class ConnectAppDeleter extends Deleter { + private String pathSid; private String pathAccountSid; - public ConnectAppDeleter(final String pathSid){ + public ConnectAppDeleter(final String pathSid) { this.pathSid = pathSid; } - public ConnectAppDeleter(final String pathAccountSid, final String pathSid){ + + public ConnectAppDeleter( + final String pathAccountSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/ConnectApps/{Sid}.json"; + String path = + "/2010-04-01/Accounts/{AccountSid}/ConnectApps/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -55,9 +65,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("ConnectApp delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "ConnectApp delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/ConnectAppFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/ConnectAppFetcher.java index 4137d64b30..84e5fa0a92 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/ConnectAppFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/ConnectAppFetcher.java @@ -24,29 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class ConnectAppFetcher extends Fetcher { + private String pathSid; private String pathAccountSid; - public ConnectAppFetcher(final String pathSid){ + public ConnectAppFetcher(final String pathSid) { this.pathSid = pathSid; } - public ConnectAppFetcher(final String pathAccountSid, final String pathSid){ + + public ConnectAppFetcher( + final String pathAccountSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - @Override public ConnectApp fetch(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/ConnectApps/{Sid}.json"; + String path = + "/2010-04-01/Accounts/{AccountSid}/ConnectApps/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -56,15 +65,23 @@ public ConnectApp fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("ConnectApp fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "ConnectApp fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return ConnectApp.fromJson(response.getStream(), client.getObjectMapper()); + return ConnectApp.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/ConnectAppReader.java b/src/main/java/com/twilio/rest/api/v2010/account/ConnectAppReader.java index 64a944419a..35ccedfa4d 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/ConnectAppReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/ConnectAppReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.api.v2010.account; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,21 +25,19 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class ConnectAppReader extends Reader { + private String pathAccountSid; private Integer pageSize; - public ConnectAppReader(){ - } - public ConnectAppReader(final String pathAccountSid){ + public ConnectAppReader() {} + + public ConnectAppReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - public ConnectAppReader setPageSize(final Integer pageSize){ + public ConnectAppReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -50,8 +49,15 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/2010-04-01/Accounts/{AccountSid}/ConnectApps.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -63,13 +69,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("ConnectApp read failed: Unable to connect to server"); + throw new ApiConnectionException( + "ConnectApp read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -85,7 +99,10 @@ private Page pageForRequest(final TwilioRestClient client, final Req } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.API.toString()) @@ -93,9 +110,11 @@ public Page previousPage(final Page page, final TwilioRe return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.API.toString()) @@ -104,21 +123,21 @@ public Page nextPage(final Page page, final TwilioRestCl } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/ConnectAppUpdater.java b/src/main/java/com/twilio/rest/api/v2010/account/ConnectAppUpdater.java index bf5c9f0795..75691c32d4 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/ConnectAppUpdater.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/ConnectAppUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010.account; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -24,13 +25,11 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.net.URI; - import java.util.List; +public class ConnectAppUpdater extends Updater { -public class ConnectAppUpdater extends Updater{ private String pathSid; private String pathAccountSid; private URI authorizeRedirectUrl; @@ -42,123 +41,172 @@ public class ConnectAppUpdater extends Updater{ private URI homepageUrl; private List permissions; - public ConnectAppUpdater(final String pathSid){ + public ConnectAppUpdater(final String pathSid) { this.pathSid = pathSid; } - public ConnectAppUpdater(final String pathAccountSid, final String pathSid){ + + public ConnectAppUpdater( + final String pathAccountSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - public ConnectAppUpdater setAuthorizeRedirectUrl(final URI authorizeRedirectUrl){ + public ConnectAppUpdater setAuthorizeRedirectUrl( + final URI authorizeRedirectUrl + ) { this.authorizeRedirectUrl = authorizeRedirectUrl; return this; } - public ConnectAppUpdater setAuthorizeRedirectUrl(final String authorizeRedirectUrl){ - return setAuthorizeRedirectUrl(Promoter.uriFromString(authorizeRedirectUrl)); + public ConnectAppUpdater setAuthorizeRedirectUrl( + final String authorizeRedirectUrl + ) { + return setAuthorizeRedirectUrl( + Promoter.uriFromString(authorizeRedirectUrl) + ); } - public ConnectAppUpdater setCompanyName(final String companyName){ + + public ConnectAppUpdater setCompanyName(final String companyName) { this.companyName = companyName; return this; } - public ConnectAppUpdater setDeauthorizeCallbackMethod(final HttpMethod deauthorizeCallbackMethod){ + + public ConnectAppUpdater setDeauthorizeCallbackMethod( + final HttpMethod deauthorizeCallbackMethod + ) { this.deauthorizeCallbackMethod = deauthorizeCallbackMethod; return this; } - public ConnectAppUpdater setDeauthorizeCallbackUrl(final URI deauthorizeCallbackUrl){ + + public ConnectAppUpdater setDeauthorizeCallbackUrl( + final URI deauthorizeCallbackUrl + ) { this.deauthorizeCallbackUrl = deauthorizeCallbackUrl; return this; } - public ConnectAppUpdater setDeauthorizeCallbackUrl(final String deauthorizeCallbackUrl){ - return setDeauthorizeCallbackUrl(Promoter.uriFromString(deauthorizeCallbackUrl)); + public ConnectAppUpdater setDeauthorizeCallbackUrl( + final String deauthorizeCallbackUrl + ) { + return setDeauthorizeCallbackUrl( + Promoter.uriFromString(deauthorizeCallbackUrl) + ); } - public ConnectAppUpdater setDescription(final String description){ + + public ConnectAppUpdater setDescription(final String description) { this.description = description; return this; } - public ConnectAppUpdater setFriendlyName(final String friendlyName){ + + public ConnectAppUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public ConnectAppUpdater setHomepageUrl(final URI homepageUrl){ + + public ConnectAppUpdater setHomepageUrl(final URI homepageUrl) { this.homepageUrl = homepageUrl; return this; } - public ConnectAppUpdater setHomepageUrl(final String homepageUrl){ + public ConnectAppUpdater setHomepageUrl(final String homepageUrl) { return setHomepageUrl(Promoter.uriFromString(homepageUrl)); } - public ConnectAppUpdater setPermissions(final List permissions){ + + public ConnectAppUpdater setPermissions( + final List permissions + ) { this.permissions = permissions; return this; } - public ConnectAppUpdater setPermissions(final ConnectApp.Permission permissions){ + + public ConnectAppUpdater setPermissions( + final ConnectApp.Permission permissions + ) { return setPermissions(Promoter.listOfOne(permissions)); } @Override - public ConnectApp update(final TwilioRestClient client){ - String path = "/2010-04-01/Accounts/{AccountSid}/ConnectApps/{Sid}.json"; + public ConnectApp update(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/ConnectApps/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.API.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("ConnectApp update failed: Unable to connect to server"); + throw new ApiConnectionException( + "ConnectApp update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return ConnectApp.fromJson(response.getStream(), client.getObjectMapper()); + return ConnectApp.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (authorizeRedirectUrl != null) { - request.addPostParam("AuthorizeRedirectUrl", authorizeRedirectUrl.toString()); - + request.addPostParam( + "AuthorizeRedirectUrl", + authorizeRedirectUrl.toString() + ); } if (companyName != null) { request.addPostParam("CompanyName", companyName); - } if (deauthorizeCallbackMethod != null) { - request.addPostParam("DeauthorizeCallbackMethod", deauthorizeCallbackMethod.toString()); - + request.addPostParam( + "DeauthorizeCallbackMethod", + deauthorizeCallbackMethod.toString() + ); } if (deauthorizeCallbackUrl != null) { - request.addPostParam("DeauthorizeCallbackUrl", deauthorizeCallbackUrl.toString()); - + request.addPostParam( + "DeauthorizeCallbackUrl", + deauthorizeCallbackUrl.toString() + ); } if (description != null) { request.addPostParam("Description", description); - } if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (homepageUrl != null) { request.addPostParam("HomepageUrl", homepageUrl.toString()); - } if (permissions != null) { for (ConnectApp.Permission prop : permissions) { request.addPostParam("Permissions", prop.toString()); } - } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/IncomingPhoneNumber.java b/src/main/java/com/twilio/rest/api/v2010/account/IncomingPhoneNumber.java index e5dcb11d01..f91c2df76c 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/IncomingPhoneNumber.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/IncomingPhoneNumber.java @@ -24,76 +24,101 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; import com.twilio.http.HttpMethod; - -import lombok.ToString; - +import com.twilio.type.PhoneNumberCapabilities; import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - -import com.twilio.type.PhoneNumberCapabilities; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class IncomingPhoneNumber extends Resource { + private static final long serialVersionUID = 82830627507260L; - public static IncomingPhoneNumberCreator creator(final com.twilio.type.PhoneNumber phoneNumber){ + public static IncomingPhoneNumberCreator creator( + final com.twilio.type.PhoneNumber phoneNumber + ) { return new IncomingPhoneNumberCreator(phoneNumber); } - public static IncomingPhoneNumberCreator creator(final String pathAccountSid, final com.twilio.type.PhoneNumber phoneNumber){ + + public static IncomingPhoneNumberCreator creator( + final String pathAccountSid, + final com.twilio.type.PhoneNumber phoneNumber + ) { return new IncomingPhoneNumberCreator(pathAccountSid, phoneNumber); } - public static IncomingPhoneNumberCreator creator(final String areaCode){ + + public static IncomingPhoneNumberCreator creator(final String areaCode) { return new IncomingPhoneNumberCreator(areaCode); } - public static IncomingPhoneNumberCreator creator(final String pathAccountSid, final String areaCode){ + + public static IncomingPhoneNumberCreator creator( + final String pathAccountSid, + final String areaCode + ) { return new IncomingPhoneNumberCreator(pathAccountSid, areaCode); } - public static IncomingPhoneNumberDeleter deleter(final String pathSid){ + public static IncomingPhoneNumberDeleter deleter(final String pathSid) { return new IncomingPhoneNumberDeleter(pathSid); } - public static IncomingPhoneNumberDeleter deleter(final String pathAccountSid, final String pathSid){ + + public static IncomingPhoneNumberDeleter deleter( + final String pathAccountSid, + final String pathSid + ) { return new IncomingPhoneNumberDeleter(pathAccountSid, pathSid); } - public static IncomingPhoneNumberFetcher fetcher(final String pathSid){ + public static IncomingPhoneNumberFetcher fetcher(final String pathSid) { return new IncomingPhoneNumberFetcher(pathSid); } - public static IncomingPhoneNumberFetcher fetcher(final String pathAccountSid, final String pathSid){ + + public static IncomingPhoneNumberFetcher fetcher( + final String pathAccountSid, + final String pathSid + ) { return new IncomingPhoneNumberFetcher(pathAccountSid, pathSid); } - public static IncomingPhoneNumberReader reader(){ + public static IncomingPhoneNumberReader reader() { return new IncomingPhoneNumberReader(); } - public static IncomingPhoneNumberReader reader(final String pathAccountSid){ + + public static IncomingPhoneNumberReader reader( + final String pathAccountSid + ) { return new IncomingPhoneNumberReader(pathAccountSid); } - public static IncomingPhoneNumberUpdater updater(final String pathSid){ + public static IncomingPhoneNumberUpdater updater(final String pathSid) { return new IncomingPhoneNumberUpdater(pathSid); } - public static IncomingPhoneNumberUpdater updater(final String pathAccountSid, final String pathSid){ + + public static IncomingPhoneNumberUpdater updater( + final String pathAccountSid, + final String pathSid + ) { return new IncomingPhoneNumberUpdater(pathAccountSid, pathSid); } /** - * Converts a JSON String into a IncomingPhoneNumber object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return IncomingPhoneNumber object represented by the provided JSON - */ - public static IncomingPhoneNumber fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a IncomingPhoneNumber object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return IncomingPhoneNumber object represented by the provided JSON + */ + public static IncomingPhoneNumber fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, IncomingPhoneNumber.class); @@ -105,14 +130,17 @@ public static IncomingPhoneNumber fromJson(final String json, final ObjectMapper } /** - * Converts a JSON InputStream into a IncomingPhoneNumber object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return IncomingPhoneNumber object represented by the provided JSON - */ - public static IncomingPhoneNumber fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a IncomingPhoneNumber object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return IncomingPhoneNumber object represented by the provided JSON + */ + public static IncomingPhoneNumber fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, IncomingPhoneNumber.class); @@ -122,6 +150,7 @@ public static IncomingPhoneNumber fromJson(final InputStream json, final ObjectM throw new ApiConnectionException(e.getMessage(), e); } } + public enum AddressRequirement { NONE("none"), ANY("any"), @@ -143,6 +172,7 @@ public static AddressRequirement forValue(final String value) { return Promoter.enumFromString(value, AddressRequirement.values()); } } + public enum EmergencyAddressStatus { REGISTERED("registered"), UNREGISTERED("unregistered"), @@ -163,9 +193,13 @@ public String toString() { @JsonCreator public static EmergencyAddressStatus forValue(final String value) { - return Promoter.enumFromString(value, EmergencyAddressStatus.values()); + return Promoter.enumFromString( + value, + EmergencyAddressStatus.values() + ); } } + public enum EmergencyStatus { ACTIVE("Active"), INACTIVE("Inactive"); @@ -185,6 +219,7 @@ public static EmergencyStatus forValue(final String value) { return Promoter.enumFromString(value, EmergencyStatus.values()); } } + public enum VoiceReceiveMode { VOICE("voice"), FAX("fax"); @@ -242,107 +277,58 @@ public static VoiceReceiveMode forValue(final String value) { @JsonCreator private IncomingPhoneNumber( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("address_sid") - final String addressSid, - - @JsonProperty("address_requirements") - final IncomingPhoneNumber.AddressRequirement addressRequirements, - - @JsonProperty("api_version") - final String apiVersion, - - @JsonProperty("beta") - final Boolean beta, - - @JsonProperty("capabilities") - final PhoneNumberCapabilities capabilities, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("identity_sid") - final String identitySid, - - @JsonProperty("phone_number") - final com.twilio.type.PhoneNumber phoneNumber, - - @JsonProperty("origin") - final String origin, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("sms_application_sid") - final String smsApplicationSid, - - @JsonProperty("sms_fallback_method") - final HttpMethod smsFallbackMethod, - - @JsonProperty("sms_fallback_url") - final URI smsFallbackUrl, - - @JsonProperty("sms_method") - final HttpMethod smsMethod, - - @JsonProperty("sms_url") - final URI smsUrl, - - @JsonProperty("status_callback") - final URI statusCallback, - - @JsonProperty("status_callback_method") - final HttpMethod statusCallbackMethod, - - @JsonProperty("trunk_sid") - final String trunkSid, - - @JsonProperty("uri") - final String uri, - - @JsonProperty("voice_receive_mode") - final IncomingPhoneNumber.VoiceReceiveMode voiceReceiveMode, - - @JsonProperty("voice_application_sid") - final String voiceApplicationSid, - - @JsonProperty("voice_caller_id_lookup") - final Boolean voiceCallerIdLookup, - - @JsonProperty("voice_fallback_method") - final HttpMethod voiceFallbackMethod, - - @JsonProperty("voice_fallback_url") - final URI voiceFallbackUrl, - - @JsonProperty("voice_method") - final HttpMethod voiceMethod, - - @JsonProperty("voice_url") - final URI voiceUrl, - - @JsonProperty("emergency_status") - final IncomingPhoneNumber.EmergencyStatus emergencyStatus, - - @JsonProperty("emergency_address_sid") - final String emergencyAddressSid, - - @JsonProperty("emergency_address_status") - final IncomingPhoneNumber.EmergencyAddressStatus emergencyAddressStatus, - - @JsonProperty("bundle_sid") - final String bundleSid, - - @JsonProperty("status") - final String status + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("address_sid") final String addressSid, + @JsonProperty( + "address_requirements" + ) final IncomingPhoneNumber.AddressRequirement addressRequirements, + @JsonProperty("api_version") final String apiVersion, + @JsonProperty("beta") final Boolean beta, + @JsonProperty( + "capabilities" + ) final PhoneNumberCapabilities capabilities, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("identity_sid") final String identitySid, + @JsonProperty( + "phone_number" + ) final com.twilio.type.PhoneNumber phoneNumber, + @JsonProperty("origin") final String origin, + @JsonProperty("sid") final String sid, + @JsonProperty("sms_application_sid") final String smsApplicationSid, + @JsonProperty("sms_fallback_method") final HttpMethod smsFallbackMethod, + @JsonProperty("sms_fallback_url") final URI smsFallbackUrl, + @JsonProperty("sms_method") final HttpMethod smsMethod, + @JsonProperty("sms_url") final URI smsUrl, + @JsonProperty("status_callback") final URI statusCallback, + @JsonProperty( + "status_callback_method" + ) final HttpMethod statusCallbackMethod, + @JsonProperty("trunk_sid") final String trunkSid, + @JsonProperty("uri") final String uri, + @JsonProperty( + "voice_receive_mode" + ) final IncomingPhoneNumber.VoiceReceiveMode voiceReceiveMode, + @JsonProperty("voice_application_sid") final String voiceApplicationSid, + @JsonProperty( + "voice_caller_id_lookup" + ) final Boolean voiceCallerIdLookup, + @JsonProperty( + "voice_fallback_method" + ) final HttpMethod voiceFallbackMethod, + @JsonProperty("voice_fallback_url") final URI voiceFallbackUrl, + @JsonProperty("voice_method") final HttpMethod voiceMethod, + @JsonProperty("voice_url") final URI voiceUrl, + @JsonProperty( + "emergency_status" + ) final IncomingPhoneNumber.EmergencyStatus emergencyStatus, + @JsonProperty("emergency_address_sid") final String emergencyAddressSid, + @JsonProperty( + "emergency_address_status" + ) final IncomingPhoneNumber.EmergencyAddressStatus emergencyAddressStatus, + @JsonProperty("bundle_sid") final String bundleSid, + @JsonProperty("status") final String status ) { this.accountSid = accountSid; this.addressSid = addressSid; @@ -380,112 +366,145 @@ private IncomingPhoneNumber( this.status = status; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getAddressSid() { - return this.addressSid; - } - public final IncomingPhoneNumber.AddressRequirement getAddressRequirements() { - return this.addressRequirements; - } - public final String getApiVersion() { - return this.apiVersion; - } - public final Boolean getBeta() { - return this.beta; - } - public final PhoneNumberCapabilities getCapabilities() { - return this.capabilities; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getIdentitySid() { - return this.identitySid; - } - public final com.twilio.type.PhoneNumber getPhoneNumber() { - return this.phoneNumber; - } - public final String getOrigin() { - return this.origin; - } - public final String getSid() { - return this.sid; - } - public final String getSmsApplicationSid() { - return this.smsApplicationSid; - } - public final HttpMethod getSmsFallbackMethod() { - return this.smsFallbackMethod; - } - public final URI getSmsFallbackUrl() { - return this.smsFallbackUrl; - } - public final HttpMethod getSmsMethod() { - return this.smsMethod; - } - public final URI getSmsUrl() { - return this.smsUrl; - } - public final URI getStatusCallback() { - return this.statusCallback; - } - public final HttpMethod getStatusCallbackMethod() { - return this.statusCallbackMethod; - } - public final String getTrunkSid() { - return this.trunkSid; - } - public final String getUri() { - return this.uri; - } - public final IncomingPhoneNumber.VoiceReceiveMode getVoiceReceiveMode() { - return this.voiceReceiveMode; - } - public final String getVoiceApplicationSid() { - return this.voiceApplicationSid; - } - public final Boolean getVoiceCallerIdLookup() { - return this.voiceCallerIdLookup; - } - public final HttpMethod getVoiceFallbackMethod() { - return this.voiceFallbackMethod; - } - public final URI getVoiceFallbackUrl() { - return this.voiceFallbackUrl; - } - public final HttpMethod getVoiceMethod() { - return this.voiceMethod; - } - public final URI getVoiceUrl() { - return this.voiceUrl; - } - public final IncomingPhoneNumber.EmergencyStatus getEmergencyStatus() { - return this.emergencyStatus; - } - public final String getEmergencyAddressSid() { - return this.emergencyAddressSid; - } - public final IncomingPhoneNumber.EmergencyAddressStatus getEmergencyAddressStatus() { - return this.emergencyAddressStatus; - } - public final String getBundleSid() { - return this.bundleSid; - } - public final String getStatus() { - return this.status; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getAddressSid() { + return this.addressSid; + } + + public final IncomingPhoneNumber.AddressRequirement getAddressRequirements() { + return this.addressRequirements; + } + + public final String getApiVersion() { + return this.apiVersion; + } + + public final Boolean getBeta() { + return this.beta; + } + + public final PhoneNumberCapabilities getCapabilities() { + return this.capabilities; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getIdentitySid() { + return this.identitySid; + } + + public final com.twilio.type.PhoneNumber getPhoneNumber() { + return this.phoneNumber; + } + + public final String getOrigin() { + return this.origin; + } + + public final String getSid() { + return this.sid; + } + + public final String getSmsApplicationSid() { + return this.smsApplicationSid; + } + + public final HttpMethod getSmsFallbackMethod() { + return this.smsFallbackMethod; + } + + public final URI getSmsFallbackUrl() { + return this.smsFallbackUrl; + } + + public final HttpMethod getSmsMethod() { + return this.smsMethod; + } + + public final URI getSmsUrl() { + return this.smsUrl; + } + + public final URI getStatusCallback() { + return this.statusCallback; + } + + public final HttpMethod getStatusCallbackMethod() { + return this.statusCallbackMethod; + } + + public final String getTrunkSid() { + return this.trunkSid; + } + + public final String getUri() { + return this.uri; + } + + public final IncomingPhoneNumber.VoiceReceiveMode getVoiceReceiveMode() { + return this.voiceReceiveMode; + } + + public final String getVoiceApplicationSid() { + return this.voiceApplicationSid; + } + + public final Boolean getVoiceCallerIdLookup() { + return this.voiceCallerIdLookup; + } + + public final HttpMethod getVoiceFallbackMethod() { + return this.voiceFallbackMethod; + } + + public final URI getVoiceFallbackUrl() { + return this.voiceFallbackUrl; + } + + public final HttpMethod getVoiceMethod() { + return this.voiceMethod; + } + + public final URI getVoiceUrl() { + return this.voiceUrl; + } + + public final IncomingPhoneNumber.EmergencyStatus getEmergencyStatus() { + return this.emergencyStatus; + } + + public final String getEmergencyAddressSid() { + return this.emergencyAddressSid; + } + + public final IncomingPhoneNumber.EmergencyAddressStatus getEmergencyAddressStatus() { + return this.emergencyAddressStatus; + } + + public final String getBundleSid() { + return this.bundleSid; + } + + public final String getStatus() { + return this.status; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -495,13 +514,84 @@ public boolean equals(final Object o) { IncomingPhoneNumber other = (IncomingPhoneNumber) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(addressSid, other.addressSid) && Objects.equals(addressRequirements, other.addressRequirements) && Objects.equals(apiVersion, other.apiVersion) && Objects.equals(beta, other.beta) && Objects.equals(capabilities, other.capabilities) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(identitySid, other.identitySid) && Objects.equals(phoneNumber, other.phoneNumber) && Objects.equals(origin, other.origin) && Objects.equals(sid, other.sid) && Objects.equals(smsApplicationSid, other.smsApplicationSid) && Objects.equals(smsFallbackMethod, other.smsFallbackMethod) && Objects.equals(smsFallbackUrl, other.smsFallbackUrl) && Objects.equals(smsMethod, other.smsMethod) && Objects.equals(smsUrl, other.smsUrl) && Objects.equals(statusCallback, other.statusCallback) && Objects.equals(statusCallbackMethod, other.statusCallbackMethod) && Objects.equals(trunkSid, other.trunkSid) && Objects.equals(uri, other.uri) && Objects.equals(voiceReceiveMode, other.voiceReceiveMode) && Objects.equals(voiceApplicationSid, other.voiceApplicationSid) && Objects.equals(voiceCallerIdLookup, other.voiceCallerIdLookup) && Objects.equals(voiceFallbackMethod, other.voiceFallbackMethod) && Objects.equals(voiceFallbackUrl, other.voiceFallbackUrl) && Objects.equals(voiceMethod, other.voiceMethod) && Objects.equals(voiceUrl, other.voiceUrl) && Objects.equals(emergencyStatus, other.emergencyStatus) && Objects.equals(emergencyAddressSid, other.emergencyAddressSid) && Objects.equals(emergencyAddressStatus, other.emergencyAddressStatus) && Objects.equals(bundleSid, other.bundleSid) && Objects.equals(status, other.status) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(addressSid, other.addressSid) && + Objects.equals(addressRequirements, other.addressRequirements) && + Objects.equals(apiVersion, other.apiVersion) && + Objects.equals(beta, other.beta) && + Objects.equals(capabilities, other.capabilities) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(identitySid, other.identitySid) && + Objects.equals(phoneNumber, other.phoneNumber) && + Objects.equals(origin, other.origin) && + Objects.equals(sid, other.sid) && + Objects.equals(smsApplicationSid, other.smsApplicationSid) && + Objects.equals(smsFallbackMethod, other.smsFallbackMethod) && + Objects.equals(smsFallbackUrl, other.smsFallbackUrl) && + Objects.equals(smsMethod, other.smsMethod) && + Objects.equals(smsUrl, other.smsUrl) && + Objects.equals(statusCallback, other.statusCallback) && + Objects.equals(statusCallbackMethod, other.statusCallbackMethod) && + Objects.equals(trunkSid, other.trunkSid) && + Objects.equals(uri, other.uri) && + Objects.equals(voiceReceiveMode, other.voiceReceiveMode) && + Objects.equals(voiceApplicationSid, other.voiceApplicationSid) && + Objects.equals(voiceCallerIdLookup, other.voiceCallerIdLookup) && + Objects.equals(voiceFallbackMethod, other.voiceFallbackMethod) && + Objects.equals(voiceFallbackUrl, other.voiceFallbackUrl) && + Objects.equals(voiceMethod, other.voiceMethod) && + Objects.equals(voiceUrl, other.voiceUrl) && + Objects.equals(emergencyStatus, other.emergencyStatus) && + Objects.equals(emergencyAddressSid, other.emergencyAddressSid) && + Objects.equals( + emergencyAddressStatus, + other.emergencyAddressStatus + ) && + Objects.equals(bundleSid, other.bundleSid) && + Objects.equals(status, other.status) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, addressSid, addressRequirements, apiVersion, beta, capabilities, dateCreated, dateUpdated, friendlyName, identitySid, phoneNumber, origin, sid, smsApplicationSid, smsFallbackMethod, smsFallbackUrl, smsMethod, smsUrl, statusCallback, statusCallbackMethod, trunkSid, uri, voiceReceiveMode, voiceApplicationSid, voiceCallerIdLookup, voiceFallbackMethod, voiceFallbackUrl, voiceMethod, voiceUrl, emergencyStatus, emergencyAddressSid, emergencyAddressStatus, bundleSid, status); + return Objects.hash( + accountSid, + addressSid, + addressRequirements, + apiVersion, + beta, + capabilities, + dateCreated, + dateUpdated, + friendlyName, + identitySid, + phoneNumber, + origin, + sid, + smsApplicationSid, + smsFallbackMethod, + smsFallbackUrl, + smsMethod, + smsUrl, + statusCallback, + statusCallbackMethod, + trunkSid, + uri, + voiceReceiveMode, + voiceApplicationSid, + voiceCallerIdLookup, + voiceFallbackMethod, + voiceFallbackUrl, + voiceMethod, + voiceUrl, + emergencyStatus, + emergencyAddressSid, + emergencyAddressStatus, + bundleSid, + status + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/IncomingPhoneNumberCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/IncomingPhoneNumberCreator.java index b7e72f7862..b60c4deb83 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/IncomingPhoneNumberCreator.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/IncomingPhoneNumberCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010.account; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -25,12 +26,10 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.net.URI; - - - import java.net.URI; -public class IncomingPhoneNumberCreator extends Creator{ +public class IncomingPhoneNumberCreator extends Creator { + private String pathAccountSid; private String apiVersion; private String friendlyName; @@ -57,264 +56,346 @@ public class IncomingPhoneNumberCreator extends Creator{ private com.twilio.type.PhoneNumber phoneNumber; private String areaCode; - public IncomingPhoneNumberCreator(final com.twilio.type.PhoneNumber phoneNumber) { + public IncomingPhoneNumberCreator( + final com.twilio.type.PhoneNumber phoneNumber + ) { this.phoneNumber = phoneNumber; } - public IncomingPhoneNumberCreator(final String pathAccountSid, final com.twilio.type.PhoneNumber phoneNumber) { + + public IncomingPhoneNumberCreator( + final String pathAccountSid, + final com.twilio.type.PhoneNumber phoneNumber + ) { this.pathAccountSid = pathAccountSid; this.phoneNumber = phoneNumber; } + public IncomingPhoneNumberCreator(final String areaCode) { this.areaCode = areaCode; } - public IncomingPhoneNumberCreator(final String pathAccountSid, final String areaCode) { + + public IncomingPhoneNumberCreator( + final String pathAccountSid, + final String areaCode + ) { this.pathAccountSid = pathAccountSid; this.areaCode = areaCode; } - public IncomingPhoneNumberCreator setApiVersion(final String apiVersion){ + public IncomingPhoneNumberCreator setApiVersion(final String apiVersion) { this.apiVersion = apiVersion; return this; } - public IncomingPhoneNumberCreator setFriendlyName(final String friendlyName){ + + public IncomingPhoneNumberCreator setFriendlyName( + final String friendlyName + ) { this.friendlyName = friendlyName; return this; } - public IncomingPhoneNumberCreator setSmsApplicationSid(final String smsApplicationSid){ + + public IncomingPhoneNumberCreator setSmsApplicationSid( + final String smsApplicationSid + ) { this.smsApplicationSid = smsApplicationSid; return this; } - public IncomingPhoneNumberCreator setSmsFallbackMethod(final HttpMethod smsFallbackMethod){ + + public IncomingPhoneNumberCreator setSmsFallbackMethod( + final HttpMethod smsFallbackMethod + ) { this.smsFallbackMethod = smsFallbackMethod; return this; } - public IncomingPhoneNumberCreator setSmsFallbackUrl(final URI smsFallbackUrl){ + + public IncomingPhoneNumberCreator setSmsFallbackUrl( + final URI smsFallbackUrl + ) { this.smsFallbackUrl = smsFallbackUrl; return this; } - public IncomingPhoneNumberCreator setSmsFallbackUrl(final String smsFallbackUrl){ + public IncomingPhoneNumberCreator setSmsFallbackUrl( + final String smsFallbackUrl + ) { return setSmsFallbackUrl(Promoter.uriFromString(smsFallbackUrl)); } - public IncomingPhoneNumberCreator setSmsMethod(final HttpMethod smsMethod){ + + public IncomingPhoneNumberCreator setSmsMethod(final HttpMethod smsMethod) { this.smsMethod = smsMethod; return this; } - public IncomingPhoneNumberCreator setSmsUrl(final URI smsUrl){ + + public IncomingPhoneNumberCreator setSmsUrl(final URI smsUrl) { this.smsUrl = smsUrl; return this; } - public IncomingPhoneNumberCreator setSmsUrl(final String smsUrl){ + public IncomingPhoneNumberCreator setSmsUrl(final String smsUrl) { return setSmsUrl(Promoter.uriFromString(smsUrl)); } - public IncomingPhoneNumberCreator setStatusCallback(final URI statusCallback){ + + public IncomingPhoneNumberCreator setStatusCallback( + final URI statusCallback + ) { this.statusCallback = statusCallback; return this; } - public IncomingPhoneNumberCreator setStatusCallback(final String statusCallback){ + public IncomingPhoneNumberCreator setStatusCallback( + final String statusCallback + ) { return setStatusCallback(Promoter.uriFromString(statusCallback)); } - public IncomingPhoneNumberCreator setStatusCallbackMethod(final HttpMethod statusCallbackMethod){ + + public IncomingPhoneNumberCreator setStatusCallbackMethod( + final HttpMethod statusCallbackMethod + ) { this.statusCallbackMethod = statusCallbackMethod; return this; } - public IncomingPhoneNumberCreator setVoiceApplicationSid(final String voiceApplicationSid){ + + public IncomingPhoneNumberCreator setVoiceApplicationSid( + final String voiceApplicationSid + ) { this.voiceApplicationSid = voiceApplicationSid; return this; } - public IncomingPhoneNumberCreator setVoiceCallerIdLookup(final Boolean voiceCallerIdLookup){ + + public IncomingPhoneNumberCreator setVoiceCallerIdLookup( + final Boolean voiceCallerIdLookup + ) { this.voiceCallerIdLookup = voiceCallerIdLookup; return this; } - public IncomingPhoneNumberCreator setVoiceFallbackMethod(final HttpMethod voiceFallbackMethod){ + + public IncomingPhoneNumberCreator setVoiceFallbackMethod( + final HttpMethod voiceFallbackMethod + ) { this.voiceFallbackMethod = voiceFallbackMethod; return this; } - public IncomingPhoneNumberCreator setVoiceFallbackUrl(final URI voiceFallbackUrl){ + + public IncomingPhoneNumberCreator setVoiceFallbackUrl( + final URI voiceFallbackUrl + ) { this.voiceFallbackUrl = voiceFallbackUrl; return this; } - public IncomingPhoneNumberCreator setVoiceFallbackUrl(final String voiceFallbackUrl){ + public IncomingPhoneNumberCreator setVoiceFallbackUrl( + final String voiceFallbackUrl + ) { return setVoiceFallbackUrl(Promoter.uriFromString(voiceFallbackUrl)); } - public IncomingPhoneNumberCreator setVoiceMethod(final HttpMethod voiceMethod){ + + public IncomingPhoneNumberCreator setVoiceMethod( + final HttpMethod voiceMethod + ) { this.voiceMethod = voiceMethod; return this; } - public IncomingPhoneNumberCreator setVoiceUrl(final URI voiceUrl){ + + public IncomingPhoneNumberCreator setVoiceUrl(final URI voiceUrl) { this.voiceUrl = voiceUrl; return this; } - public IncomingPhoneNumberCreator setVoiceUrl(final String voiceUrl){ + public IncomingPhoneNumberCreator setVoiceUrl(final String voiceUrl) { return setVoiceUrl(Promoter.uriFromString(voiceUrl)); } - public IncomingPhoneNumberCreator setEmergencyStatus(final IncomingPhoneNumber.EmergencyStatus emergencyStatus){ + + public IncomingPhoneNumberCreator setEmergencyStatus( + final IncomingPhoneNumber.EmergencyStatus emergencyStatus + ) { this.emergencyStatus = emergencyStatus; return this; } - public IncomingPhoneNumberCreator setEmergencyAddressSid(final String emergencyAddressSid){ + + public IncomingPhoneNumberCreator setEmergencyAddressSid( + final String emergencyAddressSid + ) { this.emergencyAddressSid = emergencyAddressSid; return this; } - public IncomingPhoneNumberCreator setTrunkSid(final String trunkSid){ + + public IncomingPhoneNumberCreator setTrunkSid(final String trunkSid) { this.trunkSid = trunkSid; return this; } - public IncomingPhoneNumberCreator setIdentitySid(final String identitySid){ + + public IncomingPhoneNumberCreator setIdentitySid(final String identitySid) { this.identitySid = identitySid; return this; } - public IncomingPhoneNumberCreator setAddressSid(final String addressSid){ + + public IncomingPhoneNumberCreator setAddressSid(final String addressSid) { this.addressSid = addressSid; return this; } - public IncomingPhoneNumberCreator setVoiceReceiveMode(final IncomingPhoneNumber.VoiceReceiveMode voiceReceiveMode){ + + public IncomingPhoneNumberCreator setVoiceReceiveMode( + final IncomingPhoneNumber.VoiceReceiveMode voiceReceiveMode + ) { this.voiceReceiveMode = voiceReceiveMode; return this; } - public IncomingPhoneNumberCreator setBundleSid(final String bundleSid){ + + public IncomingPhoneNumberCreator setBundleSid(final String bundleSid) { this.bundleSid = bundleSid; return this; } - public IncomingPhoneNumberCreator setPhoneNumber(final com.twilio.type.PhoneNumber phoneNumber){ + + public IncomingPhoneNumberCreator setPhoneNumber( + final com.twilio.type.PhoneNumber phoneNumber + ) { this.phoneNumber = phoneNumber; return this; } - public IncomingPhoneNumberCreator setPhoneNumber(final String phoneNumber){ + public IncomingPhoneNumberCreator setPhoneNumber(final String phoneNumber) { return setPhoneNumber(Promoter.phoneNumberFromString(phoneNumber)); } - public IncomingPhoneNumberCreator setAreaCode(final String areaCode){ + + public IncomingPhoneNumberCreator setAreaCode(final String areaCode) { this.areaCode = areaCode; return this; } @Override - public IncomingPhoneNumber create(final TwilioRestClient client){ - String path = "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers.json"; + public IncomingPhoneNumber create(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.API.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("IncomingPhoneNumber creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "IncomingPhoneNumber creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return IncomingPhoneNumber.fromJson(response.getStream(), client.getObjectMapper()); + return IncomingPhoneNumber.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (apiVersion != null) { request.addPostParam("ApiVersion", apiVersion); - } if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (smsApplicationSid != null) { request.addPostParam("SmsApplicationSid", smsApplicationSid); - } if (smsFallbackMethod != null) { - request.addPostParam("SmsFallbackMethod", smsFallbackMethod.toString()); - + request.addPostParam( + "SmsFallbackMethod", + smsFallbackMethod.toString() + ); } if (smsFallbackUrl != null) { request.addPostParam("SmsFallbackUrl", smsFallbackUrl.toString()); - } if (smsMethod != null) { request.addPostParam("SmsMethod", smsMethod.toString()); - } if (smsUrl != null) { request.addPostParam("SmsUrl", smsUrl.toString()); - } if (statusCallback != null) { request.addPostParam("StatusCallback", statusCallback.toString()); - } if (statusCallbackMethod != null) { - request.addPostParam("StatusCallbackMethod", statusCallbackMethod.toString()); - + request.addPostParam( + "StatusCallbackMethod", + statusCallbackMethod.toString() + ); } if (voiceApplicationSid != null) { request.addPostParam("VoiceApplicationSid", voiceApplicationSid); - } if (voiceCallerIdLookup != null) { - request.addPostParam("VoiceCallerIdLookup", voiceCallerIdLookup.toString()); - + request.addPostParam( + "VoiceCallerIdLookup", + voiceCallerIdLookup.toString() + ); } if (voiceFallbackMethod != null) { - request.addPostParam("VoiceFallbackMethod", voiceFallbackMethod.toString()); - + request.addPostParam( + "VoiceFallbackMethod", + voiceFallbackMethod.toString() + ); } if (voiceFallbackUrl != null) { - request.addPostParam("VoiceFallbackUrl", voiceFallbackUrl.toString()); - + request.addPostParam( + "VoiceFallbackUrl", + voiceFallbackUrl.toString() + ); } if (voiceMethod != null) { request.addPostParam("VoiceMethod", voiceMethod.toString()); - } if (voiceUrl != null) { request.addPostParam("VoiceUrl", voiceUrl.toString()); - } if (emergencyStatus != null) { request.addPostParam("EmergencyStatus", emergencyStatus.toString()); - } if (emergencyAddressSid != null) { request.addPostParam("EmergencyAddressSid", emergencyAddressSid); - } if (trunkSid != null) { request.addPostParam("TrunkSid", trunkSid); - } if (identitySid != null) { request.addPostParam("IdentitySid", identitySid); - } if (addressSid != null) { request.addPostParam("AddressSid", addressSid); - } if (voiceReceiveMode != null) { - request.addPostParam("VoiceReceiveMode", voiceReceiveMode.toString()); - + request.addPostParam( + "VoiceReceiveMode", + voiceReceiveMode.toString() + ); } if (bundleSid != null) { request.addPostParam("BundleSid", bundleSid); - } if (phoneNumber != null) { request.addPostParam("PhoneNumber", phoneNumber.toString()); - } if (areaCode != null) { request.addPostParam("AreaCode", areaCode); - } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/IncomingPhoneNumberDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/IncomingPhoneNumberDeleter.java index d496e83aa6..25132f9fac 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/IncomingPhoneNumberDeleter.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/IncomingPhoneNumberDeleter.java @@ -24,28 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class IncomingPhoneNumberDeleter extends Deleter { + private String pathSid; private String pathAccountSid; - public IncomingPhoneNumberDeleter(final String pathSid){ + public IncomingPhoneNumberDeleter(final String pathSid) { this.pathSid = pathSid; } - public IncomingPhoneNumberDeleter(final String pathAccountSid, final String pathSid){ + + public IncomingPhoneNumberDeleter( + final String pathAccountSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{Sid}.json"; + String path = + "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -55,9 +65,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("IncomingPhoneNumber delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "IncomingPhoneNumber delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/IncomingPhoneNumberFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/IncomingPhoneNumberFetcher.java index f1c646734d..50a05b53a6 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/IncomingPhoneNumberFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/IncomingPhoneNumberFetcher.java @@ -24,29 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class IncomingPhoneNumberFetcher extends Fetcher { + private String pathSid; private String pathAccountSid; - public IncomingPhoneNumberFetcher(final String pathSid){ + public IncomingPhoneNumberFetcher(final String pathSid) { this.pathSid = pathSid; } - public IncomingPhoneNumberFetcher(final String pathAccountSid, final String pathSid){ + + public IncomingPhoneNumberFetcher( + final String pathAccountSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - @Override public IncomingPhoneNumber fetch(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{Sid}.json"; + String path = + "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -56,15 +65,23 @@ public IncomingPhoneNumber fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("IncomingPhoneNumber fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "IncomingPhoneNumber fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return IncomingPhoneNumber.fromJson(response.getStream(), client.getObjectMapper()); + return IncomingPhoneNumber.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/IncomingPhoneNumberReader.java b/src/main/java/com/twilio/rest/api/v2010/account/IncomingPhoneNumberReader.java index 4da1c32b0b..81e04cb5ea 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/IncomingPhoneNumberReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/IncomingPhoneNumberReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.api.v2010.account; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.converter.Promoter; @@ -25,11 +26,9 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class IncomingPhoneNumberReader extends Reader { + private String pathAccountSid; private Boolean beta; private String friendlyName; @@ -37,46 +36,64 @@ public class IncomingPhoneNumberReader extends Reader { private String origin; private Integer pageSize; - public IncomingPhoneNumberReader(){ - } - public IncomingPhoneNumberReader(final String pathAccountSid){ + public IncomingPhoneNumberReader() {} + + public IncomingPhoneNumberReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - public IncomingPhoneNumberReader setBeta(final Boolean beta){ + public IncomingPhoneNumberReader setBeta(final Boolean beta) { this.beta = beta; return this; } - public IncomingPhoneNumberReader setFriendlyName(final String friendlyName){ + + public IncomingPhoneNumberReader setFriendlyName( + final String friendlyName + ) { this.friendlyName = friendlyName; return this; } - public IncomingPhoneNumberReader setPhoneNumber(final com.twilio.type.PhoneNumber phoneNumber){ + + public IncomingPhoneNumberReader setPhoneNumber( + final com.twilio.type.PhoneNumber phoneNumber + ) { this.phoneNumber = phoneNumber; return this; } - public IncomingPhoneNumberReader setPhoneNumber(final String phoneNumber){ + public IncomingPhoneNumberReader setPhoneNumber(final String phoneNumber) { return setPhoneNumber(Promoter.phoneNumberFromString(phoneNumber)); } - public IncomingPhoneNumberReader setOrigin(final String origin){ + + public IncomingPhoneNumberReader setOrigin(final String origin) { this.origin = origin; return this; } - public IncomingPhoneNumberReader setPageSize(final Integer pageSize){ + + public IncomingPhoneNumberReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @Override - public ResourceSet read(final TwilioRestClient client) { + public ResourceSet read( + final TwilioRestClient client + ) { return new ResourceSet<>(this, client, firstPage(client)); } public Page firstPage(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); + String path = + "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers.json"; + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -88,13 +105,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("IncomingPhoneNumber read failed: Unable to connect to server"); + throw new ApiConnectionException( + "IncomingPhoneNumber read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -110,7 +135,10 @@ private Page pageForRequest(final TwilioRestClient client, } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.API.toString()) @@ -118,9 +146,11 @@ public Page previousPage(final Page pa return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.API.toString()) @@ -129,37 +159,33 @@ public Page nextPage(final Page page, } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (beta != null) { - request.addQueryParam("Beta", beta.toString()); } if (friendlyName != null) { - request.addQueryParam("FriendlyName", friendlyName); } if (phoneNumber != null) { - request.addQueryParam("PhoneNumber", phoneNumber.toString()); } if (origin != null) { - request.addQueryParam("Origin", origin); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/IncomingPhoneNumberUpdater.java b/src/main/java/com/twilio/rest/api/v2010/account/IncomingPhoneNumberUpdater.java index 39813a0216..78f365e2d5 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/IncomingPhoneNumberUpdater.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/IncomingPhoneNumberUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010.account; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -24,12 +25,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.net.URI; +public class IncomingPhoneNumberUpdater extends Updater { - -public class IncomingPhoneNumberUpdater extends Updater{ private String pathSid; private String pathAccountSid; private String accountSid; @@ -56,246 +55,319 @@ public class IncomingPhoneNumberUpdater extends Updater{ private String addressSid; private String bundleSid; - public IncomingPhoneNumberUpdater(final String pathSid){ + public IncomingPhoneNumberUpdater(final String pathSid) { this.pathSid = pathSid; } - public IncomingPhoneNumberUpdater(final String pathAccountSid, final String pathSid){ + + public IncomingPhoneNumberUpdater( + final String pathAccountSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - public IncomingPhoneNumberUpdater setAccountSid(final String accountSid){ + public IncomingPhoneNumberUpdater setAccountSid(final String accountSid) { this.accountSid = accountSid; return this; } - public IncomingPhoneNumberUpdater setApiVersion(final String apiVersion){ + + public IncomingPhoneNumberUpdater setApiVersion(final String apiVersion) { this.apiVersion = apiVersion; return this; } - public IncomingPhoneNumberUpdater setFriendlyName(final String friendlyName){ + + public IncomingPhoneNumberUpdater setFriendlyName( + final String friendlyName + ) { this.friendlyName = friendlyName; return this; } - public IncomingPhoneNumberUpdater setSmsApplicationSid(final String smsApplicationSid){ + + public IncomingPhoneNumberUpdater setSmsApplicationSid( + final String smsApplicationSid + ) { this.smsApplicationSid = smsApplicationSid; return this; } - public IncomingPhoneNumberUpdater setSmsFallbackMethod(final HttpMethod smsFallbackMethod){ + + public IncomingPhoneNumberUpdater setSmsFallbackMethod( + final HttpMethod smsFallbackMethod + ) { this.smsFallbackMethod = smsFallbackMethod; return this; } - public IncomingPhoneNumberUpdater setSmsFallbackUrl(final URI smsFallbackUrl){ + + public IncomingPhoneNumberUpdater setSmsFallbackUrl( + final URI smsFallbackUrl + ) { this.smsFallbackUrl = smsFallbackUrl; return this; } - public IncomingPhoneNumberUpdater setSmsFallbackUrl(final String smsFallbackUrl){ + public IncomingPhoneNumberUpdater setSmsFallbackUrl( + final String smsFallbackUrl + ) { return setSmsFallbackUrl(Promoter.uriFromString(smsFallbackUrl)); } - public IncomingPhoneNumberUpdater setSmsMethod(final HttpMethod smsMethod){ + + public IncomingPhoneNumberUpdater setSmsMethod(final HttpMethod smsMethod) { this.smsMethod = smsMethod; return this; } - public IncomingPhoneNumberUpdater setSmsUrl(final URI smsUrl){ + + public IncomingPhoneNumberUpdater setSmsUrl(final URI smsUrl) { this.smsUrl = smsUrl; return this; } - public IncomingPhoneNumberUpdater setSmsUrl(final String smsUrl){ + public IncomingPhoneNumberUpdater setSmsUrl(final String smsUrl) { return setSmsUrl(Promoter.uriFromString(smsUrl)); } - public IncomingPhoneNumberUpdater setStatusCallback(final URI statusCallback){ + + public IncomingPhoneNumberUpdater setStatusCallback( + final URI statusCallback + ) { this.statusCallback = statusCallback; return this; } - public IncomingPhoneNumberUpdater setStatusCallback(final String statusCallback){ + public IncomingPhoneNumberUpdater setStatusCallback( + final String statusCallback + ) { return setStatusCallback(Promoter.uriFromString(statusCallback)); } - public IncomingPhoneNumberUpdater setStatusCallbackMethod(final HttpMethod statusCallbackMethod){ + + public IncomingPhoneNumberUpdater setStatusCallbackMethod( + final HttpMethod statusCallbackMethod + ) { this.statusCallbackMethod = statusCallbackMethod; return this; } - public IncomingPhoneNumberUpdater setVoiceApplicationSid(final String voiceApplicationSid){ + + public IncomingPhoneNumberUpdater setVoiceApplicationSid( + final String voiceApplicationSid + ) { this.voiceApplicationSid = voiceApplicationSid; return this; } - public IncomingPhoneNumberUpdater setVoiceCallerIdLookup(final Boolean voiceCallerIdLookup){ + + public IncomingPhoneNumberUpdater setVoiceCallerIdLookup( + final Boolean voiceCallerIdLookup + ) { this.voiceCallerIdLookup = voiceCallerIdLookup; return this; } - public IncomingPhoneNumberUpdater setVoiceFallbackMethod(final HttpMethod voiceFallbackMethod){ + + public IncomingPhoneNumberUpdater setVoiceFallbackMethod( + final HttpMethod voiceFallbackMethod + ) { this.voiceFallbackMethod = voiceFallbackMethod; return this; } - public IncomingPhoneNumberUpdater setVoiceFallbackUrl(final URI voiceFallbackUrl){ + + public IncomingPhoneNumberUpdater setVoiceFallbackUrl( + final URI voiceFallbackUrl + ) { this.voiceFallbackUrl = voiceFallbackUrl; return this; } - public IncomingPhoneNumberUpdater setVoiceFallbackUrl(final String voiceFallbackUrl){ + public IncomingPhoneNumberUpdater setVoiceFallbackUrl( + final String voiceFallbackUrl + ) { return setVoiceFallbackUrl(Promoter.uriFromString(voiceFallbackUrl)); } - public IncomingPhoneNumberUpdater setVoiceMethod(final HttpMethod voiceMethod){ + + public IncomingPhoneNumberUpdater setVoiceMethod( + final HttpMethod voiceMethod + ) { this.voiceMethod = voiceMethod; return this; } - public IncomingPhoneNumberUpdater setVoiceUrl(final URI voiceUrl){ + + public IncomingPhoneNumberUpdater setVoiceUrl(final URI voiceUrl) { this.voiceUrl = voiceUrl; return this; } - public IncomingPhoneNumberUpdater setVoiceUrl(final String voiceUrl){ + public IncomingPhoneNumberUpdater setVoiceUrl(final String voiceUrl) { return setVoiceUrl(Promoter.uriFromString(voiceUrl)); } - public IncomingPhoneNumberUpdater setEmergencyStatus(final IncomingPhoneNumber.EmergencyStatus emergencyStatus){ + + public IncomingPhoneNumberUpdater setEmergencyStatus( + final IncomingPhoneNumber.EmergencyStatus emergencyStatus + ) { this.emergencyStatus = emergencyStatus; return this; } - public IncomingPhoneNumberUpdater setEmergencyAddressSid(final String emergencyAddressSid){ + + public IncomingPhoneNumberUpdater setEmergencyAddressSid( + final String emergencyAddressSid + ) { this.emergencyAddressSid = emergencyAddressSid; return this; } - public IncomingPhoneNumberUpdater setTrunkSid(final String trunkSid){ + + public IncomingPhoneNumberUpdater setTrunkSid(final String trunkSid) { this.trunkSid = trunkSid; return this; } - public IncomingPhoneNumberUpdater setVoiceReceiveMode(final IncomingPhoneNumber.VoiceReceiveMode voiceReceiveMode){ + + public IncomingPhoneNumberUpdater setVoiceReceiveMode( + final IncomingPhoneNumber.VoiceReceiveMode voiceReceiveMode + ) { this.voiceReceiveMode = voiceReceiveMode; return this; } - public IncomingPhoneNumberUpdater setIdentitySid(final String identitySid){ + + public IncomingPhoneNumberUpdater setIdentitySid(final String identitySid) { this.identitySid = identitySid; return this; } - public IncomingPhoneNumberUpdater setAddressSid(final String addressSid){ + + public IncomingPhoneNumberUpdater setAddressSid(final String addressSid) { this.addressSid = addressSid; return this; } - public IncomingPhoneNumberUpdater setBundleSid(final String bundleSid){ + + public IncomingPhoneNumberUpdater setBundleSid(final String bundleSid) { this.bundleSid = bundleSid; return this; } @Override - public IncomingPhoneNumber update(final TwilioRestClient client){ - String path = "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{Sid}.json"; + public IncomingPhoneNumber update(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.API.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("IncomingPhoneNumber update failed: Unable to connect to server"); + throw new ApiConnectionException( + "IncomingPhoneNumber update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return IncomingPhoneNumber.fromJson(response.getStream(), client.getObjectMapper()); + return IncomingPhoneNumber.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (accountSid != null) { request.addPostParam("AccountSid", accountSid); - } if (apiVersion != null) { request.addPostParam("ApiVersion", apiVersion); - } if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (smsApplicationSid != null) { request.addPostParam("SmsApplicationSid", smsApplicationSid); - } if (smsFallbackMethod != null) { - request.addPostParam("SmsFallbackMethod", smsFallbackMethod.toString()); - + request.addPostParam( + "SmsFallbackMethod", + smsFallbackMethod.toString() + ); } if (smsFallbackUrl != null) { request.addPostParam("SmsFallbackUrl", smsFallbackUrl.toString()); - } if (smsMethod != null) { request.addPostParam("SmsMethod", smsMethod.toString()); - } if (smsUrl != null) { request.addPostParam("SmsUrl", smsUrl.toString()); - } if (statusCallback != null) { request.addPostParam("StatusCallback", statusCallback.toString()); - } if (statusCallbackMethod != null) { - request.addPostParam("StatusCallbackMethod", statusCallbackMethod.toString()); - + request.addPostParam( + "StatusCallbackMethod", + statusCallbackMethod.toString() + ); } if (voiceApplicationSid != null) { request.addPostParam("VoiceApplicationSid", voiceApplicationSid); - } if (voiceCallerIdLookup != null) { - request.addPostParam("VoiceCallerIdLookup", voiceCallerIdLookup.toString()); - + request.addPostParam( + "VoiceCallerIdLookup", + voiceCallerIdLookup.toString() + ); } if (voiceFallbackMethod != null) { - request.addPostParam("VoiceFallbackMethod", voiceFallbackMethod.toString()); - + request.addPostParam( + "VoiceFallbackMethod", + voiceFallbackMethod.toString() + ); } if (voiceFallbackUrl != null) { - request.addPostParam("VoiceFallbackUrl", voiceFallbackUrl.toString()); - + request.addPostParam( + "VoiceFallbackUrl", + voiceFallbackUrl.toString() + ); } if (voiceMethod != null) { request.addPostParam("VoiceMethod", voiceMethod.toString()); - } if (voiceUrl != null) { request.addPostParam("VoiceUrl", voiceUrl.toString()); - } if (emergencyStatus != null) { request.addPostParam("EmergencyStatus", emergencyStatus.toString()); - } if (emergencyAddressSid != null) { request.addPostParam("EmergencyAddressSid", emergencyAddressSid); - } if (trunkSid != null) { request.addPostParam("TrunkSid", trunkSid); - } if (voiceReceiveMode != null) { - request.addPostParam("VoiceReceiveMode", voiceReceiveMode.toString()); - + request.addPostParam( + "VoiceReceiveMode", + voiceReceiveMode.toString() + ); } if (identitySid != null) { request.addPostParam("IdentitySid", identitySid); - } if (addressSid != null) { request.addPostParam("AddressSid", addressSid); - } if (bundleSid != null) { request.addPostParam("BundleSid", bundleSid); - } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/Key.java b/src/main/java/com/twilio/rest/api/v2010/account/Key.java index ade24c79e2..d4accbbe79 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/Key.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/Key.java @@ -23,60 +23,72 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Key extends Resource { + private static final long serialVersionUID = 35259719636912L; - public static KeyDeleter deleter(final String pathSid){ + public static KeyDeleter deleter(final String pathSid) { return new KeyDeleter(pathSid); } - public static KeyDeleter deleter(final String pathAccountSid, final String pathSid){ + + public static KeyDeleter deleter( + final String pathAccountSid, + final String pathSid + ) { return new KeyDeleter(pathAccountSid, pathSid); } - public static KeyFetcher fetcher(final String pathSid){ + public static KeyFetcher fetcher(final String pathSid) { return new KeyFetcher(pathSid); } - public static KeyFetcher fetcher(final String pathAccountSid, final String pathSid){ + + public static KeyFetcher fetcher( + final String pathAccountSid, + final String pathSid + ) { return new KeyFetcher(pathAccountSid, pathSid); } - public static KeyReader reader(){ + public static KeyReader reader() { return new KeyReader(); } - public static KeyReader reader(final String pathAccountSid){ + + public static KeyReader reader(final String pathAccountSid) { return new KeyReader(pathAccountSid); } - public static KeyUpdater updater(final String pathSid){ + public static KeyUpdater updater(final String pathSid) { return new KeyUpdater(pathSid); } - public static KeyUpdater updater(final String pathAccountSid, final String pathSid){ + + public static KeyUpdater updater( + final String pathAccountSid, + final String pathSid + ) { return new KeyUpdater(pathAccountSid, pathSid); } /** - * Converts a JSON String into a Key object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Key object represented by the provided JSON - */ - public static Key fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Key object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Key object represented by the provided JSON + */ + public static Key fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Key.class); @@ -88,14 +100,17 @@ public static Key fromJson(final String json, final ObjectMapper objectMapper) { } /** - * Converts a JSON InputStream into a Key object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Key object represented by the provided JSON - */ - public static Key fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Key object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Key object represented by the provided JSON + */ + public static Key fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Key.class); @@ -113,17 +128,10 @@ public static Key fromJson(final InputStream json, final ObjectMapper objectMapp @JsonCreator private Key( - @JsonProperty("sid") - final String sid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated + @JsonProperty("sid") final String sid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated ) { this.sid = sid; this.friendlyName = friendlyName; @@ -131,22 +139,25 @@ private Key( this.dateUpdated = DateConverter.rfc2822DateTimeFromString(dateUpdated); } - public final String getSid() { - return this.sid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } + public final String getSid() { + return this.sid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -156,13 +167,16 @@ public boolean equals(final Object o) { Key other = (Key) o; - return Objects.equals(sid, other.sid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) + ); } @Override public int hashCode() { return Objects.hash(sid, friendlyName, dateCreated, dateUpdated); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/KeyDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/KeyDeleter.java index 5b5ea7075d..a0b7347d71 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/KeyDeleter.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/KeyDeleter.java @@ -24,28 +24,34 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class KeyDeleter extends Deleter { + private String pathSid; private String pathAccountSid; - public KeyDeleter(final String pathSid){ + public KeyDeleter(final String pathSid) { this.pathSid = pathSid; } - public KeyDeleter(final String pathAccountSid, final String pathSid){ + + public KeyDeleter(final String pathAccountSid, final String pathSid) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/2010-04-01/Accounts/{AccountSid}/Keys/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -55,9 +61,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Key delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Key delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/KeyFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/KeyFetcher.java index b6ed114077..a5c68753d1 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/KeyFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/KeyFetcher.java @@ -24,29 +24,34 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class KeyFetcher extends Fetcher { + private String pathSid; private String pathAccountSid; - public KeyFetcher(final String pathSid){ + public KeyFetcher(final String pathSid) { this.pathSid = pathSid; } - public KeyFetcher(final String pathAccountSid, final String pathSid){ + + public KeyFetcher(final String pathAccountSid, final String pathSid) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - @Override public Key fetch(final TwilioRestClient client) { String path = "/2010-04-01/Accounts/{AccountSid}/Keys/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -56,9 +61,14 @@ public Key fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Key fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Key fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/KeyReader.java b/src/main/java/com/twilio/rest/api/v2010/account/KeyReader.java index 22f54d78f4..e2ad56e092 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/KeyReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/KeyReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.api.v2010.account; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,21 +25,19 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class KeyReader extends Reader { + private String pathAccountSid; private Integer pageSize; - public KeyReader(){ - } - public KeyReader(final String pathAccountSid){ + public KeyReader() {} + + public KeyReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - public KeyReader setPageSize(final Integer pageSize){ + public KeyReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -50,8 +49,15 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/2010-04-01/Accounts/{AccountSid}/Keys.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -63,13 +69,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Key read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Key read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -85,7 +99,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request re } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.API.toString()) @@ -93,9 +110,11 @@ public Page previousPage(final Page page, final TwilioRestClient clien return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.API.toString()) @@ -104,21 +123,21 @@ public Page nextPage(final Page page, final TwilioRestClient client) { } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/KeyUpdater.java b/src/main/java/com/twilio/rest/api/v2010/account/KeyUpdater.java index 45af8ef595..51f20e29c0 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/KeyUpdater.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/KeyUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010.account; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,46 +25,58 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class KeyUpdater extends Updater { - - -public class KeyUpdater extends Updater{ private String pathSid; private String pathAccountSid; private String friendlyName; - public KeyUpdater(final String pathSid){ + public KeyUpdater(final String pathSid) { this.pathSid = pathSid; } - public KeyUpdater(final String pathAccountSid, final String pathSid){ + + public KeyUpdater(final String pathAccountSid, final String pathSid) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - public KeyUpdater setFriendlyName(final String friendlyName){ + public KeyUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } @Override - public Key update(final TwilioRestClient client){ + public Key update(final TwilioRestClient client) { String path = "/2010-04-01/Accounts/{AccountSid}/Keys/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.API.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Key update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Key update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -72,10 +85,10 @@ public Key update(final TwilioRestClient client){ return Key.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/Message.java b/src/main/java/com/twilio/rest/api/v2010/account/Message.java index 26a99ae2bf..c21a614fa5 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/Message.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/Message.java @@ -20,96 +20,161 @@ import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.twilio.base.Resource; -import java.util.Currency; +import com.twilio.converter.CurrencyDeserializer; import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; -import com.twilio.converter.CurrencyDeserializer; import com.twilio.exception.ApiConnectionException; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - +import java.util.Currency; import java.util.List; import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Message extends Resource { + private static final long serialVersionUID = 20600562506098L; - public static MessageCreator creator(final com.twilio.type.PhoneNumber to, final com.twilio.type.PhoneNumber from, final String body){ + public static MessageCreator creator( + final com.twilio.type.PhoneNumber to, + final com.twilio.type.PhoneNumber from, + final String body + ) { return new MessageCreator(to, from, body); } - public static MessageCreator creator(final String pathAccountSid, final com.twilio.type.PhoneNumber to, final com.twilio.type.PhoneNumber from, final String body){ + + public static MessageCreator creator( + final String pathAccountSid, + final com.twilio.type.PhoneNumber to, + final com.twilio.type.PhoneNumber from, + final String body + ) { return new MessageCreator(pathAccountSid, to, from, body); } - public static MessageCreator creator(final com.twilio.type.PhoneNumber to, final com.twilio.type.PhoneNumber from, final List mediaUrl){ + + public static MessageCreator creator( + final com.twilio.type.PhoneNumber to, + final com.twilio.type.PhoneNumber from, + final List mediaUrl + ) { return new MessageCreator(to, from, mediaUrl); } - public static MessageCreator creator(final String pathAccountSid, final com.twilio.type.PhoneNumber to, final com.twilio.type.PhoneNumber from, final List mediaUrl){ + + public static MessageCreator creator( + final String pathAccountSid, + final com.twilio.type.PhoneNumber to, + final com.twilio.type.PhoneNumber from, + final List mediaUrl + ) { return new MessageCreator(pathAccountSid, to, from, mediaUrl); } - public static MessageCreator creator(final com.twilio.type.PhoneNumber to, final String messagingServiceSid, final String body){ + + public static MessageCreator creator( + final com.twilio.type.PhoneNumber to, + final String messagingServiceSid, + final String body + ) { return new MessageCreator(to, messagingServiceSid, body); } - public static MessageCreator creator(final String pathAccountSid, final com.twilio.type.PhoneNumber to, final String messagingServiceSid, final String body){ - return new MessageCreator(pathAccountSid, to, messagingServiceSid, body); + + public static MessageCreator creator( + final String pathAccountSid, + final com.twilio.type.PhoneNumber to, + final String messagingServiceSid, + final String body + ) { + return new MessageCreator( + pathAccountSid, + to, + messagingServiceSid, + body + ); } - public static MessageCreator creator(final com.twilio.type.PhoneNumber to, final String messagingServiceSid, final List mediaUrl){ + + public static MessageCreator creator( + final com.twilio.type.PhoneNumber to, + final String messagingServiceSid, + final List mediaUrl + ) { return new MessageCreator(to, messagingServiceSid, mediaUrl); } - public static MessageCreator creator(final String pathAccountSid, final com.twilio.type.PhoneNumber to, final String messagingServiceSid, final List mediaUrl){ - return new MessageCreator(pathAccountSid, to, messagingServiceSid, mediaUrl); + + public static MessageCreator creator( + final String pathAccountSid, + final com.twilio.type.PhoneNumber to, + final String messagingServiceSid, + final List mediaUrl + ) { + return new MessageCreator( + pathAccountSid, + to, + messagingServiceSid, + mediaUrl + ); } - public static MessageDeleter deleter(final String pathSid){ + public static MessageDeleter deleter(final String pathSid) { return new MessageDeleter(pathSid); } - public static MessageDeleter deleter(final String pathAccountSid, final String pathSid){ + + public static MessageDeleter deleter( + final String pathAccountSid, + final String pathSid + ) { return new MessageDeleter(pathAccountSid, pathSid); } - public static MessageFetcher fetcher(final String pathSid){ + public static MessageFetcher fetcher(final String pathSid) { return new MessageFetcher(pathSid); } - public static MessageFetcher fetcher(final String pathAccountSid, final String pathSid){ + + public static MessageFetcher fetcher( + final String pathAccountSid, + final String pathSid + ) { return new MessageFetcher(pathAccountSid, pathSid); } - public static MessageReader reader(){ + public static MessageReader reader() { return new MessageReader(); } - public static MessageReader reader(final String pathAccountSid){ + + public static MessageReader reader(final String pathAccountSid) { return new MessageReader(pathAccountSid); } - public static MessageUpdater updater(final String pathSid){ + public static MessageUpdater updater(final String pathSid) { return new MessageUpdater(pathSid); } - public static MessageUpdater updater(final String pathAccountSid, final String pathSid){ + + public static MessageUpdater updater( + final String pathAccountSid, + final String pathSid + ) { return new MessageUpdater(pathAccountSid, pathSid); } /** - * Converts a JSON String into a Message object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Message object represented by the provided JSON - */ - public static Message fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Message object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Message object represented by the provided JSON + */ + public static Message fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Message.class); @@ -121,14 +186,17 @@ public static Message fromJson(final String json, final ObjectMapper objectMappe } /** - * Converts a JSON InputStream into a Message object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Message object represented by the provided JSON - */ - public static Message fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Message object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Message object represented by the provided JSON + */ + public static Message fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Message.class); @@ -138,8 +206,10 @@ public static Message fromJson(final InputStream json, final ObjectMapper object throw new ApiConnectionException(e.getMessage(), e); } } + public enum AddressRetention { - RETAIN("retain"); + RETAIN("retain"), + OBFUSCATE("obfuscate"); private final String value; @@ -156,8 +226,10 @@ public static AddressRetention forValue(final String value) { return Promoter.enumFromString(value, AddressRetention.values()); } } + public enum ContentRetention { - RETAIN("retain"); + RETAIN("retain"), + DISCARD("discard"); private final String value; @@ -174,6 +246,7 @@ public static ContentRetention forValue(final String value) { return Promoter.enumFromString(value, ContentRetention.values()); } } + public enum Direction { INBOUND("inbound"), OUTBOUND_API("outbound-api"), @@ -195,6 +268,7 @@ public static Direction forValue(final String value) { return Promoter.enumFromString(value, Direction.values()); } } + public enum ScheduleType { FIXED("fixed"); @@ -213,6 +287,7 @@ public static ScheduleType forValue(final String value) { return Promoter.enumFromString(value, ScheduleType.values()); } } + public enum Status { QUEUED("queued"), SENDING("sending"), @@ -243,6 +318,7 @@ public static Status forValue(final String value) { return Promoter.enumFromString(value, Status.values()); } } + public enum UpdateStatus { CANCELED("canceled"); @@ -285,66 +361,30 @@ public static UpdateStatus forValue(final String value) { @JsonCreator private Message( - @JsonProperty("body") - final String body, - - @JsonProperty("num_segments") - final String numSegments, - - @JsonProperty("direction") - final Message.Direction direction, - - @JsonProperty("from") - final com.twilio.type.PhoneNumber from, - - @JsonProperty("to") - final String to, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("price") - final String price, - - @JsonProperty("error_message") - final String errorMessage, - - @JsonProperty("uri") - final String uri, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("num_media") - final String numMedia, - - @JsonProperty("status") - final Message.Status status, - - @JsonProperty("messaging_service_sid") - final String messagingServiceSid, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("date_sent") - final String dateSent, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("error_code") - final Integer errorCode, - - @JsonProperty("price_unit") - @JsonDeserialize(using = com.twilio.converter.CurrencyDeserializer.class) - final Currency priceUnit, - - @JsonProperty("api_version") - final String apiVersion, - - @JsonProperty("subresource_uris") - final Map subresourceUris + @JsonProperty("body") final String body, + @JsonProperty("num_segments") final String numSegments, + @JsonProperty("direction") final Message.Direction direction, + @JsonProperty("from") final com.twilio.type.PhoneNumber from, + @JsonProperty("to") final String to, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("price") final String price, + @JsonProperty("error_message") final String errorMessage, + @JsonProperty("uri") final String uri, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("num_media") final String numMedia, + @JsonProperty("status") final Message.Status status, + @JsonProperty("messaging_service_sid") final String messagingServiceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("date_sent") final String dateSent, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("error_code") final Integer errorCode, + @JsonProperty("price_unit") @JsonDeserialize( + using = com.twilio.converter.CurrencyDeserializer.class + ) final Currency priceUnit, + @JsonProperty("api_version") final String apiVersion, + @JsonProperty( + "subresource_uris" + ) final Map subresourceUris ) { this.body = body; this.numSegments = numSegments; @@ -368,70 +408,89 @@ private Message( this.subresourceUris = subresourceUris; } - public final String getBody() { - return this.body; - } - public final String getNumSegments() { - return this.numSegments; - } - public final Message.Direction getDirection() { - return this.direction; - } - public final com.twilio.type.PhoneNumber getFrom() { - return this.from; - } - public final String getTo() { - return this.to; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getPrice() { - return this.price; - } - public final String getErrorMessage() { - return this.errorMessage; - } - public final String getUri() { - return this.uri; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getNumMedia() { - return this.numMedia; - } - public final Message.Status getStatus() { - return this.status; - } - public final String getMessagingServiceSid() { - return this.messagingServiceSid; - } - public final String getSid() { - return this.sid; - } - public final ZonedDateTime getDateSent() { - return this.dateSent; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final Integer getErrorCode() { - return this.errorCode; - } - public final Currency getPriceUnit() { - return this.priceUnit; - } - public final String getApiVersion() { - return this.apiVersion; - } - public final Map getSubresourceUris() { - return this.subresourceUris; - } + public final String getBody() { + return this.body; + } + + public final String getNumSegments() { + return this.numSegments; + } + + public final Message.Direction getDirection() { + return this.direction; + } + + public final com.twilio.type.PhoneNumber getFrom() { + return this.from; + } + + public final String getTo() { + return this.to; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getPrice() { + return this.price; + } + + public final String getErrorMessage() { + return this.errorMessage; + } + + public final String getUri() { + return this.uri; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getNumMedia() { + return this.numMedia; + } + + public final Message.Status getStatus() { + return this.status; + } + + public final String getMessagingServiceSid() { + return this.messagingServiceSid; + } + + public final String getSid() { + return this.sid; + } + + public final ZonedDateTime getDateSent() { + return this.dateSent; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final Integer getErrorCode() { + return this.errorCode; + } + + public final Currency getPriceUnit() { + return this.priceUnit; + } + + public final String getApiVersion() { + return this.apiVersion; + } + + public final Map getSubresourceUris() { + return this.subresourceUris; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -441,13 +500,53 @@ public boolean equals(final Object o) { Message other = (Message) o; - return Objects.equals(body, other.body) && Objects.equals(numSegments, other.numSegments) && Objects.equals(direction, other.direction) && Objects.equals(from, other.from) && Objects.equals(to, other.to) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(price, other.price) && Objects.equals(errorMessage, other.errorMessage) && Objects.equals(uri, other.uri) && Objects.equals(accountSid, other.accountSid) && Objects.equals(numMedia, other.numMedia) && Objects.equals(status, other.status) && Objects.equals(messagingServiceSid, other.messagingServiceSid) && Objects.equals(sid, other.sid) && Objects.equals(dateSent, other.dateSent) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(errorCode, other.errorCode) && Objects.equals(priceUnit, other.priceUnit) && Objects.equals(apiVersion, other.apiVersion) && Objects.equals(subresourceUris, other.subresourceUris) ; + return ( + Objects.equals(body, other.body) && + Objects.equals(numSegments, other.numSegments) && + Objects.equals(direction, other.direction) && + Objects.equals(from, other.from) && + Objects.equals(to, other.to) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(price, other.price) && + Objects.equals(errorMessage, other.errorMessage) && + Objects.equals(uri, other.uri) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(numMedia, other.numMedia) && + Objects.equals(status, other.status) && + Objects.equals(messagingServiceSid, other.messagingServiceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(dateSent, other.dateSent) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(errorCode, other.errorCode) && + Objects.equals(priceUnit, other.priceUnit) && + Objects.equals(apiVersion, other.apiVersion) && + Objects.equals(subresourceUris, other.subresourceUris) + ); } @Override public int hashCode() { - return Objects.hash(body, numSegments, direction, from, to, dateUpdated, price, errorMessage, uri, accountSid, numMedia, status, messagingServiceSid, sid, dateSent, dateCreated, errorCode, priceUnit, apiVersion, subresourceUris); + return Objects.hash( + body, + numSegments, + direction, + from, + to, + dateUpdated, + price, + errorMessage, + uri, + accountSid, + numMedia, + status, + messagingServiceSid, + sid, + dateSent, + dateCreated, + errorCode, + priceUnit, + apiVersion, + subresourceUris + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/MessageCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/MessageCreator.java index 64198f2d0e..d54f5da285 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/MessageCreator.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/MessageCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010.account; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -25,17 +26,15 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.math.BigDecimal; -import java.util.List; -import java.time.ZonedDateTime; import java.math.BigDecimal; import java.net.URI; - +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.List; import java.util.List; +public class MessageCreator extends Creator { -import java.net.URI; - -public class MessageCreator extends Creator{ private com.twilio.type.PhoneNumber to; private String pathAccountSid; private URI statusCallback; @@ -60,181 +59,270 @@ public class MessageCreator extends Creator{ private List mediaUrl; private String contentSid; - public MessageCreator(final com.twilio.type.PhoneNumber to, final com.twilio.type.PhoneNumber from, final String body) { + public MessageCreator( + final com.twilio.type.PhoneNumber to, + final com.twilio.type.PhoneNumber from, + final String body + ) { this.to = to; this.from = from; this.body = body; } - public MessageCreator(final String pathAccountSid, final com.twilio.type.PhoneNumber to, final com.twilio.type.PhoneNumber from, final String body) { + + public MessageCreator( + final String pathAccountSid, + final com.twilio.type.PhoneNumber to, + final com.twilio.type.PhoneNumber from, + final String body + ) { this.pathAccountSid = pathAccountSid; this.to = to; this.from = from; this.body = body; } - public MessageCreator(final com.twilio.type.PhoneNumber to, final com.twilio.type.PhoneNumber from, final List mediaUrl) { + + public MessageCreator( + final com.twilio.type.PhoneNumber to, + final com.twilio.type.PhoneNumber from, + final List mediaUrl + ) { this.to = to; this.from = from; this.mediaUrl = mediaUrl; } - public MessageCreator(final String pathAccountSid, final com.twilio.type.PhoneNumber to, final com.twilio.type.PhoneNumber from, final List mediaUrl) { + + public MessageCreator( + final String pathAccountSid, + final com.twilio.type.PhoneNumber to, + final com.twilio.type.PhoneNumber from, + final List mediaUrl + ) { this.pathAccountSid = pathAccountSid; this.to = to; this.from = from; this.mediaUrl = mediaUrl; } - public MessageCreator(final com.twilio.type.PhoneNumber to, final String messagingServiceSid, final String body) { + + public MessageCreator( + final com.twilio.type.PhoneNumber to, + final String messagingServiceSid, + final String body + ) { this.to = to; this.messagingServiceSid = messagingServiceSid; this.body = body; } - public MessageCreator(final String pathAccountSid, final com.twilio.type.PhoneNumber to, final String messagingServiceSid, final String body) { + + public MessageCreator( + final String pathAccountSid, + final com.twilio.type.PhoneNumber to, + final String messagingServiceSid, + final String body + ) { this.pathAccountSid = pathAccountSid; this.to = to; this.messagingServiceSid = messagingServiceSid; this.body = body; } - public MessageCreator(final com.twilio.type.PhoneNumber to, final String messagingServiceSid, final List mediaUrl) { + + public MessageCreator( + final com.twilio.type.PhoneNumber to, + final String messagingServiceSid, + final List mediaUrl + ) { this.to = to; this.messagingServiceSid = messagingServiceSid; this.mediaUrl = mediaUrl; } - public MessageCreator(final String pathAccountSid, final com.twilio.type.PhoneNumber to, final String messagingServiceSid, final List mediaUrl) { + + public MessageCreator( + final String pathAccountSid, + final com.twilio.type.PhoneNumber to, + final String messagingServiceSid, + final List mediaUrl + ) { this.pathAccountSid = pathAccountSid; this.to = to; this.messagingServiceSid = messagingServiceSid; this.mediaUrl = mediaUrl; } - public MessageCreator setTo(final com.twilio.type.PhoneNumber to){ + public MessageCreator setTo(final com.twilio.type.PhoneNumber to) { this.to = to; return this; } - public MessageCreator setTo(final String to){ + public MessageCreator setTo(final String to) { return setTo(Promoter.phoneNumberFromString(to)); } - public MessageCreator setStatusCallback(final URI statusCallback){ + + public MessageCreator setStatusCallback(final URI statusCallback) { this.statusCallback = statusCallback; return this; } - public MessageCreator setStatusCallback(final String statusCallback){ + public MessageCreator setStatusCallback(final String statusCallback) { return setStatusCallback(Promoter.uriFromString(statusCallback)); } - public MessageCreator setApplicationSid(final String applicationSid){ + + public MessageCreator setApplicationSid(final String applicationSid) { this.applicationSid = applicationSid; return this; } - public MessageCreator setMaxPrice(final BigDecimal maxPrice){ + + public MessageCreator setMaxPrice(final BigDecimal maxPrice) { this.maxPrice = maxPrice; return this; } - public MessageCreator setProvideFeedback(final Boolean provideFeedback){ + + public MessageCreator setProvideFeedback(final Boolean provideFeedback) { this.provideFeedback = provideFeedback; return this; } - public MessageCreator setAttempt(final Integer attempt){ + + public MessageCreator setAttempt(final Integer attempt) { this.attempt = attempt; return this; } - public MessageCreator setValidityPeriod(final Integer validityPeriod){ + + public MessageCreator setValidityPeriod(final Integer validityPeriod) { this.validityPeriod = validityPeriod; return this; } - public MessageCreator setForceDelivery(final Boolean forceDelivery){ + + public MessageCreator setForceDelivery(final Boolean forceDelivery) { this.forceDelivery = forceDelivery; return this; } - public MessageCreator setContentRetention(final Message.ContentRetention contentRetention){ + + public MessageCreator setContentRetention( + final Message.ContentRetention contentRetention + ) { this.contentRetention = contentRetention; return this; } - public MessageCreator setAddressRetention(final Message.AddressRetention addressRetention){ + + public MessageCreator setAddressRetention( + final Message.AddressRetention addressRetention + ) { this.addressRetention = addressRetention; return this; } - public MessageCreator setSmartEncoded(final Boolean smartEncoded){ + + public MessageCreator setSmartEncoded(final Boolean smartEncoded) { this.smartEncoded = smartEncoded; return this; } - public MessageCreator setPersistentAction(final List persistentAction){ + + public MessageCreator setPersistentAction( + final List persistentAction + ) { this.persistentAction = persistentAction; return this; } - public MessageCreator setPersistentAction(final String persistentAction){ + + public MessageCreator setPersistentAction(final String persistentAction) { return setPersistentAction(Promoter.listOfOne(persistentAction)); } - public MessageCreator setShortenUrls(final Boolean shortenUrls){ + + public MessageCreator setShortenUrls(final Boolean shortenUrls) { this.shortenUrls = shortenUrls; return this; } - public MessageCreator setScheduleType(final Message.ScheduleType scheduleType){ + + public MessageCreator setScheduleType( + final Message.ScheduleType scheduleType + ) { this.scheduleType = scheduleType; return this; } - public MessageCreator setSendAt(final ZonedDateTime sendAt){ + + public MessageCreator setSendAt(final ZonedDateTime sendAt) { this.sendAt = sendAt; return this; } - public MessageCreator setSendAsMms(final Boolean sendAsMms){ + + public MessageCreator setSendAsMms(final Boolean sendAsMms) { this.sendAsMms = sendAsMms; return this; } - public MessageCreator setContentVariables(final String contentVariables){ + + public MessageCreator setContentVariables(final String contentVariables) { this.contentVariables = contentVariables; return this; } - public MessageCreator setFrom(final com.twilio.type.PhoneNumber from){ + + public MessageCreator setFrom(final com.twilio.type.PhoneNumber from) { this.from = from; return this; } - public MessageCreator setFrom(final String from){ + public MessageCreator setFrom(final String from) { return setFrom(Promoter.phoneNumberFromString(from)); } - public MessageCreator setMessagingServiceSid(final String messagingServiceSid){ + + public MessageCreator setMessagingServiceSid( + final String messagingServiceSid + ) { this.messagingServiceSid = messagingServiceSid; return this; } - public MessageCreator setBody(final String body){ + + public MessageCreator setBody(final String body) { this.body = body; return this; } - public MessageCreator setMediaUrl(final List mediaUrl){ + + public MessageCreator setMediaUrl(final List mediaUrl) { this.mediaUrl = mediaUrl; return this; } - public MessageCreator setMediaUrl(final URI mediaUrl){ + + public MessageCreator setMediaUrl(final URI mediaUrl) { return setMediaUrl(Promoter.listOfOne(mediaUrl)); } - public MessageCreator setMediaUrl(final String mediaUrl){ + public MessageCreator setMediaUrl(final String mediaUrl) { return setMediaUrl(Promoter.uriFromString(mediaUrl)); } - public MessageCreator setContentSid(final String contentSid){ + + public MessageCreator setContentSid(final String contentSid) { this.contentSid = contentSid; return this; } @Override - public Message create(final TwilioRestClient client){ + public Message create(final TwilioRestClient client) { String path = "/2010-04-01/Accounts/{AccountSid}/Messages.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"To"+"}", this.to.encode("utf-8")); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "To" + "}", this.to.encode("utf-8")); Request request = new Request( HttpMethod.POST, Domains.API.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Message creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Message creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -243,98 +331,83 @@ public Message create(final TwilioRestClient client){ return Message.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (to != null) { request.addPostParam("To", to.toString()); - } if (statusCallback != null) { request.addPostParam("StatusCallback", statusCallback.toString()); - } if (applicationSid != null) { request.addPostParam("ApplicationSid", applicationSid); - } if (maxPrice != null) { request.addPostParam("MaxPrice", maxPrice.toString()); - } if (provideFeedback != null) { request.addPostParam("ProvideFeedback", provideFeedback.toString()); - } if (attempt != null) { request.addPostParam("Attempt", attempt.toString()); - } if (validityPeriod != null) { request.addPostParam("ValidityPeriod", validityPeriod.toString()); - } if (forceDelivery != null) { request.addPostParam("ForceDelivery", forceDelivery.toString()); - } if (contentRetention != null) { - request.addPostParam("ContentRetention", contentRetention.toString()); - + request.addPostParam( + "ContentRetention", + contentRetention.toString() + ); } if (addressRetention != null) { - request.addPostParam("AddressRetention", addressRetention.toString()); - + request.addPostParam( + "AddressRetention", + addressRetention.toString() + ); } if (smartEncoded != null) { request.addPostParam("SmartEncoded", smartEncoded.toString()); - } if (persistentAction != null) { for (String prop : persistentAction) { request.addPostParam("PersistentAction", prop); } - } if (shortenUrls != null) { request.addPostParam("ShortenUrls", shortenUrls.toString()); - } if (scheduleType != null) { request.addPostParam("ScheduleType", scheduleType.toString()); - } if (sendAt != null) { request.addPostParam("SendAt", sendAt.toInstant().toString()); - } if (sendAsMms != null) { request.addPostParam("SendAsMms", sendAsMms.toString()); - } if (contentVariables != null) { request.addPostParam("ContentVariables", contentVariables); - } if (from != null) { request.addPostParam("From", from.toString()); - } if (messagingServiceSid != null) { request.addPostParam("MessagingServiceSid", messagingServiceSid); - } if (body != null) { request.addPostParam("Body", body); - } if (mediaUrl != null) { for (URI prop : mediaUrl) { request.addPostParam("MediaUrl", prop.toString()); } - } if (contentSid != null) { request.addPostParam("ContentSid", contentSid); - } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/MessageDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/MessageDeleter.java index 4e41764985..1319e9e5ab 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/MessageDeleter.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/MessageDeleter.java @@ -24,28 +24,34 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class MessageDeleter extends Deleter { + private String pathSid; private String pathAccountSid; - public MessageDeleter(final String pathSid){ + public MessageDeleter(final String pathSid) { this.pathSid = pathSid; } - public MessageDeleter(final String pathAccountSid, final String pathSid){ + + public MessageDeleter(final String pathAccountSid, final String pathSid) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/2010-04-01/Accounts/{AccountSid}/Messages/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -55,9 +61,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Message delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Message delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/MessageFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/MessageFetcher.java index 2c2b1a8b88..2ddd2179fd 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/MessageFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/MessageFetcher.java @@ -24,29 +24,34 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class MessageFetcher extends Fetcher { + private String pathSid; private String pathAccountSid; - public MessageFetcher(final String pathSid){ + public MessageFetcher(final String pathSid) { this.pathSid = pathSid; } - public MessageFetcher(final String pathAccountSid, final String pathSid){ + + public MessageFetcher(final String pathAccountSid, final String pathSid) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - @Override public Message fetch(final TwilioRestClient client) { String path = "/2010-04-01/Accounts/{AccountSid}/Messages/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -56,9 +61,14 @@ public Message fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Message fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Message fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/MessageReader.java b/src/main/java/com/twilio/rest/api/v2010/account/MessageReader.java index fc14bea3cf..d059de500f 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/MessageReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/MessageReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.api.v2010.account; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.converter.Promoter; @@ -25,13 +26,11 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; - - public class MessageReader extends Reader { + private String pathAccountSid; private com.twilio.type.PhoneNumber to; private com.twilio.type.PhoneNumber from; @@ -40,41 +39,46 @@ public class MessageReader extends Reader { private ZonedDateTime dateSentAfter; private Integer pageSize; - public MessageReader(){ - } - public MessageReader(final String pathAccountSid){ + public MessageReader() {} + + public MessageReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - public MessageReader setTo(final com.twilio.type.PhoneNumber to){ + public MessageReader setTo(final com.twilio.type.PhoneNumber to) { this.to = to; return this; } - public MessageReader setTo(final String to){ + public MessageReader setTo(final String to) { return setTo(Promoter.phoneNumberFromString(to)); } - public MessageReader setFrom(final com.twilio.type.PhoneNumber from){ + + public MessageReader setFrom(final com.twilio.type.PhoneNumber from) { this.from = from; return this; } - public MessageReader setFrom(final String from){ + public MessageReader setFrom(final String from) { return setFrom(Promoter.phoneNumberFromString(from)); } - public MessageReader setDateSent(final ZonedDateTime dateSent){ + + public MessageReader setDateSent(final ZonedDateTime dateSent) { this.dateSent = dateSent; return this; } - public MessageReader setDateSentBefore(final ZonedDateTime dateSentBefore){ + + public MessageReader setDateSentBefore(final ZonedDateTime dateSentBefore) { this.dateSentBefore = dateSentBefore; return this; } - public MessageReader setDateSentAfter(final ZonedDateTime dateSentAfter){ + + public MessageReader setDateSentAfter(final ZonedDateTime dateSentAfter) { this.dateSentAfter = dateSentAfter; return this; } - public MessageReader setPageSize(final Integer pageSize){ + + public MessageReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -86,8 +90,15 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/2010-04-01/Accounts/{AccountSid}/Messages.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -99,13 +110,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Message read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Message read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -121,7 +140,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reques } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.API.toString()) @@ -129,9 +151,11 @@ public Page previousPage(final Page page, final TwilioRestClie return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.API.toString()) @@ -140,35 +164,43 @@ public Page nextPage(final Page page, final TwilioRestClient c } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (to != null) { - request.addQueryParam("To", to.toString()); } if (from != null) { - request.addQueryParam("From", from.toString()); } if (dateSent != null) { - request.addQueryParam("DateSent", dateSent.format(DateTimeFormatter.ofPattern(Request.QUERY_STRING_DATE_TIME_FORMAT))); - } - else if (dateSentAfter != null || dateSentBefore != null) { - request.addQueryDateTimeRange("DateSent", dateSentAfter, dateSentBefore); + request.addQueryParam( + "DateSent", + dateSent.format( + DateTimeFormatter.ofPattern( + Request.QUERY_STRING_DATE_TIME_FORMAT + ) + ) + ); + } else if (dateSentAfter != null || dateSentBefore != null) { + request.addQueryDateTimeRange( + "DateSent", + dateSentAfter, + dateSentBefore + ); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/MessageUpdater.java b/src/main/java/com/twilio/rest/api/v2010/account/MessageUpdater.java index 6945de3648..a059f30491 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/MessageUpdater.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/MessageUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010.account; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,51 +25,64 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class MessageUpdater extends Updater { - - -public class MessageUpdater extends Updater{ private String pathSid; private String pathAccountSid; private String body; private Message.UpdateStatus status; - public MessageUpdater(final String pathSid){ + public MessageUpdater(final String pathSid) { this.pathSid = pathSid; } - public MessageUpdater(final String pathAccountSid, final String pathSid){ + + public MessageUpdater(final String pathAccountSid, final String pathSid) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - public MessageUpdater setBody(final String body){ + public MessageUpdater setBody(final String body) { this.body = body; return this; } - public MessageUpdater setStatus(final Message.UpdateStatus status){ + + public MessageUpdater setStatus(final Message.UpdateStatus status) { this.status = status; return this; } @Override - public Message update(final TwilioRestClient client){ + public Message update(final TwilioRestClient client) { String path = "/2010-04-01/Accounts/{AccountSid}/Messages/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.API.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Message update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Message update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -77,14 +91,13 @@ public Message update(final TwilioRestClient client){ return Message.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (body != null) { request.addPostParam("Body", body); - } if (status != null) { request.addPostParam("Status", status.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/NewKey.java b/src/main/java/com/twilio/rest/api/v2010/account/NewKey.java index ab96ce7db9..234fe5e285 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/NewKey.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/NewKey.java @@ -23,39 +23,39 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class NewKey extends Resource { + private static final long serialVersionUID = 142441509867514L; - public static NewKeyCreator creator(){ + public static NewKeyCreator creator() { return new NewKeyCreator(); } - public static NewKeyCreator creator(final String pathAccountSid){ + + public static NewKeyCreator creator(final String pathAccountSid) { return new NewKeyCreator(pathAccountSid); } /** - * Converts a JSON String into a NewKey object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return NewKey object represented by the provided JSON - */ - public static NewKey fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a NewKey object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return NewKey object represented by the provided JSON + */ + public static NewKey fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, NewKey.class); @@ -67,14 +67,17 @@ public static NewKey fromJson(final String json, final ObjectMapper objectMapper } /** - * Converts a JSON InputStream into a NewKey object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return NewKey object represented by the provided JSON - */ - public static NewKey fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a NewKey object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return NewKey object represented by the provided JSON + */ + public static NewKey fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, NewKey.class); @@ -93,20 +96,11 @@ public static NewKey fromJson(final InputStream json, final ObjectMapper objectM @JsonCreator private NewKey( - @JsonProperty("sid") - final String sid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("secret") - final String secret + @JsonProperty("sid") final String sid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("secret") final String secret ) { this.sid = sid; this.friendlyName = friendlyName; @@ -115,25 +109,29 @@ private NewKey( this.secret = secret; } - public final String getSid() { - return this.sid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getSecret() { - return this.secret; - } + public final String getSid() { + return this.sid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getSecret() { + return this.secret; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -143,13 +141,23 @@ public boolean equals(final Object o) { NewKey other = (NewKey) o; - return Objects.equals(sid, other.sid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(secret, other.secret) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(secret, other.secret) + ); } @Override public int hashCode() { - return Objects.hash(sid, friendlyName, dateCreated, dateUpdated, secret); + return Objects.hash( + sid, + friendlyName, + dateCreated, + dateUpdated, + secret + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/NewKeyCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/NewKeyCreator.java index 649cde49af..605f0f1ecd 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/NewKeyCreator.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/NewKeyCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010.account; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,42 +25,53 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class NewKeyCreator extends Creator { - - -public class NewKeyCreator extends Creator{ private String pathAccountSid; private String friendlyName; - public NewKeyCreator() { - } + public NewKeyCreator() {} + public NewKeyCreator(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - public NewKeyCreator setFriendlyName(final String friendlyName){ + public NewKeyCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } @Override - public NewKey create(final TwilioRestClient client){ + public NewKey create(final TwilioRestClient client) { String path = "/2010-04-01/Accounts/{AccountSid}/Keys.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.API.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("NewKey creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "NewKey creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -68,10 +80,10 @@ public NewKey create(final TwilioRestClient client){ return NewKey.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/NewSigningKey.java b/src/main/java/com/twilio/rest/api/v2010/account/NewSigningKey.java index c4885f18de..a8a1925ec4 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/NewSigningKey.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/NewSigningKey.java @@ -23,39 +23,39 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class NewSigningKey extends Resource { + private static final long serialVersionUID = 142441509867514L; - public static NewSigningKeyCreator creator(){ + public static NewSigningKeyCreator creator() { return new NewSigningKeyCreator(); } - public static NewSigningKeyCreator creator(final String pathAccountSid){ + + public static NewSigningKeyCreator creator(final String pathAccountSid) { return new NewSigningKeyCreator(pathAccountSid); } /** - * Converts a JSON String into a NewSigningKey object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return NewSigningKey object represented by the provided JSON - */ - public static NewSigningKey fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a NewSigningKey object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return NewSigningKey object represented by the provided JSON + */ + public static NewSigningKey fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, NewSigningKey.class); @@ -67,14 +67,17 @@ public static NewSigningKey fromJson(final String json, final ObjectMapper objec } /** - * Converts a JSON InputStream into a NewSigningKey object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return NewSigningKey object represented by the provided JSON - */ - public static NewSigningKey fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a NewSigningKey object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return NewSigningKey object represented by the provided JSON + */ + public static NewSigningKey fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, NewSigningKey.class); @@ -93,20 +96,11 @@ public static NewSigningKey fromJson(final InputStream json, final ObjectMapper @JsonCreator private NewSigningKey( - @JsonProperty("sid") - final String sid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("secret") - final String secret + @JsonProperty("sid") final String sid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("secret") final String secret ) { this.sid = sid; this.friendlyName = friendlyName; @@ -115,25 +109,29 @@ private NewSigningKey( this.secret = secret; } - public final String getSid() { - return this.sid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getSecret() { - return this.secret; - } + public final String getSid() { + return this.sid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getSecret() { + return this.secret; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -143,13 +141,23 @@ public boolean equals(final Object o) { NewSigningKey other = (NewSigningKey) o; - return Objects.equals(sid, other.sid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(secret, other.secret) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(secret, other.secret) + ); } @Override public int hashCode() { - return Objects.hash(sid, friendlyName, dateCreated, dateUpdated, secret); + return Objects.hash( + sid, + friendlyName, + dateCreated, + dateUpdated, + secret + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/NewSigningKeyCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/NewSigningKeyCreator.java index 07d4ec101c..2ffe471bf7 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/NewSigningKeyCreator.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/NewSigningKeyCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010.account; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,54 +25,68 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class NewSigningKeyCreator extends Creator { - - -public class NewSigningKeyCreator extends Creator{ private String pathAccountSid; private String friendlyName; - public NewSigningKeyCreator() { - } + public NewSigningKeyCreator() {} + public NewSigningKeyCreator(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - public NewSigningKeyCreator setFriendlyName(final String friendlyName){ + public NewSigningKeyCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } @Override - public NewSigningKey create(final TwilioRestClient client){ + public NewSigningKey create(final TwilioRestClient client) { String path = "/2010-04-01/Accounts/{AccountSid}/SigningKeys.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.API.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("NewSigningKey creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "NewSigningKey creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return NewSigningKey.fromJson(response.getStream(), client.getObjectMapper()); + return NewSigningKey.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/Notification.java b/src/main/java/com/twilio/rest/api/v2010/account/Notification.java index fc9f1c0eb6..455d8c991a 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/Notification.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/Notification.java @@ -23,48 +23,52 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; import com.twilio.http.HttpMethod; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Notification extends Resource { + private static final long serialVersionUID = 162458167875227L; - public static NotificationFetcher fetcher(final String pathSid){ + public static NotificationFetcher fetcher(final String pathSid) { return new NotificationFetcher(pathSid); } - public static NotificationFetcher fetcher(final String pathAccountSid, final String pathSid){ + + public static NotificationFetcher fetcher( + final String pathAccountSid, + final String pathSid + ) { return new NotificationFetcher(pathAccountSid, pathSid); } - public static NotificationReader reader(){ + public static NotificationReader reader() { return new NotificationReader(); } - public static NotificationReader reader(final String pathAccountSid){ + + public static NotificationReader reader(final String pathAccountSid) { return new NotificationReader(pathAccountSid); } /** - * Converts a JSON String into a Notification object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Notification object represented by the provided JSON - */ - public static Notification fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Notification object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Notification object represented by the provided JSON + */ + public static Notification fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Notification.class); @@ -76,14 +80,17 @@ public static Notification fromJson(final String json, final ObjectMapper object } /** - * Converts a JSON InputStream into a Notification object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Notification object represented by the provided JSON - */ - public static Notification fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Notification object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Notification object represented by the provided JSON + */ + public static Notification fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Notification.class); @@ -114,56 +121,23 @@ public static Notification fromJson(final InputStream json, final ObjectMapper o @JsonCreator private Notification( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("api_version") - final String apiVersion, - - @JsonProperty("call_sid") - final String callSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("error_code") - final String errorCode, - - @JsonProperty("log") - final String log, - - @JsonProperty("message_date") - final String messageDate, - - @JsonProperty("message_text") - final String messageText, - - @JsonProperty("more_info") - final URI moreInfo, - - @JsonProperty("request_method") - final HttpMethod requestMethod, - - @JsonProperty("request_url") - final URI requestUrl, - - @JsonProperty("request_variables") - final String requestVariables, - - @JsonProperty("response_body") - final String responseBody, - - @JsonProperty("response_headers") - final String responseHeaders, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("uri") - final String uri + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("api_version") final String apiVersion, + @JsonProperty("call_sid") final String callSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("error_code") final String errorCode, + @JsonProperty("log") final String log, + @JsonProperty("message_date") final String messageDate, + @JsonProperty("message_text") final String messageText, + @JsonProperty("more_info") final URI moreInfo, + @JsonProperty("request_method") final HttpMethod requestMethod, + @JsonProperty("request_url") final URI requestUrl, + @JsonProperty("request_variables") final String requestVariables, + @JsonProperty("response_body") final String responseBody, + @JsonProperty("response_headers") final String responseHeaders, + @JsonProperty("sid") final String sid, + @JsonProperty("uri") final String uri ) { this.accountSid = accountSid; this.apiVersion = apiVersion; @@ -184,61 +158,77 @@ private Notification( this.uri = uri; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getApiVersion() { - return this.apiVersion; - } - public final String getCallSid() { - return this.callSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getErrorCode() { - return this.errorCode; - } - public final String getLog() { - return this.log; - } - public final ZonedDateTime getMessageDate() { - return this.messageDate; - } - public final String getMessageText() { - return this.messageText; - } - public final URI getMoreInfo() { - return this.moreInfo; - } - public final HttpMethod getRequestMethod() { - return this.requestMethod; - } - public final URI getRequestUrl() { - return this.requestUrl; - } - public final String getRequestVariables() { - return this.requestVariables; - } - public final String getResponseBody() { - return this.responseBody; - } - public final String getResponseHeaders() { - return this.responseHeaders; - } - public final String getSid() { - return this.sid; - } - public final String getUri() { - return this.uri; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getApiVersion() { + return this.apiVersion; + } + + public final String getCallSid() { + return this.callSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getErrorCode() { + return this.errorCode; + } + + public final String getLog() { + return this.log; + } + + public final ZonedDateTime getMessageDate() { + return this.messageDate; + } + + public final String getMessageText() { + return this.messageText; + } + + public final URI getMoreInfo() { + return this.moreInfo; + } + + public final HttpMethod getRequestMethod() { + return this.requestMethod; + } + + public final URI getRequestUrl() { + return this.requestUrl; + } + + public final String getRequestVariables() { + return this.requestVariables; + } + + public final String getResponseBody() { + return this.responseBody; + } + + public final String getResponseHeaders() { + return this.responseHeaders; + } + + public final String getSid() { + return this.sid; + } + + public final String getUri() { + return this.uri; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -248,13 +238,47 @@ public boolean equals(final Object o) { Notification other = (Notification) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(apiVersion, other.apiVersion) && Objects.equals(callSid, other.callSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(errorCode, other.errorCode) && Objects.equals(log, other.log) && Objects.equals(messageDate, other.messageDate) && Objects.equals(messageText, other.messageText) && Objects.equals(moreInfo, other.moreInfo) && Objects.equals(requestMethod, other.requestMethod) && Objects.equals(requestUrl, other.requestUrl) && Objects.equals(requestVariables, other.requestVariables) && Objects.equals(responseBody, other.responseBody) && Objects.equals(responseHeaders, other.responseHeaders) && Objects.equals(sid, other.sid) && Objects.equals(uri, other.uri) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(apiVersion, other.apiVersion) && + Objects.equals(callSid, other.callSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(errorCode, other.errorCode) && + Objects.equals(log, other.log) && + Objects.equals(messageDate, other.messageDate) && + Objects.equals(messageText, other.messageText) && + Objects.equals(moreInfo, other.moreInfo) && + Objects.equals(requestMethod, other.requestMethod) && + Objects.equals(requestUrl, other.requestUrl) && + Objects.equals(requestVariables, other.requestVariables) && + Objects.equals(responseBody, other.responseBody) && + Objects.equals(responseHeaders, other.responseHeaders) && + Objects.equals(sid, other.sid) && + Objects.equals(uri, other.uri) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, apiVersion, callSid, dateCreated, dateUpdated, errorCode, log, messageDate, messageText, moreInfo, requestMethod, requestUrl, requestVariables, responseBody, responseHeaders, sid, uri); + return Objects.hash( + accountSid, + apiVersion, + callSid, + dateCreated, + dateUpdated, + errorCode, + log, + messageDate, + messageText, + moreInfo, + requestMethod, + requestUrl, + requestVariables, + responseBody, + responseHeaders, + sid, + uri + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/NotificationFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/NotificationFetcher.java index 130abded15..a338490ca1 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/NotificationFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/NotificationFetcher.java @@ -24,29 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class NotificationFetcher extends Fetcher { + private String pathSid; private String pathAccountSid; - public NotificationFetcher(final String pathSid){ + public NotificationFetcher(final String pathSid) { this.pathSid = pathSid; } - public NotificationFetcher(final String pathAccountSid, final String pathSid){ + + public NotificationFetcher( + final String pathAccountSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - @Override public Notification fetch(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/Notifications/{Sid}.json"; + String path = + "/2010-04-01/Accounts/{AccountSid}/Notifications/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -56,15 +65,23 @@ public Notification fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Notification fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Notification fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Notification.fromJson(response.getStream(), client.getObjectMapper()); + return Notification.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/NotificationReader.java b/src/main/java/com/twilio/rest/api/v2010/account/NotificationReader.java index 7fa42f0e6a..be51e69dcb 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/NotificationReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/NotificationReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.api.v2010.account; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,13 +25,11 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; import java.time.LocalDate; import java.time.format.DateTimeFormatter; - - public class NotificationReader extends Reader { + private String pathAccountSid; private Integer log; private LocalDate messageDate; @@ -38,29 +37,37 @@ public class NotificationReader extends Reader { private LocalDate messageDateAfter; private Integer pageSize; - public NotificationReader(){ - } - public NotificationReader(final String pathAccountSid){ + public NotificationReader() {} + + public NotificationReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - public NotificationReader setLog(final Integer log){ + public NotificationReader setLog(final Integer log) { this.log = log; return this; } - public NotificationReader setMessageDate(final LocalDate messageDate){ + + public NotificationReader setMessageDate(final LocalDate messageDate) { this.messageDate = messageDate; return this; } - public NotificationReader setMessageDateBefore(final LocalDate messageDateBefore){ + + public NotificationReader setMessageDateBefore( + final LocalDate messageDateBefore + ) { this.messageDateBefore = messageDateBefore; return this; } - public NotificationReader setMessageDateAfter(final LocalDate messageDateAfter){ + + public NotificationReader setMessageDateAfter( + final LocalDate messageDateAfter + ) { this.messageDateAfter = messageDateAfter; return this; } - public NotificationReader setPageSize(final Integer pageSize){ + + public NotificationReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -72,8 +79,15 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/2010-04-01/Accounts/{AccountSid}/Notifications.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -85,13 +99,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Notification read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Notification read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -107,7 +129,10 @@ private Page pageForRequest(final TwilioRestClient client, final R } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.API.toString()) @@ -115,9 +140,11 @@ public Page previousPage(final Page page, final Twil return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.API.toString()) @@ -126,31 +153,40 @@ public Page nextPage(final Page page, final TwilioRe } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (log != null) { - request.addQueryParam("Log", log.toString()); } if (messageDate != null) { - request.addQueryParam("MessageDate", messageDate.format(DateTimeFormatter.ofPattern(Request.QUERY_STRING_DATE_TIME_FORMAT))); - } - else if (messageDateAfter != null || messageDateBefore != null) { - request.addQueryDateRange("MessageDate", messageDateAfter, messageDateBefore); + request.addQueryParam( + "MessageDate", + messageDate.format( + DateTimeFormatter.ofPattern( + Request.QUERY_STRING_DATE_FORMAT + ) + ) + ); + } else if (messageDateAfter != null || messageDateBefore != null) { + request.addQueryDateRange( + "MessageDate", + messageDateAfter, + messageDateBefore + ); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/OutgoingCallerId.java b/src/main/java/com/twilio/rest/api/v2010/account/OutgoingCallerId.java index ecf5017659..40f1bd6469 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/OutgoingCallerId.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/OutgoingCallerId.java @@ -23,60 +23,72 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class OutgoingCallerId extends Resource { + private static final long serialVersionUID = 75956517535233L; - public static OutgoingCallerIdDeleter deleter(final String pathSid){ + public static OutgoingCallerIdDeleter deleter(final String pathSid) { return new OutgoingCallerIdDeleter(pathSid); } - public static OutgoingCallerIdDeleter deleter(final String pathAccountSid, final String pathSid){ + + public static OutgoingCallerIdDeleter deleter( + final String pathAccountSid, + final String pathSid + ) { return new OutgoingCallerIdDeleter(pathAccountSid, pathSid); } - public static OutgoingCallerIdFetcher fetcher(final String pathSid){ + public static OutgoingCallerIdFetcher fetcher(final String pathSid) { return new OutgoingCallerIdFetcher(pathSid); } - public static OutgoingCallerIdFetcher fetcher(final String pathAccountSid, final String pathSid){ + + public static OutgoingCallerIdFetcher fetcher( + final String pathAccountSid, + final String pathSid + ) { return new OutgoingCallerIdFetcher(pathAccountSid, pathSid); } - public static OutgoingCallerIdReader reader(){ + public static OutgoingCallerIdReader reader() { return new OutgoingCallerIdReader(); } - public static OutgoingCallerIdReader reader(final String pathAccountSid){ + + public static OutgoingCallerIdReader reader(final String pathAccountSid) { return new OutgoingCallerIdReader(pathAccountSid); } - public static OutgoingCallerIdUpdater updater(final String pathSid){ + public static OutgoingCallerIdUpdater updater(final String pathSid) { return new OutgoingCallerIdUpdater(pathSid); } - public static OutgoingCallerIdUpdater updater(final String pathAccountSid, final String pathSid){ + + public static OutgoingCallerIdUpdater updater( + final String pathAccountSid, + final String pathSid + ) { return new OutgoingCallerIdUpdater(pathAccountSid, pathSid); } /** - * Converts a JSON String into a OutgoingCallerId object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return OutgoingCallerId object represented by the provided JSON - */ - public static OutgoingCallerId fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a OutgoingCallerId object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return OutgoingCallerId object represented by the provided JSON + */ + public static OutgoingCallerId fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, OutgoingCallerId.class); @@ -88,14 +100,17 @@ public static OutgoingCallerId fromJson(final String json, final ObjectMapper ob } /** - * Converts a JSON InputStream into a OutgoingCallerId object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return OutgoingCallerId object represented by the provided JSON - */ - public static OutgoingCallerId fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a OutgoingCallerId object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return OutgoingCallerId object represented by the provided JSON + */ + public static OutgoingCallerId fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, OutgoingCallerId.class); @@ -116,26 +131,15 @@ public static OutgoingCallerId fromJson(final InputStream json, final ObjectMapp @JsonCreator private OutgoingCallerId( - @JsonProperty("sid") - final String sid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("phone_number") - final com.twilio.type.PhoneNumber phoneNumber, - - @JsonProperty("uri") - final String uri + @JsonProperty("sid") final String sid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty( + "phone_number" + ) final com.twilio.type.PhoneNumber phoneNumber, + @JsonProperty("uri") final String uri ) { this.sid = sid; this.dateCreated = DateConverter.rfc2822DateTimeFromString(dateCreated); @@ -146,31 +150,37 @@ private OutgoingCallerId( this.uri = uri; } - public final String getSid() { - return this.sid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getAccountSid() { - return this.accountSid; - } - public final com.twilio.type.PhoneNumber getPhoneNumber() { - return this.phoneNumber; - } - public final String getUri() { - return this.uri; - } + public final String getSid() { + return this.sid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final com.twilio.type.PhoneNumber getPhoneNumber() { + return this.phoneNumber; + } + + public final String getUri() { + return this.uri; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -180,13 +190,27 @@ public boolean equals(final Object o) { OutgoingCallerId other = (OutgoingCallerId) o; - return Objects.equals(sid, other.sid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(accountSid, other.accountSid) && Objects.equals(phoneNumber, other.phoneNumber) && Objects.equals(uri, other.uri) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(phoneNumber, other.phoneNumber) && + Objects.equals(uri, other.uri) + ); } @Override public int hashCode() { - return Objects.hash(sid, dateCreated, dateUpdated, friendlyName, accountSid, phoneNumber, uri); + return Objects.hash( + sid, + dateCreated, + dateUpdated, + friendlyName, + accountSid, + phoneNumber, + uri + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/OutgoingCallerIdDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/OutgoingCallerIdDeleter.java index a2a2dafe91..76d535d150 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/OutgoingCallerIdDeleter.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/OutgoingCallerIdDeleter.java @@ -24,28 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class OutgoingCallerIdDeleter extends Deleter { + private String pathSid; private String pathAccountSid; - public OutgoingCallerIdDeleter(final String pathSid){ + public OutgoingCallerIdDeleter(final String pathSid) { this.pathSid = pathSid; } - public OutgoingCallerIdDeleter(final String pathAccountSid, final String pathSid){ + + public OutgoingCallerIdDeleter( + final String pathAccountSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/OutgoingCallerIds/{Sid}.json"; + String path = + "/2010-04-01/Accounts/{AccountSid}/OutgoingCallerIds/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -55,9 +65,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("OutgoingCallerId delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "OutgoingCallerId delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/OutgoingCallerIdFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/OutgoingCallerIdFetcher.java index b55b1b6ccb..bca8258d50 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/OutgoingCallerIdFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/OutgoingCallerIdFetcher.java @@ -24,29 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class OutgoingCallerIdFetcher extends Fetcher { + private String pathSid; private String pathAccountSid; - public OutgoingCallerIdFetcher(final String pathSid){ + public OutgoingCallerIdFetcher(final String pathSid) { this.pathSid = pathSid; } - public OutgoingCallerIdFetcher(final String pathAccountSid, final String pathSid){ + + public OutgoingCallerIdFetcher( + final String pathAccountSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - @Override public OutgoingCallerId fetch(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/OutgoingCallerIds/{Sid}.json"; + String path = + "/2010-04-01/Accounts/{AccountSid}/OutgoingCallerIds/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -56,15 +65,23 @@ public OutgoingCallerId fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("OutgoingCallerId fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "OutgoingCallerId fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return OutgoingCallerId.fromJson(response.getStream(), client.getObjectMapper()); + return OutgoingCallerId.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/OutgoingCallerIdReader.java b/src/main/java/com/twilio/rest/api/v2010/account/OutgoingCallerIdReader.java index 32db807456..2a75306070 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/OutgoingCallerIdReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/OutgoingCallerIdReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.api.v2010.account; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.converter.Promoter; @@ -25,35 +26,37 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class OutgoingCallerIdReader extends Reader { + private String pathAccountSid; private com.twilio.type.PhoneNumber phoneNumber; private String friendlyName; private Integer pageSize; - public OutgoingCallerIdReader(){ - } - public OutgoingCallerIdReader(final String pathAccountSid){ + public OutgoingCallerIdReader() {} + + public OutgoingCallerIdReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - public OutgoingCallerIdReader setPhoneNumber(final com.twilio.type.PhoneNumber phoneNumber){ + public OutgoingCallerIdReader setPhoneNumber( + final com.twilio.type.PhoneNumber phoneNumber + ) { this.phoneNumber = phoneNumber; return this; } - public OutgoingCallerIdReader setPhoneNumber(final String phoneNumber){ + public OutgoingCallerIdReader setPhoneNumber(final String phoneNumber) { return setPhoneNumber(Promoter.phoneNumberFromString(phoneNumber)); } - public OutgoingCallerIdReader setFriendlyName(final String friendlyName){ + + public OutgoingCallerIdReader setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public OutgoingCallerIdReader setPageSize(final Integer pageSize){ + + public OutgoingCallerIdReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -64,9 +67,17 @@ public ResourceSet read(final TwilioRestClient client) { } public Page firstPage(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/OutgoingCallerIds.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); + String path = + "/2010-04-01/Accounts/{AccountSid}/OutgoingCallerIds.json"; + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -78,13 +89,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("OutgoingCallerId read failed: Unable to connect to server"); + throw new ApiConnectionException( + "OutgoingCallerId read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -100,7 +119,10 @@ private Page pageForRequest(final TwilioRestClient client, fin } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.API.toString()) @@ -108,9 +130,11 @@ public Page previousPage(final Page page, fi return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.API.toString()) @@ -119,29 +143,27 @@ public Page nextPage(final Page page, final } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (phoneNumber != null) { - request.addQueryParam("PhoneNumber", phoneNumber.toString()); } if (friendlyName != null) { - request.addQueryParam("FriendlyName", friendlyName); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/OutgoingCallerIdUpdater.java b/src/main/java/com/twilio/rest/api/v2010/account/OutgoingCallerIdUpdater.java index 23049b5de8..5a1e6a6c68 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/OutgoingCallerIdUpdater.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/OutgoingCallerIdUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010.account; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,58 +25,77 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class OutgoingCallerIdUpdater extends Updater { - - -public class OutgoingCallerIdUpdater extends Updater{ private String pathSid; private String pathAccountSid; private String friendlyName; - public OutgoingCallerIdUpdater(final String pathSid){ + public OutgoingCallerIdUpdater(final String pathSid) { this.pathSid = pathSid; } - public OutgoingCallerIdUpdater(final String pathAccountSid, final String pathSid){ + + public OutgoingCallerIdUpdater( + final String pathAccountSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - public OutgoingCallerIdUpdater setFriendlyName(final String friendlyName){ + public OutgoingCallerIdUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } @Override - public OutgoingCallerId update(final TwilioRestClient client){ - String path = "/2010-04-01/Accounts/{AccountSid}/OutgoingCallerIds/{Sid}.json"; + public OutgoingCallerId update(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/OutgoingCallerIds/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.API.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("OutgoingCallerId update failed: Unable to connect to server"); + throw new ApiConnectionException( + "OutgoingCallerId update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return OutgoingCallerId.fromJson(response.getStream(), client.getObjectMapper()); + return OutgoingCallerId.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/Queue.java b/src/main/java/com/twilio/rest/api/v2010/account/Queue.java index 1dbd2295bd..673d5f862b 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/Queue.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/Queue.java @@ -23,67 +23,83 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Queue extends Resource { + private static final long serialVersionUID = 17909156629067L; - public static QueueCreator creator(final String friendlyName){ + public static QueueCreator creator(final String friendlyName) { return new QueueCreator(friendlyName); } - public static QueueCreator creator(final String pathAccountSid, final String friendlyName){ + + public static QueueCreator creator( + final String pathAccountSid, + final String friendlyName + ) { return new QueueCreator(pathAccountSid, friendlyName); } - public static QueueDeleter deleter(final String pathSid){ + public static QueueDeleter deleter(final String pathSid) { return new QueueDeleter(pathSid); } - public static QueueDeleter deleter(final String pathAccountSid, final String pathSid){ + + public static QueueDeleter deleter( + final String pathAccountSid, + final String pathSid + ) { return new QueueDeleter(pathAccountSid, pathSid); } - public static QueueFetcher fetcher(final String pathSid){ + public static QueueFetcher fetcher(final String pathSid) { return new QueueFetcher(pathSid); } - public static QueueFetcher fetcher(final String pathAccountSid, final String pathSid){ + + public static QueueFetcher fetcher( + final String pathAccountSid, + final String pathSid + ) { return new QueueFetcher(pathAccountSid, pathSid); } - public static QueueReader reader(){ + public static QueueReader reader() { return new QueueReader(); } - public static QueueReader reader(final String pathAccountSid){ + + public static QueueReader reader(final String pathAccountSid) { return new QueueReader(pathAccountSid); } - public static QueueUpdater updater(final String pathSid){ + public static QueueUpdater updater(final String pathSid) { return new QueueUpdater(pathSid); } - public static QueueUpdater updater(final String pathAccountSid, final String pathSid){ + + public static QueueUpdater updater( + final String pathAccountSid, + final String pathSid + ) { return new QueueUpdater(pathAccountSid, pathSid); } /** - * Converts a JSON String into a Queue object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Queue object represented by the provided JSON - */ - public static Queue fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Queue object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Queue object represented by the provided JSON + */ + public static Queue fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Queue.class); @@ -95,14 +111,17 @@ public static Queue fromJson(final String json, final ObjectMapper objectMapper) } /** - * Converts a JSON InputStream into a Queue object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Queue object represented by the provided JSON - */ - public static Queue fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Queue object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Queue object represented by the provided JSON + */ + public static Queue fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Queue.class); @@ -125,32 +144,15 @@ public static Queue fromJson(final InputStream json, final ObjectMapper objectMa @JsonCreator private Queue( - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("current_size") - final Integer currentSize, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("uri") - final String uri, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("average_wait_time") - final Integer averageWaitTime, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("max_size") - final Integer maxSize + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("current_size") final Integer currentSize, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("uri") final String uri, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("average_wait_time") final Integer averageWaitTime, + @JsonProperty("sid") final String sid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("max_size") final Integer maxSize ) { this.dateUpdated = DateConverter.rfc2822DateTimeFromString(dateUpdated); this.currentSize = currentSize; @@ -163,37 +165,45 @@ private Queue( this.maxSize = maxSize; } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final Integer getCurrentSize() { - return this.currentSize; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getUri() { - return this.uri; - } - public final String getAccountSid() { - return this.accountSid; - } - public final Integer getAverageWaitTime() { - return this.averageWaitTime; - } - public final String getSid() { - return this.sid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final Integer getMaxSize() { - return this.maxSize; - } + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final Integer getCurrentSize() { + return this.currentSize; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getUri() { + return this.uri; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final Integer getAverageWaitTime() { + return this.averageWaitTime; + } + + public final String getSid() { + return this.sid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final Integer getMaxSize() { + return this.maxSize; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -203,13 +213,31 @@ public boolean equals(final Object o) { Queue other = (Queue) o; - return Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(currentSize, other.currentSize) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(uri, other.uri) && Objects.equals(accountSid, other.accountSid) && Objects.equals(averageWaitTime, other.averageWaitTime) && Objects.equals(sid, other.sid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(maxSize, other.maxSize) ; + return ( + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(currentSize, other.currentSize) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(uri, other.uri) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(averageWaitTime, other.averageWaitTime) && + Objects.equals(sid, other.sid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(maxSize, other.maxSize) + ); } @Override public int hashCode() { - return Objects.hash(dateUpdated, currentSize, friendlyName, uri, accountSid, averageWaitTime, sid, dateCreated, maxSize); + return Objects.hash( + dateUpdated, + currentSize, + friendlyName, + uri, + accountSid, + averageWaitTime, + sid, + dateCreated, + maxSize + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/QueueCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/QueueCreator.java index e16dc46863..e1d7b7db00 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/QueueCreator.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/QueueCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010.account; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class QueueCreator extends Creator { - - -public class QueueCreator extends Creator{ private String friendlyName; private String pathAccountSid; private Integer maxSize; @@ -35,39 +34,61 @@ public class QueueCreator extends Creator{ public QueueCreator(final String friendlyName) { this.friendlyName = friendlyName; } - public QueueCreator(final String pathAccountSid, final String friendlyName) { + + public QueueCreator( + final String pathAccountSid, + final String friendlyName + ) { this.pathAccountSid = pathAccountSid; this.friendlyName = friendlyName; } - public QueueCreator setFriendlyName(final String friendlyName){ + public QueueCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public QueueCreator setMaxSize(final Integer maxSize){ + + public QueueCreator setMaxSize(final Integer maxSize) { this.maxSize = maxSize; return this; } @Override - public Queue create(final TwilioRestClient client){ + public Queue create(final TwilioRestClient client) { String path = "/2010-04-01/Accounts/{AccountSid}/Queues.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"FriendlyName"+"}", this.friendlyName.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "FriendlyName" + "}", + this.friendlyName.toString() + ); Request request = new Request( HttpMethod.POST, Domains.API.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Queue creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Queue creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -76,14 +97,13 @@ public Queue create(final TwilioRestClient client){ return Queue.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (maxSize != null) { request.addPostParam("MaxSize", maxSize.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/QueueDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/QueueDeleter.java index e7901f0d53..2283d1d6fe 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/QueueDeleter.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/QueueDeleter.java @@ -24,28 +24,34 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class QueueDeleter extends Deleter { + private String pathSid; private String pathAccountSid; - public QueueDeleter(final String pathSid){ + public QueueDeleter(final String pathSid) { this.pathSid = pathSid; } - public QueueDeleter(final String pathAccountSid, final String pathSid){ + + public QueueDeleter(final String pathAccountSid, final String pathSid) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/2010-04-01/Accounts/{AccountSid}/Queues/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -55,9 +61,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Queue delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Queue delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/QueueFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/QueueFetcher.java index a8459ccc25..1110b7e71c 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/QueueFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/QueueFetcher.java @@ -24,29 +24,34 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class QueueFetcher extends Fetcher { + private String pathSid; private String pathAccountSid; - public QueueFetcher(final String pathSid){ + public QueueFetcher(final String pathSid) { this.pathSid = pathSid; } - public QueueFetcher(final String pathAccountSid, final String pathSid){ + + public QueueFetcher(final String pathAccountSid, final String pathSid) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - @Override public Queue fetch(final TwilioRestClient client) { String path = "/2010-04-01/Accounts/{AccountSid}/Queues/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -56,9 +61,14 @@ public Queue fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Queue fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Queue fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/QueueReader.java b/src/main/java/com/twilio/rest/api/v2010/account/QueueReader.java index 9a83db9ee3..5c3c08384d 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/QueueReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/QueueReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.api.v2010.account; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,21 +25,19 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class QueueReader extends Reader { + private String pathAccountSid; private Integer pageSize; - public QueueReader(){ - } - public QueueReader(final String pathAccountSid){ + public QueueReader() {} + + public QueueReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - public QueueReader setPageSize(final Integer pageSize){ + public QueueReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -50,8 +49,15 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/2010-04-01/Accounts/{AccountSid}/Queues.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -63,13 +69,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Queue read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Queue read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -85,7 +99,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.API.toString()) @@ -93,9 +110,11 @@ public Page previousPage(final Page page, final TwilioRestClient c return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.API.toString()) @@ -104,21 +123,21 @@ public Page nextPage(final Page page, final TwilioRestClient clien } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/QueueUpdater.java b/src/main/java/com/twilio/rest/api/v2010/account/QueueUpdater.java index 529f362a2f..9f9076d7bb 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/QueueUpdater.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/QueueUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010.account; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,51 +25,64 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class QueueUpdater extends Updater { - - -public class QueueUpdater extends Updater{ private String pathSid; private String pathAccountSid; private String friendlyName; private Integer maxSize; - public QueueUpdater(final String pathSid){ + public QueueUpdater(final String pathSid) { this.pathSid = pathSid; } - public QueueUpdater(final String pathAccountSid, final String pathSid){ + + public QueueUpdater(final String pathAccountSid, final String pathSid) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - public QueueUpdater setFriendlyName(final String friendlyName){ + public QueueUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public QueueUpdater setMaxSize(final Integer maxSize){ + + public QueueUpdater setMaxSize(final Integer maxSize) { this.maxSize = maxSize; return this; } @Override - public Queue update(final TwilioRestClient client){ + public Queue update(final TwilioRestClient client) { String path = "/2010-04-01/Accounts/{AccountSid}/Queues/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.API.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Queue update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Queue update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -77,14 +91,13 @@ public Queue update(final TwilioRestClient client){ return Queue.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (maxSize != null) { request.addPostParam("MaxSize", maxSize.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/Recording.java b/src/main/java/com/twilio/rest/api/v2010/account/Recording.java index 21d909752f..9c79f513c3 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/Recording.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/Recording.java @@ -24,56 +24,64 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Recording extends Resource { + private static final long serialVersionUID = 8927692317007L; - public static RecordingDeleter deleter(final String pathSid){ + public static RecordingDeleter deleter(final String pathSid) { return new RecordingDeleter(pathSid); } - public static RecordingDeleter deleter(final String pathAccountSid, final String pathSid){ + + public static RecordingDeleter deleter( + final String pathAccountSid, + final String pathSid + ) { return new RecordingDeleter(pathAccountSid, pathSid); } - public static RecordingFetcher fetcher(final String pathSid){ + public static RecordingFetcher fetcher(final String pathSid) { return new RecordingFetcher(pathSid); } - public static RecordingFetcher fetcher(final String pathAccountSid, final String pathSid){ + + public static RecordingFetcher fetcher( + final String pathAccountSid, + final String pathSid + ) { return new RecordingFetcher(pathAccountSid, pathSid); } - public static RecordingReader reader(){ + public static RecordingReader reader() { return new RecordingReader(); } - public static RecordingReader reader(final String pathAccountSid){ + + public static RecordingReader reader(final String pathAccountSid) { return new RecordingReader(pathAccountSid); } /** - * Converts a JSON String into a Recording object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Recording object represented by the provided JSON - */ - public static Recording fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Recording object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Recording object represented by the provided JSON + */ + public static Recording fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Recording.class); @@ -85,14 +93,17 @@ public static Recording fromJson(final String json, final ObjectMapper objectMap } /** - * Converts a JSON InputStream into a Recording object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Recording object represented by the provided JSON - */ - public static Recording fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Recording object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Recording object represented by the provided JSON + */ + public static Recording fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Recording.class); @@ -102,6 +113,7 @@ public static Recording fromJson(final InputStream json, final ObjectMapper obje throw new ApiConnectionException(e.getMessage(), e); } } + public enum Source { DIALVERB("DialVerb"), CONFERENCE("Conference"), @@ -126,6 +138,7 @@ public static Source forValue(final String value) { return Promoter.enumFromString(value, Source.values()); } } + public enum Status { IN_PROGRESS("in-progress"), PAUSED("paused"), @@ -173,62 +186,29 @@ public static Status forValue(final String value) { @JsonCreator private Recording( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("api_version") - final String apiVersion, - - @JsonProperty("call_sid") - final String callSid, - - @JsonProperty("conference_sid") - final String conferenceSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("start_time") - final String startTime, - - @JsonProperty("duration") - final String duration, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("price") - final String price, - - @JsonProperty("price_unit") - final String priceUnit, - - @JsonProperty("status") - final Recording.Status status, - - @JsonProperty("channels") - final Integer channels, - - @JsonProperty("source") - final Recording.Source source, - - @JsonProperty("error_code") - final Integer errorCode, - - @JsonProperty("uri") - final String uri, - - @JsonProperty("encryption_details") - final Map encryptionDetails, - - @JsonProperty("subresource_uris") - final Map subresourceUris, - - @JsonProperty("media_url") - final URI mediaUrl + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("api_version") final String apiVersion, + @JsonProperty("call_sid") final String callSid, + @JsonProperty("conference_sid") final String conferenceSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("start_time") final String startTime, + @JsonProperty("duration") final String duration, + @JsonProperty("sid") final String sid, + @JsonProperty("price") final String price, + @JsonProperty("price_unit") final String priceUnit, + @JsonProperty("status") final Recording.Status status, + @JsonProperty("channels") final Integer channels, + @JsonProperty("source") final Recording.Source source, + @JsonProperty("error_code") final Integer errorCode, + @JsonProperty("uri") final String uri, + @JsonProperty( + "encryption_details" + ) final Map encryptionDetails, + @JsonProperty( + "subresource_uris" + ) final Map subresourceUris, + @JsonProperty("media_url") final URI mediaUrl ) { this.accountSid = accountSid; this.apiVersion = apiVersion; @@ -251,67 +231,85 @@ private Recording( this.mediaUrl = mediaUrl; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getApiVersion() { - return this.apiVersion; - } - public final String getCallSid() { - return this.callSid; - } - public final String getConferenceSid() { - return this.conferenceSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final ZonedDateTime getStartTime() { - return this.startTime; - } - public final String getDuration() { - return this.duration; - } - public final String getSid() { - return this.sid; - } - public final String getPrice() { - return this.price; - } - public final String getPriceUnit() { - return this.priceUnit; - } - public final Recording.Status getStatus() { - return this.status; - } - public final Integer getChannels() { - return this.channels; - } - public final Recording.Source getSource() { - return this.source; - } - public final Integer getErrorCode() { - return this.errorCode; - } - public final String getUri() { - return this.uri; - } - public final Map getEncryptionDetails() { - return this.encryptionDetails; - } - public final Map getSubresourceUris() { - return this.subresourceUris; - } - public final URI getMediaUrl() { - return this.mediaUrl; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getApiVersion() { + return this.apiVersion; + } + + public final String getCallSid() { + return this.callSid; + } + + public final String getConferenceSid() { + return this.conferenceSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final ZonedDateTime getStartTime() { + return this.startTime; + } + + public final String getDuration() { + return this.duration; + } + + public final String getSid() { + return this.sid; + } + + public final String getPrice() { + return this.price; + } + + public final String getPriceUnit() { + return this.priceUnit; + } + + public final Recording.Status getStatus() { + return this.status; + } + + public final Integer getChannels() { + return this.channels; + } + + public final Recording.Source getSource() { + return this.source; + } + + public final Integer getErrorCode() { + return this.errorCode; + } + + public final String getUri() { + return this.uri; + } + + public final Map getEncryptionDetails() { + return this.encryptionDetails; + } + + public final Map getSubresourceUris() { + return this.subresourceUris; + } + + public final URI getMediaUrl() { + return this.mediaUrl; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -321,13 +319,51 @@ public boolean equals(final Object o) { Recording other = (Recording) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(apiVersion, other.apiVersion) && Objects.equals(callSid, other.callSid) && Objects.equals(conferenceSid, other.conferenceSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(startTime, other.startTime) && Objects.equals(duration, other.duration) && Objects.equals(sid, other.sid) && Objects.equals(price, other.price) && Objects.equals(priceUnit, other.priceUnit) && Objects.equals(status, other.status) && Objects.equals(channels, other.channels) && Objects.equals(source, other.source) && Objects.equals(errorCode, other.errorCode) && Objects.equals(uri, other.uri) && Objects.equals(encryptionDetails, other.encryptionDetails) && Objects.equals(subresourceUris, other.subresourceUris) && Objects.equals(mediaUrl, other.mediaUrl) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(apiVersion, other.apiVersion) && + Objects.equals(callSid, other.callSid) && + Objects.equals(conferenceSid, other.conferenceSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(startTime, other.startTime) && + Objects.equals(duration, other.duration) && + Objects.equals(sid, other.sid) && + Objects.equals(price, other.price) && + Objects.equals(priceUnit, other.priceUnit) && + Objects.equals(status, other.status) && + Objects.equals(channels, other.channels) && + Objects.equals(source, other.source) && + Objects.equals(errorCode, other.errorCode) && + Objects.equals(uri, other.uri) && + Objects.equals(encryptionDetails, other.encryptionDetails) && + Objects.equals(subresourceUris, other.subresourceUris) && + Objects.equals(mediaUrl, other.mediaUrl) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, apiVersion, callSid, conferenceSid, dateCreated, dateUpdated, startTime, duration, sid, price, priceUnit, status, channels, source, errorCode, uri, encryptionDetails, subresourceUris, mediaUrl); + return Objects.hash( + accountSid, + apiVersion, + callSid, + conferenceSid, + dateCreated, + dateUpdated, + startTime, + duration, + sid, + price, + priceUnit, + status, + channels, + source, + errorCode, + uri, + encryptionDetails, + subresourceUris, + mediaUrl + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/RecordingDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/RecordingDeleter.java index e844d03d46..9c75eb7b9a 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/RecordingDeleter.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/RecordingDeleter.java @@ -24,28 +24,34 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class RecordingDeleter extends Deleter { + private String pathSid; private String pathAccountSid; - public RecordingDeleter(final String pathSid){ + public RecordingDeleter(final String pathSid) { this.pathSid = pathSid; } - public RecordingDeleter(final String pathAccountSid, final String pathSid){ + + public RecordingDeleter(final String pathAccountSid, final String pathSid) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/2010-04-01/Accounts/{AccountSid}/Recordings/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -55,9 +61,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Recording delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Recording delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/RecordingFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/RecordingFetcher.java index 03f21ae5cd..cb95f06150 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/RecordingFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/RecordingFetcher.java @@ -24,23 +24,24 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class RecordingFetcher extends Fetcher { + private String pathSid; private String pathAccountSid; private Boolean includeSoftDeleted; - public RecordingFetcher(final String pathSid){ + public RecordingFetcher(final String pathSid) { this.pathSid = pathSid; } - public RecordingFetcher(final String pathAccountSid, final String pathSid){ + + public RecordingFetcher(final String pathAccountSid, final String pathSid) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - public RecordingFetcher setIncludeSoftDeleted(final Boolean includeSoftDeleted){ + public RecordingFetcher setIncludeSoftDeleted( + final Boolean includeSoftDeleted + ) { this.includeSoftDeleted = includeSoftDeleted; return this; } @@ -49,9 +50,16 @@ public RecordingFetcher setIncludeSoftDeleted(final Boolean includeSoftDeleted){ public Recording fetch(final TwilioRestClient client) { String path = "/2010-04-01/Accounts/{AccountSid}/Recordings/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -62,21 +70,32 @@ public Recording fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Recording fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Recording fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Recording.fromJson(response.getStream(), client.getObjectMapper()); + return Recording.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addQueryParams(final Request request) { if (includeSoftDeleted != null) { - - request.addQueryParam("IncludeSoftDeleted", includeSoftDeleted.toString()); + request.addQueryParam( + "IncludeSoftDeleted", + includeSoftDeleted.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/RecordingReader.java b/src/main/java/com/twilio/rest/api/v2010/account/RecordingReader.java index a8f12bb5e7..b90378618b 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/RecordingReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/RecordingReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.api.v2010.account; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,13 +25,11 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; - - public class RecordingReader extends Reader { + private String pathAccountSid; private ZonedDateTime dateCreated; private ZonedDateTime dateCreatedBefore; @@ -40,37 +39,49 @@ public class RecordingReader extends Reader { private Boolean includeSoftDeleted; private Integer pageSize; - public RecordingReader(){ - } - public RecordingReader(final String pathAccountSid){ + public RecordingReader() {} + + public RecordingReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - public RecordingReader setDateCreated(final ZonedDateTime dateCreated){ + public RecordingReader setDateCreated(final ZonedDateTime dateCreated) { this.dateCreated = dateCreated; return this; } - public RecordingReader setDateCreatedBefore(final ZonedDateTime dateCreatedBefore){ + + public RecordingReader setDateCreatedBefore( + final ZonedDateTime dateCreatedBefore + ) { this.dateCreatedBefore = dateCreatedBefore; return this; } - public RecordingReader setDateCreatedAfter(final ZonedDateTime dateCreatedAfter){ + + public RecordingReader setDateCreatedAfter( + final ZonedDateTime dateCreatedAfter + ) { this.dateCreatedAfter = dateCreatedAfter; return this; } - public RecordingReader setCallSid(final String callSid){ + + public RecordingReader setCallSid(final String callSid) { this.callSid = callSid; return this; } - public RecordingReader setConferenceSid(final String conferenceSid){ + + public RecordingReader setConferenceSid(final String conferenceSid) { this.conferenceSid = conferenceSid; return this; } - public RecordingReader setIncludeSoftDeleted(final Boolean includeSoftDeleted){ + + public RecordingReader setIncludeSoftDeleted( + final Boolean includeSoftDeleted + ) { this.includeSoftDeleted = includeSoftDeleted; return this; } - public RecordingReader setPageSize(final Integer pageSize){ + + public RecordingReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -82,8 +93,15 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/2010-04-01/Accounts/{AccountSid}/Recordings.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -95,13 +113,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Recording read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Recording read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -117,7 +143,10 @@ private Page pageForRequest(final TwilioRestClient client, final Requ } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.API.toString()) @@ -125,9 +154,11 @@ public Page previousPage(final Page page, final TwilioRest return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.API.toString()) @@ -136,39 +167,49 @@ public Page nextPage(final Page page, final TwilioRestClie } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (dateCreated != null) { - request.addQueryParam("DateCreated", dateCreated.format(DateTimeFormatter.ofPattern(Request.QUERY_STRING_DATE_TIME_FORMAT))); - } - else if (dateCreatedAfter != null || dateCreatedBefore != null) { - request.addQueryDateTimeRange("DateCreated", dateCreatedAfter, dateCreatedBefore); + request.addQueryParam( + "DateCreated", + dateCreated.format( + DateTimeFormatter.ofPattern( + Request.QUERY_STRING_DATE_TIME_FORMAT + ) + ) + ); + } else if (dateCreatedAfter != null || dateCreatedBefore != null) { + request.addQueryDateTimeRange( + "DateCreated", + dateCreatedAfter, + dateCreatedBefore + ); } if (callSid != null) { - request.addQueryParam("CallSid", callSid); } if (conferenceSid != null) { - request.addQueryParam("ConferenceSid", conferenceSid); } if (includeSoftDeleted != null) { - - request.addQueryParam("IncludeSoftDeleted", includeSoftDeleted.toString()); + request.addQueryParam( + "IncludeSoftDeleted", + includeSoftDeleted.toString() + ); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/ShortCode.java b/src/main/java/com/twilio/rest/api/v2010/account/ShortCode.java index 348371e136..810e86246f 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/ShortCode.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/ShortCode.java @@ -23,55 +23,63 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; import com.twilio.http.HttpMethod; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class ShortCode extends Resource { + private static final long serialVersionUID = 169753160210519L; - public static ShortCodeFetcher fetcher(final String pathSid){ + public static ShortCodeFetcher fetcher(final String pathSid) { return new ShortCodeFetcher(pathSid); } - public static ShortCodeFetcher fetcher(final String pathAccountSid, final String pathSid){ + + public static ShortCodeFetcher fetcher( + final String pathAccountSid, + final String pathSid + ) { return new ShortCodeFetcher(pathAccountSid, pathSid); } - public static ShortCodeReader reader(){ + public static ShortCodeReader reader() { return new ShortCodeReader(); } - public static ShortCodeReader reader(final String pathAccountSid){ + + public static ShortCodeReader reader(final String pathAccountSid) { return new ShortCodeReader(pathAccountSid); } - public static ShortCodeUpdater updater(final String pathSid){ + public static ShortCodeUpdater updater(final String pathSid) { return new ShortCodeUpdater(pathSid); } - public static ShortCodeUpdater updater(final String pathAccountSid, final String pathSid){ + + public static ShortCodeUpdater updater( + final String pathAccountSid, + final String pathSid + ) { return new ShortCodeUpdater(pathAccountSid, pathSid); } /** - * Converts a JSON String into a ShortCode object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return ShortCode object represented by the provided JSON - */ - public static ShortCode fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a ShortCode object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return ShortCode object represented by the provided JSON + */ + public static ShortCode fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, ShortCode.class); @@ -83,14 +91,17 @@ public static ShortCode fromJson(final String json, final ObjectMapper objectMap } /** - * Converts a JSON InputStream into a ShortCode object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return ShortCode object represented by the provided JSON - */ - public static ShortCode fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a ShortCode object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return ShortCode object represented by the provided JSON + */ + public static ShortCode fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, ShortCode.class); @@ -116,41 +127,18 @@ public static ShortCode fromJson(final InputStream json, final ObjectMapper obje @JsonCreator private ShortCode( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("api_version") - final String apiVersion, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("short_code") - final String shortCode, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("sms_fallback_method") - final HttpMethod smsFallbackMethod, - - @JsonProperty("sms_fallback_url") - final URI smsFallbackUrl, - - @JsonProperty("sms_method") - final HttpMethod smsMethod, - - @JsonProperty("sms_url") - final URI smsUrl, - - @JsonProperty("uri") - final String uri + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("api_version") final String apiVersion, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("short_code") final String shortCode, + @JsonProperty("sid") final String sid, + @JsonProperty("sms_fallback_method") final HttpMethod smsFallbackMethod, + @JsonProperty("sms_fallback_url") final URI smsFallbackUrl, + @JsonProperty("sms_method") final HttpMethod smsMethod, + @JsonProperty("sms_url") final URI smsUrl, + @JsonProperty("uri") final String uri ) { this.accountSid = accountSid; this.apiVersion = apiVersion; @@ -166,46 +154,57 @@ private ShortCode( this.uri = uri; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getApiVersion() { - return this.apiVersion; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getShortCode() { - return this.shortCode; - } - public final String getSid() { - return this.sid; - } - public final HttpMethod getSmsFallbackMethod() { - return this.smsFallbackMethod; - } - public final URI getSmsFallbackUrl() { - return this.smsFallbackUrl; - } - public final HttpMethod getSmsMethod() { - return this.smsMethod; - } - public final URI getSmsUrl() { - return this.smsUrl; - } - public final String getUri() { - return this.uri; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getApiVersion() { + return this.apiVersion; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getShortCode() { + return this.shortCode; + } + + public final String getSid() { + return this.sid; + } + + public final HttpMethod getSmsFallbackMethod() { + return this.smsFallbackMethod; + } + + public final URI getSmsFallbackUrl() { + return this.smsFallbackUrl; + } + + public final HttpMethod getSmsMethod() { + return this.smsMethod; + } + + public final URI getSmsUrl() { + return this.smsUrl; + } + + public final String getUri() { + return this.uri; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -215,13 +214,37 @@ public boolean equals(final Object o) { ShortCode other = (ShortCode) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(apiVersion, other.apiVersion) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(shortCode, other.shortCode) && Objects.equals(sid, other.sid) && Objects.equals(smsFallbackMethod, other.smsFallbackMethod) && Objects.equals(smsFallbackUrl, other.smsFallbackUrl) && Objects.equals(smsMethod, other.smsMethod) && Objects.equals(smsUrl, other.smsUrl) && Objects.equals(uri, other.uri) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(apiVersion, other.apiVersion) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(shortCode, other.shortCode) && + Objects.equals(sid, other.sid) && + Objects.equals(smsFallbackMethod, other.smsFallbackMethod) && + Objects.equals(smsFallbackUrl, other.smsFallbackUrl) && + Objects.equals(smsMethod, other.smsMethod) && + Objects.equals(smsUrl, other.smsUrl) && + Objects.equals(uri, other.uri) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, apiVersion, dateCreated, dateUpdated, friendlyName, shortCode, sid, smsFallbackMethod, smsFallbackUrl, smsMethod, smsUrl, uri); + return Objects.hash( + accountSid, + apiVersion, + dateCreated, + dateUpdated, + friendlyName, + shortCode, + sid, + smsFallbackMethod, + smsFallbackUrl, + smsMethod, + smsUrl, + uri + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/ShortCodeFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/ShortCodeFetcher.java index 4303f97333..cb3a44c2f7 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/ShortCodeFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/ShortCodeFetcher.java @@ -24,29 +24,35 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class ShortCodeFetcher extends Fetcher { + private String pathSid; private String pathAccountSid; - public ShortCodeFetcher(final String pathSid){ + public ShortCodeFetcher(final String pathSid) { this.pathSid = pathSid; } - public ShortCodeFetcher(final String pathAccountSid, final String pathSid){ + + public ShortCodeFetcher(final String pathAccountSid, final String pathSid) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - @Override public ShortCode fetch(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/SMS/ShortCodes/{Sid}.json"; + String path = + "/2010-04-01/Accounts/{AccountSid}/SMS/ShortCodes/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -56,15 +62,23 @@ public ShortCode fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("ShortCode fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "ShortCode fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return ShortCode.fromJson(response.getStream(), client.getObjectMapper()); + return ShortCode.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/ShortCodeReader.java b/src/main/java/com/twilio/rest/api/v2010/account/ShortCodeReader.java index d80b9ab0be..27dcc561c2 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/ShortCodeReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/ShortCodeReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.api.v2010.account; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,31 +25,31 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class ShortCodeReader extends Reader { + private String pathAccountSid; private String friendlyName; private String shortCode; private Integer pageSize; - public ShortCodeReader(){ - } - public ShortCodeReader(final String pathAccountSid){ + public ShortCodeReader() {} + + public ShortCodeReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - public ShortCodeReader setFriendlyName(final String friendlyName){ + public ShortCodeReader setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public ShortCodeReader setShortCode(final String shortCode){ + + public ShortCodeReader setShortCode(final String shortCode) { this.shortCode = shortCode; return this; } - public ShortCodeReader setPageSize(final Integer pageSize){ + + public ShortCodeReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -60,8 +61,15 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/2010-04-01/Accounts/{AccountSid}/SMS/ShortCodes.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -73,13 +81,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("ShortCode read failed: Unable to connect to server"); + throw new ApiConnectionException( + "ShortCode read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -95,7 +111,10 @@ private Page pageForRequest(final TwilioRestClient client, final Requ } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.API.toString()) @@ -103,9 +122,11 @@ public Page previousPage(final Page page, final TwilioRest return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.API.toString()) @@ -114,29 +135,27 @@ public Page nextPage(final Page page, final TwilioRestClie } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (friendlyName != null) { - request.addQueryParam("FriendlyName", friendlyName); } if (shortCode != null) { - request.addQueryParam("ShortCode", shortCode); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/ShortCodeUpdater.java b/src/main/java/com/twilio/rest/api/v2010/account/ShortCodeUpdater.java index 69b2e139bc..7b7654de1e 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/ShortCodeUpdater.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/ShortCodeUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010.account; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -24,12 +25,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.net.URI; +public class ShortCodeUpdater extends Updater { - -public class ShortCodeUpdater extends Updater{ private String pathSid; private String pathAccountSid; private String friendlyName; @@ -39,98 +38,121 @@ public class ShortCodeUpdater extends Updater{ private URI smsFallbackUrl; private HttpMethod smsFallbackMethod; - public ShortCodeUpdater(final String pathSid){ + public ShortCodeUpdater(final String pathSid) { this.pathSid = pathSid; } - public ShortCodeUpdater(final String pathAccountSid, final String pathSid){ + + public ShortCodeUpdater(final String pathAccountSid, final String pathSid) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - public ShortCodeUpdater setFriendlyName(final String friendlyName){ + public ShortCodeUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public ShortCodeUpdater setApiVersion(final String apiVersion){ + + public ShortCodeUpdater setApiVersion(final String apiVersion) { this.apiVersion = apiVersion; return this; } - public ShortCodeUpdater setSmsUrl(final URI smsUrl){ + + public ShortCodeUpdater setSmsUrl(final URI smsUrl) { this.smsUrl = smsUrl; return this; } - public ShortCodeUpdater setSmsUrl(final String smsUrl){ + public ShortCodeUpdater setSmsUrl(final String smsUrl) { return setSmsUrl(Promoter.uriFromString(smsUrl)); } - public ShortCodeUpdater setSmsMethod(final HttpMethod smsMethod){ + + public ShortCodeUpdater setSmsMethod(final HttpMethod smsMethod) { this.smsMethod = smsMethod; return this; } - public ShortCodeUpdater setSmsFallbackUrl(final URI smsFallbackUrl){ + + public ShortCodeUpdater setSmsFallbackUrl(final URI smsFallbackUrl) { this.smsFallbackUrl = smsFallbackUrl; return this; } - public ShortCodeUpdater setSmsFallbackUrl(final String smsFallbackUrl){ + public ShortCodeUpdater setSmsFallbackUrl(final String smsFallbackUrl) { return setSmsFallbackUrl(Promoter.uriFromString(smsFallbackUrl)); } - public ShortCodeUpdater setSmsFallbackMethod(final HttpMethod smsFallbackMethod){ + + public ShortCodeUpdater setSmsFallbackMethod( + final HttpMethod smsFallbackMethod + ) { this.smsFallbackMethod = smsFallbackMethod; return this; } @Override - public ShortCode update(final TwilioRestClient client){ - String path = "/2010-04-01/Accounts/{AccountSid}/SMS/ShortCodes/{Sid}.json"; + public ShortCode update(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SMS/ShortCodes/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.API.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("ShortCode update failed: Unable to connect to server"); + throw new ApiConnectionException( + "ShortCode update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return ShortCode.fromJson(response.getStream(), client.getObjectMapper()); + return ShortCode.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (apiVersion != null) { request.addPostParam("ApiVersion", apiVersion); - } if (smsUrl != null) { request.addPostParam("SmsUrl", smsUrl.toString()); - } if (smsMethod != null) { request.addPostParam("SmsMethod", smsMethod.toString()); - } if (smsFallbackUrl != null) { request.addPostParam("SmsFallbackUrl", smsFallbackUrl.toString()); - } if (smsFallbackMethod != null) { - request.addPostParam("SmsFallbackMethod", smsFallbackMethod.toString()); - + request.addPostParam( + "SmsFallbackMethod", + smsFallbackMethod.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/SigningKey.java b/src/main/java/com/twilio/rest/api/v2010/account/SigningKey.java index be2d792334..e8ee7a453d 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/SigningKey.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/SigningKey.java @@ -23,60 +23,72 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class SigningKey extends Resource { + private static final long serialVersionUID = 35259719636912L; - public static SigningKeyDeleter deleter(final String pathSid){ + public static SigningKeyDeleter deleter(final String pathSid) { return new SigningKeyDeleter(pathSid); } - public static SigningKeyDeleter deleter(final String pathAccountSid, final String pathSid){ + + public static SigningKeyDeleter deleter( + final String pathAccountSid, + final String pathSid + ) { return new SigningKeyDeleter(pathAccountSid, pathSid); } - public static SigningKeyFetcher fetcher(final String pathSid){ + public static SigningKeyFetcher fetcher(final String pathSid) { return new SigningKeyFetcher(pathSid); } - public static SigningKeyFetcher fetcher(final String pathAccountSid, final String pathSid){ + + public static SigningKeyFetcher fetcher( + final String pathAccountSid, + final String pathSid + ) { return new SigningKeyFetcher(pathAccountSid, pathSid); } - public static SigningKeyReader reader(){ + public static SigningKeyReader reader() { return new SigningKeyReader(); } - public static SigningKeyReader reader(final String pathAccountSid){ + + public static SigningKeyReader reader(final String pathAccountSid) { return new SigningKeyReader(pathAccountSid); } - public static SigningKeyUpdater updater(final String pathSid){ + public static SigningKeyUpdater updater(final String pathSid) { return new SigningKeyUpdater(pathSid); } - public static SigningKeyUpdater updater(final String pathAccountSid, final String pathSid){ + + public static SigningKeyUpdater updater( + final String pathAccountSid, + final String pathSid + ) { return new SigningKeyUpdater(pathAccountSid, pathSid); } /** - * Converts a JSON String into a SigningKey object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return SigningKey object represented by the provided JSON - */ - public static SigningKey fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a SigningKey object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return SigningKey object represented by the provided JSON + */ + public static SigningKey fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SigningKey.class); @@ -88,14 +100,17 @@ public static SigningKey fromJson(final String json, final ObjectMapper objectMa } /** - * Converts a JSON InputStream into a SigningKey object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return SigningKey object represented by the provided JSON - */ - public static SigningKey fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a SigningKey object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return SigningKey object represented by the provided JSON + */ + public static SigningKey fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SigningKey.class); @@ -113,17 +128,10 @@ public static SigningKey fromJson(final InputStream json, final ObjectMapper obj @JsonCreator private SigningKey( - @JsonProperty("sid") - final String sid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated + @JsonProperty("sid") final String sid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated ) { this.sid = sid; this.friendlyName = friendlyName; @@ -131,22 +139,25 @@ private SigningKey( this.dateUpdated = DateConverter.rfc2822DateTimeFromString(dateUpdated); } - public final String getSid() { - return this.sid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } + public final String getSid() { + return this.sid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -156,13 +167,16 @@ public boolean equals(final Object o) { SigningKey other = (SigningKey) o; - return Objects.equals(sid, other.sid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) + ); } @Override public int hashCode() { return Objects.hash(sid, friendlyName, dateCreated, dateUpdated); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/SigningKeyDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/SigningKeyDeleter.java index 0d05e72ae3..4a8bada3f4 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/SigningKeyDeleter.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/SigningKeyDeleter.java @@ -24,28 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class SigningKeyDeleter extends Deleter { + private String pathSid; private String pathAccountSid; - public SigningKeyDeleter(final String pathSid){ + public SigningKeyDeleter(final String pathSid) { this.pathSid = pathSid; } - public SigningKeyDeleter(final String pathAccountSid, final String pathSid){ + + public SigningKeyDeleter( + final String pathAccountSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/SigningKeys/{Sid}.json"; + String path = + "/2010-04-01/Accounts/{AccountSid}/SigningKeys/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -55,9 +65,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SigningKey delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "SigningKey delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/SigningKeyFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/SigningKeyFetcher.java index 75659e2d3e..2099406333 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/SigningKeyFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/SigningKeyFetcher.java @@ -24,29 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class SigningKeyFetcher extends Fetcher { + private String pathSid; private String pathAccountSid; - public SigningKeyFetcher(final String pathSid){ + public SigningKeyFetcher(final String pathSid) { this.pathSid = pathSid; } - public SigningKeyFetcher(final String pathAccountSid, final String pathSid){ + + public SigningKeyFetcher( + final String pathAccountSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - @Override public SigningKey fetch(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/SigningKeys/{Sid}.json"; + String path = + "/2010-04-01/Accounts/{AccountSid}/SigningKeys/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -56,15 +65,23 @@ public SigningKey fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SigningKey fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "SigningKey fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return SigningKey.fromJson(response.getStream(), client.getObjectMapper()); + return SigningKey.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/SigningKeyReader.java b/src/main/java/com/twilio/rest/api/v2010/account/SigningKeyReader.java index bbc6aa510b..04591da0d8 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/SigningKeyReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/SigningKeyReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.api.v2010.account; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,21 +25,19 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class SigningKeyReader extends Reader { + private String pathAccountSid; private Integer pageSize; - public SigningKeyReader(){ - } - public SigningKeyReader(final String pathAccountSid){ + public SigningKeyReader() {} + + public SigningKeyReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - public SigningKeyReader setPageSize(final Integer pageSize){ + public SigningKeyReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -50,8 +49,15 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/2010-04-01/Accounts/{AccountSid}/SigningKeys.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -63,13 +69,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SigningKey read failed: Unable to connect to server"); + throw new ApiConnectionException( + "SigningKey read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -85,7 +99,10 @@ private Page pageForRequest(final TwilioRestClient client, final Req } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.API.toString()) @@ -93,9 +110,11 @@ public Page previousPage(final Page page, final TwilioRe return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.API.toString()) @@ -104,21 +123,21 @@ public Page nextPage(final Page page, final TwilioRestCl } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/SigningKeyUpdater.java b/src/main/java/com/twilio/rest/api/v2010/account/SigningKeyUpdater.java index 542d5b5203..a4972d4ef6 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/SigningKeyUpdater.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/SigningKeyUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010.account; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,58 +25,77 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class SigningKeyUpdater extends Updater { - - -public class SigningKeyUpdater extends Updater{ private String pathSid; private String pathAccountSid; private String friendlyName; - public SigningKeyUpdater(final String pathSid){ + public SigningKeyUpdater(final String pathSid) { this.pathSid = pathSid; } - public SigningKeyUpdater(final String pathAccountSid, final String pathSid){ + + public SigningKeyUpdater( + final String pathAccountSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - public SigningKeyUpdater setFriendlyName(final String friendlyName){ + public SigningKeyUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } @Override - public SigningKey update(final TwilioRestClient client){ - String path = "/2010-04-01/Accounts/{AccountSid}/SigningKeys/{Sid}.json"; + public SigningKey update(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SigningKeys/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.API.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SigningKey update failed: Unable to connect to server"); + throw new ApiConnectionException( + "SigningKey update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return SigningKey.fromJson(response.getStream(), client.getObjectMapper()); + return SigningKey.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/Token.java b/src/main/java/com/twilio/rest/api/v2010/account/Token.java index 9e0d1e7b97..6ab0eff4fc 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/Token.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/Token.java @@ -23,41 +23,41 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - +import com.twilio.type.IceServer; import java.io.IOException; import java.io.InputStream; import java.time.ZonedDateTime; - import java.util.List; import java.util.Objects; - - -import com.twilio.type.IceServer; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Token extends Resource { + private static final long serialVersionUID = 218446728059095L; - public static TokenCreator creator(){ + public static TokenCreator creator() { return new TokenCreator(); } - public static TokenCreator creator(final String pathAccountSid){ + + public static TokenCreator creator(final String pathAccountSid) { return new TokenCreator(pathAccountSid); } /** - * Converts a JSON String into a Token object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Token object represented by the provided JSON - */ - public static Token fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Token object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Token object represented by the provided JSON + */ + public static Token fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Token.class); @@ -69,14 +69,17 @@ public static Token fromJson(final String json, final ObjectMapper objectMapper) } /** - * Converts a JSON InputStream into a Token object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Token object represented by the provided JSON - */ - public static Token fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Token object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Token object represented by the provided JSON + */ + public static Token fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Token.class); @@ -97,26 +100,13 @@ public static Token fromJson(final InputStream json, final ObjectMapper objectMa @JsonCreator private Token( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("ice_servers") - final List iceServers, - - @JsonProperty("password") - final String password, - - @JsonProperty("ttl") - final String ttl, - - @JsonProperty("username") - final String username + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("ice_servers") final List iceServers, + @JsonProperty("password") final String password, + @JsonProperty("ttl") final String ttl, + @JsonProperty("username") final String username ) { this.accountSid = accountSid; this.dateCreated = DateConverter.rfc2822DateTimeFromString(dateCreated); @@ -127,31 +117,37 @@ private Token( this.username = username; } - public final String getAccountSid() { - return this.accountSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final List getIceServers() { - return this.iceServers; - } - public final String getPassword() { - return this.password; - } - public final String getTtl() { - return this.ttl; - } - public final String getUsername() { - return this.username; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final List getIceServers() { + return this.iceServers; + } + + public final String getPassword() { + return this.password; + } + + public final String getTtl() { + return this.ttl; + } + + public final String getUsername() { + return this.username; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -161,13 +157,27 @@ public boolean equals(final Object o) { Token other = (Token) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(iceServers, other.iceServers) && Objects.equals(password, other.password) && Objects.equals(ttl, other.ttl) && Objects.equals(username, other.username) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(iceServers, other.iceServers) && + Objects.equals(password, other.password) && + Objects.equals(ttl, other.ttl) && + Objects.equals(username, other.username) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, dateCreated, dateUpdated, iceServers, password, ttl, username); + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + iceServers, + password, + ttl, + username + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/TokenCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/TokenCreator.java index 325bdfcff6..80584d6cad 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/TokenCreator.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/TokenCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010.account; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,42 +25,53 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class TokenCreator extends Creator { - - -public class TokenCreator extends Creator{ private String pathAccountSid; private Integer ttl; - public TokenCreator() { - } + public TokenCreator() {} + public TokenCreator(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - public TokenCreator setTtl(final Integer ttl){ + public TokenCreator setTtl(final Integer ttl) { this.ttl = ttl; return this; } @Override - public Token create(final TwilioRestClient client){ + public Token create(final TwilioRestClient client) { String path = "/2010-04-01/Accounts/{AccountSid}/Tokens.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.API.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Token creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Token creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -68,10 +80,10 @@ public Token create(final TwilioRestClient client){ return Token.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (ttl != null) { request.addPostParam("Ttl", ttl.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/Transcription.java b/src/main/java/com/twilio/rest/api/v2010/account/Transcription.java index 30f051698f..65bca310ff 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/Transcription.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/Transcription.java @@ -20,61 +20,69 @@ import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.twilio.base.Resource; -import java.util.Currency; +import com.twilio.converter.CurrencyDeserializer; import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; -import com.twilio.converter.CurrencyDeserializer; import com.twilio.exception.ApiConnectionException; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; +import java.math.BigDecimal; import java.time.ZonedDateTime; - +import java.util.Currency; import java.util.Objects; - - -import java.math.BigDecimal; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Transcription extends Resource { + private static final long serialVersionUID = 169453036448500L; - public static TranscriptionDeleter deleter(final String pathSid){ + public static TranscriptionDeleter deleter(final String pathSid) { return new TranscriptionDeleter(pathSid); } - public static TranscriptionDeleter deleter(final String pathAccountSid, final String pathSid){ + + public static TranscriptionDeleter deleter( + final String pathAccountSid, + final String pathSid + ) { return new TranscriptionDeleter(pathAccountSid, pathSid); } - public static TranscriptionFetcher fetcher(final String pathSid){ + public static TranscriptionFetcher fetcher(final String pathSid) { return new TranscriptionFetcher(pathSid); } - public static TranscriptionFetcher fetcher(final String pathAccountSid, final String pathSid){ + + public static TranscriptionFetcher fetcher( + final String pathAccountSid, + final String pathSid + ) { return new TranscriptionFetcher(pathAccountSid, pathSid); } - public static TranscriptionReader reader(){ + public static TranscriptionReader reader() { return new TranscriptionReader(); } - public static TranscriptionReader reader(final String pathAccountSid){ + + public static TranscriptionReader reader(final String pathAccountSid) { return new TranscriptionReader(pathAccountSid); } /** - * Converts a JSON String into a Transcription object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Transcription object represented by the provided JSON - */ - public static Transcription fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Transcription object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Transcription object represented by the provided JSON + */ + public static Transcription fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Transcription.class); @@ -86,14 +94,17 @@ public static Transcription fromJson(final String json, final ObjectMapper objec } /** - * Converts a JSON InputStream into a Transcription object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Transcription object represented by the provided JSON - */ - public static Transcription fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Transcription object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Transcription object represented by the provided JSON + */ + public static Transcription fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Transcription.class); @@ -103,6 +114,7 @@ public static Transcription fromJson(final InputStream json, final ObjectMapper throw new ApiConnectionException(e.getMessage(), e); } } + public enum Status { IN_PROGRESS("in-progress"), COMPLETED("completed"), @@ -140,45 +152,21 @@ public static Status forValue(final String value) { @JsonCreator private Transcription( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("api_version") - final String apiVersion, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("duration") - final String duration, - - @JsonProperty("price") - final BigDecimal price, - - @JsonProperty("price_unit") - @JsonDeserialize(using = com.twilio.converter.CurrencyDeserializer.class) - final Currency priceUnit, - - @JsonProperty("recording_sid") - final String recordingSid, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("status") - final Transcription.Status status, - - @JsonProperty("transcription_text") - final String transcriptionText, - - @JsonProperty("type") - final String type, - - @JsonProperty("uri") - final String uri + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("api_version") final String apiVersion, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("duration") final String duration, + @JsonProperty("price") final BigDecimal price, + @JsonProperty("price_unit") @JsonDeserialize( + using = com.twilio.converter.CurrencyDeserializer.class + ) final Currency priceUnit, + @JsonProperty("recording_sid") final String recordingSid, + @JsonProperty("sid") final String sid, + @JsonProperty("status") final Transcription.Status status, + @JsonProperty("transcription_text") final String transcriptionText, + @JsonProperty("type") final String type, + @JsonProperty("uri") final String uri ) { this.accountSid = accountSid; this.apiVersion = apiVersion; @@ -195,49 +183,61 @@ private Transcription( this.uri = uri; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getApiVersion() { - return this.apiVersion; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getDuration() { - return this.duration; - } - public final BigDecimal getPrice() { - return this.price; - } - public final Currency getPriceUnit() { - return this.priceUnit; - } - public final String getRecordingSid() { - return this.recordingSid; - } - public final String getSid() { - return this.sid; - } - public final Transcription.Status getStatus() { - return this.status; - } - public final String getTranscriptionText() { - return this.transcriptionText; - } - public final String getType() { - return this.type; - } - public final String getUri() { - return this.uri; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getApiVersion() { + return this.apiVersion; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getDuration() { + return this.duration; + } + + public final BigDecimal getPrice() { + return this.price; + } + + public final Currency getPriceUnit() { + return this.priceUnit; + } + + public final String getRecordingSid() { + return this.recordingSid; + } + + public final String getSid() { + return this.sid; + } + + public final Transcription.Status getStatus() { + return this.status; + } + + public final String getTranscriptionText() { + return this.transcriptionText; + } + + public final String getType() { + return this.type; + } + + public final String getUri() { + return this.uri; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -247,13 +247,39 @@ public boolean equals(final Object o) { Transcription other = (Transcription) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(apiVersion, other.apiVersion) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(duration, other.duration) && Objects.equals(price, other.price) && Objects.equals(priceUnit, other.priceUnit) && Objects.equals(recordingSid, other.recordingSid) && Objects.equals(sid, other.sid) && Objects.equals(status, other.status) && Objects.equals(transcriptionText, other.transcriptionText) && Objects.equals(type, other.type) && Objects.equals(uri, other.uri) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(apiVersion, other.apiVersion) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(duration, other.duration) && + Objects.equals(price, other.price) && + Objects.equals(priceUnit, other.priceUnit) && + Objects.equals(recordingSid, other.recordingSid) && + Objects.equals(sid, other.sid) && + Objects.equals(status, other.status) && + Objects.equals(transcriptionText, other.transcriptionText) && + Objects.equals(type, other.type) && + Objects.equals(uri, other.uri) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, apiVersion, dateCreated, dateUpdated, duration, price, priceUnit, recordingSid, sid, status, transcriptionText, type, uri); + return Objects.hash( + accountSid, + apiVersion, + dateCreated, + dateUpdated, + duration, + price, + priceUnit, + recordingSid, + sid, + status, + transcriptionText, + type, + uri + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/TranscriptionDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/TranscriptionDeleter.java index 04a3c99cce..797a8a9178 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/TranscriptionDeleter.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/TranscriptionDeleter.java @@ -24,28 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class TranscriptionDeleter extends Deleter { + private String pathSid; private String pathAccountSid; - public TranscriptionDeleter(final String pathSid){ + public TranscriptionDeleter(final String pathSid) { this.pathSid = pathSid; } - public TranscriptionDeleter(final String pathAccountSid, final String pathSid){ + + public TranscriptionDeleter( + final String pathAccountSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/Transcriptions/{Sid}.json"; + String path = + "/2010-04-01/Accounts/{AccountSid}/Transcriptions/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -55,9 +65,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Transcription delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Transcription delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/TranscriptionFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/TranscriptionFetcher.java index 9a108e585a..2b9044a8f3 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/TranscriptionFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/TranscriptionFetcher.java @@ -24,29 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class TranscriptionFetcher extends Fetcher { + private String pathSid; private String pathAccountSid; - public TranscriptionFetcher(final String pathSid){ + public TranscriptionFetcher(final String pathSid) { this.pathSid = pathSid; } - public TranscriptionFetcher(final String pathAccountSid, final String pathSid){ + + public TranscriptionFetcher( + final String pathAccountSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - @Override public Transcription fetch(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/Transcriptions/{Sid}.json"; + String path = + "/2010-04-01/Accounts/{AccountSid}/Transcriptions/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -56,15 +65,23 @@ public Transcription fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Transcription fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Transcription fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Transcription.fromJson(response.getStream(), client.getObjectMapper()); + return Transcription.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/TranscriptionReader.java b/src/main/java/com/twilio/rest/api/v2010/account/TranscriptionReader.java index 8549c3a8ee..e5814b8f5f 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/TranscriptionReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/TranscriptionReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.api.v2010.account; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,21 +25,19 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class TranscriptionReader extends Reader { + private String pathAccountSid; private Integer pageSize; - public TranscriptionReader(){ - } - public TranscriptionReader(final String pathAccountSid){ + public TranscriptionReader() {} + + public TranscriptionReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - public TranscriptionReader setPageSize(final Integer pageSize){ + public TranscriptionReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -50,8 +49,15 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/2010-04-01/Accounts/{AccountSid}/Transcriptions.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -63,13 +69,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Transcription read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Transcription read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -85,7 +99,10 @@ private Page pageForRequest(final TwilioRestClient client, final } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.API.toString()) @@ -93,9 +110,11 @@ public Page previousPage(final Page page, final Tw return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.API.toString()) @@ -104,21 +123,21 @@ public Page nextPage(final Page page, final Twilio } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/ValidationRequest.java b/src/main/java/com/twilio/rest/api/v2010/account/ValidationRequest.java index dff81928ca..e4135dd589 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/ValidationRequest.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/ValidationRequest.java @@ -22,38 +22,43 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class ValidationRequest extends Resource { + private static final long serialVersionUID = 159203610764140L; - public static ValidationRequestCreator creator(final com.twilio.type.PhoneNumber phoneNumber){ + public static ValidationRequestCreator creator( + final com.twilio.type.PhoneNumber phoneNumber + ) { return new ValidationRequestCreator(phoneNumber); } - public static ValidationRequestCreator creator(final String pathAccountSid, final com.twilio.type.PhoneNumber phoneNumber){ + + public static ValidationRequestCreator creator( + final String pathAccountSid, + final com.twilio.type.PhoneNumber phoneNumber + ) { return new ValidationRequestCreator(pathAccountSid, phoneNumber); } /** - * Converts a JSON String into a ValidationRequest object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return ValidationRequest object represented by the provided JSON - */ - public static ValidationRequest fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a ValidationRequest object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return ValidationRequest object represented by the provided JSON + */ + public static ValidationRequest fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, ValidationRequest.class); @@ -65,14 +70,17 @@ public static ValidationRequest fromJson(final String json, final ObjectMapper o } /** - * Converts a JSON InputStream into a ValidationRequest object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return ValidationRequest object represented by the provided JSON - */ - public static ValidationRequest fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a ValidationRequest object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return ValidationRequest object represented by the provided JSON + */ + public static ValidationRequest fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, ValidationRequest.class); @@ -91,20 +99,13 @@ public static ValidationRequest fromJson(final InputStream json, final ObjectMap @JsonCreator private ValidationRequest( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("call_sid") - final String callSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("phone_number") - final com.twilio.type.PhoneNumber phoneNumber, - - @JsonProperty("validation_code") - final String validationCode + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("call_sid") final String callSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty( + "phone_number" + ) final com.twilio.type.PhoneNumber phoneNumber, + @JsonProperty("validation_code") final String validationCode ) { this.accountSid = accountSid; this.callSid = callSid; @@ -113,25 +114,29 @@ private ValidationRequest( this.validationCode = validationCode; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getCallSid() { - return this.callSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final com.twilio.type.PhoneNumber getPhoneNumber() { - return this.phoneNumber; - } - public final String getValidationCode() { - return this.validationCode; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getCallSid() { + return this.callSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final com.twilio.type.PhoneNumber getPhoneNumber() { + return this.phoneNumber; + } + + public final String getValidationCode() { + return this.validationCode; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -141,13 +146,23 @@ public boolean equals(final Object o) { ValidationRequest other = (ValidationRequest) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(callSid, other.callSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(phoneNumber, other.phoneNumber) && Objects.equals(validationCode, other.validationCode) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(callSid, other.callSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(phoneNumber, other.phoneNumber) && + Objects.equals(validationCode, other.validationCode) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, callSid, friendlyName, phoneNumber, validationCode); + return Objects.hash( + accountSid, + callSid, + friendlyName, + phoneNumber, + validationCode + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/ValidationRequestCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/ValidationRequestCreator.java index 0783eed14a..a3cc62195a 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/ValidationRequestCreator.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/ValidationRequestCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010.account; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -25,12 +26,10 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.net.URI; - - - import java.net.URI; -public class ValidationRequestCreator extends Creator{ +public class ValidationRequestCreator extends Creator { + private com.twilio.type.PhoneNumber phoneNumber; private String pathAccountSid; private String friendlyName; @@ -39,98 +38,136 @@ public class ValidationRequestCreator extends Creator{ private URI statusCallback; private HttpMethod statusCallbackMethod; - public ValidationRequestCreator(final com.twilio.type.PhoneNumber phoneNumber) { + public ValidationRequestCreator( + final com.twilio.type.PhoneNumber phoneNumber + ) { this.phoneNumber = phoneNumber; } - public ValidationRequestCreator(final String pathAccountSid, final com.twilio.type.PhoneNumber phoneNumber) { + + public ValidationRequestCreator( + final String pathAccountSid, + final com.twilio.type.PhoneNumber phoneNumber + ) { this.pathAccountSid = pathAccountSid; this.phoneNumber = phoneNumber; } - public ValidationRequestCreator setPhoneNumber(final com.twilio.type.PhoneNumber phoneNumber){ + public ValidationRequestCreator setPhoneNumber( + final com.twilio.type.PhoneNumber phoneNumber + ) { this.phoneNumber = phoneNumber; return this; } - public ValidationRequestCreator setPhoneNumber(final String phoneNumber){ + public ValidationRequestCreator setPhoneNumber(final String phoneNumber) { return setPhoneNumber(Promoter.phoneNumberFromString(phoneNumber)); } - public ValidationRequestCreator setFriendlyName(final String friendlyName){ + + public ValidationRequestCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public ValidationRequestCreator setCallDelay(final Integer callDelay){ + + public ValidationRequestCreator setCallDelay(final Integer callDelay) { this.callDelay = callDelay; return this; } - public ValidationRequestCreator setExtension(final String extension){ + + public ValidationRequestCreator setExtension(final String extension) { this.extension = extension; return this; } - public ValidationRequestCreator setStatusCallback(final URI statusCallback){ + + public ValidationRequestCreator setStatusCallback( + final URI statusCallback + ) { this.statusCallback = statusCallback; return this; } - public ValidationRequestCreator setStatusCallback(final String statusCallback){ + public ValidationRequestCreator setStatusCallback( + final String statusCallback + ) { return setStatusCallback(Promoter.uriFromString(statusCallback)); } - public ValidationRequestCreator setStatusCallbackMethod(final HttpMethod statusCallbackMethod){ + + public ValidationRequestCreator setStatusCallbackMethod( + final HttpMethod statusCallbackMethod + ) { this.statusCallbackMethod = statusCallbackMethod; return this; } @Override - public ValidationRequest create(final TwilioRestClient client){ - String path = "/2010-04-01/Accounts/{AccountSid}/OutgoingCallerIds.json"; + public ValidationRequest create(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/OutgoingCallerIds.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"PhoneNumber"+"}", this.phoneNumber.encode("utf-8")); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "PhoneNumber" + "}", + this.phoneNumber.encode("utf-8") + ); Request request = new Request( HttpMethod.POST, Domains.API.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("ValidationRequest creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "ValidationRequest creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return ValidationRequest.fromJson(response.getStream(), client.getObjectMapper()); + return ValidationRequest.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (phoneNumber != null) { request.addPostParam("PhoneNumber", phoneNumber.toString()); - } if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (callDelay != null) { request.addPostParam("CallDelay", callDelay.toString()); - } if (extension != null) { request.addPostParam("Extension", extension); - } if (statusCallback != null) { request.addPostParam("StatusCallback", statusCallback.toString()); - } if (statusCallbackMethod != null) { - request.addPostParam("StatusCallbackMethod", statusCallbackMethod.toString()); - + request.addPostParam( + "StatusCallbackMethod", + statusCallbackMethod.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/address/DependentPhoneNumber.java b/src/main/java/com/twilio/rest/api/v2010/account/address/DependentPhoneNumber.java index 910a85b476..e46e46aac6 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/address/DependentPhoneNumber.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/address/DependentPhoneNumber.java @@ -24,43 +24,48 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; import com.twilio.http.HttpMethod; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class DependentPhoneNumber extends Resource { + private static final long serialVersionUID = 170982689441309L; - public static DependentPhoneNumberReader reader(final String pathAddressSid){ + public static DependentPhoneNumberReader reader( + final String pathAddressSid + ) { return new DependentPhoneNumberReader(pathAddressSid); } - public static DependentPhoneNumberReader reader(final String pathAccountSid, final String pathAddressSid){ + + public static DependentPhoneNumberReader reader( + final String pathAccountSid, + final String pathAddressSid + ) { return new DependentPhoneNumberReader(pathAccountSid, pathAddressSid); } /** - * Converts a JSON String into a DependentPhoneNumber object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return DependentPhoneNumber object represented by the provided JSON - */ - public static DependentPhoneNumber fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a DependentPhoneNumber object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return DependentPhoneNumber object represented by the provided JSON + */ + public static DependentPhoneNumber fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, DependentPhoneNumber.class); @@ -72,14 +77,17 @@ public static DependentPhoneNumber fromJson(final String json, final ObjectMappe } /** - * Converts a JSON InputStream into a DependentPhoneNumber object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return DependentPhoneNumber object represented by the provided JSON - */ - public static DependentPhoneNumber fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a DependentPhoneNumber object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return DependentPhoneNumber object represented by the provided JSON + */ + public static DependentPhoneNumber fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, DependentPhoneNumber.class); @@ -89,6 +97,7 @@ public static DependentPhoneNumber fromJson(final InputStream json, final Object throw new ApiConnectionException(e.getMessage(), e); } } + public enum AddressRequirement { NONE("none"), ANY("any"), @@ -110,6 +119,7 @@ public static AddressRequirement forValue(final String value) { return Promoter.enumFromString(value, AddressRequirement.values()); } } + public enum EmergencyStatus { ACTIVE("Active"), INACTIVE("Inactive"); @@ -159,83 +169,46 @@ public static EmergencyStatus forValue(final String value) { @JsonCreator private DependentPhoneNumber( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("friendly_name") - final com.twilio.type.PhoneNumber friendlyName, - - @JsonProperty("phone_number") - final com.twilio.type.PhoneNumber phoneNumber, - - @JsonProperty("voice_url") - final URI voiceUrl, - - @JsonProperty("voice_method") - final HttpMethod voiceMethod, - - @JsonProperty("voice_fallback_method") - final HttpMethod voiceFallbackMethod, - - @JsonProperty("voice_fallback_url") - final URI voiceFallbackUrl, - - @JsonProperty("voice_caller_id_lookup") - final Boolean voiceCallerIdLookup, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("sms_fallback_method") - final HttpMethod smsFallbackMethod, - - @JsonProperty("sms_fallback_url") - final URI smsFallbackUrl, - - @JsonProperty("sms_method") - final HttpMethod smsMethod, - - @JsonProperty("sms_url") - final URI smsUrl, - - @JsonProperty("address_requirements") - final DependentPhoneNumber.AddressRequirement addressRequirements, - - @JsonProperty("capabilities") - final Map capabilities, - - @JsonProperty("status_callback") - final URI statusCallback, - - @JsonProperty("status_callback_method") - final HttpMethod statusCallbackMethod, - - @JsonProperty("api_version") - final String apiVersion, - - @JsonProperty("sms_application_sid") - final String smsApplicationSid, - - @JsonProperty("voice_application_sid") - final String voiceApplicationSid, - - @JsonProperty("trunk_sid") - final String trunkSid, - - @JsonProperty("emergency_status") - final DependentPhoneNumber.EmergencyStatus emergencyStatus, - - @JsonProperty("emergency_address_sid") - final String emergencyAddressSid, - - @JsonProperty("uri") - final String uri + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty( + "friendly_name" + ) final com.twilio.type.PhoneNumber friendlyName, + @JsonProperty( + "phone_number" + ) final com.twilio.type.PhoneNumber phoneNumber, + @JsonProperty("voice_url") final URI voiceUrl, + @JsonProperty("voice_method") final HttpMethod voiceMethod, + @JsonProperty( + "voice_fallback_method" + ) final HttpMethod voiceFallbackMethod, + @JsonProperty("voice_fallback_url") final URI voiceFallbackUrl, + @JsonProperty( + "voice_caller_id_lookup" + ) final Boolean voiceCallerIdLookup, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("sms_fallback_method") final HttpMethod smsFallbackMethod, + @JsonProperty("sms_fallback_url") final URI smsFallbackUrl, + @JsonProperty("sms_method") final HttpMethod smsMethod, + @JsonProperty("sms_url") final URI smsUrl, + @JsonProperty( + "address_requirements" + ) final DependentPhoneNumber.AddressRequirement addressRequirements, + @JsonProperty("capabilities") final Map capabilities, + @JsonProperty("status_callback") final URI statusCallback, + @JsonProperty( + "status_callback_method" + ) final HttpMethod statusCallbackMethod, + @JsonProperty("api_version") final String apiVersion, + @JsonProperty("sms_application_sid") final String smsApplicationSid, + @JsonProperty("voice_application_sid") final String voiceApplicationSid, + @JsonProperty("trunk_sid") final String trunkSid, + @JsonProperty( + "emergency_status" + ) final DependentPhoneNumber.EmergencyStatus emergencyStatus, + @JsonProperty("emergency_address_sid") final String emergencyAddressSid, + @JsonProperty("uri") final String uri ) { this.sid = sid; this.accountSid = accountSid; @@ -265,88 +238,113 @@ private DependentPhoneNumber( this.uri = uri; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final com.twilio.type.PhoneNumber getFriendlyName() { - return this.friendlyName; - } - public final com.twilio.type.PhoneNumber getPhoneNumber() { - return this.phoneNumber; - } - public final URI getVoiceUrl() { - return this.voiceUrl; - } - public final HttpMethod getVoiceMethod() { - return this.voiceMethod; - } - public final HttpMethod getVoiceFallbackMethod() { - return this.voiceFallbackMethod; - } - public final URI getVoiceFallbackUrl() { - return this.voiceFallbackUrl; - } - public final Boolean getVoiceCallerIdLookup() { - return this.voiceCallerIdLookup; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final HttpMethod getSmsFallbackMethod() { - return this.smsFallbackMethod; - } - public final URI getSmsFallbackUrl() { - return this.smsFallbackUrl; - } - public final HttpMethod getSmsMethod() { - return this.smsMethod; - } - public final URI getSmsUrl() { - return this.smsUrl; - } - public final DependentPhoneNumber.AddressRequirement getAddressRequirements() { - return this.addressRequirements; - } - public final Map getCapabilities() { - return this.capabilities; - } - public final URI getStatusCallback() { - return this.statusCallback; - } - public final HttpMethod getStatusCallbackMethod() { - return this.statusCallbackMethod; - } - public final String getApiVersion() { - return this.apiVersion; - } - public final String getSmsApplicationSid() { - return this.smsApplicationSid; - } - public final String getVoiceApplicationSid() { - return this.voiceApplicationSid; - } - public final String getTrunkSid() { - return this.trunkSid; - } - public final DependentPhoneNumber.EmergencyStatus getEmergencyStatus() { - return this.emergencyStatus; - } - public final String getEmergencyAddressSid() { - return this.emergencyAddressSid; - } - public final String getUri() { - return this.uri; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final com.twilio.type.PhoneNumber getFriendlyName() { + return this.friendlyName; + } + + public final com.twilio.type.PhoneNumber getPhoneNumber() { + return this.phoneNumber; + } + + public final URI getVoiceUrl() { + return this.voiceUrl; + } + + public final HttpMethod getVoiceMethod() { + return this.voiceMethod; + } + + public final HttpMethod getVoiceFallbackMethod() { + return this.voiceFallbackMethod; + } + + public final URI getVoiceFallbackUrl() { + return this.voiceFallbackUrl; + } + + public final Boolean getVoiceCallerIdLookup() { + return this.voiceCallerIdLookup; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final HttpMethod getSmsFallbackMethod() { + return this.smsFallbackMethod; + } + + public final URI getSmsFallbackUrl() { + return this.smsFallbackUrl; + } + + public final HttpMethod getSmsMethod() { + return this.smsMethod; + } + + public final URI getSmsUrl() { + return this.smsUrl; + } + + public final DependentPhoneNumber.AddressRequirement getAddressRequirements() { + return this.addressRequirements; + } + + public final Map getCapabilities() { + return this.capabilities; + } + + public final URI getStatusCallback() { + return this.statusCallback; + } + + public final HttpMethod getStatusCallbackMethod() { + return this.statusCallbackMethod; + } + + public final String getApiVersion() { + return this.apiVersion; + } + + public final String getSmsApplicationSid() { + return this.smsApplicationSid; + } + + public final String getVoiceApplicationSid() { + return this.voiceApplicationSid; + } + + public final String getTrunkSid() { + return this.trunkSid; + } + + public final DependentPhoneNumber.EmergencyStatus getEmergencyStatus() { + return this.emergencyStatus; + } + + public final String getEmergencyAddressSid() { + return this.emergencyAddressSid; + } + + public final String getUri() { + return this.uri; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -356,13 +354,65 @@ public boolean equals(final Object o) { DependentPhoneNumber other = (DependentPhoneNumber) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(phoneNumber, other.phoneNumber) && Objects.equals(voiceUrl, other.voiceUrl) && Objects.equals(voiceMethod, other.voiceMethod) && Objects.equals(voiceFallbackMethod, other.voiceFallbackMethod) && Objects.equals(voiceFallbackUrl, other.voiceFallbackUrl) && Objects.equals(voiceCallerIdLookup, other.voiceCallerIdLookup) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(smsFallbackMethod, other.smsFallbackMethod) && Objects.equals(smsFallbackUrl, other.smsFallbackUrl) && Objects.equals(smsMethod, other.smsMethod) && Objects.equals(smsUrl, other.smsUrl) && Objects.equals(addressRequirements, other.addressRequirements) && Objects.equals(capabilities, other.capabilities) && Objects.equals(statusCallback, other.statusCallback) && Objects.equals(statusCallbackMethod, other.statusCallbackMethod) && Objects.equals(apiVersion, other.apiVersion) && Objects.equals(smsApplicationSid, other.smsApplicationSid) && Objects.equals(voiceApplicationSid, other.voiceApplicationSid) && Objects.equals(trunkSid, other.trunkSid) && Objects.equals(emergencyStatus, other.emergencyStatus) && Objects.equals(emergencyAddressSid, other.emergencyAddressSid) && Objects.equals(uri, other.uri) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(phoneNumber, other.phoneNumber) && + Objects.equals(voiceUrl, other.voiceUrl) && + Objects.equals(voiceMethod, other.voiceMethod) && + Objects.equals(voiceFallbackMethod, other.voiceFallbackMethod) && + Objects.equals(voiceFallbackUrl, other.voiceFallbackUrl) && + Objects.equals(voiceCallerIdLookup, other.voiceCallerIdLookup) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(smsFallbackMethod, other.smsFallbackMethod) && + Objects.equals(smsFallbackUrl, other.smsFallbackUrl) && + Objects.equals(smsMethod, other.smsMethod) && + Objects.equals(smsUrl, other.smsUrl) && + Objects.equals(addressRequirements, other.addressRequirements) && + Objects.equals(capabilities, other.capabilities) && + Objects.equals(statusCallback, other.statusCallback) && + Objects.equals(statusCallbackMethod, other.statusCallbackMethod) && + Objects.equals(apiVersion, other.apiVersion) && + Objects.equals(smsApplicationSid, other.smsApplicationSid) && + Objects.equals(voiceApplicationSid, other.voiceApplicationSid) && + Objects.equals(trunkSid, other.trunkSid) && + Objects.equals(emergencyStatus, other.emergencyStatus) && + Objects.equals(emergencyAddressSid, other.emergencyAddressSid) && + Objects.equals(uri, other.uri) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, friendlyName, phoneNumber, voiceUrl, voiceMethod, voiceFallbackMethod, voiceFallbackUrl, voiceCallerIdLookup, dateCreated, dateUpdated, smsFallbackMethod, smsFallbackUrl, smsMethod, smsUrl, addressRequirements, capabilities, statusCallback, statusCallbackMethod, apiVersion, smsApplicationSid, voiceApplicationSid, trunkSid, emergencyStatus, emergencyAddressSid, uri); + return Objects.hash( + sid, + accountSid, + friendlyName, + phoneNumber, + voiceUrl, + voiceMethod, + voiceFallbackMethod, + voiceFallbackUrl, + voiceCallerIdLookup, + dateCreated, + dateUpdated, + smsFallbackMethod, + smsFallbackUrl, + smsMethod, + smsUrl, + addressRequirements, + capabilities, + statusCallback, + statusCallbackMethod, + apiVersion, + smsApplicationSid, + voiceApplicationSid, + trunkSid, + emergencyStatus, + emergencyAddressSid, + uri + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/address/DependentPhoneNumberReader.java b/src/main/java/com/twilio/rest/api/v2010/account/address/DependentPhoneNumberReader.java index 264c69d74c..6c14b5e1ab 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/address/DependentPhoneNumberReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/address/DependentPhoneNumberReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.api.v2010.account.address; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,38 +25,54 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class DependentPhoneNumberReader extends Reader { + private String pathAddressSid; private String pathAccountSid; private Integer pageSize; - public DependentPhoneNumberReader(final String pathAddressSid){ + public DependentPhoneNumberReader(final String pathAddressSid) { this.pathAddressSid = pathAddressSid; } - public DependentPhoneNumberReader(final String pathAccountSid, final String pathAddressSid){ + + public DependentPhoneNumberReader( + final String pathAccountSid, + final String pathAddressSid + ) { this.pathAccountSid = pathAccountSid; this.pathAddressSid = pathAddressSid; } - public DependentPhoneNumberReader setPageSize(final Integer pageSize){ + public DependentPhoneNumberReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @Override - public ResourceSet read(final TwilioRestClient client) { + public ResourceSet read( + final TwilioRestClient client + ) { return new ResourceSet<>(this, client, firstPage(client)); } public Page firstPage(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/Addresses/{AddressSid}/DependentPhoneNumbers.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"AddressSid"+"}", this.pathAddressSid.toString()); + String path = + "/2010-04-01/Accounts/{AccountSid}/Addresses/{AddressSid}/DependentPhoneNumbers.json"; + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "AddressSid" + "}", + this.pathAddressSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -67,13 +84,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("DependentPhoneNumber read failed: Unable to connect to server"); + throw new ApiConnectionException( + "DependentPhoneNumber read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -89,7 +114,10 @@ private Page pageForRequest(final TwilioRestClient client, } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.API.toString()) @@ -97,9 +125,11 @@ public Page previousPage(final Page return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.API.toString()) @@ -108,21 +138,21 @@ public Page nextPage(final Page page } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/Local.java b/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/Local.java index 175c568012..d9eb281278 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/Local.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/Local.java @@ -22,40 +22,43 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - +import com.twilio.type.PhoneNumberCapabilities; import java.io.IOException; import java.io.InputStream; - -import java.util.Objects; - - import java.math.BigDecimal; -import com.twilio.type.PhoneNumberCapabilities; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Local extends Resource { + private static final long serialVersionUID = 211749226408502L; - public static LocalReader reader(final String pathCountryCode){ + public static LocalReader reader(final String pathCountryCode) { return new LocalReader(pathCountryCode); } - public static LocalReader reader(final String pathAccountSid, final String pathCountryCode){ + + public static LocalReader reader( + final String pathAccountSid, + final String pathCountryCode + ) { return new LocalReader(pathAccountSid, pathCountryCode); } /** - * Converts a JSON String into a Local object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Local object represented by the provided JSON - */ - public static Local fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Local object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Local object represented by the provided JSON + */ + public static Local fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Local.class); @@ -67,14 +70,17 @@ public static Local fromJson(final String json, final ObjectMapper objectMapper) } /** - * Converts a JSON InputStream into a Local object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Local object represented by the provided JSON - */ - public static Local fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Local object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Local object represented by the provided JSON + */ + public static Local fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Local.class); @@ -101,44 +107,23 @@ public static Local fromJson(final InputStream json, final ObjectMapper objectMa @JsonCreator private Local( - @JsonProperty("friendly_name") - final com.twilio.type.PhoneNumber friendlyName, - - @JsonProperty("phone_number") - final com.twilio.type.PhoneNumber phoneNumber, - - @JsonProperty("lata") - final String lata, - - @JsonProperty("locality") - final String locality, - - @JsonProperty("rate_center") - final String rateCenter, - - @JsonProperty("latitude") - final BigDecimal latitude, - - @JsonProperty("longitude") - final BigDecimal longitude, - - @JsonProperty("region") - final String region, - - @JsonProperty("postal_code") - final String postalCode, - - @JsonProperty("iso_country") - final String isoCountry, - - @JsonProperty("address_requirements") - final String addressRequirements, - - @JsonProperty("beta") - final Boolean beta, - - @JsonProperty("capabilities") - final PhoneNumberCapabilities capabilities + @JsonProperty( + "friendly_name" + ) final com.twilio.type.PhoneNumber friendlyName, + @JsonProperty( + "phone_number" + ) final com.twilio.type.PhoneNumber phoneNumber, + @JsonProperty("lata") final String lata, + @JsonProperty("locality") final String locality, + @JsonProperty("rate_center") final String rateCenter, + @JsonProperty("latitude") final BigDecimal latitude, + @JsonProperty("longitude") final BigDecimal longitude, + @JsonProperty("region") final String region, + @JsonProperty("postal_code") final String postalCode, + @JsonProperty("iso_country") final String isoCountry, + @JsonProperty("address_requirements") final String addressRequirements, + @JsonProperty("beta") final Boolean beta, + @JsonProperty("capabilities") final PhoneNumberCapabilities capabilities ) { this.friendlyName = friendlyName; this.phoneNumber = phoneNumber; @@ -155,49 +140,61 @@ private Local( this.capabilities = capabilities; } - public final com.twilio.type.PhoneNumber getFriendlyName() { - return this.friendlyName; - } - public final com.twilio.type.PhoneNumber getPhoneNumber() { - return this.phoneNumber; - } - public final String getLata() { - return this.lata; - } - public final String getLocality() { - return this.locality; - } - public final String getRateCenter() { - return this.rateCenter; - } - public final BigDecimal getLatitude() { - return this.latitude; - } - public final BigDecimal getLongitude() { - return this.longitude; - } - public final String getRegion() { - return this.region; - } - public final String getPostalCode() { - return this.postalCode; - } - public final String getIsoCountry() { - return this.isoCountry; - } - public final String getAddressRequirements() { - return this.addressRequirements; - } - public final Boolean getBeta() { - return this.beta; - } - public final PhoneNumberCapabilities getCapabilities() { - return this.capabilities; - } + public final com.twilio.type.PhoneNumber getFriendlyName() { + return this.friendlyName; + } + + public final com.twilio.type.PhoneNumber getPhoneNumber() { + return this.phoneNumber; + } + + public final String getLata() { + return this.lata; + } + + public final String getLocality() { + return this.locality; + } + + public final String getRateCenter() { + return this.rateCenter; + } + + public final BigDecimal getLatitude() { + return this.latitude; + } + + public final BigDecimal getLongitude() { + return this.longitude; + } + + public final String getRegion() { + return this.region; + } + + public final String getPostalCode() { + return this.postalCode; + } + + public final String getIsoCountry() { + return this.isoCountry; + } + + public final String getAddressRequirements() { + return this.addressRequirements; + } + + public final Boolean getBeta() { + return this.beta; + } + + public final PhoneNumberCapabilities getCapabilities() { + return this.capabilities; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -207,13 +204,39 @@ public boolean equals(final Object o) { Local other = (Local) o; - return Objects.equals(friendlyName, other.friendlyName) && Objects.equals(phoneNumber, other.phoneNumber) && Objects.equals(lata, other.lata) && Objects.equals(locality, other.locality) && Objects.equals(rateCenter, other.rateCenter) && Objects.equals(latitude, other.latitude) && Objects.equals(longitude, other.longitude) && Objects.equals(region, other.region) && Objects.equals(postalCode, other.postalCode) && Objects.equals(isoCountry, other.isoCountry) && Objects.equals(addressRequirements, other.addressRequirements) && Objects.equals(beta, other.beta) && Objects.equals(capabilities, other.capabilities) ; + return ( + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(phoneNumber, other.phoneNumber) && + Objects.equals(lata, other.lata) && + Objects.equals(locality, other.locality) && + Objects.equals(rateCenter, other.rateCenter) && + Objects.equals(latitude, other.latitude) && + Objects.equals(longitude, other.longitude) && + Objects.equals(region, other.region) && + Objects.equals(postalCode, other.postalCode) && + Objects.equals(isoCountry, other.isoCountry) && + Objects.equals(addressRequirements, other.addressRequirements) && + Objects.equals(beta, other.beta) && + Objects.equals(capabilities, other.capabilities) + ); } @Override public int hashCode() { - return Objects.hash(friendlyName, phoneNumber, lata, locality, rateCenter, latitude, longitude, region, postalCode, isoCountry, addressRequirements, beta, capabilities); + return Objects.hash( + friendlyName, + phoneNumber, + lata, + locality, + rateCenter, + latitude, + longitude, + region, + postalCode, + isoCountry, + addressRequirements, + beta, + capabilities + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/LocalReader.java b/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/LocalReader.java index ae4937c0fa..9669f544cc 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/LocalReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/LocalReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.api.v2010.account.availablephonenumbercountry; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.converter.Promoter; @@ -25,11 +26,9 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class LocalReader extends Reader { + private String pathCountryCode; private String pathAccountSid; private Integer areaCode; @@ -52,91 +51,121 @@ public class LocalReader extends Reader { private Boolean faxEnabled; private Integer pageSize; - public LocalReader(final String pathCountryCode){ + public LocalReader(final String pathCountryCode) { this.pathCountryCode = pathCountryCode; } - public LocalReader(final String pathAccountSid, final String pathCountryCode){ + + public LocalReader( + final String pathAccountSid, + final String pathCountryCode + ) { this.pathAccountSid = pathAccountSid; this.pathCountryCode = pathCountryCode; } - public LocalReader setAreaCode(final Integer areaCode){ + public LocalReader setAreaCode(final Integer areaCode) { this.areaCode = areaCode; return this; } - public LocalReader setContains(final String contains){ + + public LocalReader setContains(final String contains) { this.contains = contains; return this; } - public LocalReader setSmsEnabled(final Boolean smsEnabled){ + + public LocalReader setSmsEnabled(final Boolean smsEnabled) { this.smsEnabled = smsEnabled; return this; } - public LocalReader setMmsEnabled(final Boolean mmsEnabled){ + + public LocalReader setMmsEnabled(final Boolean mmsEnabled) { this.mmsEnabled = mmsEnabled; return this; } - public LocalReader setVoiceEnabled(final Boolean voiceEnabled){ + + public LocalReader setVoiceEnabled(final Boolean voiceEnabled) { this.voiceEnabled = voiceEnabled; return this; } - public LocalReader setExcludeAllAddressRequired(final Boolean excludeAllAddressRequired){ + + public LocalReader setExcludeAllAddressRequired( + final Boolean excludeAllAddressRequired + ) { this.excludeAllAddressRequired = excludeAllAddressRequired; return this; } - public LocalReader setExcludeLocalAddressRequired(final Boolean excludeLocalAddressRequired){ + + public LocalReader setExcludeLocalAddressRequired( + final Boolean excludeLocalAddressRequired + ) { this.excludeLocalAddressRequired = excludeLocalAddressRequired; return this; } - public LocalReader setExcludeForeignAddressRequired(final Boolean excludeForeignAddressRequired){ + + public LocalReader setExcludeForeignAddressRequired( + final Boolean excludeForeignAddressRequired + ) { this.excludeForeignAddressRequired = excludeForeignAddressRequired; return this; } - public LocalReader setBeta(final Boolean beta){ + + public LocalReader setBeta(final Boolean beta) { this.beta = beta; return this; } - public LocalReader setNearNumber(final com.twilio.type.PhoneNumber nearNumber){ + + public LocalReader setNearNumber( + final com.twilio.type.PhoneNumber nearNumber + ) { this.nearNumber = nearNumber; return this; } - public LocalReader setNearNumber(final String nearNumber){ + public LocalReader setNearNumber(final String nearNumber) { return setNearNumber(Promoter.phoneNumberFromString(nearNumber)); } - public LocalReader setNearLatLong(final String nearLatLong){ + + public LocalReader setNearLatLong(final String nearLatLong) { this.nearLatLong = nearLatLong; return this; } - public LocalReader setDistance(final Integer distance){ + + public LocalReader setDistance(final Integer distance) { this.distance = distance; return this; } - public LocalReader setInPostalCode(final String inPostalCode){ + + public LocalReader setInPostalCode(final String inPostalCode) { this.inPostalCode = inPostalCode; return this; } - public LocalReader setInRegion(final String inRegion){ + + public LocalReader setInRegion(final String inRegion) { this.inRegion = inRegion; return this; } - public LocalReader setInRateCenter(final String inRateCenter){ + + public LocalReader setInRateCenter(final String inRateCenter) { this.inRateCenter = inRateCenter; return this; } - public LocalReader setInLata(final String inLata){ + + public LocalReader setInLata(final String inLata) { this.inLata = inLata; return this; } - public LocalReader setInLocality(final String inLocality){ + + public LocalReader setInLocality(final String inLocality) { this.inLocality = inLocality; return this; } - public LocalReader setFaxEnabled(final Boolean faxEnabled){ + + public LocalReader setFaxEnabled(final Boolean faxEnabled) { this.faxEnabled = faxEnabled; return this; } - public LocalReader setPageSize(final Integer pageSize){ + + public LocalReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -147,10 +176,22 @@ public ResourceSet read(final TwilioRestClient client) { } public Page firstPage(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/AvailablePhoneNumbers/{CountryCode}/Local.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"CountryCode"+"}", this.pathCountryCode.toString()); + String path = + "/2010-04-01/Accounts/{AccountSid}/AvailablePhoneNumbers/{CountryCode}/Local.json"; + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "CountryCode" + "}", + this.pathCountryCode.toString() + ); Request request = new Request( HttpMethod.GET, @@ -162,13 +203,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Local read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Local read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -184,7 +233,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.API.toString()) @@ -192,9 +244,11 @@ public Page previousPage(final Page page, final TwilioRestClient c return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.API.toString()) @@ -203,93 +257,84 @@ public Page nextPage(final Page page, final TwilioRestClient clien } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (areaCode != null) { - request.addQueryParam("AreaCode", areaCode.toString()); } if (contains != null) { - request.addQueryParam("Contains", contains); } if (smsEnabled != null) { - request.addQueryParam("SmsEnabled", smsEnabled.toString()); } if (mmsEnabled != null) { - request.addQueryParam("MmsEnabled", mmsEnabled.toString()); } if (voiceEnabled != null) { - request.addQueryParam("VoiceEnabled", voiceEnabled.toString()); } if (excludeAllAddressRequired != null) { - - request.addQueryParam("ExcludeAllAddressRequired", excludeAllAddressRequired.toString()); + request.addQueryParam( + "ExcludeAllAddressRequired", + excludeAllAddressRequired.toString() + ); } if (excludeLocalAddressRequired != null) { - - request.addQueryParam("ExcludeLocalAddressRequired", excludeLocalAddressRequired.toString()); + request.addQueryParam( + "ExcludeLocalAddressRequired", + excludeLocalAddressRequired.toString() + ); } if (excludeForeignAddressRequired != null) { - - request.addQueryParam("ExcludeForeignAddressRequired", excludeForeignAddressRequired.toString()); + request.addQueryParam( + "ExcludeForeignAddressRequired", + excludeForeignAddressRequired.toString() + ); } if (beta != null) { - request.addQueryParam("Beta", beta.toString()); } if (nearNumber != null) { - request.addQueryParam("NearNumber", nearNumber.toString()); } if (nearLatLong != null) { - request.addQueryParam("NearLatLong", nearLatLong); } if (distance != null) { - request.addQueryParam("Distance", distance.toString()); } if (inPostalCode != null) { - request.addQueryParam("InPostalCode", inPostalCode); } if (inRegion != null) { - request.addQueryParam("InRegion", inRegion); } if (inRateCenter != null) { - request.addQueryParam("InRateCenter", inRateCenter); } if (inLata != null) { - request.addQueryParam("InLata", inLata); } if (inLocality != null) { - request.addQueryParam("InLocality", inLocality); } if (faxEnabled != null) { - request.addQueryParam("FaxEnabled", faxEnabled.toString()); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/MachineToMachine.java b/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/MachineToMachine.java index 333a9355bb..013df4f252 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/MachineToMachine.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/MachineToMachine.java @@ -22,40 +22,43 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - +import com.twilio.type.PhoneNumberCapabilities; import java.io.IOException; import java.io.InputStream; - -import java.util.Objects; - - import java.math.BigDecimal; -import com.twilio.type.PhoneNumberCapabilities; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class MachineToMachine extends Resource { + private static final long serialVersionUID = 211749226408502L; - public static MachineToMachineReader reader(final String pathCountryCode){ + public static MachineToMachineReader reader(final String pathCountryCode) { return new MachineToMachineReader(pathCountryCode); } - public static MachineToMachineReader reader(final String pathAccountSid, final String pathCountryCode){ + + public static MachineToMachineReader reader( + final String pathAccountSid, + final String pathCountryCode + ) { return new MachineToMachineReader(pathAccountSid, pathCountryCode); } /** - * Converts a JSON String into a MachineToMachine object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return MachineToMachine object represented by the provided JSON - */ - public static MachineToMachine fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a MachineToMachine object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return MachineToMachine object represented by the provided JSON + */ + public static MachineToMachine fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, MachineToMachine.class); @@ -67,14 +70,17 @@ public static MachineToMachine fromJson(final String json, final ObjectMapper ob } /** - * Converts a JSON InputStream into a MachineToMachine object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return MachineToMachine object represented by the provided JSON - */ - public static MachineToMachine fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a MachineToMachine object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return MachineToMachine object represented by the provided JSON + */ + public static MachineToMachine fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, MachineToMachine.class); @@ -101,44 +107,23 @@ public static MachineToMachine fromJson(final InputStream json, final ObjectMapp @JsonCreator private MachineToMachine( - @JsonProperty("friendly_name") - final com.twilio.type.PhoneNumber friendlyName, - - @JsonProperty("phone_number") - final com.twilio.type.PhoneNumber phoneNumber, - - @JsonProperty("lata") - final String lata, - - @JsonProperty("locality") - final String locality, - - @JsonProperty("rate_center") - final String rateCenter, - - @JsonProperty("latitude") - final BigDecimal latitude, - - @JsonProperty("longitude") - final BigDecimal longitude, - - @JsonProperty("region") - final String region, - - @JsonProperty("postal_code") - final String postalCode, - - @JsonProperty("iso_country") - final String isoCountry, - - @JsonProperty("address_requirements") - final String addressRequirements, - - @JsonProperty("beta") - final Boolean beta, - - @JsonProperty("capabilities") - final PhoneNumberCapabilities capabilities + @JsonProperty( + "friendly_name" + ) final com.twilio.type.PhoneNumber friendlyName, + @JsonProperty( + "phone_number" + ) final com.twilio.type.PhoneNumber phoneNumber, + @JsonProperty("lata") final String lata, + @JsonProperty("locality") final String locality, + @JsonProperty("rate_center") final String rateCenter, + @JsonProperty("latitude") final BigDecimal latitude, + @JsonProperty("longitude") final BigDecimal longitude, + @JsonProperty("region") final String region, + @JsonProperty("postal_code") final String postalCode, + @JsonProperty("iso_country") final String isoCountry, + @JsonProperty("address_requirements") final String addressRequirements, + @JsonProperty("beta") final Boolean beta, + @JsonProperty("capabilities") final PhoneNumberCapabilities capabilities ) { this.friendlyName = friendlyName; this.phoneNumber = phoneNumber; @@ -155,49 +140,61 @@ private MachineToMachine( this.capabilities = capabilities; } - public final com.twilio.type.PhoneNumber getFriendlyName() { - return this.friendlyName; - } - public final com.twilio.type.PhoneNumber getPhoneNumber() { - return this.phoneNumber; - } - public final String getLata() { - return this.lata; - } - public final String getLocality() { - return this.locality; - } - public final String getRateCenter() { - return this.rateCenter; - } - public final BigDecimal getLatitude() { - return this.latitude; - } - public final BigDecimal getLongitude() { - return this.longitude; - } - public final String getRegion() { - return this.region; - } - public final String getPostalCode() { - return this.postalCode; - } - public final String getIsoCountry() { - return this.isoCountry; - } - public final String getAddressRequirements() { - return this.addressRequirements; - } - public final Boolean getBeta() { - return this.beta; - } - public final PhoneNumberCapabilities getCapabilities() { - return this.capabilities; - } + public final com.twilio.type.PhoneNumber getFriendlyName() { + return this.friendlyName; + } + + public final com.twilio.type.PhoneNumber getPhoneNumber() { + return this.phoneNumber; + } + + public final String getLata() { + return this.lata; + } + + public final String getLocality() { + return this.locality; + } + + public final String getRateCenter() { + return this.rateCenter; + } + + public final BigDecimal getLatitude() { + return this.latitude; + } + + public final BigDecimal getLongitude() { + return this.longitude; + } + + public final String getRegion() { + return this.region; + } + + public final String getPostalCode() { + return this.postalCode; + } + + public final String getIsoCountry() { + return this.isoCountry; + } + + public final String getAddressRequirements() { + return this.addressRequirements; + } + + public final Boolean getBeta() { + return this.beta; + } + + public final PhoneNumberCapabilities getCapabilities() { + return this.capabilities; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -207,13 +204,39 @@ public boolean equals(final Object o) { MachineToMachine other = (MachineToMachine) o; - return Objects.equals(friendlyName, other.friendlyName) && Objects.equals(phoneNumber, other.phoneNumber) && Objects.equals(lata, other.lata) && Objects.equals(locality, other.locality) && Objects.equals(rateCenter, other.rateCenter) && Objects.equals(latitude, other.latitude) && Objects.equals(longitude, other.longitude) && Objects.equals(region, other.region) && Objects.equals(postalCode, other.postalCode) && Objects.equals(isoCountry, other.isoCountry) && Objects.equals(addressRequirements, other.addressRequirements) && Objects.equals(beta, other.beta) && Objects.equals(capabilities, other.capabilities) ; + return ( + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(phoneNumber, other.phoneNumber) && + Objects.equals(lata, other.lata) && + Objects.equals(locality, other.locality) && + Objects.equals(rateCenter, other.rateCenter) && + Objects.equals(latitude, other.latitude) && + Objects.equals(longitude, other.longitude) && + Objects.equals(region, other.region) && + Objects.equals(postalCode, other.postalCode) && + Objects.equals(isoCountry, other.isoCountry) && + Objects.equals(addressRequirements, other.addressRequirements) && + Objects.equals(beta, other.beta) && + Objects.equals(capabilities, other.capabilities) + ); } @Override public int hashCode() { - return Objects.hash(friendlyName, phoneNumber, lata, locality, rateCenter, latitude, longitude, region, postalCode, isoCountry, addressRequirements, beta, capabilities); + return Objects.hash( + friendlyName, + phoneNumber, + lata, + locality, + rateCenter, + latitude, + longitude, + region, + postalCode, + isoCountry, + addressRequirements, + beta, + capabilities + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/MachineToMachineReader.java b/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/MachineToMachineReader.java index ea7fe5e9ef..bf3ddc44ce 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/MachineToMachineReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/MachineToMachineReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.api.v2010.account.availablephonenumbercountry; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.converter.Promoter; @@ -25,11 +26,9 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class MachineToMachineReader extends Reader { + private String pathCountryCode; private String pathAccountSid; private Integer areaCode; @@ -52,91 +51,121 @@ public class MachineToMachineReader extends Reader { private Boolean faxEnabled; private Integer pageSize; - public MachineToMachineReader(final String pathCountryCode){ + public MachineToMachineReader(final String pathCountryCode) { this.pathCountryCode = pathCountryCode; } - public MachineToMachineReader(final String pathAccountSid, final String pathCountryCode){ + + public MachineToMachineReader( + final String pathAccountSid, + final String pathCountryCode + ) { this.pathAccountSid = pathAccountSid; this.pathCountryCode = pathCountryCode; } - public MachineToMachineReader setAreaCode(final Integer areaCode){ + public MachineToMachineReader setAreaCode(final Integer areaCode) { this.areaCode = areaCode; return this; } - public MachineToMachineReader setContains(final String contains){ + + public MachineToMachineReader setContains(final String contains) { this.contains = contains; return this; } - public MachineToMachineReader setSmsEnabled(final Boolean smsEnabled){ + + public MachineToMachineReader setSmsEnabled(final Boolean smsEnabled) { this.smsEnabled = smsEnabled; return this; } - public MachineToMachineReader setMmsEnabled(final Boolean mmsEnabled){ + + public MachineToMachineReader setMmsEnabled(final Boolean mmsEnabled) { this.mmsEnabled = mmsEnabled; return this; } - public MachineToMachineReader setVoiceEnabled(final Boolean voiceEnabled){ + + public MachineToMachineReader setVoiceEnabled(final Boolean voiceEnabled) { this.voiceEnabled = voiceEnabled; return this; } - public MachineToMachineReader setExcludeAllAddressRequired(final Boolean excludeAllAddressRequired){ + + public MachineToMachineReader setExcludeAllAddressRequired( + final Boolean excludeAllAddressRequired + ) { this.excludeAllAddressRequired = excludeAllAddressRequired; return this; } - public MachineToMachineReader setExcludeLocalAddressRequired(final Boolean excludeLocalAddressRequired){ + + public MachineToMachineReader setExcludeLocalAddressRequired( + final Boolean excludeLocalAddressRequired + ) { this.excludeLocalAddressRequired = excludeLocalAddressRequired; return this; } - public MachineToMachineReader setExcludeForeignAddressRequired(final Boolean excludeForeignAddressRequired){ + + public MachineToMachineReader setExcludeForeignAddressRequired( + final Boolean excludeForeignAddressRequired + ) { this.excludeForeignAddressRequired = excludeForeignAddressRequired; return this; } - public MachineToMachineReader setBeta(final Boolean beta){ + + public MachineToMachineReader setBeta(final Boolean beta) { this.beta = beta; return this; } - public MachineToMachineReader setNearNumber(final com.twilio.type.PhoneNumber nearNumber){ + + public MachineToMachineReader setNearNumber( + final com.twilio.type.PhoneNumber nearNumber + ) { this.nearNumber = nearNumber; return this; } - public MachineToMachineReader setNearNumber(final String nearNumber){ + public MachineToMachineReader setNearNumber(final String nearNumber) { return setNearNumber(Promoter.phoneNumberFromString(nearNumber)); } - public MachineToMachineReader setNearLatLong(final String nearLatLong){ + + public MachineToMachineReader setNearLatLong(final String nearLatLong) { this.nearLatLong = nearLatLong; return this; } - public MachineToMachineReader setDistance(final Integer distance){ + + public MachineToMachineReader setDistance(final Integer distance) { this.distance = distance; return this; } - public MachineToMachineReader setInPostalCode(final String inPostalCode){ + + public MachineToMachineReader setInPostalCode(final String inPostalCode) { this.inPostalCode = inPostalCode; return this; } - public MachineToMachineReader setInRegion(final String inRegion){ + + public MachineToMachineReader setInRegion(final String inRegion) { this.inRegion = inRegion; return this; } - public MachineToMachineReader setInRateCenter(final String inRateCenter){ + + public MachineToMachineReader setInRateCenter(final String inRateCenter) { this.inRateCenter = inRateCenter; return this; } - public MachineToMachineReader setInLata(final String inLata){ + + public MachineToMachineReader setInLata(final String inLata) { this.inLata = inLata; return this; } - public MachineToMachineReader setInLocality(final String inLocality){ + + public MachineToMachineReader setInLocality(final String inLocality) { this.inLocality = inLocality; return this; } - public MachineToMachineReader setFaxEnabled(final Boolean faxEnabled){ + + public MachineToMachineReader setFaxEnabled(final Boolean faxEnabled) { this.faxEnabled = faxEnabled; return this; } - public MachineToMachineReader setPageSize(final Integer pageSize){ + + public MachineToMachineReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -147,10 +176,22 @@ public ResourceSet read(final TwilioRestClient client) { } public Page firstPage(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/AvailablePhoneNumbers/{CountryCode}/MachineToMachine.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"CountryCode"+"}", this.pathCountryCode.toString()); + String path = + "/2010-04-01/Accounts/{AccountSid}/AvailablePhoneNumbers/{CountryCode}/MachineToMachine.json"; + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "CountryCode" + "}", + this.pathCountryCode.toString() + ); Request request = new Request( HttpMethod.GET, @@ -162,13 +203,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("MachineToMachine read failed: Unable to connect to server"); + throw new ApiConnectionException( + "MachineToMachine read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -184,7 +233,10 @@ private Page pageForRequest(final TwilioRestClient client, fin } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.API.toString()) @@ -192,9 +244,11 @@ public Page previousPage(final Page page, fi return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.API.toString()) @@ -203,93 +257,84 @@ public Page nextPage(final Page page, final } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (areaCode != null) { - request.addQueryParam("AreaCode", areaCode.toString()); } if (contains != null) { - request.addQueryParam("Contains", contains); } if (smsEnabled != null) { - request.addQueryParam("SmsEnabled", smsEnabled.toString()); } if (mmsEnabled != null) { - request.addQueryParam("MmsEnabled", mmsEnabled.toString()); } if (voiceEnabled != null) { - request.addQueryParam("VoiceEnabled", voiceEnabled.toString()); } if (excludeAllAddressRequired != null) { - - request.addQueryParam("ExcludeAllAddressRequired", excludeAllAddressRequired.toString()); + request.addQueryParam( + "ExcludeAllAddressRequired", + excludeAllAddressRequired.toString() + ); } if (excludeLocalAddressRequired != null) { - - request.addQueryParam("ExcludeLocalAddressRequired", excludeLocalAddressRequired.toString()); + request.addQueryParam( + "ExcludeLocalAddressRequired", + excludeLocalAddressRequired.toString() + ); } if (excludeForeignAddressRequired != null) { - - request.addQueryParam("ExcludeForeignAddressRequired", excludeForeignAddressRequired.toString()); + request.addQueryParam( + "ExcludeForeignAddressRequired", + excludeForeignAddressRequired.toString() + ); } if (beta != null) { - request.addQueryParam("Beta", beta.toString()); } if (nearNumber != null) { - request.addQueryParam("NearNumber", nearNumber.toString()); } if (nearLatLong != null) { - request.addQueryParam("NearLatLong", nearLatLong); } if (distance != null) { - request.addQueryParam("Distance", distance.toString()); } if (inPostalCode != null) { - request.addQueryParam("InPostalCode", inPostalCode); } if (inRegion != null) { - request.addQueryParam("InRegion", inRegion); } if (inRateCenter != null) { - request.addQueryParam("InRateCenter", inRateCenter); } if (inLata != null) { - request.addQueryParam("InLata", inLata); } if (inLocality != null) { - request.addQueryParam("InLocality", inLocality); } if (faxEnabled != null) { - request.addQueryParam("FaxEnabled", faxEnabled.toString()); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/Mobile.java b/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/Mobile.java index 6545bb1a8a..98d2acd516 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/Mobile.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/Mobile.java @@ -22,40 +22,43 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - +import com.twilio.type.PhoneNumberCapabilities; import java.io.IOException; import java.io.InputStream; - -import java.util.Objects; - - import java.math.BigDecimal; -import com.twilio.type.PhoneNumberCapabilities; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Mobile extends Resource { + private static final long serialVersionUID = 211749226408502L; - public static MobileReader reader(final String pathCountryCode){ + public static MobileReader reader(final String pathCountryCode) { return new MobileReader(pathCountryCode); } - public static MobileReader reader(final String pathAccountSid, final String pathCountryCode){ + + public static MobileReader reader( + final String pathAccountSid, + final String pathCountryCode + ) { return new MobileReader(pathAccountSid, pathCountryCode); } /** - * Converts a JSON String into a Mobile object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Mobile object represented by the provided JSON - */ - public static Mobile fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Mobile object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Mobile object represented by the provided JSON + */ + public static Mobile fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Mobile.class); @@ -67,14 +70,17 @@ public static Mobile fromJson(final String json, final ObjectMapper objectMapper } /** - * Converts a JSON InputStream into a Mobile object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Mobile object represented by the provided JSON - */ - public static Mobile fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Mobile object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Mobile object represented by the provided JSON + */ + public static Mobile fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Mobile.class); @@ -101,44 +107,23 @@ public static Mobile fromJson(final InputStream json, final ObjectMapper objectM @JsonCreator private Mobile( - @JsonProperty("friendly_name") - final com.twilio.type.PhoneNumber friendlyName, - - @JsonProperty("phone_number") - final com.twilio.type.PhoneNumber phoneNumber, - - @JsonProperty("lata") - final String lata, - - @JsonProperty("locality") - final String locality, - - @JsonProperty("rate_center") - final String rateCenter, - - @JsonProperty("latitude") - final BigDecimal latitude, - - @JsonProperty("longitude") - final BigDecimal longitude, - - @JsonProperty("region") - final String region, - - @JsonProperty("postal_code") - final String postalCode, - - @JsonProperty("iso_country") - final String isoCountry, - - @JsonProperty("address_requirements") - final String addressRequirements, - - @JsonProperty("beta") - final Boolean beta, - - @JsonProperty("capabilities") - final PhoneNumberCapabilities capabilities + @JsonProperty( + "friendly_name" + ) final com.twilio.type.PhoneNumber friendlyName, + @JsonProperty( + "phone_number" + ) final com.twilio.type.PhoneNumber phoneNumber, + @JsonProperty("lata") final String lata, + @JsonProperty("locality") final String locality, + @JsonProperty("rate_center") final String rateCenter, + @JsonProperty("latitude") final BigDecimal latitude, + @JsonProperty("longitude") final BigDecimal longitude, + @JsonProperty("region") final String region, + @JsonProperty("postal_code") final String postalCode, + @JsonProperty("iso_country") final String isoCountry, + @JsonProperty("address_requirements") final String addressRequirements, + @JsonProperty("beta") final Boolean beta, + @JsonProperty("capabilities") final PhoneNumberCapabilities capabilities ) { this.friendlyName = friendlyName; this.phoneNumber = phoneNumber; @@ -155,49 +140,61 @@ private Mobile( this.capabilities = capabilities; } - public final com.twilio.type.PhoneNumber getFriendlyName() { - return this.friendlyName; - } - public final com.twilio.type.PhoneNumber getPhoneNumber() { - return this.phoneNumber; - } - public final String getLata() { - return this.lata; - } - public final String getLocality() { - return this.locality; - } - public final String getRateCenter() { - return this.rateCenter; - } - public final BigDecimal getLatitude() { - return this.latitude; - } - public final BigDecimal getLongitude() { - return this.longitude; - } - public final String getRegion() { - return this.region; - } - public final String getPostalCode() { - return this.postalCode; - } - public final String getIsoCountry() { - return this.isoCountry; - } - public final String getAddressRequirements() { - return this.addressRequirements; - } - public final Boolean getBeta() { - return this.beta; - } - public final PhoneNumberCapabilities getCapabilities() { - return this.capabilities; - } + public final com.twilio.type.PhoneNumber getFriendlyName() { + return this.friendlyName; + } + + public final com.twilio.type.PhoneNumber getPhoneNumber() { + return this.phoneNumber; + } + + public final String getLata() { + return this.lata; + } + + public final String getLocality() { + return this.locality; + } + + public final String getRateCenter() { + return this.rateCenter; + } + + public final BigDecimal getLatitude() { + return this.latitude; + } + + public final BigDecimal getLongitude() { + return this.longitude; + } + + public final String getRegion() { + return this.region; + } + + public final String getPostalCode() { + return this.postalCode; + } + + public final String getIsoCountry() { + return this.isoCountry; + } + + public final String getAddressRequirements() { + return this.addressRequirements; + } + + public final Boolean getBeta() { + return this.beta; + } + + public final PhoneNumberCapabilities getCapabilities() { + return this.capabilities; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -207,13 +204,39 @@ public boolean equals(final Object o) { Mobile other = (Mobile) o; - return Objects.equals(friendlyName, other.friendlyName) && Objects.equals(phoneNumber, other.phoneNumber) && Objects.equals(lata, other.lata) && Objects.equals(locality, other.locality) && Objects.equals(rateCenter, other.rateCenter) && Objects.equals(latitude, other.latitude) && Objects.equals(longitude, other.longitude) && Objects.equals(region, other.region) && Objects.equals(postalCode, other.postalCode) && Objects.equals(isoCountry, other.isoCountry) && Objects.equals(addressRequirements, other.addressRequirements) && Objects.equals(beta, other.beta) && Objects.equals(capabilities, other.capabilities) ; + return ( + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(phoneNumber, other.phoneNumber) && + Objects.equals(lata, other.lata) && + Objects.equals(locality, other.locality) && + Objects.equals(rateCenter, other.rateCenter) && + Objects.equals(latitude, other.latitude) && + Objects.equals(longitude, other.longitude) && + Objects.equals(region, other.region) && + Objects.equals(postalCode, other.postalCode) && + Objects.equals(isoCountry, other.isoCountry) && + Objects.equals(addressRequirements, other.addressRequirements) && + Objects.equals(beta, other.beta) && + Objects.equals(capabilities, other.capabilities) + ); } @Override public int hashCode() { - return Objects.hash(friendlyName, phoneNumber, lata, locality, rateCenter, latitude, longitude, region, postalCode, isoCountry, addressRequirements, beta, capabilities); + return Objects.hash( + friendlyName, + phoneNumber, + lata, + locality, + rateCenter, + latitude, + longitude, + region, + postalCode, + isoCountry, + addressRequirements, + beta, + capabilities + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/MobileReader.java b/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/MobileReader.java index dfb002f7c6..6319b22f34 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/MobileReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/MobileReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.api.v2010.account.availablephonenumbercountry; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.converter.Promoter; @@ -25,11 +26,9 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class MobileReader extends Reader { + private String pathCountryCode; private String pathAccountSid; private Integer areaCode; @@ -52,91 +51,121 @@ public class MobileReader extends Reader { private Boolean faxEnabled; private Integer pageSize; - public MobileReader(final String pathCountryCode){ + public MobileReader(final String pathCountryCode) { this.pathCountryCode = pathCountryCode; } - public MobileReader(final String pathAccountSid, final String pathCountryCode){ + + public MobileReader( + final String pathAccountSid, + final String pathCountryCode + ) { this.pathAccountSid = pathAccountSid; this.pathCountryCode = pathCountryCode; } - public MobileReader setAreaCode(final Integer areaCode){ + public MobileReader setAreaCode(final Integer areaCode) { this.areaCode = areaCode; return this; } - public MobileReader setContains(final String contains){ + + public MobileReader setContains(final String contains) { this.contains = contains; return this; } - public MobileReader setSmsEnabled(final Boolean smsEnabled){ + + public MobileReader setSmsEnabled(final Boolean smsEnabled) { this.smsEnabled = smsEnabled; return this; } - public MobileReader setMmsEnabled(final Boolean mmsEnabled){ + + public MobileReader setMmsEnabled(final Boolean mmsEnabled) { this.mmsEnabled = mmsEnabled; return this; } - public MobileReader setVoiceEnabled(final Boolean voiceEnabled){ + + public MobileReader setVoiceEnabled(final Boolean voiceEnabled) { this.voiceEnabled = voiceEnabled; return this; } - public MobileReader setExcludeAllAddressRequired(final Boolean excludeAllAddressRequired){ + + public MobileReader setExcludeAllAddressRequired( + final Boolean excludeAllAddressRequired + ) { this.excludeAllAddressRequired = excludeAllAddressRequired; return this; } - public MobileReader setExcludeLocalAddressRequired(final Boolean excludeLocalAddressRequired){ + + public MobileReader setExcludeLocalAddressRequired( + final Boolean excludeLocalAddressRequired + ) { this.excludeLocalAddressRequired = excludeLocalAddressRequired; return this; } - public MobileReader setExcludeForeignAddressRequired(final Boolean excludeForeignAddressRequired){ + + public MobileReader setExcludeForeignAddressRequired( + final Boolean excludeForeignAddressRequired + ) { this.excludeForeignAddressRequired = excludeForeignAddressRequired; return this; } - public MobileReader setBeta(final Boolean beta){ + + public MobileReader setBeta(final Boolean beta) { this.beta = beta; return this; } - public MobileReader setNearNumber(final com.twilio.type.PhoneNumber nearNumber){ + + public MobileReader setNearNumber( + final com.twilio.type.PhoneNumber nearNumber + ) { this.nearNumber = nearNumber; return this; } - public MobileReader setNearNumber(final String nearNumber){ + public MobileReader setNearNumber(final String nearNumber) { return setNearNumber(Promoter.phoneNumberFromString(nearNumber)); } - public MobileReader setNearLatLong(final String nearLatLong){ + + public MobileReader setNearLatLong(final String nearLatLong) { this.nearLatLong = nearLatLong; return this; } - public MobileReader setDistance(final Integer distance){ + + public MobileReader setDistance(final Integer distance) { this.distance = distance; return this; } - public MobileReader setInPostalCode(final String inPostalCode){ + + public MobileReader setInPostalCode(final String inPostalCode) { this.inPostalCode = inPostalCode; return this; } - public MobileReader setInRegion(final String inRegion){ + + public MobileReader setInRegion(final String inRegion) { this.inRegion = inRegion; return this; } - public MobileReader setInRateCenter(final String inRateCenter){ + + public MobileReader setInRateCenter(final String inRateCenter) { this.inRateCenter = inRateCenter; return this; } - public MobileReader setInLata(final String inLata){ + + public MobileReader setInLata(final String inLata) { this.inLata = inLata; return this; } - public MobileReader setInLocality(final String inLocality){ + + public MobileReader setInLocality(final String inLocality) { this.inLocality = inLocality; return this; } - public MobileReader setFaxEnabled(final Boolean faxEnabled){ + + public MobileReader setFaxEnabled(final Boolean faxEnabled) { this.faxEnabled = faxEnabled; return this; } - public MobileReader setPageSize(final Integer pageSize){ + + public MobileReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -147,10 +176,22 @@ public ResourceSet read(final TwilioRestClient client) { } public Page firstPage(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/AvailablePhoneNumbers/{CountryCode}/Mobile.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"CountryCode"+"}", this.pathCountryCode.toString()); + String path = + "/2010-04-01/Accounts/{AccountSid}/AvailablePhoneNumbers/{CountryCode}/Mobile.json"; + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "CountryCode" + "}", + this.pathCountryCode.toString() + ); Request request = new Request( HttpMethod.GET, @@ -162,13 +203,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Mobile read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Mobile read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -184,7 +233,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.API.toString()) @@ -192,9 +244,11 @@ public Page previousPage(final Page page, final TwilioRestClient return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.API.toString()) @@ -203,93 +257,84 @@ public Page nextPage(final Page page, final TwilioRestClient cli } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (areaCode != null) { - request.addQueryParam("AreaCode", areaCode.toString()); } if (contains != null) { - request.addQueryParam("Contains", contains); } if (smsEnabled != null) { - request.addQueryParam("SmsEnabled", smsEnabled.toString()); } if (mmsEnabled != null) { - request.addQueryParam("MmsEnabled", mmsEnabled.toString()); } if (voiceEnabled != null) { - request.addQueryParam("VoiceEnabled", voiceEnabled.toString()); } if (excludeAllAddressRequired != null) { - - request.addQueryParam("ExcludeAllAddressRequired", excludeAllAddressRequired.toString()); + request.addQueryParam( + "ExcludeAllAddressRequired", + excludeAllAddressRequired.toString() + ); } if (excludeLocalAddressRequired != null) { - - request.addQueryParam("ExcludeLocalAddressRequired", excludeLocalAddressRequired.toString()); + request.addQueryParam( + "ExcludeLocalAddressRequired", + excludeLocalAddressRequired.toString() + ); } if (excludeForeignAddressRequired != null) { - - request.addQueryParam("ExcludeForeignAddressRequired", excludeForeignAddressRequired.toString()); + request.addQueryParam( + "ExcludeForeignAddressRequired", + excludeForeignAddressRequired.toString() + ); } if (beta != null) { - request.addQueryParam("Beta", beta.toString()); } if (nearNumber != null) { - request.addQueryParam("NearNumber", nearNumber.toString()); } if (nearLatLong != null) { - request.addQueryParam("NearLatLong", nearLatLong); } if (distance != null) { - request.addQueryParam("Distance", distance.toString()); } if (inPostalCode != null) { - request.addQueryParam("InPostalCode", inPostalCode); } if (inRegion != null) { - request.addQueryParam("InRegion", inRegion); } if (inRateCenter != null) { - request.addQueryParam("InRateCenter", inRateCenter); } if (inLata != null) { - request.addQueryParam("InLata", inLata); } if (inLocality != null) { - request.addQueryParam("InLocality", inLocality); } if (faxEnabled != null) { - request.addQueryParam("FaxEnabled", faxEnabled.toString()); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/National.java b/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/National.java index 45bf72a4a7..d9489d1055 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/National.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/National.java @@ -22,40 +22,43 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - +import com.twilio.type.PhoneNumberCapabilities; import java.io.IOException; import java.io.InputStream; - -import java.util.Objects; - - import java.math.BigDecimal; -import com.twilio.type.PhoneNumberCapabilities; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class National extends Resource { + private static final long serialVersionUID = 211749226408502L; - public static NationalReader reader(final String pathCountryCode){ + public static NationalReader reader(final String pathCountryCode) { return new NationalReader(pathCountryCode); } - public static NationalReader reader(final String pathAccountSid, final String pathCountryCode){ + + public static NationalReader reader( + final String pathAccountSid, + final String pathCountryCode + ) { return new NationalReader(pathAccountSid, pathCountryCode); } /** - * Converts a JSON String into a National object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return National object represented by the provided JSON - */ - public static National fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a National object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return National object represented by the provided JSON + */ + public static National fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, National.class); @@ -67,14 +70,17 @@ public static National fromJson(final String json, final ObjectMapper objectMapp } /** - * Converts a JSON InputStream into a National object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return National object represented by the provided JSON - */ - public static National fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a National object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return National object represented by the provided JSON + */ + public static National fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, National.class); @@ -101,44 +107,23 @@ public static National fromJson(final InputStream json, final ObjectMapper objec @JsonCreator private National( - @JsonProperty("friendly_name") - final com.twilio.type.PhoneNumber friendlyName, - - @JsonProperty("phone_number") - final com.twilio.type.PhoneNumber phoneNumber, - - @JsonProperty("lata") - final String lata, - - @JsonProperty("locality") - final String locality, - - @JsonProperty("rate_center") - final String rateCenter, - - @JsonProperty("latitude") - final BigDecimal latitude, - - @JsonProperty("longitude") - final BigDecimal longitude, - - @JsonProperty("region") - final String region, - - @JsonProperty("postal_code") - final String postalCode, - - @JsonProperty("iso_country") - final String isoCountry, - - @JsonProperty("address_requirements") - final String addressRequirements, - - @JsonProperty("beta") - final Boolean beta, - - @JsonProperty("capabilities") - final PhoneNumberCapabilities capabilities + @JsonProperty( + "friendly_name" + ) final com.twilio.type.PhoneNumber friendlyName, + @JsonProperty( + "phone_number" + ) final com.twilio.type.PhoneNumber phoneNumber, + @JsonProperty("lata") final String lata, + @JsonProperty("locality") final String locality, + @JsonProperty("rate_center") final String rateCenter, + @JsonProperty("latitude") final BigDecimal latitude, + @JsonProperty("longitude") final BigDecimal longitude, + @JsonProperty("region") final String region, + @JsonProperty("postal_code") final String postalCode, + @JsonProperty("iso_country") final String isoCountry, + @JsonProperty("address_requirements") final String addressRequirements, + @JsonProperty("beta") final Boolean beta, + @JsonProperty("capabilities") final PhoneNumberCapabilities capabilities ) { this.friendlyName = friendlyName; this.phoneNumber = phoneNumber; @@ -155,49 +140,61 @@ private National( this.capabilities = capabilities; } - public final com.twilio.type.PhoneNumber getFriendlyName() { - return this.friendlyName; - } - public final com.twilio.type.PhoneNumber getPhoneNumber() { - return this.phoneNumber; - } - public final String getLata() { - return this.lata; - } - public final String getLocality() { - return this.locality; - } - public final String getRateCenter() { - return this.rateCenter; - } - public final BigDecimal getLatitude() { - return this.latitude; - } - public final BigDecimal getLongitude() { - return this.longitude; - } - public final String getRegion() { - return this.region; - } - public final String getPostalCode() { - return this.postalCode; - } - public final String getIsoCountry() { - return this.isoCountry; - } - public final String getAddressRequirements() { - return this.addressRequirements; - } - public final Boolean getBeta() { - return this.beta; - } - public final PhoneNumberCapabilities getCapabilities() { - return this.capabilities; - } + public final com.twilio.type.PhoneNumber getFriendlyName() { + return this.friendlyName; + } + + public final com.twilio.type.PhoneNumber getPhoneNumber() { + return this.phoneNumber; + } + + public final String getLata() { + return this.lata; + } + + public final String getLocality() { + return this.locality; + } + + public final String getRateCenter() { + return this.rateCenter; + } + + public final BigDecimal getLatitude() { + return this.latitude; + } + + public final BigDecimal getLongitude() { + return this.longitude; + } + + public final String getRegion() { + return this.region; + } + + public final String getPostalCode() { + return this.postalCode; + } + + public final String getIsoCountry() { + return this.isoCountry; + } + + public final String getAddressRequirements() { + return this.addressRequirements; + } + + public final Boolean getBeta() { + return this.beta; + } + + public final PhoneNumberCapabilities getCapabilities() { + return this.capabilities; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -207,13 +204,39 @@ public boolean equals(final Object o) { National other = (National) o; - return Objects.equals(friendlyName, other.friendlyName) && Objects.equals(phoneNumber, other.phoneNumber) && Objects.equals(lata, other.lata) && Objects.equals(locality, other.locality) && Objects.equals(rateCenter, other.rateCenter) && Objects.equals(latitude, other.latitude) && Objects.equals(longitude, other.longitude) && Objects.equals(region, other.region) && Objects.equals(postalCode, other.postalCode) && Objects.equals(isoCountry, other.isoCountry) && Objects.equals(addressRequirements, other.addressRequirements) && Objects.equals(beta, other.beta) && Objects.equals(capabilities, other.capabilities) ; + return ( + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(phoneNumber, other.phoneNumber) && + Objects.equals(lata, other.lata) && + Objects.equals(locality, other.locality) && + Objects.equals(rateCenter, other.rateCenter) && + Objects.equals(latitude, other.latitude) && + Objects.equals(longitude, other.longitude) && + Objects.equals(region, other.region) && + Objects.equals(postalCode, other.postalCode) && + Objects.equals(isoCountry, other.isoCountry) && + Objects.equals(addressRequirements, other.addressRequirements) && + Objects.equals(beta, other.beta) && + Objects.equals(capabilities, other.capabilities) + ); } @Override public int hashCode() { - return Objects.hash(friendlyName, phoneNumber, lata, locality, rateCenter, latitude, longitude, region, postalCode, isoCountry, addressRequirements, beta, capabilities); + return Objects.hash( + friendlyName, + phoneNumber, + lata, + locality, + rateCenter, + latitude, + longitude, + region, + postalCode, + isoCountry, + addressRequirements, + beta, + capabilities + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/NationalReader.java b/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/NationalReader.java index 1ea0f9a995..52ed19add8 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/NationalReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/NationalReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.api.v2010.account.availablephonenumbercountry; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.converter.Promoter; @@ -25,11 +26,9 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class NationalReader extends Reader { + private String pathCountryCode; private String pathAccountSid; private Integer areaCode; @@ -52,91 +51,121 @@ public class NationalReader extends Reader { private Boolean faxEnabled; private Integer pageSize; - public NationalReader(final String pathCountryCode){ + public NationalReader(final String pathCountryCode) { this.pathCountryCode = pathCountryCode; } - public NationalReader(final String pathAccountSid, final String pathCountryCode){ + + public NationalReader( + final String pathAccountSid, + final String pathCountryCode + ) { this.pathAccountSid = pathAccountSid; this.pathCountryCode = pathCountryCode; } - public NationalReader setAreaCode(final Integer areaCode){ + public NationalReader setAreaCode(final Integer areaCode) { this.areaCode = areaCode; return this; } - public NationalReader setContains(final String contains){ + + public NationalReader setContains(final String contains) { this.contains = contains; return this; } - public NationalReader setSmsEnabled(final Boolean smsEnabled){ + + public NationalReader setSmsEnabled(final Boolean smsEnabled) { this.smsEnabled = smsEnabled; return this; } - public NationalReader setMmsEnabled(final Boolean mmsEnabled){ + + public NationalReader setMmsEnabled(final Boolean mmsEnabled) { this.mmsEnabled = mmsEnabled; return this; } - public NationalReader setVoiceEnabled(final Boolean voiceEnabled){ + + public NationalReader setVoiceEnabled(final Boolean voiceEnabled) { this.voiceEnabled = voiceEnabled; return this; } - public NationalReader setExcludeAllAddressRequired(final Boolean excludeAllAddressRequired){ + + public NationalReader setExcludeAllAddressRequired( + final Boolean excludeAllAddressRequired + ) { this.excludeAllAddressRequired = excludeAllAddressRequired; return this; } - public NationalReader setExcludeLocalAddressRequired(final Boolean excludeLocalAddressRequired){ + + public NationalReader setExcludeLocalAddressRequired( + final Boolean excludeLocalAddressRequired + ) { this.excludeLocalAddressRequired = excludeLocalAddressRequired; return this; } - public NationalReader setExcludeForeignAddressRequired(final Boolean excludeForeignAddressRequired){ + + public NationalReader setExcludeForeignAddressRequired( + final Boolean excludeForeignAddressRequired + ) { this.excludeForeignAddressRequired = excludeForeignAddressRequired; return this; } - public NationalReader setBeta(final Boolean beta){ + + public NationalReader setBeta(final Boolean beta) { this.beta = beta; return this; } - public NationalReader setNearNumber(final com.twilio.type.PhoneNumber nearNumber){ + + public NationalReader setNearNumber( + final com.twilio.type.PhoneNumber nearNumber + ) { this.nearNumber = nearNumber; return this; } - public NationalReader setNearNumber(final String nearNumber){ + public NationalReader setNearNumber(final String nearNumber) { return setNearNumber(Promoter.phoneNumberFromString(nearNumber)); } - public NationalReader setNearLatLong(final String nearLatLong){ + + public NationalReader setNearLatLong(final String nearLatLong) { this.nearLatLong = nearLatLong; return this; } - public NationalReader setDistance(final Integer distance){ + + public NationalReader setDistance(final Integer distance) { this.distance = distance; return this; } - public NationalReader setInPostalCode(final String inPostalCode){ + + public NationalReader setInPostalCode(final String inPostalCode) { this.inPostalCode = inPostalCode; return this; } - public NationalReader setInRegion(final String inRegion){ + + public NationalReader setInRegion(final String inRegion) { this.inRegion = inRegion; return this; } - public NationalReader setInRateCenter(final String inRateCenter){ + + public NationalReader setInRateCenter(final String inRateCenter) { this.inRateCenter = inRateCenter; return this; } - public NationalReader setInLata(final String inLata){ + + public NationalReader setInLata(final String inLata) { this.inLata = inLata; return this; } - public NationalReader setInLocality(final String inLocality){ + + public NationalReader setInLocality(final String inLocality) { this.inLocality = inLocality; return this; } - public NationalReader setFaxEnabled(final Boolean faxEnabled){ + + public NationalReader setFaxEnabled(final Boolean faxEnabled) { this.faxEnabled = faxEnabled; return this; } - public NationalReader setPageSize(final Integer pageSize){ + + public NationalReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -147,10 +176,22 @@ public ResourceSet read(final TwilioRestClient client) { } public Page firstPage(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/AvailablePhoneNumbers/{CountryCode}/National.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"CountryCode"+"}", this.pathCountryCode.toString()); + String path = + "/2010-04-01/Accounts/{AccountSid}/AvailablePhoneNumbers/{CountryCode}/National.json"; + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "CountryCode" + "}", + this.pathCountryCode.toString() + ); Request request = new Request( HttpMethod.GET, @@ -162,13 +203,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("National read failed: Unable to connect to server"); + throw new ApiConnectionException( + "National read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -184,7 +233,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reque } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.API.toString()) @@ -192,9 +244,11 @@ public Page previousPage(final Page page, final TwilioRestCl return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.API.toString()) @@ -203,93 +257,84 @@ public Page nextPage(final Page page, final TwilioRestClient } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (areaCode != null) { - request.addQueryParam("AreaCode", areaCode.toString()); } if (contains != null) { - request.addQueryParam("Contains", contains); } if (smsEnabled != null) { - request.addQueryParam("SmsEnabled", smsEnabled.toString()); } if (mmsEnabled != null) { - request.addQueryParam("MmsEnabled", mmsEnabled.toString()); } if (voiceEnabled != null) { - request.addQueryParam("VoiceEnabled", voiceEnabled.toString()); } if (excludeAllAddressRequired != null) { - - request.addQueryParam("ExcludeAllAddressRequired", excludeAllAddressRequired.toString()); + request.addQueryParam( + "ExcludeAllAddressRequired", + excludeAllAddressRequired.toString() + ); } if (excludeLocalAddressRequired != null) { - - request.addQueryParam("ExcludeLocalAddressRequired", excludeLocalAddressRequired.toString()); + request.addQueryParam( + "ExcludeLocalAddressRequired", + excludeLocalAddressRequired.toString() + ); } if (excludeForeignAddressRequired != null) { - - request.addQueryParam("ExcludeForeignAddressRequired", excludeForeignAddressRequired.toString()); + request.addQueryParam( + "ExcludeForeignAddressRequired", + excludeForeignAddressRequired.toString() + ); } if (beta != null) { - request.addQueryParam("Beta", beta.toString()); } if (nearNumber != null) { - request.addQueryParam("NearNumber", nearNumber.toString()); } if (nearLatLong != null) { - request.addQueryParam("NearLatLong", nearLatLong); } if (distance != null) { - request.addQueryParam("Distance", distance.toString()); } if (inPostalCode != null) { - request.addQueryParam("InPostalCode", inPostalCode); } if (inRegion != null) { - request.addQueryParam("InRegion", inRegion); } if (inRateCenter != null) { - request.addQueryParam("InRateCenter", inRateCenter); } if (inLata != null) { - request.addQueryParam("InLata", inLata); } if (inLocality != null) { - request.addQueryParam("InLocality", inLocality); } if (faxEnabled != null) { - request.addQueryParam("FaxEnabled", faxEnabled.toString()); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/SharedCost.java b/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/SharedCost.java index 4eddcfd748..cf263c0a75 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/SharedCost.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/SharedCost.java @@ -22,40 +22,43 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - +import com.twilio.type.PhoneNumberCapabilities; import java.io.IOException; import java.io.InputStream; - -import java.util.Objects; - - import java.math.BigDecimal; -import com.twilio.type.PhoneNumberCapabilities; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class SharedCost extends Resource { + private static final long serialVersionUID = 211749226408502L; - public static SharedCostReader reader(final String pathCountryCode){ + public static SharedCostReader reader(final String pathCountryCode) { return new SharedCostReader(pathCountryCode); } - public static SharedCostReader reader(final String pathAccountSid, final String pathCountryCode){ + + public static SharedCostReader reader( + final String pathAccountSid, + final String pathCountryCode + ) { return new SharedCostReader(pathAccountSid, pathCountryCode); } /** - * Converts a JSON String into a SharedCost object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return SharedCost object represented by the provided JSON - */ - public static SharedCost fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a SharedCost object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return SharedCost object represented by the provided JSON + */ + public static SharedCost fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SharedCost.class); @@ -67,14 +70,17 @@ public static SharedCost fromJson(final String json, final ObjectMapper objectMa } /** - * Converts a JSON InputStream into a SharedCost object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return SharedCost object represented by the provided JSON - */ - public static SharedCost fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a SharedCost object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return SharedCost object represented by the provided JSON + */ + public static SharedCost fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SharedCost.class); @@ -101,44 +107,23 @@ public static SharedCost fromJson(final InputStream json, final ObjectMapper obj @JsonCreator private SharedCost( - @JsonProperty("friendly_name") - final com.twilio.type.PhoneNumber friendlyName, - - @JsonProperty("phone_number") - final com.twilio.type.PhoneNumber phoneNumber, - - @JsonProperty("lata") - final String lata, - - @JsonProperty("locality") - final String locality, - - @JsonProperty("rate_center") - final String rateCenter, - - @JsonProperty("latitude") - final BigDecimal latitude, - - @JsonProperty("longitude") - final BigDecimal longitude, - - @JsonProperty("region") - final String region, - - @JsonProperty("postal_code") - final String postalCode, - - @JsonProperty("iso_country") - final String isoCountry, - - @JsonProperty("address_requirements") - final String addressRequirements, - - @JsonProperty("beta") - final Boolean beta, - - @JsonProperty("capabilities") - final PhoneNumberCapabilities capabilities + @JsonProperty( + "friendly_name" + ) final com.twilio.type.PhoneNumber friendlyName, + @JsonProperty( + "phone_number" + ) final com.twilio.type.PhoneNumber phoneNumber, + @JsonProperty("lata") final String lata, + @JsonProperty("locality") final String locality, + @JsonProperty("rate_center") final String rateCenter, + @JsonProperty("latitude") final BigDecimal latitude, + @JsonProperty("longitude") final BigDecimal longitude, + @JsonProperty("region") final String region, + @JsonProperty("postal_code") final String postalCode, + @JsonProperty("iso_country") final String isoCountry, + @JsonProperty("address_requirements") final String addressRequirements, + @JsonProperty("beta") final Boolean beta, + @JsonProperty("capabilities") final PhoneNumberCapabilities capabilities ) { this.friendlyName = friendlyName; this.phoneNumber = phoneNumber; @@ -155,49 +140,61 @@ private SharedCost( this.capabilities = capabilities; } - public final com.twilio.type.PhoneNumber getFriendlyName() { - return this.friendlyName; - } - public final com.twilio.type.PhoneNumber getPhoneNumber() { - return this.phoneNumber; - } - public final String getLata() { - return this.lata; - } - public final String getLocality() { - return this.locality; - } - public final String getRateCenter() { - return this.rateCenter; - } - public final BigDecimal getLatitude() { - return this.latitude; - } - public final BigDecimal getLongitude() { - return this.longitude; - } - public final String getRegion() { - return this.region; - } - public final String getPostalCode() { - return this.postalCode; - } - public final String getIsoCountry() { - return this.isoCountry; - } - public final String getAddressRequirements() { - return this.addressRequirements; - } - public final Boolean getBeta() { - return this.beta; - } - public final PhoneNumberCapabilities getCapabilities() { - return this.capabilities; - } + public final com.twilio.type.PhoneNumber getFriendlyName() { + return this.friendlyName; + } + + public final com.twilio.type.PhoneNumber getPhoneNumber() { + return this.phoneNumber; + } + + public final String getLata() { + return this.lata; + } + + public final String getLocality() { + return this.locality; + } + + public final String getRateCenter() { + return this.rateCenter; + } + + public final BigDecimal getLatitude() { + return this.latitude; + } + + public final BigDecimal getLongitude() { + return this.longitude; + } + + public final String getRegion() { + return this.region; + } + + public final String getPostalCode() { + return this.postalCode; + } + + public final String getIsoCountry() { + return this.isoCountry; + } + + public final String getAddressRequirements() { + return this.addressRequirements; + } + + public final Boolean getBeta() { + return this.beta; + } + + public final PhoneNumberCapabilities getCapabilities() { + return this.capabilities; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -207,13 +204,39 @@ public boolean equals(final Object o) { SharedCost other = (SharedCost) o; - return Objects.equals(friendlyName, other.friendlyName) && Objects.equals(phoneNumber, other.phoneNumber) && Objects.equals(lata, other.lata) && Objects.equals(locality, other.locality) && Objects.equals(rateCenter, other.rateCenter) && Objects.equals(latitude, other.latitude) && Objects.equals(longitude, other.longitude) && Objects.equals(region, other.region) && Objects.equals(postalCode, other.postalCode) && Objects.equals(isoCountry, other.isoCountry) && Objects.equals(addressRequirements, other.addressRequirements) && Objects.equals(beta, other.beta) && Objects.equals(capabilities, other.capabilities) ; + return ( + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(phoneNumber, other.phoneNumber) && + Objects.equals(lata, other.lata) && + Objects.equals(locality, other.locality) && + Objects.equals(rateCenter, other.rateCenter) && + Objects.equals(latitude, other.latitude) && + Objects.equals(longitude, other.longitude) && + Objects.equals(region, other.region) && + Objects.equals(postalCode, other.postalCode) && + Objects.equals(isoCountry, other.isoCountry) && + Objects.equals(addressRequirements, other.addressRequirements) && + Objects.equals(beta, other.beta) && + Objects.equals(capabilities, other.capabilities) + ); } @Override public int hashCode() { - return Objects.hash(friendlyName, phoneNumber, lata, locality, rateCenter, latitude, longitude, region, postalCode, isoCountry, addressRequirements, beta, capabilities); + return Objects.hash( + friendlyName, + phoneNumber, + lata, + locality, + rateCenter, + latitude, + longitude, + region, + postalCode, + isoCountry, + addressRequirements, + beta, + capabilities + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/SharedCostReader.java b/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/SharedCostReader.java index 2ae6f3f444..68e53e8e2f 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/SharedCostReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/SharedCostReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.api.v2010.account.availablephonenumbercountry; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.converter.Promoter; @@ -25,11 +26,9 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class SharedCostReader extends Reader { + private String pathCountryCode; private String pathAccountSid; private Integer areaCode; @@ -52,91 +51,121 @@ public class SharedCostReader extends Reader { private Boolean faxEnabled; private Integer pageSize; - public SharedCostReader(final String pathCountryCode){ + public SharedCostReader(final String pathCountryCode) { this.pathCountryCode = pathCountryCode; } - public SharedCostReader(final String pathAccountSid, final String pathCountryCode){ + + public SharedCostReader( + final String pathAccountSid, + final String pathCountryCode + ) { this.pathAccountSid = pathAccountSid; this.pathCountryCode = pathCountryCode; } - public SharedCostReader setAreaCode(final Integer areaCode){ + public SharedCostReader setAreaCode(final Integer areaCode) { this.areaCode = areaCode; return this; } - public SharedCostReader setContains(final String contains){ + + public SharedCostReader setContains(final String contains) { this.contains = contains; return this; } - public SharedCostReader setSmsEnabled(final Boolean smsEnabled){ + + public SharedCostReader setSmsEnabled(final Boolean smsEnabled) { this.smsEnabled = smsEnabled; return this; } - public SharedCostReader setMmsEnabled(final Boolean mmsEnabled){ + + public SharedCostReader setMmsEnabled(final Boolean mmsEnabled) { this.mmsEnabled = mmsEnabled; return this; } - public SharedCostReader setVoiceEnabled(final Boolean voiceEnabled){ + + public SharedCostReader setVoiceEnabled(final Boolean voiceEnabled) { this.voiceEnabled = voiceEnabled; return this; } - public SharedCostReader setExcludeAllAddressRequired(final Boolean excludeAllAddressRequired){ + + public SharedCostReader setExcludeAllAddressRequired( + final Boolean excludeAllAddressRequired + ) { this.excludeAllAddressRequired = excludeAllAddressRequired; return this; } - public SharedCostReader setExcludeLocalAddressRequired(final Boolean excludeLocalAddressRequired){ + + public SharedCostReader setExcludeLocalAddressRequired( + final Boolean excludeLocalAddressRequired + ) { this.excludeLocalAddressRequired = excludeLocalAddressRequired; return this; } - public SharedCostReader setExcludeForeignAddressRequired(final Boolean excludeForeignAddressRequired){ + + public SharedCostReader setExcludeForeignAddressRequired( + final Boolean excludeForeignAddressRequired + ) { this.excludeForeignAddressRequired = excludeForeignAddressRequired; return this; } - public SharedCostReader setBeta(final Boolean beta){ + + public SharedCostReader setBeta(final Boolean beta) { this.beta = beta; return this; } - public SharedCostReader setNearNumber(final com.twilio.type.PhoneNumber nearNumber){ + + public SharedCostReader setNearNumber( + final com.twilio.type.PhoneNumber nearNumber + ) { this.nearNumber = nearNumber; return this; } - public SharedCostReader setNearNumber(final String nearNumber){ + public SharedCostReader setNearNumber(final String nearNumber) { return setNearNumber(Promoter.phoneNumberFromString(nearNumber)); } - public SharedCostReader setNearLatLong(final String nearLatLong){ + + public SharedCostReader setNearLatLong(final String nearLatLong) { this.nearLatLong = nearLatLong; return this; } - public SharedCostReader setDistance(final Integer distance){ + + public SharedCostReader setDistance(final Integer distance) { this.distance = distance; return this; } - public SharedCostReader setInPostalCode(final String inPostalCode){ + + public SharedCostReader setInPostalCode(final String inPostalCode) { this.inPostalCode = inPostalCode; return this; } - public SharedCostReader setInRegion(final String inRegion){ + + public SharedCostReader setInRegion(final String inRegion) { this.inRegion = inRegion; return this; } - public SharedCostReader setInRateCenter(final String inRateCenter){ + + public SharedCostReader setInRateCenter(final String inRateCenter) { this.inRateCenter = inRateCenter; return this; } - public SharedCostReader setInLata(final String inLata){ + + public SharedCostReader setInLata(final String inLata) { this.inLata = inLata; return this; } - public SharedCostReader setInLocality(final String inLocality){ + + public SharedCostReader setInLocality(final String inLocality) { this.inLocality = inLocality; return this; } - public SharedCostReader setFaxEnabled(final Boolean faxEnabled){ + + public SharedCostReader setFaxEnabled(final Boolean faxEnabled) { this.faxEnabled = faxEnabled; return this; } - public SharedCostReader setPageSize(final Integer pageSize){ + + public SharedCostReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -147,10 +176,22 @@ public ResourceSet read(final TwilioRestClient client) { } public Page firstPage(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/AvailablePhoneNumbers/{CountryCode}/SharedCost.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"CountryCode"+"}", this.pathCountryCode.toString()); + String path = + "/2010-04-01/Accounts/{AccountSid}/AvailablePhoneNumbers/{CountryCode}/SharedCost.json"; + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "CountryCode" + "}", + this.pathCountryCode.toString() + ); Request request = new Request( HttpMethod.GET, @@ -162,13 +203,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SharedCost read failed: Unable to connect to server"); + throw new ApiConnectionException( + "SharedCost read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -184,7 +233,10 @@ private Page pageForRequest(final TwilioRestClient client, final Req } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.API.toString()) @@ -192,9 +244,11 @@ public Page previousPage(final Page page, final TwilioRe return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.API.toString()) @@ -203,93 +257,84 @@ public Page nextPage(final Page page, final TwilioRestCl } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (areaCode != null) { - request.addQueryParam("AreaCode", areaCode.toString()); } if (contains != null) { - request.addQueryParam("Contains", contains); } if (smsEnabled != null) { - request.addQueryParam("SmsEnabled", smsEnabled.toString()); } if (mmsEnabled != null) { - request.addQueryParam("MmsEnabled", mmsEnabled.toString()); } if (voiceEnabled != null) { - request.addQueryParam("VoiceEnabled", voiceEnabled.toString()); } if (excludeAllAddressRequired != null) { - - request.addQueryParam("ExcludeAllAddressRequired", excludeAllAddressRequired.toString()); + request.addQueryParam( + "ExcludeAllAddressRequired", + excludeAllAddressRequired.toString() + ); } if (excludeLocalAddressRequired != null) { - - request.addQueryParam("ExcludeLocalAddressRequired", excludeLocalAddressRequired.toString()); + request.addQueryParam( + "ExcludeLocalAddressRequired", + excludeLocalAddressRequired.toString() + ); } if (excludeForeignAddressRequired != null) { - - request.addQueryParam("ExcludeForeignAddressRequired", excludeForeignAddressRequired.toString()); + request.addQueryParam( + "ExcludeForeignAddressRequired", + excludeForeignAddressRequired.toString() + ); } if (beta != null) { - request.addQueryParam("Beta", beta.toString()); } if (nearNumber != null) { - request.addQueryParam("NearNumber", nearNumber.toString()); } if (nearLatLong != null) { - request.addQueryParam("NearLatLong", nearLatLong); } if (distance != null) { - request.addQueryParam("Distance", distance.toString()); } if (inPostalCode != null) { - request.addQueryParam("InPostalCode", inPostalCode); } if (inRegion != null) { - request.addQueryParam("InRegion", inRegion); } if (inRateCenter != null) { - request.addQueryParam("InRateCenter", inRateCenter); } if (inLata != null) { - request.addQueryParam("InLata", inLata); } if (inLocality != null) { - request.addQueryParam("InLocality", inLocality); } if (faxEnabled != null) { - request.addQueryParam("FaxEnabled", faxEnabled.toString()); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/TollFree.java b/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/TollFree.java index 641938112e..c9d8ac7b2e 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/TollFree.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/TollFree.java @@ -22,40 +22,43 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - +import com.twilio.type.PhoneNumberCapabilities; import java.io.IOException; import java.io.InputStream; - -import java.util.Objects; - - import java.math.BigDecimal; -import com.twilio.type.PhoneNumberCapabilities; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class TollFree extends Resource { + private static final long serialVersionUID = 211749226408502L; - public static TollFreeReader reader(final String pathCountryCode){ + public static TollFreeReader reader(final String pathCountryCode) { return new TollFreeReader(pathCountryCode); } - public static TollFreeReader reader(final String pathAccountSid, final String pathCountryCode){ + + public static TollFreeReader reader( + final String pathAccountSid, + final String pathCountryCode + ) { return new TollFreeReader(pathAccountSid, pathCountryCode); } /** - * Converts a JSON String into a TollFree object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return TollFree object represented by the provided JSON - */ - public static TollFree fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a TollFree object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return TollFree object represented by the provided JSON + */ + public static TollFree fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, TollFree.class); @@ -67,14 +70,17 @@ public static TollFree fromJson(final String json, final ObjectMapper objectMapp } /** - * Converts a JSON InputStream into a TollFree object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return TollFree object represented by the provided JSON - */ - public static TollFree fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a TollFree object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return TollFree object represented by the provided JSON + */ + public static TollFree fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, TollFree.class); @@ -101,44 +107,23 @@ public static TollFree fromJson(final InputStream json, final ObjectMapper objec @JsonCreator private TollFree( - @JsonProperty("friendly_name") - final com.twilio.type.PhoneNumber friendlyName, - - @JsonProperty("phone_number") - final com.twilio.type.PhoneNumber phoneNumber, - - @JsonProperty("lata") - final String lata, - - @JsonProperty("locality") - final String locality, - - @JsonProperty("rate_center") - final String rateCenter, - - @JsonProperty("latitude") - final BigDecimal latitude, - - @JsonProperty("longitude") - final BigDecimal longitude, - - @JsonProperty("region") - final String region, - - @JsonProperty("postal_code") - final String postalCode, - - @JsonProperty("iso_country") - final String isoCountry, - - @JsonProperty("address_requirements") - final String addressRequirements, - - @JsonProperty("beta") - final Boolean beta, - - @JsonProperty("capabilities") - final PhoneNumberCapabilities capabilities + @JsonProperty( + "friendly_name" + ) final com.twilio.type.PhoneNumber friendlyName, + @JsonProperty( + "phone_number" + ) final com.twilio.type.PhoneNumber phoneNumber, + @JsonProperty("lata") final String lata, + @JsonProperty("locality") final String locality, + @JsonProperty("rate_center") final String rateCenter, + @JsonProperty("latitude") final BigDecimal latitude, + @JsonProperty("longitude") final BigDecimal longitude, + @JsonProperty("region") final String region, + @JsonProperty("postal_code") final String postalCode, + @JsonProperty("iso_country") final String isoCountry, + @JsonProperty("address_requirements") final String addressRequirements, + @JsonProperty("beta") final Boolean beta, + @JsonProperty("capabilities") final PhoneNumberCapabilities capabilities ) { this.friendlyName = friendlyName; this.phoneNumber = phoneNumber; @@ -155,49 +140,61 @@ private TollFree( this.capabilities = capabilities; } - public final com.twilio.type.PhoneNumber getFriendlyName() { - return this.friendlyName; - } - public final com.twilio.type.PhoneNumber getPhoneNumber() { - return this.phoneNumber; - } - public final String getLata() { - return this.lata; - } - public final String getLocality() { - return this.locality; - } - public final String getRateCenter() { - return this.rateCenter; - } - public final BigDecimal getLatitude() { - return this.latitude; - } - public final BigDecimal getLongitude() { - return this.longitude; - } - public final String getRegion() { - return this.region; - } - public final String getPostalCode() { - return this.postalCode; - } - public final String getIsoCountry() { - return this.isoCountry; - } - public final String getAddressRequirements() { - return this.addressRequirements; - } - public final Boolean getBeta() { - return this.beta; - } - public final PhoneNumberCapabilities getCapabilities() { - return this.capabilities; - } + public final com.twilio.type.PhoneNumber getFriendlyName() { + return this.friendlyName; + } + + public final com.twilio.type.PhoneNumber getPhoneNumber() { + return this.phoneNumber; + } + + public final String getLata() { + return this.lata; + } + + public final String getLocality() { + return this.locality; + } + + public final String getRateCenter() { + return this.rateCenter; + } + + public final BigDecimal getLatitude() { + return this.latitude; + } + + public final BigDecimal getLongitude() { + return this.longitude; + } + + public final String getRegion() { + return this.region; + } + + public final String getPostalCode() { + return this.postalCode; + } + + public final String getIsoCountry() { + return this.isoCountry; + } + + public final String getAddressRequirements() { + return this.addressRequirements; + } + + public final Boolean getBeta() { + return this.beta; + } + + public final PhoneNumberCapabilities getCapabilities() { + return this.capabilities; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -207,13 +204,39 @@ public boolean equals(final Object o) { TollFree other = (TollFree) o; - return Objects.equals(friendlyName, other.friendlyName) && Objects.equals(phoneNumber, other.phoneNumber) && Objects.equals(lata, other.lata) && Objects.equals(locality, other.locality) && Objects.equals(rateCenter, other.rateCenter) && Objects.equals(latitude, other.latitude) && Objects.equals(longitude, other.longitude) && Objects.equals(region, other.region) && Objects.equals(postalCode, other.postalCode) && Objects.equals(isoCountry, other.isoCountry) && Objects.equals(addressRequirements, other.addressRequirements) && Objects.equals(beta, other.beta) && Objects.equals(capabilities, other.capabilities) ; + return ( + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(phoneNumber, other.phoneNumber) && + Objects.equals(lata, other.lata) && + Objects.equals(locality, other.locality) && + Objects.equals(rateCenter, other.rateCenter) && + Objects.equals(latitude, other.latitude) && + Objects.equals(longitude, other.longitude) && + Objects.equals(region, other.region) && + Objects.equals(postalCode, other.postalCode) && + Objects.equals(isoCountry, other.isoCountry) && + Objects.equals(addressRequirements, other.addressRequirements) && + Objects.equals(beta, other.beta) && + Objects.equals(capabilities, other.capabilities) + ); } @Override public int hashCode() { - return Objects.hash(friendlyName, phoneNumber, lata, locality, rateCenter, latitude, longitude, region, postalCode, isoCountry, addressRequirements, beta, capabilities); + return Objects.hash( + friendlyName, + phoneNumber, + lata, + locality, + rateCenter, + latitude, + longitude, + region, + postalCode, + isoCountry, + addressRequirements, + beta, + capabilities + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/TollFreeReader.java b/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/TollFreeReader.java index 09b66047ec..22006289e0 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/TollFreeReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/TollFreeReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.api.v2010.account.availablephonenumbercountry; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.converter.Promoter; @@ -25,11 +26,9 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class TollFreeReader extends Reader { + private String pathCountryCode; private String pathAccountSid; private Integer areaCode; @@ -52,91 +51,121 @@ public class TollFreeReader extends Reader { private Boolean faxEnabled; private Integer pageSize; - public TollFreeReader(final String pathCountryCode){ + public TollFreeReader(final String pathCountryCode) { this.pathCountryCode = pathCountryCode; } - public TollFreeReader(final String pathAccountSid, final String pathCountryCode){ + + public TollFreeReader( + final String pathAccountSid, + final String pathCountryCode + ) { this.pathAccountSid = pathAccountSid; this.pathCountryCode = pathCountryCode; } - public TollFreeReader setAreaCode(final Integer areaCode){ + public TollFreeReader setAreaCode(final Integer areaCode) { this.areaCode = areaCode; return this; } - public TollFreeReader setContains(final String contains){ + + public TollFreeReader setContains(final String contains) { this.contains = contains; return this; } - public TollFreeReader setSmsEnabled(final Boolean smsEnabled){ + + public TollFreeReader setSmsEnabled(final Boolean smsEnabled) { this.smsEnabled = smsEnabled; return this; } - public TollFreeReader setMmsEnabled(final Boolean mmsEnabled){ + + public TollFreeReader setMmsEnabled(final Boolean mmsEnabled) { this.mmsEnabled = mmsEnabled; return this; } - public TollFreeReader setVoiceEnabled(final Boolean voiceEnabled){ + + public TollFreeReader setVoiceEnabled(final Boolean voiceEnabled) { this.voiceEnabled = voiceEnabled; return this; } - public TollFreeReader setExcludeAllAddressRequired(final Boolean excludeAllAddressRequired){ + + public TollFreeReader setExcludeAllAddressRequired( + final Boolean excludeAllAddressRequired + ) { this.excludeAllAddressRequired = excludeAllAddressRequired; return this; } - public TollFreeReader setExcludeLocalAddressRequired(final Boolean excludeLocalAddressRequired){ + + public TollFreeReader setExcludeLocalAddressRequired( + final Boolean excludeLocalAddressRequired + ) { this.excludeLocalAddressRequired = excludeLocalAddressRequired; return this; } - public TollFreeReader setExcludeForeignAddressRequired(final Boolean excludeForeignAddressRequired){ + + public TollFreeReader setExcludeForeignAddressRequired( + final Boolean excludeForeignAddressRequired + ) { this.excludeForeignAddressRequired = excludeForeignAddressRequired; return this; } - public TollFreeReader setBeta(final Boolean beta){ + + public TollFreeReader setBeta(final Boolean beta) { this.beta = beta; return this; } - public TollFreeReader setNearNumber(final com.twilio.type.PhoneNumber nearNumber){ + + public TollFreeReader setNearNumber( + final com.twilio.type.PhoneNumber nearNumber + ) { this.nearNumber = nearNumber; return this; } - public TollFreeReader setNearNumber(final String nearNumber){ + public TollFreeReader setNearNumber(final String nearNumber) { return setNearNumber(Promoter.phoneNumberFromString(nearNumber)); } - public TollFreeReader setNearLatLong(final String nearLatLong){ + + public TollFreeReader setNearLatLong(final String nearLatLong) { this.nearLatLong = nearLatLong; return this; } - public TollFreeReader setDistance(final Integer distance){ + + public TollFreeReader setDistance(final Integer distance) { this.distance = distance; return this; } - public TollFreeReader setInPostalCode(final String inPostalCode){ + + public TollFreeReader setInPostalCode(final String inPostalCode) { this.inPostalCode = inPostalCode; return this; } - public TollFreeReader setInRegion(final String inRegion){ + + public TollFreeReader setInRegion(final String inRegion) { this.inRegion = inRegion; return this; } - public TollFreeReader setInRateCenter(final String inRateCenter){ + + public TollFreeReader setInRateCenter(final String inRateCenter) { this.inRateCenter = inRateCenter; return this; } - public TollFreeReader setInLata(final String inLata){ + + public TollFreeReader setInLata(final String inLata) { this.inLata = inLata; return this; } - public TollFreeReader setInLocality(final String inLocality){ + + public TollFreeReader setInLocality(final String inLocality) { this.inLocality = inLocality; return this; } - public TollFreeReader setFaxEnabled(final Boolean faxEnabled){ + + public TollFreeReader setFaxEnabled(final Boolean faxEnabled) { this.faxEnabled = faxEnabled; return this; } - public TollFreeReader setPageSize(final Integer pageSize){ + + public TollFreeReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -147,10 +176,22 @@ public ResourceSet read(final TwilioRestClient client) { } public Page firstPage(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/AvailablePhoneNumbers/{CountryCode}/TollFree.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"CountryCode"+"}", this.pathCountryCode.toString()); + String path = + "/2010-04-01/Accounts/{AccountSid}/AvailablePhoneNumbers/{CountryCode}/TollFree.json"; + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "CountryCode" + "}", + this.pathCountryCode.toString() + ); Request request = new Request( HttpMethod.GET, @@ -162,13 +203,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("TollFree read failed: Unable to connect to server"); + throw new ApiConnectionException( + "TollFree read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -184,7 +233,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reque } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.API.toString()) @@ -192,9 +244,11 @@ public Page previousPage(final Page page, final TwilioRestCl return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.API.toString()) @@ -203,93 +257,84 @@ public Page nextPage(final Page page, final TwilioRestClient } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (areaCode != null) { - request.addQueryParam("AreaCode", areaCode.toString()); } if (contains != null) { - request.addQueryParam("Contains", contains); } if (smsEnabled != null) { - request.addQueryParam("SmsEnabled", smsEnabled.toString()); } if (mmsEnabled != null) { - request.addQueryParam("MmsEnabled", mmsEnabled.toString()); } if (voiceEnabled != null) { - request.addQueryParam("VoiceEnabled", voiceEnabled.toString()); } if (excludeAllAddressRequired != null) { - - request.addQueryParam("ExcludeAllAddressRequired", excludeAllAddressRequired.toString()); + request.addQueryParam( + "ExcludeAllAddressRequired", + excludeAllAddressRequired.toString() + ); } if (excludeLocalAddressRequired != null) { - - request.addQueryParam("ExcludeLocalAddressRequired", excludeLocalAddressRequired.toString()); + request.addQueryParam( + "ExcludeLocalAddressRequired", + excludeLocalAddressRequired.toString() + ); } if (excludeForeignAddressRequired != null) { - - request.addQueryParam("ExcludeForeignAddressRequired", excludeForeignAddressRequired.toString()); + request.addQueryParam( + "ExcludeForeignAddressRequired", + excludeForeignAddressRequired.toString() + ); } if (beta != null) { - request.addQueryParam("Beta", beta.toString()); } if (nearNumber != null) { - request.addQueryParam("NearNumber", nearNumber.toString()); } if (nearLatLong != null) { - request.addQueryParam("NearLatLong", nearLatLong); } if (distance != null) { - request.addQueryParam("Distance", distance.toString()); } if (inPostalCode != null) { - request.addQueryParam("InPostalCode", inPostalCode); } if (inRegion != null) { - request.addQueryParam("InRegion", inRegion); } if (inRateCenter != null) { - request.addQueryParam("InRateCenter", inRateCenter); } if (inLata != null) { - request.addQueryParam("InLata", inLata); } if (inLocality != null) { - request.addQueryParam("InLocality", inLocality); } if (faxEnabled != null) { - request.addQueryParam("FaxEnabled", faxEnabled.toString()); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/Voip.java b/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/Voip.java index c8d02e8ad5..b7afdb186e 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/Voip.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/Voip.java @@ -22,40 +22,43 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - +import com.twilio.type.PhoneNumberCapabilities; import java.io.IOException; import java.io.InputStream; - -import java.util.Objects; - - import java.math.BigDecimal; -import com.twilio.type.PhoneNumberCapabilities; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Voip extends Resource { + private static final long serialVersionUID = 211749226408502L; - public static VoipReader reader(final String pathCountryCode){ + public static VoipReader reader(final String pathCountryCode) { return new VoipReader(pathCountryCode); } - public static VoipReader reader(final String pathAccountSid, final String pathCountryCode){ + + public static VoipReader reader( + final String pathAccountSid, + final String pathCountryCode + ) { return new VoipReader(pathAccountSid, pathCountryCode); } /** - * Converts a JSON String into a Voip object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Voip object represented by the provided JSON - */ - public static Voip fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Voip object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Voip object represented by the provided JSON + */ + public static Voip fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Voip.class); @@ -67,14 +70,17 @@ public static Voip fromJson(final String json, final ObjectMapper objectMapper) } /** - * Converts a JSON InputStream into a Voip object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Voip object represented by the provided JSON - */ - public static Voip fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Voip object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Voip object represented by the provided JSON + */ + public static Voip fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Voip.class); @@ -101,44 +107,23 @@ public static Voip fromJson(final InputStream json, final ObjectMapper objectMap @JsonCreator private Voip( - @JsonProperty("friendly_name") - final com.twilio.type.PhoneNumber friendlyName, - - @JsonProperty("phone_number") - final com.twilio.type.PhoneNumber phoneNumber, - - @JsonProperty("lata") - final String lata, - - @JsonProperty("locality") - final String locality, - - @JsonProperty("rate_center") - final String rateCenter, - - @JsonProperty("latitude") - final BigDecimal latitude, - - @JsonProperty("longitude") - final BigDecimal longitude, - - @JsonProperty("region") - final String region, - - @JsonProperty("postal_code") - final String postalCode, - - @JsonProperty("iso_country") - final String isoCountry, - - @JsonProperty("address_requirements") - final String addressRequirements, - - @JsonProperty("beta") - final Boolean beta, - - @JsonProperty("capabilities") - final PhoneNumberCapabilities capabilities + @JsonProperty( + "friendly_name" + ) final com.twilio.type.PhoneNumber friendlyName, + @JsonProperty( + "phone_number" + ) final com.twilio.type.PhoneNumber phoneNumber, + @JsonProperty("lata") final String lata, + @JsonProperty("locality") final String locality, + @JsonProperty("rate_center") final String rateCenter, + @JsonProperty("latitude") final BigDecimal latitude, + @JsonProperty("longitude") final BigDecimal longitude, + @JsonProperty("region") final String region, + @JsonProperty("postal_code") final String postalCode, + @JsonProperty("iso_country") final String isoCountry, + @JsonProperty("address_requirements") final String addressRequirements, + @JsonProperty("beta") final Boolean beta, + @JsonProperty("capabilities") final PhoneNumberCapabilities capabilities ) { this.friendlyName = friendlyName; this.phoneNumber = phoneNumber; @@ -155,49 +140,61 @@ private Voip( this.capabilities = capabilities; } - public final com.twilio.type.PhoneNumber getFriendlyName() { - return this.friendlyName; - } - public final com.twilio.type.PhoneNumber getPhoneNumber() { - return this.phoneNumber; - } - public final String getLata() { - return this.lata; - } - public final String getLocality() { - return this.locality; - } - public final String getRateCenter() { - return this.rateCenter; - } - public final BigDecimal getLatitude() { - return this.latitude; - } - public final BigDecimal getLongitude() { - return this.longitude; - } - public final String getRegion() { - return this.region; - } - public final String getPostalCode() { - return this.postalCode; - } - public final String getIsoCountry() { - return this.isoCountry; - } - public final String getAddressRequirements() { - return this.addressRequirements; - } - public final Boolean getBeta() { - return this.beta; - } - public final PhoneNumberCapabilities getCapabilities() { - return this.capabilities; - } + public final com.twilio.type.PhoneNumber getFriendlyName() { + return this.friendlyName; + } + + public final com.twilio.type.PhoneNumber getPhoneNumber() { + return this.phoneNumber; + } + + public final String getLata() { + return this.lata; + } + + public final String getLocality() { + return this.locality; + } + + public final String getRateCenter() { + return this.rateCenter; + } + + public final BigDecimal getLatitude() { + return this.latitude; + } + + public final BigDecimal getLongitude() { + return this.longitude; + } + + public final String getRegion() { + return this.region; + } + + public final String getPostalCode() { + return this.postalCode; + } + + public final String getIsoCountry() { + return this.isoCountry; + } + + public final String getAddressRequirements() { + return this.addressRequirements; + } + + public final Boolean getBeta() { + return this.beta; + } + + public final PhoneNumberCapabilities getCapabilities() { + return this.capabilities; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -207,13 +204,39 @@ public boolean equals(final Object o) { Voip other = (Voip) o; - return Objects.equals(friendlyName, other.friendlyName) && Objects.equals(phoneNumber, other.phoneNumber) && Objects.equals(lata, other.lata) && Objects.equals(locality, other.locality) && Objects.equals(rateCenter, other.rateCenter) && Objects.equals(latitude, other.latitude) && Objects.equals(longitude, other.longitude) && Objects.equals(region, other.region) && Objects.equals(postalCode, other.postalCode) && Objects.equals(isoCountry, other.isoCountry) && Objects.equals(addressRequirements, other.addressRequirements) && Objects.equals(beta, other.beta) && Objects.equals(capabilities, other.capabilities) ; + return ( + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(phoneNumber, other.phoneNumber) && + Objects.equals(lata, other.lata) && + Objects.equals(locality, other.locality) && + Objects.equals(rateCenter, other.rateCenter) && + Objects.equals(latitude, other.latitude) && + Objects.equals(longitude, other.longitude) && + Objects.equals(region, other.region) && + Objects.equals(postalCode, other.postalCode) && + Objects.equals(isoCountry, other.isoCountry) && + Objects.equals(addressRequirements, other.addressRequirements) && + Objects.equals(beta, other.beta) && + Objects.equals(capabilities, other.capabilities) + ); } @Override public int hashCode() { - return Objects.hash(friendlyName, phoneNumber, lata, locality, rateCenter, latitude, longitude, region, postalCode, isoCountry, addressRequirements, beta, capabilities); + return Objects.hash( + friendlyName, + phoneNumber, + lata, + locality, + rateCenter, + latitude, + longitude, + region, + postalCode, + isoCountry, + addressRequirements, + beta, + capabilities + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/VoipReader.java b/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/VoipReader.java index ff0c1307c0..0dd48d245a 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/VoipReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/VoipReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.api.v2010.account.availablephonenumbercountry; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.converter.Promoter; @@ -25,11 +26,9 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class VoipReader extends Reader { + private String pathCountryCode; private String pathAccountSid; private Integer areaCode; @@ -52,91 +51,121 @@ public class VoipReader extends Reader { private Boolean faxEnabled; private Integer pageSize; - public VoipReader(final String pathCountryCode){ + public VoipReader(final String pathCountryCode) { this.pathCountryCode = pathCountryCode; } - public VoipReader(final String pathAccountSid, final String pathCountryCode){ + + public VoipReader( + final String pathAccountSid, + final String pathCountryCode + ) { this.pathAccountSid = pathAccountSid; this.pathCountryCode = pathCountryCode; } - public VoipReader setAreaCode(final Integer areaCode){ + public VoipReader setAreaCode(final Integer areaCode) { this.areaCode = areaCode; return this; } - public VoipReader setContains(final String contains){ + + public VoipReader setContains(final String contains) { this.contains = contains; return this; } - public VoipReader setSmsEnabled(final Boolean smsEnabled){ + + public VoipReader setSmsEnabled(final Boolean smsEnabled) { this.smsEnabled = smsEnabled; return this; } - public VoipReader setMmsEnabled(final Boolean mmsEnabled){ + + public VoipReader setMmsEnabled(final Boolean mmsEnabled) { this.mmsEnabled = mmsEnabled; return this; } - public VoipReader setVoiceEnabled(final Boolean voiceEnabled){ + + public VoipReader setVoiceEnabled(final Boolean voiceEnabled) { this.voiceEnabled = voiceEnabled; return this; } - public VoipReader setExcludeAllAddressRequired(final Boolean excludeAllAddressRequired){ + + public VoipReader setExcludeAllAddressRequired( + final Boolean excludeAllAddressRequired + ) { this.excludeAllAddressRequired = excludeAllAddressRequired; return this; } - public VoipReader setExcludeLocalAddressRequired(final Boolean excludeLocalAddressRequired){ + + public VoipReader setExcludeLocalAddressRequired( + final Boolean excludeLocalAddressRequired + ) { this.excludeLocalAddressRequired = excludeLocalAddressRequired; return this; } - public VoipReader setExcludeForeignAddressRequired(final Boolean excludeForeignAddressRequired){ + + public VoipReader setExcludeForeignAddressRequired( + final Boolean excludeForeignAddressRequired + ) { this.excludeForeignAddressRequired = excludeForeignAddressRequired; return this; } - public VoipReader setBeta(final Boolean beta){ + + public VoipReader setBeta(final Boolean beta) { this.beta = beta; return this; } - public VoipReader setNearNumber(final com.twilio.type.PhoneNumber nearNumber){ + + public VoipReader setNearNumber( + final com.twilio.type.PhoneNumber nearNumber + ) { this.nearNumber = nearNumber; return this; } - public VoipReader setNearNumber(final String nearNumber){ + public VoipReader setNearNumber(final String nearNumber) { return setNearNumber(Promoter.phoneNumberFromString(nearNumber)); } - public VoipReader setNearLatLong(final String nearLatLong){ + + public VoipReader setNearLatLong(final String nearLatLong) { this.nearLatLong = nearLatLong; return this; } - public VoipReader setDistance(final Integer distance){ + + public VoipReader setDistance(final Integer distance) { this.distance = distance; return this; } - public VoipReader setInPostalCode(final String inPostalCode){ + + public VoipReader setInPostalCode(final String inPostalCode) { this.inPostalCode = inPostalCode; return this; } - public VoipReader setInRegion(final String inRegion){ + + public VoipReader setInRegion(final String inRegion) { this.inRegion = inRegion; return this; } - public VoipReader setInRateCenter(final String inRateCenter){ + + public VoipReader setInRateCenter(final String inRateCenter) { this.inRateCenter = inRateCenter; return this; } - public VoipReader setInLata(final String inLata){ + + public VoipReader setInLata(final String inLata) { this.inLata = inLata; return this; } - public VoipReader setInLocality(final String inLocality){ + + public VoipReader setInLocality(final String inLocality) { this.inLocality = inLocality; return this; } - public VoipReader setFaxEnabled(final Boolean faxEnabled){ + + public VoipReader setFaxEnabled(final Boolean faxEnabled) { this.faxEnabled = faxEnabled; return this; } - public VoipReader setPageSize(final Integer pageSize){ + + public VoipReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -147,10 +176,22 @@ public ResourceSet read(final TwilioRestClient client) { } public Page firstPage(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/AvailablePhoneNumbers/{CountryCode}/Voip.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"CountryCode"+"}", this.pathCountryCode.toString()); + String path = + "/2010-04-01/Accounts/{AccountSid}/AvailablePhoneNumbers/{CountryCode}/Voip.json"; + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "CountryCode" + "}", + this.pathCountryCode.toString() + ); Request request = new Request( HttpMethod.GET, @@ -162,13 +203,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Voip read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Voip read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -184,7 +233,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request r } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.API.toString()) @@ -192,9 +244,11 @@ public Page previousPage(final Page page, final TwilioRestClient cli return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.API.toString()) @@ -203,93 +257,84 @@ public Page nextPage(final Page page, final TwilioRestClient client) } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (areaCode != null) { - request.addQueryParam("AreaCode", areaCode.toString()); } if (contains != null) { - request.addQueryParam("Contains", contains); } if (smsEnabled != null) { - request.addQueryParam("SmsEnabled", smsEnabled.toString()); } if (mmsEnabled != null) { - request.addQueryParam("MmsEnabled", mmsEnabled.toString()); } if (voiceEnabled != null) { - request.addQueryParam("VoiceEnabled", voiceEnabled.toString()); } if (excludeAllAddressRequired != null) { - - request.addQueryParam("ExcludeAllAddressRequired", excludeAllAddressRequired.toString()); + request.addQueryParam( + "ExcludeAllAddressRequired", + excludeAllAddressRequired.toString() + ); } if (excludeLocalAddressRequired != null) { - - request.addQueryParam("ExcludeLocalAddressRequired", excludeLocalAddressRequired.toString()); + request.addQueryParam( + "ExcludeLocalAddressRequired", + excludeLocalAddressRequired.toString() + ); } if (excludeForeignAddressRequired != null) { - - request.addQueryParam("ExcludeForeignAddressRequired", excludeForeignAddressRequired.toString()); + request.addQueryParam( + "ExcludeForeignAddressRequired", + excludeForeignAddressRequired.toString() + ); } if (beta != null) { - request.addQueryParam("Beta", beta.toString()); } if (nearNumber != null) { - request.addQueryParam("NearNumber", nearNumber.toString()); } if (nearLatLong != null) { - request.addQueryParam("NearLatLong", nearLatLong); } if (distance != null) { - request.addQueryParam("Distance", distance.toString()); } if (inPostalCode != null) { - request.addQueryParam("InPostalCode", inPostalCode); } if (inRegion != null) { - request.addQueryParam("InRegion", inRegion); } if (inRateCenter != null) { - request.addQueryParam("InRateCenter", inRateCenter); } if (inLata != null) { - request.addQueryParam("InLata", inLata); } if (inLocality != null) { - request.addQueryParam("InLocality", inLocality); } if (faxEnabled != null) { - request.addQueryParam("FaxEnabled", faxEnabled.toString()); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/Event.java b/src/main/java/com/twilio/rest/api/v2010/account/call/Event.java index 03e8f55c00..cffe7272a7 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/call/Event.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/call/Event.java @@ -22,40 +22,43 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Event extends Resource { + private static final long serialVersionUID = 87960678380335L; - public static EventReader reader(final String pathCallSid){ + public static EventReader reader(final String pathCallSid) { return new EventReader(pathCallSid); } - public static EventReader reader(final String pathAccountSid, final String pathCallSid){ + + public static EventReader reader( + final String pathAccountSid, + final String pathCallSid + ) { return new EventReader(pathAccountSid, pathCallSid); } /** - * Converts a JSON String into a Event object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Event object represented by the provided JSON - */ - public static Event fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Event object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Event object represented by the provided JSON + */ + public static Event fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Event.class); @@ -67,14 +70,17 @@ public static Event fromJson(final String json, final ObjectMapper objectMapper) } /** - * Converts a JSON InputStream into a Event object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Event object represented by the provided JSON - */ - public static Event fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Event object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Event object represented by the provided JSON + */ + public static Event fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Event.class); @@ -90,26 +96,24 @@ public static Event fromJson(final InputStream json, final ObjectMapper objectMa @JsonCreator private Event( - @JsonProperty("request") - final Map request, - - @JsonProperty("response") - final Map response + @JsonProperty("request") final Map request, + @JsonProperty("response") final Map response ) { this.request = request; this.response = response; } - public final Map getRequest() { - return this.request; - } - public final Map getResponse() { - return this.response; - } + public final Map getRequest() { + return this.request; + } + + public final Map getResponse() { + return this.response; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -119,13 +123,14 @@ public boolean equals(final Object o) { Event other = (Event) o; - return Objects.equals(request, other.request) && Objects.equals(response, other.response) ; + return ( + Objects.equals(request, other.request) && + Objects.equals(response, other.response) + ); } @Override public int hashCode() { return Objects.hash(request, response); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/EventReader.java b/src/main/java/com/twilio/rest/api/v2010/account/call/EventReader.java index 9f83c70799..4fcaeebc37 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/call/EventReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/call/EventReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.api.v2010.account.call; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,24 +25,23 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class EventReader extends Reader { + private String pathCallSid; private String pathAccountSid; private Integer pageSize; - public EventReader(final String pathCallSid){ + public EventReader(final String pathCallSid) { this.pathCallSid = pathCallSid; } - public EventReader(final String pathAccountSid, final String pathCallSid){ + + public EventReader(final String pathAccountSid, final String pathCallSid) { this.pathAccountSid = pathAccountSid; this.pathCallSid = pathCallSid; } - public EventReader setPageSize(final Integer pageSize){ + public EventReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -52,10 +52,18 @@ public ResourceSet read(final TwilioRestClient client) { } public Page firstPage(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Events.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"CallSid"+"}", this.pathCallSid.toString()); + String path = + "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Events.json"; + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "CallSid" + "}", this.pathCallSid.toString()); Request request = new Request( HttpMethod.GET, @@ -67,13 +75,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Event read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Event read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -89,7 +105,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.API.toString()) @@ -97,9 +116,11 @@ public Page previousPage(final Page page, final TwilioRestClient c return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.API.toString()) @@ -108,21 +129,21 @@ public Page nextPage(final Page page, final TwilioRestClient clien } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/Feedback.java b/src/main/java/com/twilio/rest/api/v2010/account/call/Feedback.java index 0b69bfa521..9679064b26 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/call/Feedback.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/call/Feedback.java @@ -24,47 +24,54 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.time.ZonedDateTime; - import java.util.List; import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Feedback extends Resource { + private static final long serialVersionUID = 111537913828934L; - public static FeedbackFetcher fetcher(final String pathCallSid){ + public static FeedbackFetcher fetcher(final String pathCallSid) { return new FeedbackFetcher(pathCallSid); } - public static FeedbackFetcher fetcher(final String pathAccountSid, final String pathCallSid){ + + public static FeedbackFetcher fetcher( + final String pathAccountSid, + final String pathCallSid + ) { return new FeedbackFetcher(pathAccountSid, pathCallSid); } - public static FeedbackUpdater updater(final String pathCallSid){ + public static FeedbackUpdater updater(final String pathCallSid) { return new FeedbackUpdater(pathCallSid); } - public static FeedbackUpdater updater(final String pathAccountSid, final String pathCallSid){ + + public static FeedbackUpdater updater( + final String pathAccountSid, + final String pathCallSid + ) { return new FeedbackUpdater(pathAccountSid, pathCallSid); } /** - * Converts a JSON String into a Feedback object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Feedback object represented by the provided JSON - */ - public static Feedback fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Feedback object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Feedback object represented by the provided JSON + */ + public static Feedback fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Feedback.class); @@ -76,14 +83,17 @@ public static Feedback fromJson(final String json, final ObjectMapper objectMapp } /** - * Converts a JSON InputStream into a Feedback object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Feedback object represented by the provided JSON - */ - public static Feedback fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Feedback object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Feedback object represented by the provided JSON + */ + public static Feedback fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Feedback.class); @@ -93,6 +103,7 @@ public static Feedback fromJson(final InputStream json, final ObjectMapper objec throw new ApiConnectionException(e.getMessage(), e); } } + public enum Issues { AUDIO_LATENCY("audio-latency"), DIGITS_NOT_CAPTURED("digits-not-captured"), @@ -128,23 +139,12 @@ public static Issues forValue(final String value) { @JsonCreator private Feedback( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("issues") - final List issues, - - @JsonProperty("quality_score") - final Integer qualityScore, - - @JsonProperty("sid") - final String sid + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("issues") final List issues, + @JsonProperty("quality_score") final Integer qualityScore, + @JsonProperty("sid") final String sid ) { this.accountSid = accountSid; this.dateCreated = DateConverter.rfc2822DateTimeFromString(dateCreated); @@ -154,28 +154,33 @@ private Feedback( this.sid = sid; } - public final String getAccountSid() { - return this.accountSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final List getIssues() { - return this.issues; - } - public final Integer getQualityScore() { - return this.qualityScore; - } - public final String getSid() { - return this.sid; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final List getIssues() { + return this.issues; + } + + public final Integer getQualityScore() { + return this.qualityScore; + } + + public final String getSid() { + return this.sid; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -185,13 +190,25 @@ public boolean equals(final Object o) { Feedback other = (Feedback) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(issues, other.issues) && Objects.equals(qualityScore, other.qualityScore) && Objects.equals(sid, other.sid) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(issues, other.issues) && + Objects.equals(qualityScore, other.qualityScore) && + Objects.equals(sid, other.sid) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, dateCreated, dateUpdated, issues, qualityScore, sid); + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + issues, + qualityScore, + sid + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/FeedbackFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/call/FeedbackFetcher.java index 6528c1dc4b..d96cbe1f19 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/call/FeedbackFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/call/FeedbackFetcher.java @@ -24,29 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class FeedbackFetcher extends Fetcher { + private String pathCallSid; private String pathAccountSid; - public FeedbackFetcher(final String pathCallSid){ + public FeedbackFetcher(final String pathCallSid) { this.pathCallSid = pathCallSid; } - public FeedbackFetcher(final String pathAccountSid, final String pathCallSid){ + + public FeedbackFetcher( + final String pathAccountSid, + final String pathCallSid + ) { this.pathAccountSid = pathAccountSid; this.pathCallSid = pathCallSid; } - @Override public Feedback fetch(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Feedback.json"; + String path = + "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Feedback.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"CallSid"+"}", this.pathCallSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "CallSid" + "}", this.pathCallSid.toString()); Request request = new Request( HttpMethod.GET, @@ -56,15 +65,23 @@ public Feedback fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Feedback fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Feedback fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Feedback.fromJson(response.getStream(), client.getObjectMapper()); + return Feedback.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/FeedbackSummary.java b/src/main/java/com/twilio/rest/api/v2010/account/call/FeedbackSummary.java index 95964b0b72..4b26edf473 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/call/FeedbackSummary.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/call/FeedbackSummary.java @@ -24,58 +24,73 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; +import java.math.BigDecimal; +import java.time.LocalDate; import java.time.ZonedDateTime; - import java.util.List; import java.util.Map; -import java.util.Objects; - - import java.util.Map; -import java.time.LocalDate; -import java.math.BigDecimal; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class FeedbackSummary extends Resource { + private static final long serialVersionUID = 230453795109955L; - public static FeedbackSummaryCreator creator(final LocalDate startDate, final LocalDate endDate){ + public static FeedbackSummaryCreator creator( + final LocalDate startDate, + final LocalDate endDate + ) { return new FeedbackSummaryCreator(startDate, endDate); } - public static FeedbackSummaryCreator creator(final String pathAccountSid, final LocalDate startDate, final LocalDate endDate){ + + public static FeedbackSummaryCreator creator( + final String pathAccountSid, + final LocalDate startDate, + final LocalDate endDate + ) { return new FeedbackSummaryCreator(pathAccountSid, startDate, endDate); } - public static FeedbackSummaryDeleter deleter(final String pathSid){ + public static FeedbackSummaryDeleter deleter(final String pathSid) { return new FeedbackSummaryDeleter(pathSid); } - public static FeedbackSummaryDeleter deleter(final String pathAccountSid, final String pathSid){ + + public static FeedbackSummaryDeleter deleter( + final String pathAccountSid, + final String pathSid + ) { return new FeedbackSummaryDeleter(pathAccountSid, pathSid); } - public static FeedbackSummaryFetcher fetcher(final String pathSid){ + public static FeedbackSummaryFetcher fetcher(final String pathSid) { return new FeedbackSummaryFetcher(pathSid); } - public static FeedbackSummaryFetcher fetcher(final String pathAccountSid, final String pathSid){ + + public static FeedbackSummaryFetcher fetcher( + final String pathAccountSid, + final String pathSid + ) { return new FeedbackSummaryFetcher(pathAccountSid, pathSid); } /** - * Converts a JSON String into a FeedbackSummary object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return FeedbackSummary object represented by the provided JSON - */ - public static FeedbackSummary fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a FeedbackSummary object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return FeedbackSummary object represented by the provided JSON + */ + public static FeedbackSummary fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, FeedbackSummary.class); @@ -87,14 +102,17 @@ public static FeedbackSummary fromJson(final String json, final ObjectMapper obj } /** - * Converts a JSON InputStream into a FeedbackSummary object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return FeedbackSummary object represented by the provided JSON - */ - public static FeedbackSummary fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a FeedbackSummary object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return FeedbackSummary object represented by the provided JSON + */ + public static FeedbackSummary fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, FeedbackSummary.class); @@ -104,6 +122,7 @@ public static FeedbackSummary fromJson(final InputStream json, final ObjectMappe throw new ApiConnectionException(e.getMessage(), e); } } + public enum Status { QUEUED("queued"), IN_PROGRESS("in-progress"), @@ -143,47 +162,26 @@ public static Status forValue(final String value) { @JsonCreator private FeedbackSummary( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("call_count") - final Integer callCount, - - @JsonProperty("call_feedback_count") - final Integer callFeedbackCount, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("end_date") - final String endDate, - - @JsonProperty("include_subaccounts") - final Boolean includeSubaccounts, - - @JsonProperty("issues") - final List> issues, - - @JsonProperty("quality_score_average") - final BigDecimal qualityScoreAverage, - - @JsonProperty("quality_score_median") - final BigDecimal qualityScoreMedian, - - @JsonProperty("quality_score_standard_deviation") - final BigDecimal qualityScoreStandardDeviation, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("start_date") - final String startDate, - - @JsonProperty("status") - final FeedbackSummary.Status status + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("call_count") final Integer callCount, + @JsonProperty("call_feedback_count") final Integer callFeedbackCount, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("end_date") final String endDate, + @JsonProperty("include_subaccounts") final Boolean includeSubaccounts, + @JsonProperty("issues") final List> issues, + @JsonProperty( + "quality_score_average" + ) final BigDecimal qualityScoreAverage, + @JsonProperty( + "quality_score_median" + ) final BigDecimal qualityScoreMedian, + @JsonProperty( + "quality_score_standard_deviation" + ) final BigDecimal qualityScoreStandardDeviation, + @JsonProperty("sid") final String sid, + @JsonProperty("start_date") final String startDate, + @JsonProperty("status") final FeedbackSummary.Status status ) { this.accountSid = accountSid; this.callCount = callCount; @@ -201,52 +199,65 @@ private FeedbackSummary( this.status = status; } - public final String getAccountSid() { - return this.accountSid; - } - public final Integer getCallCount() { - return this.callCount; - } - public final Integer getCallFeedbackCount() { - return this.callFeedbackCount; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final LocalDate getEndDate() { - return this.endDate; - } - public final Boolean getIncludeSubaccounts() { - return this.includeSubaccounts; - } - public final List> getIssues() { - return this.issues; - } - public final BigDecimal getQualityScoreAverage() { - return this.qualityScoreAverage; - } - public final BigDecimal getQualityScoreMedian() { - return this.qualityScoreMedian; - } - public final BigDecimal getQualityScoreStandardDeviation() { - return this.qualityScoreStandardDeviation; - } - public final String getSid() { - return this.sid; - } - public final LocalDate getStartDate() { - return this.startDate; - } - public final FeedbackSummary.Status getStatus() { - return this.status; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final Integer getCallCount() { + return this.callCount; + } + + public final Integer getCallFeedbackCount() { + return this.callFeedbackCount; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final LocalDate getEndDate() { + return this.endDate; + } + + public final Boolean getIncludeSubaccounts() { + return this.includeSubaccounts; + } + + public final List> getIssues() { + return this.issues; + } + + public final BigDecimal getQualityScoreAverage() { + return this.qualityScoreAverage; + } + + public final BigDecimal getQualityScoreMedian() { + return this.qualityScoreMedian; + } + + public final BigDecimal getQualityScoreStandardDeviation() { + return this.qualityScoreStandardDeviation; + } + + public final String getSid() { + return this.sid; + } + + public final LocalDate getStartDate() { + return this.startDate; + } + + public final FeedbackSummary.Status getStatus() { + return this.status; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -256,13 +267,44 @@ public boolean equals(final Object o) { FeedbackSummary other = (FeedbackSummary) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(callCount, other.callCount) && Objects.equals(callFeedbackCount, other.callFeedbackCount) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(endDate, other.endDate) && Objects.equals(includeSubaccounts, other.includeSubaccounts) && Objects.equals(issues, other.issues) && Objects.equals(qualityScoreAverage, other.qualityScoreAverage) && Objects.equals(qualityScoreMedian, other.qualityScoreMedian) && Objects.equals(qualityScoreStandardDeviation, other.qualityScoreStandardDeviation) && Objects.equals(sid, other.sid) && Objects.equals(startDate, other.startDate) && Objects.equals(status, other.status) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(callCount, other.callCount) && + Objects.equals(callFeedbackCount, other.callFeedbackCount) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(endDate, other.endDate) && + Objects.equals(includeSubaccounts, other.includeSubaccounts) && + Objects.equals(issues, other.issues) && + Objects.equals(qualityScoreAverage, other.qualityScoreAverage) && + Objects.equals(qualityScoreMedian, other.qualityScoreMedian) && + Objects.equals( + qualityScoreStandardDeviation, + other.qualityScoreStandardDeviation + ) && + Objects.equals(sid, other.sid) && + Objects.equals(startDate, other.startDate) && + Objects.equals(status, other.status) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, callCount, callFeedbackCount, dateCreated, dateUpdated, endDate, includeSubaccounts, issues, qualityScoreAverage, qualityScoreMedian, qualityScoreStandardDeviation, sid, startDate, status); + return Objects.hash( + accountSid, + callCount, + callFeedbackCount, + dateCreated, + dateUpdated, + endDate, + includeSubaccounts, + issues, + qualityScoreAverage, + qualityScoreMedian, + qualityScoreStandardDeviation, + sid, + startDate, + status + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/FeedbackSummaryCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/call/FeedbackSummaryCreator.java index 698c63747e..386e46b1ef 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/call/FeedbackSummaryCreator.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/call/FeedbackSummaryCreator.java @@ -15,6 +15,8 @@ package com.twilio.rest.api.v2010.account.call; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; +import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -24,15 +26,12 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import java.time.LocalDate; import java.net.URI; -import com.twilio.converter.DateConverter; - - - import java.net.URI; +import java.time.LocalDate; + +public class FeedbackSummaryCreator extends Creator { -public class FeedbackSummaryCreator extends Creator{ private LocalDate startDate; private LocalDate endDate; private String pathAccountSid; @@ -40,89 +39,132 @@ public class FeedbackSummaryCreator extends Creator{ private URI statusCallback; private HttpMethod statusCallbackMethod; - public FeedbackSummaryCreator(final LocalDate startDate, final LocalDate endDate) { + public FeedbackSummaryCreator( + final LocalDate startDate, + final LocalDate endDate + ) { this.startDate = startDate; this.endDate = endDate; } - public FeedbackSummaryCreator(final String pathAccountSid, final LocalDate startDate, final LocalDate endDate) { + + public FeedbackSummaryCreator( + final String pathAccountSid, + final LocalDate startDate, + final LocalDate endDate + ) { this.pathAccountSid = pathAccountSid; this.startDate = startDate; this.endDate = endDate; } - public FeedbackSummaryCreator setStartDate(final LocalDate startDate){ + public FeedbackSummaryCreator setStartDate(final LocalDate startDate) { this.startDate = startDate; return this; } - public FeedbackSummaryCreator setEndDate(final LocalDate endDate){ + + public FeedbackSummaryCreator setEndDate(final LocalDate endDate) { this.endDate = endDate; return this; } - public FeedbackSummaryCreator setIncludeSubaccounts(final Boolean includeSubaccounts){ + + public FeedbackSummaryCreator setIncludeSubaccounts( + final Boolean includeSubaccounts + ) { this.includeSubaccounts = includeSubaccounts; return this; } - public FeedbackSummaryCreator setStatusCallback(final URI statusCallback){ + + public FeedbackSummaryCreator setStatusCallback(final URI statusCallback) { this.statusCallback = statusCallback; return this; } - public FeedbackSummaryCreator setStatusCallback(final String statusCallback){ + public FeedbackSummaryCreator setStatusCallback( + final String statusCallback + ) { return setStatusCallback(Promoter.uriFromString(statusCallback)); } - public FeedbackSummaryCreator setStatusCallbackMethod(final HttpMethod statusCallbackMethod){ + + public FeedbackSummaryCreator setStatusCallbackMethod( + final HttpMethod statusCallbackMethod + ) { this.statusCallbackMethod = statusCallbackMethod; return this; } @Override - public FeedbackSummary create(final TwilioRestClient client){ - String path = "/2010-04-01/Accounts/{AccountSid}/Calls/FeedbackSummary.json"; + public FeedbackSummary create(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Calls/FeedbackSummary.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"StartDate"+"}", this.startDate.toString()); - path = path.replace("{"+"EndDate"+"}", this.endDate.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "StartDate" + "}", this.startDate.toString()); + path = path.replace("{" + "EndDate" + "}", this.endDate.toString()); Request request = new Request( HttpMethod.POST, Domains.API.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("FeedbackSummary creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "FeedbackSummary creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return FeedbackSummary.fromJson(response.getStream(), client.getObjectMapper()); + return FeedbackSummary.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (startDate != null) { - request.addPostParam("StartDate", DateConverter.dateStringFromLocalDate(startDate)); - + request.addPostParam( + "StartDate", + DateConverter.dateStringFromLocalDate(startDate) + ); } if (endDate != null) { - request.addPostParam("EndDate", DateConverter.dateStringFromLocalDate(endDate)); - + request.addPostParam( + "EndDate", + DateConverter.dateStringFromLocalDate(endDate) + ); } if (includeSubaccounts != null) { - request.addPostParam("IncludeSubaccounts", includeSubaccounts.toString()); - + request.addPostParam( + "IncludeSubaccounts", + includeSubaccounts.toString() + ); } if (statusCallback != null) { request.addPostParam("StatusCallback", statusCallback.toString()); - } if (statusCallbackMethod != null) { - request.addPostParam("StatusCallbackMethod", statusCallbackMethod.toString()); - + request.addPostParam( + "StatusCallbackMethod", + statusCallbackMethod.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/FeedbackSummaryDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/call/FeedbackSummaryDeleter.java index 7f9de30d93..008f4d7227 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/call/FeedbackSummaryDeleter.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/call/FeedbackSummaryDeleter.java @@ -24,28 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class FeedbackSummaryDeleter extends Deleter { + private String pathSid; private String pathAccountSid; - public FeedbackSummaryDeleter(final String pathSid){ + public FeedbackSummaryDeleter(final String pathSid) { this.pathSid = pathSid; } - public FeedbackSummaryDeleter(final String pathAccountSid, final String pathSid){ + + public FeedbackSummaryDeleter( + final String pathAccountSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/Calls/FeedbackSummary/{Sid}.json"; + String path = + "/2010-04-01/Accounts/{AccountSid}/Calls/FeedbackSummary/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -55,9 +65,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("FeedbackSummary delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "FeedbackSummary delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/FeedbackSummaryFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/call/FeedbackSummaryFetcher.java index de0536e067..3a379fd2ea 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/call/FeedbackSummaryFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/call/FeedbackSummaryFetcher.java @@ -24,29 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class FeedbackSummaryFetcher extends Fetcher { + private String pathSid; private String pathAccountSid; - public FeedbackSummaryFetcher(final String pathSid){ + public FeedbackSummaryFetcher(final String pathSid) { this.pathSid = pathSid; } - public FeedbackSummaryFetcher(final String pathAccountSid, final String pathSid){ + + public FeedbackSummaryFetcher( + final String pathAccountSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - @Override public FeedbackSummary fetch(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/Calls/FeedbackSummary/{Sid}.json"; + String path = + "/2010-04-01/Accounts/{AccountSid}/Calls/FeedbackSummary/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -56,15 +65,23 @@ public FeedbackSummary fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("FeedbackSummary fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "FeedbackSummary fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return FeedbackSummary.fromJson(response.getStream(), client.getObjectMapper()); + return FeedbackSummary.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/FeedbackUpdater.java b/src/main/java/com/twilio/rest/api/v2010/account/call/FeedbackUpdater.java index 249dc8a61b..d1d83cc9b2 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/call/FeedbackUpdater.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/call/FeedbackUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010.account.call; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -24,74 +25,94 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - import java.util.List; +public class FeedbackUpdater extends Updater { -public class FeedbackUpdater extends Updater{ private String pathCallSid; private String pathAccountSid; private Integer qualityScore; private List issue; - public FeedbackUpdater(final String pathCallSid){ + public FeedbackUpdater(final String pathCallSid) { this.pathCallSid = pathCallSid; } - public FeedbackUpdater(final String pathAccountSid, final String pathCallSid){ + + public FeedbackUpdater( + final String pathAccountSid, + final String pathCallSid + ) { this.pathAccountSid = pathAccountSid; this.pathCallSid = pathCallSid; } - public FeedbackUpdater setQualityScore(final Integer qualityScore){ + public FeedbackUpdater setQualityScore(final Integer qualityScore) { this.qualityScore = qualityScore; return this; } - public FeedbackUpdater setIssue(final List issue){ + + public FeedbackUpdater setIssue(final List issue) { this.issue = issue; return this; } - public FeedbackUpdater setIssue(final Feedback.Issues issue){ + + public FeedbackUpdater setIssue(final Feedback.Issues issue) { return setIssue(Promoter.listOfOne(issue)); } @Override - public Feedback update(final TwilioRestClient client){ - String path = "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Feedback.json"; + public Feedback update(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Feedback.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"CallSid"+"}", this.pathCallSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "CallSid" + "}", this.pathCallSid.toString()); Request request = new Request( HttpMethod.POST, Domains.API.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Feedback update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Feedback update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Feedback.fromJson(response.getStream(), client.getObjectMapper()); + return Feedback.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (qualityScore != null) { request.addPostParam("QualityScore", qualityScore.toString()); - } if (issue != null) { for (Feedback.Issues prop : issue) { request.addPostParam("Issue", prop.toString()); } - } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/Notification.java b/src/main/java/com/twilio/rest/api/v2010/account/call/Notification.java index f417915f27..f597752c87 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/call/Notification.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/call/Notification.java @@ -23,48 +23,59 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; import com.twilio.http.HttpMethod; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Notification extends Resource { + private static final long serialVersionUID = 162458167875227L; - public static NotificationFetcher fetcher(final String pathCallSid, final String pathSid){ + public static NotificationFetcher fetcher( + final String pathCallSid, + final String pathSid + ) { return new NotificationFetcher(pathCallSid, pathSid); } - public static NotificationFetcher fetcher(final String pathAccountSid, final String pathCallSid, final String pathSid){ + + public static NotificationFetcher fetcher( + final String pathAccountSid, + final String pathCallSid, + final String pathSid + ) { return new NotificationFetcher(pathAccountSid, pathCallSid, pathSid); } - public static NotificationReader reader(final String pathCallSid){ + public static NotificationReader reader(final String pathCallSid) { return new NotificationReader(pathCallSid); } - public static NotificationReader reader(final String pathAccountSid, final String pathCallSid){ + + public static NotificationReader reader( + final String pathAccountSid, + final String pathCallSid + ) { return new NotificationReader(pathAccountSid, pathCallSid); } /** - * Converts a JSON String into a Notification object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Notification object represented by the provided JSON - */ - public static Notification fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Notification object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Notification object represented by the provided JSON + */ + public static Notification fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Notification.class); @@ -76,14 +87,17 @@ public static Notification fromJson(final String json, final ObjectMapper object } /** - * Converts a JSON InputStream into a Notification object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Notification object represented by the provided JSON - */ - public static Notification fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Notification object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Notification object represented by the provided JSON + */ + public static Notification fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Notification.class); @@ -114,56 +128,23 @@ public static Notification fromJson(final InputStream json, final ObjectMapper o @JsonCreator private Notification( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("api_version") - final String apiVersion, - - @JsonProperty("call_sid") - final String callSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("error_code") - final String errorCode, - - @JsonProperty("log") - final String log, - - @JsonProperty("message_date") - final String messageDate, - - @JsonProperty("message_text") - final String messageText, - - @JsonProperty("more_info") - final URI moreInfo, - - @JsonProperty("request_method") - final HttpMethod requestMethod, - - @JsonProperty("request_url") - final URI requestUrl, - - @JsonProperty("request_variables") - final String requestVariables, - - @JsonProperty("response_body") - final String responseBody, - - @JsonProperty("response_headers") - final String responseHeaders, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("uri") - final String uri + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("api_version") final String apiVersion, + @JsonProperty("call_sid") final String callSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("error_code") final String errorCode, + @JsonProperty("log") final String log, + @JsonProperty("message_date") final String messageDate, + @JsonProperty("message_text") final String messageText, + @JsonProperty("more_info") final URI moreInfo, + @JsonProperty("request_method") final HttpMethod requestMethod, + @JsonProperty("request_url") final URI requestUrl, + @JsonProperty("request_variables") final String requestVariables, + @JsonProperty("response_body") final String responseBody, + @JsonProperty("response_headers") final String responseHeaders, + @JsonProperty("sid") final String sid, + @JsonProperty("uri") final String uri ) { this.accountSid = accountSid; this.apiVersion = apiVersion; @@ -184,61 +165,77 @@ private Notification( this.uri = uri; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getApiVersion() { - return this.apiVersion; - } - public final String getCallSid() { - return this.callSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getErrorCode() { - return this.errorCode; - } - public final String getLog() { - return this.log; - } - public final ZonedDateTime getMessageDate() { - return this.messageDate; - } - public final String getMessageText() { - return this.messageText; - } - public final URI getMoreInfo() { - return this.moreInfo; - } - public final HttpMethod getRequestMethod() { - return this.requestMethod; - } - public final URI getRequestUrl() { - return this.requestUrl; - } - public final String getRequestVariables() { - return this.requestVariables; - } - public final String getResponseBody() { - return this.responseBody; - } - public final String getResponseHeaders() { - return this.responseHeaders; - } - public final String getSid() { - return this.sid; - } - public final String getUri() { - return this.uri; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getApiVersion() { + return this.apiVersion; + } + + public final String getCallSid() { + return this.callSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getErrorCode() { + return this.errorCode; + } + + public final String getLog() { + return this.log; + } + + public final ZonedDateTime getMessageDate() { + return this.messageDate; + } + + public final String getMessageText() { + return this.messageText; + } + + public final URI getMoreInfo() { + return this.moreInfo; + } + + public final HttpMethod getRequestMethod() { + return this.requestMethod; + } + + public final URI getRequestUrl() { + return this.requestUrl; + } + + public final String getRequestVariables() { + return this.requestVariables; + } + + public final String getResponseBody() { + return this.responseBody; + } + + public final String getResponseHeaders() { + return this.responseHeaders; + } + + public final String getSid() { + return this.sid; + } + + public final String getUri() { + return this.uri; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -248,13 +245,47 @@ public boolean equals(final Object o) { Notification other = (Notification) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(apiVersion, other.apiVersion) && Objects.equals(callSid, other.callSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(errorCode, other.errorCode) && Objects.equals(log, other.log) && Objects.equals(messageDate, other.messageDate) && Objects.equals(messageText, other.messageText) && Objects.equals(moreInfo, other.moreInfo) && Objects.equals(requestMethod, other.requestMethod) && Objects.equals(requestUrl, other.requestUrl) && Objects.equals(requestVariables, other.requestVariables) && Objects.equals(responseBody, other.responseBody) && Objects.equals(responseHeaders, other.responseHeaders) && Objects.equals(sid, other.sid) && Objects.equals(uri, other.uri) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(apiVersion, other.apiVersion) && + Objects.equals(callSid, other.callSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(errorCode, other.errorCode) && + Objects.equals(log, other.log) && + Objects.equals(messageDate, other.messageDate) && + Objects.equals(messageText, other.messageText) && + Objects.equals(moreInfo, other.moreInfo) && + Objects.equals(requestMethod, other.requestMethod) && + Objects.equals(requestUrl, other.requestUrl) && + Objects.equals(requestVariables, other.requestVariables) && + Objects.equals(responseBody, other.responseBody) && + Objects.equals(responseHeaders, other.responseHeaders) && + Objects.equals(sid, other.sid) && + Objects.equals(uri, other.uri) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, apiVersion, callSid, dateCreated, dateUpdated, errorCode, log, messageDate, messageText, moreInfo, requestMethod, requestUrl, requestVariables, responseBody, responseHeaders, sid, uri); + return Objects.hash( + accountSid, + apiVersion, + callSid, + dateCreated, + dateUpdated, + errorCode, + log, + messageDate, + messageText, + moreInfo, + requestMethod, + requestUrl, + requestVariables, + responseBody, + responseHeaders, + sid, + uri + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/NotificationFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/call/NotificationFetcher.java index 2bc8a7f157..0263ef2c0b 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/call/NotificationFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/call/NotificationFetcher.java @@ -24,33 +24,43 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class NotificationFetcher extends Fetcher { + private String pathCallSid; private String pathSid; private String pathAccountSid; - public NotificationFetcher(final String pathCallSid, final String pathSid){ + public NotificationFetcher(final String pathCallSid, final String pathSid) { this.pathCallSid = pathCallSid; this.pathSid = pathSid; } - public NotificationFetcher(final String pathAccountSid, final String pathCallSid, final String pathSid){ + + public NotificationFetcher( + final String pathAccountSid, + final String pathCallSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathCallSid = pathCallSid; this.pathSid = pathSid; } - @Override public Notification fetch(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Notifications/{Sid}.json"; + String path = + "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Notifications/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"CallSid"+"}", this.pathCallSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "CallSid" + "}", this.pathCallSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -60,15 +70,23 @@ public Notification fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Notification fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Notification fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Notification.fromJson(response.getStream(), client.getObjectMapper()); + return Notification.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/NotificationReader.java b/src/main/java/com/twilio/rest/api/v2010/account/call/NotificationReader.java index 22400a49e3..493d7a489a 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/call/NotificationReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/call/NotificationReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.api.v2010.account.call; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,13 +25,11 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; import java.time.LocalDate; import java.time.format.DateTimeFormatter; - - public class NotificationReader extends Reader { + private String pathCallSid; private String pathAccountSid; private Integer log; @@ -39,31 +38,43 @@ public class NotificationReader extends Reader { private LocalDate messageDateAfter; private Integer pageSize; - public NotificationReader(final String pathCallSid){ + public NotificationReader(final String pathCallSid) { this.pathCallSid = pathCallSid; } - public NotificationReader(final String pathAccountSid, final String pathCallSid){ + + public NotificationReader( + final String pathAccountSid, + final String pathCallSid + ) { this.pathAccountSid = pathAccountSid; this.pathCallSid = pathCallSid; } - public NotificationReader setLog(final Integer log){ + public NotificationReader setLog(final Integer log) { this.log = log; return this; } - public NotificationReader setMessageDate(final LocalDate messageDate){ + + public NotificationReader setMessageDate(final LocalDate messageDate) { this.messageDate = messageDate; return this; } - public NotificationReader setMessageDateBefore(final LocalDate messageDateBefore){ + + public NotificationReader setMessageDateBefore( + final LocalDate messageDateBefore + ) { this.messageDateBefore = messageDateBefore; return this; } - public NotificationReader setMessageDateAfter(final LocalDate messageDateAfter){ + + public NotificationReader setMessageDateAfter( + final LocalDate messageDateAfter + ) { this.messageDateAfter = messageDateAfter; return this; } - public NotificationReader setPageSize(final Integer pageSize){ + + public NotificationReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -74,10 +85,18 @@ public ResourceSet read(final TwilioRestClient client) { } public Page firstPage(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Notifications.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"CallSid"+"}", this.pathCallSid.toString()); + String path = + "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Notifications.json"; + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "CallSid" + "}", this.pathCallSid.toString()); Request request = new Request( HttpMethod.GET, @@ -89,13 +108,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Notification read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Notification read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -111,7 +138,10 @@ private Page pageForRequest(final TwilioRestClient client, final R } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.API.toString()) @@ -119,9 +149,11 @@ public Page previousPage(final Page page, final Twil return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.API.toString()) @@ -130,31 +162,40 @@ public Page nextPage(final Page page, final TwilioRe } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (log != null) { - request.addQueryParam("Log", log.toString()); } if (messageDate != null) { - request.addQueryParam("MessageDate", messageDate.format(DateTimeFormatter.ofPattern(Request.QUERY_STRING_DATE_TIME_FORMAT))); - } - else if (messageDateAfter != null || messageDateBefore != null) { - request.addQueryDateRange("MessageDate", messageDateAfter, messageDateBefore); + request.addQueryParam( + "MessageDate", + messageDate.format( + DateTimeFormatter.ofPattern( + Request.QUERY_STRING_DATE_FORMAT + ) + ) + ); + } else if (messageDateAfter != null || messageDateBefore != null) { + request.addQueryDateRange( + "MessageDate", + messageDateAfter, + messageDateBefore + ); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/Payment.java b/src/main/java/com/twilio/rest/api/v2010/account/call/Payment.java index 102d365a76..f00dfcf5bd 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/call/Payment.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/call/Payment.java @@ -24,47 +24,84 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Payment extends Resource { + private static final long serialVersionUID = 75287507384907L; - public static PaymentCreator creator(final String pathCallSid, final String idempotencyKey, final URI statusCallback){ + public static PaymentCreator creator( + final String pathCallSid, + final String idempotencyKey, + final URI statusCallback + ) { return new PaymentCreator(pathCallSid, idempotencyKey, statusCallback); } - public static PaymentCreator creator(final String pathAccountSid, final String pathCallSid, final String idempotencyKey, final URI statusCallback){ - return new PaymentCreator(pathAccountSid, pathCallSid, idempotencyKey, statusCallback); + + public static PaymentCreator creator( + final String pathAccountSid, + final String pathCallSid, + final String idempotencyKey, + final URI statusCallback + ) { + return new PaymentCreator( + pathAccountSid, + pathCallSid, + idempotencyKey, + statusCallback + ); } - public static PaymentUpdater updater(final String pathCallSid, final String pathSid, final String idempotencyKey, final URI statusCallback){ - return new PaymentUpdater(pathCallSid, pathSid, idempotencyKey, statusCallback); + public static PaymentUpdater updater( + final String pathCallSid, + final String pathSid, + final String idempotencyKey, + final URI statusCallback + ) { + return new PaymentUpdater( + pathCallSid, + pathSid, + idempotencyKey, + statusCallback + ); } - public static PaymentUpdater updater(final String pathAccountSid, final String pathCallSid, final String pathSid, final String idempotencyKey, final URI statusCallback){ - return new PaymentUpdater(pathAccountSid, pathCallSid, pathSid, idempotencyKey, statusCallback); + + public static PaymentUpdater updater( + final String pathAccountSid, + final String pathCallSid, + final String pathSid, + final String idempotencyKey, + final URI statusCallback + ) { + return new PaymentUpdater( + pathAccountSid, + pathCallSid, + pathSid, + idempotencyKey, + statusCallback + ); } /** - * Converts a JSON String into a Payment object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Payment object represented by the provided JSON - */ - public static Payment fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Payment object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Payment object represented by the provided JSON + */ + public static Payment fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Payment.class); @@ -76,14 +113,17 @@ public static Payment fromJson(final String json, final ObjectMapper objectMappe } /** - * Converts a JSON InputStream into a Payment object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Payment object represented by the provided JSON - */ - public static Payment fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Payment object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Payment object represented by the provided JSON + */ + public static Payment fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Payment.class); @@ -93,6 +133,7 @@ public static Payment fromJson(final InputStream json, final ObjectMapper object throw new ApiConnectionException(e.getMessage(), e); } } + public enum BankAccountType { CONSUMER_CHECKING("consumer-checking"), CONSUMER_SAVINGS("consumer-savings"), @@ -113,6 +154,7 @@ public static BankAccountType forValue(final String value) { return Promoter.enumFromString(value, BankAccountType.values()); } } + public enum Capture { PAYMENT_CARD_NUMBER("payment-card-number"), EXPIRATION_DATE("expiration-date"), @@ -136,6 +178,7 @@ public static Capture forValue(final String value) { return Promoter.enumFromString(value, Capture.values()); } } + public enum PaymentMethod { CREDIT_CARD("credit-card"), ACH_DEBIT("ach-debit"); @@ -155,6 +198,7 @@ public static PaymentMethod forValue(final String value) { return Promoter.enumFromString(value, PaymentMethod.values()); } } + public enum Status { COMPLETE("complete"), CANCEL("cancel"); @@ -174,6 +218,7 @@ public static Status forValue(final String value) { return Promoter.enumFromString(value, Status.values()); } } + public enum TokenType { ONE_TIME("one-time"), REUSABLE("reusable"); @@ -203,23 +248,12 @@ public static TokenType forValue(final String value) { @JsonCreator private Payment( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("call_sid") - final String callSid, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("uri") - final String uri + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("call_sid") final String callSid, + @JsonProperty("sid") final String sid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("uri") final String uri ) { this.accountSid = accountSid; this.callSid = callSid; @@ -229,28 +263,33 @@ private Payment( this.uri = uri; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getCallSid() { - return this.callSid; - } - public final String getSid() { - return this.sid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getUri() { - return this.uri; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getCallSid() { + return this.callSid; + } + + public final String getSid() { + return this.sid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getUri() { + return this.uri; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -260,13 +299,25 @@ public boolean equals(final Object o) { Payment other = (Payment) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(callSid, other.callSid) && Objects.equals(sid, other.sid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(uri, other.uri) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(callSid, other.callSid) && + Objects.equals(sid, other.sid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(uri, other.uri) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, callSid, sid, dateCreated, dateUpdated, uri); + return Objects.hash( + accountSid, + callSid, + sid, + dateCreated, + dateUpdated, + uri + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/PaymentCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/call/PaymentCreator.java index 243951ed8e..39c91e19cb 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/call/PaymentCreator.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/call/PaymentCreator.java @@ -15,9 +15,11 @@ package com.twilio.rest.api.v2010.account.call; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; +import com.twilio.converter.Converter; +import com.twilio.converter.Converter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; -import com.twilio.converter.Converter; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; @@ -26,17 +28,14 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.math.BigDecimal; -import java.util.Map; -import com.twilio.converter.Converter; import java.math.BigDecimal; import java.net.URI; - +import java.net.URI; +import java.util.Map; import java.util.Map; +public class PaymentCreator extends Creator { -import java.net.URI; - -public class PaymentCreator extends Creator{ private String pathCallSid; private String idempotencyKey; private URI statusCallback; @@ -56,108 +55,161 @@ public class PaymentCreator extends Creator{ private Payment.TokenType tokenType; private String validCardTypes; - public PaymentCreator(final String pathCallSid, final String idempotencyKey, final URI statusCallback) { + public PaymentCreator( + final String pathCallSid, + final String idempotencyKey, + final URI statusCallback + ) { this.pathCallSid = pathCallSid; this.idempotencyKey = idempotencyKey; this.statusCallback = statusCallback; } - public PaymentCreator(final String pathAccountSid, final String pathCallSid, final String idempotencyKey, final URI statusCallback) { + + public PaymentCreator( + final String pathAccountSid, + final String pathCallSid, + final String idempotencyKey, + final URI statusCallback + ) { this.pathAccountSid = pathAccountSid; this.pathCallSid = pathCallSid; this.idempotencyKey = idempotencyKey; this.statusCallback = statusCallback; } - public PaymentCreator setIdempotencyKey(final String idempotencyKey){ + public PaymentCreator setIdempotencyKey(final String idempotencyKey) { this.idempotencyKey = idempotencyKey; return this; } - public PaymentCreator setStatusCallback(final URI statusCallback){ + + public PaymentCreator setStatusCallback(final URI statusCallback) { this.statusCallback = statusCallback; return this; } - public PaymentCreator setStatusCallback(final String statusCallback){ + public PaymentCreator setStatusCallback(final String statusCallback) { return setStatusCallback(Promoter.uriFromString(statusCallback)); } - public PaymentCreator setBankAccountType(final Payment.BankAccountType bankAccountType){ + + public PaymentCreator setBankAccountType( + final Payment.BankAccountType bankAccountType + ) { this.bankAccountType = bankAccountType; return this; } - public PaymentCreator setChargeAmount(final BigDecimal chargeAmount){ + + public PaymentCreator setChargeAmount(final BigDecimal chargeAmount) { this.chargeAmount = chargeAmount; return this; } - public PaymentCreator setCurrency(final String currency){ + + public PaymentCreator setCurrency(final String currency) { this.currency = currency; return this; } - public PaymentCreator setDescription(final String description){ + + public PaymentCreator setDescription(final String description) { this.description = description; return this; } - public PaymentCreator setInput(final String input){ + + public PaymentCreator setInput(final String input) { this.input = input; return this; } - public PaymentCreator setMinPostalCodeLength(final Integer minPostalCodeLength){ + + public PaymentCreator setMinPostalCodeLength( + final Integer minPostalCodeLength + ) { this.minPostalCodeLength = minPostalCodeLength; return this; } - public PaymentCreator setParameter(final Map parameter){ + + public PaymentCreator setParameter(final Map parameter) { this.parameter = parameter; return this; } - public PaymentCreator setPaymentConnector(final String paymentConnector){ + + public PaymentCreator setPaymentConnector(final String paymentConnector) { this.paymentConnector = paymentConnector; return this; } - public PaymentCreator setPaymentMethod(final Payment.PaymentMethod paymentMethod){ + + public PaymentCreator setPaymentMethod( + final Payment.PaymentMethod paymentMethod + ) { this.paymentMethod = paymentMethod; return this; } - public PaymentCreator setPostalCode(final Boolean postalCode){ + + public PaymentCreator setPostalCode(final Boolean postalCode) { this.postalCode = postalCode; return this; } - public PaymentCreator setSecurityCode(final Boolean securityCode){ + + public PaymentCreator setSecurityCode(final Boolean securityCode) { this.securityCode = securityCode; return this; } - public PaymentCreator setTimeout(final Integer timeout){ + + public PaymentCreator setTimeout(final Integer timeout) { this.timeout = timeout; return this; } - public PaymentCreator setTokenType(final Payment.TokenType tokenType){ + + public PaymentCreator setTokenType(final Payment.TokenType tokenType) { this.tokenType = tokenType; return this; } - public PaymentCreator setValidCardTypes(final String validCardTypes){ + + public PaymentCreator setValidCardTypes(final String validCardTypes) { this.validCardTypes = validCardTypes; return this; } @Override - public Payment create(final TwilioRestClient client){ - String path = "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Payments.json"; + public Payment create(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Payments.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"CallSid"+"}", this.pathCallSid.toString()); - path = path.replace("{"+"IdempotencyKey"+"}", this.idempotencyKey.toString()); - path = path.replace("{"+"StatusCallback"+"}", this.statusCallback.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "CallSid" + "}", this.pathCallSid.toString()); + path = + path.replace( + "{" + "IdempotencyKey" + "}", + this.idempotencyKey.toString() + ); + path = + path.replace( + "{" + "StatusCallback" + "}", + this.statusCallback.toString() + ); Request request = new Request( HttpMethod.POST, Domains.API.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Payment creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Payment creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -166,70 +218,58 @@ public Payment create(final TwilioRestClient client){ return Payment.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (idempotencyKey != null) { request.addPostParam("IdempotencyKey", idempotencyKey); - } if (statusCallback != null) { request.addPostParam("StatusCallback", statusCallback.toString()); - } if (bankAccountType != null) { request.addPostParam("BankAccountType", bankAccountType.toString()); - } if (chargeAmount != null) { request.addPostParam("ChargeAmount", chargeAmount.toString()); - } if (currency != null) { request.addPostParam("Currency", currency); - } if (description != null) { request.addPostParam("Description", description); - } if (input != null) { request.addPostParam("Input", input); - } if (minPostalCodeLength != null) { - request.addPostParam("MinPostalCodeLength", minPostalCodeLength.toString()); - + request.addPostParam( + "MinPostalCodeLength", + minPostalCodeLength.toString() + ); } if (parameter != null) { - request.addPostParam("Parameter", Converter.mapToJson(parameter)); - + request.addPostParam("Parameter", Converter.mapToJson(parameter)); } if (paymentConnector != null) { request.addPostParam("PaymentConnector", paymentConnector); - } if (paymentMethod != null) { request.addPostParam("PaymentMethod", paymentMethod.toString()); - } if (postalCode != null) { request.addPostParam("PostalCode", postalCode.toString()); - } if (securityCode != null) { request.addPostParam("SecurityCode", securityCode.toString()); - } if (timeout != null) { request.addPostParam("Timeout", timeout.toString()); - } if (tokenType != null) { request.addPostParam("TokenType", tokenType.toString()); - } if (validCardTypes != null) { request.addPostParam("ValidCardTypes", validCardTypes); - } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/PaymentUpdater.java b/src/main/java/com/twilio/rest/api/v2010/account/call/PaymentUpdater.java index c6bfb2c8f1..593227fc55 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/call/PaymentUpdater.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/call/PaymentUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010.account.call; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -24,12 +25,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.net.URI; +public class PaymentUpdater extends Updater { - -public class PaymentUpdater extends Updater{ private String pathCallSid; private String pathSid; private String idempotencyKey; @@ -38,13 +37,25 @@ public class PaymentUpdater extends Updater{ private Payment.Capture capture; private Payment.Status status; - public PaymentUpdater(final String pathCallSid, final String pathSid, final String idempotencyKey, final URI statusCallback){ + public PaymentUpdater( + final String pathCallSid, + final String pathSid, + final String idempotencyKey, + final URI statusCallback + ) { this.pathCallSid = pathCallSid; this.pathSid = pathSid; this.idempotencyKey = idempotencyKey; this.statusCallback = statusCallback; } - public PaymentUpdater(final String pathAccountSid, final String pathCallSid, final String pathSid, final String idempotencyKey, final URI statusCallback){ + + public PaymentUpdater( + final String pathAccountSid, + final String pathCallSid, + final String pathSid, + final String idempotencyKey, + final URI statusCallback + ) { this.pathAccountSid = pathAccountSid; this.pathCallSid = pathCallSid; this.pathSid = pathSid; @@ -52,49 +63,74 @@ public PaymentUpdater(final String pathAccountSid, final String pathCallSid, fin this.statusCallback = statusCallback; } - public PaymentUpdater setIdempotencyKey(final String idempotencyKey){ + public PaymentUpdater setIdempotencyKey(final String idempotencyKey) { this.idempotencyKey = idempotencyKey; return this; } - public PaymentUpdater setStatusCallback(final URI statusCallback){ + + public PaymentUpdater setStatusCallback(final URI statusCallback) { this.statusCallback = statusCallback; return this; } - public PaymentUpdater setStatusCallback(final String statusCallback){ + public PaymentUpdater setStatusCallback(final String statusCallback) { return setStatusCallback(Promoter.uriFromString(statusCallback)); } - public PaymentUpdater setCapture(final Payment.Capture capture){ + + public PaymentUpdater setCapture(final Payment.Capture capture) { this.capture = capture; return this; } - public PaymentUpdater setStatus(final Payment.Status status){ + + public PaymentUpdater setStatus(final Payment.Status status) { this.status = status; return this; } @Override - public Payment update(final TwilioRestClient client){ - String path = "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Payments/{Sid}.json"; + public Payment update(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Payments/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"CallSid"+"}", this.pathCallSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); - path = path.replace("{"+"IdempotencyKey"+"}", this.idempotencyKey.toString()); - path = path.replace("{"+"StatusCallback"+"}", this.statusCallback.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "CallSid" + "}", this.pathCallSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + path = + path.replace( + "{" + "IdempotencyKey" + "}", + this.idempotencyKey.toString() + ); + path = + path.replace( + "{" + "StatusCallback" + "}", + this.statusCallback.toString() + ); Request request = new Request( HttpMethod.POST, Domains.API.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Payment update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Payment update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -103,22 +139,19 @@ public Payment update(final TwilioRestClient client){ return Payment.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (idempotencyKey != null) { request.addPostParam("IdempotencyKey", idempotencyKey); - } if (statusCallback != null) { request.addPostParam("StatusCallback", statusCallback.toString()); - } if (capture != null) { request.addPostParam("Capture", capture.toString()); - } if (status != null) { request.addPostParam("Status", status.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/Recording.java b/src/main/java/com/twilio/rest/api/v2010/account/call/Recording.java index f961e6e895..0298ffda09 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/call/Recording.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/call/Recording.java @@ -20,77 +20,115 @@ import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.twilio.base.Resource; -import java.util.Currency; +import com.twilio.converter.CurrencyDeserializer; import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; -import com.twilio.converter.CurrencyDeserializer; import com.twilio.exception.ApiConnectionException; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; +import java.math.BigDecimal; import java.time.ZonedDateTime; - +import java.util.Currency; import java.util.Map; -import java.util.Objects; - - import java.util.Map; -import java.math.BigDecimal; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Recording extends Resource { + private static final long serialVersionUID = 269042081197241L; - public static RecordingCreator creator(final String pathCallSid){ + public static RecordingCreator creator(final String pathCallSid) { return new RecordingCreator(pathCallSid); } - public static RecordingCreator creator(final String pathAccountSid, final String pathCallSid){ + + public static RecordingCreator creator( + final String pathAccountSid, + final String pathCallSid + ) { return new RecordingCreator(pathAccountSid, pathCallSid); } - public static RecordingDeleter deleter(final String pathCallSid, final String pathSid){ + public static RecordingDeleter deleter( + final String pathCallSid, + final String pathSid + ) { return new RecordingDeleter(pathCallSid, pathSid); } - public static RecordingDeleter deleter(final String pathAccountSid, final String pathCallSid, final String pathSid){ + + public static RecordingDeleter deleter( + final String pathAccountSid, + final String pathCallSid, + final String pathSid + ) { return new RecordingDeleter(pathAccountSid, pathCallSid, pathSid); } - public static RecordingFetcher fetcher(final String pathCallSid, final String pathSid){ + public static RecordingFetcher fetcher( + final String pathCallSid, + final String pathSid + ) { return new RecordingFetcher(pathCallSid, pathSid); } - public static RecordingFetcher fetcher(final String pathAccountSid, final String pathCallSid, final String pathSid){ + + public static RecordingFetcher fetcher( + final String pathAccountSid, + final String pathCallSid, + final String pathSid + ) { return new RecordingFetcher(pathAccountSid, pathCallSid, pathSid); } - public static RecordingReader reader(final String pathCallSid){ + public static RecordingReader reader(final String pathCallSid) { return new RecordingReader(pathCallSid); } - public static RecordingReader reader(final String pathAccountSid, final String pathCallSid){ + + public static RecordingReader reader( + final String pathAccountSid, + final String pathCallSid + ) { return new RecordingReader(pathAccountSid, pathCallSid); } - public static RecordingUpdater updater(final String pathCallSid, final String pathSid, final Recording.Status status){ + public static RecordingUpdater updater( + final String pathCallSid, + final String pathSid, + final Recording.Status status + ) { return new RecordingUpdater(pathCallSid, pathSid, status); } - public static RecordingUpdater updater(final String pathAccountSid, final String pathCallSid, final String pathSid, final Recording.Status status){ - return new RecordingUpdater(pathAccountSid, pathCallSid, pathSid, status); + + public static RecordingUpdater updater( + final String pathAccountSid, + final String pathCallSid, + final String pathSid, + final Recording.Status status + ) { + return new RecordingUpdater( + pathAccountSid, + pathCallSid, + pathSid, + status + ); } /** - * Converts a JSON String into a Recording object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Recording object represented by the provided JSON - */ - public static Recording fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Recording object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Recording object represented by the provided JSON + */ + public static Recording fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Recording.class); @@ -102,14 +140,17 @@ public static Recording fromJson(final String json, final ObjectMapper objectMap } /** - * Converts a JSON InputStream into a Recording object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Recording object represented by the provided JSON - */ - public static Recording fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Recording object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Recording object represented by the provided JSON + */ + public static Recording fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Recording.class); @@ -119,6 +160,7 @@ public static Recording fromJson(final InputStream json, final ObjectMapper obje throw new ApiConnectionException(e.getMessage(), e); } } + public enum Source { DIALVERB("DialVerb"), CONFERENCE("Conference"), @@ -143,6 +185,7 @@ public static Source forValue(final String value) { return Promoter.enumFromString(value, Source.values()); } } + public enum Status { IN_PROGRESS("in-progress"), PAUSED("paused"), @@ -188,60 +231,28 @@ public static Status forValue(final String value) { @JsonCreator private Recording( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("api_version") - final String apiVersion, - - @JsonProperty("call_sid") - final String callSid, - - @JsonProperty("conference_sid") - final String conferenceSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("start_time") - final String startTime, - - @JsonProperty("duration") - final String duration, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("price") - final BigDecimal price, - - @JsonProperty("uri") - final String uri, - - @JsonProperty("encryption_details") - final Map encryptionDetails, - - @JsonProperty("price_unit") - @JsonDeserialize(using = com.twilio.converter.CurrencyDeserializer.class) - final Currency priceUnit, - - @JsonProperty("status") - final Recording.Status status, - - @JsonProperty("channels") - final Integer channels, - - @JsonProperty("source") - final Recording.Source source, - - @JsonProperty("error_code") - final Integer errorCode, - - @JsonProperty("track") - final String track + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("api_version") final String apiVersion, + @JsonProperty("call_sid") final String callSid, + @JsonProperty("conference_sid") final String conferenceSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("start_time") final String startTime, + @JsonProperty("duration") final String duration, + @JsonProperty("sid") final String sid, + @JsonProperty("price") final BigDecimal price, + @JsonProperty("uri") final String uri, + @JsonProperty( + "encryption_details" + ) final Map encryptionDetails, + @JsonProperty("price_unit") @JsonDeserialize( + using = com.twilio.converter.CurrencyDeserializer.class + ) final Currency priceUnit, + @JsonProperty("status") final Recording.Status status, + @JsonProperty("channels") final Integer channels, + @JsonProperty("source") final Recording.Source source, + @JsonProperty("error_code") final Integer errorCode, + @JsonProperty("track") final String track ) { this.accountSid = accountSid; this.apiVersion = apiVersion; @@ -263,64 +274,81 @@ private Recording( this.track = track; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getApiVersion() { - return this.apiVersion; - } - public final String getCallSid() { - return this.callSid; - } - public final String getConferenceSid() { - return this.conferenceSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final ZonedDateTime getStartTime() { - return this.startTime; - } - public final String getDuration() { - return this.duration; - } - public final String getSid() { - return this.sid; - } - public final BigDecimal getPrice() { - return this.price; - } - public final String getUri() { - return this.uri; - } - public final Map getEncryptionDetails() { - return this.encryptionDetails; - } - public final Currency getPriceUnit() { - return this.priceUnit; - } - public final Recording.Status getStatus() { - return this.status; - } - public final Integer getChannels() { - return this.channels; - } - public final Recording.Source getSource() { - return this.source; - } - public final Integer getErrorCode() { - return this.errorCode; - } - public final String getTrack() { - return this.track; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getApiVersion() { + return this.apiVersion; + } + + public final String getCallSid() { + return this.callSid; + } + + public final String getConferenceSid() { + return this.conferenceSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final ZonedDateTime getStartTime() { + return this.startTime; + } + + public final String getDuration() { + return this.duration; + } + + public final String getSid() { + return this.sid; + } + + public final BigDecimal getPrice() { + return this.price; + } + + public final String getUri() { + return this.uri; + } + + public final Map getEncryptionDetails() { + return this.encryptionDetails; + } + + public final Currency getPriceUnit() { + return this.priceUnit; + } + + public final Recording.Status getStatus() { + return this.status; + } + + public final Integer getChannels() { + return this.channels; + } + + public final Recording.Source getSource() { + return this.source; + } + + public final Integer getErrorCode() { + return this.errorCode; + } + + public final String getTrack() { + return this.track; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -330,13 +358,49 @@ public boolean equals(final Object o) { Recording other = (Recording) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(apiVersion, other.apiVersion) && Objects.equals(callSid, other.callSid) && Objects.equals(conferenceSid, other.conferenceSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(startTime, other.startTime) && Objects.equals(duration, other.duration) && Objects.equals(sid, other.sid) && Objects.equals(price, other.price) && Objects.equals(uri, other.uri) && Objects.equals(encryptionDetails, other.encryptionDetails) && Objects.equals(priceUnit, other.priceUnit) && Objects.equals(status, other.status) && Objects.equals(channels, other.channels) && Objects.equals(source, other.source) && Objects.equals(errorCode, other.errorCode) && Objects.equals(track, other.track) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(apiVersion, other.apiVersion) && + Objects.equals(callSid, other.callSid) && + Objects.equals(conferenceSid, other.conferenceSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(startTime, other.startTime) && + Objects.equals(duration, other.duration) && + Objects.equals(sid, other.sid) && + Objects.equals(price, other.price) && + Objects.equals(uri, other.uri) && + Objects.equals(encryptionDetails, other.encryptionDetails) && + Objects.equals(priceUnit, other.priceUnit) && + Objects.equals(status, other.status) && + Objects.equals(channels, other.channels) && + Objects.equals(source, other.source) && + Objects.equals(errorCode, other.errorCode) && + Objects.equals(track, other.track) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, apiVersion, callSid, conferenceSid, dateCreated, dateUpdated, startTime, duration, sid, price, uri, encryptionDetails, priceUnit, status, channels, source, errorCode, track); + return Objects.hash( + accountSid, + apiVersion, + callSid, + conferenceSid, + dateCreated, + dateUpdated, + startTime, + duration, + sid, + price, + uri, + encryptionDetails, + priceUnit, + status, + channels, + source, + errorCode, + track + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/RecordingCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/call/RecordingCreator.java index 361bb9128b..2bcd721034 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/call/RecordingCreator.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/call/RecordingCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010.account.call; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -24,15 +25,13 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import java.util.List; import java.net.URI; - +import java.net.URI; +import java.util.List; import java.util.List; +public class RecordingCreator extends Creator { -import java.net.URI; - -public class RecordingCreator extends Creator{ private String pathCallSid; private String pathAccountSid; private List recordingStatusCallbackEvent; @@ -45,96 +44,140 @@ public class RecordingCreator extends Creator{ public RecordingCreator(final String pathCallSid) { this.pathCallSid = pathCallSid; } - public RecordingCreator(final String pathAccountSid, final String pathCallSid) { + + public RecordingCreator( + final String pathAccountSid, + final String pathCallSid + ) { this.pathAccountSid = pathAccountSid; this.pathCallSid = pathCallSid; } - public RecordingCreator setRecordingStatusCallbackEvent(final List recordingStatusCallbackEvent){ + public RecordingCreator setRecordingStatusCallbackEvent( + final List recordingStatusCallbackEvent + ) { this.recordingStatusCallbackEvent = recordingStatusCallbackEvent; return this; } - public RecordingCreator setRecordingStatusCallbackEvent(final String recordingStatusCallbackEvent){ - return setRecordingStatusCallbackEvent(Promoter.listOfOne(recordingStatusCallbackEvent)); + + public RecordingCreator setRecordingStatusCallbackEvent( + final String recordingStatusCallbackEvent + ) { + return setRecordingStatusCallbackEvent( + Promoter.listOfOne(recordingStatusCallbackEvent) + ); } - public RecordingCreator setRecordingStatusCallback(final URI recordingStatusCallback){ + + public RecordingCreator setRecordingStatusCallback( + final URI recordingStatusCallback + ) { this.recordingStatusCallback = recordingStatusCallback; return this; } - public RecordingCreator setRecordingStatusCallback(final String recordingStatusCallback){ - return setRecordingStatusCallback(Promoter.uriFromString(recordingStatusCallback)); + public RecordingCreator setRecordingStatusCallback( + final String recordingStatusCallback + ) { + return setRecordingStatusCallback( + Promoter.uriFromString(recordingStatusCallback) + ); } - public RecordingCreator setRecordingStatusCallbackMethod(final HttpMethod recordingStatusCallbackMethod){ + + public RecordingCreator setRecordingStatusCallbackMethod( + final HttpMethod recordingStatusCallbackMethod + ) { this.recordingStatusCallbackMethod = recordingStatusCallbackMethod; return this; } - public RecordingCreator setTrim(final String trim){ + + public RecordingCreator setTrim(final String trim) { this.trim = trim; return this; } - public RecordingCreator setRecordingChannels(final String recordingChannels){ + + public RecordingCreator setRecordingChannels( + final String recordingChannels + ) { this.recordingChannels = recordingChannels; return this; } - public RecordingCreator setRecordingTrack(final String recordingTrack){ + + public RecordingCreator setRecordingTrack(final String recordingTrack) { this.recordingTrack = recordingTrack; return this; } @Override - public Recording create(final TwilioRestClient client){ - String path = "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Recordings.json"; + public Recording create(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Recordings.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"CallSid"+"}", this.pathCallSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "CallSid" + "}", this.pathCallSid.toString()); Request request = new Request( HttpMethod.POST, Domains.API.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Recording creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Recording creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Recording.fromJson(response.getStream(), client.getObjectMapper()); + return Recording.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (recordingStatusCallbackEvent != null) { for (String prop : recordingStatusCallbackEvent) { request.addPostParam("RecordingStatusCallbackEvent", prop); } - } if (recordingStatusCallback != null) { - request.addPostParam("RecordingStatusCallback", recordingStatusCallback.toString()); - + request.addPostParam( + "RecordingStatusCallback", + recordingStatusCallback.toString() + ); } if (recordingStatusCallbackMethod != null) { - request.addPostParam("RecordingStatusCallbackMethod", recordingStatusCallbackMethod.toString()); - + request.addPostParam( + "RecordingStatusCallbackMethod", + recordingStatusCallbackMethod.toString() + ); } if (trim != null) { request.addPostParam("Trim", trim); - } if (recordingChannels != null) { request.addPostParam("RecordingChannels", recordingChannels); - } if (recordingTrack != null) { request.addPostParam("RecordingTrack", recordingTrack); - } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/RecordingDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/call/RecordingDeleter.java index 7044ba2c6b..efbed030c0 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/call/RecordingDeleter.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/call/RecordingDeleter.java @@ -24,32 +24,43 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class RecordingDeleter extends Deleter { + private String pathCallSid; private String pathSid; private String pathAccountSid; - public RecordingDeleter(final String pathCallSid, final String pathSid){ + public RecordingDeleter(final String pathCallSid, final String pathSid) { this.pathCallSid = pathCallSid; this.pathSid = pathSid; } - public RecordingDeleter(final String pathAccountSid, final String pathCallSid, final String pathSid){ + + public RecordingDeleter( + final String pathAccountSid, + final String pathCallSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathCallSid = pathCallSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Recordings/{Sid}.json"; + String path = + "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Recordings/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"CallSid"+"}", this.pathCallSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "CallSid" + "}", this.pathCallSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -59,9 +70,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Recording delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Recording delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/RecordingFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/call/RecordingFetcher.java index 3420833619..2c3ff73751 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/call/RecordingFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/call/RecordingFetcher.java @@ -24,33 +24,43 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class RecordingFetcher extends Fetcher { + private String pathCallSid; private String pathSid; private String pathAccountSid; - public RecordingFetcher(final String pathCallSid, final String pathSid){ + public RecordingFetcher(final String pathCallSid, final String pathSid) { this.pathCallSid = pathCallSid; this.pathSid = pathSid; } - public RecordingFetcher(final String pathAccountSid, final String pathCallSid, final String pathSid){ + + public RecordingFetcher( + final String pathAccountSid, + final String pathCallSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathCallSid = pathCallSid; this.pathSid = pathSid; } - @Override public Recording fetch(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Recordings/{Sid}.json"; + String path = + "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Recordings/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"CallSid"+"}", this.pathCallSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "CallSid" + "}", this.pathCallSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -60,15 +70,23 @@ public Recording fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Recording fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Recording fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Recording.fromJson(response.getStream(), client.getObjectMapper()); + return Recording.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/RecordingReader.java b/src/main/java/com/twilio/rest/api/v2010/account/call/RecordingReader.java index b56256f976..d4aa7ccf5e 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/call/RecordingReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/call/RecordingReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.api.v2010.account.call; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,13 +25,11 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; import java.time.LocalDate; import java.time.format.DateTimeFormatter; - - public class RecordingReader extends Reader { + private String pathCallSid; private String pathAccountSid; private LocalDate dateCreated; @@ -38,27 +37,38 @@ public class RecordingReader extends Reader { private LocalDate dateCreatedAfter; private Integer pageSize; - public RecordingReader(final String pathCallSid){ + public RecordingReader(final String pathCallSid) { this.pathCallSid = pathCallSid; } - public RecordingReader(final String pathAccountSid, final String pathCallSid){ + + public RecordingReader( + final String pathAccountSid, + final String pathCallSid + ) { this.pathAccountSid = pathAccountSid; this.pathCallSid = pathCallSid; } - public RecordingReader setDateCreated(final LocalDate dateCreated){ + public RecordingReader setDateCreated(final LocalDate dateCreated) { this.dateCreated = dateCreated; return this; } - public RecordingReader setDateCreatedBefore(final LocalDate dateCreatedBefore){ + + public RecordingReader setDateCreatedBefore( + final LocalDate dateCreatedBefore + ) { this.dateCreatedBefore = dateCreatedBefore; return this; } - public RecordingReader setDateCreatedAfter(final LocalDate dateCreatedAfter){ + + public RecordingReader setDateCreatedAfter( + final LocalDate dateCreatedAfter + ) { this.dateCreatedAfter = dateCreatedAfter; return this; } - public RecordingReader setPageSize(final Integer pageSize){ + + public RecordingReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -69,10 +79,18 @@ public ResourceSet read(final TwilioRestClient client) { } public Page firstPage(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Recordings.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"CallSid"+"}", this.pathCallSid.toString()); + String path = + "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Recordings.json"; + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "CallSid" + "}", this.pathCallSid.toString()); Request request = new Request( HttpMethod.GET, @@ -84,13 +102,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Recording read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Recording read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -106,7 +132,10 @@ private Page pageForRequest(final TwilioRestClient client, final Requ } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.API.toString()) @@ -114,9 +143,11 @@ public Page previousPage(final Page page, final TwilioRest return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.API.toString()) @@ -125,27 +156,37 @@ public Page nextPage(final Page page, final TwilioRestClie } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (dateCreated != null) { - request.addQueryParam("DateCreated", dateCreated.format(DateTimeFormatter.ofPattern(Request.QUERY_STRING_DATE_TIME_FORMAT))); - } - else if (dateCreatedAfter != null || dateCreatedBefore != null) { - request.addQueryDateRange("DateCreated", dateCreatedAfter, dateCreatedBefore); + request.addQueryParam( + "DateCreated", + dateCreated.format( + DateTimeFormatter.ofPattern( + Request.QUERY_STRING_DATE_FORMAT + ) + ) + ); + } else if (dateCreatedAfter != null || dateCreatedBefore != null) { + request.addQueryDateRange( + "DateCreated", + dateCreatedAfter, + dateCreatedBefore + ); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/RecordingUpdater.java b/src/main/java/com/twilio/rest/api/v2010/account/call/RecordingUpdater.java index d8b0a6f5dd..197601bc85 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/call/RecordingUpdater.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/call/RecordingUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010.account.call; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,74 +25,99 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class RecordingUpdater extends Updater { - - -public class RecordingUpdater extends Updater{ private String pathCallSid; private String pathSid; private Recording.Status status; private String pathAccountSid; private String pauseBehavior; - public RecordingUpdater(final String pathCallSid, final String pathSid, final Recording.Status status){ + public RecordingUpdater( + final String pathCallSid, + final String pathSid, + final Recording.Status status + ) { this.pathCallSid = pathCallSid; this.pathSid = pathSid; this.status = status; } - public RecordingUpdater(final String pathAccountSid, final String pathCallSid, final String pathSid, final Recording.Status status){ + + public RecordingUpdater( + final String pathAccountSid, + final String pathCallSid, + final String pathSid, + final Recording.Status status + ) { this.pathAccountSid = pathAccountSid; this.pathCallSid = pathCallSid; this.pathSid = pathSid; this.status = status; } - public RecordingUpdater setStatus(final Recording.Status status){ + public RecordingUpdater setStatus(final Recording.Status status) { this.status = status; return this; } - public RecordingUpdater setPauseBehavior(final String pauseBehavior){ + + public RecordingUpdater setPauseBehavior(final String pauseBehavior) { this.pauseBehavior = pauseBehavior; return this; } @Override - public Recording update(final TwilioRestClient client){ - String path = "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Recordings/{Sid}.json"; + public Recording update(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Recordings/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"CallSid"+"}", this.pathCallSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); - path = path.replace("{"+"Status"+"}", this.status.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "CallSid" + "}", this.pathCallSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + path = path.replace("{" + "Status" + "}", this.status.toString()); Request request = new Request( HttpMethod.POST, Domains.API.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Recording update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Recording update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Recording.fromJson(response.getStream(), client.getObjectMapper()); + return Recording.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (status != null) { request.addPostParam("Status", status.toString()); - } if (pauseBehavior != null) { request.addPostParam("PauseBehavior", pauseBehavior); - } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/Siprec.java b/src/main/java/com/twilio/rest/api/v2010/account/call/Siprec.java index 4e751d4df2..c4b9688159 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/call/Siprec.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/call/Siprec.java @@ -24,46 +24,59 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Siprec extends Resource { + private static final long serialVersionUID = 230113301753485L; - public static SiprecCreator creator(final String pathCallSid){ + public static SiprecCreator creator(final String pathCallSid) { return new SiprecCreator(pathCallSid); } - public static SiprecCreator creator(final String pathAccountSid, final String pathCallSid){ + + public static SiprecCreator creator( + final String pathAccountSid, + final String pathCallSid + ) { return new SiprecCreator(pathAccountSid, pathCallSid); } - public static SiprecUpdater updater(final String pathCallSid, final String pathSid, final Siprec.UpdateStatus status){ + public static SiprecUpdater updater( + final String pathCallSid, + final String pathSid, + final Siprec.UpdateStatus status + ) { return new SiprecUpdater(pathCallSid, pathSid, status); } - public static SiprecUpdater updater(final String pathAccountSid, final String pathCallSid, final String pathSid, final Siprec.UpdateStatus status){ + + public static SiprecUpdater updater( + final String pathAccountSid, + final String pathCallSid, + final String pathSid, + final Siprec.UpdateStatus status + ) { return new SiprecUpdater(pathAccountSid, pathCallSid, pathSid, status); } /** - * Converts a JSON String into a Siprec object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Siprec object represented by the provided JSON - */ - public static Siprec fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Siprec object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Siprec object represented by the provided JSON + */ + public static Siprec fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Siprec.class); @@ -75,14 +88,17 @@ public static Siprec fromJson(final String json, final ObjectMapper objectMapper } /** - * Converts a JSON InputStream into a Siprec object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Siprec object represented by the provided JSON - */ - public static Siprec fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Siprec object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Siprec object represented by the provided JSON + */ + public static Siprec fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Siprec.class); @@ -92,6 +108,7 @@ public static Siprec fromJson(final InputStream json, final ObjectMapper objectM throw new ApiConnectionException(e.getMessage(), e); } } + public enum Status { IN_PROGRESS("in-progress"), STOPPED("stopped"); @@ -111,6 +128,7 @@ public static Status forValue(final String value) { return Promoter.enumFromString(value, Status.values()); } } + public enum Track { INBOUND_TRACK("inbound_track"), OUTBOUND_TRACK("outbound_track"), @@ -131,6 +149,7 @@ public static Track forValue(final String value) { return Promoter.enumFromString(value, Track.values()); } } + public enum UpdateStatus { STOPPED("stopped"); @@ -160,26 +179,13 @@ public static UpdateStatus forValue(final String value) { @JsonCreator private Siprec( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("call_sid") - final String callSid, - - @JsonProperty("name") - final String name, - - @JsonProperty("status") - final Siprec.Status status, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("uri") - final String uri + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("call_sid") final String callSid, + @JsonProperty("name") final String name, + @JsonProperty("status") final Siprec.Status status, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("uri") final String uri ) { this.sid = sid; this.accountSid = accountSid; @@ -190,31 +196,37 @@ private Siprec( this.uri = uri; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getCallSid() { - return this.callSid; - } - public final String getName() { - return this.name; - } - public final Siprec.Status getStatus() { - return this.status; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getUri() { - return this.uri; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getCallSid() { + return this.callSid; + } + + public final String getName() { + return this.name; + } + + public final Siprec.Status getStatus() { + return this.status; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getUri() { + return this.uri; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -224,13 +236,27 @@ public boolean equals(final Object o) { Siprec other = (Siprec) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(callSid, other.callSid) && Objects.equals(name, other.name) && Objects.equals(status, other.status) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(uri, other.uri) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(callSid, other.callSid) && + Objects.equals(name, other.name) && + Objects.equals(status, other.status) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(uri, other.uri) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, callSid, name, status, dateUpdated, uri); + return Objects.hash( + sid, + accountSid, + callSid, + name, + status, + dateUpdated, + uri + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/SiprecCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/call/SiprecCreator.java index d42ed7c0e8..3977ca0d6a 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/call/SiprecCreator.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/call/SiprecCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010.account.call; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -25,12 +26,10 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.net.URI; - - - import java.net.URI; -public class SiprecCreator extends Creator{ +public class SiprecCreator extends Creator { + private String pathCallSid; private String pathAccountSid; private String name; @@ -240,847 +239,1069 @@ public class SiprecCreator extends Creator{ public SiprecCreator(final String pathCallSid) { this.pathCallSid = pathCallSid; } - public SiprecCreator(final String pathAccountSid, final String pathCallSid) { + + public SiprecCreator( + final String pathAccountSid, + final String pathCallSid + ) { this.pathAccountSid = pathAccountSid; this.pathCallSid = pathCallSid; } - public SiprecCreator setName(final String name){ + public SiprecCreator setName(final String name) { this.name = name; return this; } - public SiprecCreator setConnectorName(final String connectorName){ + + public SiprecCreator setConnectorName(final String connectorName) { this.connectorName = connectorName; return this; } - public SiprecCreator setTrack(final Siprec.Track track){ + + public SiprecCreator setTrack(final Siprec.Track track) { this.track = track; return this; } - public SiprecCreator setStatusCallback(final URI statusCallback){ + + public SiprecCreator setStatusCallback(final URI statusCallback) { this.statusCallback = statusCallback; return this; } - public SiprecCreator setStatusCallback(final String statusCallback){ + public SiprecCreator setStatusCallback(final String statusCallback) { return setStatusCallback(Promoter.uriFromString(statusCallback)); } - public SiprecCreator setStatusCallbackMethod(final HttpMethod statusCallbackMethod){ + + public SiprecCreator setStatusCallbackMethod( + final HttpMethod statusCallbackMethod + ) { this.statusCallbackMethod = statusCallbackMethod; return this; } - public SiprecCreator setParameter1Name(final String parameter1Name){ + + public SiprecCreator setParameter1Name(final String parameter1Name) { this.parameter1Name = parameter1Name; return this; } - public SiprecCreator setParameter1Value(final String parameter1Value){ + + public SiprecCreator setParameter1Value(final String parameter1Value) { this.parameter1Value = parameter1Value; return this; } - public SiprecCreator setParameter2Name(final String parameter2Name){ + + public SiprecCreator setParameter2Name(final String parameter2Name) { this.parameter2Name = parameter2Name; return this; } - public SiprecCreator setParameter2Value(final String parameter2Value){ + + public SiprecCreator setParameter2Value(final String parameter2Value) { this.parameter2Value = parameter2Value; return this; } - public SiprecCreator setParameter3Name(final String parameter3Name){ + + public SiprecCreator setParameter3Name(final String parameter3Name) { this.parameter3Name = parameter3Name; return this; } - public SiprecCreator setParameter3Value(final String parameter3Value){ + + public SiprecCreator setParameter3Value(final String parameter3Value) { this.parameter3Value = parameter3Value; return this; } - public SiprecCreator setParameter4Name(final String parameter4Name){ + + public SiprecCreator setParameter4Name(final String parameter4Name) { this.parameter4Name = parameter4Name; return this; } - public SiprecCreator setParameter4Value(final String parameter4Value){ + + public SiprecCreator setParameter4Value(final String parameter4Value) { this.parameter4Value = parameter4Value; return this; } - public SiprecCreator setParameter5Name(final String parameter5Name){ + + public SiprecCreator setParameter5Name(final String parameter5Name) { this.parameter5Name = parameter5Name; return this; } - public SiprecCreator setParameter5Value(final String parameter5Value){ + + public SiprecCreator setParameter5Value(final String parameter5Value) { this.parameter5Value = parameter5Value; return this; } - public SiprecCreator setParameter6Name(final String parameter6Name){ + + public SiprecCreator setParameter6Name(final String parameter6Name) { this.parameter6Name = parameter6Name; return this; } - public SiprecCreator setParameter6Value(final String parameter6Value){ + + public SiprecCreator setParameter6Value(final String parameter6Value) { this.parameter6Value = parameter6Value; return this; } - public SiprecCreator setParameter7Name(final String parameter7Name){ + + public SiprecCreator setParameter7Name(final String parameter7Name) { this.parameter7Name = parameter7Name; return this; } - public SiprecCreator setParameter7Value(final String parameter7Value){ + + public SiprecCreator setParameter7Value(final String parameter7Value) { this.parameter7Value = parameter7Value; return this; } - public SiprecCreator setParameter8Name(final String parameter8Name){ + + public SiprecCreator setParameter8Name(final String parameter8Name) { this.parameter8Name = parameter8Name; return this; } - public SiprecCreator setParameter8Value(final String parameter8Value){ + + public SiprecCreator setParameter8Value(final String parameter8Value) { this.parameter8Value = parameter8Value; return this; } - public SiprecCreator setParameter9Name(final String parameter9Name){ + + public SiprecCreator setParameter9Name(final String parameter9Name) { this.parameter9Name = parameter9Name; return this; } - public SiprecCreator setParameter9Value(final String parameter9Value){ + + public SiprecCreator setParameter9Value(final String parameter9Value) { this.parameter9Value = parameter9Value; return this; } - public SiprecCreator setParameter10Name(final String parameter10Name){ + + public SiprecCreator setParameter10Name(final String parameter10Name) { this.parameter10Name = parameter10Name; return this; } - public SiprecCreator setParameter10Value(final String parameter10Value){ + + public SiprecCreator setParameter10Value(final String parameter10Value) { this.parameter10Value = parameter10Value; return this; } - public SiprecCreator setParameter11Name(final String parameter11Name){ + + public SiprecCreator setParameter11Name(final String parameter11Name) { this.parameter11Name = parameter11Name; return this; } - public SiprecCreator setParameter11Value(final String parameter11Value){ + + public SiprecCreator setParameter11Value(final String parameter11Value) { this.parameter11Value = parameter11Value; return this; } - public SiprecCreator setParameter12Name(final String parameter12Name){ + + public SiprecCreator setParameter12Name(final String parameter12Name) { this.parameter12Name = parameter12Name; return this; } - public SiprecCreator setParameter12Value(final String parameter12Value){ + + public SiprecCreator setParameter12Value(final String parameter12Value) { this.parameter12Value = parameter12Value; return this; } - public SiprecCreator setParameter13Name(final String parameter13Name){ + + public SiprecCreator setParameter13Name(final String parameter13Name) { this.parameter13Name = parameter13Name; return this; } - public SiprecCreator setParameter13Value(final String parameter13Value){ + + public SiprecCreator setParameter13Value(final String parameter13Value) { this.parameter13Value = parameter13Value; return this; } - public SiprecCreator setParameter14Name(final String parameter14Name){ + + public SiprecCreator setParameter14Name(final String parameter14Name) { this.parameter14Name = parameter14Name; return this; } - public SiprecCreator setParameter14Value(final String parameter14Value){ + + public SiprecCreator setParameter14Value(final String parameter14Value) { this.parameter14Value = parameter14Value; return this; } - public SiprecCreator setParameter15Name(final String parameter15Name){ + + public SiprecCreator setParameter15Name(final String parameter15Name) { this.parameter15Name = parameter15Name; return this; } - public SiprecCreator setParameter15Value(final String parameter15Value){ + + public SiprecCreator setParameter15Value(final String parameter15Value) { this.parameter15Value = parameter15Value; return this; } - public SiprecCreator setParameter16Name(final String parameter16Name){ + + public SiprecCreator setParameter16Name(final String parameter16Name) { this.parameter16Name = parameter16Name; return this; } - public SiprecCreator setParameter16Value(final String parameter16Value){ + + public SiprecCreator setParameter16Value(final String parameter16Value) { this.parameter16Value = parameter16Value; return this; } - public SiprecCreator setParameter17Name(final String parameter17Name){ + + public SiprecCreator setParameter17Name(final String parameter17Name) { this.parameter17Name = parameter17Name; return this; } - public SiprecCreator setParameter17Value(final String parameter17Value){ + + public SiprecCreator setParameter17Value(final String parameter17Value) { this.parameter17Value = parameter17Value; return this; } - public SiprecCreator setParameter18Name(final String parameter18Name){ + + public SiprecCreator setParameter18Name(final String parameter18Name) { this.parameter18Name = parameter18Name; return this; } - public SiprecCreator setParameter18Value(final String parameter18Value){ + + public SiprecCreator setParameter18Value(final String parameter18Value) { this.parameter18Value = parameter18Value; return this; } - public SiprecCreator setParameter19Name(final String parameter19Name){ + + public SiprecCreator setParameter19Name(final String parameter19Name) { this.parameter19Name = parameter19Name; return this; } - public SiprecCreator setParameter19Value(final String parameter19Value){ + + public SiprecCreator setParameter19Value(final String parameter19Value) { this.parameter19Value = parameter19Value; return this; } - public SiprecCreator setParameter20Name(final String parameter20Name){ + + public SiprecCreator setParameter20Name(final String parameter20Name) { this.parameter20Name = parameter20Name; return this; } - public SiprecCreator setParameter20Value(final String parameter20Value){ + + public SiprecCreator setParameter20Value(final String parameter20Value) { this.parameter20Value = parameter20Value; return this; } - public SiprecCreator setParameter21Name(final String parameter21Name){ + + public SiprecCreator setParameter21Name(final String parameter21Name) { this.parameter21Name = parameter21Name; return this; } - public SiprecCreator setParameter21Value(final String parameter21Value){ + + public SiprecCreator setParameter21Value(final String parameter21Value) { this.parameter21Value = parameter21Value; return this; } - public SiprecCreator setParameter22Name(final String parameter22Name){ + + public SiprecCreator setParameter22Name(final String parameter22Name) { this.parameter22Name = parameter22Name; return this; } - public SiprecCreator setParameter22Value(final String parameter22Value){ + + public SiprecCreator setParameter22Value(final String parameter22Value) { this.parameter22Value = parameter22Value; return this; } - public SiprecCreator setParameter23Name(final String parameter23Name){ + + public SiprecCreator setParameter23Name(final String parameter23Name) { this.parameter23Name = parameter23Name; return this; } - public SiprecCreator setParameter23Value(final String parameter23Value){ + + public SiprecCreator setParameter23Value(final String parameter23Value) { this.parameter23Value = parameter23Value; return this; } - public SiprecCreator setParameter24Name(final String parameter24Name){ + + public SiprecCreator setParameter24Name(final String parameter24Name) { this.parameter24Name = parameter24Name; return this; } - public SiprecCreator setParameter24Value(final String parameter24Value){ + + public SiprecCreator setParameter24Value(final String parameter24Value) { this.parameter24Value = parameter24Value; return this; } - public SiprecCreator setParameter25Name(final String parameter25Name){ + + public SiprecCreator setParameter25Name(final String parameter25Name) { this.parameter25Name = parameter25Name; return this; } - public SiprecCreator setParameter25Value(final String parameter25Value){ + + public SiprecCreator setParameter25Value(final String parameter25Value) { this.parameter25Value = parameter25Value; return this; } - public SiprecCreator setParameter26Name(final String parameter26Name){ + + public SiprecCreator setParameter26Name(final String parameter26Name) { this.parameter26Name = parameter26Name; return this; } - public SiprecCreator setParameter26Value(final String parameter26Value){ + + public SiprecCreator setParameter26Value(final String parameter26Value) { this.parameter26Value = parameter26Value; return this; } - public SiprecCreator setParameter27Name(final String parameter27Name){ + + public SiprecCreator setParameter27Name(final String parameter27Name) { this.parameter27Name = parameter27Name; return this; } - public SiprecCreator setParameter27Value(final String parameter27Value){ + + public SiprecCreator setParameter27Value(final String parameter27Value) { this.parameter27Value = parameter27Value; return this; } - public SiprecCreator setParameter28Name(final String parameter28Name){ + + public SiprecCreator setParameter28Name(final String parameter28Name) { this.parameter28Name = parameter28Name; return this; } - public SiprecCreator setParameter28Value(final String parameter28Value){ + + public SiprecCreator setParameter28Value(final String parameter28Value) { this.parameter28Value = parameter28Value; return this; } - public SiprecCreator setParameter29Name(final String parameter29Name){ + + public SiprecCreator setParameter29Name(final String parameter29Name) { this.parameter29Name = parameter29Name; return this; } - public SiprecCreator setParameter29Value(final String parameter29Value){ + + public SiprecCreator setParameter29Value(final String parameter29Value) { this.parameter29Value = parameter29Value; return this; } - public SiprecCreator setParameter30Name(final String parameter30Name){ + + public SiprecCreator setParameter30Name(final String parameter30Name) { this.parameter30Name = parameter30Name; return this; } - public SiprecCreator setParameter30Value(final String parameter30Value){ + + public SiprecCreator setParameter30Value(final String parameter30Value) { this.parameter30Value = parameter30Value; return this; } - public SiprecCreator setParameter31Name(final String parameter31Name){ + + public SiprecCreator setParameter31Name(final String parameter31Name) { this.parameter31Name = parameter31Name; return this; } - public SiprecCreator setParameter31Value(final String parameter31Value){ + + public SiprecCreator setParameter31Value(final String parameter31Value) { this.parameter31Value = parameter31Value; return this; } - public SiprecCreator setParameter32Name(final String parameter32Name){ + + public SiprecCreator setParameter32Name(final String parameter32Name) { this.parameter32Name = parameter32Name; return this; } - public SiprecCreator setParameter32Value(final String parameter32Value){ + + public SiprecCreator setParameter32Value(final String parameter32Value) { this.parameter32Value = parameter32Value; return this; } - public SiprecCreator setParameter33Name(final String parameter33Name){ + + public SiprecCreator setParameter33Name(final String parameter33Name) { this.parameter33Name = parameter33Name; return this; } - public SiprecCreator setParameter33Value(final String parameter33Value){ + + public SiprecCreator setParameter33Value(final String parameter33Value) { this.parameter33Value = parameter33Value; return this; } - public SiprecCreator setParameter34Name(final String parameter34Name){ + + public SiprecCreator setParameter34Name(final String parameter34Name) { this.parameter34Name = parameter34Name; return this; } - public SiprecCreator setParameter34Value(final String parameter34Value){ + + public SiprecCreator setParameter34Value(final String parameter34Value) { this.parameter34Value = parameter34Value; return this; } - public SiprecCreator setParameter35Name(final String parameter35Name){ + + public SiprecCreator setParameter35Name(final String parameter35Name) { this.parameter35Name = parameter35Name; return this; } - public SiprecCreator setParameter35Value(final String parameter35Value){ + + public SiprecCreator setParameter35Value(final String parameter35Value) { this.parameter35Value = parameter35Value; return this; } - public SiprecCreator setParameter36Name(final String parameter36Name){ + + public SiprecCreator setParameter36Name(final String parameter36Name) { this.parameter36Name = parameter36Name; return this; } - public SiprecCreator setParameter36Value(final String parameter36Value){ + + public SiprecCreator setParameter36Value(final String parameter36Value) { this.parameter36Value = parameter36Value; return this; } - public SiprecCreator setParameter37Name(final String parameter37Name){ + + public SiprecCreator setParameter37Name(final String parameter37Name) { this.parameter37Name = parameter37Name; return this; } - public SiprecCreator setParameter37Value(final String parameter37Value){ + + public SiprecCreator setParameter37Value(final String parameter37Value) { this.parameter37Value = parameter37Value; return this; } - public SiprecCreator setParameter38Name(final String parameter38Name){ + + public SiprecCreator setParameter38Name(final String parameter38Name) { this.parameter38Name = parameter38Name; return this; } - public SiprecCreator setParameter38Value(final String parameter38Value){ + + public SiprecCreator setParameter38Value(final String parameter38Value) { this.parameter38Value = parameter38Value; return this; } - public SiprecCreator setParameter39Name(final String parameter39Name){ + + public SiprecCreator setParameter39Name(final String parameter39Name) { this.parameter39Name = parameter39Name; return this; } - public SiprecCreator setParameter39Value(final String parameter39Value){ + + public SiprecCreator setParameter39Value(final String parameter39Value) { this.parameter39Value = parameter39Value; return this; } - public SiprecCreator setParameter40Name(final String parameter40Name){ + + public SiprecCreator setParameter40Name(final String parameter40Name) { this.parameter40Name = parameter40Name; return this; } - public SiprecCreator setParameter40Value(final String parameter40Value){ + + public SiprecCreator setParameter40Value(final String parameter40Value) { this.parameter40Value = parameter40Value; return this; } - public SiprecCreator setParameter41Name(final String parameter41Name){ + + public SiprecCreator setParameter41Name(final String parameter41Name) { this.parameter41Name = parameter41Name; return this; } - public SiprecCreator setParameter41Value(final String parameter41Value){ + + public SiprecCreator setParameter41Value(final String parameter41Value) { this.parameter41Value = parameter41Value; return this; } - public SiprecCreator setParameter42Name(final String parameter42Name){ + + public SiprecCreator setParameter42Name(final String parameter42Name) { this.parameter42Name = parameter42Name; return this; } - public SiprecCreator setParameter42Value(final String parameter42Value){ + + public SiprecCreator setParameter42Value(final String parameter42Value) { this.parameter42Value = parameter42Value; return this; } - public SiprecCreator setParameter43Name(final String parameter43Name){ + + public SiprecCreator setParameter43Name(final String parameter43Name) { this.parameter43Name = parameter43Name; return this; } - public SiprecCreator setParameter43Value(final String parameter43Value){ + + public SiprecCreator setParameter43Value(final String parameter43Value) { this.parameter43Value = parameter43Value; return this; } - public SiprecCreator setParameter44Name(final String parameter44Name){ + + public SiprecCreator setParameter44Name(final String parameter44Name) { this.parameter44Name = parameter44Name; return this; } - public SiprecCreator setParameter44Value(final String parameter44Value){ + + public SiprecCreator setParameter44Value(final String parameter44Value) { this.parameter44Value = parameter44Value; return this; } - public SiprecCreator setParameter45Name(final String parameter45Name){ + + public SiprecCreator setParameter45Name(final String parameter45Name) { this.parameter45Name = parameter45Name; return this; } - public SiprecCreator setParameter45Value(final String parameter45Value){ + + public SiprecCreator setParameter45Value(final String parameter45Value) { this.parameter45Value = parameter45Value; return this; } - public SiprecCreator setParameter46Name(final String parameter46Name){ + + public SiprecCreator setParameter46Name(final String parameter46Name) { this.parameter46Name = parameter46Name; return this; } - public SiprecCreator setParameter46Value(final String parameter46Value){ + + public SiprecCreator setParameter46Value(final String parameter46Value) { this.parameter46Value = parameter46Value; return this; } - public SiprecCreator setParameter47Name(final String parameter47Name){ + + public SiprecCreator setParameter47Name(final String parameter47Name) { this.parameter47Name = parameter47Name; return this; } - public SiprecCreator setParameter47Value(final String parameter47Value){ + + public SiprecCreator setParameter47Value(final String parameter47Value) { this.parameter47Value = parameter47Value; return this; } - public SiprecCreator setParameter48Name(final String parameter48Name){ + + public SiprecCreator setParameter48Name(final String parameter48Name) { this.parameter48Name = parameter48Name; return this; } - public SiprecCreator setParameter48Value(final String parameter48Value){ + + public SiprecCreator setParameter48Value(final String parameter48Value) { this.parameter48Value = parameter48Value; return this; } - public SiprecCreator setParameter49Name(final String parameter49Name){ + + public SiprecCreator setParameter49Name(final String parameter49Name) { this.parameter49Name = parameter49Name; return this; } - public SiprecCreator setParameter49Value(final String parameter49Value){ + + public SiprecCreator setParameter49Value(final String parameter49Value) { this.parameter49Value = parameter49Value; return this; } - public SiprecCreator setParameter50Name(final String parameter50Name){ + + public SiprecCreator setParameter50Name(final String parameter50Name) { this.parameter50Name = parameter50Name; return this; } - public SiprecCreator setParameter50Value(final String parameter50Value){ + + public SiprecCreator setParameter50Value(final String parameter50Value) { this.parameter50Value = parameter50Value; return this; } - public SiprecCreator setParameter51Name(final String parameter51Name){ + + public SiprecCreator setParameter51Name(final String parameter51Name) { this.parameter51Name = parameter51Name; return this; } - public SiprecCreator setParameter51Value(final String parameter51Value){ + + public SiprecCreator setParameter51Value(final String parameter51Value) { this.parameter51Value = parameter51Value; return this; } - public SiprecCreator setParameter52Name(final String parameter52Name){ + + public SiprecCreator setParameter52Name(final String parameter52Name) { this.parameter52Name = parameter52Name; return this; } - public SiprecCreator setParameter52Value(final String parameter52Value){ + + public SiprecCreator setParameter52Value(final String parameter52Value) { this.parameter52Value = parameter52Value; return this; } - public SiprecCreator setParameter53Name(final String parameter53Name){ + + public SiprecCreator setParameter53Name(final String parameter53Name) { this.parameter53Name = parameter53Name; return this; } - public SiprecCreator setParameter53Value(final String parameter53Value){ + + public SiprecCreator setParameter53Value(final String parameter53Value) { this.parameter53Value = parameter53Value; return this; } - public SiprecCreator setParameter54Name(final String parameter54Name){ + + public SiprecCreator setParameter54Name(final String parameter54Name) { this.parameter54Name = parameter54Name; return this; } - public SiprecCreator setParameter54Value(final String parameter54Value){ + + public SiprecCreator setParameter54Value(final String parameter54Value) { this.parameter54Value = parameter54Value; return this; } - public SiprecCreator setParameter55Name(final String parameter55Name){ + + public SiprecCreator setParameter55Name(final String parameter55Name) { this.parameter55Name = parameter55Name; return this; } - public SiprecCreator setParameter55Value(final String parameter55Value){ + + public SiprecCreator setParameter55Value(final String parameter55Value) { this.parameter55Value = parameter55Value; return this; } - public SiprecCreator setParameter56Name(final String parameter56Name){ + + public SiprecCreator setParameter56Name(final String parameter56Name) { this.parameter56Name = parameter56Name; return this; } - public SiprecCreator setParameter56Value(final String parameter56Value){ + + public SiprecCreator setParameter56Value(final String parameter56Value) { this.parameter56Value = parameter56Value; return this; } - public SiprecCreator setParameter57Name(final String parameter57Name){ + + public SiprecCreator setParameter57Name(final String parameter57Name) { this.parameter57Name = parameter57Name; return this; } - public SiprecCreator setParameter57Value(final String parameter57Value){ + + public SiprecCreator setParameter57Value(final String parameter57Value) { this.parameter57Value = parameter57Value; return this; } - public SiprecCreator setParameter58Name(final String parameter58Name){ + + public SiprecCreator setParameter58Name(final String parameter58Name) { this.parameter58Name = parameter58Name; return this; } - public SiprecCreator setParameter58Value(final String parameter58Value){ + + public SiprecCreator setParameter58Value(final String parameter58Value) { this.parameter58Value = parameter58Value; return this; } - public SiprecCreator setParameter59Name(final String parameter59Name){ + + public SiprecCreator setParameter59Name(final String parameter59Name) { this.parameter59Name = parameter59Name; return this; } - public SiprecCreator setParameter59Value(final String parameter59Value){ + + public SiprecCreator setParameter59Value(final String parameter59Value) { this.parameter59Value = parameter59Value; return this; } - public SiprecCreator setParameter60Name(final String parameter60Name){ + + public SiprecCreator setParameter60Name(final String parameter60Name) { this.parameter60Name = parameter60Name; return this; } - public SiprecCreator setParameter60Value(final String parameter60Value){ + + public SiprecCreator setParameter60Value(final String parameter60Value) { this.parameter60Value = parameter60Value; return this; } - public SiprecCreator setParameter61Name(final String parameter61Name){ + + public SiprecCreator setParameter61Name(final String parameter61Name) { this.parameter61Name = parameter61Name; return this; } - public SiprecCreator setParameter61Value(final String parameter61Value){ + + public SiprecCreator setParameter61Value(final String parameter61Value) { this.parameter61Value = parameter61Value; return this; } - public SiprecCreator setParameter62Name(final String parameter62Name){ + + public SiprecCreator setParameter62Name(final String parameter62Name) { this.parameter62Name = parameter62Name; return this; } - public SiprecCreator setParameter62Value(final String parameter62Value){ + + public SiprecCreator setParameter62Value(final String parameter62Value) { this.parameter62Value = parameter62Value; return this; } - public SiprecCreator setParameter63Name(final String parameter63Name){ + + public SiprecCreator setParameter63Name(final String parameter63Name) { this.parameter63Name = parameter63Name; return this; } - public SiprecCreator setParameter63Value(final String parameter63Value){ + + public SiprecCreator setParameter63Value(final String parameter63Value) { this.parameter63Value = parameter63Value; return this; } - public SiprecCreator setParameter64Name(final String parameter64Name){ + + public SiprecCreator setParameter64Name(final String parameter64Name) { this.parameter64Name = parameter64Name; return this; } - public SiprecCreator setParameter64Value(final String parameter64Value){ + + public SiprecCreator setParameter64Value(final String parameter64Value) { this.parameter64Value = parameter64Value; return this; } - public SiprecCreator setParameter65Name(final String parameter65Name){ + + public SiprecCreator setParameter65Name(final String parameter65Name) { this.parameter65Name = parameter65Name; return this; } - public SiprecCreator setParameter65Value(final String parameter65Value){ + + public SiprecCreator setParameter65Value(final String parameter65Value) { this.parameter65Value = parameter65Value; return this; } - public SiprecCreator setParameter66Name(final String parameter66Name){ + + public SiprecCreator setParameter66Name(final String parameter66Name) { this.parameter66Name = parameter66Name; return this; } - public SiprecCreator setParameter66Value(final String parameter66Value){ + + public SiprecCreator setParameter66Value(final String parameter66Value) { this.parameter66Value = parameter66Value; return this; } - public SiprecCreator setParameter67Name(final String parameter67Name){ + + public SiprecCreator setParameter67Name(final String parameter67Name) { this.parameter67Name = parameter67Name; return this; } - public SiprecCreator setParameter67Value(final String parameter67Value){ + + public SiprecCreator setParameter67Value(final String parameter67Value) { this.parameter67Value = parameter67Value; return this; } - public SiprecCreator setParameter68Name(final String parameter68Name){ + + public SiprecCreator setParameter68Name(final String parameter68Name) { this.parameter68Name = parameter68Name; return this; } - public SiprecCreator setParameter68Value(final String parameter68Value){ + + public SiprecCreator setParameter68Value(final String parameter68Value) { this.parameter68Value = parameter68Value; return this; } - public SiprecCreator setParameter69Name(final String parameter69Name){ + + public SiprecCreator setParameter69Name(final String parameter69Name) { this.parameter69Name = parameter69Name; return this; } - public SiprecCreator setParameter69Value(final String parameter69Value){ + + public SiprecCreator setParameter69Value(final String parameter69Value) { this.parameter69Value = parameter69Value; return this; } - public SiprecCreator setParameter70Name(final String parameter70Name){ + + public SiprecCreator setParameter70Name(final String parameter70Name) { this.parameter70Name = parameter70Name; return this; } - public SiprecCreator setParameter70Value(final String parameter70Value){ + + public SiprecCreator setParameter70Value(final String parameter70Value) { this.parameter70Value = parameter70Value; return this; } - public SiprecCreator setParameter71Name(final String parameter71Name){ + + public SiprecCreator setParameter71Name(final String parameter71Name) { this.parameter71Name = parameter71Name; return this; } - public SiprecCreator setParameter71Value(final String parameter71Value){ + + public SiprecCreator setParameter71Value(final String parameter71Value) { this.parameter71Value = parameter71Value; return this; } - public SiprecCreator setParameter72Name(final String parameter72Name){ + + public SiprecCreator setParameter72Name(final String parameter72Name) { this.parameter72Name = parameter72Name; return this; } - public SiprecCreator setParameter72Value(final String parameter72Value){ + + public SiprecCreator setParameter72Value(final String parameter72Value) { this.parameter72Value = parameter72Value; return this; } - public SiprecCreator setParameter73Name(final String parameter73Name){ + + public SiprecCreator setParameter73Name(final String parameter73Name) { this.parameter73Name = parameter73Name; return this; } - public SiprecCreator setParameter73Value(final String parameter73Value){ + + public SiprecCreator setParameter73Value(final String parameter73Value) { this.parameter73Value = parameter73Value; return this; } - public SiprecCreator setParameter74Name(final String parameter74Name){ + + public SiprecCreator setParameter74Name(final String parameter74Name) { this.parameter74Name = parameter74Name; return this; } - public SiprecCreator setParameter74Value(final String parameter74Value){ + + public SiprecCreator setParameter74Value(final String parameter74Value) { this.parameter74Value = parameter74Value; return this; } - public SiprecCreator setParameter75Name(final String parameter75Name){ + + public SiprecCreator setParameter75Name(final String parameter75Name) { this.parameter75Name = parameter75Name; return this; } - public SiprecCreator setParameter75Value(final String parameter75Value){ + + public SiprecCreator setParameter75Value(final String parameter75Value) { this.parameter75Value = parameter75Value; return this; } - public SiprecCreator setParameter76Name(final String parameter76Name){ + + public SiprecCreator setParameter76Name(final String parameter76Name) { this.parameter76Name = parameter76Name; return this; } - public SiprecCreator setParameter76Value(final String parameter76Value){ + + public SiprecCreator setParameter76Value(final String parameter76Value) { this.parameter76Value = parameter76Value; return this; } - public SiprecCreator setParameter77Name(final String parameter77Name){ + + public SiprecCreator setParameter77Name(final String parameter77Name) { this.parameter77Name = parameter77Name; return this; } - public SiprecCreator setParameter77Value(final String parameter77Value){ + + public SiprecCreator setParameter77Value(final String parameter77Value) { this.parameter77Value = parameter77Value; return this; } - public SiprecCreator setParameter78Name(final String parameter78Name){ + + public SiprecCreator setParameter78Name(final String parameter78Name) { this.parameter78Name = parameter78Name; return this; } - public SiprecCreator setParameter78Value(final String parameter78Value){ + + public SiprecCreator setParameter78Value(final String parameter78Value) { this.parameter78Value = parameter78Value; return this; } - public SiprecCreator setParameter79Name(final String parameter79Name){ + + public SiprecCreator setParameter79Name(final String parameter79Name) { this.parameter79Name = parameter79Name; return this; } - public SiprecCreator setParameter79Value(final String parameter79Value){ + + public SiprecCreator setParameter79Value(final String parameter79Value) { this.parameter79Value = parameter79Value; return this; } - public SiprecCreator setParameter80Name(final String parameter80Name){ + + public SiprecCreator setParameter80Name(final String parameter80Name) { this.parameter80Name = parameter80Name; return this; } - public SiprecCreator setParameter80Value(final String parameter80Value){ + + public SiprecCreator setParameter80Value(final String parameter80Value) { this.parameter80Value = parameter80Value; return this; } - public SiprecCreator setParameter81Name(final String parameter81Name){ + + public SiprecCreator setParameter81Name(final String parameter81Name) { this.parameter81Name = parameter81Name; return this; } - public SiprecCreator setParameter81Value(final String parameter81Value){ + + public SiprecCreator setParameter81Value(final String parameter81Value) { this.parameter81Value = parameter81Value; return this; } - public SiprecCreator setParameter82Name(final String parameter82Name){ + + public SiprecCreator setParameter82Name(final String parameter82Name) { this.parameter82Name = parameter82Name; return this; } - public SiprecCreator setParameter82Value(final String parameter82Value){ + + public SiprecCreator setParameter82Value(final String parameter82Value) { this.parameter82Value = parameter82Value; return this; } - public SiprecCreator setParameter83Name(final String parameter83Name){ + + public SiprecCreator setParameter83Name(final String parameter83Name) { this.parameter83Name = parameter83Name; return this; } - public SiprecCreator setParameter83Value(final String parameter83Value){ + + public SiprecCreator setParameter83Value(final String parameter83Value) { this.parameter83Value = parameter83Value; return this; } - public SiprecCreator setParameter84Name(final String parameter84Name){ + + public SiprecCreator setParameter84Name(final String parameter84Name) { this.parameter84Name = parameter84Name; return this; } - public SiprecCreator setParameter84Value(final String parameter84Value){ + + public SiprecCreator setParameter84Value(final String parameter84Value) { this.parameter84Value = parameter84Value; return this; } - public SiprecCreator setParameter85Name(final String parameter85Name){ + + public SiprecCreator setParameter85Name(final String parameter85Name) { this.parameter85Name = parameter85Name; return this; } - public SiprecCreator setParameter85Value(final String parameter85Value){ + + public SiprecCreator setParameter85Value(final String parameter85Value) { this.parameter85Value = parameter85Value; return this; } - public SiprecCreator setParameter86Name(final String parameter86Name){ + + public SiprecCreator setParameter86Name(final String parameter86Name) { this.parameter86Name = parameter86Name; return this; } - public SiprecCreator setParameter86Value(final String parameter86Value){ + + public SiprecCreator setParameter86Value(final String parameter86Value) { this.parameter86Value = parameter86Value; return this; } - public SiprecCreator setParameter87Name(final String parameter87Name){ + + public SiprecCreator setParameter87Name(final String parameter87Name) { this.parameter87Name = parameter87Name; return this; } - public SiprecCreator setParameter87Value(final String parameter87Value){ + + public SiprecCreator setParameter87Value(final String parameter87Value) { this.parameter87Value = parameter87Value; return this; } - public SiprecCreator setParameter88Name(final String parameter88Name){ + + public SiprecCreator setParameter88Name(final String parameter88Name) { this.parameter88Name = parameter88Name; return this; } - public SiprecCreator setParameter88Value(final String parameter88Value){ + + public SiprecCreator setParameter88Value(final String parameter88Value) { this.parameter88Value = parameter88Value; return this; } - public SiprecCreator setParameter89Name(final String parameter89Name){ + + public SiprecCreator setParameter89Name(final String parameter89Name) { this.parameter89Name = parameter89Name; return this; } - public SiprecCreator setParameter89Value(final String parameter89Value){ + + public SiprecCreator setParameter89Value(final String parameter89Value) { this.parameter89Value = parameter89Value; return this; } - public SiprecCreator setParameter90Name(final String parameter90Name){ + + public SiprecCreator setParameter90Name(final String parameter90Name) { this.parameter90Name = parameter90Name; return this; } - public SiprecCreator setParameter90Value(final String parameter90Value){ + + public SiprecCreator setParameter90Value(final String parameter90Value) { this.parameter90Value = parameter90Value; return this; } - public SiprecCreator setParameter91Name(final String parameter91Name){ + + public SiprecCreator setParameter91Name(final String parameter91Name) { this.parameter91Name = parameter91Name; return this; } - public SiprecCreator setParameter91Value(final String parameter91Value){ + + public SiprecCreator setParameter91Value(final String parameter91Value) { this.parameter91Value = parameter91Value; return this; } - public SiprecCreator setParameter92Name(final String parameter92Name){ + + public SiprecCreator setParameter92Name(final String parameter92Name) { this.parameter92Name = parameter92Name; return this; } - public SiprecCreator setParameter92Value(final String parameter92Value){ + + public SiprecCreator setParameter92Value(final String parameter92Value) { this.parameter92Value = parameter92Value; return this; } - public SiprecCreator setParameter93Name(final String parameter93Name){ + + public SiprecCreator setParameter93Name(final String parameter93Name) { this.parameter93Name = parameter93Name; return this; } - public SiprecCreator setParameter93Value(final String parameter93Value){ + + public SiprecCreator setParameter93Value(final String parameter93Value) { this.parameter93Value = parameter93Value; return this; } - public SiprecCreator setParameter94Name(final String parameter94Name){ + + public SiprecCreator setParameter94Name(final String parameter94Name) { this.parameter94Name = parameter94Name; return this; } - public SiprecCreator setParameter94Value(final String parameter94Value){ + + public SiprecCreator setParameter94Value(final String parameter94Value) { this.parameter94Value = parameter94Value; return this; } - public SiprecCreator setParameter95Name(final String parameter95Name){ + + public SiprecCreator setParameter95Name(final String parameter95Name) { this.parameter95Name = parameter95Name; return this; } - public SiprecCreator setParameter95Value(final String parameter95Value){ + + public SiprecCreator setParameter95Value(final String parameter95Value) { this.parameter95Value = parameter95Value; return this; } - public SiprecCreator setParameter96Name(final String parameter96Name){ + + public SiprecCreator setParameter96Name(final String parameter96Name) { this.parameter96Name = parameter96Name; return this; } - public SiprecCreator setParameter96Value(final String parameter96Value){ + + public SiprecCreator setParameter96Value(final String parameter96Value) { this.parameter96Value = parameter96Value; return this; } - public SiprecCreator setParameter97Name(final String parameter97Name){ + + public SiprecCreator setParameter97Name(final String parameter97Name) { this.parameter97Name = parameter97Name; return this; } - public SiprecCreator setParameter97Value(final String parameter97Value){ + + public SiprecCreator setParameter97Value(final String parameter97Value) { this.parameter97Value = parameter97Value; return this; } - public SiprecCreator setParameter98Name(final String parameter98Name){ + + public SiprecCreator setParameter98Name(final String parameter98Name) { this.parameter98Name = parameter98Name; return this; } - public SiprecCreator setParameter98Value(final String parameter98Value){ + + public SiprecCreator setParameter98Value(final String parameter98Value) { this.parameter98Value = parameter98Value; return this; } - public SiprecCreator setParameter99Name(final String parameter99Name){ + + public SiprecCreator setParameter99Name(final String parameter99Name) { this.parameter99Name = parameter99Name; return this; } - public SiprecCreator setParameter99Value(final String parameter99Value){ + + public SiprecCreator setParameter99Value(final String parameter99Value) { this.parameter99Value = parameter99Value; return this; } @Override - public Siprec create(final TwilioRestClient client){ - String path = "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Siprec.json"; + public Siprec create(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Siprec.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"CallSid"+"}", this.pathCallSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "CallSid" + "}", this.pathCallSid.toString()); Request request = new Request( HttpMethod.POST, Domains.API.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Siprec creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Siprec creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -1089,818 +1310,619 @@ public Siprec create(final TwilioRestClient client){ return Siprec.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (name != null) { request.addPostParam("Name", name); - } if (connectorName != null) { request.addPostParam("ConnectorName", connectorName); - } if (track != null) { request.addPostParam("Track", track.toString()); - } if (statusCallback != null) { request.addPostParam("StatusCallback", statusCallback.toString()); - } if (statusCallbackMethod != null) { - request.addPostParam("StatusCallbackMethod", statusCallbackMethod.toString()); - + request.addPostParam( + "StatusCallbackMethod", + statusCallbackMethod.toString() + ); } if (parameter1Name != null) { request.addPostParam("Parameter1.Name", parameter1Name); - } if (parameter1Value != null) { request.addPostParam("Parameter1.Value", parameter1Value); - } if (parameter2Name != null) { request.addPostParam("Parameter2.Name", parameter2Name); - } if (parameter2Value != null) { request.addPostParam("Parameter2.Value", parameter2Value); - } if (parameter3Name != null) { request.addPostParam("Parameter3.Name", parameter3Name); - } if (parameter3Value != null) { request.addPostParam("Parameter3.Value", parameter3Value); - } if (parameter4Name != null) { request.addPostParam("Parameter4.Name", parameter4Name); - } if (parameter4Value != null) { request.addPostParam("Parameter4.Value", parameter4Value); - } if (parameter5Name != null) { request.addPostParam("Parameter5.Name", parameter5Name); - } if (parameter5Value != null) { request.addPostParam("Parameter5.Value", parameter5Value); - } if (parameter6Name != null) { request.addPostParam("Parameter6.Name", parameter6Name); - } if (parameter6Value != null) { request.addPostParam("Parameter6.Value", parameter6Value); - } if (parameter7Name != null) { request.addPostParam("Parameter7.Name", parameter7Name); - } if (parameter7Value != null) { request.addPostParam("Parameter7.Value", parameter7Value); - } if (parameter8Name != null) { request.addPostParam("Parameter8.Name", parameter8Name); - } if (parameter8Value != null) { request.addPostParam("Parameter8.Value", parameter8Value); - } if (parameter9Name != null) { request.addPostParam("Parameter9.Name", parameter9Name); - } if (parameter9Value != null) { request.addPostParam("Parameter9.Value", parameter9Value); - } if (parameter10Name != null) { request.addPostParam("Parameter10.Name", parameter10Name); - } if (parameter10Value != null) { request.addPostParam("Parameter10.Value", parameter10Value); - } if (parameter11Name != null) { request.addPostParam("Parameter11.Name", parameter11Name); - } if (parameter11Value != null) { request.addPostParam("Parameter11.Value", parameter11Value); - } if (parameter12Name != null) { request.addPostParam("Parameter12.Name", parameter12Name); - } if (parameter12Value != null) { request.addPostParam("Parameter12.Value", parameter12Value); - } if (parameter13Name != null) { request.addPostParam("Parameter13.Name", parameter13Name); - } if (parameter13Value != null) { request.addPostParam("Parameter13.Value", parameter13Value); - } if (parameter14Name != null) { request.addPostParam("Parameter14.Name", parameter14Name); - } if (parameter14Value != null) { request.addPostParam("Parameter14.Value", parameter14Value); - } if (parameter15Name != null) { request.addPostParam("Parameter15.Name", parameter15Name); - } if (parameter15Value != null) { request.addPostParam("Parameter15.Value", parameter15Value); - } if (parameter16Name != null) { request.addPostParam("Parameter16.Name", parameter16Name); - } if (parameter16Value != null) { request.addPostParam("Parameter16.Value", parameter16Value); - } if (parameter17Name != null) { request.addPostParam("Parameter17.Name", parameter17Name); - } if (parameter17Value != null) { request.addPostParam("Parameter17.Value", parameter17Value); - } if (parameter18Name != null) { request.addPostParam("Parameter18.Name", parameter18Name); - } if (parameter18Value != null) { request.addPostParam("Parameter18.Value", parameter18Value); - } if (parameter19Name != null) { request.addPostParam("Parameter19.Name", parameter19Name); - } if (parameter19Value != null) { request.addPostParam("Parameter19.Value", parameter19Value); - } if (parameter20Name != null) { request.addPostParam("Parameter20.Name", parameter20Name); - } if (parameter20Value != null) { request.addPostParam("Parameter20.Value", parameter20Value); - } if (parameter21Name != null) { request.addPostParam("Parameter21.Name", parameter21Name); - } if (parameter21Value != null) { request.addPostParam("Parameter21.Value", parameter21Value); - } if (parameter22Name != null) { request.addPostParam("Parameter22.Name", parameter22Name); - } if (parameter22Value != null) { request.addPostParam("Parameter22.Value", parameter22Value); - } if (parameter23Name != null) { request.addPostParam("Parameter23.Name", parameter23Name); - } if (parameter23Value != null) { request.addPostParam("Parameter23.Value", parameter23Value); - } if (parameter24Name != null) { request.addPostParam("Parameter24.Name", parameter24Name); - } if (parameter24Value != null) { request.addPostParam("Parameter24.Value", parameter24Value); - } if (parameter25Name != null) { request.addPostParam("Parameter25.Name", parameter25Name); - } if (parameter25Value != null) { request.addPostParam("Parameter25.Value", parameter25Value); - } if (parameter26Name != null) { request.addPostParam("Parameter26.Name", parameter26Name); - } if (parameter26Value != null) { request.addPostParam("Parameter26.Value", parameter26Value); - } if (parameter27Name != null) { request.addPostParam("Parameter27.Name", parameter27Name); - } if (parameter27Value != null) { request.addPostParam("Parameter27.Value", parameter27Value); - } if (parameter28Name != null) { request.addPostParam("Parameter28.Name", parameter28Name); - } if (parameter28Value != null) { request.addPostParam("Parameter28.Value", parameter28Value); - } if (parameter29Name != null) { request.addPostParam("Parameter29.Name", parameter29Name); - } if (parameter29Value != null) { request.addPostParam("Parameter29.Value", parameter29Value); - } if (parameter30Name != null) { request.addPostParam("Parameter30.Name", parameter30Name); - } if (parameter30Value != null) { request.addPostParam("Parameter30.Value", parameter30Value); - } if (parameter31Name != null) { request.addPostParam("Parameter31.Name", parameter31Name); - } if (parameter31Value != null) { request.addPostParam("Parameter31.Value", parameter31Value); - } if (parameter32Name != null) { request.addPostParam("Parameter32.Name", parameter32Name); - } if (parameter32Value != null) { request.addPostParam("Parameter32.Value", parameter32Value); - } if (parameter33Name != null) { request.addPostParam("Parameter33.Name", parameter33Name); - } if (parameter33Value != null) { request.addPostParam("Parameter33.Value", parameter33Value); - } if (parameter34Name != null) { request.addPostParam("Parameter34.Name", parameter34Name); - } if (parameter34Value != null) { request.addPostParam("Parameter34.Value", parameter34Value); - } if (parameter35Name != null) { request.addPostParam("Parameter35.Name", parameter35Name); - } if (parameter35Value != null) { request.addPostParam("Parameter35.Value", parameter35Value); - } if (parameter36Name != null) { request.addPostParam("Parameter36.Name", parameter36Name); - } if (parameter36Value != null) { request.addPostParam("Parameter36.Value", parameter36Value); - } if (parameter37Name != null) { request.addPostParam("Parameter37.Name", parameter37Name); - } if (parameter37Value != null) { request.addPostParam("Parameter37.Value", parameter37Value); - } if (parameter38Name != null) { request.addPostParam("Parameter38.Name", parameter38Name); - } if (parameter38Value != null) { request.addPostParam("Parameter38.Value", parameter38Value); - } if (parameter39Name != null) { request.addPostParam("Parameter39.Name", parameter39Name); - } if (parameter39Value != null) { request.addPostParam("Parameter39.Value", parameter39Value); - } if (parameter40Name != null) { request.addPostParam("Parameter40.Name", parameter40Name); - } if (parameter40Value != null) { request.addPostParam("Parameter40.Value", parameter40Value); - } if (parameter41Name != null) { request.addPostParam("Parameter41.Name", parameter41Name); - } if (parameter41Value != null) { request.addPostParam("Parameter41.Value", parameter41Value); - } if (parameter42Name != null) { request.addPostParam("Parameter42.Name", parameter42Name); - } if (parameter42Value != null) { request.addPostParam("Parameter42.Value", parameter42Value); - } if (parameter43Name != null) { request.addPostParam("Parameter43.Name", parameter43Name); - } if (parameter43Value != null) { request.addPostParam("Parameter43.Value", parameter43Value); - } if (parameter44Name != null) { request.addPostParam("Parameter44.Name", parameter44Name); - } if (parameter44Value != null) { request.addPostParam("Parameter44.Value", parameter44Value); - } if (parameter45Name != null) { request.addPostParam("Parameter45.Name", parameter45Name); - } if (parameter45Value != null) { request.addPostParam("Parameter45.Value", parameter45Value); - } if (parameter46Name != null) { request.addPostParam("Parameter46.Name", parameter46Name); - } if (parameter46Value != null) { request.addPostParam("Parameter46.Value", parameter46Value); - } if (parameter47Name != null) { request.addPostParam("Parameter47.Name", parameter47Name); - } if (parameter47Value != null) { request.addPostParam("Parameter47.Value", parameter47Value); - } if (parameter48Name != null) { request.addPostParam("Parameter48.Name", parameter48Name); - } if (parameter48Value != null) { request.addPostParam("Parameter48.Value", parameter48Value); - } if (parameter49Name != null) { request.addPostParam("Parameter49.Name", parameter49Name); - } if (parameter49Value != null) { request.addPostParam("Parameter49.Value", parameter49Value); - } if (parameter50Name != null) { request.addPostParam("Parameter50.Name", parameter50Name); - } if (parameter50Value != null) { request.addPostParam("Parameter50.Value", parameter50Value); - } if (parameter51Name != null) { request.addPostParam("Parameter51.Name", parameter51Name); - } if (parameter51Value != null) { request.addPostParam("Parameter51.Value", parameter51Value); - } if (parameter52Name != null) { request.addPostParam("Parameter52.Name", parameter52Name); - } if (parameter52Value != null) { request.addPostParam("Parameter52.Value", parameter52Value); - } if (parameter53Name != null) { request.addPostParam("Parameter53.Name", parameter53Name); - } if (parameter53Value != null) { request.addPostParam("Parameter53.Value", parameter53Value); - } if (parameter54Name != null) { request.addPostParam("Parameter54.Name", parameter54Name); - } if (parameter54Value != null) { request.addPostParam("Parameter54.Value", parameter54Value); - } if (parameter55Name != null) { request.addPostParam("Parameter55.Name", parameter55Name); - } if (parameter55Value != null) { request.addPostParam("Parameter55.Value", parameter55Value); - } if (parameter56Name != null) { request.addPostParam("Parameter56.Name", parameter56Name); - } if (parameter56Value != null) { request.addPostParam("Parameter56.Value", parameter56Value); - } if (parameter57Name != null) { request.addPostParam("Parameter57.Name", parameter57Name); - } if (parameter57Value != null) { request.addPostParam("Parameter57.Value", parameter57Value); - } if (parameter58Name != null) { request.addPostParam("Parameter58.Name", parameter58Name); - } if (parameter58Value != null) { request.addPostParam("Parameter58.Value", parameter58Value); - } if (parameter59Name != null) { request.addPostParam("Parameter59.Name", parameter59Name); - } if (parameter59Value != null) { request.addPostParam("Parameter59.Value", parameter59Value); - } if (parameter60Name != null) { request.addPostParam("Parameter60.Name", parameter60Name); - } if (parameter60Value != null) { request.addPostParam("Parameter60.Value", parameter60Value); - } if (parameter61Name != null) { request.addPostParam("Parameter61.Name", parameter61Name); - } if (parameter61Value != null) { request.addPostParam("Parameter61.Value", parameter61Value); - } if (parameter62Name != null) { request.addPostParam("Parameter62.Name", parameter62Name); - } if (parameter62Value != null) { request.addPostParam("Parameter62.Value", parameter62Value); - } if (parameter63Name != null) { request.addPostParam("Parameter63.Name", parameter63Name); - } if (parameter63Value != null) { request.addPostParam("Parameter63.Value", parameter63Value); - } if (parameter64Name != null) { request.addPostParam("Parameter64.Name", parameter64Name); - } if (parameter64Value != null) { request.addPostParam("Parameter64.Value", parameter64Value); - } if (parameter65Name != null) { request.addPostParam("Parameter65.Name", parameter65Name); - } if (parameter65Value != null) { request.addPostParam("Parameter65.Value", parameter65Value); - } if (parameter66Name != null) { request.addPostParam("Parameter66.Name", parameter66Name); - } if (parameter66Value != null) { request.addPostParam("Parameter66.Value", parameter66Value); - } if (parameter67Name != null) { request.addPostParam("Parameter67.Name", parameter67Name); - } if (parameter67Value != null) { request.addPostParam("Parameter67.Value", parameter67Value); - } if (parameter68Name != null) { request.addPostParam("Parameter68.Name", parameter68Name); - } if (parameter68Value != null) { request.addPostParam("Parameter68.Value", parameter68Value); - } if (parameter69Name != null) { request.addPostParam("Parameter69.Name", parameter69Name); - } if (parameter69Value != null) { request.addPostParam("Parameter69.Value", parameter69Value); - } if (parameter70Name != null) { request.addPostParam("Parameter70.Name", parameter70Name); - } if (parameter70Value != null) { request.addPostParam("Parameter70.Value", parameter70Value); - } if (parameter71Name != null) { request.addPostParam("Parameter71.Name", parameter71Name); - } if (parameter71Value != null) { request.addPostParam("Parameter71.Value", parameter71Value); - } if (parameter72Name != null) { request.addPostParam("Parameter72.Name", parameter72Name); - } if (parameter72Value != null) { request.addPostParam("Parameter72.Value", parameter72Value); - } if (parameter73Name != null) { request.addPostParam("Parameter73.Name", parameter73Name); - } if (parameter73Value != null) { request.addPostParam("Parameter73.Value", parameter73Value); - } if (parameter74Name != null) { request.addPostParam("Parameter74.Name", parameter74Name); - } if (parameter74Value != null) { request.addPostParam("Parameter74.Value", parameter74Value); - } if (parameter75Name != null) { request.addPostParam("Parameter75.Name", parameter75Name); - } if (parameter75Value != null) { request.addPostParam("Parameter75.Value", parameter75Value); - } if (parameter76Name != null) { request.addPostParam("Parameter76.Name", parameter76Name); - } if (parameter76Value != null) { request.addPostParam("Parameter76.Value", parameter76Value); - } if (parameter77Name != null) { request.addPostParam("Parameter77.Name", parameter77Name); - } if (parameter77Value != null) { request.addPostParam("Parameter77.Value", parameter77Value); - } if (parameter78Name != null) { request.addPostParam("Parameter78.Name", parameter78Name); - } if (parameter78Value != null) { request.addPostParam("Parameter78.Value", parameter78Value); - } if (parameter79Name != null) { request.addPostParam("Parameter79.Name", parameter79Name); - } if (parameter79Value != null) { request.addPostParam("Parameter79.Value", parameter79Value); - } if (parameter80Name != null) { request.addPostParam("Parameter80.Name", parameter80Name); - } if (parameter80Value != null) { request.addPostParam("Parameter80.Value", parameter80Value); - } if (parameter81Name != null) { request.addPostParam("Parameter81.Name", parameter81Name); - } if (parameter81Value != null) { request.addPostParam("Parameter81.Value", parameter81Value); - } if (parameter82Name != null) { request.addPostParam("Parameter82.Name", parameter82Name); - } if (parameter82Value != null) { request.addPostParam("Parameter82.Value", parameter82Value); - } if (parameter83Name != null) { request.addPostParam("Parameter83.Name", parameter83Name); - } if (parameter83Value != null) { request.addPostParam("Parameter83.Value", parameter83Value); - } if (parameter84Name != null) { request.addPostParam("Parameter84.Name", parameter84Name); - } if (parameter84Value != null) { request.addPostParam("Parameter84.Value", parameter84Value); - } if (parameter85Name != null) { request.addPostParam("Parameter85.Name", parameter85Name); - } if (parameter85Value != null) { request.addPostParam("Parameter85.Value", parameter85Value); - } if (parameter86Name != null) { request.addPostParam("Parameter86.Name", parameter86Name); - } if (parameter86Value != null) { request.addPostParam("Parameter86.Value", parameter86Value); - } if (parameter87Name != null) { request.addPostParam("Parameter87.Name", parameter87Name); - } if (parameter87Value != null) { request.addPostParam("Parameter87.Value", parameter87Value); - } if (parameter88Name != null) { request.addPostParam("Parameter88.Name", parameter88Name); - } if (parameter88Value != null) { request.addPostParam("Parameter88.Value", parameter88Value); - } if (parameter89Name != null) { request.addPostParam("Parameter89.Name", parameter89Name); - } if (parameter89Value != null) { request.addPostParam("Parameter89.Value", parameter89Value); - } if (parameter90Name != null) { request.addPostParam("Parameter90.Name", parameter90Name); - } if (parameter90Value != null) { request.addPostParam("Parameter90.Value", parameter90Value); - } if (parameter91Name != null) { request.addPostParam("Parameter91.Name", parameter91Name); - } if (parameter91Value != null) { request.addPostParam("Parameter91.Value", parameter91Value); - } if (parameter92Name != null) { request.addPostParam("Parameter92.Name", parameter92Name); - } if (parameter92Value != null) { request.addPostParam("Parameter92.Value", parameter92Value); - } if (parameter93Name != null) { request.addPostParam("Parameter93.Name", parameter93Name); - } if (parameter93Value != null) { request.addPostParam("Parameter93.Value", parameter93Value); - } if (parameter94Name != null) { request.addPostParam("Parameter94.Name", parameter94Name); - } if (parameter94Value != null) { request.addPostParam("Parameter94.Value", parameter94Value); - } if (parameter95Name != null) { request.addPostParam("Parameter95.Name", parameter95Name); - } if (parameter95Value != null) { request.addPostParam("Parameter95.Value", parameter95Value); - } if (parameter96Name != null) { request.addPostParam("Parameter96.Name", parameter96Name); - } if (parameter96Value != null) { request.addPostParam("Parameter96.Value", parameter96Value); - } if (parameter97Name != null) { request.addPostParam("Parameter97.Name", parameter97Name); - } if (parameter97Value != null) { request.addPostParam("Parameter97.Value", parameter97Value); - } if (parameter98Name != null) { request.addPostParam("Parameter98.Name", parameter98Name); - } if (parameter98Value != null) { request.addPostParam("Parameter98.Value", parameter98Value); - } if (parameter99Name != null) { request.addPostParam("Parameter99.Name", parameter99Name); - } if (parameter99Value != null) { request.addPostParam("Parameter99.Value", parameter99Value); - } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/SiprecUpdater.java b/src/main/java/com/twilio/rest/api/v2010/account/call/SiprecUpdater.java index 1dc1698349..a0185b531b 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/call/SiprecUpdater.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/call/SiprecUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010.account.call; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,53 +25,75 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class SiprecUpdater extends Updater { - - -public class SiprecUpdater extends Updater{ private String pathCallSid; private String pathSid; private Siprec.UpdateStatus status; private String pathAccountSid; - public SiprecUpdater(final String pathCallSid, final String pathSid, final Siprec.UpdateStatus status){ + public SiprecUpdater( + final String pathCallSid, + final String pathSid, + final Siprec.UpdateStatus status + ) { this.pathCallSid = pathCallSid; this.pathSid = pathSid; this.status = status; } - public SiprecUpdater(final String pathAccountSid, final String pathCallSid, final String pathSid, final Siprec.UpdateStatus status){ + + public SiprecUpdater( + final String pathAccountSid, + final String pathCallSid, + final String pathSid, + final Siprec.UpdateStatus status + ) { this.pathAccountSid = pathAccountSid; this.pathCallSid = pathCallSid; this.pathSid = pathSid; this.status = status; } - public SiprecUpdater setStatus(final Siprec.UpdateStatus status){ + public SiprecUpdater setStatus(final Siprec.UpdateStatus status) { this.status = status; return this; } @Override - public Siprec update(final TwilioRestClient client){ - String path = "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Siprec/{Sid}.json"; + public Siprec update(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Siprec/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"CallSid"+"}", this.pathCallSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); - path = path.replace("{"+"Status"+"}", this.status.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "CallSid" + "}", this.pathCallSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + path = path.replace("{" + "Status" + "}", this.status.toString()); Request request = new Request( HttpMethod.POST, Domains.API.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Siprec update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Siprec update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -79,10 +102,10 @@ public Siprec update(final TwilioRestClient client){ return Siprec.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (status != null) { request.addPostParam("Status", status.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/Stream.java b/src/main/java/com/twilio/rest/api/v2010/account/call/Stream.java index 3317a9ffa2..b2ce666175 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/call/Stream.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/call/Stream.java @@ -24,47 +24,64 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Stream extends Resource { + private static final long serialVersionUID = 189203494840345L; - public static StreamCreator creator(final String pathCallSid, final URI url){ + public static StreamCreator creator( + final String pathCallSid, + final URI url + ) { return new StreamCreator(pathCallSid, url); } - public static StreamCreator creator(final String pathAccountSid, final String pathCallSid, final URI url){ + + public static StreamCreator creator( + final String pathAccountSid, + final String pathCallSid, + final URI url + ) { return new StreamCreator(pathAccountSid, pathCallSid, url); } - public static StreamUpdater updater(final String pathCallSid, final String pathSid, final Stream.UpdateStatus status){ + public static StreamUpdater updater( + final String pathCallSid, + final String pathSid, + final Stream.UpdateStatus status + ) { return new StreamUpdater(pathCallSid, pathSid, status); } - public static StreamUpdater updater(final String pathAccountSid, final String pathCallSid, final String pathSid, final Stream.UpdateStatus status){ + + public static StreamUpdater updater( + final String pathAccountSid, + final String pathCallSid, + final String pathSid, + final Stream.UpdateStatus status + ) { return new StreamUpdater(pathAccountSid, pathCallSid, pathSid, status); } /** - * Converts a JSON String into a Stream object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Stream object represented by the provided JSON - */ - public static Stream fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Stream object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Stream object represented by the provided JSON + */ + public static Stream fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Stream.class); @@ -76,14 +93,17 @@ public static Stream fromJson(final String json, final ObjectMapper objectMapper } /** - * Converts a JSON InputStream into a Stream object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Stream object represented by the provided JSON - */ - public static Stream fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Stream object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Stream object represented by the provided JSON + */ + public static Stream fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Stream.class); @@ -93,6 +113,7 @@ public static Stream fromJson(final InputStream json, final ObjectMapper objectM throw new ApiConnectionException(e.getMessage(), e); } } + public enum Status { IN_PROGRESS("in-progress"), STOPPED("stopped"); @@ -112,6 +133,7 @@ public static Status forValue(final String value) { return Promoter.enumFromString(value, Status.values()); } } + public enum Track { INBOUND_TRACK("inbound_track"), OUTBOUND_TRACK("outbound_track"), @@ -132,6 +154,7 @@ public static Track forValue(final String value) { return Promoter.enumFromString(value, Track.values()); } } + public enum UpdateStatus { STOPPED("stopped"); @@ -161,26 +184,13 @@ public static UpdateStatus forValue(final String value) { @JsonCreator private Stream( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("call_sid") - final String callSid, - - @JsonProperty("name") - final String name, - - @JsonProperty("status") - final Stream.Status status, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("uri") - final String uri + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("call_sid") final String callSid, + @JsonProperty("name") final String name, + @JsonProperty("status") final Stream.Status status, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("uri") final String uri ) { this.sid = sid; this.accountSid = accountSid; @@ -191,31 +201,37 @@ private Stream( this.uri = uri; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getCallSid() { - return this.callSid; - } - public final String getName() { - return this.name; - } - public final Stream.Status getStatus() { - return this.status; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getUri() { - return this.uri; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getCallSid() { + return this.callSid; + } + + public final String getName() { + return this.name; + } + + public final Stream.Status getStatus() { + return this.status; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getUri() { + return this.uri; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -225,13 +241,27 @@ public boolean equals(final Object o) { Stream other = (Stream) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(callSid, other.callSid) && Objects.equals(name, other.name) && Objects.equals(status, other.status) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(uri, other.uri) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(callSid, other.callSid) && + Objects.equals(name, other.name) && + Objects.equals(status, other.status) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(uri, other.uri) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, callSid, name, status, dateUpdated, uri); + return Objects.hash( + sid, + accountSid, + callSid, + name, + status, + dateUpdated, + uri + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/StreamCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/call/StreamCreator.java index 08104728fe..b811a98c4c 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/call/StreamCreator.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/call/StreamCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010.account.call; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -25,12 +26,10 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.net.URI; - - - import java.net.URI; -public class StreamCreator extends Creator{ +public class StreamCreator extends Creator { + private String pathCallSid; private URI url; private String pathAccountSid; @@ -241,853 +240,1076 @@ public StreamCreator(final String pathCallSid, final URI url) { this.pathCallSid = pathCallSid; this.url = url; } - public StreamCreator(final String pathAccountSid, final String pathCallSid, final URI url) { + + public StreamCreator( + final String pathAccountSid, + final String pathCallSid, + final URI url + ) { this.pathAccountSid = pathAccountSid; this.pathCallSid = pathCallSid; this.url = url; } - public StreamCreator setUrl(final URI url){ + public StreamCreator setUrl(final URI url) { this.url = url; return this; } - public StreamCreator setUrl(final String url){ + public StreamCreator setUrl(final String url) { return setUrl(Promoter.uriFromString(url)); } - public StreamCreator setName(final String name){ + + public StreamCreator setName(final String name) { this.name = name; return this; } - public StreamCreator setTrack(final Stream.Track track){ + + public StreamCreator setTrack(final Stream.Track track) { this.track = track; return this; } - public StreamCreator setStatusCallback(final URI statusCallback){ + + public StreamCreator setStatusCallback(final URI statusCallback) { this.statusCallback = statusCallback; return this; } - public StreamCreator setStatusCallback(final String statusCallback){ + public StreamCreator setStatusCallback(final String statusCallback) { return setStatusCallback(Promoter.uriFromString(statusCallback)); } - public StreamCreator setStatusCallbackMethod(final HttpMethod statusCallbackMethod){ + + public StreamCreator setStatusCallbackMethod( + final HttpMethod statusCallbackMethod + ) { this.statusCallbackMethod = statusCallbackMethod; return this; } - public StreamCreator setParameter1Name(final String parameter1Name){ + + public StreamCreator setParameter1Name(final String parameter1Name) { this.parameter1Name = parameter1Name; return this; } - public StreamCreator setParameter1Value(final String parameter1Value){ + + public StreamCreator setParameter1Value(final String parameter1Value) { this.parameter1Value = parameter1Value; return this; } - public StreamCreator setParameter2Name(final String parameter2Name){ + + public StreamCreator setParameter2Name(final String parameter2Name) { this.parameter2Name = parameter2Name; return this; } - public StreamCreator setParameter2Value(final String parameter2Value){ + + public StreamCreator setParameter2Value(final String parameter2Value) { this.parameter2Value = parameter2Value; return this; } - public StreamCreator setParameter3Name(final String parameter3Name){ + + public StreamCreator setParameter3Name(final String parameter3Name) { this.parameter3Name = parameter3Name; return this; } - public StreamCreator setParameter3Value(final String parameter3Value){ + + public StreamCreator setParameter3Value(final String parameter3Value) { this.parameter3Value = parameter3Value; return this; } - public StreamCreator setParameter4Name(final String parameter4Name){ + + public StreamCreator setParameter4Name(final String parameter4Name) { this.parameter4Name = parameter4Name; return this; } - public StreamCreator setParameter4Value(final String parameter4Value){ + + public StreamCreator setParameter4Value(final String parameter4Value) { this.parameter4Value = parameter4Value; return this; } - public StreamCreator setParameter5Name(final String parameter5Name){ + + public StreamCreator setParameter5Name(final String parameter5Name) { this.parameter5Name = parameter5Name; return this; } - public StreamCreator setParameter5Value(final String parameter5Value){ + + public StreamCreator setParameter5Value(final String parameter5Value) { this.parameter5Value = parameter5Value; return this; } - public StreamCreator setParameter6Name(final String parameter6Name){ + + public StreamCreator setParameter6Name(final String parameter6Name) { this.parameter6Name = parameter6Name; return this; } - public StreamCreator setParameter6Value(final String parameter6Value){ + + public StreamCreator setParameter6Value(final String parameter6Value) { this.parameter6Value = parameter6Value; return this; } - public StreamCreator setParameter7Name(final String parameter7Name){ + + public StreamCreator setParameter7Name(final String parameter7Name) { this.parameter7Name = parameter7Name; return this; } - public StreamCreator setParameter7Value(final String parameter7Value){ + + public StreamCreator setParameter7Value(final String parameter7Value) { this.parameter7Value = parameter7Value; return this; } - public StreamCreator setParameter8Name(final String parameter8Name){ + + public StreamCreator setParameter8Name(final String parameter8Name) { this.parameter8Name = parameter8Name; return this; } - public StreamCreator setParameter8Value(final String parameter8Value){ + + public StreamCreator setParameter8Value(final String parameter8Value) { this.parameter8Value = parameter8Value; return this; } - public StreamCreator setParameter9Name(final String parameter9Name){ + + public StreamCreator setParameter9Name(final String parameter9Name) { this.parameter9Name = parameter9Name; return this; } - public StreamCreator setParameter9Value(final String parameter9Value){ + + public StreamCreator setParameter9Value(final String parameter9Value) { this.parameter9Value = parameter9Value; return this; } - public StreamCreator setParameter10Name(final String parameter10Name){ + + public StreamCreator setParameter10Name(final String parameter10Name) { this.parameter10Name = parameter10Name; return this; } - public StreamCreator setParameter10Value(final String parameter10Value){ + + public StreamCreator setParameter10Value(final String parameter10Value) { this.parameter10Value = parameter10Value; return this; } - public StreamCreator setParameter11Name(final String parameter11Name){ + + public StreamCreator setParameter11Name(final String parameter11Name) { this.parameter11Name = parameter11Name; return this; } - public StreamCreator setParameter11Value(final String parameter11Value){ + + public StreamCreator setParameter11Value(final String parameter11Value) { this.parameter11Value = parameter11Value; return this; } - public StreamCreator setParameter12Name(final String parameter12Name){ + + public StreamCreator setParameter12Name(final String parameter12Name) { this.parameter12Name = parameter12Name; return this; } - public StreamCreator setParameter12Value(final String parameter12Value){ + + public StreamCreator setParameter12Value(final String parameter12Value) { this.parameter12Value = parameter12Value; return this; } - public StreamCreator setParameter13Name(final String parameter13Name){ + + public StreamCreator setParameter13Name(final String parameter13Name) { this.parameter13Name = parameter13Name; return this; } - public StreamCreator setParameter13Value(final String parameter13Value){ + + public StreamCreator setParameter13Value(final String parameter13Value) { this.parameter13Value = parameter13Value; return this; } - public StreamCreator setParameter14Name(final String parameter14Name){ + + public StreamCreator setParameter14Name(final String parameter14Name) { this.parameter14Name = parameter14Name; return this; } - public StreamCreator setParameter14Value(final String parameter14Value){ + + public StreamCreator setParameter14Value(final String parameter14Value) { this.parameter14Value = parameter14Value; return this; } - public StreamCreator setParameter15Name(final String parameter15Name){ + + public StreamCreator setParameter15Name(final String parameter15Name) { this.parameter15Name = parameter15Name; return this; } - public StreamCreator setParameter15Value(final String parameter15Value){ + + public StreamCreator setParameter15Value(final String parameter15Value) { this.parameter15Value = parameter15Value; return this; } - public StreamCreator setParameter16Name(final String parameter16Name){ + + public StreamCreator setParameter16Name(final String parameter16Name) { this.parameter16Name = parameter16Name; return this; } - public StreamCreator setParameter16Value(final String parameter16Value){ + + public StreamCreator setParameter16Value(final String parameter16Value) { this.parameter16Value = parameter16Value; return this; } - public StreamCreator setParameter17Name(final String parameter17Name){ + + public StreamCreator setParameter17Name(final String parameter17Name) { this.parameter17Name = parameter17Name; return this; } - public StreamCreator setParameter17Value(final String parameter17Value){ + + public StreamCreator setParameter17Value(final String parameter17Value) { this.parameter17Value = parameter17Value; return this; } - public StreamCreator setParameter18Name(final String parameter18Name){ + + public StreamCreator setParameter18Name(final String parameter18Name) { this.parameter18Name = parameter18Name; return this; } - public StreamCreator setParameter18Value(final String parameter18Value){ + + public StreamCreator setParameter18Value(final String parameter18Value) { this.parameter18Value = parameter18Value; return this; } - public StreamCreator setParameter19Name(final String parameter19Name){ + + public StreamCreator setParameter19Name(final String parameter19Name) { this.parameter19Name = parameter19Name; return this; } - public StreamCreator setParameter19Value(final String parameter19Value){ + + public StreamCreator setParameter19Value(final String parameter19Value) { this.parameter19Value = parameter19Value; return this; } - public StreamCreator setParameter20Name(final String parameter20Name){ + + public StreamCreator setParameter20Name(final String parameter20Name) { this.parameter20Name = parameter20Name; return this; } - public StreamCreator setParameter20Value(final String parameter20Value){ + + public StreamCreator setParameter20Value(final String parameter20Value) { this.parameter20Value = parameter20Value; return this; } - public StreamCreator setParameter21Name(final String parameter21Name){ + + public StreamCreator setParameter21Name(final String parameter21Name) { this.parameter21Name = parameter21Name; return this; } - public StreamCreator setParameter21Value(final String parameter21Value){ + + public StreamCreator setParameter21Value(final String parameter21Value) { this.parameter21Value = parameter21Value; return this; } - public StreamCreator setParameter22Name(final String parameter22Name){ + + public StreamCreator setParameter22Name(final String parameter22Name) { this.parameter22Name = parameter22Name; return this; } - public StreamCreator setParameter22Value(final String parameter22Value){ + + public StreamCreator setParameter22Value(final String parameter22Value) { this.parameter22Value = parameter22Value; return this; } - public StreamCreator setParameter23Name(final String parameter23Name){ + + public StreamCreator setParameter23Name(final String parameter23Name) { this.parameter23Name = parameter23Name; return this; } - public StreamCreator setParameter23Value(final String parameter23Value){ + + public StreamCreator setParameter23Value(final String parameter23Value) { this.parameter23Value = parameter23Value; return this; } - public StreamCreator setParameter24Name(final String parameter24Name){ + + public StreamCreator setParameter24Name(final String parameter24Name) { this.parameter24Name = parameter24Name; return this; } - public StreamCreator setParameter24Value(final String parameter24Value){ + + public StreamCreator setParameter24Value(final String parameter24Value) { this.parameter24Value = parameter24Value; return this; } - public StreamCreator setParameter25Name(final String parameter25Name){ + + public StreamCreator setParameter25Name(final String parameter25Name) { this.parameter25Name = parameter25Name; return this; } - public StreamCreator setParameter25Value(final String parameter25Value){ + + public StreamCreator setParameter25Value(final String parameter25Value) { this.parameter25Value = parameter25Value; return this; } - public StreamCreator setParameter26Name(final String parameter26Name){ + + public StreamCreator setParameter26Name(final String parameter26Name) { this.parameter26Name = parameter26Name; return this; } - public StreamCreator setParameter26Value(final String parameter26Value){ + + public StreamCreator setParameter26Value(final String parameter26Value) { this.parameter26Value = parameter26Value; return this; } - public StreamCreator setParameter27Name(final String parameter27Name){ + + public StreamCreator setParameter27Name(final String parameter27Name) { this.parameter27Name = parameter27Name; return this; } - public StreamCreator setParameter27Value(final String parameter27Value){ + + public StreamCreator setParameter27Value(final String parameter27Value) { this.parameter27Value = parameter27Value; return this; } - public StreamCreator setParameter28Name(final String parameter28Name){ + + public StreamCreator setParameter28Name(final String parameter28Name) { this.parameter28Name = parameter28Name; return this; } - public StreamCreator setParameter28Value(final String parameter28Value){ + + public StreamCreator setParameter28Value(final String parameter28Value) { this.parameter28Value = parameter28Value; return this; } - public StreamCreator setParameter29Name(final String parameter29Name){ + + public StreamCreator setParameter29Name(final String parameter29Name) { this.parameter29Name = parameter29Name; return this; } - public StreamCreator setParameter29Value(final String parameter29Value){ + + public StreamCreator setParameter29Value(final String parameter29Value) { this.parameter29Value = parameter29Value; return this; } - public StreamCreator setParameter30Name(final String parameter30Name){ + + public StreamCreator setParameter30Name(final String parameter30Name) { this.parameter30Name = parameter30Name; return this; } - public StreamCreator setParameter30Value(final String parameter30Value){ + + public StreamCreator setParameter30Value(final String parameter30Value) { this.parameter30Value = parameter30Value; return this; } - public StreamCreator setParameter31Name(final String parameter31Name){ + + public StreamCreator setParameter31Name(final String parameter31Name) { this.parameter31Name = parameter31Name; return this; } - public StreamCreator setParameter31Value(final String parameter31Value){ + + public StreamCreator setParameter31Value(final String parameter31Value) { this.parameter31Value = parameter31Value; return this; } - public StreamCreator setParameter32Name(final String parameter32Name){ + + public StreamCreator setParameter32Name(final String parameter32Name) { this.parameter32Name = parameter32Name; return this; } - public StreamCreator setParameter32Value(final String parameter32Value){ + + public StreamCreator setParameter32Value(final String parameter32Value) { this.parameter32Value = parameter32Value; return this; } - public StreamCreator setParameter33Name(final String parameter33Name){ + + public StreamCreator setParameter33Name(final String parameter33Name) { this.parameter33Name = parameter33Name; return this; } - public StreamCreator setParameter33Value(final String parameter33Value){ + + public StreamCreator setParameter33Value(final String parameter33Value) { this.parameter33Value = parameter33Value; return this; } - public StreamCreator setParameter34Name(final String parameter34Name){ + + public StreamCreator setParameter34Name(final String parameter34Name) { this.parameter34Name = parameter34Name; return this; } - public StreamCreator setParameter34Value(final String parameter34Value){ + + public StreamCreator setParameter34Value(final String parameter34Value) { this.parameter34Value = parameter34Value; return this; } - public StreamCreator setParameter35Name(final String parameter35Name){ + + public StreamCreator setParameter35Name(final String parameter35Name) { this.parameter35Name = parameter35Name; return this; } - public StreamCreator setParameter35Value(final String parameter35Value){ + + public StreamCreator setParameter35Value(final String parameter35Value) { this.parameter35Value = parameter35Value; return this; } - public StreamCreator setParameter36Name(final String parameter36Name){ + + public StreamCreator setParameter36Name(final String parameter36Name) { this.parameter36Name = parameter36Name; return this; } - public StreamCreator setParameter36Value(final String parameter36Value){ + + public StreamCreator setParameter36Value(final String parameter36Value) { this.parameter36Value = parameter36Value; return this; } - public StreamCreator setParameter37Name(final String parameter37Name){ + + public StreamCreator setParameter37Name(final String parameter37Name) { this.parameter37Name = parameter37Name; return this; } - public StreamCreator setParameter37Value(final String parameter37Value){ + + public StreamCreator setParameter37Value(final String parameter37Value) { this.parameter37Value = parameter37Value; return this; } - public StreamCreator setParameter38Name(final String parameter38Name){ + + public StreamCreator setParameter38Name(final String parameter38Name) { this.parameter38Name = parameter38Name; return this; } - public StreamCreator setParameter38Value(final String parameter38Value){ + + public StreamCreator setParameter38Value(final String parameter38Value) { this.parameter38Value = parameter38Value; return this; } - public StreamCreator setParameter39Name(final String parameter39Name){ + + public StreamCreator setParameter39Name(final String parameter39Name) { this.parameter39Name = parameter39Name; return this; } - public StreamCreator setParameter39Value(final String parameter39Value){ + + public StreamCreator setParameter39Value(final String parameter39Value) { this.parameter39Value = parameter39Value; return this; } - public StreamCreator setParameter40Name(final String parameter40Name){ + + public StreamCreator setParameter40Name(final String parameter40Name) { this.parameter40Name = parameter40Name; return this; } - public StreamCreator setParameter40Value(final String parameter40Value){ + + public StreamCreator setParameter40Value(final String parameter40Value) { this.parameter40Value = parameter40Value; return this; } - public StreamCreator setParameter41Name(final String parameter41Name){ + + public StreamCreator setParameter41Name(final String parameter41Name) { this.parameter41Name = parameter41Name; return this; } - public StreamCreator setParameter41Value(final String parameter41Value){ + + public StreamCreator setParameter41Value(final String parameter41Value) { this.parameter41Value = parameter41Value; return this; } - public StreamCreator setParameter42Name(final String parameter42Name){ + + public StreamCreator setParameter42Name(final String parameter42Name) { this.parameter42Name = parameter42Name; return this; } - public StreamCreator setParameter42Value(final String parameter42Value){ + + public StreamCreator setParameter42Value(final String parameter42Value) { this.parameter42Value = parameter42Value; return this; } - public StreamCreator setParameter43Name(final String parameter43Name){ + + public StreamCreator setParameter43Name(final String parameter43Name) { this.parameter43Name = parameter43Name; return this; } - public StreamCreator setParameter43Value(final String parameter43Value){ + + public StreamCreator setParameter43Value(final String parameter43Value) { this.parameter43Value = parameter43Value; return this; } - public StreamCreator setParameter44Name(final String parameter44Name){ + + public StreamCreator setParameter44Name(final String parameter44Name) { this.parameter44Name = parameter44Name; return this; } - public StreamCreator setParameter44Value(final String parameter44Value){ + + public StreamCreator setParameter44Value(final String parameter44Value) { this.parameter44Value = parameter44Value; return this; } - public StreamCreator setParameter45Name(final String parameter45Name){ + + public StreamCreator setParameter45Name(final String parameter45Name) { this.parameter45Name = parameter45Name; return this; } - public StreamCreator setParameter45Value(final String parameter45Value){ + + public StreamCreator setParameter45Value(final String parameter45Value) { this.parameter45Value = parameter45Value; return this; } - public StreamCreator setParameter46Name(final String parameter46Name){ + + public StreamCreator setParameter46Name(final String parameter46Name) { this.parameter46Name = parameter46Name; return this; } - public StreamCreator setParameter46Value(final String parameter46Value){ + + public StreamCreator setParameter46Value(final String parameter46Value) { this.parameter46Value = parameter46Value; return this; } - public StreamCreator setParameter47Name(final String parameter47Name){ + + public StreamCreator setParameter47Name(final String parameter47Name) { this.parameter47Name = parameter47Name; return this; } - public StreamCreator setParameter47Value(final String parameter47Value){ + + public StreamCreator setParameter47Value(final String parameter47Value) { this.parameter47Value = parameter47Value; return this; } - public StreamCreator setParameter48Name(final String parameter48Name){ + + public StreamCreator setParameter48Name(final String parameter48Name) { this.parameter48Name = parameter48Name; return this; } - public StreamCreator setParameter48Value(final String parameter48Value){ + + public StreamCreator setParameter48Value(final String parameter48Value) { this.parameter48Value = parameter48Value; return this; } - public StreamCreator setParameter49Name(final String parameter49Name){ + + public StreamCreator setParameter49Name(final String parameter49Name) { this.parameter49Name = parameter49Name; return this; } - public StreamCreator setParameter49Value(final String parameter49Value){ + + public StreamCreator setParameter49Value(final String parameter49Value) { this.parameter49Value = parameter49Value; return this; } - public StreamCreator setParameter50Name(final String parameter50Name){ + + public StreamCreator setParameter50Name(final String parameter50Name) { this.parameter50Name = parameter50Name; return this; } - public StreamCreator setParameter50Value(final String parameter50Value){ + + public StreamCreator setParameter50Value(final String parameter50Value) { this.parameter50Value = parameter50Value; return this; } - public StreamCreator setParameter51Name(final String parameter51Name){ + + public StreamCreator setParameter51Name(final String parameter51Name) { this.parameter51Name = parameter51Name; return this; } - public StreamCreator setParameter51Value(final String parameter51Value){ + + public StreamCreator setParameter51Value(final String parameter51Value) { this.parameter51Value = parameter51Value; return this; } - public StreamCreator setParameter52Name(final String parameter52Name){ + + public StreamCreator setParameter52Name(final String parameter52Name) { this.parameter52Name = parameter52Name; return this; } - public StreamCreator setParameter52Value(final String parameter52Value){ + + public StreamCreator setParameter52Value(final String parameter52Value) { this.parameter52Value = parameter52Value; return this; } - public StreamCreator setParameter53Name(final String parameter53Name){ + + public StreamCreator setParameter53Name(final String parameter53Name) { this.parameter53Name = parameter53Name; return this; } - public StreamCreator setParameter53Value(final String parameter53Value){ + + public StreamCreator setParameter53Value(final String parameter53Value) { this.parameter53Value = parameter53Value; return this; } - public StreamCreator setParameter54Name(final String parameter54Name){ + + public StreamCreator setParameter54Name(final String parameter54Name) { this.parameter54Name = parameter54Name; return this; } - public StreamCreator setParameter54Value(final String parameter54Value){ + + public StreamCreator setParameter54Value(final String parameter54Value) { this.parameter54Value = parameter54Value; return this; } - public StreamCreator setParameter55Name(final String parameter55Name){ + + public StreamCreator setParameter55Name(final String parameter55Name) { this.parameter55Name = parameter55Name; return this; } - public StreamCreator setParameter55Value(final String parameter55Value){ + + public StreamCreator setParameter55Value(final String parameter55Value) { this.parameter55Value = parameter55Value; return this; } - public StreamCreator setParameter56Name(final String parameter56Name){ + + public StreamCreator setParameter56Name(final String parameter56Name) { this.parameter56Name = parameter56Name; return this; } - public StreamCreator setParameter56Value(final String parameter56Value){ + + public StreamCreator setParameter56Value(final String parameter56Value) { this.parameter56Value = parameter56Value; return this; } - public StreamCreator setParameter57Name(final String parameter57Name){ + + public StreamCreator setParameter57Name(final String parameter57Name) { this.parameter57Name = parameter57Name; return this; } - public StreamCreator setParameter57Value(final String parameter57Value){ + + public StreamCreator setParameter57Value(final String parameter57Value) { this.parameter57Value = parameter57Value; return this; } - public StreamCreator setParameter58Name(final String parameter58Name){ + + public StreamCreator setParameter58Name(final String parameter58Name) { this.parameter58Name = parameter58Name; return this; } - public StreamCreator setParameter58Value(final String parameter58Value){ + + public StreamCreator setParameter58Value(final String parameter58Value) { this.parameter58Value = parameter58Value; return this; } - public StreamCreator setParameter59Name(final String parameter59Name){ + + public StreamCreator setParameter59Name(final String parameter59Name) { this.parameter59Name = parameter59Name; return this; } - public StreamCreator setParameter59Value(final String parameter59Value){ + + public StreamCreator setParameter59Value(final String parameter59Value) { this.parameter59Value = parameter59Value; return this; } - public StreamCreator setParameter60Name(final String parameter60Name){ + + public StreamCreator setParameter60Name(final String parameter60Name) { this.parameter60Name = parameter60Name; return this; } - public StreamCreator setParameter60Value(final String parameter60Value){ + + public StreamCreator setParameter60Value(final String parameter60Value) { this.parameter60Value = parameter60Value; return this; } - public StreamCreator setParameter61Name(final String parameter61Name){ + + public StreamCreator setParameter61Name(final String parameter61Name) { this.parameter61Name = parameter61Name; return this; } - public StreamCreator setParameter61Value(final String parameter61Value){ + + public StreamCreator setParameter61Value(final String parameter61Value) { this.parameter61Value = parameter61Value; return this; } - public StreamCreator setParameter62Name(final String parameter62Name){ + + public StreamCreator setParameter62Name(final String parameter62Name) { this.parameter62Name = parameter62Name; return this; } - public StreamCreator setParameter62Value(final String parameter62Value){ + + public StreamCreator setParameter62Value(final String parameter62Value) { this.parameter62Value = parameter62Value; return this; } - public StreamCreator setParameter63Name(final String parameter63Name){ + + public StreamCreator setParameter63Name(final String parameter63Name) { this.parameter63Name = parameter63Name; return this; } - public StreamCreator setParameter63Value(final String parameter63Value){ + + public StreamCreator setParameter63Value(final String parameter63Value) { this.parameter63Value = parameter63Value; return this; } - public StreamCreator setParameter64Name(final String parameter64Name){ + + public StreamCreator setParameter64Name(final String parameter64Name) { this.parameter64Name = parameter64Name; return this; } - public StreamCreator setParameter64Value(final String parameter64Value){ + + public StreamCreator setParameter64Value(final String parameter64Value) { this.parameter64Value = parameter64Value; return this; } - public StreamCreator setParameter65Name(final String parameter65Name){ + + public StreamCreator setParameter65Name(final String parameter65Name) { this.parameter65Name = parameter65Name; return this; } - public StreamCreator setParameter65Value(final String parameter65Value){ + + public StreamCreator setParameter65Value(final String parameter65Value) { this.parameter65Value = parameter65Value; return this; } - public StreamCreator setParameter66Name(final String parameter66Name){ + + public StreamCreator setParameter66Name(final String parameter66Name) { this.parameter66Name = parameter66Name; return this; } - public StreamCreator setParameter66Value(final String parameter66Value){ + + public StreamCreator setParameter66Value(final String parameter66Value) { this.parameter66Value = parameter66Value; return this; } - public StreamCreator setParameter67Name(final String parameter67Name){ + + public StreamCreator setParameter67Name(final String parameter67Name) { this.parameter67Name = parameter67Name; return this; } - public StreamCreator setParameter67Value(final String parameter67Value){ + + public StreamCreator setParameter67Value(final String parameter67Value) { this.parameter67Value = parameter67Value; return this; } - public StreamCreator setParameter68Name(final String parameter68Name){ + + public StreamCreator setParameter68Name(final String parameter68Name) { this.parameter68Name = parameter68Name; return this; } - public StreamCreator setParameter68Value(final String parameter68Value){ + + public StreamCreator setParameter68Value(final String parameter68Value) { this.parameter68Value = parameter68Value; return this; } - public StreamCreator setParameter69Name(final String parameter69Name){ + + public StreamCreator setParameter69Name(final String parameter69Name) { this.parameter69Name = parameter69Name; return this; } - public StreamCreator setParameter69Value(final String parameter69Value){ + + public StreamCreator setParameter69Value(final String parameter69Value) { this.parameter69Value = parameter69Value; return this; } - public StreamCreator setParameter70Name(final String parameter70Name){ + + public StreamCreator setParameter70Name(final String parameter70Name) { this.parameter70Name = parameter70Name; return this; } - public StreamCreator setParameter70Value(final String parameter70Value){ + + public StreamCreator setParameter70Value(final String parameter70Value) { this.parameter70Value = parameter70Value; return this; } - public StreamCreator setParameter71Name(final String parameter71Name){ + + public StreamCreator setParameter71Name(final String parameter71Name) { this.parameter71Name = parameter71Name; return this; } - public StreamCreator setParameter71Value(final String parameter71Value){ + + public StreamCreator setParameter71Value(final String parameter71Value) { this.parameter71Value = parameter71Value; return this; } - public StreamCreator setParameter72Name(final String parameter72Name){ + + public StreamCreator setParameter72Name(final String parameter72Name) { this.parameter72Name = parameter72Name; return this; } - public StreamCreator setParameter72Value(final String parameter72Value){ + + public StreamCreator setParameter72Value(final String parameter72Value) { this.parameter72Value = parameter72Value; return this; } - public StreamCreator setParameter73Name(final String parameter73Name){ + + public StreamCreator setParameter73Name(final String parameter73Name) { this.parameter73Name = parameter73Name; return this; } - public StreamCreator setParameter73Value(final String parameter73Value){ + + public StreamCreator setParameter73Value(final String parameter73Value) { this.parameter73Value = parameter73Value; return this; } - public StreamCreator setParameter74Name(final String parameter74Name){ + + public StreamCreator setParameter74Name(final String parameter74Name) { this.parameter74Name = parameter74Name; return this; } - public StreamCreator setParameter74Value(final String parameter74Value){ + + public StreamCreator setParameter74Value(final String parameter74Value) { this.parameter74Value = parameter74Value; return this; } - public StreamCreator setParameter75Name(final String parameter75Name){ + + public StreamCreator setParameter75Name(final String parameter75Name) { this.parameter75Name = parameter75Name; return this; } - public StreamCreator setParameter75Value(final String parameter75Value){ + + public StreamCreator setParameter75Value(final String parameter75Value) { this.parameter75Value = parameter75Value; return this; } - public StreamCreator setParameter76Name(final String parameter76Name){ + + public StreamCreator setParameter76Name(final String parameter76Name) { this.parameter76Name = parameter76Name; return this; } - public StreamCreator setParameter76Value(final String parameter76Value){ + + public StreamCreator setParameter76Value(final String parameter76Value) { this.parameter76Value = parameter76Value; return this; } - public StreamCreator setParameter77Name(final String parameter77Name){ + + public StreamCreator setParameter77Name(final String parameter77Name) { this.parameter77Name = parameter77Name; return this; } - public StreamCreator setParameter77Value(final String parameter77Value){ + + public StreamCreator setParameter77Value(final String parameter77Value) { this.parameter77Value = parameter77Value; return this; } - public StreamCreator setParameter78Name(final String parameter78Name){ + + public StreamCreator setParameter78Name(final String parameter78Name) { this.parameter78Name = parameter78Name; return this; } - public StreamCreator setParameter78Value(final String parameter78Value){ + + public StreamCreator setParameter78Value(final String parameter78Value) { this.parameter78Value = parameter78Value; return this; } - public StreamCreator setParameter79Name(final String parameter79Name){ + + public StreamCreator setParameter79Name(final String parameter79Name) { this.parameter79Name = parameter79Name; return this; } - public StreamCreator setParameter79Value(final String parameter79Value){ + + public StreamCreator setParameter79Value(final String parameter79Value) { this.parameter79Value = parameter79Value; return this; } - public StreamCreator setParameter80Name(final String parameter80Name){ + + public StreamCreator setParameter80Name(final String parameter80Name) { this.parameter80Name = parameter80Name; return this; } - public StreamCreator setParameter80Value(final String parameter80Value){ + + public StreamCreator setParameter80Value(final String parameter80Value) { this.parameter80Value = parameter80Value; return this; } - public StreamCreator setParameter81Name(final String parameter81Name){ + + public StreamCreator setParameter81Name(final String parameter81Name) { this.parameter81Name = parameter81Name; return this; } - public StreamCreator setParameter81Value(final String parameter81Value){ + + public StreamCreator setParameter81Value(final String parameter81Value) { this.parameter81Value = parameter81Value; return this; } - public StreamCreator setParameter82Name(final String parameter82Name){ + + public StreamCreator setParameter82Name(final String parameter82Name) { this.parameter82Name = parameter82Name; return this; } - public StreamCreator setParameter82Value(final String parameter82Value){ + + public StreamCreator setParameter82Value(final String parameter82Value) { this.parameter82Value = parameter82Value; return this; } - public StreamCreator setParameter83Name(final String parameter83Name){ + + public StreamCreator setParameter83Name(final String parameter83Name) { this.parameter83Name = parameter83Name; return this; } - public StreamCreator setParameter83Value(final String parameter83Value){ + + public StreamCreator setParameter83Value(final String parameter83Value) { this.parameter83Value = parameter83Value; return this; } - public StreamCreator setParameter84Name(final String parameter84Name){ + + public StreamCreator setParameter84Name(final String parameter84Name) { this.parameter84Name = parameter84Name; return this; } - public StreamCreator setParameter84Value(final String parameter84Value){ + + public StreamCreator setParameter84Value(final String parameter84Value) { this.parameter84Value = parameter84Value; return this; } - public StreamCreator setParameter85Name(final String parameter85Name){ + + public StreamCreator setParameter85Name(final String parameter85Name) { this.parameter85Name = parameter85Name; return this; } - public StreamCreator setParameter85Value(final String parameter85Value){ + + public StreamCreator setParameter85Value(final String parameter85Value) { this.parameter85Value = parameter85Value; return this; } - public StreamCreator setParameter86Name(final String parameter86Name){ + + public StreamCreator setParameter86Name(final String parameter86Name) { this.parameter86Name = parameter86Name; return this; } - public StreamCreator setParameter86Value(final String parameter86Value){ + + public StreamCreator setParameter86Value(final String parameter86Value) { this.parameter86Value = parameter86Value; return this; } - public StreamCreator setParameter87Name(final String parameter87Name){ + + public StreamCreator setParameter87Name(final String parameter87Name) { this.parameter87Name = parameter87Name; return this; } - public StreamCreator setParameter87Value(final String parameter87Value){ + + public StreamCreator setParameter87Value(final String parameter87Value) { this.parameter87Value = parameter87Value; return this; } - public StreamCreator setParameter88Name(final String parameter88Name){ + + public StreamCreator setParameter88Name(final String parameter88Name) { this.parameter88Name = parameter88Name; return this; } - public StreamCreator setParameter88Value(final String parameter88Value){ + + public StreamCreator setParameter88Value(final String parameter88Value) { this.parameter88Value = parameter88Value; return this; } - public StreamCreator setParameter89Name(final String parameter89Name){ + + public StreamCreator setParameter89Name(final String parameter89Name) { this.parameter89Name = parameter89Name; return this; } - public StreamCreator setParameter89Value(final String parameter89Value){ + + public StreamCreator setParameter89Value(final String parameter89Value) { this.parameter89Value = parameter89Value; return this; } - public StreamCreator setParameter90Name(final String parameter90Name){ + + public StreamCreator setParameter90Name(final String parameter90Name) { this.parameter90Name = parameter90Name; return this; } - public StreamCreator setParameter90Value(final String parameter90Value){ + + public StreamCreator setParameter90Value(final String parameter90Value) { this.parameter90Value = parameter90Value; return this; } - public StreamCreator setParameter91Name(final String parameter91Name){ + + public StreamCreator setParameter91Name(final String parameter91Name) { this.parameter91Name = parameter91Name; return this; } - public StreamCreator setParameter91Value(final String parameter91Value){ + + public StreamCreator setParameter91Value(final String parameter91Value) { this.parameter91Value = parameter91Value; return this; } - public StreamCreator setParameter92Name(final String parameter92Name){ + + public StreamCreator setParameter92Name(final String parameter92Name) { this.parameter92Name = parameter92Name; return this; } - public StreamCreator setParameter92Value(final String parameter92Value){ + + public StreamCreator setParameter92Value(final String parameter92Value) { this.parameter92Value = parameter92Value; return this; } - public StreamCreator setParameter93Name(final String parameter93Name){ + + public StreamCreator setParameter93Name(final String parameter93Name) { this.parameter93Name = parameter93Name; return this; } - public StreamCreator setParameter93Value(final String parameter93Value){ + + public StreamCreator setParameter93Value(final String parameter93Value) { this.parameter93Value = parameter93Value; return this; } - public StreamCreator setParameter94Name(final String parameter94Name){ + + public StreamCreator setParameter94Name(final String parameter94Name) { this.parameter94Name = parameter94Name; return this; } - public StreamCreator setParameter94Value(final String parameter94Value){ + + public StreamCreator setParameter94Value(final String parameter94Value) { this.parameter94Value = parameter94Value; return this; } - public StreamCreator setParameter95Name(final String parameter95Name){ + + public StreamCreator setParameter95Name(final String parameter95Name) { this.parameter95Name = parameter95Name; return this; } - public StreamCreator setParameter95Value(final String parameter95Value){ + + public StreamCreator setParameter95Value(final String parameter95Value) { this.parameter95Value = parameter95Value; return this; } - public StreamCreator setParameter96Name(final String parameter96Name){ + + public StreamCreator setParameter96Name(final String parameter96Name) { this.parameter96Name = parameter96Name; return this; } - public StreamCreator setParameter96Value(final String parameter96Value){ + + public StreamCreator setParameter96Value(final String parameter96Value) { this.parameter96Value = parameter96Value; return this; } - public StreamCreator setParameter97Name(final String parameter97Name){ + + public StreamCreator setParameter97Name(final String parameter97Name) { this.parameter97Name = parameter97Name; return this; } - public StreamCreator setParameter97Value(final String parameter97Value){ + + public StreamCreator setParameter97Value(final String parameter97Value) { this.parameter97Value = parameter97Value; return this; } - public StreamCreator setParameter98Name(final String parameter98Name){ + + public StreamCreator setParameter98Name(final String parameter98Name) { this.parameter98Name = parameter98Name; return this; } - public StreamCreator setParameter98Value(final String parameter98Value){ + + public StreamCreator setParameter98Value(final String parameter98Value) { this.parameter98Value = parameter98Value; return this; } - public StreamCreator setParameter99Name(final String parameter99Name){ + + public StreamCreator setParameter99Name(final String parameter99Name) { this.parameter99Name = parameter99Name; return this; } - public StreamCreator setParameter99Value(final String parameter99Value){ + + public StreamCreator setParameter99Value(final String parameter99Value) { this.parameter99Value = parameter99Value; return this; } @Override - public Stream create(final TwilioRestClient client){ - String path = "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Streams.json"; + public Stream create(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Streams.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"CallSid"+"}", this.pathCallSid.toString()); - path = path.replace("{"+"Url"+"}", this.url.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "CallSid" + "}", this.pathCallSid.toString()); + path = path.replace("{" + "Url" + "}", this.url.toString()); Request request = new Request( HttpMethod.POST, Domains.API.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Stream creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Stream creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -1096,818 +1318,619 @@ public Stream create(final TwilioRestClient client){ return Stream.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (url != null) { request.addPostParam("Url", url.toString()); - } if (name != null) { request.addPostParam("Name", name); - } if (track != null) { request.addPostParam("Track", track.toString()); - } if (statusCallback != null) { request.addPostParam("StatusCallback", statusCallback.toString()); - } if (statusCallbackMethod != null) { - request.addPostParam("StatusCallbackMethod", statusCallbackMethod.toString()); - + request.addPostParam( + "StatusCallbackMethod", + statusCallbackMethod.toString() + ); } if (parameter1Name != null) { request.addPostParam("Parameter1.Name", parameter1Name); - } if (parameter1Value != null) { request.addPostParam("Parameter1.Value", parameter1Value); - } if (parameter2Name != null) { request.addPostParam("Parameter2.Name", parameter2Name); - } if (parameter2Value != null) { request.addPostParam("Parameter2.Value", parameter2Value); - } if (parameter3Name != null) { request.addPostParam("Parameter3.Name", parameter3Name); - } if (parameter3Value != null) { request.addPostParam("Parameter3.Value", parameter3Value); - } if (parameter4Name != null) { request.addPostParam("Parameter4.Name", parameter4Name); - } if (parameter4Value != null) { request.addPostParam("Parameter4.Value", parameter4Value); - } if (parameter5Name != null) { request.addPostParam("Parameter5.Name", parameter5Name); - } if (parameter5Value != null) { request.addPostParam("Parameter5.Value", parameter5Value); - } if (parameter6Name != null) { request.addPostParam("Parameter6.Name", parameter6Name); - } if (parameter6Value != null) { request.addPostParam("Parameter6.Value", parameter6Value); - } if (parameter7Name != null) { request.addPostParam("Parameter7.Name", parameter7Name); - } if (parameter7Value != null) { request.addPostParam("Parameter7.Value", parameter7Value); - } if (parameter8Name != null) { request.addPostParam("Parameter8.Name", parameter8Name); - } if (parameter8Value != null) { request.addPostParam("Parameter8.Value", parameter8Value); - } if (parameter9Name != null) { request.addPostParam("Parameter9.Name", parameter9Name); - } if (parameter9Value != null) { request.addPostParam("Parameter9.Value", parameter9Value); - } if (parameter10Name != null) { request.addPostParam("Parameter10.Name", parameter10Name); - } if (parameter10Value != null) { request.addPostParam("Parameter10.Value", parameter10Value); - } if (parameter11Name != null) { request.addPostParam("Parameter11.Name", parameter11Name); - } if (parameter11Value != null) { request.addPostParam("Parameter11.Value", parameter11Value); - } if (parameter12Name != null) { request.addPostParam("Parameter12.Name", parameter12Name); - } if (parameter12Value != null) { request.addPostParam("Parameter12.Value", parameter12Value); - } if (parameter13Name != null) { request.addPostParam("Parameter13.Name", parameter13Name); - } if (parameter13Value != null) { request.addPostParam("Parameter13.Value", parameter13Value); - } if (parameter14Name != null) { request.addPostParam("Parameter14.Name", parameter14Name); - } if (parameter14Value != null) { request.addPostParam("Parameter14.Value", parameter14Value); - } if (parameter15Name != null) { request.addPostParam("Parameter15.Name", parameter15Name); - } if (parameter15Value != null) { request.addPostParam("Parameter15.Value", parameter15Value); - } if (parameter16Name != null) { request.addPostParam("Parameter16.Name", parameter16Name); - } if (parameter16Value != null) { request.addPostParam("Parameter16.Value", parameter16Value); - } if (parameter17Name != null) { request.addPostParam("Parameter17.Name", parameter17Name); - } if (parameter17Value != null) { request.addPostParam("Parameter17.Value", parameter17Value); - } if (parameter18Name != null) { request.addPostParam("Parameter18.Name", parameter18Name); - } if (parameter18Value != null) { request.addPostParam("Parameter18.Value", parameter18Value); - } if (parameter19Name != null) { request.addPostParam("Parameter19.Name", parameter19Name); - } if (parameter19Value != null) { request.addPostParam("Parameter19.Value", parameter19Value); - } if (parameter20Name != null) { request.addPostParam("Parameter20.Name", parameter20Name); - } if (parameter20Value != null) { request.addPostParam("Parameter20.Value", parameter20Value); - } if (parameter21Name != null) { request.addPostParam("Parameter21.Name", parameter21Name); - } if (parameter21Value != null) { request.addPostParam("Parameter21.Value", parameter21Value); - } if (parameter22Name != null) { request.addPostParam("Parameter22.Name", parameter22Name); - } if (parameter22Value != null) { request.addPostParam("Parameter22.Value", parameter22Value); - } if (parameter23Name != null) { request.addPostParam("Parameter23.Name", parameter23Name); - } if (parameter23Value != null) { request.addPostParam("Parameter23.Value", parameter23Value); - } if (parameter24Name != null) { request.addPostParam("Parameter24.Name", parameter24Name); - } if (parameter24Value != null) { request.addPostParam("Parameter24.Value", parameter24Value); - } if (parameter25Name != null) { request.addPostParam("Parameter25.Name", parameter25Name); - } if (parameter25Value != null) { request.addPostParam("Parameter25.Value", parameter25Value); - } if (parameter26Name != null) { request.addPostParam("Parameter26.Name", parameter26Name); - } if (parameter26Value != null) { request.addPostParam("Parameter26.Value", parameter26Value); - } if (parameter27Name != null) { request.addPostParam("Parameter27.Name", parameter27Name); - } if (parameter27Value != null) { request.addPostParam("Parameter27.Value", parameter27Value); - } if (parameter28Name != null) { request.addPostParam("Parameter28.Name", parameter28Name); - } if (parameter28Value != null) { request.addPostParam("Parameter28.Value", parameter28Value); - } if (parameter29Name != null) { request.addPostParam("Parameter29.Name", parameter29Name); - } if (parameter29Value != null) { request.addPostParam("Parameter29.Value", parameter29Value); - } if (parameter30Name != null) { request.addPostParam("Parameter30.Name", parameter30Name); - } if (parameter30Value != null) { request.addPostParam("Parameter30.Value", parameter30Value); - } if (parameter31Name != null) { request.addPostParam("Parameter31.Name", parameter31Name); - } if (parameter31Value != null) { request.addPostParam("Parameter31.Value", parameter31Value); - } if (parameter32Name != null) { request.addPostParam("Parameter32.Name", parameter32Name); - } if (parameter32Value != null) { request.addPostParam("Parameter32.Value", parameter32Value); - } if (parameter33Name != null) { request.addPostParam("Parameter33.Name", parameter33Name); - } if (parameter33Value != null) { request.addPostParam("Parameter33.Value", parameter33Value); - } if (parameter34Name != null) { request.addPostParam("Parameter34.Name", parameter34Name); - } if (parameter34Value != null) { request.addPostParam("Parameter34.Value", parameter34Value); - } if (parameter35Name != null) { request.addPostParam("Parameter35.Name", parameter35Name); - } if (parameter35Value != null) { request.addPostParam("Parameter35.Value", parameter35Value); - } if (parameter36Name != null) { request.addPostParam("Parameter36.Name", parameter36Name); - } if (parameter36Value != null) { request.addPostParam("Parameter36.Value", parameter36Value); - } if (parameter37Name != null) { request.addPostParam("Parameter37.Name", parameter37Name); - } if (parameter37Value != null) { request.addPostParam("Parameter37.Value", parameter37Value); - } if (parameter38Name != null) { request.addPostParam("Parameter38.Name", parameter38Name); - } if (parameter38Value != null) { request.addPostParam("Parameter38.Value", parameter38Value); - } if (parameter39Name != null) { request.addPostParam("Parameter39.Name", parameter39Name); - } if (parameter39Value != null) { request.addPostParam("Parameter39.Value", parameter39Value); - } if (parameter40Name != null) { request.addPostParam("Parameter40.Name", parameter40Name); - } if (parameter40Value != null) { request.addPostParam("Parameter40.Value", parameter40Value); - } if (parameter41Name != null) { request.addPostParam("Parameter41.Name", parameter41Name); - } if (parameter41Value != null) { request.addPostParam("Parameter41.Value", parameter41Value); - } if (parameter42Name != null) { request.addPostParam("Parameter42.Name", parameter42Name); - } if (parameter42Value != null) { request.addPostParam("Parameter42.Value", parameter42Value); - } if (parameter43Name != null) { request.addPostParam("Parameter43.Name", parameter43Name); - } if (parameter43Value != null) { request.addPostParam("Parameter43.Value", parameter43Value); - } if (parameter44Name != null) { request.addPostParam("Parameter44.Name", parameter44Name); - } if (parameter44Value != null) { request.addPostParam("Parameter44.Value", parameter44Value); - } if (parameter45Name != null) { request.addPostParam("Parameter45.Name", parameter45Name); - } if (parameter45Value != null) { request.addPostParam("Parameter45.Value", parameter45Value); - } if (parameter46Name != null) { request.addPostParam("Parameter46.Name", parameter46Name); - } if (parameter46Value != null) { request.addPostParam("Parameter46.Value", parameter46Value); - } if (parameter47Name != null) { request.addPostParam("Parameter47.Name", parameter47Name); - } if (parameter47Value != null) { request.addPostParam("Parameter47.Value", parameter47Value); - } if (parameter48Name != null) { request.addPostParam("Parameter48.Name", parameter48Name); - } if (parameter48Value != null) { request.addPostParam("Parameter48.Value", parameter48Value); - } if (parameter49Name != null) { request.addPostParam("Parameter49.Name", parameter49Name); - } if (parameter49Value != null) { request.addPostParam("Parameter49.Value", parameter49Value); - } if (parameter50Name != null) { request.addPostParam("Parameter50.Name", parameter50Name); - } if (parameter50Value != null) { request.addPostParam("Parameter50.Value", parameter50Value); - } if (parameter51Name != null) { request.addPostParam("Parameter51.Name", parameter51Name); - } if (parameter51Value != null) { request.addPostParam("Parameter51.Value", parameter51Value); - } if (parameter52Name != null) { request.addPostParam("Parameter52.Name", parameter52Name); - } if (parameter52Value != null) { request.addPostParam("Parameter52.Value", parameter52Value); - } if (parameter53Name != null) { request.addPostParam("Parameter53.Name", parameter53Name); - } if (parameter53Value != null) { request.addPostParam("Parameter53.Value", parameter53Value); - } if (parameter54Name != null) { request.addPostParam("Parameter54.Name", parameter54Name); - } if (parameter54Value != null) { request.addPostParam("Parameter54.Value", parameter54Value); - } if (parameter55Name != null) { request.addPostParam("Parameter55.Name", parameter55Name); - } if (parameter55Value != null) { request.addPostParam("Parameter55.Value", parameter55Value); - } if (parameter56Name != null) { request.addPostParam("Parameter56.Name", parameter56Name); - } if (parameter56Value != null) { request.addPostParam("Parameter56.Value", parameter56Value); - } if (parameter57Name != null) { request.addPostParam("Parameter57.Name", parameter57Name); - } if (parameter57Value != null) { request.addPostParam("Parameter57.Value", parameter57Value); - } if (parameter58Name != null) { request.addPostParam("Parameter58.Name", parameter58Name); - } if (parameter58Value != null) { request.addPostParam("Parameter58.Value", parameter58Value); - } if (parameter59Name != null) { request.addPostParam("Parameter59.Name", parameter59Name); - } if (parameter59Value != null) { request.addPostParam("Parameter59.Value", parameter59Value); - } if (parameter60Name != null) { request.addPostParam("Parameter60.Name", parameter60Name); - } if (parameter60Value != null) { request.addPostParam("Parameter60.Value", parameter60Value); - } if (parameter61Name != null) { request.addPostParam("Parameter61.Name", parameter61Name); - } if (parameter61Value != null) { request.addPostParam("Parameter61.Value", parameter61Value); - } if (parameter62Name != null) { request.addPostParam("Parameter62.Name", parameter62Name); - } if (parameter62Value != null) { request.addPostParam("Parameter62.Value", parameter62Value); - } if (parameter63Name != null) { request.addPostParam("Parameter63.Name", parameter63Name); - } if (parameter63Value != null) { request.addPostParam("Parameter63.Value", parameter63Value); - } if (parameter64Name != null) { request.addPostParam("Parameter64.Name", parameter64Name); - } if (parameter64Value != null) { request.addPostParam("Parameter64.Value", parameter64Value); - } if (parameter65Name != null) { request.addPostParam("Parameter65.Name", parameter65Name); - } if (parameter65Value != null) { request.addPostParam("Parameter65.Value", parameter65Value); - } if (parameter66Name != null) { request.addPostParam("Parameter66.Name", parameter66Name); - } if (parameter66Value != null) { request.addPostParam("Parameter66.Value", parameter66Value); - } if (parameter67Name != null) { request.addPostParam("Parameter67.Name", parameter67Name); - } if (parameter67Value != null) { request.addPostParam("Parameter67.Value", parameter67Value); - } if (parameter68Name != null) { request.addPostParam("Parameter68.Name", parameter68Name); - } if (parameter68Value != null) { request.addPostParam("Parameter68.Value", parameter68Value); - } if (parameter69Name != null) { request.addPostParam("Parameter69.Name", parameter69Name); - } if (parameter69Value != null) { request.addPostParam("Parameter69.Value", parameter69Value); - } if (parameter70Name != null) { request.addPostParam("Parameter70.Name", parameter70Name); - } if (parameter70Value != null) { request.addPostParam("Parameter70.Value", parameter70Value); - } if (parameter71Name != null) { request.addPostParam("Parameter71.Name", parameter71Name); - } if (parameter71Value != null) { request.addPostParam("Parameter71.Value", parameter71Value); - } if (parameter72Name != null) { request.addPostParam("Parameter72.Name", parameter72Name); - } if (parameter72Value != null) { request.addPostParam("Parameter72.Value", parameter72Value); - } if (parameter73Name != null) { request.addPostParam("Parameter73.Name", parameter73Name); - } if (parameter73Value != null) { request.addPostParam("Parameter73.Value", parameter73Value); - } if (parameter74Name != null) { request.addPostParam("Parameter74.Name", parameter74Name); - } if (parameter74Value != null) { request.addPostParam("Parameter74.Value", parameter74Value); - } if (parameter75Name != null) { request.addPostParam("Parameter75.Name", parameter75Name); - } if (parameter75Value != null) { request.addPostParam("Parameter75.Value", parameter75Value); - } if (parameter76Name != null) { request.addPostParam("Parameter76.Name", parameter76Name); - } if (parameter76Value != null) { request.addPostParam("Parameter76.Value", parameter76Value); - } if (parameter77Name != null) { request.addPostParam("Parameter77.Name", parameter77Name); - } if (parameter77Value != null) { request.addPostParam("Parameter77.Value", parameter77Value); - } if (parameter78Name != null) { request.addPostParam("Parameter78.Name", parameter78Name); - } if (parameter78Value != null) { request.addPostParam("Parameter78.Value", parameter78Value); - } if (parameter79Name != null) { request.addPostParam("Parameter79.Name", parameter79Name); - } if (parameter79Value != null) { request.addPostParam("Parameter79.Value", parameter79Value); - } if (parameter80Name != null) { request.addPostParam("Parameter80.Name", parameter80Name); - } if (parameter80Value != null) { request.addPostParam("Parameter80.Value", parameter80Value); - } if (parameter81Name != null) { request.addPostParam("Parameter81.Name", parameter81Name); - } if (parameter81Value != null) { request.addPostParam("Parameter81.Value", parameter81Value); - } if (parameter82Name != null) { request.addPostParam("Parameter82.Name", parameter82Name); - } if (parameter82Value != null) { request.addPostParam("Parameter82.Value", parameter82Value); - } if (parameter83Name != null) { request.addPostParam("Parameter83.Name", parameter83Name); - } if (parameter83Value != null) { request.addPostParam("Parameter83.Value", parameter83Value); - } if (parameter84Name != null) { request.addPostParam("Parameter84.Name", parameter84Name); - } if (parameter84Value != null) { request.addPostParam("Parameter84.Value", parameter84Value); - } if (parameter85Name != null) { request.addPostParam("Parameter85.Name", parameter85Name); - } if (parameter85Value != null) { request.addPostParam("Parameter85.Value", parameter85Value); - } if (parameter86Name != null) { request.addPostParam("Parameter86.Name", parameter86Name); - } if (parameter86Value != null) { request.addPostParam("Parameter86.Value", parameter86Value); - } if (parameter87Name != null) { request.addPostParam("Parameter87.Name", parameter87Name); - } if (parameter87Value != null) { request.addPostParam("Parameter87.Value", parameter87Value); - } if (parameter88Name != null) { request.addPostParam("Parameter88.Name", parameter88Name); - } if (parameter88Value != null) { request.addPostParam("Parameter88.Value", parameter88Value); - } if (parameter89Name != null) { request.addPostParam("Parameter89.Name", parameter89Name); - } if (parameter89Value != null) { request.addPostParam("Parameter89.Value", parameter89Value); - } if (parameter90Name != null) { request.addPostParam("Parameter90.Name", parameter90Name); - } if (parameter90Value != null) { request.addPostParam("Parameter90.Value", parameter90Value); - } if (parameter91Name != null) { request.addPostParam("Parameter91.Name", parameter91Name); - } if (parameter91Value != null) { request.addPostParam("Parameter91.Value", parameter91Value); - } if (parameter92Name != null) { request.addPostParam("Parameter92.Name", parameter92Name); - } if (parameter92Value != null) { request.addPostParam("Parameter92.Value", parameter92Value); - } if (parameter93Name != null) { request.addPostParam("Parameter93.Name", parameter93Name); - } if (parameter93Value != null) { request.addPostParam("Parameter93.Value", parameter93Value); - } if (parameter94Name != null) { request.addPostParam("Parameter94.Name", parameter94Name); - } if (parameter94Value != null) { request.addPostParam("Parameter94.Value", parameter94Value); - } if (parameter95Name != null) { request.addPostParam("Parameter95.Name", parameter95Name); - } if (parameter95Value != null) { request.addPostParam("Parameter95.Value", parameter95Value); - } if (parameter96Name != null) { request.addPostParam("Parameter96.Name", parameter96Name); - } if (parameter96Value != null) { request.addPostParam("Parameter96.Value", parameter96Value); - } if (parameter97Name != null) { request.addPostParam("Parameter97.Name", parameter97Name); - } if (parameter97Value != null) { request.addPostParam("Parameter97.Value", parameter97Value); - } if (parameter98Name != null) { request.addPostParam("Parameter98.Name", parameter98Name); - } if (parameter98Value != null) { request.addPostParam("Parameter98.Value", parameter98Value); - } if (parameter99Name != null) { request.addPostParam("Parameter99.Name", parameter99Name); - } if (parameter99Value != null) { request.addPostParam("Parameter99.Value", parameter99Value); - } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/StreamUpdater.java b/src/main/java/com/twilio/rest/api/v2010/account/call/StreamUpdater.java index 13dc560985..dff3c19dd2 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/call/StreamUpdater.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/call/StreamUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010.account.call; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,53 +25,75 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class StreamUpdater extends Updater { - - -public class StreamUpdater extends Updater{ private String pathCallSid; private String pathSid; private Stream.UpdateStatus status; private String pathAccountSid; - public StreamUpdater(final String pathCallSid, final String pathSid, final Stream.UpdateStatus status){ + public StreamUpdater( + final String pathCallSid, + final String pathSid, + final Stream.UpdateStatus status + ) { this.pathCallSid = pathCallSid; this.pathSid = pathSid; this.status = status; } - public StreamUpdater(final String pathAccountSid, final String pathCallSid, final String pathSid, final Stream.UpdateStatus status){ + + public StreamUpdater( + final String pathAccountSid, + final String pathCallSid, + final String pathSid, + final Stream.UpdateStatus status + ) { this.pathAccountSid = pathAccountSid; this.pathCallSid = pathCallSid; this.pathSid = pathSid; this.status = status; } - public StreamUpdater setStatus(final Stream.UpdateStatus status){ + public StreamUpdater setStatus(final Stream.UpdateStatus status) { this.status = status; return this; } @Override - public Stream update(final TwilioRestClient client){ - String path = "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Streams/{Sid}.json"; + public Stream update(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Streams/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"CallSid"+"}", this.pathCallSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); - path = path.replace("{"+"Status"+"}", this.status.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "CallSid" + "}", this.pathCallSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + path = path.replace("{" + "Status" + "}", this.status.toString()); Request request = new Request( HttpMethod.POST, Domains.API.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Stream update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Stream update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -79,10 +102,10 @@ public Stream update(final TwilioRestClient client){ return Stream.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (status != null) { request.addPostParam("Status", status.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/UserDefinedMessage.java b/src/main/java/com/twilio/rest/api/v2010/account/call/UserDefinedMessage.java index 83f0b338ee..94140fe427 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/call/UserDefinedMessage.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/call/UserDefinedMessage.java @@ -23,39 +23,50 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class UserDefinedMessage extends Resource { + private static final long serialVersionUID = 278501461523415L; - public static UserDefinedMessageCreator creator(final String pathCallSid, final String content){ + public static UserDefinedMessageCreator creator( + final String pathCallSid, + final String content + ) { return new UserDefinedMessageCreator(pathCallSid, content); } - public static UserDefinedMessageCreator creator(final String pathAccountSid, final String pathCallSid, final String content){ - return new UserDefinedMessageCreator(pathAccountSid, pathCallSid, content); + + public static UserDefinedMessageCreator creator( + final String pathAccountSid, + final String pathCallSid, + final String content + ) { + return new UserDefinedMessageCreator( + pathAccountSid, + pathCallSid, + content + ); } /** - * Converts a JSON String into a UserDefinedMessage object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return UserDefinedMessage object represented by the provided JSON - */ - public static UserDefinedMessage fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a UserDefinedMessage object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return UserDefinedMessage object represented by the provided JSON + */ + public static UserDefinedMessage fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, UserDefinedMessage.class); @@ -67,14 +78,17 @@ public static UserDefinedMessage fromJson(final String json, final ObjectMapper } /** - * Converts a JSON InputStream into a UserDefinedMessage object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return UserDefinedMessage object represented by the provided JSON - */ - public static UserDefinedMessage fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a UserDefinedMessage object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return UserDefinedMessage object represented by the provided JSON + */ + public static UserDefinedMessage fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, UserDefinedMessage.class); @@ -92,17 +106,10 @@ public static UserDefinedMessage fromJson(final InputStream json, final ObjectMa @JsonCreator private UserDefinedMessage( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("call_sid") - final String callSid, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("date_created") - final String dateCreated + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("call_sid") final String callSid, + @JsonProperty("sid") final String sid, + @JsonProperty("date_created") final String dateCreated ) { this.accountSid = accountSid; this.callSid = callSid; @@ -110,22 +117,25 @@ private UserDefinedMessage( this.dateCreated = DateConverter.rfc2822DateTimeFromString(dateCreated); } - public final String getAccountSid() { - return this.accountSid; - } - public final String getCallSid() { - return this.callSid; - } - public final String getSid() { - return this.sid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getCallSid() { + return this.callSid; + } + + public final String getSid() { + return this.sid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -135,13 +145,16 @@ public boolean equals(final Object o) { UserDefinedMessage other = (UserDefinedMessage) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(callSid, other.callSid) && Objects.equals(sid, other.sid) && Objects.equals(dateCreated, other.dateCreated) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(callSid, other.callSid) && + Objects.equals(sid, other.sid) && + Objects.equals(dateCreated, other.dateCreated) + ); } @Override public int hashCode() { return Objects.hash(accountSid, callSid, sid, dateCreated); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/UserDefinedMessageCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/call/UserDefinedMessageCreator.java index b70f5e14af..a0fb6f722e 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/call/UserDefinedMessageCreator.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/call/UserDefinedMessageCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010.account.call; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,70 +25,95 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class UserDefinedMessageCreator extends Creator { - - -public class UserDefinedMessageCreator extends Creator{ private String pathCallSid; private String content; private String pathAccountSid; private String idempotencyKey; - public UserDefinedMessageCreator(final String pathCallSid, final String content) { + public UserDefinedMessageCreator( + final String pathCallSid, + final String content + ) { this.pathCallSid = pathCallSid; this.content = content; } - public UserDefinedMessageCreator(final String pathAccountSid, final String pathCallSid, final String content) { + + public UserDefinedMessageCreator( + final String pathAccountSid, + final String pathCallSid, + final String content + ) { this.pathAccountSid = pathAccountSid; this.pathCallSid = pathCallSid; this.content = content; } - public UserDefinedMessageCreator setContent(final String content){ + public UserDefinedMessageCreator setContent(final String content) { this.content = content; return this; } - public UserDefinedMessageCreator setIdempotencyKey(final String idempotencyKey){ + + public UserDefinedMessageCreator setIdempotencyKey( + final String idempotencyKey + ) { this.idempotencyKey = idempotencyKey; return this; } @Override - public UserDefinedMessage create(final TwilioRestClient client){ - String path = "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/UserDefinedMessages.json"; + public UserDefinedMessage create(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/UserDefinedMessages.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"CallSid"+"}", this.pathCallSid.toString()); - path = path.replace("{"+"Content"+"}", this.content.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "CallSid" + "}", this.pathCallSid.toString()); + path = path.replace("{" + "Content" + "}", this.content.toString()); Request request = new Request( HttpMethod.POST, Domains.API.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("UserDefinedMessage creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "UserDefinedMessage creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return UserDefinedMessage.fromJson(response.getStream(), client.getObjectMapper()); + return UserDefinedMessage.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (content != null) { request.addPostParam("Content", content); - } if (idempotencyKey != null) { request.addPostParam("IdempotencyKey", idempotencyKey); - } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/UserDefinedMessageSubscription.java b/src/main/java/com/twilio/rest/api/v2010/account/call/UserDefinedMessageSubscription.java index 025191010f..ae702709e4 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/call/UserDefinedMessageSubscription.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/call/UserDefinedMessageSubscription.java @@ -23,50 +23,76 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class UserDefinedMessageSubscription extends Resource { + private static final long serialVersionUID = 182880491726748L; - public static UserDefinedMessageSubscriptionCreator creator(final String pathCallSid, final URI callback){ + public static UserDefinedMessageSubscriptionCreator creator( + final String pathCallSid, + final URI callback + ) { return new UserDefinedMessageSubscriptionCreator(pathCallSid, callback); } - public static UserDefinedMessageSubscriptionCreator creator(final String pathAccountSid, final String pathCallSid, final URI callback){ - return new UserDefinedMessageSubscriptionCreator(pathAccountSid, pathCallSid, callback); + + public static UserDefinedMessageSubscriptionCreator creator( + final String pathAccountSid, + final String pathCallSid, + final URI callback + ) { + return new UserDefinedMessageSubscriptionCreator( + pathAccountSid, + pathCallSid, + callback + ); } - public static UserDefinedMessageSubscriptionDeleter deleter(final String pathCallSid, final String pathSid){ + public static UserDefinedMessageSubscriptionDeleter deleter( + final String pathCallSid, + final String pathSid + ) { return new UserDefinedMessageSubscriptionDeleter(pathCallSid, pathSid); } - public static UserDefinedMessageSubscriptionDeleter deleter(final String pathAccountSid, final String pathCallSid, final String pathSid){ - return new UserDefinedMessageSubscriptionDeleter(pathAccountSid, pathCallSid, pathSid); + + public static UserDefinedMessageSubscriptionDeleter deleter( + final String pathAccountSid, + final String pathCallSid, + final String pathSid + ) { + return new UserDefinedMessageSubscriptionDeleter( + pathAccountSid, + pathCallSid, + pathSid + ); } /** - * Converts a JSON String into a UserDefinedMessageSubscription object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return UserDefinedMessageSubscription object represented by the provided JSON - */ - public static UserDefinedMessageSubscription fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a UserDefinedMessageSubscription object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return UserDefinedMessageSubscription object represented by the provided JSON + */ + public static UserDefinedMessageSubscription fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, UserDefinedMessageSubscription.class); + return objectMapper.readValue( + json, + UserDefinedMessageSubscription.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -75,17 +101,23 @@ public static UserDefinedMessageSubscription fromJson(final String json, final O } /** - * Converts a JSON InputStream into a UserDefinedMessageSubscription object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return UserDefinedMessageSubscription object represented by the provided JSON - */ - public static UserDefinedMessageSubscription fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a UserDefinedMessageSubscription object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return UserDefinedMessageSubscription object represented by the provided JSON + */ + public static UserDefinedMessageSubscription fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, UserDefinedMessageSubscription.class); + return objectMapper.readValue( + json, + UserDefinedMessageSubscription.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -101,20 +133,11 @@ public static UserDefinedMessageSubscription fromJson(final InputStream json, fi @JsonCreator private UserDefinedMessageSubscription( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("call_sid") - final String callSid, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("uri") - final String uri + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("call_sid") final String callSid, + @JsonProperty("sid") final String sid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("uri") final String uri ) { this.accountSid = accountSid; this.callSid = callSid; @@ -123,25 +146,29 @@ private UserDefinedMessageSubscription( this.uri = uri; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getCallSid() { - return this.callSid; - } - public final String getSid() { - return this.sid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final String getUri() { - return this.uri; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getCallSid() { + return this.callSid; + } + + public final String getSid() { + return this.sid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final String getUri() { + return this.uri; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -149,15 +176,20 @@ public boolean equals(final Object o) { return false; } - UserDefinedMessageSubscription other = (UserDefinedMessageSubscription) o; + UserDefinedMessageSubscription other = + (UserDefinedMessageSubscription) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(callSid, other.callSid) && Objects.equals(sid, other.sid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(uri, other.uri) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(callSid, other.callSid) && + Objects.equals(sid, other.sid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(uri, other.uri) + ); } @Override public int hashCode() { return Objects.hash(accountSid, callSid, sid, dateCreated, uri); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/UserDefinedMessageSubscriptionCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/call/UserDefinedMessageSubscriptionCreator.java index ac387a6561..09a8d86c67 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/call/UserDefinedMessageSubscriptionCreator.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/call/UserDefinedMessageSubscriptionCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010.account.call; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -25,85 +26,119 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.net.URI; - - - import java.net.URI; -public class UserDefinedMessageSubscriptionCreator extends Creator{ +public class UserDefinedMessageSubscriptionCreator + extends Creator { + private String pathCallSid; private URI callback; private String pathAccountSid; private String idempotencyKey; private HttpMethod method; - public UserDefinedMessageSubscriptionCreator(final String pathCallSid, final URI callback) { + public UserDefinedMessageSubscriptionCreator( + final String pathCallSid, + final URI callback + ) { this.pathCallSid = pathCallSid; this.callback = callback; } - public UserDefinedMessageSubscriptionCreator(final String pathAccountSid, final String pathCallSid, final URI callback) { + + public UserDefinedMessageSubscriptionCreator( + final String pathAccountSid, + final String pathCallSid, + final URI callback + ) { this.pathAccountSid = pathAccountSid; this.pathCallSid = pathCallSid; this.callback = callback; } - public UserDefinedMessageSubscriptionCreator setCallback(final URI callback){ + public UserDefinedMessageSubscriptionCreator setCallback( + final URI callback + ) { this.callback = callback; return this; } - public UserDefinedMessageSubscriptionCreator setCallback(final String callback){ + public UserDefinedMessageSubscriptionCreator setCallback( + final String callback + ) { return setCallback(Promoter.uriFromString(callback)); } - public UserDefinedMessageSubscriptionCreator setIdempotencyKey(final String idempotencyKey){ + + public UserDefinedMessageSubscriptionCreator setIdempotencyKey( + final String idempotencyKey + ) { this.idempotencyKey = idempotencyKey; return this; } - public UserDefinedMessageSubscriptionCreator setMethod(final HttpMethod method){ + + public UserDefinedMessageSubscriptionCreator setMethod( + final HttpMethod method + ) { this.method = method; return this; } @Override - public UserDefinedMessageSubscription create(final TwilioRestClient client){ - String path = "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/UserDefinedMessageSubscriptions.json"; + public UserDefinedMessageSubscription create( + final TwilioRestClient client + ) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/UserDefinedMessageSubscriptions.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"CallSid"+"}", this.pathCallSid.toString()); - path = path.replace("{"+"Callback"+"}", this.callback.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "CallSid" + "}", this.pathCallSid.toString()); + path = path.replace("{" + "Callback" + "}", this.callback.toString()); Request request = new Request( HttpMethod.POST, Domains.API.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("UserDefinedMessageSubscription creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "UserDefinedMessageSubscription creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return UserDefinedMessageSubscription.fromJson(response.getStream(), client.getObjectMapper()); + return UserDefinedMessageSubscription.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (callback != null) { request.addPostParam("Callback", callback.toString()); - } if (idempotencyKey != null) { request.addPostParam("IdempotencyKey", idempotencyKey); - } if (method != null) { request.addPostParam("Method", method.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/UserDefinedMessageSubscriptionDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/call/UserDefinedMessageSubscriptionDeleter.java index 49adb888d9..44cf0ca56b 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/call/UserDefinedMessageSubscriptionDeleter.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/call/UserDefinedMessageSubscriptionDeleter.java @@ -24,32 +24,47 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class UserDefinedMessageSubscriptionDeleter + extends Deleter { - -public class UserDefinedMessageSubscriptionDeleter extends Deleter { private String pathCallSid; private String pathSid; private String pathAccountSid; - public UserDefinedMessageSubscriptionDeleter(final String pathCallSid, final String pathSid){ + public UserDefinedMessageSubscriptionDeleter( + final String pathCallSid, + final String pathSid + ) { this.pathCallSid = pathCallSid; this.pathSid = pathSid; } - public UserDefinedMessageSubscriptionDeleter(final String pathAccountSid, final String pathCallSid, final String pathSid){ + + public UserDefinedMessageSubscriptionDeleter( + final String pathAccountSid, + final String pathCallSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathCallSid = pathCallSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/UserDefinedMessageSubscriptions/{Sid}.json"; + String path = + "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/UserDefinedMessageSubscriptions/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"CallSid"+"}", this.pathCallSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "CallSid" + "}", this.pathCallSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -59,9 +74,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("UserDefinedMessageSubscription delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "UserDefinedMessageSubscription delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/conference/Participant.java b/src/main/java/com/twilio/rest/api/v2010/account/conference/Participant.java index 0607f4b1cb..be442ba6c9 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/conference/Participant.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/conference/Participant.java @@ -24,67 +24,121 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Participant extends Resource { + private static final long serialVersionUID = 78654773226378L; - public static ParticipantCreator creator(final String pathConferenceSid, final com.twilio.type.Endpoint from, final com.twilio.type.Endpoint to){ + public static ParticipantCreator creator( + final String pathConferenceSid, + final com.twilio.type.Endpoint from, + final com.twilio.type.Endpoint to + ) { return new ParticipantCreator(pathConferenceSid, from, to); } - public static ParticipantCreator creator(final String pathAccountSid, final String pathConferenceSid, final com.twilio.type.Endpoint from, final com.twilio.type.Endpoint to){ - return new ParticipantCreator(pathAccountSid, pathConferenceSid, from, to); + + public static ParticipantCreator creator( + final String pathAccountSid, + final String pathConferenceSid, + final com.twilio.type.Endpoint from, + final com.twilio.type.Endpoint to + ) { + return new ParticipantCreator( + pathAccountSid, + pathConferenceSid, + from, + to + ); } - public static ParticipantDeleter deleter(final String pathConferenceSid, final String pathCallSid){ + public static ParticipantDeleter deleter( + final String pathConferenceSid, + final String pathCallSid + ) { return new ParticipantDeleter(pathConferenceSid, pathCallSid); } - public static ParticipantDeleter deleter(final String pathAccountSid, final String pathConferenceSid, final String pathCallSid){ - return new ParticipantDeleter(pathAccountSid, pathConferenceSid, pathCallSid); + + public static ParticipantDeleter deleter( + final String pathAccountSid, + final String pathConferenceSid, + final String pathCallSid + ) { + return new ParticipantDeleter( + pathAccountSid, + pathConferenceSid, + pathCallSid + ); } - public static ParticipantFetcher fetcher(final String pathConferenceSid, final String pathCallSid){ + public static ParticipantFetcher fetcher( + final String pathConferenceSid, + final String pathCallSid + ) { return new ParticipantFetcher(pathConferenceSid, pathCallSid); } - public static ParticipantFetcher fetcher(final String pathAccountSid, final String pathConferenceSid, final String pathCallSid){ - return new ParticipantFetcher(pathAccountSid, pathConferenceSid, pathCallSid); + + public static ParticipantFetcher fetcher( + final String pathAccountSid, + final String pathConferenceSid, + final String pathCallSid + ) { + return new ParticipantFetcher( + pathAccountSid, + pathConferenceSid, + pathCallSid + ); } - public static ParticipantReader reader(final String pathConferenceSid){ + public static ParticipantReader reader(final String pathConferenceSid) { return new ParticipantReader(pathConferenceSid); } - public static ParticipantReader reader(final String pathAccountSid, final String pathConferenceSid){ + + public static ParticipantReader reader( + final String pathAccountSid, + final String pathConferenceSid + ) { return new ParticipantReader(pathAccountSid, pathConferenceSid); } - public static ParticipantUpdater updater(final String pathConferenceSid, final String pathCallSid){ + public static ParticipantUpdater updater( + final String pathConferenceSid, + final String pathCallSid + ) { return new ParticipantUpdater(pathConferenceSid, pathCallSid); } - public static ParticipantUpdater updater(final String pathAccountSid, final String pathConferenceSid, final String pathCallSid){ - return new ParticipantUpdater(pathAccountSid, pathConferenceSid, pathCallSid); + + public static ParticipantUpdater updater( + final String pathAccountSid, + final String pathConferenceSid, + final String pathCallSid + ) { + return new ParticipantUpdater( + pathAccountSid, + pathConferenceSid, + pathCallSid + ); } /** - * Converts a JSON String into a Participant object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Participant object represented by the provided JSON - */ - public static Participant fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Participant object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Participant object represented by the provided JSON + */ + public static Participant fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Participant.class); @@ -96,14 +150,17 @@ public static Participant fromJson(final String json, final ObjectMapper objectM } /** - * Converts a JSON InputStream into a Participant object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Participant object represented by the provided JSON - */ - public static Participant fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Participant object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Participant object represented by the provided JSON + */ + public static Participant fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Participant.class); @@ -113,6 +170,7 @@ public static Participant fromJson(final InputStream json, final ObjectMapper ob throw new ApiConnectionException(e.getMessage(), e); } } + public enum Status { QUEUED("queued"), CONNECTING("connecting"), @@ -154,47 +212,24 @@ public static Status forValue(final String value) { @JsonCreator private Participant( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("call_sid") - final String callSid, - - @JsonProperty("label") - final String label, - - @JsonProperty("call_sid_to_coach") - final String callSidToCoach, - - @JsonProperty("coaching") - final Boolean coaching, - - @JsonProperty("conference_sid") - final String conferenceSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("end_conference_on_exit") - final Boolean endConferenceOnExit, - - @JsonProperty("muted") - final Boolean muted, - - @JsonProperty("hold") - final Boolean hold, - - @JsonProperty("start_conference_on_enter") - final Boolean startConferenceOnEnter, - - @JsonProperty("status") - final Participant.Status status, - - @JsonProperty("uri") - final String uri + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("call_sid") final String callSid, + @JsonProperty("label") final String label, + @JsonProperty("call_sid_to_coach") final String callSidToCoach, + @JsonProperty("coaching") final Boolean coaching, + @JsonProperty("conference_sid") final String conferenceSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty( + "end_conference_on_exit" + ) final Boolean endConferenceOnExit, + @JsonProperty("muted") final Boolean muted, + @JsonProperty("hold") final Boolean hold, + @JsonProperty( + "start_conference_on_enter" + ) final Boolean startConferenceOnEnter, + @JsonProperty("status") final Participant.Status status, + @JsonProperty("uri") final String uri ) { this.accountSid = accountSid; this.callSid = callSid; @@ -212,52 +247,65 @@ private Participant( this.uri = uri; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getCallSid() { - return this.callSid; - } - public final String getLabel() { - return this.label; - } - public final String getCallSidToCoach() { - return this.callSidToCoach; - } - public final Boolean getCoaching() { - return this.coaching; - } - public final String getConferenceSid() { - return this.conferenceSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final Boolean getEndConferenceOnExit() { - return this.endConferenceOnExit; - } - public final Boolean getMuted() { - return this.muted; - } - public final Boolean getHold() { - return this.hold; - } - public final Boolean getStartConferenceOnEnter() { - return this.startConferenceOnEnter; - } - public final Participant.Status getStatus() { - return this.status; - } - public final String getUri() { - return this.uri; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getCallSid() { + return this.callSid; + } + + public final String getLabel() { + return this.label; + } + + public final String getCallSidToCoach() { + return this.callSidToCoach; + } + + public final Boolean getCoaching() { + return this.coaching; + } + + public final String getConferenceSid() { + return this.conferenceSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final Boolean getEndConferenceOnExit() { + return this.endConferenceOnExit; + } + + public final Boolean getMuted() { + return this.muted; + } + + public final Boolean getHold() { + return this.hold; + } + + public final Boolean getStartConferenceOnEnter() { + return this.startConferenceOnEnter; + } + + public final Participant.Status getStatus() { + return this.status; + } + + public final String getUri() { + return this.uri; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -267,13 +315,44 @@ public boolean equals(final Object o) { Participant other = (Participant) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(callSid, other.callSid) && Objects.equals(label, other.label) && Objects.equals(callSidToCoach, other.callSidToCoach) && Objects.equals(coaching, other.coaching) && Objects.equals(conferenceSid, other.conferenceSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(endConferenceOnExit, other.endConferenceOnExit) && Objects.equals(muted, other.muted) && Objects.equals(hold, other.hold) && Objects.equals(startConferenceOnEnter, other.startConferenceOnEnter) && Objects.equals(status, other.status) && Objects.equals(uri, other.uri) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(callSid, other.callSid) && + Objects.equals(label, other.label) && + Objects.equals(callSidToCoach, other.callSidToCoach) && + Objects.equals(coaching, other.coaching) && + Objects.equals(conferenceSid, other.conferenceSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(endConferenceOnExit, other.endConferenceOnExit) && + Objects.equals(muted, other.muted) && + Objects.equals(hold, other.hold) && + Objects.equals( + startConferenceOnEnter, + other.startConferenceOnEnter + ) && + Objects.equals(status, other.status) && + Objects.equals(uri, other.uri) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, callSid, label, callSidToCoach, coaching, conferenceSid, dateCreated, dateUpdated, endConferenceOnExit, muted, hold, startConferenceOnEnter, status, uri); + return Objects.hash( + accountSid, + callSid, + label, + callSidToCoach, + coaching, + conferenceSid, + dateCreated, + dateUpdated, + endConferenceOnExit, + muted, + hold, + startConferenceOnEnter, + status, + uri + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/conference/ParticipantCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/conference/ParticipantCreator.java index 585ca8a2c5..00f96a518d 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/conference/ParticipantCreator.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/conference/ParticipantCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010.account.conference; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -24,15 +25,13 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import java.util.List; import java.net.URI; - +import java.net.URI; +import java.util.List; import java.util.List; +public class ParticipantCreator extends Creator { -import java.net.URI; - -public class ParticipantCreator extends Creator{ private String pathConferenceSid; private com.twilio.type.Endpoint from; private com.twilio.type.Endpoint to; @@ -83,468 +82,631 @@ public class ParticipantCreator extends Creator{ private HttpMethod amdStatusCallbackMethod; private String trim; - public ParticipantCreator(final String pathConferenceSid, final com.twilio.type.Endpoint from, final com.twilio.type.Endpoint to) { + public ParticipantCreator( + final String pathConferenceSid, + final com.twilio.type.Endpoint from, + final com.twilio.type.Endpoint to + ) { this.pathConferenceSid = pathConferenceSid; this.from = from; this.to = to; } - public ParticipantCreator(final String pathAccountSid, final String pathConferenceSid, final com.twilio.type.Endpoint from, final com.twilio.type.Endpoint to) { + + public ParticipantCreator( + final String pathAccountSid, + final String pathConferenceSid, + final com.twilio.type.Endpoint from, + final com.twilio.type.Endpoint to + ) { this.pathAccountSid = pathAccountSid; this.pathConferenceSid = pathConferenceSid; this.from = from; this.to = to; } - public ParticipantCreator setFrom(final com.twilio.type.Endpoint from){ + public ParticipantCreator setFrom(final com.twilio.type.Endpoint from) { this.from = from; return this; } - public ParticipantCreator setTo(final com.twilio.type.Endpoint to){ + + public ParticipantCreator setTo(final com.twilio.type.Endpoint to) { this.to = to; return this; } - public ParticipantCreator setStatusCallback(final URI statusCallback){ + + public ParticipantCreator setStatusCallback(final URI statusCallback) { this.statusCallback = statusCallback; return this; } - public ParticipantCreator setStatusCallback(final String statusCallback){ + public ParticipantCreator setStatusCallback(final String statusCallback) { return setStatusCallback(Promoter.uriFromString(statusCallback)); } - public ParticipantCreator setStatusCallbackMethod(final HttpMethod statusCallbackMethod){ + + public ParticipantCreator setStatusCallbackMethod( + final HttpMethod statusCallbackMethod + ) { this.statusCallbackMethod = statusCallbackMethod; return this; } - public ParticipantCreator setStatusCallbackEvent(final List statusCallbackEvent){ + + public ParticipantCreator setStatusCallbackEvent( + final List statusCallbackEvent + ) { this.statusCallbackEvent = statusCallbackEvent; return this; } - public ParticipantCreator setStatusCallbackEvent(final String statusCallbackEvent){ + + public ParticipantCreator setStatusCallbackEvent( + final String statusCallbackEvent + ) { return setStatusCallbackEvent(Promoter.listOfOne(statusCallbackEvent)); } - public ParticipantCreator setLabel(final String label){ + + public ParticipantCreator setLabel(final String label) { this.label = label; return this; } - public ParticipantCreator setTimeout(final Integer timeout){ + + public ParticipantCreator setTimeout(final Integer timeout) { this.timeout = timeout; return this; } - public ParticipantCreator setRecord(final Boolean record){ + + public ParticipantCreator setRecord(final Boolean record) { this.record = record; return this; } - public ParticipantCreator setMuted(final Boolean muted){ + + public ParticipantCreator setMuted(final Boolean muted) { this.muted = muted; return this; } - public ParticipantCreator setBeep(final String beep){ + + public ParticipantCreator setBeep(final String beep) { this.beep = beep; return this; } - public ParticipantCreator setStartConferenceOnEnter(final Boolean startConferenceOnEnter){ + + public ParticipantCreator setStartConferenceOnEnter( + final Boolean startConferenceOnEnter + ) { this.startConferenceOnEnter = startConferenceOnEnter; return this; } - public ParticipantCreator setEndConferenceOnExit(final Boolean endConferenceOnExit){ + + public ParticipantCreator setEndConferenceOnExit( + final Boolean endConferenceOnExit + ) { this.endConferenceOnExit = endConferenceOnExit; return this; } - public ParticipantCreator setWaitUrl(final URI waitUrl){ + + public ParticipantCreator setWaitUrl(final URI waitUrl) { this.waitUrl = waitUrl; return this; } - public ParticipantCreator setWaitUrl(final String waitUrl){ + public ParticipantCreator setWaitUrl(final String waitUrl) { return setWaitUrl(Promoter.uriFromString(waitUrl)); } - public ParticipantCreator setWaitMethod(final HttpMethod waitMethod){ + + public ParticipantCreator setWaitMethod(final HttpMethod waitMethod) { this.waitMethod = waitMethod; return this; } - public ParticipantCreator setEarlyMedia(final Boolean earlyMedia){ + + public ParticipantCreator setEarlyMedia(final Boolean earlyMedia) { this.earlyMedia = earlyMedia; return this; } - public ParticipantCreator setMaxParticipants(final Integer maxParticipants){ + + public ParticipantCreator setMaxParticipants( + final Integer maxParticipants + ) { this.maxParticipants = maxParticipants; return this; } - public ParticipantCreator setConferenceRecord(final String conferenceRecord){ + + public ParticipantCreator setConferenceRecord( + final String conferenceRecord + ) { this.conferenceRecord = conferenceRecord; return this; } - public ParticipantCreator setConferenceTrim(final String conferenceTrim){ + + public ParticipantCreator setConferenceTrim(final String conferenceTrim) { this.conferenceTrim = conferenceTrim; return this; } - public ParticipantCreator setConferenceStatusCallback(final URI conferenceStatusCallback){ + + public ParticipantCreator setConferenceStatusCallback( + final URI conferenceStatusCallback + ) { this.conferenceStatusCallback = conferenceStatusCallback; return this; } - public ParticipantCreator setConferenceStatusCallback(final String conferenceStatusCallback){ - return setConferenceStatusCallback(Promoter.uriFromString(conferenceStatusCallback)); + public ParticipantCreator setConferenceStatusCallback( + final String conferenceStatusCallback + ) { + return setConferenceStatusCallback( + Promoter.uriFromString(conferenceStatusCallback) + ); } - public ParticipantCreator setConferenceStatusCallbackMethod(final HttpMethod conferenceStatusCallbackMethod){ + + public ParticipantCreator setConferenceStatusCallbackMethod( + final HttpMethod conferenceStatusCallbackMethod + ) { this.conferenceStatusCallbackMethod = conferenceStatusCallbackMethod; return this; } - public ParticipantCreator setConferenceStatusCallbackEvent(final List conferenceStatusCallbackEvent){ + + public ParticipantCreator setConferenceStatusCallbackEvent( + final List conferenceStatusCallbackEvent + ) { this.conferenceStatusCallbackEvent = conferenceStatusCallbackEvent; return this; } - public ParticipantCreator setConferenceStatusCallbackEvent(final String conferenceStatusCallbackEvent){ - return setConferenceStatusCallbackEvent(Promoter.listOfOne(conferenceStatusCallbackEvent)); + + public ParticipantCreator setConferenceStatusCallbackEvent( + final String conferenceStatusCallbackEvent + ) { + return setConferenceStatusCallbackEvent( + Promoter.listOfOne(conferenceStatusCallbackEvent) + ); } - public ParticipantCreator setRecordingChannels(final String recordingChannels){ + + public ParticipantCreator setRecordingChannels( + final String recordingChannels + ) { this.recordingChannels = recordingChannels; return this; } - public ParticipantCreator setRecordingStatusCallback(final URI recordingStatusCallback){ + + public ParticipantCreator setRecordingStatusCallback( + final URI recordingStatusCallback + ) { this.recordingStatusCallback = recordingStatusCallback; return this; } - public ParticipantCreator setRecordingStatusCallback(final String recordingStatusCallback){ - return setRecordingStatusCallback(Promoter.uriFromString(recordingStatusCallback)); + public ParticipantCreator setRecordingStatusCallback( + final String recordingStatusCallback + ) { + return setRecordingStatusCallback( + Promoter.uriFromString(recordingStatusCallback) + ); } - public ParticipantCreator setRecordingStatusCallbackMethod(final HttpMethod recordingStatusCallbackMethod){ + + public ParticipantCreator setRecordingStatusCallbackMethod( + final HttpMethod recordingStatusCallbackMethod + ) { this.recordingStatusCallbackMethod = recordingStatusCallbackMethod; return this; } - public ParticipantCreator setSipAuthUsername(final String sipAuthUsername){ + + public ParticipantCreator setSipAuthUsername(final String sipAuthUsername) { this.sipAuthUsername = sipAuthUsername; return this; } - public ParticipantCreator setSipAuthPassword(final String sipAuthPassword){ + + public ParticipantCreator setSipAuthPassword(final String sipAuthPassword) { this.sipAuthPassword = sipAuthPassword; return this; } - public ParticipantCreator setRegion(final String region){ + + public ParticipantCreator setRegion(final String region) { this.region = region; return this; } - public ParticipantCreator setConferenceRecordingStatusCallback(final URI conferenceRecordingStatusCallback){ - this.conferenceRecordingStatusCallback = conferenceRecordingStatusCallback; + + public ParticipantCreator setConferenceRecordingStatusCallback( + final URI conferenceRecordingStatusCallback + ) { + this.conferenceRecordingStatusCallback = + conferenceRecordingStatusCallback; return this; } - public ParticipantCreator setConferenceRecordingStatusCallback(final String conferenceRecordingStatusCallback){ - return setConferenceRecordingStatusCallback(Promoter.uriFromString(conferenceRecordingStatusCallback)); + public ParticipantCreator setConferenceRecordingStatusCallback( + final String conferenceRecordingStatusCallback + ) { + return setConferenceRecordingStatusCallback( + Promoter.uriFromString(conferenceRecordingStatusCallback) + ); } - public ParticipantCreator setConferenceRecordingStatusCallbackMethod(final HttpMethod conferenceRecordingStatusCallbackMethod){ - this.conferenceRecordingStatusCallbackMethod = conferenceRecordingStatusCallbackMethod; + + public ParticipantCreator setConferenceRecordingStatusCallbackMethod( + final HttpMethod conferenceRecordingStatusCallbackMethod + ) { + this.conferenceRecordingStatusCallbackMethod = + conferenceRecordingStatusCallbackMethod; return this; } - public ParticipantCreator setRecordingStatusCallbackEvent(final List recordingStatusCallbackEvent){ + + public ParticipantCreator setRecordingStatusCallbackEvent( + final List recordingStatusCallbackEvent + ) { this.recordingStatusCallbackEvent = recordingStatusCallbackEvent; return this; } - public ParticipantCreator setRecordingStatusCallbackEvent(final String recordingStatusCallbackEvent){ - return setRecordingStatusCallbackEvent(Promoter.listOfOne(recordingStatusCallbackEvent)); + + public ParticipantCreator setRecordingStatusCallbackEvent( + final String recordingStatusCallbackEvent + ) { + return setRecordingStatusCallbackEvent( + Promoter.listOfOne(recordingStatusCallbackEvent) + ); } - public ParticipantCreator setConferenceRecordingStatusCallbackEvent(final List conferenceRecordingStatusCallbackEvent){ - this.conferenceRecordingStatusCallbackEvent = conferenceRecordingStatusCallbackEvent; + + public ParticipantCreator setConferenceRecordingStatusCallbackEvent( + final List conferenceRecordingStatusCallbackEvent + ) { + this.conferenceRecordingStatusCallbackEvent = + conferenceRecordingStatusCallbackEvent; return this; } - public ParticipantCreator setConferenceRecordingStatusCallbackEvent(final String conferenceRecordingStatusCallbackEvent){ - return setConferenceRecordingStatusCallbackEvent(Promoter.listOfOne(conferenceRecordingStatusCallbackEvent)); + + public ParticipantCreator setConferenceRecordingStatusCallbackEvent( + final String conferenceRecordingStatusCallbackEvent + ) { + return setConferenceRecordingStatusCallbackEvent( + Promoter.listOfOne(conferenceRecordingStatusCallbackEvent) + ); } - public ParticipantCreator setCoaching(final Boolean coaching){ + + public ParticipantCreator setCoaching(final Boolean coaching) { this.coaching = coaching; return this; } - public ParticipantCreator setCallSidToCoach(final String callSidToCoach){ + + public ParticipantCreator setCallSidToCoach(final String callSidToCoach) { this.callSidToCoach = callSidToCoach; return this; } - public ParticipantCreator setJitterBufferSize(final String jitterBufferSize){ + + public ParticipantCreator setJitterBufferSize( + final String jitterBufferSize + ) { this.jitterBufferSize = jitterBufferSize; return this; } - public ParticipantCreator setByoc(final String byoc){ + + public ParticipantCreator setByoc(final String byoc) { this.byoc = byoc; return this; } - public ParticipantCreator setCallerId(final String callerId){ + + public ParticipantCreator setCallerId(final String callerId) { this.callerId = callerId; return this; } - public ParticipantCreator setCallReason(final String callReason){ + + public ParticipantCreator setCallReason(final String callReason) { this.callReason = callReason; return this; } - public ParticipantCreator setRecordingTrack(final String recordingTrack){ + + public ParticipantCreator setRecordingTrack(final String recordingTrack) { this.recordingTrack = recordingTrack; return this; } - public ParticipantCreator setTimeLimit(final Integer timeLimit){ + + public ParticipantCreator setTimeLimit(final Integer timeLimit) { this.timeLimit = timeLimit; return this; } - public ParticipantCreator setMachineDetection(final String machineDetection){ + + public ParticipantCreator setMachineDetection( + final String machineDetection + ) { this.machineDetection = machineDetection; return this; } - public ParticipantCreator setMachineDetectionTimeout(final Integer machineDetectionTimeout){ + + public ParticipantCreator setMachineDetectionTimeout( + final Integer machineDetectionTimeout + ) { this.machineDetectionTimeout = machineDetectionTimeout; return this; } - public ParticipantCreator setMachineDetectionSpeechThreshold(final Integer machineDetectionSpeechThreshold){ + + public ParticipantCreator setMachineDetectionSpeechThreshold( + final Integer machineDetectionSpeechThreshold + ) { this.machineDetectionSpeechThreshold = machineDetectionSpeechThreshold; return this; } - public ParticipantCreator setMachineDetectionSpeechEndThreshold(final Integer machineDetectionSpeechEndThreshold){ - this.machineDetectionSpeechEndThreshold = machineDetectionSpeechEndThreshold; + + public ParticipantCreator setMachineDetectionSpeechEndThreshold( + final Integer machineDetectionSpeechEndThreshold + ) { + this.machineDetectionSpeechEndThreshold = + machineDetectionSpeechEndThreshold; return this; } - public ParticipantCreator setMachineDetectionSilenceTimeout(final Integer machineDetectionSilenceTimeout){ + + public ParticipantCreator setMachineDetectionSilenceTimeout( + final Integer machineDetectionSilenceTimeout + ) { this.machineDetectionSilenceTimeout = machineDetectionSilenceTimeout; return this; } - public ParticipantCreator setAmdStatusCallback(final URI amdStatusCallback){ + + public ParticipantCreator setAmdStatusCallback( + final URI amdStatusCallback + ) { this.amdStatusCallback = amdStatusCallback; return this; } - public ParticipantCreator setAmdStatusCallback(final String amdStatusCallback){ + public ParticipantCreator setAmdStatusCallback( + final String amdStatusCallback + ) { return setAmdStatusCallback(Promoter.uriFromString(amdStatusCallback)); } - public ParticipantCreator setAmdStatusCallbackMethod(final HttpMethod amdStatusCallbackMethod){ + + public ParticipantCreator setAmdStatusCallbackMethod( + final HttpMethod amdStatusCallbackMethod + ) { this.amdStatusCallbackMethod = amdStatusCallbackMethod; return this; } - public ParticipantCreator setTrim(final String trim){ + + public ParticipantCreator setTrim(final String trim) { this.trim = trim; return this; } @Override - public Participant create(final TwilioRestClient client){ - String path = "/2010-04-01/Accounts/{AccountSid}/Conferences/{ConferenceSid}/Participants.json"; + public Participant create(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Conferences/{ConferenceSid}/Participants.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"ConferenceSid"+"}", this.pathConferenceSid.toString()); - path = path.replace("{"+"From"+"}", this.from.toString()); - path = path.replace("{"+"To"+"}", this.to.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "ConferenceSid" + "}", + this.pathConferenceSid.toString() + ); + path = path.replace("{" + "From" + "}", this.from.toString()); + path = path.replace("{" + "To" + "}", this.to.toString()); Request request = new Request( HttpMethod.POST, Domains.API.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Participant creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Participant creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Participant.fromJson(response.getStream(), client.getObjectMapper()); + return Participant.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (from != null) { request.addPostParam("From", from.toString()); - } if (to != null) { request.addPostParam("To", to.toString()); - } if (statusCallback != null) { request.addPostParam("StatusCallback", statusCallback.toString()); - } if (statusCallbackMethod != null) { - request.addPostParam("StatusCallbackMethod", statusCallbackMethod.toString()); - + request.addPostParam( + "StatusCallbackMethod", + statusCallbackMethod.toString() + ); } if (statusCallbackEvent != null) { for (String prop : statusCallbackEvent) { request.addPostParam("StatusCallbackEvent", prop); } - } if (label != null) { request.addPostParam("Label", label); - } if (timeout != null) { request.addPostParam("Timeout", timeout.toString()); - } if (record != null) { request.addPostParam("Record", record.toString()); - } if (muted != null) { request.addPostParam("Muted", muted.toString()); - } if (beep != null) { request.addPostParam("Beep", beep); - } if (startConferenceOnEnter != null) { - request.addPostParam("StartConferenceOnEnter", startConferenceOnEnter.toString()); - + request.addPostParam( + "StartConferenceOnEnter", + startConferenceOnEnter.toString() + ); } if (endConferenceOnExit != null) { - request.addPostParam("EndConferenceOnExit", endConferenceOnExit.toString()); - + request.addPostParam( + "EndConferenceOnExit", + endConferenceOnExit.toString() + ); } if (waitUrl != null) { request.addPostParam("WaitUrl", waitUrl.toString()); - } if (waitMethod != null) { request.addPostParam("WaitMethod", waitMethod.toString()); - } if (earlyMedia != null) { request.addPostParam("EarlyMedia", earlyMedia.toString()); - } if (maxParticipants != null) { request.addPostParam("MaxParticipants", maxParticipants.toString()); - } if (conferenceRecord != null) { request.addPostParam("ConferenceRecord", conferenceRecord); - } if (conferenceTrim != null) { request.addPostParam("ConferenceTrim", conferenceTrim); - } if (conferenceStatusCallback != null) { - request.addPostParam("ConferenceStatusCallback", conferenceStatusCallback.toString()); - + request.addPostParam( + "ConferenceStatusCallback", + conferenceStatusCallback.toString() + ); } if (conferenceStatusCallbackMethod != null) { - request.addPostParam("ConferenceStatusCallbackMethod", conferenceStatusCallbackMethod.toString()); - + request.addPostParam( + "ConferenceStatusCallbackMethod", + conferenceStatusCallbackMethod.toString() + ); } if (conferenceStatusCallbackEvent != null) { for (String prop : conferenceStatusCallbackEvent) { request.addPostParam("ConferenceStatusCallbackEvent", prop); } - } if (recordingChannels != null) { request.addPostParam("RecordingChannels", recordingChannels); - } if (recordingStatusCallback != null) { - request.addPostParam("RecordingStatusCallback", recordingStatusCallback.toString()); - + request.addPostParam( + "RecordingStatusCallback", + recordingStatusCallback.toString() + ); } if (recordingStatusCallbackMethod != null) { - request.addPostParam("RecordingStatusCallbackMethod", recordingStatusCallbackMethod.toString()); - + request.addPostParam( + "RecordingStatusCallbackMethod", + recordingStatusCallbackMethod.toString() + ); } if (sipAuthUsername != null) { request.addPostParam("SipAuthUsername", sipAuthUsername); - } if (sipAuthPassword != null) { request.addPostParam("SipAuthPassword", sipAuthPassword); - } if (region != null) { request.addPostParam("Region", region); - } if (conferenceRecordingStatusCallback != null) { - request.addPostParam("ConferenceRecordingStatusCallback", conferenceRecordingStatusCallback.toString()); - + request.addPostParam( + "ConferenceRecordingStatusCallback", + conferenceRecordingStatusCallback.toString() + ); } if (conferenceRecordingStatusCallbackMethod != null) { - request.addPostParam("ConferenceRecordingStatusCallbackMethod", conferenceRecordingStatusCallbackMethod.toString()); - + request.addPostParam( + "ConferenceRecordingStatusCallbackMethod", + conferenceRecordingStatusCallbackMethod.toString() + ); } if (recordingStatusCallbackEvent != null) { for (String prop : recordingStatusCallbackEvent) { request.addPostParam("RecordingStatusCallbackEvent", prop); } - } if (conferenceRecordingStatusCallbackEvent != null) { for (String prop : conferenceRecordingStatusCallbackEvent) { - request.addPostParam("ConferenceRecordingStatusCallbackEvent", prop); + request.addPostParam( + "ConferenceRecordingStatusCallbackEvent", + prop + ); } - } if (coaching != null) { request.addPostParam("Coaching", coaching.toString()); - } if (callSidToCoach != null) { request.addPostParam("CallSidToCoach", callSidToCoach); - } if (jitterBufferSize != null) { request.addPostParam("JitterBufferSize", jitterBufferSize); - } if (byoc != null) { request.addPostParam("Byoc", byoc); - } if (callerId != null) { request.addPostParam("CallerId", callerId); - } if (callReason != null) { request.addPostParam("CallReason", callReason); - } if (recordingTrack != null) { request.addPostParam("RecordingTrack", recordingTrack); - } if (timeLimit != null) { request.addPostParam("TimeLimit", timeLimit.toString()); - } if (machineDetection != null) { request.addPostParam("MachineDetection", machineDetection); - } if (machineDetectionTimeout != null) { - request.addPostParam("MachineDetectionTimeout", machineDetectionTimeout.toString()); - + request.addPostParam( + "MachineDetectionTimeout", + machineDetectionTimeout.toString() + ); } if (machineDetectionSpeechThreshold != null) { - request.addPostParam("MachineDetectionSpeechThreshold", machineDetectionSpeechThreshold.toString()); - + request.addPostParam( + "MachineDetectionSpeechThreshold", + machineDetectionSpeechThreshold.toString() + ); } if (machineDetectionSpeechEndThreshold != null) { - request.addPostParam("MachineDetectionSpeechEndThreshold", machineDetectionSpeechEndThreshold.toString()); - + request.addPostParam( + "MachineDetectionSpeechEndThreshold", + machineDetectionSpeechEndThreshold.toString() + ); } if (machineDetectionSilenceTimeout != null) { - request.addPostParam("MachineDetectionSilenceTimeout", machineDetectionSilenceTimeout.toString()); - + request.addPostParam( + "MachineDetectionSilenceTimeout", + machineDetectionSilenceTimeout.toString() + ); } if (amdStatusCallback != null) { - request.addPostParam("AmdStatusCallback", amdStatusCallback.toString()); - + request.addPostParam( + "AmdStatusCallback", + amdStatusCallback.toString() + ); } if (amdStatusCallbackMethod != null) { - request.addPostParam("AmdStatusCallbackMethod", amdStatusCallbackMethod.toString()); - + request.addPostParam( + "AmdStatusCallbackMethod", + amdStatusCallbackMethod.toString() + ); } if (trim != null) { request.addPostParam("Trim", trim); - } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/conference/ParticipantDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/conference/ParticipantDeleter.java index 03ea60bac9..6c7bfb88c6 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/conference/ParticipantDeleter.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/conference/ParticipantDeleter.java @@ -24,32 +24,50 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class ParticipantDeleter extends Deleter { + private String pathConferenceSid; private String pathCallSid; private String pathAccountSid; - public ParticipantDeleter(final String pathConferenceSid, final String pathCallSid){ + public ParticipantDeleter( + final String pathConferenceSid, + final String pathCallSid + ) { this.pathConferenceSid = pathConferenceSid; this.pathCallSid = pathCallSid; } - public ParticipantDeleter(final String pathAccountSid, final String pathConferenceSid, final String pathCallSid){ + + public ParticipantDeleter( + final String pathAccountSid, + final String pathConferenceSid, + final String pathCallSid + ) { this.pathAccountSid = pathAccountSid; this.pathConferenceSid = pathConferenceSid; this.pathCallSid = pathCallSid; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/Conferences/{ConferenceSid}/Participants/{CallSid}.json"; + String path = + "/2010-04-01/Accounts/{AccountSid}/Conferences/{ConferenceSid}/Participants/{CallSid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"ConferenceSid"+"}", this.pathConferenceSid.toString()); - path = path.replace("{"+"CallSid"+"}", this.pathCallSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "ConferenceSid" + "}", + this.pathConferenceSid.toString() + ); + path = path.replace("{" + "CallSid" + "}", this.pathCallSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -59,9 +77,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Participant delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Participant delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/conference/ParticipantFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/conference/ParticipantFetcher.java index 49353bfe6e..36cee2d9af 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/conference/ParticipantFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/conference/ParticipantFetcher.java @@ -24,33 +24,50 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class ParticipantFetcher extends Fetcher { + private String pathConferenceSid; private String pathCallSid; private String pathAccountSid; - public ParticipantFetcher(final String pathConferenceSid, final String pathCallSid){ + public ParticipantFetcher( + final String pathConferenceSid, + final String pathCallSid + ) { this.pathConferenceSid = pathConferenceSid; this.pathCallSid = pathCallSid; } - public ParticipantFetcher(final String pathAccountSid, final String pathConferenceSid, final String pathCallSid){ + + public ParticipantFetcher( + final String pathAccountSid, + final String pathConferenceSid, + final String pathCallSid + ) { this.pathAccountSid = pathAccountSid; this.pathConferenceSid = pathConferenceSid; this.pathCallSid = pathCallSid; } - @Override public Participant fetch(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/Conferences/{ConferenceSid}/Participants/{CallSid}.json"; + String path = + "/2010-04-01/Accounts/{AccountSid}/Conferences/{ConferenceSid}/Participants/{CallSid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"ConferenceSid"+"}", this.pathConferenceSid.toString()); - path = path.replace("{"+"CallSid"+"}", this.pathCallSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "ConferenceSid" + "}", + this.pathConferenceSid.toString() + ); + path = path.replace("{" + "CallSid" + "}", this.pathCallSid.toString()); Request request = new Request( HttpMethod.GET, @@ -60,15 +77,23 @@ public Participant fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Participant fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Participant fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Participant.fromJson(response.getStream(), client.getObjectMapper()); + return Participant.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/conference/ParticipantReader.java b/src/main/java/com/twilio/rest/api/v2010/account/conference/ParticipantReader.java index eab5f0522c..f336d2613b 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/conference/ParticipantReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/conference/ParticipantReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.api.v2010.account.conference; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,11 +25,9 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class ParticipantReader extends Reader { + private String pathConferenceSid; private String pathAccountSid; private Boolean muted; @@ -36,27 +35,34 @@ public class ParticipantReader extends Reader { private Boolean coaching; private Integer pageSize; - public ParticipantReader(final String pathConferenceSid){ + public ParticipantReader(final String pathConferenceSid) { this.pathConferenceSid = pathConferenceSid; } - public ParticipantReader(final String pathAccountSid, final String pathConferenceSid){ + + public ParticipantReader( + final String pathAccountSid, + final String pathConferenceSid + ) { this.pathAccountSid = pathAccountSid; this.pathConferenceSid = pathConferenceSid; } - public ParticipantReader setMuted(final Boolean muted){ + public ParticipantReader setMuted(final Boolean muted) { this.muted = muted; return this; } - public ParticipantReader setHold(final Boolean hold){ + + public ParticipantReader setHold(final Boolean hold) { this.hold = hold; return this; } - public ParticipantReader setCoaching(final Boolean coaching){ + + public ParticipantReader setCoaching(final Boolean coaching) { this.coaching = coaching; return this; } - public ParticipantReader setPageSize(final Integer pageSize){ + + public ParticipantReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -67,10 +73,22 @@ public ResourceSet read(final TwilioRestClient client) { } public Page firstPage(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/Conferences/{ConferenceSid}/Participants.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"ConferenceSid"+"}", this.pathConferenceSid.toString()); + String path = + "/2010-04-01/Accounts/{AccountSid}/Conferences/{ConferenceSid}/Participants.json"; + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "ConferenceSid" + "}", + this.pathConferenceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -82,13 +100,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Participant read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Participant read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -104,7 +130,10 @@ private Page pageForRequest(final TwilioRestClient client, final Re } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.API.toString()) @@ -112,9 +141,11 @@ public Page previousPage(final Page page, final Twilio return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.API.toString()) @@ -123,33 +154,30 @@ public Page nextPage(final Page page, final TwilioRest } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (muted != null) { - request.addQueryParam("Muted", muted.toString()); } if (hold != null) { - request.addQueryParam("Hold", hold.toString()); } if (coaching != null) { - request.addQueryParam("Coaching", coaching.toString()); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/conference/ParticipantUpdater.java b/src/main/java/com/twilio/rest/api/v2010/account/conference/ParticipantUpdater.java index 197098997b..4586efec74 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/conference/ParticipantUpdater.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/conference/ParticipantUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010.account.conference; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -24,12 +25,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.net.URI; +public class ParticipantUpdater extends Updater { - -public class ParticipantUpdater extends Updater{ private String pathConferenceSid; private String pathCallSid; private String pathAccountSid; @@ -46,153 +45,189 @@ public class ParticipantUpdater extends Updater{ private Boolean coaching; private String callSidToCoach; - public ParticipantUpdater(final String pathConferenceSid, final String pathCallSid){ + public ParticipantUpdater( + final String pathConferenceSid, + final String pathCallSid + ) { this.pathConferenceSid = pathConferenceSid; this.pathCallSid = pathCallSid; } - public ParticipantUpdater(final String pathAccountSid, final String pathConferenceSid, final String pathCallSid){ + + public ParticipantUpdater( + final String pathAccountSid, + final String pathConferenceSid, + final String pathCallSid + ) { this.pathAccountSid = pathAccountSid; this.pathConferenceSid = pathConferenceSid; this.pathCallSid = pathCallSid; } - public ParticipantUpdater setMuted(final Boolean muted){ + public ParticipantUpdater setMuted(final Boolean muted) { this.muted = muted; return this; } - public ParticipantUpdater setHold(final Boolean hold){ + + public ParticipantUpdater setHold(final Boolean hold) { this.hold = hold; return this; } - public ParticipantUpdater setHoldUrl(final URI holdUrl){ + + public ParticipantUpdater setHoldUrl(final URI holdUrl) { this.holdUrl = holdUrl; return this; } - public ParticipantUpdater setHoldUrl(final String holdUrl){ + public ParticipantUpdater setHoldUrl(final String holdUrl) { return setHoldUrl(Promoter.uriFromString(holdUrl)); } - public ParticipantUpdater setHoldMethod(final HttpMethod holdMethod){ + + public ParticipantUpdater setHoldMethod(final HttpMethod holdMethod) { this.holdMethod = holdMethod; return this; } - public ParticipantUpdater setAnnounceUrl(final URI announceUrl){ + + public ParticipantUpdater setAnnounceUrl(final URI announceUrl) { this.announceUrl = announceUrl; return this; } - public ParticipantUpdater setAnnounceUrl(final String announceUrl){ + public ParticipantUpdater setAnnounceUrl(final String announceUrl) { return setAnnounceUrl(Promoter.uriFromString(announceUrl)); } - public ParticipantUpdater setAnnounceMethod(final HttpMethod announceMethod){ + + public ParticipantUpdater setAnnounceMethod( + final HttpMethod announceMethod + ) { this.announceMethod = announceMethod; return this; } - public ParticipantUpdater setWaitUrl(final URI waitUrl){ + + public ParticipantUpdater setWaitUrl(final URI waitUrl) { this.waitUrl = waitUrl; return this; } - public ParticipantUpdater setWaitUrl(final String waitUrl){ + public ParticipantUpdater setWaitUrl(final String waitUrl) { return setWaitUrl(Promoter.uriFromString(waitUrl)); } - public ParticipantUpdater setWaitMethod(final HttpMethod waitMethod){ + + public ParticipantUpdater setWaitMethod(final HttpMethod waitMethod) { this.waitMethod = waitMethod; return this; } - public ParticipantUpdater setBeepOnExit(final Boolean beepOnExit){ + + public ParticipantUpdater setBeepOnExit(final Boolean beepOnExit) { this.beepOnExit = beepOnExit; return this; } - public ParticipantUpdater setEndConferenceOnExit(final Boolean endConferenceOnExit){ + + public ParticipantUpdater setEndConferenceOnExit( + final Boolean endConferenceOnExit + ) { this.endConferenceOnExit = endConferenceOnExit; return this; } - public ParticipantUpdater setCoaching(final Boolean coaching){ + + public ParticipantUpdater setCoaching(final Boolean coaching) { this.coaching = coaching; return this; } - public ParticipantUpdater setCallSidToCoach(final String callSidToCoach){ + + public ParticipantUpdater setCallSidToCoach(final String callSidToCoach) { this.callSidToCoach = callSidToCoach; return this; } @Override - public Participant update(final TwilioRestClient client){ - String path = "/2010-04-01/Accounts/{AccountSid}/Conferences/{ConferenceSid}/Participants/{CallSid}.json"; + public Participant update(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Conferences/{ConferenceSid}/Participants/{CallSid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"ConferenceSid"+"}", this.pathConferenceSid.toString()); - path = path.replace("{"+"CallSid"+"}", this.pathCallSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "ConferenceSid" + "}", + this.pathConferenceSid.toString() + ); + path = path.replace("{" + "CallSid" + "}", this.pathCallSid.toString()); Request request = new Request( HttpMethod.POST, Domains.API.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Participant update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Participant update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Participant.fromJson(response.getStream(), client.getObjectMapper()); + return Participant.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (muted != null) { request.addPostParam("Muted", muted.toString()); - } if (hold != null) { request.addPostParam("Hold", hold.toString()); - } if (holdUrl != null) { request.addPostParam("HoldUrl", holdUrl.toString()); - } if (holdMethod != null) { request.addPostParam("HoldMethod", holdMethod.toString()); - } if (announceUrl != null) { request.addPostParam("AnnounceUrl", announceUrl.toString()); - } if (announceMethod != null) { request.addPostParam("AnnounceMethod", announceMethod.toString()); - } if (waitUrl != null) { request.addPostParam("WaitUrl", waitUrl.toString()); - } if (waitMethod != null) { request.addPostParam("WaitMethod", waitMethod.toString()); - } if (beepOnExit != null) { request.addPostParam("BeepOnExit", beepOnExit.toString()); - } if (endConferenceOnExit != null) { - request.addPostParam("EndConferenceOnExit", endConferenceOnExit.toString()); - + request.addPostParam( + "EndConferenceOnExit", + endConferenceOnExit.toString() + ); } if (coaching != null) { request.addPostParam("Coaching", coaching.toString()); - } if (callSidToCoach != null) { request.addPostParam("CallSidToCoach", callSidToCoach); - } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/conference/Recording.java b/src/main/java/com/twilio/rest/api/v2010/account/conference/Recording.java index cea61eb962..751d5d3fda 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/conference/Recording.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/conference/Recording.java @@ -20,69 +20,103 @@ import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.twilio.base.Resource; -import java.util.Currency; +import com.twilio.converter.CurrencyDeserializer; import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; -import com.twilio.converter.CurrencyDeserializer; import com.twilio.exception.ApiConnectionException; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.time.ZonedDateTime; - +import java.util.Currency; import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Recording extends Resource { + private static final long serialVersionUID = 71375271651535L; - public static RecordingDeleter deleter(final String pathConferenceSid, final String pathSid){ + public static RecordingDeleter deleter( + final String pathConferenceSid, + final String pathSid + ) { return new RecordingDeleter(pathConferenceSid, pathSid); } - public static RecordingDeleter deleter(final String pathAccountSid, final String pathConferenceSid, final String pathSid){ + + public static RecordingDeleter deleter( + final String pathAccountSid, + final String pathConferenceSid, + final String pathSid + ) { return new RecordingDeleter(pathAccountSid, pathConferenceSid, pathSid); } - public static RecordingFetcher fetcher(final String pathConferenceSid, final String pathSid){ + public static RecordingFetcher fetcher( + final String pathConferenceSid, + final String pathSid + ) { return new RecordingFetcher(pathConferenceSid, pathSid); } - public static RecordingFetcher fetcher(final String pathAccountSid, final String pathConferenceSid, final String pathSid){ + + public static RecordingFetcher fetcher( + final String pathAccountSid, + final String pathConferenceSid, + final String pathSid + ) { return new RecordingFetcher(pathAccountSid, pathConferenceSid, pathSid); } - public static RecordingReader reader(final String pathConferenceSid){ + public static RecordingReader reader(final String pathConferenceSid) { return new RecordingReader(pathConferenceSid); } - public static RecordingReader reader(final String pathAccountSid, final String pathConferenceSid){ + + public static RecordingReader reader( + final String pathAccountSid, + final String pathConferenceSid + ) { return new RecordingReader(pathAccountSid, pathConferenceSid); } - public static RecordingUpdater updater(final String pathConferenceSid, final String pathSid, final Recording.Status status){ + public static RecordingUpdater updater( + final String pathConferenceSid, + final String pathSid, + final Recording.Status status + ) { return new RecordingUpdater(pathConferenceSid, pathSid, status); } - public static RecordingUpdater updater(final String pathAccountSid, final String pathConferenceSid, final String pathSid, final Recording.Status status){ - return new RecordingUpdater(pathAccountSid, pathConferenceSid, pathSid, status); + + public static RecordingUpdater updater( + final String pathAccountSid, + final String pathConferenceSid, + final String pathSid, + final Recording.Status status + ) { + return new RecordingUpdater( + pathAccountSid, + pathConferenceSid, + pathSid, + status + ); } /** - * Converts a JSON String into a Recording object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Recording object represented by the provided JSON - */ - public static Recording fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Recording object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Recording object represented by the provided JSON + */ + public static Recording fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Recording.class); @@ -94,14 +128,17 @@ public static Recording fromJson(final String json, final ObjectMapper objectMap } /** - * Converts a JSON InputStream into a Recording object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Recording object represented by the provided JSON - */ - public static Recording fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Recording object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Recording object represented by the provided JSON + */ + public static Recording fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Recording.class); @@ -111,6 +148,7 @@ public static Recording fromJson(final InputStream json, final ObjectMapper obje throw new ApiConnectionException(e.getMessage(), e); } } + public enum Source { DIALVERB("DialVerb"), CONFERENCE("Conference"), @@ -135,6 +173,7 @@ public static Source forValue(final String value) { return Promoter.enumFromString(value, Source.values()); } } + public enum Status { IN_PROGRESS("in-progress"), PAUSED("paused"), @@ -179,57 +218,27 @@ public static Status forValue(final String value) { @JsonCreator private Recording( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("api_version") - final String apiVersion, - - @JsonProperty("call_sid") - final String callSid, - - @JsonProperty("conference_sid") - final String conferenceSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("start_time") - final String startTime, - - @JsonProperty("duration") - final String duration, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("price") - final String price, - - @JsonProperty("price_unit") - @JsonDeserialize(using = com.twilio.converter.CurrencyDeserializer.class) - final Currency priceUnit, - - @JsonProperty("status") - final Recording.Status status, - - @JsonProperty("channels") - final Integer channels, - - @JsonProperty("source") - final Recording.Source source, - - @JsonProperty("error_code") - final Integer errorCode, - - @JsonProperty("encryption_details") - final Map encryptionDetails, - - @JsonProperty("uri") - final String uri + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("api_version") final String apiVersion, + @JsonProperty("call_sid") final String callSid, + @JsonProperty("conference_sid") final String conferenceSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("start_time") final String startTime, + @JsonProperty("duration") final String duration, + @JsonProperty("sid") final String sid, + @JsonProperty("price") final String price, + @JsonProperty("price_unit") @JsonDeserialize( + using = com.twilio.converter.CurrencyDeserializer.class + ) final Currency priceUnit, + @JsonProperty("status") final Recording.Status status, + @JsonProperty("channels") final Integer channels, + @JsonProperty("source") final Recording.Source source, + @JsonProperty("error_code") final Integer errorCode, + @JsonProperty( + "encryption_details" + ) final Map encryptionDetails, + @JsonProperty("uri") final String uri ) { this.accountSid = accountSid; this.apiVersion = apiVersion; @@ -250,61 +259,77 @@ private Recording( this.uri = uri; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getApiVersion() { - return this.apiVersion; - } - public final String getCallSid() { - return this.callSid; - } - public final String getConferenceSid() { - return this.conferenceSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final ZonedDateTime getStartTime() { - return this.startTime; - } - public final String getDuration() { - return this.duration; - } - public final String getSid() { - return this.sid; - } - public final String getPrice() { - return this.price; - } - public final Currency getPriceUnit() { - return this.priceUnit; - } - public final Recording.Status getStatus() { - return this.status; - } - public final Integer getChannels() { - return this.channels; - } - public final Recording.Source getSource() { - return this.source; - } - public final Integer getErrorCode() { - return this.errorCode; - } - public final Map getEncryptionDetails() { - return this.encryptionDetails; - } - public final String getUri() { - return this.uri; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getApiVersion() { + return this.apiVersion; + } + + public final String getCallSid() { + return this.callSid; + } + + public final String getConferenceSid() { + return this.conferenceSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final ZonedDateTime getStartTime() { + return this.startTime; + } + + public final String getDuration() { + return this.duration; + } + + public final String getSid() { + return this.sid; + } + + public final String getPrice() { + return this.price; + } + + public final Currency getPriceUnit() { + return this.priceUnit; + } + + public final Recording.Status getStatus() { + return this.status; + } + + public final Integer getChannels() { + return this.channels; + } + + public final Recording.Source getSource() { + return this.source; + } + + public final Integer getErrorCode() { + return this.errorCode; + } + + public final Map getEncryptionDetails() { + return this.encryptionDetails; + } + + public final String getUri() { + return this.uri; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -314,13 +339,47 @@ public boolean equals(final Object o) { Recording other = (Recording) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(apiVersion, other.apiVersion) && Objects.equals(callSid, other.callSid) && Objects.equals(conferenceSid, other.conferenceSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(startTime, other.startTime) && Objects.equals(duration, other.duration) && Objects.equals(sid, other.sid) && Objects.equals(price, other.price) && Objects.equals(priceUnit, other.priceUnit) && Objects.equals(status, other.status) && Objects.equals(channels, other.channels) && Objects.equals(source, other.source) && Objects.equals(errorCode, other.errorCode) && Objects.equals(encryptionDetails, other.encryptionDetails) && Objects.equals(uri, other.uri) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(apiVersion, other.apiVersion) && + Objects.equals(callSid, other.callSid) && + Objects.equals(conferenceSid, other.conferenceSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(startTime, other.startTime) && + Objects.equals(duration, other.duration) && + Objects.equals(sid, other.sid) && + Objects.equals(price, other.price) && + Objects.equals(priceUnit, other.priceUnit) && + Objects.equals(status, other.status) && + Objects.equals(channels, other.channels) && + Objects.equals(source, other.source) && + Objects.equals(errorCode, other.errorCode) && + Objects.equals(encryptionDetails, other.encryptionDetails) && + Objects.equals(uri, other.uri) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, apiVersion, callSid, conferenceSid, dateCreated, dateUpdated, startTime, duration, sid, price, priceUnit, status, channels, source, errorCode, encryptionDetails, uri); + return Objects.hash( + accountSid, + apiVersion, + callSid, + conferenceSid, + dateCreated, + dateUpdated, + startTime, + duration, + sid, + price, + priceUnit, + status, + channels, + source, + errorCode, + encryptionDetails, + uri + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/conference/RecordingDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/conference/RecordingDeleter.java index 35cb1b9752..0df3b62be4 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/conference/RecordingDeleter.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/conference/RecordingDeleter.java @@ -24,32 +24,50 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class RecordingDeleter extends Deleter { + private String pathConferenceSid; private String pathSid; private String pathAccountSid; - public RecordingDeleter(final String pathConferenceSid, final String pathSid){ + public RecordingDeleter( + final String pathConferenceSid, + final String pathSid + ) { this.pathConferenceSid = pathConferenceSid; this.pathSid = pathSid; } - public RecordingDeleter(final String pathAccountSid, final String pathConferenceSid, final String pathSid){ + + public RecordingDeleter( + final String pathAccountSid, + final String pathConferenceSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathConferenceSid = pathConferenceSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/Conferences/{ConferenceSid}/Recordings/{Sid}.json"; + String path = + "/2010-04-01/Accounts/{AccountSid}/Conferences/{ConferenceSid}/Recordings/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"ConferenceSid"+"}", this.pathConferenceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "ConferenceSid" + "}", + this.pathConferenceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -59,9 +77,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Recording delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Recording delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/conference/RecordingFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/conference/RecordingFetcher.java index 278defe6e6..bfa44572c3 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/conference/RecordingFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/conference/RecordingFetcher.java @@ -24,33 +24,50 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class RecordingFetcher extends Fetcher { + private String pathConferenceSid; private String pathSid; private String pathAccountSid; - public RecordingFetcher(final String pathConferenceSid, final String pathSid){ + public RecordingFetcher( + final String pathConferenceSid, + final String pathSid + ) { this.pathConferenceSid = pathConferenceSid; this.pathSid = pathSid; } - public RecordingFetcher(final String pathAccountSid, final String pathConferenceSid, final String pathSid){ + + public RecordingFetcher( + final String pathAccountSid, + final String pathConferenceSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathConferenceSid = pathConferenceSid; this.pathSid = pathSid; } - @Override public Recording fetch(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/Conferences/{ConferenceSid}/Recordings/{Sid}.json"; + String path = + "/2010-04-01/Accounts/{AccountSid}/Conferences/{ConferenceSid}/Recordings/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"ConferenceSid"+"}", this.pathConferenceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "ConferenceSid" + "}", + this.pathConferenceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -60,15 +77,23 @@ public Recording fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Recording fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Recording fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Recording.fromJson(response.getStream(), client.getObjectMapper()); + return Recording.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/conference/RecordingReader.java b/src/main/java/com/twilio/rest/api/v2010/account/conference/RecordingReader.java index 03eef2f02b..ad16c531a8 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/conference/RecordingReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/conference/RecordingReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.api.v2010.account.conference; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,13 +25,11 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; import java.time.LocalDate; import java.time.format.DateTimeFormatter; - - public class RecordingReader extends Reader { + private String pathConferenceSid; private String pathAccountSid; private LocalDate dateCreated; @@ -38,27 +37,38 @@ public class RecordingReader extends Reader { private LocalDate dateCreatedAfter; private Integer pageSize; - public RecordingReader(final String pathConferenceSid){ + public RecordingReader(final String pathConferenceSid) { this.pathConferenceSid = pathConferenceSid; } - public RecordingReader(final String pathAccountSid, final String pathConferenceSid){ + + public RecordingReader( + final String pathAccountSid, + final String pathConferenceSid + ) { this.pathAccountSid = pathAccountSid; this.pathConferenceSid = pathConferenceSid; } - public RecordingReader setDateCreated(final LocalDate dateCreated){ + public RecordingReader setDateCreated(final LocalDate dateCreated) { this.dateCreated = dateCreated; return this; } - public RecordingReader setDateCreatedBefore(final LocalDate dateCreatedBefore){ + + public RecordingReader setDateCreatedBefore( + final LocalDate dateCreatedBefore + ) { this.dateCreatedBefore = dateCreatedBefore; return this; } - public RecordingReader setDateCreatedAfter(final LocalDate dateCreatedAfter){ + + public RecordingReader setDateCreatedAfter( + final LocalDate dateCreatedAfter + ) { this.dateCreatedAfter = dateCreatedAfter; return this; } - public RecordingReader setPageSize(final Integer pageSize){ + + public RecordingReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -69,10 +79,22 @@ public ResourceSet read(final TwilioRestClient client) { } public Page firstPage(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/Conferences/{ConferenceSid}/Recordings.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"ConferenceSid"+"}", this.pathConferenceSid.toString()); + String path = + "/2010-04-01/Accounts/{AccountSid}/Conferences/{ConferenceSid}/Recordings.json"; + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "ConferenceSid" + "}", + this.pathConferenceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -84,13 +106,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Recording read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Recording read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -106,7 +136,10 @@ private Page pageForRequest(final TwilioRestClient client, final Requ } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.API.toString()) @@ -114,9 +147,11 @@ public Page previousPage(final Page page, final TwilioRest return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.API.toString()) @@ -125,27 +160,37 @@ public Page nextPage(final Page page, final TwilioRestClie } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (dateCreated != null) { - request.addQueryParam("DateCreated", dateCreated.format(DateTimeFormatter.ofPattern(Request.QUERY_STRING_DATE_TIME_FORMAT))); - } - else if (dateCreatedAfter != null || dateCreatedBefore != null) { - request.addQueryDateRange("DateCreated", dateCreatedAfter, dateCreatedBefore); + request.addQueryParam( + "DateCreated", + dateCreated.format( + DateTimeFormatter.ofPattern( + Request.QUERY_STRING_DATE_FORMAT + ) + ) + ); + } else if (dateCreatedAfter != null || dateCreatedBefore != null) { + request.addQueryDateRange( + "DateCreated", + dateCreatedAfter, + dateCreatedBefore + ); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/conference/RecordingUpdater.java b/src/main/java/com/twilio/rest/api/v2010/account/conference/RecordingUpdater.java index 9d39b447cf..af71583e29 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/conference/RecordingUpdater.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/conference/RecordingUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010.account.conference; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,74 +25,103 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class RecordingUpdater extends Updater { - - -public class RecordingUpdater extends Updater{ private String pathConferenceSid; private String pathSid; private Recording.Status status; private String pathAccountSid; private String pauseBehavior; - public RecordingUpdater(final String pathConferenceSid, final String pathSid, final Recording.Status status){ + public RecordingUpdater( + final String pathConferenceSid, + final String pathSid, + final Recording.Status status + ) { this.pathConferenceSid = pathConferenceSid; this.pathSid = pathSid; this.status = status; } - public RecordingUpdater(final String pathAccountSid, final String pathConferenceSid, final String pathSid, final Recording.Status status){ + + public RecordingUpdater( + final String pathAccountSid, + final String pathConferenceSid, + final String pathSid, + final Recording.Status status + ) { this.pathAccountSid = pathAccountSid; this.pathConferenceSid = pathConferenceSid; this.pathSid = pathSid; this.status = status; } - public RecordingUpdater setStatus(final Recording.Status status){ + public RecordingUpdater setStatus(final Recording.Status status) { this.status = status; return this; } - public RecordingUpdater setPauseBehavior(final String pauseBehavior){ + + public RecordingUpdater setPauseBehavior(final String pauseBehavior) { this.pauseBehavior = pauseBehavior; return this; } @Override - public Recording update(final TwilioRestClient client){ - String path = "/2010-04-01/Accounts/{AccountSid}/Conferences/{ConferenceSid}/Recordings/{Sid}.json"; + public Recording update(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Conferences/{ConferenceSid}/Recordings/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"ConferenceSid"+"}", this.pathConferenceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); - path = path.replace("{"+"Status"+"}", this.status.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "ConferenceSid" + "}", + this.pathConferenceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + path = path.replace("{" + "Status" + "}", this.status.toString()); Request request = new Request( HttpMethod.POST, Domains.API.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Recording update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Recording update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Recording.fromJson(response.getStream(), client.getObjectMapper()); + return Recording.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (status != null) { request.addPostParam("Status", status.toString()); - } if (pauseBehavior != null) { request.addPostParam("PauseBehavior", pauseBehavior); - } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/AssignedAddOn.java b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/AssignedAddOn.java index d4eabe52a2..56babaeb0b 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/AssignedAddOn.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/AssignedAddOn.java @@ -23,62 +23,101 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class AssignedAddOn extends Resource { + private static final long serialVersionUID = 114193682949091L; - public static AssignedAddOnCreator creator(final String pathResourceSid, final String installedAddOnSid){ + public static AssignedAddOnCreator creator( + final String pathResourceSid, + final String installedAddOnSid + ) { return new AssignedAddOnCreator(pathResourceSid, installedAddOnSid); } - public static AssignedAddOnCreator creator(final String pathAccountSid, final String pathResourceSid, final String installedAddOnSid){ - return new AssignedAddOnCreator(pathAccountSid, pathResourceSid, installedAddOnSid); + + public static AssignedAddOnCreator creator( + final String pathAccountSid, + final String pathResourceSid, + final String installedAddOnSid + ) { + return new AssignedAddOnCreator( + pathAccountSid, + pathResourceSid, + installedAddOnSid + ); } - public static AssignedAddOnDeleter deleter(final String pathResourceSid, final String pathSid){ + public static AssignedAddOnDeleter deleter( + final String pathResourceSid, + final String pathSid + ) { return new AssignedAddOnDeleter(pathResourceSid, pathSid); } - public static AssignedAddOnDeleter deleter(final String pathAccountSid, final String pathResourceSid, final String pathSid){ - return new AssignedAddOnDeleter(pathAccountSid, pathResourceSid, pathSid); + + public static AssignedAddOnDeleter deleter( + final String pathAccountSid, + final String pathResourceSid, + final String pathSid + ) { + return new AssignedAddOnDeleter( + pathAccountSid, + pathResourceSid, + pathSid + ); } - public static AssignedAddOnFetcher fetcher(final String pathResourceSid, final String pathSid){ + public static AssignedAddOnFetcher fetcher( + final String pathResourceSid, + final String pathSid + ) { return new AssignedAddOnFetcher(pathResourceSid, pathSid); } - public static AssignedAddOnFetcher fetcher(final String pathAccountSid, final String pathResourceSid, final String pathSid){ - return new AssignedAddOnFetcher(pathAccountSid, pathResourceSid, pathSid); + + public static AssignedAddOnFetcher fetcher( + final String pathAccountSid, + final String pathResourceSid, + final String pathSid + ) { + return new AssignedAddOnFetcher( + pathAccountSid, + pathResourceSid, + pathSid + ); } - public static AssignedAddOnReader reader(final String pathResourceSid){ + public static AssignedAddOnReader reader(final String pathResourceSid) { return new AssignedAddOnReader(pathResourceSid); } - public static AssignedAddOnReader reader(final String pathAccountSid, final String pathResourceSid){ + + public static AssignedAddOnReader reader( + final String pathAccountSid, + final String pathResourceSid + ) { return new AssignedAddOnReader(pathAccountSid, pathResourceSid); } /** - * Converts a JSON String into a AssignedAddOn object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return AssignedAddOn object represented by the provided JSON - */ - public static AssignedAddOn fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a AssignedAddOn object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return AssignedAddOn object represented by the provided JSON + */ + public static AssignedAddOn fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, AssignedAddOn.class); @@ -90,14 +129,17 @@ public static AssignedAddOn fromJson(final String json, final ObjectMapper objec } /** - * Converts a JSON InputStream into a AssignedAddOn object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return AssignedAddOn object represented by the provided JSON - */ - public static AssignedAddOn fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a AssignedAddOn object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return AssignedAddOn object represented by the provided JSON + */ + public static AssignedAddOn fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, AssignedAddOn.class); @@ -122,38 +164,19 @@ public static AssignedAddOn fromJson(final InputStream json, final ObjectMapper @JsonCreator private AssignedAddOn( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("resource_sid") - final String resourceSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("description") - final String description, - - @JsonProperty("configuration") - final Map configuration, - - @JsonProperty("unique_name") - final String uniqueName, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("uri") - final String uri, - - @JsonProperty("subresource_uris") - final Map subresourceUris + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("resource_sid") final String resourceSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("description") final String description, + @JsonProperty("configuration") final Map configuration, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("uri") final String uri, + @JsonProperty( + "subresource_uris" + ) final Map subresourceUris ) { this.sid = sid; this.accountSid = accountSid; @@ -168,43 +191,53 @@ private AssignedAddOn( this.subresourceUris = subresourceUris; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getResourceSid() { - return this.resourceSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getDescription() { - return this.description; - } - public final Map getConfiguration() { - return this.configuration; - } - public final String getUniqueName() { - return this.uniqueName; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getUri() { - return this.uri; - } - public final Map getSubresourceUris() { - return this.subresourceUris; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getResourceSid() { + return this.resourceSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getDescription() { + return this.description; + } + + public final Map getConfiguration() { + return this.configuration; + } + + public final String getUniqueName() { + return this.uniqueName; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getUri() { + return this.uri; + } + + public final Map getSubresourceUris() { + return this.subresourceUris; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -214,13 +247,35 @@ public boolean equals(final Object o) { AssignedAddOn other = (AssignedAddOn) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(resourceSid, other.resourceSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(description, other.description) && Objects.equals(configuration, other.configuration) && Objects.equals(uniqueName, other.uniqueName) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(uri, other.uri) && Objects.equals(subresourceUris, other.subresourceUris) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(resourceSid, other.resourceSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(description, other.description) && + Objects.equals(configuration, other.configuration) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(uri, other.uri) && + Objects.equals(subresourceUris, other.subresourceUris) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, resourceSid, friendlyName, description, configuration, uniqueName, dateCreated, dateUpdated, uri, subresourceUris); + return Objects.hash( + sid, + accountSid, + resourceSid, + friendlyName, + description, + configuration, + uniqueName, + dateCreated, + dateUpdated, + uri, + subresourceUris + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/AssignedAddOnCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/AssignedAddOnCreator.java index 773d03021f..fe7bce5fcc 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/AssignedAddOnCreator.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/AssignedAddOnCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010.account.incomingphonenumber; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,61 +25,94 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class AssignedAddOnCreator extends Creator { - - -public class AssignedAddOnCreator extends Creator{ private String pathResourceSid; private String installedAddOnSid; private String pathAccountSid; - public AssignedAddOnCreator(final String pathResourceSid, final String installedAddOnSid) { + public AssignedAddOnCreator( + final String pathResourceSid, + final String installedAddOnSid + ) { this.pathResourceSid = pathResourceSid; this.installedAddOnSid = installedAddOnSid; } - public AssignedAddOnCreator(final String pathAccountSid, final String pathResourceSid, final String installedAddOnSid) { + + public AssignedAddOnCreator( + final String pathAccountSid, + final String pathResourceSid, + final String installedAddOnSid + ) { this.pathAccountSid = pathAccountSid; this.pathResourceSid = pathResourceSid; this.installedAddOnSid = installedAddOnSid; } - public AssignedAddOnCreator setInstalledAddOnSid(final String installedAddOnSid){ + public AssignedAddOnCreator setInstalledAddOnSid( + final String installedAddOnSid + ) { this.installedAddOnSid = installedAddOnSid; return this; } @Override - public AssignedAddOn create(final TwilioRestClient client){ - String path = "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{ResourceSid}/AssignedAddOns.json"; + public AssignedAddOn create(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{ResourceSid}/AssignedAddOns.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"ResourceSid"+"}", this.pathResourceSid.toString()); - path = path.replace("{"+"InstalledAddOnSid"+"}", this.installedAddOnSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "ResourceSid" + "}", + this.pathResourceSid.toString() + ); + path = + path.replace( + "{" + "InstalledAddOnSid" + "}", + this.installedAddOnSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.API.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AssignedAddOn creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "AssignedAddOn creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return AssignedAddOn.fromJson(response.getStream(), client.getObjectMapper()); + return AssignedAddOn.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (installedAddOnSid != null) { request.addPostParam("InstalledAddOnSid", installedAddOnSid); - } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/AssignedAddOnDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/AssignedAddOnDeleter.java index 3ed82ce702..d47f51073c 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/AssignedAddOnDeleter.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/AssignedAddOnDeleter.java @@ -24,32 +24,50 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class AssignedAddOnDeleter extends Deleter { + private String pathResourceSid; private String pathSid; private String pathAccountSid; - public AssignedAddOnDeleter(final String pathResourceSid, final String pathSid){ + public AssignedAddOnDeleter( + final String pathResourceSid, + final String pathSid + ) { this.pathResourceSid = pathResourceSid; this.pathSid = pathSid; } - public AssignedAddOnDeleter(final String pathAccountSid, final String pathResourceSid, final String pathSid){ + + public AssignedAddOnDeleter( + final String pathAccountSid, + final String pathResourceSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathResourceSid = pathResourceSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{ResourceSid}/AssignedAddOns/{Sid}.json"; + String path = + "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{ResourceSid}/AssignedAddOns/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"ResourceSid"+"}", this.pathResourceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "ResourceSid" + "}", + this.pathResourceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -59,9 +77,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AssignedAddOn delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "AssignedAddOn delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/AssignedAddOnFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/AssignedAddOnFetcher.java index e479a4e2f7..77baa4d5ec 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/AssignedAddOnFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/AssignedAddOnFetcher.java @@ -24,33 +24,50 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class AssignedAddOnFetcher extends Fetcher { + private String pathResourceSid; private String pathSid; private String pathAccountSid; - public AssignedAddOnFetcher(final String pathResourceSid, final String pathSid){ + public AssignedAddOnFetcher( + final String pathResourceSid, + final String pathSid + ) { this.pathResourceSid = pathResourceSid; this.pathSid = pathSid; } - public AssignedAddOnFetcher(final String pathAccountSid, final String pathResourceSid, final String pathSid){ + + public AssignedAddOnFetcher( + final String pathAccountSid, + final String pathResourceSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathResourceSid = pathResourceSid; this.pathSid = pathSid; } - @Override public AssignedAddOn fetch(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{ResourceSid}/AssignedAddOns/{Sid}.json"; + String path = + "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{ResourceSid}/AssignedAddOns/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"ResourceSid"+"}", this.pathResourceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "ResourceSid" + "}", + this.pathResourceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -60,15 +77,23 @@ public AssignedAddOn fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AssignedAddOn fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "AssignedAddOn fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return AssignedAddOn.fromJson(response.getStream(), client.getObjectMapper()); + return AssignedAddOn.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/AssignedAddOnReader.java b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/AssignedAddOnReader.java index 37e10e2c4f..cf3c395b3e 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/AssignedAddOnReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/AssignedAddOnReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.api.v2010.account.incomingphonenumber; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,24 +25,26 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class AssignedAddOnReader extends Reader { + private String pathResourceSid; private String pathAccountSid; private Integer pageSize; - public AssignedAddOnReader(final String pathResourceSid){ + public AssignedAddOnReader(final String pathResourceSid) { this.pathResourceSid = pathResourceSid; } - public AssignedAddOnReader(final String pathAccountSid, final String pathResourceSid){ + + public AssignedAddOnReader( + final String pathAccountSid, + final String pathResourceSid + ) { this.pathAccountSid = pathAccountSid; this.pathResourceSid = pathResourceSid; } - public AssignedAddOnReader setPageSize(final Integer pageSize){ + public AssignedAddOnReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -52,10 +55,22 @@ public ResourceSet read(final TwilioRestClient client) { } public Page firstPage(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{ResourceSid}/AssignedAddOns.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"ResourceSid"+"}", this.pathResourceSid.toString()); + String path = + "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{ResourceSid}/AssignedAddOns.json"; + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "ResourceSid" + "}", + this.pathResourceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -67,13 +82,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AssignedAddOn read failed: Unable to connect to server"); + throw new ApiConnectionException( + "AssignedAddOn read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -89,7 +112,10 @@ private Page pageForRequest(final TwilioRestClient client, final } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.API.toString()) @@ -97,9 +123,11 @@ public Page previousPage(final Page page, final Tw return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.API.toString()) @@ -108,21 +136,21 @@ public Page nextPage(final Page page, final Twilio } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/Local.java b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/Local.java index 454181ebe3..ba07f206a0 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/Local.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/Local.java @@ -24,49 +24,55 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; import com.twilio.http.HttpMethod; - -import lombok.ToString; - +import com.twilio.type.PhoneNumberCapabilities; import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - -import com.twilio.type.PhoneNumberCapabilities; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Local extends Resource { + private static final long serialVersionUID = 226189121371341L; - public static LocalCreator creator(final com.twilio.type.PhoneNumber phoneNumber){ + public static LocalCreator creator( + final com.twilio.type.PhoneNumber phoneNumber + ) { return new LocalCreator(phoneNumber); } - public static LocalCreator creator(final String pathAccountSid, final com.twilio.type.PhoneNumber phoneNumber){ + + public static LocalCreator creator( + final String pathAccountSid, + final com.twilio.type.PhoneNumber phoneNumber + ) { return new LocalCreator(pathAccountSid, phoneNumber); } - public static LocalReader reader(){ + public static LocalReader reader() { return new LocalReader(); } - public static LocalReader reader(final String pathAccountSid){ + + public static LocalReader reader(final String pathAccountSid) { return new LocalReader(pathAccountSid); } /** - * Converts a JSON String into a Local object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Local object represented by the provided JSON - */ - public static Local fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Local object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Local object represented by the provided JSON + */ + public static Local fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Local.class); @@ -78,14 +84,17 @@ public static Local fromJson(final String json, final ObjectMapper objectMapper) } /** - * Converts a JSON InputStream into a Local object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Local object represented by the provided JSON - */ - public static Local fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Local object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Local object represented by the provided JSON + */ + public static Local fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Local.class); @@ -95,6 +104,7 @@ public static Local fromJson(final InputStream json, final ObjectMapper objectMa throw new ApiConnectionException(e.getMessage(), e); } } + public enum AddressRequirement { NONE("none"), ANY("any"), @@ -116,6 +126,7 @@ public static AddressRequirement forValue(final String value) { return Promoter.enumFromString(value, AddressRequirement.values()); } } + public enum EmergencyAddressStatus { REGISTERED("registered"), UNREGISTERED("unregistered"), @@ -136,9 +147,13 @@ public String toString() { @JsonCreator public static EmergencyAddressStatus forValue(final String value) { - return Promoter.enumFromString(value, EmergencyAddressStatus.values()); + return Promoter.enumFromString( + value, + EmergencyAddressStatus.values() + ); } } + public enum EmergencyStatus { ACTIVE("Active"), INACTIVE("Inactive"); @@ -158,6 +173,7 @@ public static EmergencyStatus forValue(final String value) { return Promoter.enumFromString(value, EmergencyStatus.values()); } } + public enum VoiceReceiveMode { VOICE("voice"), FAX("fax"); @@ -215,107 +231,58 @@ public static VoiceReceiveMode forValue(final String value) { @JsonCreator private Local( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("address_sid") - final String addressSid, - - @JsonProperty("address_requirements") - final Local.AddressRequirement addressRequirements, - - @JsonProperty("api_version") - final String apiVersion, - - @JsonProperty("beta") - final Boolean beta, - - @JsonProperty("capabilities") - final PhoneNumberCapabilities capabilities, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("identity_sid") - final String identitySid, - - @JsonProperty("phone_number") - final com.twilio.type.PhoneNumber phoneNumber, - - @JsonProperty("origin") - final String origin, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("sms_application_sid") - final String smsApplicationSid, - - @JsonProperty("sms_fallback_method") - final HttpMethod smsFallbackMethod, - - @JsonProperty("sms_fallback_url") - final URI smsFallbackUrl, - - @JsonProperty("sms_method") - final HttpMethod smsMethod, - - @JsonProperty("sms_url") - final URI smsUrl, - - @JsonProperty("status_callback") - final URI statusCallback, - - @JsonProperty("status_callback_method") - final HttpMethod statusCallbackMethod, - - @JsonProperty("trunk_sid") - final String trunkSid, - - @JsonProperty("uri") - final String uri, - - @JsonProperty("voice_receive_mode") - final Local.VoiceReceiveMode voiceReceiveMode, - - @JsonProperty("voice_application_sid") - final String voiceApplicationSid, - - @JsonProperty("voice_caller_id_lookup") - final Boolean voiceCallerIdLookup, - - @JsonProperty("voice_fallback_method") - final HttpMethod voiceFallbackMethod, - - @JsonProperty("voice_fallback_url") - final URI voiceFallbackUrl, - - @JsonProperty("voice_method") - final HttpMethod voiceMethod, - - @JsonProperty("voice_url") - final URI voiceUrl, - - @JsonProperty("emergency_status") - final Local.EmergencyStatus emergencyStatus, - - @JsonProperty("emergency_address_sid") - final String emergencyAddressSid, - - @JsonProperty("emergency_address_status") - final Local.EmergencyAddressStatus emergencyAddressStatus, - - @JsonProperty("bundle_sid") - final String bundleSid, - - @JsonProperty("status") - final String status + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("address_sid") final String addressSid, + @JsonProperty( + "address_requirements" + ) final Local.AddressRequirement addressRequirements, + @JsonProperty("api_version") final String apiVersion, + @JsonProperty("beta") final Boolean beta, + @JsonProperty( + "capabilities" + ) final PhoneNumberCapabilities capabilities, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("identity_sid") final String identitySid, + @JsonProperty( + "phone_number" + ) final com.twilio.type.PhoneNumber phoneNumber, + @JsonProperty("origin") final String origin, + @JsonProperty("sid") final String sid, + @JsonProperty("sms_application_sid") final String smsApplicationSid, + @JsonProperty("sms_fallback_method") final HttpMethod smsFallbackMethod, + @JsonProperty("sms_fallback_url") final URI smsFallbackUrl, + @JsonProperty("sms_method") final HttpMethod smsMethod, + @JsonProperty("sms_url") final URI smsUrl, + @JsonProperty("status_callback") final URI statusCallback, + @JsonProperty( + "status_callback_method" + ) final HttpMethod statusCallbackMethod, + @JsonProperty("trunk_sid") final String trunkSid, + @JsonProperty("uri") final String uri, + @JsonProperty( + "voice_receive_mode" + ) final Local.VoiceReceiveMode voiceReceiveMode, + @JsonProperty("voice_application_sid") final String voiceApplicationSid, + @JsonProperty( + "voice_caller_id_lookup" + ) final Boolean voiceCallerIdLookup, + @JsonProperty( + "voice_fallback_method" + ) final HttpMethod voiceFallbackMethod, + @JsonProperty("voice_fallback_url") final URI voiceFallbackUrl, + @JsonProperty("voice_method") final HttpMethod voiceMethod, + @JsonProperty("voice_url") final URI voiceUrl, + @JsonProperty( + "emergency_status" + ) final Local.EmergencyStatus emergencyStatus, + @JsonProperty("emergency_address_sid") final String emergencyAddressSid, + @JsonProperty( + "emergency_address_status" + ) final Local.EmergencyAddressStatus emergencyAddressStatus, + @JsonProperty("bundle_sid") final String bundleSid, + @JsonProperty("status") final String status ) { this.accountSid = accountSid; this.addressSid = addressSid; @@ -353,112 +320,145 @@ private Local( this.status = status; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getAddressSid() { - return this.addressSid; - } - public final Local.AddressRequirement getAddressRequirements() { - return this.addressRequirements; - } - public final String getApiVersion() { - return this.apiVersion; - } - public final Boolean getBeta() { - return this.beta; - } - public final PhoneNumberCapabilities getCapabilities() { - return this.capabilities; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getIdentitySid() { - return this.identitySid; - } - public final com.twilio.type.PhoneNumber getPhoneNumber() { - return this.phoneNumber; - } - public final String getOrigin() { - return this.origin; - } - public final String getSid() { - return this.sid; - } - public final String getSmsApplicationSid() { - return this.smsApplicationSid; - } - public final HttpMethod getSmsFallbackMethod() { - return this.smsFallbackMethod; - } - public final URI getSmsFallbackUrl() { - return this.smsFallbackUrl; - } - public final HttpMethod getSmsMethod() { - return this.smsMethod; - } - public final URI getSmsUrl() { - return this.smsUrl; - } - public final URI getStatusCallback() { - return this.statusCallback; - } - public final HttpMethod getStatusCallbackMethod() { - return this.statusCallbackMethod; - } - public final String getTrunkSid() { - return this.trunkSid; - } - public final String getUri() { - return this.uri; - } - public final Local.VoiceReceiveMode getVoiceReceiveMode() { - return this.voiceReceiveMode; - } - public final String getVoiceApplicationSid() { - return this.voiceApplicationSid; - } - public final Boolean getVoiceCallerIdLookup() { - return this.voiceCallerIdLookup; - } - public final HttpMethod getVoiceFallbackMethod() { - return this.voiceFallbackMethod; - } - public final URI getVoiceFallbackUrl() { - return this.voiceFallbackUrl; - } - public final HttpMethod getVoiceMethod() { - return this.voiceMethod; - } - public final URI getVoiceUrl() { - return this.voiceUrl; - } - public final Local.EmergencyStatus getEmergencyStatus() { - return this.emergencyStatus; - } - public final String getEmergencyAddressSid() { - return this.emergencyAddressSid; - } - public final Local.EmergencyAddressStatus getEmergencyAddressStatus() { - return this.emergencyAddressStatus; - } - public final String getBundleSid() { - return this.bundleSid; - } - public final String getStatus() { - return this.status; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getAddressSid() { + return this.addressSid; + } + + public final Local.AddressRequirement getAddressRequirements() { + return this.addressRequirements; + } + + public final String getApiVersion() { + return this.apiVersion; + } + + public final Boolean getBeta() { + return this.beta; + } + + public final PhoneNumberCapabilities getCapabilities() { + return this.capabilities; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getIdentitySid() { + return this.identitySid; + } + + public final com.twilio.type.PhoneNumber getPhoneNumber() { + return this.phoneNumber; + } + + public final String getOrigin() { + return this.origin; + } + + public final String getSid() { + return this.sid; + } + + public final String getSmsApplicationSid() { + return this.smsApplicationSid; + } + + public final HttpMethod getSmsFallbackMethod() { + return this.smsFallbackMethod; + } + + public final URI getSmsFallbackUrl() { + return this.smsFallbackUrl; + } + + public final HttpMethod getSmsMethod() { + return this.smsMethod; + } + + public final URI getSmsUrl() { + return this.smsUrl; + } + + public final URI getStatusCallback() { + return this.statusCallback; + } + + public final HttpMethod getStatusCallbackMethod() { + return this.statusCallbackMethod; + } + + public final String getTrunkSid() { + return this.trunkSid; + } + + public final String getUri() { + return this.uri; + } + + public final Local.VoiceReceiveMode getVoiceReceiveMode() { + return this.voiceReceiveMode; + } + + public final String getVoiceApplicationSid() { + return this.voiceApplicationSid; + } + + public final Boolean getVoiceCallerIdLookup() { + return this.voiceCallerIdLookup; + } + + public final HttpMethod getVoiceFallbackMethod() { + return this.voiceFallbackMethod; + } + + public final URI getVoiceFallbackUrl() { + return this.voiceFallbackUrl; + } + + public final HttpMethod getVoiceMethod() { + return this.voiceMethod; + } + + public final URI getVoiceUrl() { + return this.voiceUrl; + } + + public final Local.EmergencyStatus getEmergencyStatus() { + return this.emergencyStatus; + } + + public final String getEmergencyAddressSid() { + return this.emergencyAddressSid; + } + + public final Local.EmergencyAddressStatus getEmergencyAddressStatus() { + return this.emergencyAddressStatus; + } + + public final String getBundleSid() { + return this.bundleSid; + } + + public final String getStatus() { + return this.status; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -468,13 +468,84 @@ public boolean equals(final Object o) { Local other = (Local) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(addressSid, other.addressSid) && Objects.equals(addressRequirements, other.addressRequirements) && Objects.equals(apiVersion, other.apiVersion) && Objects.equals(beta, other.beta) && Objects.equals(capabilities, other.capabilities) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(identitySid, other.identitySid) && Objects.equals(phoneNumber, other.phoneNumber) && Objects.equals(origin, other.origin) && Objects.equals(sid, other.sid) && Objects.equals(smsApplicationSid, other.smsApplicationSid) && Objects.equals(smsFallbackMethod, other.smsFallbackMethod) && Objects.equals(smsFallbackUrl, other.smsFallbackUrl) && Objects.equals(smsMethod, other.smsMethod) && Objects.equals(smsUrl, other.smsUrl) && Objects.equals(statusCallback, other.statusCallback) && Objects.equals(statusCallbackMethod, other.statusCallbackMethod) && Objects.equals(trunkSid, other.trunkSid) && Objects.equals(uri, other.uri) && Objects.equals(voiceReceiveMode, other.voiceReceiveMode) && Objects.equals(voiceApplicationSid, other.voiceApplicationSid) && Objects.equals(voiceCallerIdLookup, other.voiceCallerIdLookup) && Objects.equals(voiceFallbackMethod, other.voiceFallbackMethod) && Objects.equals(voiceFallbackUrl, other.voiceFallbackUrl) && Objects.equals(voiceMethod, other.voiceMethod) && Objects.equals(voiceUrl, other.voiceUrl) && Objects.equals(emergencyStatus, other.emergencyStatus) && Objects.equals(emergencyAddressSid, other.emergencyAddressSid) && Objects.equals(emergencyAddressStatus, other.emergencyAddressStatus) && Objects.equals(bundleSid, other.bundleSid) && Objects.equals(status, other.status) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(addressSid, other.addressSid) && + Objects.equals(addressRequirements, other.addressRequirements) && + Objects.equals(apiVersion, other.apiVersion) && + Objects.equals(beta, other.beta) && + Objects.equals(capabilities, other.capabilities) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(identitySid, other.identitySid) && + Objects.equals(phoneNumber, other.phoneNumber) && + Objects.equals(origin, other.origin) && + Objects.equals(sid, other.sid) && + Objects.equals(smsApplicationSid, other.smsApplicationSid) && + Objects.equals(smsFallbackMethod, other.smsFallbackMethod) && + Objects.equals(smsFallbackUrl, other.smsFallbackUrl) && + Objects.equals(smsMethod, other.smsMethod) && + Objects.equals(smsUrl, other.smsUrl) && + Objects.equals(statusCallback, other.statusCallback) && + Objects.equals(statusCallbackMethod, other.statusCallbackMethod) && + Objects.equals(trunkSid, other.trunkSid) && + Objects.equals(uri, other.uri) && + Objects.equals(voiceReceiveMode, other.voiceReceiveMode) && + Objects.equals(voiceApplicationSid, other.voiceApplicationSid) && + Objects.equals(voiceCallerIdLookup, other.voiceCallerIdLookup) && + Objects.equals(voiceFallbackMethod, other.voiceFallbackMethod) && + Objects.equals(voiceFallbackUrl, other.voiceFallbackUrl) && + Objects.equals(voiceMethod, other.voiceMethod) && + Objects.equals(voiceUrl, other.voiceUrl) && + Objects.equals(emergencyStatus, other.emergencyStatus) && + Objects.equals(emergencyAddressSid, other.emergencyAddressSid) && + Objects.equals( + emergencyAddressStatus, + other.emergencyAddressStatus + ) && + Objects.equals(bundleSid, other.bundleSid) && + Objects.equals(status, other.status) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, addressSid, addressRequirements, apiVersion, beta, capabilities, dateCreated, dateUpdated, friendlyName, identitySid, phoneNumber, origin, sid, smsApplicationSid, smsFallbackMethod, smsFallbackUrl, smsMethod, smsUrl, statusCallback, statusCallbackMethod, trunkSid, uri, voiceReceiveMode, voiceApplicationSid, voiceCallerIdLookup, voiceFallbackMethod, voiceFallbackUrl, voiceMethod, voiceUrl, emergencyStatus, emergencyAddressSid, emergencyAddressStatus, bundleSid, status); + return Objects.hash( + accountSid, + addressSid, + addressRequirements, + apiVersion, + beta, + capabilities, + dateCreated, + dateUpdated, + friendlyName, + identitySid, + phoneNumber, + origin, + sid, + smsApplicationSid, + smsFallbackMethod, + smsFallbackUrl, + smsMethod, + smsUrl, + statusCallback, + statusCallbackMethod, + trunkSid, + uri, + voiceReceiveMode, + voiceApplicationSid, + voiceCallerIdLookup, + voiceFallbackMethod, + voiceFallbackUrl, + voiceMethod, + voiceUrl, + emergencyStatus, + emergencyAddressSid, + emergencyAddressStatus, + bundleSid, + status + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/LocalCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/LocalCreator.java index 2516534e42..7ce4865a7f 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/LocalCreator.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/LocalCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010.account.incomingphonenumber; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -25,12 +26,10 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.net.URI; - - - import java.net.URI; -public class LocalCreator extends Creator{ +public class LocalCreator extends Creator { + private com.twilio.type.PhoneNumber phoneNumber; private String pathAccountSid; private String apiVersion; @@ -59,147 +58,209 @@ public class LocalCreator extends Creator{ public LocalCreator(final com.twilio.type.PhoneNumber phoneNumber) { this.phoneNumber = phoneNumber; } - public LocalCreator(final String pathAccountSid, final com.twilio.type.PhoneNumber phoneNumber) { + + public LocalCreator( + final String pathAccountSid, + final com.twilio.type.PhoneNumber phoneNumber + ) { this.pathAccountSid = pathAccountSid; this.phoneNumber = phoneNumber; } - public LocalCreator setPhoneNumber(final com.twilio.type.PhoneNumber phoneNumber){ + public LocalCreator setPhoneNumber( + final com.twilio.type.PhoneNumber phoneNumber + ) { this.phoneNumber = phoneNumber; return this; } - public LocalCreator setPhoneNumber(final String phoneNumber){ + public LocalCreator setPhoneNumber(final String phoneNumber) { return setPhoneNumber(Promoter.phoneNumberFromString(phoneNumber)); } - public LocalCreator setApiVersion(final String apiVersion){ + + public LocalCreator setApiVersion(final String apiVersion) { this.apiVersion = apiVersion; return this; } - public LocalCreator setFriendlyName(final String friendlyName){ + + public LocalCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public LocalCreator setSmsApplicationSid(final String smsApplicationSid){ + + public LocalCreator setSmsApplicationSid(final String smsApplicationSid) { this.smsApplicationSid = smsApplicationSid; return this; } - public LocalCreator setSmsFallbackMethod(final HttpMethod smsFallbackMethod){ + + public LocalCreator setSmsFallbackMethod( + final HttpMethod smsFallbackMethod + ) { this.smsFallbackMethod = smsFallbackMethod; return this; } - public LocalCreator setSmsFallbackUrl(final URI smsFallbackUrl){ + + public LocalCreator setSmsFallbackUrl(final URI smsFallbackUrl) { this.smsFallbackUrl = smsFallbackUrl; return this; } - public LocalCreator setSmsFallbackUrl(final String smsFallbackUrl){ + public LocalCreator setSmsFallbackUrl(final String smsFallbackUrl) { return setSmsFallbackUrl(Promoter.uriFromString(smsFallbackUrl)); } - public LocalCreator setSmsMethod(final HttpMethod smsMethod){ + + public LocalCreator setSmsMethod(final HttpMethod smsMethod) { this.smsMethod = smsMethod; return this; } - public LocalCreator setSmsUrl(final URI smsUrl){ + + public LocalCreator setSmsUrl(final URI smsUrl) { this.smsUrl = smsUrl; return this; } - public LocalCreator setSmsUrl(final String smsUrl){ + public LocalCreator setSmsUrl(final String smsUrl) { return setSmsUrl(Promoter.uriFromString(smsUrl)); } - public LocalCreator setStatusCallback(final URI statusCallback){ + + public LocalCreator setStatusCallback(final URI statusCallback) { this.statusCallback = statusCallback; return this; } - public LocalCreator setStatusCallback(final String statusCallback){ + public LocalCreator setStatusCallback(final String statusCallback) { return setStatusCallback(Promoter.uriFromString(statusCallback)); } - public LocalCreator setStatusCallbackMethod(final HttpMethod statusCallbackMethod){ + + public LocalCreator setStatusCallbackMethod( + final HttpMethod statusCallbackMethod + ) { this.statusCallbackMethod = statusCallbackMethod; return this; } - public LocalCreator setVoiceApplicationSid(final String voiceApplicationSid){ + + public LocalCreator setVoiceApplicationSid( + final String voiceApplicationSid + ) { this.voiceApplicationSid = voiceApplicationSid; return this; } - public LocalCreator setVoiceCallerIdLookup(final Boolean voiceCallerIdLookup){ + + public LocalCreator setVoiceCallerIdLookup( + final Boolean voiceCallerIdLookup + ) { this.voiceCallerIdLookup = voiceCallerIdLookup; return this; } - public LocalCreator setVoiceFallbackMethod(final HttpMethod voiceFallbackMethod){ + + public LocalCreator setVoiceFallbackMethod( + final HttpMethod voiceFallbackMethod + ) { this.voiceFallbackMethod = voiceFallbackMethod; return this; } - public LocalCreator setVoiceFallbackUrl(final URI voiceFallbackUrl){ + + public LocalCreator setVoiceFallbackUrl(final URI voiceFallbackUrl) { this.voiceFallbackUrl = voiceFallbackUrl; return this; } - public LocalCreator setVoiceFallbackUrl(final String voiceFallbackUrl){ + public LocalCreator setVoiceFallbackUrl(final String voiceFallbackUrl) { return setVoiceFallbackUrl(Promoter.uriFromString(voiceFallbackUrl)); } - public LocalCreator setVoiceMethod(final HttpMethod voiceMethod){ + + public LocalCreator setVoiceMethod(final HttpMethod voiceMethod) { this.voiceMethod = voiceMethod; return this; } - public LocalCreator setVoiceUrl(final URI voiceUrl){ + + public LocalCreator setVoiceUrl(final URI voiceUrl) { this.voiceUrl = voiceUrl; return this; } - public LocalCreator setVoiceUrl(final String voiceUrl){ + public LocalCreator setVoiceUrl(final String voiceUrl) { return setVoiceUrl(Promoter.uriFromString(voiceUrl)); } - public LocalCreator setIdentitySid(final String identitySid){ + + public LocalCreator setIdentitySid(final String identitySid) { this.identitySid = identitySid; return this; } - public LocalCreator setAddressSid(final String addressSid){ + + public LocalCreator setAddressSid(final String addressSid) { this.addressSid = addressSid; return this; } - public LocalCreator setEmergencyStatus(final Local.EmergencyStatus emergencyStatus){ + + public LocalCreator setEmergencyStatus( + final Local.EmergencyStatus emergencyStatus + ) { this.emergencyStatus = emergencyStatus; return this; } - public LocalCreator setEmergencyAddressSid(final String emergencyAddressSid){ + + public LocalCreator setEmergencyAddressSid( + final String emergencyAddressSid + ) { this.emergencyAddressSid = emergencyAddressSid; return this; } - public LocalCreator setTrunkSid(final String trunkSid){ + + public LocalCreator setTrunkSid(final String trunkSid) { this.trunkSid = trunkSid; return this; } - public LocalCreator setVoiceReceiveMode(final Local.VoiceReceiveMode voiceReceiveMode){ + + public LocalCreator setVoiceReceiveMode( + final Local.VoiceReceiveMode voiceReceiveMode + ) { this.voiceReceiveMode = voiceReceiveMode; return this; } - public LocalCreator setBundleSid(final String bundleSid){ + + public LocalCreator setBundleSid(final String bundleSid) { this.bundleSid = bundleSid; return this; } @Override - public Local create(final TwilioRestClient client){ - String path = "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/Local.json"; + public Local create(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/Local.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"PhoneNumber"+"}", this.phoneNumber.encode("utf-8")); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "PhoneNumber" + "}", + this.phoneNumber.encode("utf-8") + ); Request request = new Request( HttpMethod.POST, Domains.API.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Local creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Local creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -208,98 +269,94 @@ public Local create(final TwilioRestClient client){ return Local.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (phoneNumber != null) { request.addPostParam("PhoneNumber", phoneNumber.toString()); - } if (apiVersion != null) { request.addPostParam("ApiVersion", apiVersion); - } if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (smsApplicationSid != null) { request.addPostParam("SmsApplicationSid", smsApplicationSid); - } if (smsFallbackMethod != null) { - request.addPostParam("SmsFallbackMethod", smsFallbackMethod.toString()); - + request.addPostParam( + "SmsFallbackMethod", + smsFallbackMethod.toString() + ); } if (smsFallbackUrl != null) { request.addPostParam("SmsFallbackUrl", smsFallbackUrl.toString()); - } if (smsMethod != null) { request.addPostParam("SmsMethod", smsMethod.toString()); - } if (smsUrl != null) { request.addPostParam("SmsUrl", smsUrl.toString()); - } if (statusCallback != null) { request.addPostParam("StatusCallback", statusCallback.toString()); - } if (statusCallbackMethod != null) { - request.addPostParam("StatusCallbackMethod", statusCallbackMethod.toString()); - + request.addPostParam( + "StatusCallbackMethod", + statusCallbackMethod.toString() + ); } if (voiceApplicationSid != null) { request.addPostParam("VoiceApplicationSid", voiceApplicationSid); - } if (voiceCallerIdLookup != null) { - request.addPostParam("VoiceCallerIdLookup", voiceCallerIdLookup.toString()); - + request.addPostParam( + "VoiceCallerIdLookup", + voiceCallerIdLookup.toString() + ); } if (voiceFallbackMethod != null) { - request.addPostParam("VoiceFallbackMethod", voiceFallbackMethod.toString()); - + request.addPostParam( + "VoiceFallbackMethod", + voiceFallbackMethod.toString() + ); } if (voiceFallbackUrl != null) { - request.addPostParam("VoiceFallbackUrl", voiceFallbackUrl.toString()); - + request.addPostParam( + "VoiceFallbackUrl", + voiceFallbackUrl.toString() + ); } if (voiceMethod != null) { request.addPostParam("VoiceMethod", voiceMethod.toString()); - } if (voiceUrl != null) { request.addPostParam("VoiceUrl", voiceUrl.toString()); - } if (identitySid != null) { request.addPostParam("IdentitySid", identitySid); - } if (addressSid != null) { request.addPostParam("AddressSid", addressSid); - } if (emergencyStatus != null) { request.addPostParam("EmergencyStatus", emergencyStatus.toString()); - } if (emergencyAddressSid != null) { request.addPostParam("EmergencyAddressSid", emergencyAddressSid); - } if (trunkSid != null) { request.addPostParam("TrunkSid", trunkSid); - } if (voiceReceiveMode != null) { - request.addPostParam("VoiceReceiveMode", voiceReceiveMode.toString()); - + request.addPostParam( + "VoiceReceiveMode", + voiceReceiveMode.toString() + ); } if (bundleSid != null) { request.addPostParam("BundleSid", bundleSid); - } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/LocalReader.java b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/LocalReader.java index a5007bc727..f43ba8bd7c 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/LocalReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/LocalReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.api.v2010.account.incomingphonenumber; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.converter.Promoter; @@ -25,11 +26,9 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class LocalReader extends Reader { + private String pathAccountSid; private Boolean beta; private String friendlyName; @@ -37,33 +36,39 @@ public class LocalReader extends Reader { private String origin; private Integer pageSize; - public LocalReader(){ - } - public LocalReader(final String pathAccountSid){ + public LocalReader() {} + + public LocalReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - public LocalReader setBeta(final Boolean beta){ + public LocalReader setBeta(final Boolean beta) { this.beta = beta; return this; } - public LocalReader setFriendlyName(final String friendlyName){ + + public LocalReader setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public LocalReader setPhoneNumber(final com.twilio.type.PhoneNumber phoneNumber){ + + public LocalReader setPhoneNumber( + final com.twilio.type.PhoneNumber phoneNumber + ) { this.phoneNumber = phoneNumber; return this; } - public LocalReader setPhoneNumber(final String phoneNumber){ + public LocalReader setPhoneNumber(final String phoneNumber) { return setPhoneNumber(Promoter.phoneNumberFromString(phoneNumber)); } - public LocalReader setOrigin(final String origin){ + + public LocalReader setOrigin(final String origin) { this.origin = origin; return this; } - public LocalReader setPageSize(final Integer pageSize){ + + public LocalReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -74,9 +79,17 @@ public ResourceSet read(final TwilioRestClient client) { } public Page firstPage(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/Local.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); + String path = + "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/Local.json"; + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -88,13 +101,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Local read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Local read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -110,7 +131,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.API.toString()) @@ -118,9 +142,11 @@ public Page previousPage(final Page page, final TwilioRestClient c return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.API.toString()) @@ -129,37 +155,33 @@ public Page nextPage(final Page page, final TwilioRestClient clien } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (beta != null) { - request.addQueryParam("Beta", beta.toString()); } if (friendlyName != null) { - request.addQueryParam("FriendlyName", friendlyName); } if (phoneNumber != null) { - request.addQueryParam("PhoneNumber", phoneNumber.toString()); } if (origin != null) { - request.addQueryParam("Origin", origin); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/Mobile.java b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/Mobile.java index da3e62e507..0ab166a550 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/Mobile.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/Mobile.java @@ -24,49 +24,55 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; import com.twilio.http.HttpMethod; - -import lombok.ToString; - +import com.twilio.type.PhoneNumberCapabilities; import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - -import com.twilio.type.PhoneNumberCapabilities; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Mobile extends Resource { + private static final long serialVersionUID = 79850849216916L; - public static MobileCreator creator(final com.twilio.type.PhoneNumber phoneNumber){ + public static MobileCreator creator( + final com.twilio.type.PhoneNumber phoneNumber + ) { return new MobileCreator(phoneNumber); } - public static MobileCreator creator(final String pathAccountSid, final com.twilio.type.PhoneNumber phoneNumber){ + + public static MobileCreator creator( + final String pathAccountSid, + final com.twilio.type.PhoneNumber phoneNumber + ) { return new MobileCreator(pathAccountSid, phoneNumber); } - public static MobileReader reader(){ + public static MobileReader reader() { return new MobileReader(); } - public static MobileReader reader(final String pathAccountSid){ + + public static MobileReader reader(final String pathAccountSid) { return new MobileReader(pathAccountSid); } /** - * Converts a JSON String into a Mobile object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Mobile object represented by the provided JSON - */ - public static Mobile fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Mobile object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Mobile object represented by the provided JSON + */ + public static Mobile fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Mobile.class); @@ -78,14 +84,17 @@ public static Mobile fromJson(final String json, final ObjectMapper objectMapper } /** - * Converts a JSON InputStream into a Mobile object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Mobile object represented by the provided JSON - */ - public static Mobile fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Mobile object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Mobile object represented by the provided JSON + */ + public static Mobile fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Mobile.class); @@ -95,6 +104,7 @@ public static Mobile fromJson(final InputStream json, final ObjectMapper objectM throw new ApiConnectionException(e.getMessage(), e); } } + public enum AddressRequirement { NONE("none"), ANY("any"), @@ -116,6 +126,7 @@ public static AddressRequirement forValue(final String value) { return Promoter.enumFromString(value, AddressRequirement.values()); } } + public enum EmergencyAddressStatus { REGISTERED("registered"), UNREGISTERED("unregistered"), @@ -136,9 +147,13 @@ public String toString() { @JsonCreator public static EmergencyAddressStatus forValue(final String value) { - return Promoter.enumFromString(value, EmergencyAddressStatus.values()); + return Promoter.enumFromString( + value, + EmergencyAddressStatus.values() + ); } } + public enum EmergencyStatus { ACTIVE("Active"), INACTIVE("Inactive"); @@ -158,6 +173,7 @@ public static EmergencyStatus forValue(final String value) { return Promoter.enumFromString(value, EmergencyStatus.values()); } } + public enum VoiceReceiveMode { VOICE("voice"), FAX("fax"); @@ -215,107 +231,58 @@ public static VoiceReceiveMode forValue(final String value) { @JsonCreator private Mobile( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("address_sid") - final String addressSid, - - @JsonProperty("address_requirements") - final Mobile.AddressRequirement addressRequirements, - - @JsonProperty("api_version") - final String apiVersion, - - @JsonProperty("beta") - final Boolean beta, - - @JsonProperty("capabilities") - final PhoneNumberCapabilities capabilities, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("identity_sid") - final String identitySid, - - @JsonProperty("phone_number") - final com.twilio.type.PhoneNumber phoneNumber, - - @JsonProperty("origin") - final String origin, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("sms_application_sid") - final String smsApplicationSid, - - @JsonProperty("sms_fallback_method") - final HttpMethod smsFallbackMethod, - - @JsonProperty("sms_fallback_url") - final URI smsFallbackUrl, - - @JsonProperty("sms_method") - final HttpMethod smsMethod, - - @JsonProperty("sms_url") - final URI smsUrl, - - @JsonProperty("status_callback") - final URI statusCallback, - - @JsonProperty("status_callback_method") - final HttpMethod statusCallbackMethod, - - @JsonProperty("trunk_sid") - final String trunkSid, - - @JsonProperty("uri") - final String uri, - - @JsonProperty("voice_receive_mode") - final Mobile.VoiceReceiveMode voiceReceiveMode, - - @JsonProperty("voice_application_sid") - final String voiceApplicationSid, - - @JsonProperty("voice_caller_id_lookup") - final Boolean voiceCallerIdLookup, - - @JsonProperty("voice_fallback_method") - final HttpMethod voiceFallbackMethod, - - @JsonProperty("voice_fallback_url") - final URI voiceFallbackUrl, - - @JsonProperty("voice_method") - final HttpMethod voiceMethod, - - @JsonProperty("voice_url") - final URI voiceUrl, - - @JsonProperty("emergency_status") - final Mobile.EmergencyStatus emergencyStatus, - - @JsonProperty("emergency_address_sid") - final String emergencyAddressSid, - - @JsonProperty("emergency_address_status") - final Mobile.EmergencyAddressStatus emergencyAddressStatus, - - @JsonProperty("bundle_sid") - final String bundleSid, - - @JsonProperty("status") - final String status + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("address_sid") final String addressSid, + @JsonProperty( + "address_requirements" + ) final Mobile.AddressRequirement addressRequirements, + @JsonProperty("api_version") final String apiVersion, + @JsonProperty("beta") final Boolean beta, + @JsonProperty( + "capabilities" + ) final PhoneNumberCapabilities capabilities, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("identity_sid") final String identitySid, + @JsonProperty( + "phone_number" + ) final com.twilio.type.PhoneNumber phoneNumber, + @JsonProperty("origin") final String origin, + @JsonProperty("sid") final String sid, + @JsonProperty("sms_application_sid") final String smsApplicationSid, + @JsonProperty("sms_fallback_method") final HttpMethod smsFallbackMethod, + @JsonProperty("sms_fallback_url") final URI smsFallbackUrl, + @JsonProperty("sms_method") final HttpMethod smsMethod, + @JsonProperty("sms_url") final URI smsUrl, + @JsonProperty("status_callback") final URI statusCallback, + @JsonProperty( + "status_callback_method" + ) final HttpMethod statusCallbackMethod, + @JsonProperty("trunk_sid") final String trunkSid, + @JsonProperty("uri") final String uri, + @JsonProperty( + "voice_receive_mode" + ) final Mobile.VoiceReceiveMode voiceReceiveMode, + @JsonProperty("voice_application_sid") final String voiceApplicationSid, + @JsonProperty( + "voice_caller_id_lookup" + ) final Boolean voiceCallerIdLookup, + @JsonProperty( + "voice_fallback_method" + ) final HttpMethod voiceFallbackMethod, + @JsonProperty("voice_fallback_url") final URI voiceFallbackUrl, + @JsonProperty("voice_method") final HttpMethod voiceMethod, + @JsonProperty("voice_url") final URI voiceUrl, + @JsonProperty( + "emergency_status" + ) final Mobile.EmergencyStatus emergencyStatus, + @JsonProperty("emergency_address_sid") final String emergencyAddressSid, + @JsonProperty( + "emergency_address_status" + ) final Mobile.EmergencyAddressStatus emergencyAddressStatus, + @JsonProperty("bundle_sid") final String bundleSid, + @JsonProperty("status") final String status ) { this.accountSid = accountSid; this.addressSid = addressSid; @@ -353,112 +320,145 @@ private Mobile( this.status = status; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getAddressSid() { - return this.addressSid; - } - public final Mobile.AddressRequirement getAddressRequirements() { - return this.addressRequirements; - } - public final String getApiVersion() { - return this.apiVersion; - } - public final Boolean getBeta() { - return this.beta; - } - public final PhoneNumberCapabilities getCapabilities() { - return this.capabilities; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getIdentitySid() { - return this.identitySid; - } - public final com.twilio.type.PhoneNumber getPhoneNumber() { - return this.phoneNumber; - } - public final String getOrigin() { - return this.origin; - } - public final String getSid() { - return this.sid; - } - public final String getSmsApplicationSid() { - return this.smsApplicationSid; - } - public final HttpMethod getSmsFallbackMethod() { - return this.smsFallbackMethod; - } - public final URI getSmsFallbackUrl() { - return this.smsFallbackUrl; - } - public final HttpMethod getSmsMethod() { - return this.smsMethod; - } - public final URI getSmsUrl() { - return this.smsUrl; - } - public final URI getStatusCallback() { - return this.statusCallback; - } - public final HttpMethod getStatusCallbackMethod() { - return this.statusCallbackMethod; - } - public final String getTrunkSid() { - return this.trunkSid; - } - public final String getUri() { - return this.uri; - } - public final Mobile.VoiceReceiveMode getVoiceReceiveMode() { - return this.voiceReceiveMode; - } - public final String getVoiceApplicationSid() { - return this.voiceApplicationSid; - } - public final Boolean getVoiceCallerIdLookup() { - return this.voiceCallerIdLookup; - } - public final HttpMethod getVoiceFallbackMethod() { - return this.voiceFallbackMethod; - } - public final URI getVoiceFallbackUrl() { - return this.voiceFallbackUrl; - } - public final HttpMethod getVoiceMethod() { - return this.voiceMethod; - } - public final URI getVoiceUrl() { - return this.voiceUrl; - } - public final Mobile.EmergencyStatus getEmergencyStatus() { - return this.emergencyStatus; - } - public final String getEmergencyAddressSid() { - return this.emergencyAddressSid; - } - public final Mobile.EmergencyAddressStatus getEmergencyAddressStatus() { - return this.emergencyAddressStatus; - } - public final String getBundleSid() { - return this.bundleSid; - } - public final String getStatus() { - return this.status; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getAddressSid() { + return this.addressSid; + } + + public final Mobile.AddressRequirement getAddressRequirements() { + return this.addressRequirements; + } + + public final String getApiVersion() { + return this.apiVersion; + } + + public final Boolean getBeta() { + return this.beta; + } + + public final PhoneNumberCapabilities getCapabilities() { + return this.capabilities; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getIdentitySid() { + return this.identitySid; + } + + public final com.twilio.type.PhoneNumber getPhoneNumber() { + return this.phoneNumber; + } + + public final String getOrigin() { + return this.origin; + } + + public final String getSid() { + return this.sid; + } + + public final String getSmsApplicationSid() { + return this.smsApplicationSid; + } + + public final HttpMethod getSmsFallbackMethod() { + return this.smsFallbackMethod; + } + + public final URI getSmsFallbackUrl() { + return this.smsFallbackUrl; + } + + public final HttpMethod getSmsMethod() { + return this.smsMethod; + } + + public final URI getSmsUrl() { + return this.smsUrl; + } + + public final URI getStatusCallback() { + return this.statusCallback; + } + + public final HttpMethod getStatusCallbackMethod() { + return this.statusCallbackMethod; + } + + public final String getTrunkSid() { + return this.trunkSid; + } + + public final String getUri() { + return this.uri; + } + + public final Mobile.VoiceReceiveMode getVoiceReceiveMode() { + return this.voiceReceiveMode; + } + + public final String getVoiceApplicationSid() { + return this.voiceApplicationSid; + } + + public final Boolean getVoiceCallerIdLookup() { + return this.voiceCallerIdLookup; + } + + public final HttpMethod getVoiceFallbackMethod() { + return this.voiceFallbackMethod; + } + + public final URI getVoiceFallbackUrl() { + return this.voiceFallbackUrl; + } + + public final HttpMethod getVoiceMethod() { + return this.voiceMethod; + } + + public final URI getVoiceUrl() { + return this.voiceUrl; + } + + public final Mobile.EmergencyStatus getEmergencyStatus() { + return this.emergencyStatus; + } + + public final String getEmergencyAddressSid() { + return this.emergencyAddressSid; + } + + public final Mobile.EmergencyAddressStatus getEmergencyAddressStatus() { + return this.emergencyAddressStatus; + } + + public final String getBundleSid() { + return this.bundleSid; + } + + public final String getStatus() { + return this.status; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -468,13 +468,84 @@ public boolean equals(final Object o) { Mobile other = (Mobile) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(addressSid, other.addressSid) && Objects.equals(addressRequirements, other.addressRequirements) && Objects.equals(apiVersion, other.apiVersion) && Objects.equals(beta, other.beta) && Objects.equals(capabilities, other.capabilities) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(identitySid, other.identitySid) && Objects.equals(phoneNumber, other.phoneNumber) && Objects.equals(origin, other.origin) && Objects.equals(sid, other.sid) && Objects.equals(smsApplicationSid, other.smsApplicationSid) && Objects.equals(smsFallbackMethod, other.smsFallbackMethod) && Objects.equals(smsFallbackUrl, other.smsFallbackUrl) && Objects.equals(smsMethod, other.smsMethod) && Objects.equals(smsUrl, other.smsUrl) && Objects.equals(statusCallback, other.statusCallback) && Objects.equals(statusCallbackMethod, other.statusCallbackMethod) && Objects.equals(trunkSid, other.trunkSid) && Objects.equals(uri, other.uri) && Objects.equals(voiceReceiveMode, other.voiceReceiveMode) && Objects.equals(voiceApplicationSid, other.voiceApplicationSid) && Objects.equals(voiceCallerIdLookup, other.voiceCallerIdLookup) && Objects.equals(voiceFallbackMethod, other.voiceFallbackMethod) && Objects.equals(voiceFallbackUrl, other.voiceFallbackUrl) && Objects.equals(voiceMethod, other.voiceMethod) && Objects.equals(voiceUrl, other.voiceUrl) && Objects.equals(emergencyStatus, other.emergencyStatus) && Objects.equals(emergencyAddressSid, other.emergencyAddressSid) && Objects.equals(emergencyAddressStatus, other.emergencyAddressStatus) && Objects.equals(bundleSid, other.bundleSid) && Objects.equals(status, other.status) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(addressSid, other.addressSid) && + Objects.equals(addressRequirements, other.addressRequirements) && + Objects.equals(apiVersion, other.apiVersion) && + Objects.equals(beta, other.beta) && + Objects.equals(capabilities, other.capabilities) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(identitySid, other.identitySid) && + Objects.equals(phoneNumber, other.phoneNumber) && + Objects.equals(origin, other.origin) && + Objects.equals(sid, other.sid) && + Objects.equals(smsApplicationSid, other.smsApplicationSid) && + Objects.equals(smsFallbackMethod, other.smsFallbackMethod) && + Objects.equals(smsFallbackUrl, other.smsFallbackUrl) && + Objects.equals(smsMethod, other.smsMethod) && + Objects.equals(smsUrl, other.smsUrl) && + Objects.equals(statusCallback, other.statusCallback) && + Objects.equals(statusCallbackMethod, other.statusCallbackMethod) && + Objects.equals(trunkSid, other.trunkSid) && + Objects.equals(uri, other.uri) && + Objects.equals(voiceReceiveMode, other.voiceReceiveMode) && + Objects.equals(voiceApplicationSid, other.voiceApplicationSid) && + Objects.equals(voiceCallerIdLookup, other.voiceCallerIdLookup) && + Objects.equals(voiceFallbackMethod, other.voiceFallbackMethod) && + Objects.equals(voiceFallbackUrl, other.voiceFallbackUrl) && + Objects.equals(voiceMethod, other.voiceMethod) && + Objects.equals(voiceUrl, other.voiceUrl) && + Objects.equals(emergencyStatus, other.emergencyStatus) && + Objects.equals(emergencyAddressSid, other.emergencyAddressSid) && + Objects.equals( + emergencyAddressStatus, + other.emergencyAddressStatus + ) && + Objects.equals(bundleSid, other.bundleSid) && + Objects.equals(status, other.status) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, addressSid, addressRequirements, apiVersion, beta, capabilities, dateCreated, dateUpdated, friendlyName, identitySid, phoneNumber, origin, sid, smsApplicationSid, smsFallbackMethod, smsFallbackUrl, smsMethod, smsUrl, statusCallback, statusCallbackMethod, trunkSid, uri, voiceReceiveMode, voiceApplicationSid, voiceCallerIdLookup, voiceFallbackMethod, voiceFallbackUrl, voiceMethod, voiceUrl, emergencyStatus, emergencyAddressSid, emergencyAddressStatus, bundleSid, status); + return Objects.hash( + accountSid, + addressSid, + addressRequirements, + apiVersion, + beta, + capabilities, + dateCreated, + dateUpdated, + friendlyName, + identitySid, + phoneNumber, + origin, + sid, + smsApplicationSid, + smsFallbackMethod, + smsFallbackUrl, + smsMethod, + smsUrl, + statusCallback, + statusCallbackMethod, + trunkSid, + uri, + voiceReceiveMode, + voiceApplicationSid, + voiceCallerIdLookup, + voiceFallbackMethod, + voiceFallbackUrl, + voiceMethod, + voiceUrl, + emergencyStatus, + emergencyAddressSid, + emergencyAddressStatus, + bundleSid, + status + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/MobileCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/MobileCreator.java index a116ac39e0..a812fbe30e 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/MobileCreator.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/MobileCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010.account.incomingphonenumber; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -25,12 +26,10 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.net.URI; - - - import java.net.URI; -public class MobileCreator extends Creator{ +public class MobileCreator extends Creator { + private com.twilio.type.PhoneNumber phoneNumber; private String pathAccountSid; private String apiVersion; @@ -59,147 +58,209 @@ public class MobileCreator extends Creator{ public MobileCreator(final com.twilio.type.PhoneNumber phoneNumber) { this.phoneNumber = phoneNumber; } - public MobileCreator(final String pathAccountSid, final com.twilio.type.PhoneNumber phoneNumber) { + + public MobileCreator( + final String pathAccountSid, + final com.twilio.type.PhoneNumber phoneNumber + ) { this.pathAccountSid = pathAccountSid; this.phoneNumber = phoneNumber; } - public MobileCreator setPhoneNumber(final com.twilio.type.PhoneNumber phoneNumber){ + public MobileCreator setPhoneNumber( + final com.twilio.type.PhoneNumber phoneNumber + ) { this.phoneNumber = phoneNumber; return this; } - public MobileCreator setPhoneNumber(final String phoneNumber){ + public MobileCreator setPhoneNumber(final String phoneNumber) { return setPhoneNumber(Promoter.phoneNumberFromString(phoneNumber)); } - public MobileCreator setApiVersion(final String apiVersion){ + + public MobileCreator setApiVersion(final String apiVersion) { this.apiVersion = apiVersion; return this; } - public MobileCreator setFriendlyName(final String friendlyName){ + + public MobileCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public MobileCreator setSmsApplicationSid(final String smsApplicationSid){ + + public MobileCreator setSmsApplicationSid(final String smsApplicationSid) { this.smsApplicationSid = smsApplicationSid; return this; } - public MobileCreator setSmsFallbackMethod(final HttpMethod smsFallbackMethod){ + + public MobileCreator setSmsFallbackMethod( + final HttpMethod smsFallbackMethod + ) { this.smsFallbackMethod = smsFallbackMethod; return this; } - public MobileCreator setSmsFallbackUrl(final URI smsFallbackUrl){ + + public MobileCreator setSmsFallbackUrl(final URI smsFallbackUrl) { this.smsFallbackUrl = smsFallbackUrl; return this; } - public MobileCreator setSmsFallbackUrl(final String smsFallbackUrl){ + public MobileCreator setSmsFallbackUrl(final String smsFallbackUrl) { return setSmsFallbackUrl(Promoter.uriFromString(smsFallbackUrl)); } - public MobileCreator setSmsMethod(final HttpMethod smsMethod){ + + public MobileCreator setSmsMethod(final HttpMethod smsMethod) { this.smsMethod = smsMethod; return this; } - public MobileCreator setSmsUrl(final URI smsUrl){ + + public MobileCreator setSmsUrl(final URI smsUrl) { this.smsUrl = smsUrl; return this; } - public MobileCreator setSmsUrl(final String smsUrl){ + public MobileCreator setSmsUrl(final String smsUrl) { return setSmsUrl(Promoter.uriFromString(smsUrl)); } - public MobileCreator setStatusCallback(final URI statusCallback){ + + public MobileCreator setStatusCallback(final URI statusCallback) { this.statusCallback = statusCallback; return this; } - public MobileCreator setStatusCallback(final String statusCallback){ + public MobileCreator setStatusCallback(final String statusCallback) { return setStatusCallback(Promoter.uriFromString(statusCallback)); } - public MobileCreator setStatusCallbackMethod(final HttpMethod statusCallbackMethod){ + + public MobileCreator setStatusCallbackMethod( + final HttpMethod statusCallbackMethod + ) { this.statusCallbackMethod = statusCallbackMethod; return this; } - public MobileCreator setVoiceApplicationSid(final String voiceApplicationSid){ + + public MobileCreator setVoiceApplicationSid( + final String voiceApplicationSid + ) { this.voiceApplicationSid = voiceApplicationSid; return this; } - public MobileCreator setVoiceCallerIdLookup(final Boolean voiceCallerIdLookup){ + + public MobileCreator setVoiceCallerIdLookup( + final Boolean voiceCallerIdLookup + ) { this.voiceCallerIdLookup = voiceCallerIdLookup; return this; } - public MobileCreator setVoiceFallbackMethod(final HttpMethod voiceFallbackMethod){ + + public MobileCreator setVoiceFallbackMethod( + final HttpMethod voiceFallbackMethod + ) { this.voiceFallbackMethod = voiceFallbackMethod; return this; } - public MobileCreator setVoiceFallbackUrl(final URI voiceFallbackUrl){ + + public MobileCreator setVoiceFallbackUrl(final URI voiceFallbackUrl) { this.voiceFallbackUrl = voiceFallbackUrl; return this; } - public MobileCreator setVoiceFallbackUrl(final String voiceFallbackUrl){ + public MobileCreator setVoiceFallbackUrl(final String voiceFallbackUrl) { return setVoiceFallbackUrl(Promoter.uriFromString(voiceFallbackUrl)); } - public MobileCreator setVoiceMethod(final HttpMethod voiceMethod){ + + public MobileCreator setVoiceMethod(final HttpMethod voiceMethod) { this.voiceMethod = voiceMethod; return this; } - public MobileCreator setVoiceUrl(final URI voiceUrl){ + + public MobileCreator setVoiceUrl(final URI voiceUrl) { this.voiceUrl = voiceUrl; return this; } - public MobileCreator setVoiceUrl(final String voiceUrl){ + public MobileCreator setVoiceUrl(final String voiceUrl) { return setVoiceUrl(Promoter.uriFromString(voiceUrl)); } - public MobileCreator setIdentitySid(final String identitySid){ + + public MobileCreator setIdentitySid(final String identitySid) { this.identitySid = identitySid; return this; } - public MobileCreator setAddressSid(final String addressSid){ + + public MobileCreator setAddressSid(final String addressSid) { this.addressSid = addressSid; return this; } - public MobileCreator setEmergencyStatus(final Mobile.EmergencyStatus emergencyStatus){ + + public MobileCreator setEmergencyStatus( + final Mobile.EmergencyStatus emergencyStatus + ) { this.emergencyStatus = emergencyStatus; return this; } - public MobileCreator setEmergencyAddressSid(final String emergencyAddressSid){ + + public MobileCreator setEmergencyAddressSid( + final String emergencyAddressSid + ) { this.emergencyAddressSid = emergencyAddressSid; return this; } - public MobileCreator setTrunkSid(final String trunkSid){ + + public MobileCreator setTrunkSid(final String trunkSid) { this.trunkSid = trunkSid; return this; } - public MobileCreator setVoiceReceiveMode(final Mobile.VoiceReceiveMode voiceReceiveMode){ + + public MobileCreator setVoiceReceiveMode( + final Mobile.VoiceReceiveMode voiceReceiveMode + ) { this.voiceReceiveMode = voiceReceiveMode; return this; } - public MobileCreator setBundleSid(final String bundleSid){ + + public MobileCreator setBundleSid(final String bundleSid) { this.bundleSid = bundleSid; return this; } @Override - public Mobile create(final TwilioRestClient client){ - String path = "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/Mobile.json"; + public Mobile create(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/Mobile.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"PhoneNumber"+"}", this.phoneNumber.encode("utf-8")); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "PhoneNumber" + "}", + this.phoneNumber.encode("utf-8") + ); Request request = new Request( HttpMethod.POST, Domains.API.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Mobile creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Mobile creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -208,98 +269,94 @@ public Mobile create(final TwilioRestClient client){ return Mobile.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (phoneNumber != null) { request.addPostParam("PhoneNumber", phoneNumber.toString()); - } if (apiVersion != null) { request.addPostParam("ApiVersion", apiVersion); - } if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (smsApplicationSid != null) { request.addPostParam("SmsApplicationSid", smsApplicationSid); - } if (smsFallbackMethod != null) { - request.addPostParam("SmsFallbackMethod", smsFallbackMethod.toString()); - + request.addPostParam( + "SmsFallbackMethod", + smsFallbackMethod.toString() + ); } if (smsFallbackUrl != null) { request.addPostParam("SmsFallbackUrl", smsFallbackUrl.toString()); - } if (smsMethod != null) { request.addPostParam("SmsMethod", smsMethod.toString()); - } if (smsUrl != null) { request.addPostParam("SmsUrl", smsUrl.toString()); - } if (statusCallback != null) { request.addPostParam("StatusCallback", statusCallback.toString()); - } if (statusCallbackMethod != null) { - request.addPostParam("StatusCallbackMethod", statusCallbackMethod.toString()); - + request.addPostParam( + "StatusCallbackMethod", + statusCallbackMethod.toString() + ); } if (voiceApplicationSid != null) { request.addPostParam("VoiceApplicationSid", voiceApplicationSid); - } if (voiceCallerIdLookup != null) { - request.addPostParam("VoiceCallerIdLookup", voiceCallerIdLookup.toString()); - + request.addPostParam( + "VoiceCallerIdLookup", + voiceCallerIdLookup.toString() + ); } if (voiceFallbackMethod != null) { - request.addPostParam("VoiceFallbackMethod", voiceFallbackMethod.toString()); - + request.addPostParam( + "VoiceFallbackMethod", + voiceFallbackMethod.toString() + ); } if (voiceFallbackUrl != null) { - request.addPostParam("VoiceFallbackUrl", voiceFallbackUrl.toString()); - + request.addPostParam( + "VoiceFallbackUrl", + voiceFallbackUrl.toString() + ); } if (voiceMethod != null) { request.addPostParam("VoiceMethod", voiceMethod.toString()); - } if (voiceUrl != null) { request.addPostParam("VoiceUrl", voiceUrl.toString()); - } if (identitySid != null) { request.addPostParam("IdentitySid", identitySid); - } if (addressSid != null) { request.addPostParam("AddressSid", addressSid); - } if (emergencyStatus != null) { request.addPostParam("EmergencyStatus", emergencyStatus.toString()); - } if (emergencyAddressSid != null) { request.addPostParam("EmergencyAddressSid", emergencyAddressSid); - } if (trunkSid != null) { request.addPostParam("TrunkSid", trunkSid); - } if (voiceReceiveMode != null) { - request.addPostParam("VoiceReceiveMode", voiceReceiveMode.toString()); - + request.addPostParam( + "VoiceReceiveMode", + voiceReceiveMode.toString() + ); } if (bundleSid != null) { request.addPostParam("BundleSid", bundleSid); - } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/MobileReader.java b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/MobileReader.java index 6c8b6eb1e4..e045f91d24 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/MobileReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/MobileReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.api.v2010.account.incomingphonenumber; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.converter.Promoter; @@ -25,11 +26,9 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class MobileReader extends Reader { + private String pathAccountSid; private Boolean beta; private String friendlyName; @@ -37,33 +36,39 @@ public class MobileReader extends Reader { private String origin; private Integer pageSize; - public MobileReader(){ - } - public MobileReader(final String pathAccountSid){ + public MobileReader() {} + + public MobileReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - public MobileReader setBeta(final Boolean beta){ + public MobileReader setBeta(final Boolean beta) { this.beta = beta; return this; } - public MobileReader setFriendlyName(final String friendlyName){ + + public MobileReader setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public MobileReader setPhoneNumber(final com.twilio.type.PhoneNumber phoneNumber){ + + public MobileReader setPhoneNumber( + final com.twilio.type.PhoneNumber phoneNumber + ) { this.phoneNumber = phoneNumber; return this; } - public MobileReader setPhoneNumber(final String phoneNumber){ + public MobileReader setPhoneNumber(final String phoneNumber) { return setPhoneNumber(Promoter.phoneNumberFromString(phoneNumber)); } - public MobileReader setOrigin(final String origin){ + + public MobileReader setOrigin(final String origin) { this.origin = origin; return this; } - public MobileReader setPageSize(final Integer pageSize){ + + public MobileReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -74,9 +79,17 @@ public ResourceSet read(final TwilioRestClient client) { } public Page firstPage(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/Mobile.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); + String path = + "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/Mobile.json"; + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -88,13 +101,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Mobile read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Mobile read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -110,7 +131,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.API.toString()) @@ -118,9 +142,11 @@ public Page previousPage(final Page page, final TwilioRestClient return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.API.toString()) @@ -129,37 +155,33 @@ public Page nextPage(final Page page, final TwilioRestClient cli } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (beta != null) { - request.addQueryParam("Beta", beta.toString()); } if (friendlyName != null) { - request.addQueryParam("FriendlyName", friendlyName); } if (phoneNumber != null) { - request.addQueryParam("PhoneNumber", phoneNumber.toString()); } if (origin != null) { - request.addQueryParam("Origin", origin); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/TollFree.java b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/TollFree.java index f224dfeeb0..cb3abd2ff7 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/TollFree.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/TollFree.java @@ -24,49 +24,55 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; import com.twilio.http.HttpMethod; - -import lombok.ToString; - +import com.twilio.type.PhoneNumberCapabilities; import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - -import com.twilio.type.PhoneNumberCapabilities; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class TollFree extends Resource { + private static final long serialVersionUID = 90694713647603L; - public static TollFreeCreator creator(final com.twilio.type.PhoneNumber phoneNumber){ + public static TollFreeCreator creator( + final com.twilio.type.PhoneNumber phoneNumber + ) { return new TollFreeCreator(phoneNumber); } - public static TollFreeCreator creator(final String pathAccountSid, final com.twilio.type.PhoneNumber phoneNumber){ + + public static TollFreeCreator creator( + final String pathAccountSid, + final com.twilio.type.PhoneNumber phoneNumber + ) { return new TollFreeCreator(pathAccountSid, phoneNumber); } - public static TollFreeReader reader(){ + public static TollFreeReader reader() { return new TollFreeReader(); } - public static TollFreeReader reader(final String pathAccountSid){ + + public static TollFreeReader reader(final String pathAccountSid) { return new TollFreeReader(pathAccountSid); } /** - * Converts a JSON String into a TollFree object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return TollFree object represented by the provided JSON - */ - public static TollFree fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a TollFree object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return TollFree object represented by the provided JSON + */ + public static TollFree fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, TollFree.class); @@ -78,14 +84,17 @@ public static TollFree fromJson(final String json, final ObjectMapper objectMapp } /** - * Converts a JSON InputStream into a TollFree object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return TollFree object represented by the provided JSON - */ - public static TollFree fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a TollFree object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return TollFree object represented by the provided JSON + */ + public static TollFree fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, TollFree.class); @@ -95,6 +104,7 @@ public static TollFree fromJson(final InputStream json, final ObjectMapper objec throw new ApiConnectionException(e.getMessage(), e); } } + public enum AddressRequirement { NONE("none"), ANY("any"), @@ -116,6 +126,7 @@ public static AddressRequirement forValue(final String value) { return Promoter.enumFromString(value, AddressRequirement.values()); } } + public enum EmergencyAddressStatus { REGISTERED("registered"), UNREGISTERED("unregistered"), @@ -136,9 +147,13 @@ public String toString() { @JsonCreator public static EmergencyAddressStatus forValue(final String value) { - return Promoter.enumFromString(value, EmergencyAddressStatus.values()); + return Promoter.enumFromString( + value, + EmergencyAddressStatus.values() + ); } } + public enum EmergencyStatus { ACTIVE("Active"), INACTIVE("Inactive"); @@ -158,6 +173,7 @@ public static EmergencyStatus forValue(final String value) { return Promoter.enumFromString(value, EmergencyStatus.values()); } } + public enum VoiceReceiveMode { VOICE("voice"), FAX("fax"); @@ -215,107 +231,58 @@ public static VoiceReceiveMode forValue(final String value) { @JsonCreator private TollFree( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("address_sid") - final String addressSid, - - @JsonProperty("address_requirements") - final TollFree.AddressRequirement addressRequirements, - - @JsonProperty("api_version") - final String apiVersion, - - @JsonProperty("beta") - final Boolean beta, - - @JsonProperty("capabilities") - final PhoneNumberCapabilities capabilities, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("identity_sid") - final String identitySid, - - @JsonProperty("phone_number") - final com.twilio.type.PhoneNumber phoneNumber, - - @JsonProperty("origin") - final String origin, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("sms_application_sid") - final String smsApplicationSid, - - @JsonProperty("sms_fallback_method") - final HttpMethod smsFallbackMethod, - - @JsonProperty("sms_fallback_url") - final URI smsFallbackUrl, - - @JsonProperty("sms_method") - final HttpMethod smsMethod, - - @JsonProperty("sms_url") - final URI smsUrl, - - @JsonProperty("status_callback") - final URI statusCallback, - - @JsonProperty("status_callback_method") - final HttpMethod statusCallbackMethod, - - @JsonProperty("trunk_sid") - final String trunkSid, - - @JsonProperty("uri") - final String uri, - - @JsonProperty("voice_receive_mode") - final TollFree.VoiceReceiveMode voiceReceiveMode, - - @JsonProperty("voice_application_sid") - final String voiceApplicationSid, - - @JsonProperty("voice_caller_id_lookup") - final Boolean voiceCallerIdLookup, - - @JsonProperty("voice_fallback_method") - final HttpMethod voiceFallbackMethod, - - @JsonProperty("voice_fallback_url") - final URI voiceFallbackUrl, - - @JsonProperty("voice_method") - final HttpMethod voiceMethod, - - @JsonProperty("voice_url") - final URI voiceUrl, - - @JsonProperty("emergency_status") - final TollFree.EmergencyStatus emergencyStatus, - - @JsonProperty("emergency_address_sid") - final String emergencyAddressSid, - - @JsonProperty("emergency_address_status") - final TollFree.EmergencyAddressStatus emergencyAddressStatus, - - @JsonProperty("bundle_sid") - final String bundleSid, - - @JsonProperty("status") - final String status + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("address_sid") final String addressSid, + @JsonProperty( + "address_requirements" + ) final TollFree.AddressRequirement addressRequirements, + @JsonProperty("api_version") final String apiVersion, + @JsonProperty("beta") final Boolean beta, + @JsonProperty( + "capabilities" + ) final PhoneNumberCapabilities capabilities, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("identity_sid") final String identitySid, + @JsonProperty( + "phone_number" + ) final com.twilio.type.PhoneNumber phoneNumber, + @JsonProperty("origin") final String origin, + @JsonProperty("sid") final String sid, + @JsonProperty("sms_application_sid") final String smsApplicationSid, + @JsonProperty("sms_fallback_method") final HttpMethod smsFallbackMethod, + @JsonProperty("sms_fallback_url") final URI smsFallbackUrl, + @JsonProperty("sms_method") final HttpMethod smsMethod, + @JsonProperty("sms_url") final URI smsUrl, + @JsonProperty("status_callback") final URI statusCallback, + @JsonProperty( + "status_callback_method" + ) final HttpMethod statusCallbackMethod, + @JsonProperty("trunk_sid") final String trunkSid, + @JsonProperty("uri") final String uri, + @JsonProperty( + "voice_receive_mode" + ) final TollFree.VoiceReceiveMode voiceReceiveMode, + @JsonProperty("voice_application_sid") final String voiceApplicationSid, + @JsonProperty( + "voice_caller_id_lookup" + ) final Boolean voiceCallerIdLookup, + @JsonProperty( + "voice_fallback_method" + ) final HttpMethod voiceFallbackMethod, + @JsonProperty("voice_fallback_url") final URI voiceFallbackUrl, + @JsonProperty("voice_method") final HttpMethod voiceMethod, + @JsonProperty("voice_url") final URI voiceUrl, + @JsonProperty( + "emergency_status" + ) final TollFree.EmergencyStatus emergencyStatus, + @JsonProperty("emergency_address_sid") final String emergencyAddressSid, + @JsonProperty( + "emergency_address_status" + ) final TollFree.EmergencyAddressStatus emergencyAddressStatus, + @JsonProperty("bundle_sid") final String bundleSid, + @JsonProperty("status") final String status ) { this.accountSid = accountSid; this.addressSid = addressSid; @@ -353,112 +320,145 @@ private TollFree( this.status = status; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getAddressSid() { - return this.addressSid; - } - public final TollFree.AddressRequirement getAddressRequirements() { - return this.addressRequirements; - } - public final String getApiVersion() { - return this.apiVersion; - } - public final Boolean getBeta() { - return this.beta; - } - public final PhoneNumberCapabilities getCapabilities() { - return this.capabilities; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getIdentitySid() { - return this.identitySid; - } - public final com.twilio.type.PhoneNumber getPhoneNumber() { - return this.phoneNumber; - } - public final String getOrigin() { - return this.origin; - } - public final String getSid() { - return this.sid; - } - public final String getSmsApplicationSid() { - return this.smsApplicationSid; - } - public final HttpMethod getSmsFallbackMethod() { - return this.smsFallbackMethod; - } - public final URI getSmsFallbackUrl() { - return this.smsFallbackUrl; - } - public final HttpMethod getSmsMethod() { - return this.smsMethod; - } - public final URI getSmsUrl() { - return this.smsUrl; - } - public final URI getStatusCallback() { - return this.statusCallback; - } - public final HttpMethod getStatusCallbackMethod() { - return this.statusCallbackMethod; - } - public final String getTrunkSid() { - return this.trunkSid; - } - public final String getUri() { - return this.uri; - } - public final TollFree.VoiceReceiveMode getVoiceReceiveMode() { - return this.voiceReceiveMode; - } - public final String getVoiceApplicationSid() { - return this.voiceApplicationSid; - } - public final Boolean getVoiceCallerIdLookup() { - return this.voiceCallerIdLookup; - } - public final HttpMethod getVoiceFallbackMethod() { - return this.voiceFallbackMethod; - } - public final URI getVoiceFallbackUrl() { - return this.voiceFallbackUrl; - } - public final HttpMethod getVoiceMethod() { - return this.voiceMethod; - } - public final URI getVoiceUrl() { - return this.voiceUrl; - } - public final TollFree.EmergencyStatus getEmergencyStatus() { - return this.emergencyStatus; - } - public final String getEmergencyAddressSid() { - return this.emergencyAddressSid; - } - public final TollFree.EmergencyAddressStatus getEmergencyAddressStatus() { - return this.emergencyAddressStatus; - } - public final String getBundleSid() { - return this.bundleSid; - } - public final String getStatus() { - return this.status; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getAddressSid() { + return this.addressSid; + } + + public final TollFree.AddressRequirement getAddressRequirements() { + return this.addressRequirements; + } + + public final String getApiVersion() { + return this.apiVersion; + } + + public final Boolean getBeta() { + return this.beta; + } + + public final PhoneNumberCapabilities getCapabilities() { + return this.capabilities; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getIdentitySid() { + return this.identitySid; + } + + public final com.twilio.type.PhoneNumber getPhoneNumber() { + return this.phoneNumber; + } + + public final String getOrigin() { + return this.origin; + } + + public final String getSid() { + return this.sid; + } + + public final String getSmsApplicationSid() { + return this.smsApplicationSid; + } + + public final HttpMethod getSmsFallbackMethod() { + return this.smsFallbackMethod; + } + + public final URI getSmsFallbackUrl() { + return this.smsFallbackUrl; + } + + public final HttpMethod getSmsMethod() { + return this.smsMethod; + } + + public final URI getSmsUrl() { + return this.smsUrl; + } + + public final URI getStatusCallback() { + return this.statusCallback; + } + + public final HttpMethod getStatusCallbackMethod() { + return this.statusCallbackMethod; + } + + public final String getTrunkSid() { + return this.trunkSid; + } + + public final String getUri() { + return this.uri; + } + + public final TollFree.VoiceReceiveMode getVoiceReceiveMode() { + return this.voiceReceiveMode; + } + + public final String getVoiceApplicationSid() { + return this.voiceApplicationSid; + } + + public final Boolean getVoiceCallerIdLookup() { + return this.voiceCallerIdLookup; + } + + public final HttpMethod getVoiceFallbackMethod() { + return this.voiceFallbackMethod; + } + + public final URI getVoiceFallbackUrl() { + return this.voiceFallbackUrl; + } + + public final HttpMethod getVoiceMethod() { + return this.voiceMethod; + } + + public final URI getVoiceUrl() { + return this.voiceUrl; + } + + public final TollFree.EmergencyStatus getEmergencyStatus() { + return this.emergencyStatus; + } + + public final String getEmergencyAddressSid() { + return this.emergencyAddressSid; + } + + public final TollFree.EmergencyAddressStatus getEmergencyAddressStatus() { + return this.emergencyAddressStatus; + } + + public final String getBundleSid() { + return this.bundleSid; + } + + public final String getStatus() { + return this.status; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -468,13 +468,84 @@ public boolean equals(final Object o) { TollFree other = (TollFree) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(addressSid, other.addressSid) && Objects.equals(addressRequirements, other.addressRequirements) && Objects.equals(apiVersion, other.apiVersion) && Objects.equals(beta, other.beta) && Objects.equals(capabilities, other.capabilities) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(identitySid, other.identitySid) && Objects.equals(phoneNumber, other.phoneNumber) && Objects.equals(origin, other.origin) && Objects.equals(sid, other.sid) && Objects.equals(smsApplicationSid, other.smsApplicationSid) && Objects.equals(smsFallbackMethod, other.smsFallbackMethod) && Objects.equals(smsFallbackUrl, other.smsFallbackUrl) && Objects.equals(smsMethod, other.smsMethod) && Objects.equals(smsUrl, other.smsUrl) && Objects.equals(statusCallback, other.statusCallback) && Objects.equals(statusCallbackMethod, other.statusCallbackMethod) && Objects.equals(trunkSid, other.trunkSid) && Objects.equals(uri, other.uri) && Objects.equals(voiceReceiveMode, other.voiceReceiveMode) && Objects.equals(voiceApplicationSid, other.voiceApplicationSid) && Objects.equals(voiceCallerIdLookup, other.voiceCallerIdLookup) && Objects.equals(voiceFallbackMethod, other.voiceFallbackMethod) && Objects.equals(voiceFallbackUrl, other.voiceFallbackUrl) && Objects.equals(voiceMethod, other.voiceMethod) && Objects.equals(voiceUrl, other.voiceUrl) && Objects.equals(emergencyStatus, other.emergencyStatus) && Objects.equals(emergencyAddressSid, other.emergencyAddressSid) && Objects.equals(emergencyAddressStatus, other.emergencyAddressStatus) && Objects.equals(bundleSid, other.bundleSid) && Objects.equals(status, other.status) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(addressSid, other.addressSid) && + Objects.equals(addressRequirements, other.addressRequirements) && + Objects.equals(apiVersion, other.apiVersion) && + Objects.equals(beta, other.beta) && + Objects.equals(capabilities, other.capabilities) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(identitySid, other.identitySid) && + Objects.equals(phoneNumber, other.phoneNumber) && + Objects.equals(origin, other.origin) && + Objects.equals(sid, other.sid) && + Objects.equals(smsApplicationSid, other.smsApplicationSid) && + Objects.equals(smsFallbackMethod, other.smsFallbackMethod) && + Objects.equals(smsFallbackUrl, other.smsFallbackUrl) && + Objects.equals(smsMethod, other.smsMethod) && + Objects.equals(smsUrl, other.smsUrl) && + Objects.equals(statusCallback, other.statusCallback) && + Objects.equals(statusCallbackMethod, other.statusCallbackMethod) && + Objects.equals(trunkSid, other.trunkSid) && + Objects.equals(uri, other.uri) && + Objects.equals(voiceReceiveMode, other.voiceReceiveMode) && + Objects.equals(voiceApplicationSid, other.voiceApplicationSid) && + Objects.equals(voiceCallerIdLookup, other.voiceCallerIdLookup) && + Objects.equals(voiceFallbackMethod, other.voiceFallbackMethod) && + Objects.equals(voiceFallbackUrl, other.voiceFallbackUrl) && + Objects.equals(voiceMethod, other.voiceMethod) && + Objects.equals(voiceUrl, other.voiceUrl) && + Objects.equals(emergencyStatus, other.emergencyStatus) && + Objects.equals(emergencyAddressSid, other.emergencyAddressSid) && + Objects.equals( + emergencyAddressStatus, + other.emergencyAddressStatus + ) && + Objects.equals(bundleSid, other.bundleSid) && + Objects.equals(status, other.status) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, addressSid, addressRequirements, apiVersion, beta, capabilities, dateCreated, dateUpdated, friendlyName, identitySid, phoneNumber, origin, sid, smsApplicationSid, smsFallbackMethod, smsFallbackUrl, smsMethod, smsUrl, statusCallback, statusCallbackMethod, trunkSid, uri, voiceReceiveMode, voiceApplicationSid, voiceCallerIdLookup, voiceFallbackMethod, voiceFallbackUrl, voiceMethod, voiceUrl, emergencyStatus, emergencyAddressSid, emergencyAddressStatus, bundleSid, status); + return Objects.hash( + accountSid, + addressSid, + addressRequirements, + apiVersion, + beta, + capabilities, + dateCreated, + dateUpdated, + friendlyName, + identitySid, + phoneNumber, + origin, + sid, + smsApplicationSid, + smsFallbackMethod, + smsFallbackUrl, + smsMethod, + smsUrl, + statusCallback, + statusCallbackMethod, + trunkSid, + uri, + voiceReceiveMode, + voiceApplicationSid, + voiceCallerIdLookup, + voiceFallbackMethod, + voiceFallbackUrl, + voiceMethod, + voiceUrl, + emergencyStatus, + emergencyAddressSid, + emergencyAddressStatus, + bundleSid, + status + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/TollFreeCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/TollFreeCreator.java index 06ee1dd754..d3d1c8f0dc 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/TollFreeCreator.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/TollFreeCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010.account.incomingphonenumber; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -25,12 +26,10 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.net.URI; - - - import java.net.URI; -public class TollFreeCreator extends Creator{ +public class TollFreeCreator extends Creator { + private com.twilio.type.PhoneNumber phoneNumber; private String pathAccountSid; private String apiVersion; @@ -59,247 +58,310 @@ public class TollFreeCreator extends Creator{ public TollFreeCreator(final com.twilio.type.PhoneNumber phoneNumber) { this.phoneNumber = phoneNumber; } - public TollFreeCreator(final String pathAccountSid, final com.twilio.type.PhoneNumber phoneNumber) { + + public TollFreeCreator( + final String pathAccountSid, + final com.twilio.type.PhoneNumber phoneNumber + ) { this.pathAccountSid = pathAccountSid; this.phoneNumber = phoneNumber; } - public TollFreeCreator setPhoneNumber(final com.twilio.type.PhoneNumber phoneNumber){ + public TollFreeCreator setPhoneNumber( + final com.twilio.type.PhoneNumber phoneNumber + ) { this.phoneNumber = phoneNumber; return this; } - public TollFreeCreator setPhoneNumber(final String phoneNumber){ + public TollFreeCreator setPhoneNumber(final String phoneNumber) { return setPhoneNumber(Promoter.phoneNumberFromString(phoneNumber)); } - public TollFreeCreator setApiVersion(final String apiVersion){ + + public TollFreeCreator setApiVersion(final String apiVersion) { this.apiVersion = apiVersion; return this; } - public TollFreeCreator setFriendlyName(final String friendlyName){ + + public TollFreeCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public TollFreeCreator setSmsApplicationSid(final String smsApplicationSid){ + + public TollFreeCreator setSmsApplicationSid( + final String smsApplicationSid + ) { this.smsApplicationSid = smsApplicationSid; return this; } - public TollFreeCreator setSmsFallbackMethod(final HttpMethod smsFallbackMethod){ + + public TollFreeCreator setSmsFallbackMethod( + final HttpMethod smsFallbackMethod + ) { this.smsFallbackMethod = smsFallbackMethod; return this; } - public TollFreeCreator setSmsFallbackUrl(final URI smsFallbackUrl){ + + public TollFreeCreator setSmsFallbackUrl(final URI smsFallbackUrl) { this.smsFallbackUrl = smsFallbackUrl; return this; } - public TollFreeCreator setSmsFallbackUrl(final String smsFallbackUrl){ + public TollFreeCreator setSmsFallbackUrl(final String smsFallbackUrl) { return setSmsFallbackUrl(Promoter.uriFromString(smsFallbackUrl)); } - public TollFreeCreator setSmsMethod(final HttpMethod smsMethod){ + + public TollFreeCreator setSmsMethod(final HttpMethod smsMethod) { this.smsMethod = smsMethod; return this; } - public TollFreeCreator setSmsUrl(final URI smsUrl){ + + public TollFreeCreator setSmsUrl(final URI smsUrl) { this.smsUrl = smsUrl; return this; } - public TollFreeCreator setSmsUrl(final String smsUrl){ + public TollFreeCreator setSmsUrl(final String smsUrl) { return setSmsUrl(Promoter.uriFromString(smsUrl)); } - public TollFreeCreator setStatusCallback(final URI statusCallback){ + + public TollFreeCreator setStatusCallback(final URI statusCallback) { this.statusCallback = statusCallback; return this; } - public TollFreeCreator setStatusCallback(final String statusCallback){ + public TollFreeCreator setStatusCallback(final String statusCallback) { return setStatusCallback(Promoter.uriFromString(statusCallback)); } - public TollFreeCreator setStatusCallbackMethod(final HttpMethod statusCallbackMethod){ + + public TollFreeCreator setStatusCallbackMethod( + final HttpMethod statusCallbackMethod + ) { this.statusCallbackMethod = statusCallbackMethod; return this; } - public TollFreeCreator setVoiceApplicationSid(final String voiceApplicationSid){ + + public TollFreeCreator setVoiceApplicationSid( + final String voiceApplicationSid + ) { this.voiceApplicationSid = voiceApplicationSid; return this; } - public TollFreeCreator setVoiceCallerIdLookup(final Boolean voiceCallerIdLookup){ + + public TollFreeCreator setVoiceCallerIdLookup( + final Boolean voiceCallerIdLookup + ) { this.voiceCallerIdLookup = voiceCallerIdLookup; return this; } - public TollFreeCreator setVoiceFallbackMethod(final HttpMethod voiceFallbackMethod){ + + public TollFreeCreator setVoiceFallbackMethod( + final HttpMethod voiceFallbackMethod + ) { this.voiceFallbackMethod = voiceFallbackMethod; return this; } - public TollFreeCreator setVoiceFallbackUrl(final URI voiceFallbackUrl){ + + public TollFreeCreator setVoiceFallbackUrl(final URI voiceFallbackUrl) { this.voiceFallbackUrl = voiceFallbackUrl; return this; } - public TollFreeCreator setVoiceFallbackUrl(final String voiceFallbackUrl){ + public TollFreeCreator setVoiceFallbackUrl(final String voiceFallbackUrl) { return setVoiceFallbackUrl(Promoter.uriFromString(voiceFallbackUrl)); } - public TollFreeCreator setVoiceMethod(final HttpMethod voiceMethod){ + + public TollFreeCreator setVoiceMethod(final HttpMethod voiceMethod) { this.voiceMethod = voiceMethod; return this; } - public TollFreeCreator setVoiceUrl(final URI voiceUrl){ + + public TollFreeCreator setVoiceUrl(final URI voiceUrl) { this.voiceUrl = voiceUrl; return this; } - public TollFreeCreator setVoiceUrl(final String voiceUrl){ + public TollFreeCreator setVoiceUrl(final String voiceUrl) { return setVoiceUrl(Promoter.uriFromString(voiceUrl)); } - public TollFreeCreator setIdentitySid(final String identitySid){ + + public TollFreeCreator setIdentitySid(final String identitySid) { this.identitySid = identitySid; return this; } - public TollFreeCreator setAddressSid(final String addressSid){ + + public TollFreeCreator setAddressSid(final String addressSid) { this.addressSid = addressSid; return this; } - public TollFreeCreator setEmergencyStatus(final TollFree.EmergencyStatus emergencyStatus){ + + public TollFreeCreator setEmergencyStatus( + final TollFree.EmergencyStatus emergencyStatus + ) { this.emergencyStatus = emergencyStatus; return this; } - public TollFreeCreator setEmergencyAddressSid(final String emergencyAddressSid){ + + public TollFreeCreator setEmergencyAddressSid( + final String emergencyAddressSid + ) { this.emergencyAddressSid = emergencyAddressSid; return this; } - public TollFreeCreator setTrunkSid(final String trunkSid){ + + public TollFreeCreator setTrunkSid(final String trunkSid) { this.trunkSid = trunkSid; return this; } - public TollFreeCreator setVoiceReceiveMode(final TollFree.VoiceReceiveMode voiceReceiveMode){ + + public TollFreeCreator setVoiceReceiveMode( + final TollFree.VoiceReceiveMode voiceReceiveMode + ) { this.voiceReceiveMode = voiceReceiveMode; return this; } - public TollFreeCreator setBundleSid(final String bundleSid){ + + public TollFreeCreator setBundleSid(final String bundleSid) { this.bundleSid = bundleSid; return this; } @Override - public TollFree create(final TwilioRestClient client){ - String path = "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/TollFree.json"; + public TollFree create(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/TollFree.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"PhoneNumber"+"}", this.phoneNumber.encode("utf-8")); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "PhoneNumber" + "}", + this.phoneNumber.encode("utf-8") + ); Request request = new Request( HttpMethod.POST, Domains.API.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("TollFree creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "TollFree creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return TollFree.fromJson(response.getStream(), client.getObjectMapper()); + return TollFree.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (phoneNumber != null) { request.addPostParam("PhoneNumber", phoneNumber.toString()); - } if (apiVersion != null) { request.addPostParam("ApiVersion", apiVersion); - } if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (smsApplicationSid != null) { request.addPostParam("SmsApplicationSid", smsApplicationSid); - } if (smsFallbackMethod != null) { - request.addPostParam("SmsFallbackMethod", smsFallbackMethod.toString()); - + request.addPostParam( + "SmsFallbackMethod", + smsFallbackMethod.toString() + ); } if (smsFallbackUrl != null) { request.addPostParam("SmsFallbackUrl", smsFallbackUrl.toString()); - } if (smsMethod != null) { request.addPostParam("SmsMethod", smsMethod.toString()); - } if (smsUrl != null) { request.addPostParam("SmsUrl", smsUrl.toString()); - } if (statusCallback != null) { request.addPostParam("StatusCallback", statusCallback.toString()); - } if (statusCallbackMethod != null) { - request.addPostParam("StatusCallbackMethod", statusCallbackMethod.toString()); - + request.addPostParam( + "StatusCallbackMethod", + statusCallbackMethod.toString() + ); } if (voiceApplicationSid != null) { request.addPostParam("VoiceApplicationSid", voiceApplicationSid); - } if (voiceCallerIdLookup != null) { - request.addPostParam("VoiceCallerIdLookup", voiceCallerIdLookup.toString()); - + request.addPostParam( + "VoiceCallerIdLookup", + voiceCallerIdLookup.toString() + ); } if (voiceFallbackMethod != null) { - request.addPostParam("VoiceFallbackMethod", voiceFallbackMethod.toString()); - + request.addPostParam( + "VoiceFallbackMethod", + voiceFallbackMethod.toString() + ); } if (voiceFallbackUrl != null) { - request.addPostParam("VoiceFallbackUrl", voiceFallbackUrl.toString()); - + request.addPostParam( + "VoiceFallbackUrl", + voiceFallbackUrl.toString() + ); } if (voiceMethod != null) { request.addPostParam("VoiceMethod", voiceMethod.toString()); - } if (voiceUrl != null) { request.addPostParam("VoiceUrl", voiceUrl.toString()); - } if (identitySid != null) { request.addPostParam("IdentitySid", identitySid); - } if (addressSid != null) { request.addPostParam("AddressSid", addressSid); - } if (emergencyStatus != null) { request.addPostParam("EmergencyStatus", emergencyStatus.toString()); - } if (emergencyAddressSid != null) { request.addPostParam("EmergencyAddressSid", emergencyAddressSid); - } if (trunkSid != null) { request.addPostParam("TrunkSid", trunkSid); - } if (voiceReceiveMode != null) { - request.addPostParam("VoiceReceiveMode", voiceReceiveMode.toString()); - + request.addPostParam( + "VoiceReceiveMode", + voiceReceiveMode.toString() + ); } if (bundleSid != null) { request.addPostParam("BundleSid", bundleSid); - } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/TollFreeReader.java b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/TollFreeReader.java index ac0f2486db..dbc3b2f9db 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/TollFreeReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/TollFreeReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.api.v2010.account.incomingphonenumber; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.converter.Promoter; @@ -25,11 +26,9 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class TollFreeReader extends Reader { + private String pathAccountSid; private Boolean beta; private String friendlyName; @@ -37,33 +36,39 @@ public class TollFreeReader extends Reader { private String origin; private Integer pageSize; - public TollFreeReader(){ - } - public TollFreeReader(final String pathAccountSid){ + public TollFreeReader() {} + + public TollFreeReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - public TollFreeReader setBeta(final Boolean beta){ + public TollFreeReader setBeta(final Boolean beta) { this.beta = beta; return this; } - public TollFreeReader setFriendlyName(final String friendlyName){ + + public TollFreeReader setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public TollFreeReader setPhoneNumber(final com.twilio.type.PhoneNumber phoneNumber){ + + public TollFreeReader setPhoneNumber( + final com.twilio.type.PhoneNumber phoneNumber + ) { this.phoneNumber = phoneNumber; return this; } - public TollFreeReader setPhoneNumber(final String phoneNumber){ + public TollFreeReader setPhoneNumber(final String phoneNumber) { return setPhoneNumber(Promoter.phoneNumberFromString(phoneNumber)); } - public TollFreeReader setOrigin(final String origin){ + + public TollFreeReader setOrigin(final String origin) { this.origin = origin; return this; } - public TollFreeReader setPageSize(final Integer pageSize){ + + public TollFreeReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -74,9 +79,17 @@ public ResourceSet read(final TwilioRestClient client) { } public Page firstPage(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/TollFree.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); + String path = + "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/TollFree.json"; + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -88,13 +101,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("TollFree read failed: Unable to connect to server"); + throw new ApiConnectionException( + "TollFree read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -110,7 +131,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reque } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.API.toString()) @@ -118,9 +142,11 @@ public Page previousPage(final Page page, final TwilioRestCl return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.API.toString()) @@ -129,37 +155,33 @@ public Page nextPage(final Page page, final TwilioRestClient } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (beta != null) { - request.addQueryParam("Beta", beta.toString()); } if (friendlyName != null) { - request.addQueryParam("FriendlyName", friendlyName); } if (phoneNumber != null) { - request.addQueryParam("PhoneNumber", phoneNumber.toString()); } if (origin != null) { - request.addQueryParam("Origin", origin); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/assignedaddon/AssignedAddOnExtension.java b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/assignedaddon/AssignedAddOnExtension.java index eb3ccc4b39..9542116e1e 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/assignedaddon/AssignedAddOnExtension.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/assignedaddon/AssignedAddOnExtension.java @@ -22,45 +22,78 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class AssignedAddOnExtension extends Resource { + private static final long serialVersionUID = 103705040276662L; - public static AssignedAddOnExtensionFetcher fetcher(final String pathResourceSid, final String pathAssignedAddOnSid, final String pathSid){ - return new AssignedAddOnExtensionFetcher(pathResourceSid, pathAssignedAddOnSid, pathSid); + public static AssignedAddOnExtensionFetcher fetcher( + final String pathResourceSid, + final String pathAssignedAddOnSid, + final String pathSid + ) { + return new AssignedAddOnExtensionFetcher( + pathResourceSid, + pathAssignedAddOnSid, + pathSid + ); } - public static AssignedAddOnExtensionFetcher fetcher(final String pathAccountSid, final String pathResourceSid, final String pathAssignedAddOnSid, final String pathSid){ - return new AssignedAddOnExtensionFetcher(pathAccountSid, pathResourceSid, pathAssignedAddOnSid, pathSid); + + public static AssignedAddOnExtensionFetcher fetcher( + final String pathAccountSid, + final String pathResourceSid, + final String pathAssignedAddOnSid, + final String pathSid + ) { + return new AssignedAddOnExtensionFetcher( + pathAccountSid, + pathResourceSid, + pathAssignedAddOnSid, + pathSid + ); } - public static AssignedAddOnExtensionReader reader(final String pathResourceSid, final String pathAssignedAddOnSid){ - return new AssignedAddOnExtensionReader(pathResourceSid, pathAssignedAddOnSid); + public static AssignedAddOnExtensionReader reader( + final String pathResourceSid, + final String pathAssignedAddOnSid + ) { + return new AssignedAddOnExtensionReader( + pathResourceSid, + pathAssignedAddOnSid + ); } - public static AssignedAddOnExtensionReader reader(final String pathAccountSid, final String pathResourceSid, final String pathAssignedAddOnSid){ - return new AssignedAddOnExtensionReader(pathAccountSid, pathResourceSid, pathAssignedAddOnSid); + + public static AssignedAddOnExtensionReader reader( + final String pathAccountSid, + final String pathResourceSid, + final String pathAssignedAddOnSid + ) { + return new AssignedAddOnExtensionReader( + pathAccountSid, + pathResourceSid, + pathAssignedAddOnSid + ); } /** - * Converts a JSON String into a AssignedAddOnExtension object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return AssignedAddOnExtension object represented by the provided JSON - */ - public static AssignedAddOnExtension fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a AssignedAddOnExtension object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return AssignedAddOnExtension object represented by the provided JSON + */ + public static AssignedAddOnExtension fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, AssignedAddOnExtension.class); @@ -72,14 +105,17 @@ public static AssignedAddOnExtension fromJson(final String json, final ObjectMap } /** - * Converts a JSON InputStream into a AssignedAddOnExtension object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return AssignedAddOnExtension object represented by the provided JSON - */ - public static AssignedAddOnExtension fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a AssignedAddOnExtension object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return AssignedAddOnExtension object represented by the provided JSON + */ + public static AssignedAddOnExtension fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, AssignedAddOnExtension.class); @@ -102,32 +138,15 @@ public static AssignedAddOnExtension fromJson(final InputStream json, final Obje @JsonCreator private AssignedAddOnExtension( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("resource_sid") - final String resourceSid, - - @JsonProperty("assigned_add_on_sid") - final String assignedAddOnSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("product_name") - final String productName, - - @JsonProperty("unique_name") - final String uniqueName, - - @JsonProperty("uri") - final String uri, - - @JsonProperty("enabled") - final Boolean enabled + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("resource_sid") final String resourceSid, + @JsonProperty("assigned_add_on_sid") final String assignedAddOnSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("product_name") final String productName, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("uri") final String uri, + @JsonProperty("enabled") final Boolean enabled ) { this.sid = sid; this.accountSid = accountSid; @@ -140,37 +159,45 @@ private AssignedAddOnExtension( this.enabled = enabled; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getResourceSid() { - return this.resourceSid; - } - public final String getAssignedAddOnSid() { - return this.assignedAddOnSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getProductName() { - return this.productName; - } - public final String getUniqueName() { - return this.uniqueName; - } - public final String getUri() { - return this.uri; - } - public final Boolean getEnabled() { - return this.enabled; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getResourceSid() { + return this.resourceSid; + } + + public final String getAssignedAddOnSid() { + return this.assignedAddOnSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getProductName() { + return this.productName; + } + + public final String getUniqueName() { + return this.uniqueName; + } + + public final String getUri() { + return this.uri; + } + + public final Boolean getEnabled() { + return this.enabled; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -180,13 +207,31 @@ public boolean equals(final Object o) { AssignedAddOnExtension other = (AssignedAddOnExtension) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(resourceSid, other.resourceSid) && Objects.equals(assignedAddOnSid, other.assignedAddOnSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(productName, other.productName) && Objects.equals(uniqueName, other.uniqueName) && Objects.equals(uri, other.uri) && Objects.equals(enabled, other.enabled) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(resourceSid, other.resourceSid) && + Objects.equals(assignedAddOnSid, other.assignedAddOnSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(productName, other.productName) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(uri, other.uri) && + Objects.equals(enabled, other.enabled) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, resourceSid, assignedAddOnSid, friendlyName, productName, uniqueName, uri, enabled); + return Objects.hash( + sid, + accountSid, + resourceSid, + assignedAddOnSid, + friendlyName, + productName, + uniqueName, + uri, + enabled + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/assignedaddon/AssignedAddOnExtensionFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/assignedaddon/AssignedAddOnExtensionFetcher.java index 70b06a1afc..9ea2e83c28 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/assignedaddon/AssignedAddOnExtensionFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/assignedaddon/AssignedAddOnExtensionFetcher.java @@ -24,37 +24,61 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class AssignedAddOnExtensionFetcher + extends Fetcher { - - -public class AssignedAddOnExtensionFetcher extends Fetcher { private String pathResourceSid; private String pathAssignedAddOnSid; private String pathSid; private String pathAccountSid; - public AssignedAddOnExtensionFetcher(final String pathResourceSid, final String pathAssignedAddOnSid, final String pathSid){ + public AssignedAddOnExtensionFetcher( + final String pathResourceSid, + final String pathAssignedAddOnSid, + final String pathSid + ) { this.pathResourceSid = pathResourceSid; this.pathAssignedAddOnSid = pathAssignedAddOnSid; this.pathSid = pathSid; } - public AssignedAddOnExtensionFetcher(final String pathAccountSid, final String pathResourceSid, final String pathAssignedAddOnSid, final String pathSid){ + + public AssignedAddOnExtensionFetcher( + final String pathAccountSid, + final String pathResourceSid, + final String pathAssignedAddOnSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathResourceSid = pathResourceSid; this.pathAssignedAddOnSid = pathAssignedAddOnSid; this.pathSid = pathSid; } - @Override public AssignedAddOnExtension fetch(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{ResourceSid}/AssignedAddOns/{AssignedAddOnSid}/Extensions/{Sid}.json"; + String path = + "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{ResourceSid}/AssignedAddOns/{AssignedAddOnSid}/Extensions/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"ResourceSid"+"}", this.pathResourceSid.toString()); - path = path.replace("{"+"AssignedAddOnSid"+"}", this.pathAssignedAddOnSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "ResourceSid" + "}", + this.pathResourceSid.toString() + ); + path = + path.replace( + "{" + "AssignedAddOnSid" + "}", + this.pathAssignedAddOnSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -64,15 +88,23 @@ public AssignedAddOnExtension fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AssignedAddOnExtension fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "AssignedAddOnExtension fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return AssignedAddOnExtension.fromJson(response.getStream(), client.getObjectMapper()); + return AssignedAddOnExtension.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/assignedaddon/AssignedAddOnExtensionReader.java b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/assignedaddon/AssignedAddOnExtensionReader.java index 871b8a1524..fb8dda0530 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/assignedaddon/AssignedAddOnExtensionReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/assignedaddon/AssignedAddOnExtensionReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.api.v2010.account.incomingphonenumber.assignedaddon; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,42 +25,69 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - +public class AssignedAddOnExtensionReader + extends Reader { -public class AssignedAddOnExtensionReader extends Reader { private String pathResourceSid; private String pathAssignedAddOnSid; private String pathAccountSid; private Integer pageSize; - public AssignedAddOnExtensionReader(final String pathResourceSid, final String pathAssignedAddOnSid){ + public AssignedAddOnExtensionReader( + final String pathResourceSid, + final String pathAssignedAddOnSid + ) { this.pathResourceSid = pathResourceSid; this.pathAssignedAddOnSid = pathAssignedAddOnSid; } - public AssignedAddOnExtensionReader(final String pathAccountSid, final String pathResourceSid, final String pathAssignedAddOnSid){ + + public AssignedAddOnExtensionReader( + final String pathAccountSid, + final String pathResourceSid, + final String pathAssignedAddOnSid + ) { this.pathAccountSid = pathAccountSid; this.pathResourceSid = pathResourceSid; this.pathAssignedAddOnSid = pathAssignedAddOnSid; } - public AssignedAddOnExtensionReader setPageSize(final Integer pageSize){ + public AssignedAddOnExtensionReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @Override - public ResourceSet read(final TwilioRestClient client) { + public ResourceSet read( + final TwilioRestClient client + ) { return new ResourceSet<>(this, client, firstPage(client)); } - public Page firstPage(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{ResourceSid}/AssignedAddOns/{AssignedAddOnSid}/Extensions.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"ResourceSid"+"}", this.pathResourceSid.toString()); - path = path.replace("{"+"AssignedAddOnSid"+"}", this.pathAssignedAddOnSid.toString()); + public Page firstPage( + final TwilioRestClient client + ) { + String path = + "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{ResourceSid}/AssignedAddOns/{AssignedAddOnSid}/Extensions.json"; + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "ResourceSid" + "}", + this.pathResourceSid.toString() + ); + path = + path.replace( + "{" + "AssignedAddOnSid" + "}", + this.pathAssignedAddOnSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -71,13 +99,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AssignedAddOnExtension read failed: Unable to connect to server"); + throw new ApiConnectionException( + "AssignedAddOnExtension read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -93,7 +129,10 @@ private Page pageForRequest(final TwilioRestClient clien } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.API.toString()) @@ -101,9 +140,11 @@ public Page previousPage(final Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.API.toString()) @@ -112,21 +153,21 @@ public Page nextPage(final Page } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/message/Feedback.java b/src/main/java/com/twilio/rest/api/v2010/account/message/Feedback.java index 558dce1023..3245dbe815 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/message/Feedback.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/message/Feedback.java @@ -24,39 +24,42 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Feedback extends Resource { + private static final long serialVersionUID = 229414222116486L; - public static FeedbackCreator creator(final String pathMessageSid){ + public static FeedbackCreator creator(final String pathMessageSid) { return new FeedbackCreator(pathMessageSid); } - public static FeedbackCreator creator(final String pathAccountSid, final String pathMessageSid){ + + public static FeedbackCreator creator( + final String pathAccountSid, + final String pathMessageSid + ) { return new FeedbackCreator(pathAccountSid, pathMessageSid); } /** - * Converts a JSON String into a Feedback object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Feedback object represented by the provided JSON - */ - public static Feedback fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Feedback object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Feedback object represented by the provided JSON + */ + public static Feedback fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Feedback.class); @@ -68,14 +71,17 @@ public static Feedback fromJson(final String json, final ObjectMapper objectMapp } /** - * Converts a JSON InputStream into a Feedback object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Feedback object represented by the provided JSON - */ - public static Feedback fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Feedback object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Feedback object represented by the provided JSON + */ + public static Feedback fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Feedback.class); @@ -85,6 +91,7 @@ public static Feedback fromJson(final InputStream json, final ObjectMapper objec throw new ApiConnectionException(e.getMessage(), e); } } + public enum Outcome { CONFIRMED("confirmed"), UNCONFIRMED("unconfirmed"); @@ -114,23 +121,12 @@ public static Outcome forValue(final String value) { @JsonCreator private Feedback( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("message_sid") - final String messageSid, - - @JsonProperty("outcome") - final Feedback.Outcome outcome, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("uri") - final String uri + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("message_sid") final String messageSid, + @JsonProperty("outcome") final Feedback.Outcome outcome, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("uri") final String uri ) { this.accountSid = accountSid; this.messageSid = messageSid; @@ -140,28 +136,33 @@ private Feedback( this.uri = uri; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getMessageSid() { - return this.messageSid; - } - public final Feedback.Outcome getOutcome() { - return this.outcome; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getUri() { - return this.uri; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getMessageSid() { + return this.messageSid; + } + + public final Feedback.Outcome getOutcome() { + return this.outcome; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getUri() { + return this.uri; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -171,13 +172,25 @@ public boolean equals(final Object o) { Feedback other = (Feedback) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(messageSid, other.messageSid) && Objects.equals(outcome, other.outcome) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(uri, other.uri) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(messageSid, other.messageSid) && + Objects.equals(outcome, other.outcome) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(uri, other.uri) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, messageSid, outcome, dateCreated, dateUpdated, uri); + return Objects.hash( + accountSid, + messageSid, + outcome, + dateCreated, + dateUpdated, + uri + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/message/FeedbackCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/message/FeedbackCreator.java index 69804a1382..9c6bb4e62e 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/message/FeedbackCreator.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/message/FeedbackCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010.account.message; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class FeedbackCreator extends Creator { - - -public class FeedbackCreator extends Creator{ private String pathMessageSid; private String pathAccountSid; private Feedback.Outcome outcome; @@ -35,47 +34,72 @@ public class FeedbackCreator extends Creator{ public FeedbackCreator(final String pathMessageSid) { this.pathMessageSid = pathMessageSid; } - public FeedbackCreator(final String pathAccountSid, final String pathMessageSid) { + + public FeedbackCreator( + final String pathAccountSid, + final String pathMessageSid + ) { this.pathAccountSid = pathAccountSid; this.pathMessageSid = pathMessageSid; } - public FeedbackCreator setOutcome(final Feedback.Outcome outcome){ + public FeedbackCreator setOutcome(final Feedback.Outcome outcome) { this.outcome = outcome; return this; } @Override - public Feedback create(final TwilioRestClient client){ - String path = "/2010-04-01/Accounts/{AccountSid}/Messages/{MessageSid}/Feedback.json"; + public Feedback create(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Messages/{MessageSid}/Feedback.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"MessageSid"+"}", this.pathMessageSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "MessageSid" + "}", + this.pathMessageSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.API.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Feedback creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Feedback creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Feedback.fromJson(response.getStream(), client.getObjectMapper()); + return Feedback.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (outcome != null) { request.addPostParam("Outcome", outcome.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/message/Media.java b/src/main/java/com/twilio/rest/api/v2010/account/message/Media.java index cd1c9db361..05da369ce0 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/message/Media.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/message/Media.java @@ -23,53 +23,72 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Media extends Resource { + private static final long serialVersionUID = 86856561367712L; - public static MediaDeleter deleter(final String pathMessageSid, final String pathSid){ + public static MediaDeleter deleter( + final String pathMessageSid, + final String pathSid + ) { return new MediaDeleter(pathMessageSid, pathSid); } - public static MediaDeleter deleter(final String pathAccountSid, final String pathMessageSid, final String pathSid){ + + public static MediaDeleter deleter( + final String pathAccountSid, + final String pathMessageSid, + final String pathSid + ) { return new MediaDeleter(pathAccountSid, pathMessageSid, pathSid); } - public static MediaFetcher fetcher(final String pathMessageSid, final String pathSid){ + public static MediaFetcher fetcher( + final String pathMessageSid, + final String pathSid + ) { return new MediaFetcher(pathMessageSid, pathSid); } - public static MediaFetcher fetcher(final String pathAccountSid, final String pathMessageSid, final String pathSid){ + + public static MediaFetcher fetcher( + final String pathAccountSid, + final String pathMessageSid, + final String pathSid + ) { return new MediaFetcher(pathAccountSid, pathMessageSid, pathSid); } - public static MediaReader reader(final String pathMessageSid){ + public static MediaReader reader(final String pathMessageSid) { return new MediaReader(pathMessageSid); } - public static MediaReader reader(final String pathAccountSid, final String pathMessageSid){ + + public static MediaReader reader( + final String pathAccountSid, + final String pathMessageSid + ) { return new MediaReader(pathAccountSid, pathMessageSid); } /** - * Converts a JSON String into a Media object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Media object represented by the provided JSON - */ - public static Media fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Media object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Media object represented by the provided JSON + */ + public static Media fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Media.class); @@ -81,14 +100,17 @@ public static Media fromJson(final String json, final ObjectMapper objectMapper) } /** - * Converts a JSON InputStream into a Media object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Media object represented by the provided JSON - */ - public static Media fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Media object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Media object represented by the provided JSON + */ + public static Media fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Media.class); @@ -109,26 +131,13 @@ public static Media fromJson(final InputStream json, final ObjectMapper objectMa @JsonCreator private Media( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("content_type") - final String contentType, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("parent_sid") - final String parentSid, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("uri") - final String uri + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("content_type") final String contentType, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("parent_sid") final String parentSid, + @JsonProperty("sid") final String sid, + @JsonProperty("uri") final String uri ) { this.accountSid = accountSid; this.contentType = contentType; @@ -139,31 +148,37 @@ private Media( this.uri = uri; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getContentType() { - return this.contentType; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getParentSid() { - return this.parentSid; - } - public final String getSid() { - return this.sid; - } - public final String getUri() { - return this.uri; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getContentType() { + return this.contentType; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getParentSid() { + return this.parentSid; + } + + public final String getSid() { + return this.sid; + } + + public final String getUri() { + return this.uri; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -173,13 +188,27 @@ public boolean equals(final Object o) { Media other = (Media) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(contentType, other.contentType) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(parentSid, other.parentSid) && Objects.equals(sid, other.sid) && Objects.equals(uri, other.uri) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(contentType, other.contentType) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(parentSid, other.parentSid) && + Objects.equals(sid, other.sid) && + Objects.equals(uri, other.uri) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, contentType, dateCreated, dateUpdated, parentSid, sid, uri); + return Objects.hash( + accountSid, + contentType, + dateCreated, + dateUpdated, + parentSid, + sid, + uri + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/message/MediaDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/message/MediaDeleter.java index 24581ae0dd..90ebb93dcb 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/message/MediaDeleter.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/message/MediaDeleter.java @@ -24,32 +24,47 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class MediaDeleter extends Deleter { + private String pathMessageSid; private String pathSid; private String pathAccountSid; - public MediaDeleter(final String pathMessageSid, final String pathSid){ + public MediaDeleter(final String pathMessageSid, final String pathSid) { this.pathMessageSid = pathMessageSid; this.pathSid = pathSid; } - public MediaDeleter(final String pathAccountSid, final String pathMessageSid, final String pathSid){ + + public MediaDeleter( + final String pathAccountSid, + final String pathMessageSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathMessageSid = pathMessageSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/Messages/{MessageSid}/Media/{Sid}.json"; + String path = + "/2010-04-01/Accounts/{AccountSid}/Messages/{MessageSid}/Media/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"MessageSid"+"}", this.pathMessageSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "MessageSid" + "}", + this.pathMessageSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -59,9 +74,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Media delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Media delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/message/MediaFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/message/MediaFetcher.java index 1a020cef98..7eccccba82 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/message/MediaFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/message/MediaFetcher.java @@ -24,33 +24,47 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class MediaFetcher extends Fetcher { + private String pathMessageSid; private String pathSid; private String pathAccountSid; - public MediaFetcher(final String pathMessageSid, final String pathSid){ + public MediaFetcher(final String pathMessageSid, final String pathSid) { this.pathMessageSid = pathMessageSid; this.pathSid = pathSid; } - public MediaFetcher(final String pathAccountSid, final String pathMessageSid, final String pathSid){ + + public MediaFetcher( + final String pathAccountSid, + final String pathMessageSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathMessageSid = pathMessageSid; this.pathSid = pathSid; } - @Override public Media fetch(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/Messages/{MessageSid}/Media/{Sid}.json"; + String path = + "/2010-04-01/Accounts/{AccountSid}/Messages/{MessageSid}/Media/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"MessageSid"+"}", this.pathMessageSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "MessageSid" + "}", + this.pathMessageSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -60,9 +74,14 @@ public Media fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Media fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Media fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/message/MediaReader.java b/src/main/java/com/twilio/rest/api/v2010/account/message/MediaReader.java index 636f88097b..4e3af77f1d 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/message/MediaReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/message/MediaReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.api.v2010.account.message; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,13 +25,11 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; - - public class MediaReader extends Reader { + private String pathMessageSid; private String pathAccountSid; private ZonedDateTime dateCreated; @@ -38,27 +37,38 @@ public class MediaReader extends Reader { private ZonedDateTime dateCreatedAfter; private Integer pageSize; - public MediaReader(final String pathMessageSid){ + public MediaReader(final String pathMessageSid) { this.pathMessageSid = pathMessageSid; } - public MediaReader(final String pathAccountSid, final String pathMessageSid){ + + public MediaReader( + final String pathAccountSid, + final String pathMessageSid + ) { this.pathAccountSid = pathAccountSid; this.pathMessageSid = pathMessageSid; } - public MediaReader setDateCreated(final ZonedDateTime dateCreated){ + public MediaReader setDateCreated(final ZonedDateTime dateCreated) { this.dateCreated = dateCreated; return this; } - public MediaReader setDateCreatedBefore(final ZonedDateTime dateCreatedBefore){ + + public MediaReader setDateCreatedBefore( + final ZonedDateTime dateCreatedBefore + ) { this.dateCreatedBefore = dateCreatedBefore; return this; } - public MediaReader setDateCreatedAfter(final ZonedDateTime dateCreatedAfter){ + + public MediaReader setDateCreatedAfter( + final ZonedDateTime dateCreatedAfter + ) { this.dateCreatedAfter = dateCreatedAfter; return this; } - public MediaReader setPageSize(final Integer pageSize){ + + public MediaReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -69,10 +79,22 @@ public ResourceSet read(final TwilioRestClient client) { } public Page firstPage(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/Messages/{MessageSid}/Media.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"MessageSid"+"}", this.pathMessageSid.toString()); + String path = + "/2010-04-01/Accounts/{AccountSid}/Messages/{MessageSid}/Media.json"; + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "MessageSid" + "}", + this.pathMessageSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -84,13 +106,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Media read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Media read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -106,7 +136,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.API.toString()) @@ -114,9 +147,11 @@ public Page previousPage(final Page page, final TwilioRestClient c return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.API.toString()) @@ -125,27 +160,37 @@ public Page nextPage(final Page page, final TwilioRestClient clien } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (dateCreated != null) { - request.addQueryParam("DateCreated", dateCreated.format(DateTimeFormatter.ofPattern(Request.QUERY_STRING_DATE_TIME_FORMAT))); - } - else if (dateCreatedAfter != null || dateCreatedBefore != null) { - request.addQueryDateTimeRange("DateCreated", dateCreatedAfter, dateCreatedBefore); + request.addQueryParam( + "DateCreated", + dateCreated.format( + DateTimeFormatter.ofPattern( + Request.QUERY_STRING_DATE_TIME_FORMAT + ) + ) + ); + } else if (dateCreatedAfter != null || dateCreatedBefore != null) { + request.addQueryDateTimeRange( + "DateCreated", + dateCreatedAfter, + dateCreatedBefore + ); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/queue/Member.java b/src/main/java/com/twilio/rest/api/v2010/account/queue/Member.java index 0a89da040e..9ce1680c73 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/queue/Member.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/queue/Member.java @@ -23,54 +23,80 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Member extends Resource { + private static final long serialVersionUID = 196464556782918L; - public static MemberFetcher fetcher(final String pathQueueSid, final String pathCallSid){ + public static MemberFetcher fetcher( + final String pathQueueSid, + final String pathCallSid + ) { return new MemberFetcher(pathQueueSid, pathCallSid); } - public static MemberFetcher fetcher(final String pathAccountSid, final String pathQueueSid, final String pathCallSid){ + + public static MemberFetcher fetcher( + final String pathAccountSid, + final String pathQueueSid, + final String pathCallSid + ) { return new MemberFetcher(pathAccountSid, pathQueueSid, pathCallSid); } - public static MemberReader reader(final String pathQueueSid){ + public static MemberReader reader(final String pathQueueSid) { return new MemberReader(pathQueueSid); } - public static MemberReader reader(final String pathAccountSid, final String pathQueueSid){ + + public static MemberReader reader( + final String pathAccountSid, + final String pathQueueSid + ) { return new MemberReader(pathAccountSid, pathQueueSid); } - public static MemberUpdater updater(final String pathQueueSid, final String pathCallSid, final URI url){ + public static MemberUpdater updater( + final String pathQueueSid, + final String pathCallSid, + final URI url + ) { return new MemberUpdater(pathQueueSid, pathCallSid, url); } - public static MemberUpdater updater(final String pathAccountSid, final String pathQueueSid, final String pathCallSid, final URI url){ - return new MemberUpdater(pathAccountSid, pathQueueSid, pathCallSid, url); + + public static MemberUpdater updater( + final String pathAccountSid, + final String pathQueueSid, + final String pathCallSid, + final URI url + ) { + return new MemberUpdater( + pathAccountSid, + pathQueueSid, + pathCallSid, + url + ); } /** - * Converts a JSON String into a Member object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Member object represented by the provided JSON - */ - public static Member fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Member object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Member object represented by the provided JSON + */ + public static Member fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Member.class); @@ -82,14 +108,17 @@ public static Member fromJson(final String json, final ObjectMapper objectMapper } /** - * Converts a JSON InputStream into a Member object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Member object represented by the provided JSON - */ - public static Member fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Member object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Member object represented by the provided JSON + */ + public static Member fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Member.class); @@ -109,54 +138,49 @@ public static Member fromJson(final InputStream json, final ObjectMapper objectM @JsonCreator private Member( - @JsonProperty("call_sid") - final String callSid, - - @JsonProperty("date_enqueued") - final String dateEnqueued, - - @JsonProperty("position") - final Integer position, - - @JsonProperty("uri") - final String uri, - - @JsonProperty("wait_time") - final Integer waitTime, - - @JsonProperty("queue_sid") - final String queueSid + @JsonProperty("call_sid") final String callSid, + @JsonProperty("date_enqueued") final String dateEnqueued, + @JsonProperty("position") final Integer position, + @JsonProperty("uri") final String uri, + @JsonProperty("wait_time") final Integer waitTime, + @JsonProperty("queue_sid") final String queueSid ) { this.callSid = callSid; - this.dateEnqueued = DateConverter.rfc2822DateTimeFromString(dateEnqueued); + this.dateEnqueued = + DateConverter.rfc2822DateTimeFromString(dateEnqueued); this.position = position; this.uri = uri; this.waitTime = waitTime; this.queueSid = queueSid; } - public final String getCallSid() { - return this.callSid; - } - public final ZonedDateTime getDateEnqueued() { - return this.dateEnqueued; - } - public final Integer getPosition() { - return this.position; - } - public final String getUri() { - return this.uri; - } - public final Integer getWaitTime() { - return this.waitTime; - } - public final String getQueueSid() { - return this.queueSid; - } + public final String getCallSid() { + return this.callSid; + } + + public final ZonedDateTime getDateEnqueued() { + return this.dateEnqueued; + } + + public final Integer getPosition() { + return this.position; + } + + public final String getUri() { + return this.uri; + } + + public final Integer getWaitTime() { + return this.waitTime; + } + + public final String getQueueSid() { + return this.queueSid; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -166,13 +190,25 @@ public boolean equals(final Object o) { Member other = (Member) o; - return Objects.equals(callSid, other.callSid) && Objects.equals(dateEnqueued, other.dateEnqueued) && Objects.equals(position, other.position) && Objects.equals(uri, other.uri) && Objects.equals(waitTime, other.waitTime) && Objects.equals(queueSid, other.queueSid) ; + return ( + Objects.equals(callSid, other.callSid) && + Objects.equals(dateEnqueued, other.dateEnqueued) && + Objects.equals(position, other.position) && + Objects.equals(uri, other.uri) && + Objects.equals(waitTime, other.waitTime) && + Objects.equals(queueSid, other.queueSid) + ); } @Override public int hashCode() { - return Objects.hash(callSid, dateEnqueued, position, uri, waitTime, queueSid); + return Objects.hash( + callSid, + dateEnqueued, + position, + uri, + waitTime, + queueSid + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/queue/MemberFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/queue/MemberFetcher.java index 6f807cac83..f338882ec6 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/queue/MemberFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/queue/MemberFetcher.java @@ -24,33 +24,44 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class MemberFetcher extends Fetcher { + private String pathQueueSid; private String pathCallSid; private String pathAccountSid; - public MemberFetcher(final String pathQueueSid, final String pathCallSid){ + public MemberFetcher(final String pathQueueSid, final String pathCallSid) { this.pathQueueSid = pathQueueSid; this.pathCallSid = pathCallSid; } - public MemberFetcher(final String pathAccountSid, final String pathQueueSid, final String pathCallSid){ + + public MemberFetcher( + final String pathAccountSid, + final String pathQueueSid, + final String pathCallSid + ) { this.pathAccountSid = pathAccountSid; this.pathQueueSid = pathQueueSid; this.pathCallSid = pathCallSid; } - @Override public Member fetch(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/Queues/{QueueSid}/Members/{CallSid}.json"; + String path = + "/2010-04-01/Accounts/{AccountSid}/Queues/{QueueSid}/Members/{CallSid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"QueueSid"+"}", this.pathQueueSid.toString()); - path = path.replace("{"+"CallSid"+"}", this.pathCallSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace("{" + "QueueSid" + "}", this.pathQueueSid.toString()); + path = path.replace("{" + "CallSid" + "}", this.pathCallSid.toString()); Request request = new Request( HttpMethod.GET, @@ -60,9 +71,14 @@ public Member fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Member fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Member fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/queue/MemberReader.java b/src/main/java/com/twilio/rest/api/v2010/account/queue/MemberReader.java index 7feee6f8bb..1abbb45cd5 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/queue/MemberReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/queue/MemberReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.api.v2010.account.queue; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,24 +25,26 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class MemberReader extends Reader { + private String pathQueueSid; private String pathAccountSid; private Integer pageSize; - public MemberReader(final String pathQueueSid){ + public MemberReader(final String pathQueueSid) { this.pathQueueSid = pathQueueSid; } - public MemberReader(final String pathAccountSid, final String pathQueueSid){ + + public MemberReader( + final String pathAccountSid, + final String pathQueueSid + ) { this.pathAccountSid = pathAccountSid; this.pathQueueSid = pathQueueSid; } - public MemberReader setPageSize(final Integer pageSize){ + public MemberReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -52,10 +55,19 @@ public ResourceSet read(final TwilioRestClient client) { } public Page firstPage(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/Queues/{QueueSid}/Members.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"QueueSid"+"}", this.pathQueueSid.toString()); + String path = + "/2010-04-01/Accounts/{AccountSid}/Queues/{QueueSid}/Members.json"; + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace("{" + "QueueSid" + "}", this.pathQueueSid.toString()); Request request = new Request( HttpMethod.GET, @@ -67,13 +79,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Member read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Member read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -89,7 +109,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.API.toString()) @@ -97,9 +120,11 @@ public Page previousPage(final Page page, final TwilioRestClient return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.API.toString()) @@ -108,21 +133,21 @@ public Page nextPage(final Page page, final TwilioRestClient cli } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/queue/MemberUpdater.java b/src/main/java/com/twilio/rest/api/v2010/account/queue/MemberUpdater.java index b17ce94c08..51084d5c7e 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/queue/MemberUpdater.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/queue/MemberUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010.account.queue; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -24,64 +25,88 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.net.URI; +public class MemberUpdater extends Updater { - -public class MemberUpdater extends Updater{ private String pathQueueSid; private String pathCallSid; private URI url; private String pathAccountSid; private HttpMethod method; - public MemberUpdater(final String pathQueueSid, final String pathCallSid, final URI url){ + public MemberUpdater( + final String pathQueueSid, + final String pathCallSid, + final URI url + ) { this.pathQueueSid = pathQueueSid; this.pathCallSid = pathCallSid; this.url = url; } - public MemberUpdater(final String pathAccountSid, final String pathQueueSid, final String pathCallSid, final URI url){ + + public MemberUpdater( + final String pathAccountSid, + final String pathQueueSid, + final String pathCallSid, + final URI url + ) { this.pathAccountSid = pathAccountSid; this.pathQueueSid = pathQueueSid; this.pathCallSid = pathCallSid; this.url = url; } - public MemberUpdater setUrl(final URI url){ + public MemberUpdater setUrl(final URI url) { this.url = url; return this; } - public MemberUpdater setUrl(final String url){ + public MemberUpdater setUrl(final String url) { return setUrl(Promoter.uriFromString(url)); } - public MemberUpdater setMethod(final HttpMethod method){ + + public MemberUpdater setMethod(final HttpMethod method) { this.method = method; return this; } @Override - public Member update(final TwilioRestClient client){ - String path = "/2010-04-01/Accounts/{AccountSid}/Queues/{QueueSid}/Members/{CallSid}.json"; + public Member update(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Queues/{QueueSid}/Members/{CallSid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"QueueSid"+"}", this.pathQueueSid.toString()); - path = path.replace("{"+"CallSid"+"}", this.pathCallSid.toString()); - path = path.replace("{"+"Url"+"}", this.url.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace("{" + "QueueSid" + "}", this.pathQueueSid.toString()); + path = path.replace("{" + "CallSid" + "}", this.pathCallSid.toString()); + path = path.replace("{" + "Url" + "}", this.url.toString()); Request request = new Request( HttpMethod.POST, Domains.API.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Member update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Member update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -90,14 +115,13 @@ public Member update(final TwilioRestClient client){ return Member.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (url != null) { request.addPostParam("Url", url.toString()); - } if (method != null) { request.addPostParam("Method", method.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/recording/AddOnResult.java b/src/main/java/com/twilio/rest/api/v2010/account/recording/AddOnResult.java index 9f7229f46b..2893545545 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/recording/AddOnResult.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/recording/AddOnResult.java @@ -24,55 +24,82 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class AddOnResult extends Resource { + private static final long serialVersionUID = 121199532836736L; - public static AddOnResultDeleter deleter(final String pathReferenceSid, final String pathSid){ + public static AddOnResultDeleter deleter( + final String pathReferenceSid, + final String pathSid + ) { return new AddOnResultDeleter(pathReferenceSid, pathSid); } - public static AddOnResultDeleter deleter(final String pathAccountSid, final String pathReferenceSid, final String pathSid){ - return new AddOnResultDeleter(pathAccountSid, pathReferenceSid, pathSid); + + public static AddOnResultDeleter deleter( + final String pathAccountSid, + final String pathReferenceSid, + final String pathSid + ) { + return new AddOnResultDeleter( + pathAccountSid, + pathReferenceSid, + pathSid + ); } - public static AddOnResultFetcher fetcher(final String pathReferenceSid, final String pathSid){ + public static AddOnResultFetcher fetcher( + final String pathReferenceSid, + final String pathSid + ) { return new AddOnResultFetcher(pathReferenceSid, pathSid); } - public static AddOnResultFetcher fetcher(final String pathAccountSid, final String pathReferenceSid, final String pathSid){ - return new AddOnResultFetcher(pathAccountSid, pathReferenceSid, pathSid); + + public static AddOnResultFetcher fetcher( + final String pathAccountSid, + final String pathReferenceSid, + final String pathSid + ) { + return new AddOnResultFetcher( + pathAccountSid, + pathReferenceSid, + pathSid + ); } - public static AddOnResultReader reader(final String pathReferenceSid){ + public static AddOnResultReader reader(final String pathReferenceSid) { return new AddOnResultReader(pathReferenceSid); } - public static AddOnResultReader reader(final String pathAccountSid, final String pathReferenceSid){ + + public static AddOnResultReader reader( + final String pathAccountSid, + final String pathReferenceSid + ) { return new AddOnResultReader(pathAccountSid, pathReferenceSid); } /** - * Converts a JSON String into a AddOnResult object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return AddOnResult object represented by the provided JSON - */ - public static AddOnResult fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a AddOnResult object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return AddOnResult object represented by the provided JSON + */ + public static AddOnResult fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, AddOnResult.class); @@ -84,14 +111,17 @@ public static AddOnResult fromJson(final String json, final ObjectMapper objectM } /** - * Converts a JSON InputStream into a AddOnResult object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return AddOnResult object represented by the provided JSON - */ - public static AddOnResult fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a AddOnResult object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return AddOnResult object represented by the provided JSON + */ + public static AddOnResult fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, AddOnResult.class); @@ -101,6 +131,7 @@ public static AddOnResult fromJson(final InputStream json, final ObjectMapper ob throw new ApiConnectionException(e.getMessage(), e); } } + public enum Status { CANCELED("canceled"), COMPLETED("completed"), @@ -140,35 +171,20 @@ public static Status forValue(final String value) { @JsonCreator private AddOnResult( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("status") - final AddOnResult.Status status, - - @JsonProperty("add_on_sid") - final String addOnSid, - - @JsonProperty("add_on_configuration_sid") - final String addOnConfigurationSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("date_completed") - final String dateCompleted, - - @JsonProperty("reference_sid") - final String referenceSid, - - @JsonProperty("subresource_uris") - final Map subresourceUris + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("status") final AddOnResult.Status status, + @JsonProperty("add_on_sid") final String addOnSid, + @JsonProperty( + "add_on_configuration_sid" + ) final String addOnConfigurationSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("date_completed") final String dateCompleted, + @JsonProperty("reference_sid") final String referenceSid, + @JsonProperty( + "subresource_uris" + ) final Map subresourceUris ) { this.sid = sid; this.accountSid = accountSid; @@ -177,45 +193,55 @@ private AddOnResult( this.addOnConfigurationSid = addOnConfigurationSid; this.dateCreated = DateConverter.rfc2822DateTimeFromString(dateCreated); this.dateUpdated = DateConverter.rfc2822DateTimeFromString(dateUpdated); - this.dateCompleted = DateConverter.rfc2822DateTimeFromString(dateCompleted); + this.dateCompleted = + DateConverter.rfc2822DateTimeFromString(dateCompleted); this.referenceSid = referenceSid; this.subresourceUris = subresourceUris; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final AddOnResult.Status getStatus() { - return this.status; - } - public final String getAddOnSid() { - return this.addOnSid; - } - public final String getAddOnConfigurationSid() { - return this.addOnConfigurationSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final ZonedDateTime getDateCompleted() { - return this.dateCompleted; - } - public final String getReferenceSid() { - return this.referenceSid; - } - public final Map getSubresourceUris() { - return this.subresourceUris; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final AddOnResult.Status getStatus() { + return this.status; + } + + public final String getAddOnSid() { + return this.addOnSid; + } + + public final String getAddOnConfigurationSid() { + return this.addOnConfigurationSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final ZonedDateTime getDateCompleted() { + return this.dateCompleted; + } + + public final String getReferenceSid() { + return this.referenceSid; + } + + public final Map getSubresourceUris() { + return this.subresourceUris; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -225,13 +251,36 @@ public boolean equals(final Object o) { AddOnResult other = (AddOnResult) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(status, other.status) && Objects.equals(addOnSid, other.addOnSid) && Objects.equals(addOnConfigurationSid, other.addOnConfigurationSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(dateCompleted, other.dateCompleted) && Objects.equals(referenceSid, other.referenceSid) && Objects.equals(subresourceUris, other.subresourceUris) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(status, other.status) && + Objects.equals(addOnSid, other.addOnSid) && + Objects.equals( + addOnConfigurationSid, + other.addOnConfigurationSid + ) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(dateCompleted, other.dateCompleted) && + Objects.equals(referenceSid, other.referenceSid) && + Objects.equals(subresourceUris, other.subresourceUris) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, status, addOnSid, addOnConfigurationSid, dateCreated, dateUpdated, dateCompleted, referenceSid, subresourceUris); + return Objects.hash( + sid, + accountSid, + status, + addOnSid, + addOnConfigurationSid, + dateCreated, + dateUpdated, + dateCompleted, + referenceSid, + subresourceUris + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/recording/AddOnResultDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/recording/AddOnResultDeleter.java index 377aa88477..49ec1f07e8 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/recording/AddOnResultDeleter.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/recording/AddOnResultDeleter.java @@ -24,32 +24,50 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class AddOnResultDeleter extends Deleter { + private String pathReferenceSid; private String pathSid; private String pathAccountSid; - public AddOnResultDeleter(final String pathReferenceSid, final String pathSid){ + public AddOnResultDeleter( + final String pathReferenceSid, + final String pathSid + ) { this.pathReferenceSid = pathReferenceSid; this.pathSid = pathSid; } - public AddOnResultDeleter(final String pathAccountSid, final String pathReferenceSid, final String pathSid){ + + public AddOnResultDeleter( + final String pathAccountSid, + final String pathReferenceSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathReferenceSid = pathReferenceSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/Recordings/{ReferenceSid}/AddOnResults/{Sid}.json"; + String path = + "/2010-04-01/Accounts/{AccountSid}/Recordings/{ReferenceSid}/AddOnResults/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"ReferenceSid"+"}", this.pathReferenceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "ReferenceSid" + "}", + this.pathReferenceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -59,9 +77,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AddOnResult delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "AddOnResult delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/recording/AddOnResultFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/recording/AddOnResultFetcher.java index bc26b94601..6ec7bcd22e 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/recording/AddOnResultFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/recording/AddOnResultFetcher.java @@ -24,33 +24,50 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class AddOnResultFetcher extends Fetcher { + private String pathReferenceSid; private String pathSid; private String pathAccountSid; - public AddOnResultFetcher(final String pathReferenceSid, final String pathSid){ + public AddOnResultFetcher( + final String pathReferenceSid, + final String pathSid + ) { this.pathReferenceSid = pathReferenceSid; this.pathSid = pathSid; } - public AddOnResultFetcher(final String pathAccountSid, final String pathReferenceSid, final String pathSid){ + + public AddOnResultFetcher( + final String pathAccountSid, + final String pathReferenceSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathReferenceSid = pathReferenceSid; this.pathSid = pathSid; } - @Override public AddOnResult fetch(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/Recordings/{ReferenceSid}/AddOnResults/{Sid}.json"; + String path = + "/2010-04-01/Accounts/{AccountSid}/Recordings/{ReferenceSid}/AddOnResults/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"ReferenceSid"+"}", this.pathReferenceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "ReferenceSid" + "}", + this.pathReferenceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -60,15 +77,23 @@ public AddOnResult fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AddOnResult fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "AddOnResult fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return AddOnResult.fromJson(response.getStream(), client.getObjectMapper()); + return AddOnResult.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/recording/AddOnResultReader.java b/src/main/java/com/twilio/rest/api/v2010/account/recording/AddOnResultReader.java index c51b8ea552..e2e8e4a58b 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/recording/AddOnResultReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/recording/AddOnResultReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.api.v2010.account.recording; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,24 +25,26 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class AddOnResultReader extends Reader { + private String pathReferenceSid; private String pathAccountSid; private Integer pageSize; - public AddOnResultReader(final String pathReferenceSid){ + public AddOnResultReader(final String pathReferenceSid) { this.pathReferenceSid = pathReferenceSid; } - public AddOnResultReader(final String pathAccountSid, final String pathReferenceSid){ + + public AddOnResultReader( + final String pathAccountSid, + final String pathReferenceSid + ) { this.pathAccountSid = pathAccountSid; this.pathReferenceSid = pathReferenceSid; } - public AddOnResultReader setPageSize(final Integer pageSize){ + public AddOnResultReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -52,10 +55,22 @@ public ResourceSet read(final TwilioRestClient client) { } public Page firstPage(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/Recordings/{ReferenceSid}/AddOnResults.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"ReferenceSid"+"}", this.pathReferenceSid.toString()); + String path = + "/2010-04-01/Accounts/{AccountSid}/Recordings/{ReferenceSid}/AddOnResults.json"; + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "ReferenceSid" + "}", + this.pathReferenceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -67,13 +82,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AddOnResult read failed: Unable to connect to server"); + throw new ApiConnectionException( + "AddOnResult read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -89,7 +112,10 @@ private Page pageForRequest(final TwilioRestClient client, final Re } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.API.toString()) @@ -97,9 +123,11 @@ public Page previousPage(final Page page, final Twilio return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.API.toString()) @@ -108,21 +136,21 @@ public Page nextPage(final Page page, final TwilioRest } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/recording/Transcription.java b/src/main/java/com/twilio/rest/api/v2010/account/recording/Transcription.java index 5b01855b1b..e19d0b203b 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/recording/Transcription.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/recording/Transcription.java @@ -20,61 +20,88 @@ import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.twilio.base.Resource; -import java.util.Currency; +import com.twilio.converter.CurrencyDeserializer; import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; -import com.twilio.converter.CurrencyDeserializer; import com.twilio.exception.ApiConnectionException; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; +import java.math.BigDecimal; import java.time.ZonedDateTime; - +import java.util.Currency; import java.util.Objects; - - -import java.math.BigDecimal; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Transcription extends Resource { + private static final long serialVersionUID = 169453036448500L; - public static TranscriptionDeleter deleter(final String pathRecordingSid, final String pathSid){ + public static TranscriptionDeleter deleter( + final String pathRecordingSid, + final String pathSid + ) { return new TranscriptionDeleter(pathRecordingSid, pathSid); } - public static TranscriptionDeleter deleter(final String pathAccountSid, final String pathRecordingSid, final String pathSid){ - return new TranscriptionDeleter(pathAccountSid, pathRecordingSid, pathSid); + + public static TranscriptionDeleter deleter( + final String pathAccountSid, + final String pathRecordingSid, + final String pathSid + ) { + return new TranscriptionDeleter( + pathAccountSid, + pathRecordingSid, + pathSid + ); } - public static TranscriptionFetcher fetcher(final String pathRecordingSid, final String pathSid){ + public static TranscriptionFetcher fetcher( + final String pathRecordingSid, + final String pathSid + ) { return new TranscriptionFetcher(pathRecordingSid, pathSid); } - public static TranscriptionFetcher fetcher(final String pathAccountSid, final String pathRecordingSid, final String pathSid){ - return new TranscriptionFetcher(pathAccountSid, pathRecordingSid, pathSid); + + public static TranscriptionFetcher fetcher( + final String pathAccountSid, + final String pathRecordingSid, + final String pathSid + ) { + return new TranscriptionFetcher( + pathAccountSid, + pathRecordingSid, + pathSid + ); } - public static TranscriptionReader reader(final String pathRecordingSid){ + public static TranscriptionReader reader(final String pathRecordingSid) { return new TranscriptionReader(pathRecordingSid); } - public static TranscriptionReader reader(final String pathAccountSid, final String pathRecordingSid){ + + public static TranscriptionReader reader( + final String pathAccountSid, + final String pathRecordingSid + ) { return new TranscriptionReader(pathAccountSid, pathRecordingSid); } /** - * Converts a JSON String into a Transcription object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Transcription object represented by the provided JSON - */ - public static Transcription fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Transcription object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Transcription object represented by the provided JSON + */ + public static Transcription fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Transcription.class); @@ -86,14 +113,17 @@ public static Transcription fromJson(final String json, final ObjectMapper objec } /** - * Converts a JSON InputStream into a Transcription object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Transcription object represented by the provided JSON - */ - public static Transcription fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Transcription object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Transcription object represented by the provided JSON + */ + public static Transcription fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Transcription.class); @@ -103,6 +133,7 @@ public static Transcription fromJson(final InputStream json, final ObjectMapper throw new ApiConnectionException(e.getMessage(), e); } } + public enum Status { IN_PROGRESS("in-progress"), COMPLETED("completed"), @@ -140,45 +171,21 @@ public static Status forValue(final String value) { @JsonCreator private Transcription( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("api_version") - final String apiVersion, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("duration") - final String duration, - - @JsonProperty("price") - final BigDecimal price, - - @JsonProperty("price_unit") - @JsonDeserialize(using = com.twilio.converter.CurrencyDeserializer.class) - final Currency priceUnit, - - @JsonProperty("recording_sid") - final String recordingSid, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("status") - final Transcription.Status status, - - @JsonProperty("transcription_text") - final String transcriptionText, - - @JsonProperty("type") - final String type, - - @JsonProperty("uri") - final String uri + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("api_version") final String apiVersion, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("duration") final String duration, + @JsonProperty("price") final BigDecimal price, + @JsonProperty("price_unit") @JsonDeserialize( + using = com.twilio.converter.CurrencyDeserializer.class + ) final Currency priceUnit, + @JsonProperty("recording_sid") final String recordingSid, + @JsonProperty("sid") final String sid, + @JsonProperty("status") final Transcription.Status status, + @JsonProperty("transcription_text") final String transcriptionText, + @JsonProperty("type") final String type, + @JsonProperty("uri") final String uri ) { this.accountSid = accountSid; this.apiVersion = apiVersion; @@ -195,49 +202,61 @@ private Transcription( this.uri = uri; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getApiVersion() { - return this.apiVersion; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getDuration() { - return this.duration; - } - public final BigDecimal getPrice() { - return this.price; - } - public final Currency getPriceUnit() { - return this.priceUnit; - } - public final String getRecordingSid() { - return this.recordingSid; - } - public final String getSid() { - return this.sid; - } - public final Transcription.Status getStatus() { - return this.status; - } - public final String getTranscriptionText() { - return this.transcriptionText; - } - public final String getType() { - return this.type; - } - public final String getUri() { - return this.uri; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getApiVersion() { + return this.apiVersion; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getDuration() { + return this.duration; + } + + public final BigDecimal getPrice() { + return this.price; + } + + public final Currency getPriceUnit() { + return this.priceUnit; + } + + public final String getRecordingSid() { + return this.recordingSid; + } + + public final String getSid() { + return this.sid; + } + + public final Transcription.Status getStatus() { + return this.status; + } + + public final String getTranscriptionText() { + return this.transcriptionText; + } + + public final String getType() { + return this.type; + } + + public final String getUri() { + return this.uri; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -247,13 +266,39 @@ public boolean equals(final Object o) { Transcription other = (Transcription) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(apiVersion, other.apiVersion) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(duration, other.duration) && Objects.equals(price, other.price) && Objects.equals(priceUnit, other.priceUnit) && Objects.equals(recordingSid, other.recordingSid) && Objects.equals(sid, other.sid) && Objects.equals(status, other.status) && Objects.equals(transcriptionText, other.transcriptionText) && Objects.equals(type, other.type) && Objects.equals(uri, other.uri) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(apiVersion, other.apiVersion) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(duration, other.duration) && + Objects.equals(price, other.price) && + Objects.equals(priceUnit, other.priceUnit) && + Objects.equals(recordingSid, other.recordingSid) && + Objects.equals(sid, other.sid) && + Objects.equals(status, other.status) && + Objects.equals(transcriptionText, other.transcriptionText) && + Objects.equals(type, other.type) && + Objects.equals(uri, other.uri) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, apiVersion, dateCreated, dateUpdated, duration, price, priceUnit, recordingSid, sid, status, transcriptionText, type, uri); + return Objects.hash( + accountSid, + apiVersion, + dateCreated, + dateUpdated, + duration, + price, + priceUnit, + recordingSid, + sid, + status, + transcriptionText, + type, + uri + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/recording/TranscriptionDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/recording/TranscriptionDeleter.java index a1eeec74e7..7fe1e232af 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/recording/TranscriptionDeleter.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/recording/TranscriptionDeleter.java @@ -24,32 +24,50 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class TranscriptionDeleter extends Deleter { + private String pathRecordingSid; private String pathSid; private String pathAccountSid; - public TranscriptionDeleter(final String pathRecordingSid, final String pathSid){ + public TranscriptionDeleter( + final String pathRecordingSid, + final String pathSid + ) { this.pathRecordingSid = pathRecordingSid; this.pathSid = pathSid; } - public TranscriptionDeleter(final String pathAccountSid, final String pathRecordingSid, final String pathSid){ + + public TranscriptionDeleter( + final String pathAccountSid, + final String pathRecordingSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathRecordingSid = pathRecordingSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/Recordings/{RecordingSid}/Transcriptions/{Sid}.json"; + String path = + "/2010-04-01/Accounts/{AccountSid}/Recordings/{RecordingSid}/Transcriptions/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"RecordingSid"+"}", this.pathRecordingSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "RecordingSid" + "}", + this.pathRecordingSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -59,9 +77,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Transcription delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Transcription delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/recording/TranscriptionFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/recording/TranscriptionFetcher.java index 11c2cb358c..b541ebc03d 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/recording/TranscriptionFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/recording/TranscriptionFetcher.java @@ -24,33 +24,50 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class TranscriptionFetcher extends Fetcher { + private String pathRecordingSid; private String pathSid; private String pathAccountSid; - public TranscriptionFetcher(final String pathRecordingSid, final String pathSid){ + public TranscriptionFetcher( + final String pathRecordingSid, + final String pathSid + ) { this.pathRecordingSid = pathRecordingSid; this.pathSid = pathSid; } - public TranscriptionFetcher(final String pathAccountSid, final String pathRecordingSid, final String pathSid){ + + public TranscriptionFetcher( + final String pathAccountSid, + final String pathRecordingSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathRecordingSid = pathRecordingSid; this.pathSid = pathSid; } - @Override public Transcription fetch(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/Recordings/{RecordingSid}/Transcriptions/{Sid}.json"; + String path = + "/2010-04-01/Accounts/{AccountSid}/Recordings/{RecordingSid}/Transcriptions/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"RecordingSid"+"}", this.pathRecordingSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "RecordingSid" + "}", + this.pathRecordingSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -60,15 +77,23 @@ public Transcription fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Transcription fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Transcription fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Transcription.fromJson(response.getStream(), client.getObjectMapper()); + return Transcription.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/recording/TranscriptionReader.java b/src/main/java/com/twilio/rest/api/v2010/account/recording/TranscriptionReader.java index c333fbd1c0..479d66643c 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/recording/TranscriptionReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/recording/TranscriptionReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.api.v2010.account.recording; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,24 +25,26 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class TranscriptionReader extends Reader { + private String pathRecordingSid; private String pathAccountSid; private Integer pageSize; - public TranscriptionReader(final String pathRecordingSid){ + public TranscriptionReader(final String pathRecordingSid) { this.pathRecordingSid = pathRecordingSid; } - public TranscriptionReader(final String pathAccountSid, final String pathRecordingSid){ + + public TranscriptionReader( + final String pathAccountSid, + final String pathRecordingSid + ) { this.pathAccountSid = pathAccountSid; this.pathRecordingSid = pathRecordingSid; } - public TranscriptionReader setPageSize(final Integer pageSize){ + public TranscriptionReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -52,10 +55,22 @@ public ResourceSet read(final TwilioRestClient client) { } public Page firstPage(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/Recordings/{RecordingSid}/Transcriptions.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"RecordingSid"+"}", this.pathRecordingSid.toString()); + String path = + "/2010-04-01/Accounts/{AccountSid}/Recordings/{RecordingSid}/Transcriptions.json"; + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "RecordingSid" + "}", + this.pathRecordingSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -67,13 +82,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Transcription read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Transcription read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -89,7 +112,10 @@ private Page pageForRequest(final TwilioRestClient client, final } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.API.toString()) @@ -97,9 +123,11 @@ public Page previousPage(final Page page, final Tw return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.API.toString()) @@ -108,21 +136,21 @@ public Page nextPage(final Page page, final Twilio } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/recording/addonresult/Payload.java b/src/main/java/com/twilio/rest/api/v2010/account/recording/addonresult/Payload.java index bb3f51c0ca..aa95484d94 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/recording/addonresult/Payload.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/recording/addonresult/Payload.java @@ -23,55 +23,104 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Payload extends Resource { + private static final long serialVersionUID = 241774798598483L; - public static PayloadDeleter deleter(final String pathReferenceSid, final String pathAddOnResultSid, final String pathSid){ - return new PayloadDeleter(pathReferenceSid, pathAddOnResultSid, pathSid); + public static PayloadDeleter deleter( + final String pathReferenceSid, + final String pathAddOnResultSid, + final String pathSid + ) { + return new PayloadDeleter( + pathReferenceSid, + pathAddOnResultSid, + pathSid + ); } - public static PayloadDeleter deleter(final String pathAccountSid, final String pathReferenceSid, final String pathAddOnResultSid, final String pathSid){ - return new PayloadDeleter(pathAccountSid, pathReferenceSid, pathAddOnResultSid, pathSid); + + public static PayloadDeleter deleter( + final String pathAccountSid, + final String pathReferenceSid, + final String pathAddOnResultSid, + final String pathSid + ) { + return new PayloadDeleter( + pathAccountSid, + pathReferenceSid, + pathAddOnResultSid, + pathSid + ); } - public static PayloadFetcher fetcher(final String pathReferenceSid, final String pathAddOnResultSid, final String pathSid){ - return new PayloadFetcher(pathReferenceSid, pathAddOnResultSid, pathSid); + public static PayloadFetcher fetcher( + final String pathReferenceSid, + final String pathAddOnResultSid, + final String pathSid + ) { + return new PayloadFetcher( + pathReferenceSid, + pathAddOnResultSid, + pathSid + ); } - public static PayloadFetcher fetcher(final String pathAccountSid, final String pathReferenceSid, final String pathAddOnResultSid, final String pathSid){ - return new PayloadFetcher(pathAccountSid, pathReferenceSid, pathAddOnResultSid, pathSid); + + public static PayloadFetcher fetcher( + final String pathAccountSid, + final String pathReferenceSid, + final String pathAddOnResultSid, + final String pathSid + ) { + return new PayloadFetcher( + pathAccountSid, + pathReferenceSid, + pathAddOnResultSid, + pathSid + ); } - public static PayloadReader reader(final String pathReferenceSid, final String pathAddOnResultSid){ + public static PayloadReader reader( + final String pathReferenceSid, + final String pathAddOnResultSid + ) { return new PayloadReader(pathReferenceSid, pathAddOnResultSid); } - public static PayloadReader reader(final String pathAccountSid, final String pathReferenceSid, final String pathAddOnResultSid){ - return new PayloadReader(pathAccountSid, pathReferenceSid, pathAddOnResultSid); + + public static PayloadReader reader( + final String pathAccountSid, + final String pathReferenceSid, + final String pathAddOnResultSid + ) { + return new PayloadReader( + pathAccountSid, + pathReferenceSid, + pathAddOnResultSid + ); } /** - * Converts a JSON String into a Payload object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Payload object represented by the provided JSON - */ - public static Payload fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Payload object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Payload object represented by the provided JSON + */ + public static Payload fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Payload.class); @@ -83,14 +132,17 @@ public static Payload fromJson(final String json, final ObjectMapper objectMappe } /** - * Converts a JSON InputStream into a Payload object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Payload object represented by the provided JSON - */ - public static Payload fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Payload object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Payload object represented by the provided JSON + */ + public static Payload fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Payload.class); @@ -115,38 +167,21 @@ public static Payload fromJson(final InputStream json, final ObjectMapper object @JsonCreator private Payload( - @JsonProperty("sid") - final String sid, - - @JsonProperty("add_on_result_sid") - final String addOnResultSid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("label") - final String label, - - @JsonProperty("add_on_sid") - final String addOnSid, - - @JsonProperty("add_on_configuration_sid") - final String addOnConfigurationSid, - - @JsonProperty("content_type") - final String contentType, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("reference_sid") - final String referenceSid, - - @JsonProperty("subresource_uris") - final Map subresourceUris + @JsonProperty("sid") final String sid, + @JsonProperty("add_on_result_sid") final String addOnResultSid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("label") final String label, + @JsonProperty("add_on_sid") final String addOnSid, + @JsonProperty( + "add_on_configuration_sid" + ) final String addOnConfigurationSid, + @JsonProperty("content_type") final String contentType, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("reference_sid") final String referenceSid, + @JsonProperty( + "subresource_uris" + ) final Map subresourceUris ) { this.sid = sid; this.addOnResultSid = addOnResultSid; @@ -161,43 +196,53 @@ private Payload( this.subresourceUris = subresourceUris; } - public final String getSid() { - return this.sid; - } - public final String getAddOnResultSid() { - return this.addOnResultSid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getLabel() { - return this.label; - } - public final String getAddOnSid() { - return this.addOnSid; - } - public final String getAddOnConfigurationSid() { - return this.addOnConfigurationSid; - } - public final String getContentType() { - return this.contentType; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getReferenceSid() { - return this.referenceSid; - } - public final Map getSubresourceUris() { - return this.subresourceUris; - } + public final String getSid() { + return this.sid; + } + + public final String getAddOnResultSid() { + return this.addOnResultSid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getLabel() { + return this.label; + } + + public final String getAddOnSid() { + return this.addOnSid; + } + + public final String getAddOnConfigurationSid() { + return this.addOnConfigurationSid; + } + + public final String getContentType() { + return this.contentType; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getReferenceSid() { + return this.referenceSid; + } + + public final Map getSubresourceUris() { + return this.subresourceUris; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -207,13 +252,38 @@ public boolean equals(final Object o) { Payload other = (Payload) o; - return Objects.equals(sid, other.sid) && Objects.equals(addOnResultSid, other.addOnResultSid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(label, other.label) && Objects.equals(addOnSid, other.addOnSid) && Objects.equals(addOnConfigurationSid, other.addOnConfigurationSid) && Objects.equals(contentType, other.contentType) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(referenceSid, other.referenceSid) && Objects.equals(subresourceUris, other.subresourceUris) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(addOnResultSid, other.addOnResultSid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(label, other.label) && + Objects.equals(addOnSid, other.addOnSid) && + Objects.equals( + addOnConfigurationSid, + other.addOnConfigurationSid + ) && + Objects.equals(contentType, other.contentType) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(referenceSid, other.referenceSid) && + Objects.equals(subresourceUris, other.subresourceUris) + ); } @Override public int hashCode() { - return Objects.hash(sid, addOnResultSid, accountSid, label, addOnSid, addOnConfigurationSid, contentType, dateCreated, dateUpdated, referenceSid, subresourceUris); + return Objects.hash( + sid, + addOnResultSid, + accountSid, + label, + addOnSid, + addOnConfigurationSid, + contentType, + dateCreated, + dateUpdated, + referenceSid, + subresourceUris + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/recording/addonresult/PayloadDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/recording/addonresult/PayloadDeleter.java index c476d2d862..3155d5cacd 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/recording/addonresult/PayloadDeleter.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/recording/addonresult/PayloadDeleter.java @@ -24,36 +24,60 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class PayloadDeleter extends Deleter { + private String pathReferenceSid; private String pathAddOnResultSid; private String pathSid; private String pathAccountSid; - public PayloadDeleter(final String pathReferenceSid, final String pathAddOnResultSid, final String pathSid){ + public PayloadDeleter( + final String pathReferenceSid, + final String pathAddOnResultSid, + final String pathSid + ) { this.pathReferenceSid = pathReferenceSid; this.pathAddOnResultSid = pathAddOnResultSid; this.pathSid = pathSid; } - public PayloadDeleter(final String pathAccountSid, final String pathReferenceSid, final String pathAddOnResultSid, final String pathSid){ + + public PayloadDeleter( + final String pathAccountSid, + final String pathReferenceSid, + final String pathAddOnResultSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathReferenceSid = pathReferenceSid; this.pathAddOnResultSid = pathAddOnResultSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/Recordings/{ReferenceSid}/AddOnResults/{AddOnResultSid}/Payloads/{Sid}.json"; + String path = + "/2010-04-01/Accounts/{AccountSid}/Recordings/{ReferenceSid}/AddOnResults/{AddOnResultSid}/Payloads/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"ReferenceSid"+"}", this.pathReferenceSid.toString()); - path = path.replace("{"+"AddOnResultSid"+"}", this.pathAddOnResultSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "ReferenceSid" + "}", + this.pathReferenceSid.toString() + ); + path = + path.replace( + "{" + "AddOnResultSid" + "}", + this.pathAddOnResultSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -63,9 +87,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Payload delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Payload delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/recording/addonresult/PayloadFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/recording/addonresult/PayloadFetcher.java index 98abad893c..6953338377 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/recording/addonresult/PayloadFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/recording/addonresult/PayloadFetcher.java @@ -24,37 +24,60 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class PayloadFetcher extends Fetcher { + private String pathReferenceSid; private String pathAddOnResultSid; private String pathSid; private String pathAccountSid; - public PayloadFetcher(final String pathReferenceSid, final String pathAddOnResultSid, final String pathSid){ + public PayloadFetcher( + final String pathReferenceSid, + final String pathAddOnResultSid, + final String pathSid + ) { this.pathReferenceSid = pathReferenceSid; this.pathAddOnResultSid = pathAddOnResultSid; this.pathSid = pathSid; } - public PayloadFetcher(final String pathAccountSid, final String pathReferenceSid, final String pathAddOnResultSid, final String pathSid){ + + public PayloadFetcher( + final String pathAccountSid, + final String pathReferenceSid, + final String pathAddOnResultSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathReferenceSid = pathReferenceSid; this.pathAddOnResultSid = pathAddOnResultSid; this.pathSid = pathSid; } - @Override public Payload fetch(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/Recordings/{ReferenceSid}/AddOnResults/{AddOnResultSid}/Payloads/{Sid}.json"; + String path = + "/2010-04-01/Accounts/{AccountSid}/Recordings/{ReferenceSid}/AddOnResults/{AddOnResultSid}/Payloads/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"ReferenceSid"+"}", this.pathReferenceSid.toString()); - path = path.replace("{"+"AddOnResultSid"+"}", this.pathAddOnResultSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "ReferenceSid" + "}", + this.pathReferenceSid.toString() + ); + path = + path.replace( + "{" + "AddOnResultSid" + "}", + this.pathAddOnResultSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -64,9 +87,14 @@ public Payload fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Payload fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Payload fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/recording/addonresult/PayloadReader.java b/src/main/java/com/twilio/rest/api/v2010/account/recording/addonresult/PayloadReader.java index 4bac6da30e..b98ee21df7 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/recording/addonresult/PayloadReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/recording/addonresult/PayloadReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.api.v2010.account.recording.addonresult; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,27 +25,33 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class PayloadReader extends Reader { + private String pathReferenceSid; private String pathAddOnResultSid; private String pathAccountSid; private Integer pageSize; - public PayloadReader(final String pathReferenceSid, final String pathAddOnResultSid){ + public PayloadReader( + final String pathReferenceSid, + final String pathAddOnResultSid + ) { this.pathReferenceSid = pathReferenceSid; this.pathAddOnResultSid = pathAddOnResultSid; } - public PayloadReader(final String pathAccountSid, final String pathReferenceSid, final String pathAddOnResultSid){ + + public PayloadReader( + final String pathAccountSid, + final String pathReferenceSid, + final String pathAddOnResultSid + ) { this.pathAccountSid = pathAccountSid; this.pathReferenceSid = pathReferenceSid; this.pathAddOnResultSid = pathAddOnResultSid; } - public PayloadReader setPageSize(final Integer pageSize){ + public PayloadReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -55,11 +62,27 @@ public ResourceSet read(final TwilioRestClient client) { } public Page firstPage(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/Recordings/{ReferenceSid}/AddOnResults/{AddOnResultSid}/Payloads.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"ReferenceSid"+"}", this.pathReferenceSid.toString()); - path = path.replace("{"+"AddOnResultSid"+"}", this.pathAddOnResultSid.toString()); + String path = + "/2010-04-01/Accounts/{AccountSid}/Recordings/{ReferenceSid}/AddOnResults/{AddOnResultSid}/Payloads.json"; + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "ReferenceSid" + "}", + this.pathReferenceSid.toString() + ); + path = + path.replace( + "{" + "AddOnResultSid" + "}", + this.pathAddOnResultSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -71,13 +94,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Payload read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Payload read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -93,7 +124,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reques } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.API.toString()) @@ -101,9 +135,11 @@ public Page previousPage(final Page page, final TwilioRestClie return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.API.toString()) @@ -112,21 +148,21 @@ public Page nextPage(final Page page, final TwilioRestClient c } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/CredentialList.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/CredentialList.java index 95d8e3e1d3..8834fea5b4 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/CredentialList.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/CredentialList.java @@ -23,69 +23,89 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class CredentialList extends Resource { + private static final long serialVersionUID = 178395545365846L; - public static CredentialListCreator creator(final String friendlyName){ + public static CredentialListCreator creator(final String friendlyName) { return new CredentialListCreator(friendlyName); } - public static CredentialListCreator creator(final String pathAccountSid, final String friendlyName){ + + public static CredentialListCreator creator( + final String pathAccountSid, + final String friendlyName + ) { return new CredentialListCreator(pathAccountSid, friendlyName); } - public static CredentialListDeleter deleter(final String pathSid){ + public static CredentialListDeleter deleter(final String pathSid) { return new CredentialListDeleter(pathSid); } - public static CredentialListDeleter deleter(final String pathAccountSid, final String pathSid){ + + public static CredentialListDeleter deleter( + final String pathAccountSid, + final String pathSid + ) { return new CredentialListDeleter(pathAccountSid, pathSid); } - public static CredentialListFetcher fetcher(final String pathSid){ + public static CredentialListFetcher fetcher(final String pathSid) { return new CredentialListFetcher(pathSid); } - public static CredentialListFetcher fetcher(final String pathAccountSid, final String pathSid){ + + public static CredentialListFetcher fetcher( + final String pathAccountSid, + final String pathSid + ) { return new CredentialListFetcher(pathAccountSid, pathSid); } - public static CredentialListReader reader(){ + public static CredentialListReader reader() { return new CredentialListReader(); } - public static CredentialListReader reader(final String pathAccountSid){ + + public static CredentialListReader reader(final String pathAccountSid) { return new CredentialListReader(pathAccountSid); } - public static CredentialListUpdater updater(final String pathSid, final String friendlyName){ + public static CredentialListUpdater updater( + final String pathSid, + final String friendlyName + ) { return new CredentialListUpdater(pathSid, friendlyName); } - public static CredentialListUpdater updater(final String pathAccountSid, final String pathSid, final String friendlyName){ + + public static CredentialListUpdater updater( + final String pathAccountSid, + final String pathSid, + final String friendlyName + ) { return new CredentialListUpdater(pathAccountSid, pathSid, friendlyName); } /** - * Converts a JSON String into a CredentialList object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return CredentialList object represented by the provided JSON - */ - public static CredentialList fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a CredentialList object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return CredentialList object represented by the provided JSON + */ + public static CredentialList fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, CredentialList.class); @@ -97,14 +117,17 @@ public static CredentialList fromJson(final String json, final ObjectMapper obje } /** - * Converts a JSON InputStream into a CredentialList object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return CredentialList object represented by the provided JSON - */ - public static CredentialList fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a CredentialList object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return CredentialList object represented by the provided JSON + */ + public static CredentialList fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, CredentialList.class); @@ -125,26 +148,15 @@ public static CredentialList fromJson(final InputStream json, final ObjectMapper @JsonCreator private CredentialList( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("subresource_uris") - final Map subresourceUris, - - @JsonProperty("uri") - final String uri + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("sid") final String sid, + @JsonProperty( + "subresource_uris" + ) final Map subresourceUris, + @JsonProperty("uri") final String uri ) { this.accountSid = accountSid; this.dateCreated = DateConverter.rfc2822DateTimeFromString(dateCreated); @@ -155,31 +167,37 @@ private CredentialList( this.uri = uri; } - public final String getAccountSid() { - return this.accountSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getSid() { - return this.sid; - } - public final Map getSubresourceUris() { - return this.subresourceUris; - } - public final String getUri() { - return this.uri; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getSid() { + return this.sid; + } + + public final Map getSubresourceUris() { + return this.subresourceUris; + } + + public final String getUri() { + return this.uri; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -189,13 +207,27 @@ public boolean equals(final Object o) { CredentialList other = (CredentialList) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(sid, other.sid) && Objects.equals(subresourceUris, other.subresourceUris) && Objects.equals(uri, other.uri) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(sid, other.sid) && + Objects.equals(subresourceUris, other.subresourceUris) && + Objects.equals(uri, other.uri) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, dateCreated, dateUpdated, friendlyName, sid, subresourceUris, uri); + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + friendlyName, + sid, + subresourceUris, + uri + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/CredentialListCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/CredentialListCreator.java index d62ab8820c..541ea1015a 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/CredentialListCreator.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/CredentialListCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010.account.sip; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,57 +25,80 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class CredentialListCreator extends Creator { - - -public class CredentialListCreator extends Creator{ private String friendlyName; private String pathAccountSid; public CredentialListCreator(final String friendlyName) { this.friendlyName = friendlyName; } - public CredentialListCreator(final String pathAccountSid, final String friendlyName) { + + public CredentialListCreator( + final String pathAccountSid, + final String friendlyName + ) { this.pathAccountSid = pathAccountSid; this.friendlyName = friendlyName; } - public CredentialListCreator setFriendlyName(final String friendlyName){ + public CredentialListCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } @Override - public CredentialList create(final TwilioRestClient client){ - String path = "/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists.json"; + public CredentialList create(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"FriendlyName"+"}", this.friendlyName.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "FriendlyName" + "}", + this.friendlyName.toString() + ); Request request = new Request( HttpMethod.POST, Domains.API.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("CredentialList creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "CredentialList creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return CredentialList.fromJson(response.getStream(), client.getObjectMapper()); + return CredentialList.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/CredentialListDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/CredentialListDeleter.java index 8b24ac6e58..6e8e04eb06 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/CredentialListDeleter.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/CredentialListDeleter.java @@ -24,28 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class CredentialListDeleter extends Deleter { + private String pathSid; private String pathAccountSid; - public CredentialListDeleter(final String pathSid){ + public CredentialListDeleter(final String pathSid) { this.pathSid = pathSid; } - public CredentialListDeleter(final String pathAccountSid, final String pathSid){ + + public CredentialListDeleter( + final String pathAccountSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists/{Sid}.json"; + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -55,9 +65,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("CredentialList delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "CredentialList delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/CredentialListFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/CredentialListFetcher.java index 234589eeab..a712057dea 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/CredentialListFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/CredentialListFetcher.java @@ -24,29 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class CredentialListFetcher extends Fetcher { + private String pathSid; private String pathAccountSid; - public CredentialListFetcher(final String pathSid){ + public CredentialListFetcher(final String pathSid) { this.pathSid = pathSid; } - public CredentialListFetcher(final String pathAccountSid, final String pathSid){ + + public CredentialListFetcher( + final String pathAccountSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - @Override public CredentialList fetch(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists/{Sid}.json"; + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -56,15 +65,23 @@ public CredentialList fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("CredentialList fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "CredentialList fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return CredentialList.fromJson(response.getStream(), client.getObjectMapper()); + return CredentialList.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/CredentialListReader.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/CredentialListReader.java index a1c845189e..c9a9109cf1 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/CredentialListReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/CredentialListReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.api.v2010.account.sip; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,21 +25,19 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class CredentialListReader extends Reader { + private String pathAccountSid; private Integer pageSize; - public CredentialListReader(){ - } - public CredentialListReader(final String pathAccountSid){ + public CredentialListReader() {} + + public CredentialListReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - public CredentialListReader setPageSize(final Integer pageSize){ + public CredentialListReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -49,9 +48,17 @@ public ResourceSet read(final TwilioRestClient client) { } public Page firstPage(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists.json"; + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -63,13 +70,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("CredentialList read failed: Unable to connect to server"); + throw new ApiConnectionException( + "CredentialList read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -85,7 +100,10 @@ private Page pageForRequest(final TwilioRestClient client, final } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.API.toString()) @@ -93,9 +111,11 @@ public Page previousPage(final Page page, final return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.API.toString()) @@ -104,21 +124,21 @@ public Page nextPage(final Page page, final Twil } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/CredentialListUpdater.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/CredentialListUpdater.java index bc237fcadc..3fdbecb7a0 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/CredentialListUpdater.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/CredentialListUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010.account.sip; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,61 +25,88 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class CredentialListUpdater extends Updater { - - -public class CredentialListUpdater extends Updater{ private String pathSid; private String friendlyName; private String pathAccountSid; - public CredentialListUpdater(final String pathSid, final String friendlyName){ + public CredentialListUpdater( + final String pathSid, + final String friendlyName + ) { this.pathSid = pathSid; this.friendlyName = friendlyName; } - public CredentialListUpdater(final String pathAccountSid, final String pathSid, final String friendlyName){ + + public CredentialListUpdater( + final String pathAccountSid, + final String pathSid, + final String friendlyName + ) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; this.friendlyName = friendlyName; } - public CredentialListUpdater setFriendlyName(final String friendlyName){ + public CredentialListUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } @Override - public CredentialList update(final TwilioRestClient client){ - String path = "/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists/{Sid}.json"; + public CredentialList update(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); - path = path.replace("{"+"FriendlyName"+"}", this.friendlyName.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + path = + path.replace( + "{" + "FriendlyName" + "}", + this.friendlyName.toString() + ); Request request = new Request( HttpMethod.POST, Domains.API.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("CredentialList update failed: Unable to connect to server"); + throw new ApiConnectionException( + "CredentialList update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return CredentialList.fromJson(response.getStream(), client.getObjectMapper()); + return CredentialList.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/Domain.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/Domain.java index 92c2a880a2..69256571a0 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/Domain.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/Domain.java @@ -23,71 +23,87 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; import com.twilio.http.HttpMethod; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Domain extends Resource { + private static final long serialVersionUID = 8213004596487L; - public static DomainCreator creator(final String domainName){ + public static DomainCreator creator(final String domainName) { return new DomainCreator(domainName); } - public static DomainCreator creator(final String pathAccountSid, final String domainName){ + + public static DomainCreator creator( + final String pathAccountSid, + final String domainName + ) { return new DomainCreator(pathAccountSid, domainName); } - public static DomainDeleter deleter(final String pathSid){ + public static DomainDeleter deleter(final String pathSid) { return new DomainDeleter(pathSid); } - public static DomainDeleter deleter(final String pathAccountSid, final String pathSid){ + + public static DomainDeleter deleter( + final String pathAccountSid, + final String pathSid + ) { return new DomainDeleter(pathAccountSid, pathSid); } - public static DomainFetcher fetcher(final String pathSid){ + public static DomainFetcher fetcher(final String pathSid) { return new DomainFetcher(pathSid); } - public static DomainFetcher fetcher(final String pathAccountSid, final String pathSid){ + + public static DomainFetcher fetcher( + final String pathAccountSid, + final String pathSid + ) { return new DomainFetcher(pathAccountSid, pathSid); } - public static DomainReader reader(){ + public static DomainReader reader() { return new DomainReader(); } - public static DomainReader reader(final String pathAccountSid){ + + public static DomainReader reader(final String pathAccountSid) { return new DomainReader(pathAccountSid); } - public static DomainUpdater updater(final String pathSid){ + public static DomainUpdater updater(final String pathSid) { return new DomainUpdater(pathSid); } - public static DomainUpdater updater(final String pathAccountSid, final String pathSid){ + + public static DomainUpdater updater( + final String pathAccountSid, + final String pathSid + ) { return new DomainUpdater(pathAccountSid, pathSid); } /** - * Converts a JSON String into a Domain object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Domain object represented by the provided JSON - */ - public static Domain fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Domain object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Domain object represented by the provided JSON + */ + public static Domain fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Domain.class); @@ -99,14 +115,17 @@ public static Domain fromJson(final String json, final ObjectMapper objectMapper } /** - * Converts a JSON InputStream into a Domain object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Domain object represented by the provided JSON - */ - public static Domain fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Domain object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Domain object represented by the provided JSON + */ + public static Domain fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Domain.class); @@ -141,68 +160,37 @@ public static Domain fromJson(final InputStream json, final ObjectMapper objectM @JsonCreator private Domain( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("api_version") - final String apiVersion, - - @JsonProperty("auth_type") - final String authType, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("domain_name") - final String domainName, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("uri") - final String uri, - - @JsonProperty("voice_fallback_method") - final HttpMethod voiceFallbackMethod, - - @JsonProperty("voice_fallback_url") - final URI voiceFallbackUrl, - - @JsonProperty("voice_method") - final HttpMethod voiceMethod, - - @JsonProperty("voice_status_callback_method") - final HttpMethod voiceStatusCallbackMethod, - - @JsonProperty("voice_status_callback_url") - final URI voiceStatusCallbackUrl, - - @JsonProperty("voice_url") - final URI voiceUrl, - - @JsonProperty("subresource_uris") - final Map subresourceUris, - - @JsonProperty("sip_registration") - final Boolean sipRegistration, - - @JsonProperty("emergency_calling_enabled") - final Boolean emergencyCallingEnabled, - - @JsonProperty("secure") - final Boolean secure, - - @JsonProperty("byoc_trunk_sid") - final String byocTrunkSid, - - @JsonProperty("emergency_caller_sid") - final String emergencyCallerSid + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("api_version") final String apiVersion, + @JsonProperty("auth_type") final String authType, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("domain_name") final String domainName, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("sid") final String sid, + @JsonProperty("uri") final String uri, + @JsonProperty( + "voice_fallback_method" + ) final HttpMethod voiceFallbackMethod, + @JsonProperty("voice_fallback_url") final URI voiceFallbackUrl, + @JsonProperty("voice_method") final HttpMethod voiceMethod, + @JsonProperty( + "voice_status_callback_method" + ) final HttpMethod voiceStatusCallbackMethod, + @JsonProperty( + "voice_status_callback_url" + ) final URI voiceStatusCallbackUrl, + @JsonProperty("voice_url") final URI voiceUrl, + @JsonProperty( + "subresource_uris" + ) final Map subresourceUris, + @JsonProperty("sip_registration") final Boolean sipRegistration, + @JsonProperty( + "emergency_calling_enabled" + ) final Boolean emergencyCallingEnabled, + @JsonProperty("secure") final Boolean secure, + @JsonProperty("byoc_trunk_sid") final String byocTrunkSid, + @JsonProperty("emergency_caller_sid") final String emergencyCallerSid ) { this.accountSid = accountSid; this.apiVersion = apiVersion; @@ -227,73 +215,93 @@ private Domain( this.emergencyCallerSid = emergencyCallerSid; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getApiVersion() { - return this.apiVersion; - } - public final String getAuthType() { - return this.authType; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getDomainName() { - return this.domainName; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getSid() { - return this.sid; - } - public final String getUri() { - return this.uri; - } - public final HttpMethod getVoiceFallbackMethod() { - return this.voiceFallbackMethod; - } - public final URI getVoiceFallbackUrl() { - return this.voiceFallbackUrl; - } - public final HttpMethod getVoiceMethod() { - return this.voiceMethod; - } - public final HttpMethod getVoiceStatusCallbackMethod() { - return this.voiceStatusCallbackMethod; - } - public final URI getVoiceStatusCallbackUrl() { - return this.voiceStatusCallbackUrl; - } - public final URI getVoiceUrl() { - return this.voiceUrl; - } - public final Map getSubresourceUris() { - return this.subresourceUris; - } - public final Boolean getSipRegistration() { - return this.sipRegistration; - } - public final Boolean getEmergencyCallingEnabled() { - return this.emergencyCallingEnabled; - } - public final Boolean getSecure() { - return this.secure; - } - public final String getByocTrunkSid() { - return this.byocTrunkSid; - } - public final String getEmergencyCallerSid() { - return this.emergencyCallerSid; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getApiVersion() { + return this.apiVersion; + } + + public final String getAuthType() { + return this.authType; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getDomainName() { + return this.domainName; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getSid() { + return this.sid; + } + + public final String getUri() { + return this.uri; + } + + public final HttpMethod getVoiceFallbackMethod() { + return this.voiceFallbackMethod; + } + + public final URI getVoiceFallbackUrl() { + return this.voiceFallbackUrl; + } + + public final HttpMethod getVoiceMethod() { + return this.voiceMethod; + } + + public final HttpMethod getVoiceStatusCallbackMethod() { + return this.voiceStatusCallbackMethod; + } + + public final URI getVoiceStatusCallbackUrl() { + return this.voiceStatusCallbackUrl; + } + + public final URI getVoiceUrl() { + return this.voiceUrl; + } + + public final Map getSubresourceUris() { + return this.subresourceUris; + } + + public final Boolean getSipRegistration() { + return this.sipRegistration; + } + + public final Boolean getEmergencyCallingEnabled() { + return this.emergencyCallingEnabled; + } + + public final Boolean getSecure() { + return this.secure; + } + + public final String getByocTrunkSid() { + return this.byocTrunkSid; + } + + public final String getEmergencyCallerSid() { + return this.emergencyCallerSid; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -303,13 +311,64 @@ public boolean equals(final Object o) { Domain other = (Domain) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(apiVersion, other.apiVersion) && Objects.equals(authType, other.authType) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(domainName, other.domainName) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(sid, other.sid) && Objects.equals(uri, other.uri) && Objects.equals(voiceFallbackMethod, other.voiceFallbackMethod) && Objects.equals(voiceFallbackUrl, other.voiceFallbackUrl) && Objects.equals(voiceMethod, other.voiceMethod) && Objects.equals(voiceStatusCallbackMethod, other.voiceStatusCallbackMethod) && Objects.equals(voiceStatusCallbackUrl, other.voiceStatusCallbackUrl) && Objects.equals(voiceUrl, other.voiceUrl) && Objects.equals(subresourceUris, other.subresourceUris) && Objects.equals(sipRegistration, other.sipRegistration) && Objects.equals(emergencyCallingEnabled, other.emergencyCallingEnabled) && Objects.equals(secure, other.secure) && Objects.equals(byocTrunkSid, other.byocTrunkSid) && Objects.equals(emergencyCallerSid, other.emergencyCallerSid) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(apiVersion, other.apiVersion) && + Objects.equals(authType, other.authType) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(domainName, other.domainName) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(sid, other.sid) && + Objects.equals(uri, other.uri) && + Objects.equals(voiceFallbackMethod, other.voiceFallbackMethod) && + Objects.equals(voiceFallbackUrl, other.voiceFallbackUrl) && + Objects.equals(voiceMethod, other.voiceMethod) && + Objects.equals( + voiceStatusCallbackMethod, + other.voiceStatusCallbackMethod + ) && + Objects.equals( + voiceStatusCallbackUrl, + other.voiceStatusCallbackUrl + ) && + Objects.equals(voiceUrl, other.voiceUrl) && + Objects.equals(subresourceUris, other.subresourceUris) && + Objects.equals(sipRegistration, other.sipRegistration) && + Objects.equals( + emergencyCallingEnabled, + other.emergencyCallingEnabled + ) && + Objects.equals(secure, other.secure) && + Objects.equals(byocTrunkSid, other.byocTrunkSid) && + Objects.equals(emergencyCallerSid, other.emergencyCallerSid) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, apiVersion, authType, dateCreated, dateUpdated, domainName, friendlyName, sid, uri, voiceFallbackMethod, voiceFallbackUrl, voiceMethod, voiceStatusCallbackMethod, voiceStatusCallbackUrl, voiceUrl, subresourceUris, sipRegistration, emergencyCallingEnabled, secure, byocTrunkSid, emergencyCallerSid); + return Objects.hash( + accountSid, + apiVersion, + authType, + dateCreated, + dateUpdated, + domainName, + friendlyName, + sid, + uri, + voiceFallbackMethod, + voiceFallbackUrl, + voiceMethod, + voiceStatusCallbackMethod, + voiceStatusCallbackUrl, + voiceUrl, + subresourceUris, + sipRegistration, + emergencyCallingEnabled, + secure, + byocTrunkSid, + emergencyCallerSid + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/DomainCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/DomainCreator.java index 1a1a2257ee..ca41206146 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/DomainCreator.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/DomainCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010.account.sip; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -25,12 +26,10 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.net.URI; - - - import java.net.URI; -public class DomainCreator extends Creator{ +public class DomainCreator extends Creator { + private String domainName; private String pathAccountSid; private String friendlyName; @@ -49,95 +48,136 @@ public class DomainCreator extends Creator{ public DomainCreator(final String domainName) { this.domainName = domainName; } + public DomainCreator(final String pathAccountSid, final String domainName) { this.pathAccountSid = pathAccountSid; this.domainName = domainName; } - public DomainCreator setDomainName(final String domainName){ + public DomainCreator setDomainName(final String domainName) { this.domainName = domainName; return this; } - public DomainCreator setFriendlyName(final String friendlyName){ + + public DomainCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public DomainCreator setVoiceUrl(final URI voiceUrl){ + + public DomainCreator setVoiceUrl(final URI voiceUrl) { this.voiceUrl = voiceUrl; return this; } - public DomainCreator setVoiceUrl(final String voiceUrl){ + public DomainCreator setVoiceUrl(final String voiceUrl) { return setVoiceUrl(Promoter.uriFromString(voiceUrl)); } - public DomainCreator setVoiceMethod(final HttpMethod voiceMethod){ + + public DomainCreator setVoiceMethod(final HttpMethod voiceMethod) { this.voiceMethod = voiceMethod; return this; } - public DomainCreator setVoiceFallbackUrl(final URI voiceFallbackUrl){ + + public DomainCreator setVoiceFallbackUrl(final URI voiceFallbackUrl) { this.voiceFallbackUrl = voiceFallbackUrl; return this; } - public DomainCreator setVoiceFallbackUrl(final String voiceFallbackUrl){ + public DomainCreator setVoiceFallbackUrl(final String voiceFallbackUrl) { return setVoiceFallbackUrl(Promoter.uriFromString(voiceFallbackUrl)); } - public DomainCreator setVoiceFallbackMethod(final HttpMethod voiceFallbackMethod){ + + public DomainCreator setVoiceFallbackMethod( + final HttpMethod voiceFallbackMethod + ) { this.voiceFallbackMethod = voiceFallbackMethod; return this; } - public DomainCreator setVoiceStatusCallbackUrl(final URI voiceStatusCallbackUrl){ + + public DomainCreator setVoiceStatusCallbackUrl( + final URI voiceStatusCallbackUrl + ) { this.voiceStatusCallbackUrl = voiceStatusCallbackUrl; return this; } - public DomainCreator setVoiceStatusCallbackUrl(final String voiceStatusCallbackUrl){ - return setVoiceStatusCallbackUrl(Promoter.uriFromString(voiceStatusCallbackUrl)); + public DomainCreator setVoiceStatusCallbackUrl( + final String voiceStatusCallbackUrl + ) { + return setVoiceStatusCallbackUrl( + Promoter.uriFromString(voiceStatusCallbackUrl) + ); } - public DomainCreator setVoiceStatusCallbackMethod(final HttpMethod voiceStatusCallbackMethod){ + + public DomainCreator setVoiceStatusCallbackMethod( + final HttpMethod voiceStatusCallbackMethod + ) { this.voiceStatusCallbackMethod = voiceStatusCallbackMethod; return this; } - public DomainCreator setSipRegistration(final Boolean sipRegistration){ + + public DomainCreator setSipRegistration(final Boolean sipRegistration) { this.sipRegistration = sipRegistration; return this; } - public DomainCreator setEmergencyCallingEnabled(final Boolean emergencyCallingEnabled){ + + public DomainCreator setEmergencyCallingEnabled( + final Boolean emergencyCallingEnabled + ) { this.emergencyCallingEnabled = emergencyCallingEnabled; return this; } - public DomainCreator setSecure(final Boolean secure){ + + public DomainCreator setSecure(final Boolean secure) { this.secure = secure; return this; } - public DomainCreator setByocTrunkSid(final String byocTrunkSid){ + + public DomainCreator setByocTrunkSid(final String byocTrunkSid) { this.byocTrunkSid = byocTrunkSid; return this; } - public DomainCreator setEmergencyCallerSid(final String emergencyCallerSid){ + + public DomainCreator setEmergencyCallerSid( + final String emergencyCallerSid + ) { this.emergencyCallerSid = emergencyCallerSid; return this; } @Override - public Domain create(final TwilioRestClient client){ + public Domain create(final TwilioRestClient client) { String path = "/2010-04-01/Accounts/{AccountSid}/SIP/Domains.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"DomainName"+"}", this.domainName.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace("{" + "DomainName" + "}", this.domainName.toString()); Request request = new Request( HttpMethod.POST, Domains.API.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Domain creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Domain creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -146,58 +186,61 @@ public Domain create(final TwilioRestClient client){ return Domain.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (domainName != null) { request.addPostParam("DomainName", domainName); - } if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (voiceUrl != null) { request.addPostParam("VoiceUrl", voiceUrl.toString()); - } if (voiceMethod != null) { request.addPostParam("VoiceMethod", voiceMethod.toString()); - } if (voiceFallbackUrl != null) { - request.addPostParam("VoiceFallbackUrl", voiceFallbackUrl.toString()); - + request.addPostParam( + "VoiceFallbackUrl", + voiceFallbackUrl.toString() + ); } if (voiceFallbackMethod != null) { - request.addPostParam("VoiceFallbackMethod", voiceFallbackMethod.toString()); - + request.addPostParam( + "VoiceFallbackMethod", + voiceFallbackMethod.toString() + ); } if (voiceStatusCallbackUrl != null) { - request.addPostParam("VoiceStatusCallbackUrl", voiceStatusCallbackUrl.toString()); - + request.addPostParam( + "VoiceStatusCallbackUrl", + voiceStatusCallbackUrl.toString() + ); } if (voiceStatusCallbackMethod != null) { - request.addPostParam("VoiceStatusCallbackMethod", voiceStatusCallbackMethod.toString()); - + request.addPostParam( + "VoiceStatusCallbackMethod", + voiceStatusCallbackMethod.toString() + ); } if (sipRegistration != null) { request.addPostParam("SipRegistration", sipRegistration.toString()); - } if (emergencyCallingEnabled != null) { - request.addPostParam("EmergencyCallingEnabled", emergencyCallingEnabled.toString()); - + request.addPostParam( + "EmergencyCallingEnabled", + emergencyCallingEnabled.toString() + ); } if (secure != null) { request.addPostParam("Secure", secure.toString()); - } if (byocTrunkSid != null) { request.addPostParam("ByocTrunkSid", byocTrunkSid); - } if (emergencyCallerSid != null) { request.addPostParam("EmergencyCallerSid", emergencyCallerSid); - } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/DomainDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/DomainDeleter.java index 8caa18e0c3..6b1d4eacbe 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/DomainDeleter.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/DomainDeleter.java @@ -24,28 +24,35 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class DomainDeleter extends Deleter { + private String pathSid; private String pathAccountSid; - public DomainDeleter(final String pathSid){ + public DomainDeleter(final String pathSid) { this.pathSid = pathSid; } - public DomainDeleter(final String pathAccountSid, final String pathSid){ + + public DomainDeleter(final String pathAccountSid, final String pathSid) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{Sid}.json"; + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -55,9 +62,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Domain delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Domain delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/DomainFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/DomainFetcher.java index d9764445aa..73e0fc3a29 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/DomainFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/DomainFetcher.java @@ -24,29 +24,35 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class DomainFetcher extends Fetcher { + private String pathSid; private String pathAccountSid; - public DomainFetcher(final String pathSid){ + public DomainFetcher(final String pathSid) { this.pathSid = pathSid; } - public DomainFetcher(final String pathAccountSid, final String pathSid){ + + public DomainFetcher(final String pathAccountSid, final String pathSid) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - @Override public Domain fetch(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{Sid}.json"; + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -56,9 +62,14 @@ public Domain fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Domain fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Domain fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/DomainReader.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/DomainReader.java index 184ae12764..18df3f75fc 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/DomainReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/DomainReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.api.v2010.account.sip; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,21 +25,19 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class DomainReader extends Reader { + private String pathAccountSid; private Integer pageSize; - public DomainReader(){ - } - public DomainReader(final String pathAccountSid){ + public DomainReader() {} + + public DomainReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - public DomainReader setPageSize(final Integer pageSize){ + public DomainReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -50,8 +49,15 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/2010-04-01/Accounts/{AccountSid}/SIP/Domains.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -63,13 +69,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Domain read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Domain read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -85,7 +99,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.API.toString()) @@ -93,9 +110,11 @@ public Page previousPage(final Page page, final TwilioRestClient return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.API.toString()) @@ -104,21 +123,21 @@ public Page nextPage(final Page page, final TwilioRestClient cli } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/DomainUpdater.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/DomainUpdater.java index 35cc8516a9..50a7f13367 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/DomainUpdater.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/DomainUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010.account.sip; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -24,12 +25,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.net.URI; +public class DomainUpdater extends Updater { - -public class DomainUpdater extends Updater{ private String pathSid; private String pathAccountSid; private String friendlyName; @@ -46,98 +45,139 @@ public class DomainUpdater extends Updater{ private String byocTrunkSid; private String emergencyCallerSid; - public DomainUpdater(final String pathSid){ + public DomainUpdater(final String pathSid) { this.pathSid = pathSid; } - public DomainUpdater(final String pathAccountSid, final String pathSid){ + + public DomainUpdater(final String pathAccountSid, final String pathSid) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - public DomainUpdater setFriendlyName(final String friendlyName){ + public DomainUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public DomainUpdater setVoiceFallbackMethod(final HttpMethod voiceFallbackMethod){ + + public DomainUpdater setVoiceFallbackMethod( + final HttpMethod voiceFallbackMethod + ) { this.voiceFallbackMethod = voiceFallbackMethod; return this; } - public DomainUpdater setVoiceFallbackUrl(final URI voiceFallbackUrl){ + + public DomainUpdater setVoiceFallbackUrl(final URI voiceFallbackUrl) { this.voiceFallbackUrl = voiceFallbackUrl; return this; } - public DomainUpdater setVoiceFallbackUrl(final String voiceFallbackUrl){ + public DomainUpdater setVoiceFallbackUrl(final String voiceFallbackUrl) { return setVoiceFallbackUrl(Promoter.uriFromString(voiceFallbackUrl)); } - public DomainUpdater setVoiceMethod(final HttpMethod voiceMethod){ + + public DomainUpdater setVoiceMethod(final HttpMethod voiceMethod) { this.voiceMethod = voiceMethod; return this; } - public DomainUpdater setVoiceStatusCallbackMethod(final HttpMethod voiceStatusCallbackMethod){ + + public DomainUpdater setVoiceStatusCallbackMethod( + final HttpMethod voiceStatusCallbackMethod + ) { this.voiceStatusCallbackMethod = voiceStatusCallbackMethod; return this; } - public DomainUpdater setVoiceStatusCallbackUrl(final URI voiceStatusCallbackUrl){ + + public DomainUpdater setVoiceStatusCallbackUrl( + final URI voiceStatusCallbackUrl + ) { this.voiceStatusCallbackUrl = voiceStatusCallbackUrl; return this; } - public DomainUpdater setVoiceStatusCallbackUrl(final String voiceStatusCallbackUrl){ - return setVoiceStatusCallbackUrl(Promoter.uriFromString(voiceStatusCallbackUrl)); + public DomainUpdater setVoiceStatusCallbackUrl( + final String voiceStatusCallbackUrl + ) { + return setVoiceStatusCallbackUrl( + Promoter.uriFromString(voiceStatusCallbackUrl) + ); } - public DomainUpdater setVoiceUrl(final URI voiceUrl){ + + public DomainUpdater setVoiceUrl(final URI voiceUrl) { this.voiceUrl = voiceUrl; return this; } - public DomainUpdater setVoiceUrl(final String voiceUrl){ + public DomainUpdater setVoiceUrl(final String voiceUrl) { return setVoiceUrl(Promoter.uriFromString(voiceUrl)); } - public DomainUpdater setSipRegistration(final Boolean sipRegistration){ + + public DomainUpdater setSipRegistration(final Boolean sipRegistration) { this.sipRegistration = sipRegistration; return this; } - public DomainUpdater setDomainName(final String domainName){ + + public DomainUpdater setDomainName(final String domainName) { this.domainName = domainName; return this; } - public DomainUpdater setEmergencyCallingEnabled(final Boolean emergencyCallingEnabled){ + + public DomainUpdater setEmergencyCallingEnabled( + final Boolean emergencyCallingEnabled + ) { this.emergencyCallingEnabled = emergencyCallingEnabled; return this; } - public DomainUpdater setSecure(final Boolean secure){ + + public DomainUpdater setSecure(final Boolean secure) { this.secure = secure; return this; } - public DomainUpdater setByocTrunkSid(final String byocTrunkSid){ + + public DomainUpdater setByocTrunkSid(final String byocTrunkSid) { this.byocTrunkSid = byocTrunkSid; return this; } - public DomainUpdater setEmergencyCallerSid(final String emergencyCallerSid){ + + public DomainUpdater setEmergencyCallerSid( + final String emergencyCallerSid + ) { this.emergencyCallerSid = emergencyCallerSid; return this; } @Override - public Domain update(final TwilioRestClient client){ - String path = "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{Sid}.json"; + public Domain update(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.API.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Domain update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Domain update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -146,58 +186,61 @@ public Domain update(final TwilioRestClient client){ return Domain.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (voiceFallbackMethod != null) { - request.addPostParam("VoiceFallbackMethod", voiceFallbackMethod.toString()); - + request.addPostParam( + "VoiceFallbackMethod", + voiceFallbackMethod.toString() + ); } if (voiceFallbackUrl != null) { - request.addPostParam("VoiceFallbackUrl", voiceFallbackUrl.toString()); - + request.addPostParam( + "VoiceFallbackUrl", + voiceFallbackUrl.toString() + ); } if (voiceMethod != null) { request.addPostParam("VoiceMethod", voiceMethod.toString()); - } if (voiceStatusCallbackMethod != null) { - request.addPostParam("VoiceStatusCallbackMethod", voiceStatusCallbackMethod.toString()); - + request.addPostParam( + "VoiceStatusCallbackMethod", + voiceStatusCallbackMethod.toString() + ); } if (voiceStatusCallbackUrl != null) { - request.addPostParam("VoiceStatusCallbackUrl", voiceStatusCallbackUrl.toString()); - + request.addPostParam( + "VoiceStatusCallbackUrl", + voiceStatusCallbackUrl.toString() + ); } if (voiceUrl != null) { request.addPostParam("VoiceUrl", voiceUrl.toString()); - } if (sipRegistration != null) { request.addPostParam("SipRegistration", sipRegistration.toString()); - } if (domainName != null) { request.addPostParam("DomainName", domainName); - } if (emergencyCallingEnabled != null) { - request.addPostParam("EmergencyCallingEnabled", emergencyCallingEnabled.toString()); - + request.addPostParam( + "EmergencyCallingEnabled", + emergencyCallingEnabled.toString() + ); } if (secure != null) { request.addPostParam("Secure", secure.toString()); - } if (byocTrunkSid != null) { request.addPostParam("ByocTrunkSid", byocTrunkSid); - } if (emergencyCallerSid != null) { request.addPostParam("EmergencyCallerSid", emergencyCallerSid); - } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/IpAccessControlList.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/IpAccessControlList.java index 76839e9ffe..27fba3b8fd 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/IpAccessControlList.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/IpAccessControlList.java @@ -23,69 +23,97 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class IpAccessControlList extends Resource { + private static final long serialVersionUID = 178395545365846L; - public static IpAccessControlListCreator creator(final String friendlyName){ + public static IpAccessControlListCreator creator( + final String friendlyName + ) { return new IpAccessControlListCreator(friendlyName); } - public static IpAccessControlListCreator creator(final String pathAccountSid, final String friendlyName){ + + public static IpAccessControlListCreator creator( + final String pathAccountSid, + final String friendlyName + ) { return new IpAccessControlListCreator(pathAccountSid, friendlyName); } - public static IpAccessControlListDeleter deleter(final String pathSid){ + public static IpAccessControlListDeleter deleter(final String pathSid) { return new IpAccessControlListDeleter(pathSid); } - public static IpAccessControlListDeleter deleter(final String pathAccountSid, final String pathSid){ + + public static IpAccessControlListDeleter deleter( + final String pathAccountSid, + final String pathSid + ) { return new IpAccessControlListDeleter(pathAccountSid, pathSid); } - public static IpAccessControlListFetcher fetcher(final String pathSid){ + public static IpAccessControlListFetcher fetcher(final String pathSid) { return new IpAccessControlListFetcher(pathSid); } - public static IpAccessControlListFetcher fetcher(final String pathAccountSid, final String pathSid){ + + public static IpAccessControlListFetcher fetcher( + final String pathAccountSid, + final String pathSid + ) { return new IpAccessControlListFetcher(pathAccountSid, pathSid); } - public static IpAccessControlListReader reader(){ + public static IpAccessControlListReader reader() { return new IpAccessControlListReader(); } - public static IpAccessControlListReader reader(final String pathAccountSid){ + + public static IpAccessControlListReader reader( + final String pathAccountSid + ) { return new IpAccessControlListReader(pathAccountSid); } - public static IpAccessControlListUpdater updater(final String pathSid, final String friendlyName){ + public static IpAccessControlListUpdater updater( + final String pathSid, + final String friendlyName + ) { return new IpAccessControlListUpdater(pathSid, friendlyName); } - public static IpAccessControlListUpdater updater(final String pathAccountSid, final String pathSid, final String friendlyName){ - return new IpAccessControlListUpdater(pathAccountSid, pathSid, friendlyName); + + public static IpAccessControlListUpdater updater( + final String pathAccountSid, + final String pathSid, + final String friendlyName + ) { + return new IpAccessControlListUpdater( + pathAccountSid, + pathSid, + friendlyName + ); } /** - * Converts a JSON String into a IpAccessControlList object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return IpAccessControlList object represented by the provided JSON - */ - public static IpAccessControlList fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a IpAccessControlList object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return IpAccessControlList object represented by the provided JSON + */ + public static IpAccessControlList fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, IpAccessControlList.class); @@ -97,14 +125,17 @@ public static IpAccessControlList fromJson(final String json, final ObjectMapper } /** - * Converts a JSON InputStream into a IpAccessControlList object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return IpAccessControlList object represented by the provided JSON - */ - public static IpAccessControlList fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a IpAccessControlList object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return IpAccessControlList object represented by the provided JSON + */ + public static IpAccessControlList fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, IpAccessControlList.class); @@ -125,26 +156,15 @@ public static IpAccessControlList fromJson(final InputStream json, final ObjectM @JsonCreator private IpAccessControlList( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("subresource_uris") - final Map subresourceUris, - - @JsonProperty("uri") - final String uri + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty( + "subresource_uris" + ) final Map subresourceUris, + @JsonProperty("uri") final String uri ) { this.sid = sid; this.accountSid = accountSid; @@ -155,31 +175,37 @@ private IpAccessControlList( this.uri = uri; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final Map getSubresourceUris() { - return this.subresourceUris; - } - public final String getUri() { - return this.uri; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final Map getSubresourceUris() { + return this.subresourceUris; + } + + public final String getUri() { + return this.uri; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -189,13 +215,27 @@ public boolean equals(final Object o) { IpAccessControlList other = (IpAccessControlList) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(subresourceUris, other.subresourceUris) && Objects.equals(uri, other.uri) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(subresourceUris, other.subresourceUris) && + Objects.equals(uri, other.uri) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, friendlyName, dateCreated, dateUpdated, subresourceUris, uri); + return Objects.hash( + sid, + accountSid, + friendlyName, + dateCreated, + dateUpdated, + subresourceUris, + uri + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/IpAccessControlListCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/IpAccessControlListCreator.java index f54caf1045..4c6c493f90 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/IpAccessControlListCreator.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/IpAccessControlListCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010.account.sip; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,57 +25,82 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class IpAccessControlListCreator extends Creator { - - -public class IpAccessControlListCreator extends Creator{ private String friendlyName; private String pathAccountSid; public IpAccessControlListCreator(final String friendlyName) { this.friendlyName = friendlyName; } - public IpAccessControlListCreator(final String pathAccountSid, final String friendlyName) { + + public IpAccessControlListCreator( + final String pathAccountSid, + final String friendlyName + ) { this.pathAccountSid = pathAccountSid; this.friendlyName = friendlyName; } - public IpAccessControlListCreator setFriendlyName(final String friendlyName){ + public IpAccessControlListCreator setFriendlyName( + final String friendlyName + ) { this.friendlyName = friendlyName; return this; } @Override - public IpAccessControlList create(final TwilioRestClient client){ - String path = "/2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists.json"; + public IpAccessControlList create(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"FriendlyName"+"}", this.friendlyName.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "FriendlyName" + "}", + this.friendlyName.toString() + ); Request request = new Request( HttpMethod.POST, Domains.API.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("IpAccessControlList creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "IpAccessControlList creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return IpAccessControlList.fromJson(response.getStream(), client.getObjectMapper()); + return IpAccessControlList.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/IpAccessControlListDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/IpAccessControlListDeleter.java index cc96d652c6..b54d0529b7 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/IpAccessControlListDeleter.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/IpAccessControlListDeleter.java @@ -24,28 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class IpAccessControlListDeleter extends Deleter { + private String pathSid; private String pathAccountSid; - public IpAccessControlListDeleter(final String pathSid){ + public IpAccessControlListDeleter(final String pathSid) { this.pathSid = pathSid; } - public IpAccessControlListDeleter(final String pathAccountSid, final String pathSid){ + + public IpAccessControlListDeleter( + final String pathAccountSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists/{Sid}.json"; + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -55,9 +65,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("IpAccessControlList delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "IpAccessControlList delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/IpAccessControlListFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/IpAccessControlListFetcher.java index 40744de600..b4539aacaa 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/IpAccessControlListFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/IpAccessControlListFetcher.java @@ -24,29 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class IpAccessControlListFetcher extends Fetcher { + private String pathSid; private String pathAccountSid; - public IpAccessControlListFetcher(final String pathSid){ + public IpAccessControlListFetcher(final String pathSid) { this.pathSid = pathSid; } - public IpAccessControlListFetcher(final String pathAccountSid, final String pathSid){ + + public IpAccessControlListFetcher( + final String pathAccountSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - @Override public IpAccessControlList fetch(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists/{Sid}.json"; + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -56,15 +65,23 @@ public IpAccessControlList fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("IpAccessControlList fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "IpAccessControlList fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return IpAccessControlList.fromJson(response.getStream(), client.getObjectMapper()); + return IpAccessControlList.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/IpAccessControlListReader.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/IpAccessControlListReader.java index 91bb664505..f51a2e3030 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/IpAccessControlListReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/IpAccessControlListReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.api.v2010.account.sip; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,34 +25,42 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class IpAccessControlListReader extends Reader { + private String pathAccountSid; private Integer pageSize; - public IpAccessControlListReader(){ - } - public IpAccessControlListReader(final String pathAccountSid){ + public IpAccessControlListReader() {} + + public IpAccessControlListReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - public IpAccessControlListReader setPageSize(final Integer pageSize){ + public IpAccessControlListReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @Override - public ResourceSet read(final TwilioRestClient client) { + public ResourceSet read( + final TwilioRestClient client + ) { return new ResourceSet<>(this, client, firstPage(client)); } public Page firstPage(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists.json"; + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -63,13 +72,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("IpAccessControlList read failed: Unable to connect to server"); + throw new ApiConnectionException( + "IpAccessControlList read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -85,7 +102,10 @@ private Page pageForRequest(final TwilioRestClient client, } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.API.toString()) @@ -93,9 +113,11 @@ public Page previousPage(final Page pa return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.API.toString()) @@ -104,21 +126,21 @@ public Page nextPage(final Page page, } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/IpAccessControlListUpdater.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/IpAccessControlListUpdater.java index 3e046a4e41..f3e8587506 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/IpAccessControlListUpdater.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/IpAccessControlListUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010.account.sip; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,61 +25,90 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class IpAccessControlListUpdater extends Updater { - - -public class IpAccessControlListUpdater extends Updater{ private String pathSid; private String friendlyName; private String pathAccountSid; - public IpAccessControlListUpdater(final String pathSid, final String friendlyName){ + public IpAccessControlListUpdater( + final String pathSid, + final String friendlyName + ) { this.pathSid = pathSid; this.friendlyName = friendlyName; } - public IpAccessControlListUpdater(final String pathAccountSid, final String pathSid, final String friendlyName){ + + public IpAccessControlListUpdater( + final String pathAccountSid, + final String pathSid, + final String friendlyName + ) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; this.friendlyName = friendlyName; } - public IpAccessControlListUpdater setFriendlyName(final String friendlyName){ + public IpAccessControlListUpdater setFriendlyName( + final String friendlyName + ) { this.friendlyName = friendlyName; return this; } @Override - public IpAccessControlList update(final TwilioRestClient client){ - String path = "/2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists/{Sid}.json"; + public IpAccessControlList update(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); - path = path.replace("{"+"FriendlyName"+"}", this.friendlyName.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + path = + path.replace( + "{" + "FriendlyName" + "}", + this.friendlyName.toString() + ); Request request = new Request( HttpMethod.POST, Domains.API.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("IpAccessControlList update failed: Unable to connect to server"); + throw new ApiConnectionException( + "IpAccessControlList update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return IpAccessControlList.fromJson(response.getStream(), client.getObjectMapper()); + return IpAccessControlList.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/credentiallist/Credential.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/credentiallist/Credential.java index 44919e878e..a249e91e92 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/credentiallist/Credential.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/credentiallist/Credential.java @@ -23,67 +23,121 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Credential extends Resource { + private static final long serialVersionUID = 238688210273177L; - public static CredentialCreator creator(final String pathCredentialListSid, final String username, final String password){ + public static CredentialCreator creator( + final String pathCredentialListSid, + final String username, + final String password + ) { return new CredentialCreator(pathCredentialListSid, username, password); } - public static CredentialCreator creator(final String pathAccountSid, final String pathCredentialListSid, final String username, final String password){ - return new CredentialCreator(pathAccountSid, pathCredentialListSid, username, password); + + public static CredentialCreator creator( + final String pathAccountSid, + final String pathCredentialListSid, + final String username, + final String password + ) { + return new CredentialCreator( + pathAccountSid, + pathCredentialListSid, + username, + password + ); } - public static CredentialDeleter deleter(final String pathCredentialListSid, final String pathSid){ + public static CredentialDeleter deleter( + final String pathCredentialListSid, + final String pathSid + ) { return new CredentialDeleter(pathCredentialListSid, pathSid); } - public static CredentialDeleter deleter(final String pathAccountSid, final String pathCredentialListSid, final String pathSid){ - return new CredentialDeleter(pathAccountSid, pathCredentialListSid, pathSid); + + public static CredentialDeleter deleter( + final String pathAccountSid, + final String pathCredentialListSid, + final String pathSid + ) { + return new CredentialDeleter( + pathAccountSid, + pathCredentialListSid, + pathSid + ); } - public static CredentialFetcher fetcher(final String pathCredentialListSid, final String pathSid){ + public static CredentialFetcher fetcher( + final String pathCredentialListSid, + final String pathSid + ) { return new CredentialFetcher(pathCredentialListSid, pathSid); } - public static CredentialFetcher fetcher(final String pathAccountSid, final String pathCredentialListSid, final String pathSid){ - return new CredentialFetcher(pathAccountSid, pathCredentialListSid, pathSid); + + public static CredentialFetcher fetcher( + final String pathAccountSid, + final String pathCredentialListSid, + final String pathSid + ) { + return new CredentialFetcher( + pathAccountSid, + pathCredentialListSid, + pathSid + ); } - public static CredentialReader reader(final String pathCredentialListSid){ + public static CredentialReader reader(final String pathCredentialListSid) { return new CredentialReader(pathCredentialListSid); } - public static CredentialReader reader(final String pathAccountSid, final String pathCredentialListSid){ + + public static CredentialReader reader( + final String pathAccountSid, + final String pathCredentialListSid + ) { return new CredentialReader(pathAccountSid, pathCredentialListSid); } - public static CredentialUpdater updater(final String pathCredentialListSid, final String pathSid){ + public static CredentialUpdater updater( + final String pathCredentialListSid, + final String pathSid + ) { return new CredentialUpdater(pathCredentialListSid, pathSid); } - public static CredentialUpdater updater(final String pathAccountSid, final String pathCredentialListSid, final String pathSid){ - return new CredentialUpdater(pathAccountSid, pathCredentialListSid, pathSid); + + public static CredentialUpdater updater( + final String pathAccountSid, + final String pathCredentialListSid, + final String pathSid + ) { + return new CredentialUpdater( + pathAccountSid, + pathCredentialListSid, + pathSid + ); } /** - * Converts a JSON String into a Credential object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Credential object represented by the provided JSON - */ - public static Credential fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Credential object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Credential object represented by the provided JSON + */ + public static Credential fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Credential.class); @@ -95,14 +149,17 @@ public static Credential fromJson(final String json, final ObjectMapper objectMa } /** - * Converts a JSON InputStream into a Credential object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Credential object represented by the provided JSON - */ - public static Credential fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Credential object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Credential object represented by the provided JSON + */ + public static Credential fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Credential.class); @@ -123,26 +180,13 @@ public static Credential fromJson(final InputStream json, final ObjectMapper obj @JsonCreator private Credential( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("credential_list_sid") - final String credentialListSid, - - @JsonProperty("username") - final String username, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("uri") - final String uri + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("credential_list_sid") final String credentialListSid, + @JsonProperty("username") final String username, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("uri") final String uri ) { this.sid = sid; this.accountSid = accountSid; @@ -153,31 +197,37 @@ private Credential( this.uri = uri; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getCredentialListSid() { - return this.credentialListSid; - } - public final String getUsername() { - return this.username; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getUri() { - return this.uri; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getCredentialListSid() { + return this.credentialListSid; + } + + public final String getUsername() { + return this.username; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getUri() { + return this.uri; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -187,13 +237,27 @@ public boolean equals(final Object o) { Credential other = (Credential) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(credentialListSid, other.credentialListSid) && Objects.equals(username, other.username) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(uri, other.uri) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(credentialListSid, other.credentialListSid) && + Objects.equals(username, other.username) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(uri, other.uri) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, credentialListSid, username, dateCreated, dateUpdated, uri); + return Objects.hash( + sid, + accountSid, + credentialListSid, + username, + dateCreated, + dateUpdated, + uri + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/credentiallist/CredentialCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/credentiallist/CredentialCreator.java index 94b93cbe92..d11c0111ed 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/credentiallist/CredentialCreator.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/credentiallist/CredentialCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010.account.sip.credentiallist; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,73 +25,102 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class CredentialCreator extends Creator { - - -public class CredentialCreator extends Creator{ private String pathCredentialListSid; private String username; private String password; private String pathAccountSid; - public CredentialCreator(final String pathCredentialListSid, final String username, final String password) { + public CredentialCreator( + final String pathCredentialListSid, + final String username, + final String password + ) { this.pathCredentialListSid = pathCredentialListSid; this.username = username; this.password = password; } - public CredentialCreator(final String pathAccountSid, final String pathCredentialListSid, final String username, final String password) { + + public CredentialCreator( + final String pathAccountSid, + final String pathCredentialListSid, + final String username, + final String password + ) { this.pathAccountSid = pathAccountSid; this.pathCredentialListSid = pathCredentialListSid; this.username = username; this.password = password; } - public CredentialCreator setUsername(final String username){ + public CredentialCreator setUsername(final String username) { this.username = username; return this; } - public CredentialCreator setPassword(final String password){ + + public CredentialCreator setPassword(final String password) { this.password = password; return this; } @Override - public Credential create(final TwilioRestClient client){ - String path = "/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists/{CredentialListSid}/Credentials.json"; + public Credential create(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists/{CredentialListSid}/Credentials.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"CredentialListSid"+"}", this.pathCredentialListSid.toString()); - path = path.replace("{"+"Username"+"}", this.username.toString()); - path = path.replace("{"+"Password"+"}", this.password.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "CredentialListSid" + "}", + this.pathCredentialListSid.toString() + ); + path = path.replace("{" + "Username" + "}", this.username.toString()); + path = path.replace("{" + "Password" + "}", this.password.toString()); Request request = new Request( HttpMethod.POST, Domains.API.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Credential creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Credential creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Credential.fromJson(response.getStream(), client.getObjectMapper()); + return Credential.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (username != null) { request.addPostParam("Username", username); - } if (password != null) { request.addPostParam("Password", password); - } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/credentiallist/CredentialDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/credentiallist/CredentialDeleter.java index 3fb60c4d4a..177b1a31c7 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/credentiallist/CredentialDeleter.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/credentiallist/CredentialDeleter.java @@ -24,32 +24,50 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class CredentialDeleter extends Deleter { + private String pathCredentialListSid; private String pathSid; private String pathAccountSid; - public CredentialDeleter(final String pathCredentialListSid, final String pathSid){ + public CredentialDeleter( + final String pathCredentialListSid, + final String pathSid + ) { this.pathCredentialListSid = pathCredentialListSid; this.pathSid = pathSid; } - public CredentialDeleter(final String pathAccountSid, final String pathCredentialListSid, final String pathSid){ + + public CredentialDeleter( + final String pathAccountSid, + final String pathCredentialListSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathCredentialListSid = pathCredentialListSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists/{CredentialListSid}/Credentials/{Sid}.json"; + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists/{CredentialListSid}/Credentials/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"CredentialListSid"+"}", this.pathCredentialListSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "CredentialListSid" + "}", + this.pathCredentialListSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -59,9 +77,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Credential delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Credential delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/credentiallist/CredentialFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/credentiallist/CredentialFetcher.java index 2a75ec9b27..eff2181e22 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/credentiallist/CredentialFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/credentiallist/CredentialFetcher.java @@ -24,33 +24,50 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class CredentialFetcher extends Fetcher { + private String pathCredentialListSid; private String pathSid; private String pathAccountSid; - public CredentialFetcher(final String pathCredentialListSid, final String pathSid){ + public CredentialFetcher( + final String pathCredentialListSid, + final String pathSid + ) { this.pathCredentialListSid = pathCredentialListSid; this.pathSid = pathSid; } - public CredentialFetcher(final String pathAccountSid, final String pathCredentialListSid, final String pathSid){ + + public CredentialFetcher( + final String pathAccountSid, + final String pathCredentialListSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathCredentialListSid = pathCredentialListSid; this.pathSid = pathSid; } - @Override public Credential fetch(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists/{CredentialListSid}/Credentials/{Sid}.json"; + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists/{CredentialListSid}/Credentials/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"CredentialListSid"+"}", this.pathCredentialListSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "CredentialListSid" + "}", + this.pathCredentialListSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -60,15 +77,23 @@ public Credential fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Credential fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Credential fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Credential.fromJson(response.getStream(), client.getObjectMapper()); + return Credential.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/credentiallist/CredentialReader.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/credentiallist/CredentialReader.java index 8efd925b6a..04a06133d5 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/credentiallist/CredentialReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/credentiallist/CredentialReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.api.v2010.account.sip.credentiallist; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,24 +25,26 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class CredentialReader extends Reader { + private String pathCredentialListSid; private String pathAccountSid; private Integer pageSize; - public CredentialReader(final String pathCredentialListSid){ + public CredentialReader(final String pathCredentialListSid) { this.pathCredentialListSid = pathCredentialListSid; } - public CredentialReader(final String pathAccountSid, final String pathCredentialListSid){ + + public CredentialReader( + final String pathAccountSid, + final String pathCredentialListSid + ) { this.pathAccountSid = pathAccountSid; this.pathCredentialListSid = pathCredentialListSid; } - public CredentialReader setPageSize(final Integer pageSize){ + public CredentialReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -52,10 +55,22 @@ public ResourceSet read(final TwilioRestClient client) { } public Page firstPage(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists/{CredentialListSid}/Credentials.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"CredentialListSid"+"}", this.pathCredentialListSid.toString()); + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists/{CredentialListSid}/Credentials.json"; + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "CredentialListSid" + "}", + this.pathCredentialListSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -67,13 +82,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Credential read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Credential read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -89,7 +112,10 @@ private Page pageForRequest(final TwilioRestClient client, final Req } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.API.toString()) @@ -97,9 +123,11 @@ public Page previousPage(final Page page, final TwilioRe return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.API.toString()) @@ -108,21 +136,21 @@ public Page nextPage(final Page page, final TwilioRestCl } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/credentiallist/CredentialUpdater.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/credentiallist/CredentialUpdater.java index 482b000421..18e325f5eb 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/credentiallist/CredentialUpdater.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/credentiallist/CredentialUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010.account.sip.credentiallist; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,62 +25,89 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class CredentialUpdater extends Updater { - - -public class CredentialUpdater extends Updater{ private String pathCredentialListSid; private String pathSid; private String pathAccountSid; private String password; - public CredentialUpdater(final String pathCredentialListSid, final String pathSid){ + public CredentialUpdater( + final String pathCredentialListSid, + final String pathSid + ) { this.pathCredentialListSid = pathCredentialListSid; this.pathSid = pathSid; } - public CredentialUpdater(final String pathAccountSid, final String pathCredentialListSid, final String pathSid){ + + public CredentialUpdater( + final String pathAccountSid, + final String pathCredentialListSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathCredentialListSid = pathCredentialListSid; this.pathSid = pathSid; } - public CredentialUpdater setPassword(final String password){ + public CredentialUpdater setPassword(final String password) { this.password = password; return this; } @Override - public Credential update(final TwilioRestClient client){ - String path = "/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists/{CredentialListSid}/Credentials/{Sid}.json"; + public Credential update(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists/{CredentialListSid}/Credentials/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"CredentialListSid"+"}", this.pathCredentialListSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "CredentialListSid" + "}", + this.pathCredentialListSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.API.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Credential update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Credential update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Credential.fromJson(response.getStream(), client.getObjectMapper()); + return Credential.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (password != null) { request.addPostParam("Password", password); - } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/CredentialListMapping.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/CredentialListMapping.java index 96f42e7c8b..090d71d493 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/CredentialListMapping.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/CredentialListMapping.java @@ -23,60 +23,104 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class CredentialListMapping extends Resource { + private static final long serialVersionUID = 220550473371145L; - public static CredentialListMappingCreator creator(final String pathDomainSid, final String credentialListSid){ - return new CredentialListMappingCreator(pathDomainSid, credentialListSid); + public static CredentialListMappingCreator creator( + final String pathDomainSid, + final String credentialListSid + ) { + return new CredentialListMappingCreator( + pathDomainSid, + credentialListSid + ); } - public static CredentialListMappingCreator creator(final String pathAccountSid, final String pathDomainSid, final String credentialListSid){ - return new CredentialListMappingCreator(pathAccountSid, pathDomainSid, credentialListSid); + + public static CredentialListMappingCreator creator( + final String pathAccountSid, + final String pathDomainSid, + final String credentialListSid + ) { + return new CredentialListMappingCreator( + pathAccountSid, + pathDomainSid, + credentialListSid + ); } - public static CredentialListMappingDeleter deleter(final String pathDomainSid, final String pathSid){ + public static CredentialListMappingDeleter deleter( + final String pathDomainSid, + final String pathSid + ) { return new CredentialListMappingDeleter(pathDomainSid, pathSid); } - public static CredentialListMappingDeleter deleter(final String pathAccountSid, final String pathDomainSid, final String pathSid){ - return new CredentialListMappingDeleter(pathAccountSid, pathDomainSid, pathSid); + + public static CredentialListMappingDeleter deleter( + final String pathAccountSid, + final String pathDomainSid, + final String pathSid + ) { + return new CredentialListMappingDeleter( + pathAccountSid, + pathDomainSid, + pathSid + ); } - public static CredentialListMappingFetcher fetcher(final String pathDomainSid, final String pathSid){ + public static CredentialListMappingFetcher fetcher( + final String pathDomainSid, + final String pathSid + ) { return new CredentialListMappingFetcher(pathDomainSid, pathSid); } - public static CredentialListMappingFetcher fetcher(final String pathAccountSid, final String pathDomainSid, final String pathSid){ - return new CredentialListMappingFetcher(pathAccountSid, pathDomainSid, pathSid); + + public static CredentialListMappingFetcher fetcher( + final String pathAccountSid, + final String pathDomainSid, + final String pathSid + ) { + return new CredentialListMappingFetcher( + pathAccountSid, + pathDomainSid, + pathSid + ); } - public static CredentialListMappingReader reader(final String pathDomainSid){ + public static CredentialListMappingReader reader( + final String pathDomainSid + ) { return new CredentialListMappingReader(pathDomainSid); } - public static CredentialListMappingReader reader(final String pathAccountSid, final String pathDomainSid){ + + public static CredentialListMappingReader reader( + final String pathAccountSid, + final String pathDomainSid + ) { return new CredentialListMappingReader(pathAccountSid, pathDomainSid); } /** - * Converts a JSON String into a CredentialListMapping object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return CredentialListMapping object represented by the provided JSON - */ - public static CredentialListMapping fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a CredentialListMapping object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return CredentialListMapping object represented by the provided JSON + */ + public static CredentialListMapping fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, CredentialListMapping.class); @@ -88,14 +132,17 @@ public static CredentialListMapping fromJson(final String json, final ObjectMapp } /** - * Converts a JSON InputStream into a CredentialListMapping object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return CredentialListMapping object represented by the provided JSON - */ - public static CredentialListMapping fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a CredentialListMapping object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return CredentialListMapping object represented by the provided JSON + */ + public static CredentialListMapping fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, CredentialListMapping.class); @@ -116,26 +163,13 @@ public static CredentialListMapping fromJson(final InputStream json, final Objec @JsonCreator private CredentialListMapping( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("domain_sid") - final String domainSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("uri") - final String uri + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("domain_sid") final String domainSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("sid") final String sid, + @JsonProperty("uri") final String uri ) { this.accountSid = accountSid; this.dateCreated = DateConverter.rfc2822DateTimeFromString(dateCreated); @@ -146,31 +180,37 @@ private CredentialListMapping( this.uri = uri; } - public final String getAccountSid() { - return this.accountSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getDomainSid() { - return this.domainSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getSid() { - return this.sid; - } - public final String getUri() { - return this.uri; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getDomainSid() { + return this.domainSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getSid() { + return this.sid; + } + + public final String getUri() { + return this.uri; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -180,13 +220,27 @@ public boolean equals(final Object o) { CredentialListMapping other = (CredentialListMapping) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(domainSid, other.domainSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(sid, other.sid) && Objects.equals(uri, other.uri) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(domainSid, other.domainSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(sid, other.sid) && + Objects.equals(uri, other.uri) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, dateCreated, dateUpdated, domainSid, friendlyName, sid, uri); + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + domainSid, + friendlyName, + sid, + uri + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/CredentialListMappingCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/CredentialListMappingCreator.java index 5f880134e9..69863c7e5a 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/CredentialListMappingCreator.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/CredentialListMappingCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010.account.sip.domain; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,61 +25,95 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class CredentialListMappingCreator + extends Creator { - - -public class CredentialListMappingCreator extends Creator{ private String pathDomainSid; private String credentialListSid; private String pathAccountSid; - public CredentialListMappingCreator(final String pathDomainSid, final String credentialListSid) { + public CredentialListMappingCreator( + final String pathDomainSid, + final String credentialListSid + ) { this.pathDomainSid = pathDomainSid; this.credentialListSid = credentialListSid; } - public CredentialListMappingCreator(final String pathAccountSid, final String pathDomainSid, final String credentialListSid) { + + public CredentialListMappingCreator( + final String pathAccountSid, + final String pathDomainSid, + final String credentialListSid + ) { this.pathAccountSid = pathAccountSid; this.pathDomainSid = pathDomainSid; this.credentialListSid = credentialListSid; } - public CredentialListMappingCreator setCredentialListSid(final String credentialListSid){ + public CredentialListMappingCreator setCredentialListSid( + final String credentialListSid + ) { this.credentialListSid = credentialListSid; return this; } @Override - public CredentialListMapping create(final TwilioRestClient client){ - String path = "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/CredentialListMappings.json"; + public CredentialListMapping create(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/CredentialListMappings.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"DomainSid"+"}", this.pathDomainSid.toString()); - path = path.replace("{"+"CredentialListSid"+"}", this.credentialListSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "DomainSid" + "}", + this.pathDomainSid.toString() + ); + path = + path.replace( + "{" + "CredentialListSid" + "}", + this.credentialListSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.API.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("CredentialListMapping creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "CredentialListMapping creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return CredentialListMapping.fromJson(response.getStream(), client.getObjectMapper()); + return CredentialListMapping.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (credentialListSid != null) { request.addPostParam("CredentialListSid", credentialListSid); - } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/CredentialListMappingDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/CredentialListMappingDeleter.java index ce7c25bb55..10485eddea 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/CredentialListMappingDeleter.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/CredentialListMappingDeleter.java @@ -24,32 +24,51 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class CredentialListMappingDeleter + extends Deleter { - -public class CredentialListMappingDeleter extends Deleter { private String pathDomainSid; private String pathSid; private String pathAccountSid; - public CredentialListMappingDeleter(final String pathDomainSid, final String pathSid){ + public CredentialListMappingDeleter( + final String pathDomainSid, + final String pathSid + ) { this.pathDomainSid = pathDomainSid; this.pathSid = pathSid; } - public CredentialListMappingDeleter(final String pathAccountSid, final String pathDomainSid, final String pathSid){ + + public CredentialListMappingDeleter( + final String pathAccountSid, + final String pathDomainSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathDomainSid = pathDomainSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/CredentialListMappings/{Sid}.json"; + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/CredentialListMappings/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"DomainSid"+"}", this.pathDomainSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "DomainSid" + "}", + this.pathDomainSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -59,9 +78,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("CredentialListMapping delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "CredentialListMapping delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/CredentialListMappingFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/CredentialListMappingFetcher.java index e4a3e027cc..580a438b7e 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/CredentialListMappingFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/CredentialListMappingFetcher.java @@ -24,33 +24,51 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class CredentialListMappingFetcher + extends Fetcher { - - -public class CredentialListMappingFetcher extends Fetcher { private String pathDomainSid; private String pathSid; private String pathAccountSid; - public CredentialListMappingFetcher(final String pathDomainSid, final String pathSid){ + public CredentialListMappingFetcher( + final String pathDomainSid, + final String pathSid + ) { this.pathDomainSid = pathDomainSid; this.pathSid = pathSid; } - public CredentialListMappingFetcher(final String pathAccountSid, final String pathDomainSid, final String pathSid){ + + public CredentialListMappingFetcher( + final String pathAccountSid, + final String pathDomainSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathDomainSid = pathDomainSid; this.pathSid = pathSid; } - @Override public CredentialListMapping fetch(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/CredentialListMappings/{Sid}.json"; + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/CredentialListMappings/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"DomainSid"+"}", this.pathDomainSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "DomainSid" + "}", + this.pathDomainSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -60,15 +78,23 @@ public CredentialListMapping fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("CredentialListMapping fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "CredentialListMapping fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return CredentialListMapping.fromJson(response.getStream(), client.getObjectMapper()); + return CredentialListMapping.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/CredentialListMappingReader.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/CredentialListMappingReader.java index eaca2e5d32..5a816722ba 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/CredentialListMappingReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/CredentialListMappingReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.api.v2010.account.sip.domain; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,38 +25,56 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class CredentialListMappingReader extends Reader { + private String pathDomainSid; private String pathAccountSid; private Integer pageSize; - public CredentialListMappingReader(final String pathDomainSid){ + public CredentialListMappingReader(final String pathDomainSid) { this.pathDomainSid = pathDomainSid; } - public CredentialListMappingReader(final String pathAccountSid, final String pathDomainSid){ + + public CredentialListMappingReader( + final String pathAccountSid, + final String pathDomainSid + ) { this.pathAccountSid = pathAccountSid; this.pathDomainSid = pathDomainSid; } - public CredentialListMappingReader setPageSize(final Integer pageSize){ + public CredentialListMappingReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @Override - public ResourceSet read(final TwilioRestClient client) { + public ResourceSet read( + final TwilioRestClient client + ) { return new ResourceSet<>(this, client, firstPage(client)); } - public Page firstPage(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/CredentialListMappings.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"DomainSid"+"}", this.pathDomainSid.toString()); + public Page firstPage( + final TwilioRestClient client + ) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/CredentialListMappings.json"; + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "DomainSid" + "}", + this.pathDomainSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -67,13 +86,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("CredentialListMapping read failed: Unable to connect to server"); + throw new ApiConnectionException( + "CredentialListMapping read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -89,7 +116,10 @@ private Page pageForRequest(final TwilioRestClient client } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.API.toString()) @@ -97,9 +127,11 @@ public Page previousPage(final Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.API.toString()) @@ -108,21 +140,21 @@ public Page nextPage(final Page pa } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/IpAccessControlListMapping.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/IpAccessControlListMapping.java index 7ee8d155eb..a1e6f04654 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/IpAccessControlListMapping.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/IpAccessControlListMapping.java @@ -23,63 +23,113 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class IpAccessControlListMapping extends Resource { + private static final long serialVersionUID = 220550473371145L; - public static IpAccessControlListMappingCreator creator(final String pathDomainSid, final String ipAccessControlListSid){ - return new IpAccessControlListMappingCreator(pathDomainSid, ipAccessControlListSid); + public static IpAccessControlListMappingCreator creator( + final String pathDomainSid, + final String ipAccessControlListSid + ) { + return new IpAccessControlListMappingCreator( + pathDomainSid, + ipAccessControlListSid + ); } - public static IpAccessControlListMappingCreator creator(final String pathAccountSid, final String pathDomainSid, final String ipAccessControlListSid){ - return new IpAccessControlListMappingCreator(pathAccountSid, pathDomainSid, ipAccessControlListSid); + + public static IpAccessControlListMappingCreator creator( + final String pathAccountSid, + final String pathDomainSid, + final String ipAccessControlListSid + ) { + return new IpAccessControlListMappingCreator( + pathAccountSid, + pathDomainSid, + ipAccessControlListSid + ); } - public static IpAccessControlListMappingDeleter deleter(final String pathDomainSid, final String pathSid){ + public static IpAccessControlListMappingDeleter deleter( + final String pathDomainSid, + final String pathSid + ) { return new IpAccessControlListMappingDeleter(pathDomainSid, pathSid); } - public static IpAccessControlListMappingDeleter deleter(final String pathAccountSid, final String pathDomainSid, final String pathSid){ - return new IpAccessControlListMappingDeleter(pathAccountSid, pathDomainSid, pathSid); + + public static IpAccessControlListMappingDeleter deleter( + final String pathAccountSid, + final String pathDomainSid, + final String pathSid + ) { + return new IpAccessControlListMappingDeleter( + pathAccountSid, + pathDomainSid, + pathSid + ); } - public static IpAccessControlListMappingFetcher fetcher(final String pathDomainSid, final String pathSid){ + public static IpAccessControlListMappingFetcher fetcher( + final String pathDomainSid, + final String pathSid + ) { return new IpAccessControlListMappingFetcher(pathDomainSid, pathSid); } - public static IpAccessControlListMappingFetcher fetcher(final String pathAccountSid, final String pathDomainSid, final String pathSid){ - return new IpAccessControlListMappingFetcher(pathAccountSid, pathDomainSid, pathSid); + + public static IpAccessControlListMappingFetcher fetcher( + final String pathAccountSid, + final String pathDomainSid, + final String pathSid + ) { + return new IpAccessControlListMappingFetcher( + pathAccountSid, + pathDomainSid, + pathSid + ); } - public static IpAccessControlListMappingReader reader(final String pathDomainSid){ + public static IpAccessControlListMappingReader reader( + final String pathDomainSid + ) { return new IpAccessControlListMappingReader(pathDomainSid); } - public static IpAccessControlListMappingReader reader(final String pathAccountSid, final String pathDomainSid){ - return new IpAccessControlListMappingReader(pathAccountSid, pathDomainSid); + + public static IpAccessControlListMappingReader reader( + final String pathAccountSid, + final String pathDomainSid + ) { + return new IpAccessControlListMappingReader( + pathAccountSid, + pathDomainSid + ); } /** - * Converts a JSON String into a IpAccessControlListMapping object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return IpAccessControlListMapping object represented by the provided JSON - */ - public static IpAccessControlListMapping fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a IpAccessControlListMapping object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return IpAccessControlListMapping object represented by the provided JSON + */ + public static IpAccessControlListMapping fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, IpAccessControlListMapping.class); + return objectMapper.readValue( + json, + IpAccessControlListMapping.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -88,17 +138,23 @@ public static IpAccessControlListMapping fromJson(final String json, final Objec } /** - * Converts a JSON InputStream into a IpAccessControlListMapping object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return IpAccessControlListMapping object represented by the provided JSON - */ - public static IpAccessControlListMapping fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a IpAccessControlListMapping object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return IpAccessControlListMapping object represented by the provided JSON + */ + public static IpAccessControlListMapping fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, IpAccessControlListMapping.class); + return objectMapper.readValue( + json, + IpAccessControlListMapping.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -116,26 +172,13 @@ public static IpAccessControlListMapping fromJson(final InputStream json, final @JsonCreator private IpAccessControlListMapping( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("domain_sid") - final String domainSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("uri") - final String uri + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("domain_sid") final String domainSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("sid") final String sid, + @JsonProperty("uri") final String uri ) { this.accountSid = accountSid; this.dateCreated = DateConverter.rfc2822DateTimeFromString(dateCreated); @@ -146,31 +189,37 @@ private IpAccessControlListMapping( this.uri = uri; } - public final String getAccountSid() { - return this.accountSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getDomainSid() { - return this.domainSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getSid() { - return this.sid; - } - public final String getUri() { - return this.uri; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getDomainSid() { + return this.domainSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getSid() { + return this.sid; + } + + public final String getUri() { + return this.uri; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -180,13 +229,27 @@ public boolean equals(final Object o) { IpAccessControlListMapping other = (IpAccessControlListMapping) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(domainSid, other.domainSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(sid, other.sid) && Objects.equals(uri, other.uri) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(domainSid, other.domainSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(sid, other.sid) && + Objects.equals(uri, other.uri) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, dateCreated, dateUpdated, domainSid, friendlyName, sid, uri); + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + domainSid, + friendlyName, + sid, + uri + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/IpAccessControlListMappingCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/IpAccessControlListMappingCreator.java index 84b724e3f3..787280999f 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/IpAccessControlListMappingCreator.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/IpAccessControlListMappingCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010.account.sip.domain; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,61 +25,98 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class IpAccessControlListMappingCreator + extends Creator { - - -public class IpAccessControlListMappingCreator extends Creator{ private String pathDomainSid; private String ipAccessControlListSid; private String pathAccountSid; - public IpAccessControlListMappingCreator(final String pathDomainSid, final String ipAccessControlListSid) { + public IpAccessControlListMappingCreator( + final String pathDomainSid, + final String ipAccessControlListSid + ) { this.pathDomainSid = pathDomainSid; this.ipAccessControlListSid = ipAccessControlListSid; } - public IpAccessControlListMappingCreator(final String pathAccountSid, final String pathDomainSid, final String ipAccessControlListSid) { + + public IpAccessControlListMappingCreator( + final String pathAccountSid, + final String pathDomainSid, + final String ipAccessControlListSid + ) { this.pathAccountSid = pathAccountSid; this.pathDomainSid = pathDomainSid; this.ipAccessControlListSid = ipAccessControlListSid; } - public IpAccessControlListMappingCreator setIpAccessControlListSid(final String ipAccessControlListSid){ + public IpAccessControlListMappingCreator setIpAccessControlListSid( + final String ipAccessControlListSid + ) { this.ipAccessControlListSid = ipAccessControlListSid; return this; } @Override - public IpAccessControlListMapping create(final TwilioRestClient client){ - String path = "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/IpAccessControlListMappings.json"; + public IpAccessControlListMapping create(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/IpAccessControlListMappings.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"DomainSid"+"}", this.pathDomainSid.toString()); - path = path.replace("{"+"IpAccessControlListSid"+"}", this.ipAccessControlListSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "DomainSid" + "}", + this.pathDomainSid.toString() + ); + path = + path.replace( + "{" + "IpAccessControlListSid" + "}", + this.ipAccessControlListSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.API.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("IpAccessControlListMapping creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "IpAccessControlListMapping creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return IpAccessControlListMapping.fromJson(response.getStream(), client.getObjectMapper()); + return IpAccessControlListMapping.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (ipAccessControlListSid != null) { - request.addPostParam("IpAccessControlListSid", ipAccessControlListSid); - + request.addPostParam( + "IpAccessControlListSid", + ipAccessControlListSid + ); } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/IpAccessControlListMappingDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/IpAccessControlListMappingDeleter.java index 56b38d005f..f5adeb1dd2 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/IpAccessControlListMappingDeleter.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/IpAccessControlListMappingDeleter.java @@ -24,32 +24,51 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class IpAccessControlListMappingDeleter + extends Deleter { - -public class IpAccessControlListMappingDeleter extends Deleter { private String pathDomainSid; private String pathSid; private String pathAccountSid; - public IpAccessControlListMappingDeleter(final String pathDomainSid, final String pathSid){ + public IpAccessControlListMappingDeleter( + final String pathDomainSid, + final String pathSid + ) { this.pathDomainSid = pathDomainSid; this.pathSid = pathSid; } - public IpAccessControlListMappingDeleter(final String pathAccountSid, final String pathDomainSid, final String pathSid){ + + public IpAccessControlListMappingDeleter( + final String pathAccountSid, + final String pathDomainSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathDomainSid = pathDomainSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/IpAccessControlListMappings/{Sid}.json"; + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/IpAccessControlListMappings/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"DomainSid"+"}", this.pathDomainSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "DomainSid" + "}", + this.pathDomainSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -59,9 +78,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("IpAccessControlListMapping delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "IpAccessControlListMapping delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/IpAccessControlListMappingFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/IpAccessControlListMappingFetcher.java index 5de88963d3..7979ea8718 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/IpAccessControlListMappingFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/IpAccessControlListMappingFetcher.java @@ -24,33 +24,51 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class IpAccessControlListMappingFetcher + extends Fetcher { - - -public class IpAccessControlListMappingFetcher extends Fetcher { private String pathDomainSid; private String pathSid; private String pathAccountSid; - public IpAccessControlListMappingFetcher(final String pathDomainSid, final String pathSid){ + public IpAccessControlListMappingFetcher( + final String pathDomainSid, + final String pathSid + ) { this.pathDomainSid = pathDomainSid; this.pathSid = pathSid; } - public IpAccessControlListMappingFetcher(final String pathAccountSid, final String pathDomainSid, final String pathSid){ + + public IpAccessControlListMappingFetcher( + final String pathAccountSid, + final String pathDomainSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathDomainSid = pathDomainSid; this.pathSid = pathSid; } - @Override public IpAccessControlListMapping fetch(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/IpAccessControlListMappings/{Sid}.json"; + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/IpAccessControlListMappings/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"DomainSid"+"}", this.pathDomainSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "DomainSid" + "}", + this.pathDomainSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -60,15 +78,23 @@ public IpAccessControlListMapping fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("IpAccessControlListMapping fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "IpAccessControlListMapping fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return IpAccessControlListMapping.fromJson(response.getStream(), client.getObjectMapper()); + return IpAccessControlListMapping.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/IpAccessControlListMappingReader.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/IpAccessControlListMappingReader.java index 55c8006eed..955863b0a5 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/IpAccessControlListMappingReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/IpAccessControlListMappingReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.api.v2010.account.sip.domain; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,38 +25,59 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - +public class IpAccessControlListMappingReader + extends Reader { -public class IpAccessControlListMappingReader extends Reader { private String pathDomainSid; private String pathAccountSid; private Integer pageSize; - public IpAccessControlListMappingReader(final String pathDomainSid){ + public IpAccessControlListMappingReader(final String pathDomainSid) { this.pathDomainSid = pathDomainSid; } - public IpAccessControlListMappingReader(final String pathAccountSid, final String pathDomainSid){ + + public IpAccessControlListMappingReader( + final String pathAccountSid, + final String pathDomainSid + ) { this.pathAccountSid = pathAccountSid; this.pathDomainSid = pathDomainSid; } - public IpAccessControlListMappingReader setPageSize(final Integer pageSize){ + public IpAccessControlListMappingReader setPageSize( + final Integer pageSize + ) { this.pageSize = pageSize; return this; } @Override - public ResourceSet read(final TwilioRestClient client) { + public ResourceSet read( + final TwilioRestClient client + ) { return new ResourceSet<>(this, client, firstPage(client)); } - public Page firstPage(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/IpAccessControlListMappings.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"DomainSid"+"}", this.pathDomainSid.toString()); + public Page firstPage( + final TwilioRestClient client + ) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/IpAccessControlListMappings.json"; + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "DomainSid" + "}", + this.pathDomainSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -67,13 +89,21 @@ public Page firstPage(final TwilioRestClient client) return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("IpAccessControlListMapping read failed: Unable to connect to server"); + throw new ApiConnectionException( + "IpAccessControlListMapping read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -89,7 +119,10 @@ private Page pageForRequest(final TwilioRestClient c } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.API.toString()) @@ -97,9 +130,11 @@ public Page previousPage(final Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.API.toString()) @@ -108,21 +143,21 @@ public Page nextPage(final Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsCredentialListMapping.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsCredentialListMapping.java index 37cd3b7d63..902b4cda8d 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsCredentialListMapping.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsCredentialListMapping.java @@ -23,63 +23,119 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class AuthCallsCredentialListMapping extends Resource { + private static final long serialVersionUID = 16012497789519L; - public static AuthCallsCredentialListMappingCreator creator(final String pathDomainSid, final String credentialListSid){ - return new AuthCallsCredentialListMappingCreator(pathDomainSid, credentialListSid); + public static AuthCallsCredentialListMappingCreator creator( + final String pathDomainSid, + final String credentialListSid + ) { + return new AuthCallsCredentialListMappingCreator( + pathDomainSid, + credentialListSid + ); } - public static AuthCallsCredentialListMappingCreator creator(final String pathAccountSid, final String pathDomainSid, final String credentialListSid){ - return new AuthCallsCredentialListMappingCreator(pathAccountSid, pathDomainSid, credentialListSid); + + public static AuthCallsCredentialListMappingCreator creator( + final String pathAccountSid, + final String pathDomainSid, + final String credentialListSid + ) { + return new AuthCallsCredentialListMappingCreator( + pathAccountSid, + pathDomainSid, + credentialListSid + ); } - public static AuthCallsCredentialListMappingDeleter deleter(final String pathDomainSid, final String pathSid){ - return new AuthCallsCredentialListMappingDeleter(pathDomainSid, pathSid); + public static AuthCallsCredentialListMappingDeleter deleter( + final String pathDomainSid, + final String pathSid + ) { + return new AuthCallsCredentialListMappingDeleter( + pathDomainSid, + pathSid + ); } - public static AuthCallsCredentialListMappingDeleter deleter(final String pathAccountSid, final String pathDomainSid, final String pathSid){ - return new AuthCallsCredentialListMappingDeleter(pathAccountSid, pathDomainSid, pathSid); + + public static AuthCallsCredentialListMappingDeleter deleter( + final String pathAccountSid, + final String pathDomainSid, + final String pathSid + ) { + return new AuthCallsCredentialListMappingDeleter( + pathAccountSid, + pathDomainSid, + pathSid + ); } - public static AuthCallsCredentialListMappingFetcher fetcher(final String pathDomainSid, final String pathSid){ - return new AuthCallsCredentialListMappingFetcher(pathDomainSid, pathSid); + public static AuthCallsCredentialListMappingFetcher fetcher( + final String pathDomainSid, + final String pathSid + ) { + return new AuthCallsCredentialListMappingFetcher( + pathDomainSid, + pathSid + ); } - public static AuthCallsCredentialListMappingFetcher fetcher(final String pathAccountSid, final String pathDomainSid, final String pathSid){ - return new AuthCallsCredentialListMappingFetcher(pathAccountSid, pathDomainSid, pathSid); + + public static AuthCallsCredentialListMappingFetcher fetcher( + final String pathAccountSid, + final String pathDomainSid, + final String pathSid + ) { + return new AuthCallsCredentialListMappingFetcher( + pathAccountSid, + pathDomainSid, + pathSid + ); } - public static AuthCallsCredentialListMappingReader reader(final String pathDomainSid){ + public static AuthCallsCredentialListMappingReader reader( + final String pathDomainSid + ) { return new AuthCallsCredentialListMappingReader(pathDomainSid); } - public static AuthCallsCredentialListMappingReader reader(final String pathAccountSid, final String pathDomainSid){ - return new AuthCallsCredentialListMappingReader(pathAccountSid, pathDomainSid); + + public static AuthCallsCredentialListMappingReader reader( + final String pathAccountSid, + final String pathDomainSid + ) { + return new AuthCallsCredentialListMappingReader( + pathAccountSid, + pathDomainSid + ); } /** - * Converts a JSON String into a AuthCallsCredentialListMapping object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return AuthCallsCredentialListMapping object represented by the provided JSON - */ - public static AuthCallsCredentialListMapping fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a AuthCallsCredentialListMapping object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return AuthCallsCredentialListMapping object represented by the provided JSON + */ + public static AuthCallsCredentialListMapping fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, AuthCallsCredentialListMapping.class); + return objectMapper.readValue( + json, + AuthCallsCredentialListMapping.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -88,17 +144,23 @@ public static AuthCallsCredentialListMapping fromJson(final String json, final O } /** - * Converts a JSON InputStream into a AuthCallsCredentialListMapping object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return AuthCallsCredentialListMapping object represented by the provided JSON - */ - public static AuthCallsCredentialListMapping fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a AuthCallsCredentialListMapping object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return AuthCallsCredentialListMapping object represented by the provided JSON + */ + public static AuthCallsCredentialListMapping fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, AuthCallsCredentialListMapping.class); + return objectMapper.readValue( + json, + AuthCallsCredentialListMapping.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -114,20 +176,11 @@ public static AuthCallsCredentialListMapping fromJson(final InputStream json, fi @JsonCreator private AuthCallsCredentialListMapping( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("sid") - final String sid + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("sid") final String sid ) { this.accountSid = accountSid; this.dateCreated = DateConverter.rfc2822DateTimeFromString(dateCreated); @@ -136,25 +189,29 @@ private AuthCallsCredentialListMapping( this.sid = sid; } - public final String getAccountSid() { - return this.accountSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getSid() { - return this.sid; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getSid() { + return this.sid; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -162,15 +219,26 @@ public boolean equals(final Object o) { return false; } - AuthCallsCredentialListMapping other = (AuthCallsCredentialListMapping) o; + AuthCallsCredentialListMapping other = + (AuthCallsCredentialListMapping) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(sid, other.sid) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(sid, other.sid) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, dateCreated, dateUpdated, friendlyName, sid); + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + friendlyName, + sid + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsCredentialListMappingCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsCredentialListMappingCreator.java index a5fa945f47..ddf0d52b74 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsCredentialListMappingCreator.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsCredentialListMappingCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010.account.sip.domain.authtypes.authtypecalls; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,61 +25,97 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class AuthCallsCredentialListMappingCreator + extends Creator { - - -public class AuthCallsCredentialListMappingCreator extends Creator{ private String pathDomainSid; private String credentialListSid; private String pathAccountSid; - public AuthCallsCredentialListMappingCreator(final String pathDomainSid, final String credentialListSid) { + public AuthCallsCredentialListMappingCreator( + final String pathDomainSid, + final String credentialListSid + ) { this.pathDomainSid = pathDomainSid; this.credentialListSid = credentialListSid; } - public AuthCallsCredentialListMappingCreator(final String pathAccountSid, final String pathDomainSid, final String credentialListSid) { + + public AuthCallsCredentialListMappingCreator( + final String pathAccountSid, + final String pathDomainSid, + final String credentialListSid + ) { this.pathAccountSid = pathAccountSid; this.pathDomainSid = pathDomainSid; this.credentialListSid = credentialListSid; } - public AuthCallsCredentialListMappingCreator setCredentialListSid(final String credentialListSid){ + public AuthCallsCredentialListMappingCreator setCredentialListSid( + final String credentialListSid + ) { this.credentialListSid = credentialListSid; return this; } @Override - public AuthCallsCredentialListMapping create(final TwilioRestClient client){ - String path = "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Calls/CredentialListMappings.json"; + public AuthCallsCredentialListMapping create( + final TwilioRestClient client + ) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Calls/CredentialListMappings.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"DomainSid"+"}", this.pathDomainSid.toString()); - path = path.replace("{"+"CredentialListSid"+"}", this.credentialListSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "DomainSid" + "}", + this.pathDomainSid.toString() + ); + path = + path.replace( + "{" + "CredentialListSid" + "}", + this.credentialListSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.API.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AuthCallsCredentialListMapping creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "AuthCallsCredentialListMapping creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return AuthCallsCredentialListMapping.fromJson(response.getStream(), client.getObjectMapper()); + return AuthCallsCredentialListMapping.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (credentialListSid != null) { request.addPostParam("CredentialListSid", credentialListSid); - } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsCredentialListMappingDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsCredentialListMappingDeleter.java index 097f9ae0bd..bd42fdd64a 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsCredentialListMappingDeleter.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsCredentialListMappingDeleter.java @@ -24,32 +24,51 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class AuthCallsCredentialListMappingDeleter + extends Deleter { - -public class AuthCallsCredentialListMappingDeleter extends Deleter { private String pathDomainSid; private String pathSid; private String pathAccountSid; - public AuthCallsCredentialListMappingDeleter(final String pathDomainSid, final String pathSid){ + public AuthCallsCredentialListMappingDeleter( + final String pathDomainSid, + final String pathSid + ) { this.pathDomainSid = pathDomainSid; this.pathSid = pathSid; } - public AuthCallsCredentialListMappingDeleter(final String pathAccountSid, final String pathDomainSid, final String pathSid){ + + public AuthCallsCredentialListMappingDeleter( + final String pathAccountSid, + final String pathDomainSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathDomainSid = pathDomainSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Calls/CredentialListMappings/{Sid}.json"; + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Calls/CredentialListMappings/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"DomainSid"+"}", this.pathDomainSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "DomainSid" + "}", + this.pathDomainSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -59,9 +78,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AuthCallsCredentialListMapping delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "AuthCallsCredentialListMapping delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsCredentialListMappingFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsCredentialListMappingFetcher.java index 6f6fef8733..ac7882336c 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsCredentialListMappingFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsCredentialListMappingFetcher.java @@ -24,33 +24,51 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class AuthCallsCredentialListMappingFetcher + extends Fetcher { - - -public class AuthCallsCredentialListMappingFetcher extends Fetcher { private String pathDomainSid; private String pathSid; private String pathAccountSid; - public AuthCallsCredentialListMappingFetcher(final String pathDomainSid, final String pathSid){ + public AuthCallsCredentialListMappingFetcher( + final String pathDomainSid, + final String pathSid + ) { this.pathDomainSid = pathDomainSid; this.pathSid = pathSid; } - public AuthCallsCredentialListMappingFetcher(final String pathAccountSid, final String pathDomainSid, final String pathSid){ + + public AuthCallsCredentialListMappingFetcher( + final String pathAccountSid, + final String pathDomainSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathDomainSid = pathDomainSid; this.pathSid = pathSid; } - @Override public AuthCallsCredentialListMapping fetch(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Calls/CredentialListMappings/{Sid}.json"; + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Calls/CredentialListMappings/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"DomainSid"+"}", this.pathDomainSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "DomainSid" + "}", + this.pathDomainSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -60,15 +78,23 @@ public AuthCallsCredentialListMapping fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AuthCallsCredentialListMapping fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "AuthCallsCredentialListMapping fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return AuthCallsCredentialListMapping.fromJson(response.getStream(), client.getObjectMapper()); + return AuthCallsCredentialListMapping.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsCredentialListMappingReader.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsCredentialListMappingReader.java index b67bb77eab..5f65f8cbf9 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsCredentialListMappingReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsCredentialListMappingReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.api.v2010.account.sip.domain.authtypes.authtypecalls; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,38 +25,59 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - +public class AuthCallsCredentialListMappingReader + extends Reader { -public class AuthCallsCredentialListMappingReader extends Reader { private String pathDomainSid; private String pathAccountSid; private Integer pageSize; - public AuthCallsCredentialListMappingReader(final String pathDomainSid){ + public AuthCallsCredentialListMappingReader(final String pathDomainSid) { this.pathDomainSid = pathDomainSid; } - public AuthCallsCredentialListMappingReader(final String pathAccountSid, final String pathDomainSid){ + + public AuthCallsCredentialListMappingReader( + final String pathAccountSid, + final String pathDomainSid + ) { this.pathAccountSid = pathAccountSid; this.pathDomainSid = pathDomainSid; } - public AuthCallsCredentialListMappingReader setPageSize(final Integer pageSize){ + public AuthCallsCredentialListMappingReader setPageSize( + final Integer pageSize + ) { this.pageSize = pageSize; return this; } @Override - public ResourceSet read(final TwilioRestClient client) { + public ResourceSet read( + final TwilioRestClient client + ) { return new ResourceSet<>(this, client, firstPage(client)); } - public Page firstPage(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Calls/CredentialListMappings.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"DomainSid"+"}", this.pathDomainSid.toString()); + public Page firstPage( + final TwilioRestClient client + ) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Calls/CredentialListMappings.json"; + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "DomainSid" + "}", + this.pathDomainSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -67,13 +89,21 @@ public Page firstPage(final TwilioRestClient cli return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AuthCallsCredentialListMapping read failed: Unable to connect to server"); + throw new ApiConnectionException( + "AuthCallsCredentialListMapping read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -89,7 +119,10 @@ private Page pageForRequest(final TwilioRestClie } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.API.toString()) @@ -97,9 +130,11 @@ public Page previousPage(final Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.API.toString()) @@ -108,21 +143,21 @@ public Page nextPage(final Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsIpAccessControlListMapping.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsIpAccessControlListMapping.java index 1ef09641f6..a3d646a11c 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsIpAccessControlListMapping.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsIpAccessControlListMapping.java @@ -23,63 +23,119 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class AuthCallsIpAccessControlListMapping extends Resource { + private static final long serialVersionUID = 16012497789519L; - public static AuthCallsIpAccessControlListMappingCreator creator(final String pathDomainSid, final String ipAccessControlListSid){ - return new AuthCallsIpAccessControlListMappingCreator(pathDomainSid, ipAccessControlListSid); + public static AuthCallsIpAccessControlListMappingCreator creator( + final String pathDomainSid, + final String ipAccessControlListSid + ) { + return new AuthCallsIpAccessControlListMappingCreator( + pathDomainSid, + ipAccessControlListSid + ); } - public static AuthCallsIpAccessControlListMappingCreator creator(final String pathAccountSid, final String pathDomainSid, final String ipAccessControlListSid){ - return new AuthCallsIpAccessControlListMappingCreator(pathAccountSid, pathDomainSid, ipAccessControlListSid); + + public static AuthCallsIpAccessControlListMappingCreator creator( + final String pathAccountSid, + final String pathDomainSid, + final String ipAccessControlListSid + ) { + return new AuthCallsIpAccessControlListMappingCreator( + pathAccountSid, + pathDomainSid, + ipAccessControlListSid + ); } - public static AuthCallsIpAccessControlListMappingDeleter deleter(final String pathDomainSid, final String pathSid){ - return new AuthCallsIpAccessControlListMappingDeleter(pathDomainSid, pathSid); + public static AuthCallsIpAccessControlListMappingDeleter deleter( + final String pathDomainSid, + final String pathSid + ) { + return new AuthCallsIpAccessControlListMappingDeleter( + pathDomainSid, + pathSid + ); } - public static AuthCallsIpAccessControlListMappingDeleter deleter(final String pathAccountSid, final String pathDomainSid, final String pathSid){ - return new AuthCallsIpAccessControlListMappingDeleter(pathAccountSid, pathDomainSid, pathSid); + + public static AuthCallsIpAccessControlListMappingDeleter deleter( + final String pathAccountSid, + final String pathDomainSid, + final String pathSid + ) { + return new AuthCallsIpAccessControlListMappingDeleter( + pathAccountSid, + pathDomainSid, + pathSid + ); } - public static AuthCallsIpAccessControlListMappingFetcher fetcher(final String pathDomainSid, final String pathSid){ - return new AuthCallsIpAccessControlListMappingFetcher(pathDomainSid, pathSid); + public static AuthCallsIpAccessControlListMappingFetcher fetcher( + final String pathDomainSid, + final String pathSid + ) { + return new AuthCallsIpAccessControlListMappingFetcher( + pathDomainSid, + pathSid + ); } - public static AuthCallsIpAccessControlListMappingFetcher fetcher(final String pathAccountSid, final String pathDomainSid, final String pathSid){ - return new AuthCallsIpAccessControlListMappingFetcher(pathAccountSid, pathDomainSid, pathSid); + + public static AuthCallsIpAccessControlListMappingFetcher fetcher( + final String pathAccountSid, + final String pathDomainSid, + final String pathSid + ) { + return new AuthCallsIpAccessControlListMappingFetcher( + pathAccountSid, + pathDomainSid, + pathSid + ); } - public static AuthCallsIpAccessControlListMappingReader reader(final String pathDomainSid){ + public static AuthCallsIpAccessControlListMappingReader reader( + final String pathDomainSid + ) { return new AuthCallsIpAccessControlListMappingReader(pathDomainSid); } - public static AuthCallsIpAccessControlListMappingReader reader(final String pathAccountSid, final String pathDomainSid){ - return new AuthCallsIpAccessControlListMappingReader(pathAccountSid, pathDomainSid); + + public static AuthCallsIpAccessControlListMappingReader reader( + final String pathAccountSid, + final String pathDomainSid + ) { + return new AuthCallsIpAccessControlListMappingReader( + pathAccountSid, + pathDomainSid + ); } /** - * Converts a JSON String into a AuthCallsIpAccessControlListMapping object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return AuthCallsIpAccessControlListMapping object represented by the provided JSON - */ - public static AuthCallsIpAccessControlListMapping fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a AuthCallsIpAccessControlListMapping object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return AuthCallsIpAccessControlListMapping object represented by the provided JSON + */ + public static AuthCallsIpAccessControlListMapping fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, AuthCallsIpAccessControlListMapping.class); + return objectMapper.readValue( + json, + AuthCallsIpAccessControlListMapping.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -88,17 +144,23 @@ public static AuthCallsIpAccessControlListMapping fromJson(final String json, fi } /** - * Converts a JSON InputStream into a AuthCallsIpAccessControlListMapping object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return AuthCallsIpAccessControlListMapping object represented by the provided JSON - */ - public static AuthCallsIpAccessControlListMapping fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a AuthCallsIpAccessControlListMapping object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return AuthCallsIpAccessControlListMapping object represented by the provided JSON + */ + public static AuthCallsIpAccessControlListMapping fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, AuthCallsIpAccessControlListMapping.class); + return objectMapper.readValue( + json, + AuthCallsIpAccessControlListMapping.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -114,20 +176,11 @@ public static AuthCallsIpAccessControlListMapping fromJson(final InputStream jso @JsonCreator private AuthCallsIpAccessControlListMapping( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("sid") - final String sid + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("sid") final String sid ) { this.accountSid = accountSid; this.dateCreated = DateConverter.rfc2822DateTimeFromString(dateCreated); @@ -136,25 +189,29 @@ private AuthCallsIpAccessControlListMapping( this.sid = sid; } - public final String getAccountSid() { - return this.accountSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getSid() { - return this.sid; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getSid() { + return this.sid; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -162,15 +219,26 @@ public boolean equals(final Object o) { return false; } - AuthCallsIpAccessControlListMapping other = (AuthCallsIpAccessControlListMapping) o; + AuthCallsIpAccessControlListMapping other = + (AuthCallsIpAccessControlListMapping) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(sid, other.sid) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(sid, other.sid) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, dateCreated, dateUpdated, friendlyName, sid); + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + friendlyName, + sid + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsIpAccessControlListMappingCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsIpAccessControlListMappingCreator.java index 6f610716d0..1ec2d66ca6 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsIpAccessControlListMappingCreator.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsIpAccessControlListMappingCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010.account.sip.domain.authtypes.authtypecalls; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,61 +25,100 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class AuthCallsIpAccessControlListMappingCreator + extends Creator { - - -public class AuthCallsIpAccessControlListMappingCreator extends Creator{ private String pathDomainSid; private String ipAccessControlListSid; private String pathAccountSid; - public AuthCallsIpAccessControlListMappingCreator(final String pathDomainSid, final String ipAccessControlListSid) { + public AuthCallsIpAccessControlListMappingCreator( + final String pathDomainSid, + final String ipAccessControlListSid + ) { this.pathDomainSid = pathDomainSid; this.ipAccessControlListSid = ipAccessControlListSid; } - public AuthCallsIpAccessControlListMappingCreator(final String pathAccountSid, final String pathDomainSid, final String ipAccessControlListSid) { + + public AuthCallsIpAccessControlListMappingCreator( + final String pathAccountSid, + final String pathDomainSid, + final String ipAccessControlListSid + ) { this.pathAccountSid = pathAccountSid; this.pathDomainSid = pathDomainSid; this.ipAccessControlListSid = ipAccessControlListSid; } - public AuthCallsIpAccessControlListMappingCreator setIpAccessControlListSid(final String ipAccessControlListSid){ + public AuthCallsIpAccessControlListMappingCreator setIpAccessControlListSid( + final String ipAccessControlListSid + ) { this.ipAccessControlListSid = ipAccessControlListSid; return this; } @Override - public AuthCallsIpAccessControlListMapping create(final TwilioRestClient client){ - String path = "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Calls/IpAccessControlListMappings.json"; + public AuthCallsIpAccessControlListMapping create( + final TwilioRestClient client + ) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Calls/IpAccessControlListMappings.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"DomainSid"+"}", this.pathDomainSid.toString()); - path = path.replace("{"+"IpAccessControlListSid"+"}", this.ipAccessControlListSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "DomainSid" + "}", + this.pathDomainSid.toString() + ); + path = + path.replace( + "{" + "IpAccessControlListSid" + "}", + this.ipAccessControlListSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.API.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AuthCallsIpAccessControlListMapping creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "AuthCallsIpAccessControlListMapping creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return AuthCallsIpAccessControlListMapping.fromJson(response.getStream(), client.getObjectMapper()); + return AuthCallsIpAccessControlListMapping.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (ipAccessControlListSid != null) { - request.addPostParam("IpAccessControlListSid", ipAccessControlListSid); - + request.addPostParam( + "IpAccessControlListSid", + ipAccessControlListSid + ); } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsIpAccessControlListMappingDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsIpAccessControlListMappingDeleter.java index f76bdbf725..a26121e96d 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsIpAccessControlListMappingDeleter.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsIpAccessControlListMappingDeleter.java @@ -24,32 +24,51 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class AuthCallsIpAccessControlListMappingDeleter + extends Deleter { - -public class AuthCallsIpAccessControlListMappingDeleter extends Deleter { private String pathDomainSid; private String pathSid; private String pathAccountSid; - public AuthCallsIpAccessControlListMappingDeleter(final String pathDomainSid, final String pathSid){ + public AuthCallsIpAccessControlListMappingDeleter( + final String pathDomainSid, + final String pathSid + ) { this.pathDomainSid = pathDomainSid; this.pathSid = pathSid; } - public AuthCallsIpAccessControlListMappingDeleter(final String pathAccountSid, final String pathDomainSid, final String pathSid){ + + public AuthCallsIpAccessControlListMappingDeleter( + final String pathAccountSid, + final String pathDomainSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathDomainSid = pathDomainSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Calls/IpAccessControlListMappings/{Sid}.json"; + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Calls/IpAccessControlListMappings/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"DomainSid"+"}", this.pathDomainSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "DomainSid" + "}", + this.pathDomainSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -59,9 +78,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AuthCallsIpAccessControlListMapping delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "AuthCallsIpAccessControlListMapping delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsIpAccessControlListMappingFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsIpAccessControlListMappingFetcher.java index 27ad5c6b59..69bf0f5aa0 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsIpAccessControlListMappingFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsIpAccessControlListMappingFetcher.java @@ -24,33 +24,53 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class AuthCallsIpAccessControlListMappingFetcher + extends Fetcher { - - -public class AuthCallsIpAccessControlListMappingFetcher extends Fetcher { private String pathDomainSid; private String pathSid; private String pathAccountSid; - public AuthCallsIpAccessControlListMappingFetcher(final String pathDomainSid, final String pathSid){ + public AuthCallsIpAccessControlListMappingFetcher( + final String pathDomainSid, + final String pathSid + ) { this.pathDomainSid = pathDomainSid; this.pathSid = pathSid; } - public AuthCallsIpAccessControlListMappingFetcher(final String pathAccountSid, final String pathDomainSid, final String pathSid){ + + public AuthCallsIpAccessControlListMappingFetcher( + final String pathAccountSid, + final String pathDomainSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathDomainSid = pathDomainSid; this.pathSid = pathSid; } - @Override - public AuthCallsIpAccessControlListMapping fetch(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Calls/IpAccessControlListMappings/{Sid}.json"; + public AuthCallsIpAccessControlListMapping fetch( + final TwilioRestClient client + ) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Calls/IpAccessControlListMappings/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"DomainSid"+"}", this.pathDomainSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "DomainSid" + "}", + this.pathDomainSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -60,15 +80,23 @@ public AuthCallsIpAccessControlListMapping fetch(final TwilioRestClient client) Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AuthCallsIpAccessControlListMapping fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "AuthCallsIpAccessControlListMapping fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return AuthCallsIpAccessControlListMapping.fromJson(response.getStream(), client.getObjectMapper()); + return AuthCallsIpAccessControlListMapping.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsIpAccessControlListMappingReader.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsIpAccessControlListMappingReader.java index f7dadb8554..086b7efb9f 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsIpAccessControlListMappingReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsIpAccessControlListMappingReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.api.v2010.account.sip.domain.authtypes.authtypecalls; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,38 +25,61 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - +public class AuthCallsIpAccessControlListMappingReader + extends Reader { -public class AuthCallsIpAccessControlListMappingReader extends Reader { private String pathDomainSid; private String pathAccountSid; private Integer pageSize; - public AuthCallsIpAccessControlListMappingReader(final String pathDomainSid){ + public AuthCallsIpAccessControlListMappingReader( + final String pathDomainSid + ) { this.pathDomainSid = pathDomainSid; } - public AuthCallsIpAccessControlListMappingReader(final String pathAccountSid, final String pathDomainSid){ + + public AuthCallsIpAccessControlListMappingReader( + final String pathAccountSid, + final String pathDomainSid + ) { this.pathAccountSid = pathAccountSid; this.pathDomainSid = pathDomainSid; } - public AuthCallsIpAccessControlListMappingReader setPageSize(final Integer pageSize){ + public AuthCallsIpAccessControlListMappingReader setPageSize( + final Integer pageSize + ) { this.pageSize = pageSize; return this; } @Override - public ResourceSet read(final TwilioRestClient client) { + public ResourceSet read( + final TwilioRestClient client + ) { return new ResourceSet<>(this, client, firstPage(client)); } - public Page firstPage(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Calls/IpAccessControlListMappings.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"DomainSid"+"}", this.pathDomainSid.toString()); + public Page firstPage( + final TwilioRestClient client + ) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Calls/IpAccessControlListMappings.json"; + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "DomainSid" + "}", + this.pathDomainSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -67,13 +91,21 @@ public Page firstPage(final TwilioRestClien return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AuthCallsIpAccessControlListMapping read failed: Unable to connect to server"); + throw new ApiConnectionException( + "AuthCallsIpAccessControlListMapping read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -89,7 +121,10 @@ private Page pageForRequest(final TwilioRes } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.API.toString()) @@ -97,9 +132,11 @@ public Page previousPage(final Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.API.toString()) @@ -108,21 +145,21 @@ public Page nextPage(final Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtyperegistrations/AuthRegistrationsCredentialListMapping.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtyperegistrations/AuthRegistrationsCredentialListMapping.java index e6e7b03c1c..24efcfa23d 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtyperegistrations/AuthRegistrationsCredentialListMapping.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtyperegistrations/AuthRegistrationsCredentialListMapping.java @@ -23,63 +23,119 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class AuthRegistrationsCredentialListMapping extends Resource { + private static final long serialVersionUID = 16012497789519L; - public static AuthRegistrationsCredentialListMappingCreator creator(final String pathDomainSid, final String credentialListSid){ - return new AuthRegistrationsCredentialListMappingCreator(pathDomainSid, credentialListSid); + public static AuthRegistrationsCredentialListMappingCreator creator( + final String pathDomainSid, + final String credentialListSid + ) { + return new AuthRegistrationsCredentialListMappingCreator( + pathDomainSid, + credentialListSid + ); } - public static AuthRegistrationsCredentialListMappingCreator creator(final String pathAccountSid, final String pathDomainSid, final String credentialListSid){ - return new AuthRegistrationsCredentialListMappingCreator(pathAccountSid, pathDomainSid, credentialListSid); + + public static AuthRegistrationsCredentialListMappingCreator creator( + final String pathAccountSid, + final String pathDomainSid, + final String credentialListSid + ) { + return new AuthRegistrationsCredentialListMappingCreator( + pathAccountSid, + pathDomainSid, + credentialListSid + ); } - public static AuthRegistrationsCredentialListMappingDeleter deleter(final String pathDomainSid, final String pathSid){ - return new AuthRegistrationsCredentialListMappingDeleter(pathDomainSid, pathSid); + public static AuthRegistrationsCredentialListMappingDeleter deleter( + final String pathDomainSid, + final String pathSid + ) { + return new AuthRegistrationsCredentialListMappingDeleter( + pathDomainSid, + pathSid + ); } - public static AuthRegistrationsCredentialListMappingDeleter deleter(final String pathAccountSid, final String pathDomainSid, final String pathSid){ - return new AuthRegistrationsCredentialListMappingDeleter(pathAccountSid, pathDomainSid, pathSid); + + public static AuthRegistrationsCredentialListMappingDeleter deleter( + final String pathAccountSid, + final String pathDomainSid, + final String pathSid + ) { + return new AuthRegistrationsCredentialListMappingDeleter( + pathAccountSid, + pathDomainSid, + pathSid + ); } - public static AuthRegistrationsCredentialListMappingFetcher fetcher(final String pathDomainSid, final String pathSid){ - return new AuthRegistrationsCredentialListMappingFetcher(pathDomainSid, pathSid); + public static AuthRegistrationsCredentialListMappingFetcher fetcher( + final String pathDomainSid, + final String pathSid + ) { + return new AuthRegistrationsCredentialListMappingFetcher( + pathDomainSid, + pathSid + ); } - public static AuthRegistrationsCredentialListMappingFetcher fetcher(final String pathAccountSid, final String pathDomainSid, final String pathSid){ - return new AuthRegistrationsCredentialListMappingFetcher(pathAccountSid, pathDomainSid, pathSid); + + public static AuthRegistrationsCredentialListMappingFetcher fetcher( + final String pathAccountSid, + final String pathDomainSid, + final String pathSid + ) { + return new AuthRegistrationsCredentialListMappingFetcher( + pathAccountSid, + pathDomainSid, + pathSid + ); } - public static AuthRegistrationsCredentialListMappingReader reader(final String pathDomainSid){ + public static AuthRegistrationsCredentialListMappingReader reader( + final String pathDomainSid + ) { return new AuthRegistrationsCredentialListMappingReader(pathDomainSid); } - public static AuthRegistrationsCredentialListMappingReader reader(final String pathAccountSid, final String pathDomainSid){ - return new AuthRegistrationsCredentialListMappingReader(pathAccountSid, pathDomainSid); + + public static AuthRegistrationsCredentialListMappingReader reader( + final String pathAccountSid, + final String pathDomainSid + ) { + return new AuthRegistrationsCredentialListMappingReader( + pathAccountSid, + pathDomainSid + ); } /** - * Converts a JSON String into a AuthRegistrationsCredentialListMapping object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return AuthRegistrationsCredentialListMapping object represented by the provided JSON - */ - public static AuthRegistrationsCredentialListMapping fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a AuthRegistrationsCredentialListMapping object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return AuthRegistrationsCredentialListMapping object represented by the provided JSON + */ + public static AuthRegistrationsCredentialListMapping fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, AuthRegistrationsCredentialListMapping.class); + return objectMapper.readValue( + json, + AuthRegistrationsCredentialListMapping.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -88,17 +144,23 @@ public static AuthRegistrationsCredentialListMapping fromJson(final String json, } /** - * Converts a JSON InputStream into a AuthRegistrationsCredentialListMapping object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return AuthRegistrationsCredentialListMapping object represented by the provided JSON - */ - public static AuthRegistrationsCredentialListMapping fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a AuthRegistrationsCredentialListMapping object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return AuthRegistrationsCredentialListMapping object represented by the provided JSON + */ + public static AuthRegistrationsCredentialListMapping fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, AuthRegistrationsCredentialListMapping.class); + return objectMapper.readValue( + json, + AuthRegistrationsCredentialListMapping.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -114,20 +176,11 @@ public static AuthRegistrationsCredentialListMapping fromJson(final InputStream @JsonCreator private AuthRegistrationsCredentialListMapping( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("sid") - final String sid + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("sid") final String sid ) { this.accountSid = accountSid; this.dateCreated = DateConverter.rfc2822DateTimeFromString(dateCreated); @@ -136,25 +189,29 @@ private AuthRegistrationsCredentialListMapping( this.sid = sid; } - public final String getAccountSid() { - return this.accountSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getSid() { - return this.sid; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getSid() { + return this.sid; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -162,15 +219,26 @@ public boolean equals(final Object o) { return false; } - AuthRegistrationsCredentialListMapping other = (AuthRegistrationsCredentialListMapping) o; + AuthRegistrationsCredentialListMapping other = + (AuthRegistrationsCredentialListMapping) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(sid, other.sid) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(sid, other.sid) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, dateCreated, dateUpdated, friendlyName, sid); + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + friendlyName, + sid + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtyperegistrations/AuthRegistrationsCredentialListMappingCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtyperegistrations/AuthRegistrationsCredentialListMappingCreator.java index 223d6a02e7..b310ca7da1 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtyperegistrations/AuthRegistrationsCredentialListMappingCreator.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtyperegistrations/AuthRegistrationsCredentialListMappingCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010.account.sip.domain.authtypes.authtyperegistrations; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,61 +25,97 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class AuthRegistrationsCredentialListMappingCreator + extends Creator { - - -public class AuthRegistrationsCredentialListMappingCreator extends Creator{ private String pathDomainSid; private String credentialListSid; private String pathAccountSid; - public AuthRegistrationsCredentialListMappingCreator(final String pathDomainSid, final String credentialListSid) { + public AuthRegistrationsCredentialListMappingCreator( + final String pathDomainSid, + final String credentialListSid + ) { this.pathDomainSid = pathDomainSid; this.credentialListSid = credentialListSid; } - public AuthRegistrationsCredentialListMappingCreator(final String pathAccountSid, final String pathDomainSid, final String credentialListSid) { + + public AuthRegistrationsCredentialListMappingCreator( + final String pathAccountSid, + final String pathDomainSid, + final String credentialListSid + ) { this.pathAccountSid = pathAccountSid; this.pathDomainSid = pathDomainSid; this.credentialListSid = credentialListSid; } - public AuthRegistrationsCredentialListMappingCreator setCredentialListSid(final String credentialListSid){ + public AuthRegistrationsCredentialListMappingCreator setCredentialListSid( + final String credentialListSid + ) { this.credentialListSid = credentialListSid; return this; } @Override - public AuthRegistrationsCredentialListMapping create(final TwilioRestClient client){ - String path = "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Registrations/CredentialListMappings.json"; + public AuthRegistrationsCredentialListMapping create( + final TwilioRestClient client + ) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Registrations/CredentialListMappings.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"DomainSid"+"}", this.pathDomainSid.toString()); - path = path.replace("{"+"CredentialListSid"+"}", this.credentialListSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "DomainSid" + "}", + this.pathDomainSid.toString() + ); + path = + path.replace( + "{" + "CredentialListSid" + "}", + this.credentialListSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.API.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AuthRegistrationsCredentialListMapping creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "AuthRegistrationsCredentialListMapping creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return AuthRegistrationsCredentialListMapping.fromJson(response.getStream(), client.getObjectMapper()); + return AuthRegistrationsCredentialListMapping.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (credentialListSid != null) { request.addPostParam("CredentialListSid", credentialListSid); - } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtyperegistrations/AuthRegistrationsCredentialListMappingDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtyperegistrations/AuthRegistrationsCredentialListMappingDeleter.java index 2fc5482def..6f11642c80 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtyperegistrations/AuthRegistrationsCredentialListMappingDeleter.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtyperegistrations/AuthRegistrationsCredentialListMappingDeleter.java @@ -24,32 +24,51 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class AuthRegistrationsCredentialListMappingDeleter + extends Deleter { - -public class AuthRegistrationsCredentialListMappingDeleter extends Deleter { private String pathDomainSid; private String pathSid; private String pathAccountSid; - public AuthRegistrationsCredentialListMappingDeleter(final String pathDomainSid, final String pathSid){ + public AuthRegistrationsCredentialListMappingDeleter( + final String pathDomainSid, + final String pathSid + ) { this.pathDomainSid = pathDomainSid; this.pathSid = pathSid; } - public AuthRegistrationsCredentialListMappingDeleter(final String pathAccountSid, final String pathDomainSid, final String pathSid){ + + public AuthRegistrationsCredentialListMappingDeleter( + final String pathAccountSid, + final String pathDomainSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathDomainSid = pathDomainSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Registrations/CredentialListMappings/{Sid}.json"; + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Registrations/CredentialListMappings/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"DomainSid"+"}", this.pathDomainSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "DomainSid" + "}", + this.pathDomainSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -59,9 +78,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AuthRegistrationsCredentialListMapping delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "AuthRegistrationsCredentialListMapping delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtyperegistrations/AuthRegistrationsCredentialListMappingFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtyperegistrations/AuthRegistrationsCredentialListMappingFetcher.java index dff26d2e8c..4ab88e3834 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtyperegistrations/AuthRegistrationsCredentialListMappingFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtyperegistrations/AuthRegistrationsCredentialListMappingFetcher.java @@ -24,33 +24,53 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class AuthRegistrationsCredentialListMappingFetcher + extends Fetcher { - - -public class AuthRegistrationsCredentialListMappingFetcher extends Fetcher { private String pathDomainSid; private String pathSid; private String pathAccountSid; - public AuthRegistrationsCredentialListMappingFetcher(final String pathDomainSid, final String pathSid){ + public AuthRegistrationsCredentialListMappingFetcher( + final String pathDomainSid, + final String pathSid + ) { this.pathDomainSid = pathDomainSid; this.pathSid = pathSid; } - public AuthRegistrationsCredentialListMappingFetcher(final String pathAccountSid, final String pathDomainSid, final String pathSid){ + + public AuthRegistrationsCredentialListMappingFetcher( + final String pathAccountSid, + final String pathDomainSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathDomainSid = pathDomainSid; this.pathSid = pathSid; } - @Override - public AuthRegistrationsCredentialListMapping fetch(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Registrations/CredentialListMappings/{Sid}.json"; + public AuthRegistrationsCredentialListMapping fetch( + final TwilioRestClient client + ) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Registrations/CredentialListMappings/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"DomainSid"+"}", this.pathDomainSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "DomainSid" + "}", + this.pathDomainSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -60,15 +80,23 @@ public AuthRegistrationsCredentialListMapping fetch(final TwilioRestClient clien Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AuthRegistrationsCredentialListMapping fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "AuthRegistrationsCredentialListMapping fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return AuthRegistrationsCredentialListMapping.fromJson(response.getStream(), client.getObjectMapper()); + return AuthRegistrationsCredentialListMapping.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtyperegistrations/AuthRegistrationsCredentialListMappingReader.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtyperegistrations/AuthRegistrationsCredentialListMappingReader.java index 8f71de2659..c4356f81d9 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtyperegistrations/AuthRegistrationsCredentialListMappingReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtyperegistrations/AuthRegistrationsCredentialListMappingReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.api.v2010.account.sip.domain.authtypes.authtyperegistrations; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,38 +25,61 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - +public class AuthRegistrationsCredentialListMappingReader + extends Reader { -public class AuthRegistrationsCredentialListMappingReader extends Reader { private String pathDomainSid; private String pathAccountSid; private Integer pageSize; - public AuthRegistrationsCredentialListMappingReader(final String pathDomainSid){ + public AuthRegistrationsCredentialListMappingReader( + final String pathDomainSid + ) { this.pathDomainSid = pathDomainSid; } - public AuthRegistrationsCredentialListMappingReader(final String pathAccountSid, final String pathDomainSid){ + + public AuthRegistrationsCredentialListMappingReader( + final String pathAccountSid, + final String pathDomainSid + ) { this.pathAccountSid = pathAccountSid; this.pathDomainSid = pathDomainSid; } - public AuthRegistrationsCredentialListMappingReader setPageSize(final Integer pageSize){ + public AuthRegistrationsCredentialListMappingReader setPageSize( + final Integer pageSize + ) { this.pageSize = pageSize; return this; } @Override - public ResourceSet read(final TwilioRestClient client) { + public ResourceSet read( + final TwilioRestClient client + ) { return new ResourceSet<>(this, client, firstPage(client)); } - public Page firstPage(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Registrations/CredentialListMappings.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"DomainSid"+"}", this.pathDomainSid.toString()); + public Page firstPage( + final TwilioRestClient client + ) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Registrations/CredentialListMappings.json"; + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "DomainSid" + "}", + this.pathDomainSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -67,13 +91,21 @@ public Page firstPage(final TwilioRestCl return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AuthRegistrationsCredentialListMapping read failed: Unable to connect to server"); + throw new ApiConnectionException( + "AuthRegistrationsCredentialListMapping read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -89,7 +121,10 @@ private Page pageForRequest(final Twilio } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.API.toString()) @@ -97,9 +132,11 @@ public Page previousPage(final Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.API.toString()) @@ -108,21 +145,21 @@ public Page nextPage(final Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/ipaccesscontrollist/IpAddress.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/ipaccesscontrollist/IpAddress.java index e13f0e0bf9..4f7db3b4ad 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/ipaccesscontrollist/IpAddress.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/ipaccesscontrollist/IpAddress.java @@ -23,67 +23,127 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class IpAddress extends Resource { + private static final long serialVersionUID = 125766891149812L; - public static IpAddressCreator creator(final String pathIpAccessControlListSid, final String friendlyName, final String ipAddress){ - return new IpAddressCreator(pathIpAccessControlListSid, friendlyName, ipAddress); + public static IpAddressCreator creator( + final String pathIpAccessControlListSid, + final String friendlyName, + final String ipAddress + ) { + return new IpAddressCreator( + pathIpAccessControlListSid, + friendlyName, + ipAddress + ); } - public static IpAddressCreator creator(final String pathAccountSid, final String pathIpAccessControlListSid, final String friendlyName, final String ipAddress){ - return new IpAddressCreator(pathAccountSid, pathIpAccessControlListSid, friendlyName, ipAddress); + + public static IpAddressCreator creator( + final String pathAccountSid, + final String pathIpAccessControlListSid, + final String friendlyName, + final String ipAddress + ) { + return new IpAddressCreator( + pathAccountSid, + pathIpAccessControlListSid, + friendlyName, + ipAddress + ); } - public static IpAddressDeleter deleter(final String pathIpAccessControlListSid, final String pathSid){ + public static IpAddressDeleter deleter( + final String pathIpAccessControlListSid, + final String pathSid + ) { return new IpAddressDeleter(pathIpAccessControlListSid, pathSid); } - public static IpAddressDeleter deleter(final String pathAccountSid, final String pathIpAccessControlListSid, final String pathSid){ - return new IpAddressDeleter(pathAccountSid, pathIpAccessControlListSid, pathSid); + + public static IpAddressDeleter deleter( + final String pathAccountSid, + final String pathIpAccessControlListSid, + final String pathSid + ) { + return new IpAddressDeleter( + pathAccountSid, + pathIpAccessControlListSid, + pathSid + ); } - public static IpAddressFetcher fetcher(final String pathIpAccessControlListSid, final String pathSid){ + public static IpAddressFetcher fetcher( + final String pathIpAccessControlListSid, + final String pathSid + ) { return new IpAddressFetcher(pathIpAccessControlListSid, pathSid); } - public static IpAddressFetcher fetcher(final String pathAccountSid, final String pathIpAccessControlListSid, final String pathSid){ - return new IpAddressFetcher(pathAccountSid, pathIpAccessControlListSid, pathSid); + + public static IpAddressFetcher fetcher( + final String pathAccountSid, + final String pathIpAccessControlListSid, + final String pathSid + ) { + return new IpAddressFetcher( + pathAccountSid, + pathIpAccessControlListSid, + pathSid + ); } - public static IpAddressReader reader(final String pathIpAccessControlListSid){ + public static IpAddressReader reader( + final String pathIpAccessControlListSid + ) { return new IpAddressReader(pathIpAccessControlListSid); } - public static IpAddressReader reader(final String pathAccountSid, final String pathIpAccessControlListSid){ + + public static IpAddressReader reader( + final String pathAccountSid, + final String pathIpAccessControlListSid + ) { return new IpAddressReader(pathAccountSid, pathIpAccessControlListSid); } - public static IpAddressUpdater updater(final String pathIpAccessControlListSid, final String pathSid){ + public static IpAddressUpdater updater( + final String pathIpAccessControlListSid, + final String pathSid + ) { return new IpAddressUpdater(pathIpAccessControlListSid, pathSid); } - public static IpAddressUpdater updater(final String pathAccountSid, final String pathIpAccessControlListSid, final String pathSid){ - return new IpAddressUpdater(pathAccountSid, pathIpAccessControlListSid, pathSid); + + public static IpAddressUpdater updater( + final String pathAccountSid, + final String pathIpAccessControlListSid, + final String pathSid + ) { + return new IpAddressUpdater( + pathAccountSid, + pathIpAccessControlListSid, + pathSid + ); } /** - * Converts a JSON String into a IpAddress object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return IpAddress object represented by the provided JSON - */ - public static IpAddress fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a IpAddress object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return IpAddress object represented by the provided JSON + */ + public static IpAddress fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, IpAddress.class); @@ -95,14 +155,17 @@ public static IpAddress fromJson(final String json, final ObjectMapper objectMap } /** - * Converts a JSON InputStream into a IpAddress object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return IpAddress object represented by the provided JSON - */ - public static IpAddress fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a IpAddress object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return IpAddress object represented by the provided JSON + */ + public static IpAddress fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, IpAddress.class); @@ -125,32 +188,17 @@ public static IpAddress fromJson(final InputStream json, final ObjectMapper obje @JsonCreator private IpAddress( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("ip_address") - final String ipAddress, - - @JsonProperty("cidr_prefix_length") - final Integer cidrPrefixLength, - - @JsonProperty("ip_access_control_list_sid") - final String ipAccessControlListSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("uri") - final String uri + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("ip_address") final String ipAddress, + @JsonProperty("cidr_prefix_length") final Integer cidrPrefixLength, + @JsonProperty( + "ip_access_control_list_sid" + ) final String ipAccessControlListSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("uri") final String uri ) { this.sid = sid; this.accountSid = accountSid; @@ -163,37 +211,45 @@ private IpAddress( this.uri = uri; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getIpAddress() { - return this.ipAddress; - } - public final Integer getCidrPrefixLength() { - return this.cidrPrefixLength; - } - public final String getIpAccessControlListSid() { - return this.ipAccessControlListSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getUri() { - return this.uri; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getIpAddress() { + return this.ipAddress; + } + + public final Integer getCidrPrefixLength() { + return this.cidrPrefixLength; + } + + public final String getIpAccessControlListSid() { + return this.ipAccessControlListSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getUri() { + return this.uri; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -203,13 +259,34 @@ public boolean equals(final Object o) { IpAddress other = (IpAddress) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(ipAddress, other.ipAddress) && Objects.equals(cidrPrefixLength, other.cidrPrefixLength) && Objects.equals(ipAccessControlListSid, other.ipAccessControlListSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(uri, other.uri) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(ipAddress, other.ipAddress) && + Objects.equals(cidrPrefixLength, other.cidrPrefixLength) && + Objects.equals( + ipAccessControlListSid, + other.ipAccessControlListSid + ) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(uri, other.uri) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, friendlyName, ipAddress, cidrPrefixLength, ipAccessControlListSid, dateCreated, dateUpdated, uri); + return Objects.hash( + sid, + accountSid, + friendlyName, + ipAddress, + cidrPrefixLength, + ipAccessControlListSid, + dateCreated, + dateUpdated, + uri + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/ipaccesscontrollist/IpAddressCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/ipaccesscontrollist/IpAddressCreator.java index 4f906be427..84fe63385f 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/ipaccesscontrollist/IpAddressCreator.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/ipaccesscontrollist/IpAddressCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010.account.sip.ipaccesscontrollist; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,82 +25,120 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class IpAddressCreator extends Creator { - - -public class IpAddressCreator extends Creator{ private String pathIpAccessControlListSid; private String friendlyName; private String ipAddress; private String pathAccountSid; private Integer cidrPrefixLength; - public IpAddressCreator(final String pathIpAccessControlListSid, final String friendlyName, final String ipAddress) { + public IpAddressCreator( + final String pathIpAccessControlListSid, + final String friendlyName, + final String ipAddress + ) { this.pathIpAccessControlListSid = pathIpAccessControlListSid; this.friendlyName = friendlyName; this.ipAddress = ipAddress; } - public IpAddressCreator(final String pathAccountSid, final String pathIpAccessControlListSid, final String friendlyName, final String ipAddress) { + + public IpAddressCreator( + final String pathAccountSid, + final String pathIpAccessControlListSid, + final String friendlyName, + final String ipAddress + ) { this.pathAccountSid = pathAccountSid; this.pathIpAccessControlListSid = pathIpAccessControlListSid; this.friendlyName = friendlyName; this.ipAddress = ipAddress; } - public IpAddressCreator setFriendlyName(final String friendlyName){ + public IpAddressCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public IpAddressCreator setIpAddress(final String ipAddress){ + + public IpAddressCreator setIpAddress(final String ipAddress) { this.ipAddress = ipAddress; return this; } - public IpAddressCreator setCidrPrefixLength(final Integer cidrPrefixLength){ + + public IpAddressCreator setCidrPrefixLength( + final Integer cidrPrefixLength + ) { this.cidrPrefixLength = cidrPrefixLength; return this; } @Override - public IpAddress create(final TwilioRestClient client){ - String path = "/2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists/{IpAccessControlListSid}/IpAddresses.json"; + public IpAddress create(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists/{IpAccessControlListSid}/IpAddresses.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"IpAccessControlListSid"+"}", this.pathIpAccessControlListSid.toString()); - path = path.replace("{"+"FriendlyName"+"}", this.friendlyName.toString()); - path = path.replace("{"+"IpAddress"+"}", this.ipAddress.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "IpAccessControlListSid" + "}", + this.pathIpAccessControlListSid.toString() + ); + path = + path.replace( + "{" + "FriendlyName" + "}", + this.friendlyName.toString() + ); + path = path.replace("{" + "IpAddress" + "}", this.ipAddress.toString()); Request request = new Request( HttpMethod.POST, Domains.API.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("IpAddress creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "IpAddress creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return IpAddress.fromJson(response.getStream(), client.getObjectMapper()); + return IpAddress.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (ipAddress != null) { request.addPostParam("IpAddress", ipAddress); - } if (cidrPrefixLength != null) { - request.addPostParam("CidrPrefixLength", cidrPrefixLength.toString()); - + request.addPostParam( + "CidrPrefixLength", + cidrPrefixLength.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/ipaccesscontrollist/IpAddressDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/ipaccesscontrollist/IpAddressDeleter.java index 411c0cbbc4..aa35921aec 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/ipaccesscontrollist/IpAddressDeleter.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/ipaccesscontrollist/IpAddressDeleter.java @@ -24,32 +24,50 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class IpAddressDeleter extends Deleter { + private String pathIpAccessControlListSid; private String pathSid; private String pathAccountSid; - public IpAddressDeleter(final String pathIpAccessControlListSid, final String pathSid){ + public IpAddressDeleter( + final String pathIpAccessControlListSid, + final String pathSid + ) { this.pathIpAccessControlListSid = pathIpAccessControlListSid; this.pathSid = pathSid; } - public IpAddressDeleter(final String pathAccountSid, final String pathIpAccessControlListSid, final String pathSid){ + + public IpAddressDeleter( + final String pathAccountSid, + final String pathIpAccessControlListSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathIpAccessControlListSid = pathIpAccessControlListSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists/{IpAccessControlListSid}/IpAddresses/{Sid}.json"; + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists/{IpAccessControlListSid}/IpAddresses/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"IpAccessControlListSid"+"}", this.pathIpAccessControlListSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "IpAccessControlListSid" + "}", + this.pathIpAccessControlListSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -59,9 +77,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("IpAddress delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "IpAddress delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/ipaccesscontrollist/IpAddressFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/ipaccesscontrollist/IpAddressFetcher.java index 5e0b59ed77..e4e9bb21e2 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/ipaccesscontrollist/IpAddressFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/ipaccesscontrollist/IpAddressFetcher.java @@ -24,33 +24,50 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class IpAddressFetcher extends Fetcher { + private String pathIpAccessControlListSid; private String pathSid; private String pathAccountSid; - public IpAddressFetcher(final String pathIpAccessControlListSid, final String pathSid){ + public IpAddressFetcher( + final String pathIpAccessControlListSid, + final String pathSid + ) { this.pathIpAccessControlListSid = pathIpAccessControlListSid; this.pathSid = pathSid; } - public IpAddressFetcher(final String pathAccountSid, final String pathIpAccessControlListSid, final String pathSid){ + + public IpAddressFetcher( + final String pathAccountSid, + final String pathIpAccessControlListSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathIpAccessControlListSid = pathIpAccessControlListSid; this.pathSid = pathSid; } - @Override public IpAddress fetch(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists/{IpAccessControlListSid}/IpAddresses/{Sid}.json"; + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists/{IpAccessControlListSid}/IpAddresses/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"IpAccessControlListSid"+"}", this.pathIpAccessControlListSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "IpAccessControlListSid" + "}", + this.pathIpAccessControlListSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -60,15 +77,23 @@ public IpAddress fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("IpAddress fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "IpAddress fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return IpAddress.fromJson(response.getStream(), client.getObjectMapper()); + return IpAddress.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/ipaccesscontrollist/IpAddressReader.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/ipaccesscontrollist/IpAddressReader.java index e800b9ec55..56675f9256 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/ipaccesscontrollist/IpAddressReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/ipaccesscontrollist/IpAddressReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.api.v2010.account.sip.ipaccesscontrollist; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,24 +25,26 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class IpAddressReader extends Reader { + private String pathIpAccessControlListSid; private String pathAccountSid; private Integer pageSize; - public IpAddressReader(final String pathIpAccessControlListSid){ + public IpAddressReader(final String pathIpAccessControlListSid) { this.pathIpAccessControlListSid = pathIpAccessControlListSid; } - public IpAddressReader(final String pathAccountSid, final String pathIpAccessControlListSid){ + + public IpAddressReader( + final String pathAccountSid, + final String pathIpAccessControlListSid + ) { this.pathAccountSid = pathAccountSid; this.pathIpAccessControlListSid = pathIpAccessControlListSid; } - public IpAddressReader setPageSize(final Integer pageSize){ + public IpAddressReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -52,10 +55,22 @@ public ResourceSet read(final TwilioRestClient client) { } public Page firstPage(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists/{IpAccessControlListSid}/IpAddresses.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"IpAccessControlListSid"+"}", this.pathIpAccessControlListSid.toString()); + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists/{IpAccessControlListSid}/IpAddresses.json"; + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "IpAccessControlListSid" + "}", + this.pathIpAccessControlListSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -67,13 +82,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("IpAddress read failed: Unable to connect to server"); + throw new ApiConnectionException( + "IpAddress read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -89,7 +112,10 @@ private Page pageForRequest(final TwilioRestClient client, final Requ } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.API.toString()) @@ -97,9 +123,11 @@ public Page previousPage(final Page page, final TwilioRest return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.API.toString()) @@ -108,21 +136,21 @@ public Page nextPage(final Page page, final TwilioRestClie } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/ipaccesscontrollist/IpAddressUpdater.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/ipaccesscontrollist/IpAddressUpdater.java index 9a2e139a1a..1208657c2f 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/ipaccesscontrollist/IpAddressUpdater.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/ipaccesscontrollist/IpAddressUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010.account.sip.ipaccesscontrollist; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class IpAddressUpdater extends Updater { - - -public class IpAddressUpdater extends Updater{ private String pathIpAccessControlListSid; private String pathSid; private String pathAccountSid; @@ -35,69 +34,103 @@ public class IpAddressUpdater extends Updater{ private String friendlyName; private Integer cidrPrefixLength; - public IpAddressUpdater(final String pathIpAccessControlListSid, final String pathSid){ + public IpAddressUpdater( + final String pathIpAccessControlListSid, + final String pathSid + ) { this.pathIpAccessControlListSid = pathIpAccessControlListSid; this.pathSid = pathSid; } - public IpAddressUpdater(final String pathAccountSid, final String pathIpAccessControlListSid, final String pathSid){ + + public IpAddressUpdater( + final String pathAccountSid, + final String pathIpAccessControlListSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathIpAccessControlListSid = pathIpAccessControlListSid; this.pathSid = pathSid; } - public IpAddressUpdater setIpAddress(final String ipAddress){ + public IpAddressUpdater setIpAddress(final String ipAddress) { this.ipAddress = ipAddress; return this; } - public IpAddressUpdater setFriendlyName(final String friendlyName){ + + public IpAddressUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public IpAddressUpdater setCidrPrefixLength(final Integer cidrPrefixLength){ + + public IpAddressUpdater setCidrPrefixLength( + final Integer cidrPrefixLength + ) { this.cidrPrefixLength = cidrPrefixLength; return this; } @Override - public IpAddress update(final TwilioRestClient client){ - String path = "/2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists/{IpAccessControlListSid}/IpAddresses/{Sid}.json"; + public IpAddress update(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists/{IpAccessControlListSid}/IpAddresses/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"IpAccessControlListSid"+"}", this.pathIpAccessControlListSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "IpAccessControlListSid" + "}", + this.pathIpAccessControlListSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.API.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("IpAddress update failed: Unable to connect to server"); + throw new ApiConnectionException( + "IpAddress update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return IpAddress.fromJson(response.getStream(), client.getObjectMapper()); + return IpAddress.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (ipAddress != null) { request.addPostParam("IpAddress", ipAddress); - } if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (cidrPrefixLength != null) { - request.addPostParam("CidrPrefixLength", cidrPrefixLength.toString()); - + request.addPostParam( + "CidrPrefixLength", + cidrPrefixLength.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/usage/Record.java b/src/main/java/com/twilio/rest/api/v2010/account/usage/Record.java index 5db86e3aef..2377a1cb85 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/usage/Record.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/usage/Record.java @@ -20,49 +20,49 @@ import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.twilio.base.Resource; -import java.util.Currency; +import com.twilio.converter.CurrencyDeserializer; import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; -import com.twilio.converter.CurrencyDeserializer; import com.twilio.exception.ApiConnectionException; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; - +import java.math.BigDecimal; +import java.time.LocalDate; +import java.util.Currency; import java.util.Map; -import java.util.Objects; - - import java.util.Map; -import java.time.LocalDate; -import java.math.BigDecimal; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Record extends Resource { + private static final long serialVersionUID = 267972709897131L; - public static RecordReader reader(){ + public static RecordReader reader() { return new RecordReader(); } - public static RecordReader reader(final String pathAccountSid){ + + public static RecordReader reader(final String pathAccountSid) { return new RecordReader(pathAccountSid); } /** - * Converts a JSON String into a Record object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Record object represented by the provided JSON - */ - public static Record fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Record object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Record object represented by the provided JSON + */ + public static Record fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Record.class); @@ -74,14 +74,17 @@ public static Record fromJson(final String json, final ObjectMapper objectMapper } /** - * Converts a JSON InputStream into a Record object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Record object represented by the provided JSON - */ - public static Record fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Record object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Record object represented by the provided JSON + */ + public static Record fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Record.class); @@ -91,6 +94,7 @@ public static Record fromJson(final InputStream json, final ObjectMapper objectM throw new ApiConnectionException(e.getMessage(), e); } } + public enum Category { A2P_REGISTRATION_FEES("a2p-registration-fees"), AGENT_CONFERENCE("agent-conference"), @@ -122,7 +126,9 @@ public enum Category { CONVERSATIONS("conversations"), CONVERSATIONS_API_REQUESTS("conversations-api-requests"), CONVERSATIONS_CONVERSATION_EVENTS("conversations-conversation-events"), - CONVERSATIONS_ENDPOINT_CONNECTIVITY("conversations-endpoint-connectivity"), + CONVERSATIONS_ENDPOINT_CONNECTIVITY( + "conversations-endpoint-connectivity" + ), CONVERSATIONS_EVENTS("conversations-events"), CONVERSATIONS_PARTICIPANT_EVENTS("conversations-participant-events"), CONVERSATIONS_PARTICIPANTS("conversations-participants"), @@ -131,7 +137,9 @@ public enum Category { FRAUD_LOOKUPS("fraud-lookups"), GROUP_ROOMS("group-rooms"), GROUP_ROOMS_DATA_TRACK("group-rooms-data-track"), - GROUP_ROOMS_ENCRYPTED_MEDIA_RECORDED("group-rooms-encrypted-media-recorded"), + GROUP_ROOMS_ENCRYPTED_MEDIA_RECORDED( + "group-rooms-encrypted-media-recorded" + ), GROUP_ROOMS_MEDIA_DOWNLOADED("group-rooms-media-downloaded"), GROUP_ROOMS_MEDIA_RECORDED("group-rooms-media-recorded"), GROUP_ROOMS_MEDIA_ROUTED("group-rooms-media-routed"), @@ -141,45 +149,99 @@ public enum Category { IMP_V1_USAGE("imp-v1-usage"), LOOKUPS("lookups"), MARKETPLACE("marketplace"), - MARKETPLACE_ALGORITHMIA_NAMED_ENTITY_RECOGNITION("marketplace-algorithmia-named-entity-recognition"), + MARKETPLACE_ALGORITHMIA_NAMED_ENTITY_RECOGNITION( + "marketplace-algorithmia-named-entity-recognition" + ), MARKETPLACE_CADENCE_TRANSCRIPTION("marketplace-cadence-transcription"), MARKETPLACE_CADENCE_TRANSLATION("marketplace-cadence-translation"), MARKETPLACE_CAPIO_SPEECH_TO_TEXT("marketplace-capio-speech-to-text"), MARKETPLACE_CONVRIZA_ABABA("marketplace-convriza-ababa"), - MARKETPLACE_DEEPGRAM_PHRASE_DETECTOR("marketplace-deepgram-phrase-detector"), - MARKETPLACE_DIGITAL_SEGMENT_BUSINESS_INFO("marketplace-digital-segment-business-info"), - MARKETPLACE_FACEBOOK_OFFLINE_CONVERSIONS("marketplace-facebook-offline-conversions"), + MARKETPLACE_DEEPGRAM_PHRASE_DETECTOR( + "marketplace-deepgram-phrase-detector" + ), + MARKETPLACE_DIGITAL_SEGMENT_BUSINESS_INFO( + "marketplace-digital-segment-business-info" + ), + MARKETPLACE_FACEBOOK_OFFLINE_CONVERSIONS( + "marketplace-facebook-offline-conversions" + ), MARKETPLACE_GOOGLE_SPEECH_TO_TEXT("marketplace-google-speech-to-text"), - MARKETPLACE_IBM_WATSON_MESSAGE_INSIGHTS("marketplace-ibm-watson-message-insights"), - MARKETPLACE_IBM_WATSON_MESSAGE_SENTIMENT("marketplace-ibm-watson-message-sentiment"), - MARKETPLACE_IBM_WATSON_RECORDING_ANALYSIS("marketplace-ibm-watson-recording-analysis"), - MARKETPLACE_IBM_WATSON_TONE_ANALYZER("marketplace-ibm-watson-tone-analyzer"), + MARKETPLACE_IBM_WATSON_MESSAGE_INSIGHTS( + "marketplace-ibm-watson-message-insights" + ), + MARKETPLACE_IBM_WATSON_MESSAGE_SENTIMENT( + "marketplace-ibm-watson-message-sentiment" + ), + MARKETPLACE_IBM_WATSON_RECORDING_ANALYSIS( + "marketplace-ibm-watson-recording-analysis" + ), + MARKETPLACE_IBM_WATSON_TONE_ANALYZER( + "marketplace-ibm-watson-tone-analyzer" + ), MARKETPLACE_ICEHOOK_SYSTEMS_SCOUT("marketplace-icehook-systems-scout"), - MARKETPLACE_INFOGROUP_DATAAXLE_BIZINFO("marketplace-infogroup-dataaxle-bizinfo"), - MARKETPLACE_KEEN_IO_CONTACT_CENTER_ANALYTICS("marketplace-keen-io-contact-center-analytics"), + MARKETPLACE_INFOGROUP_DATAAXLE_BIZINFO( + "marketplace-infogroup-dataaxle-bizinfo" + ), + MARKETPLACE_KEEN_IO_CONTACT_CENTER_ANALYTICS( + "marketplace-keen-io-contact-center-analytics" + ), MARKETPLACE_MARCHEX_CLEANCALL("marketplace-marchex-cleancall"), - MARKETPLACE_MARCHEX_SENTIMENT_ANALYSIS_FOR_SMS("marketplace-marchex-sentiment-analysis-for-sms"), - MARKETPLACE_MARKETPLACE_NEXTCALLER_SOCIAL_ID("marketplace-marketplace-nextcaller-social-id"), - MARKETPLACE_MOBILE_COMMONS_OPT_OUT_CLASSIFIER("marketplace-mobile-commons-opt-out-classifier"), - MARKETPLACE_NEXIWAVE_VOICEMAIL_TO_TEXT("marketplace-nexiwave-voicemail-to-text"), - MARKETPLACE_NEXTCALLER_ADVANCED_CALLER_IDENTIFICATION("marketplace-nextcaller-advanced-caller-identification"), + MARKETPLACE_MARCHEX_SENTIMENT_ANALYSIS_FOR_SMS( + "marketplace-marchex-sentiment-analysis-for-sms" + ), + MARKETPLACE_MARKETPLACE_NEXTCALLER_SOCIAL_ID( + "marketplace-marketplace-nextcaller-social-id" + ), + MARKETPLACE_MOBILE_COMMONS_OPT_OUT_CLASSIFIER( + "marketplace-mobile-commons-opt-out-classifier" + ), + MARKETPLACE_NEXIWAVE_VOICEMAIL_TO_TEXT( + "marketplace-nexiwave-voicemail-to-text" + ), + MARKETPLACE_NEXTCALLER_ADVANCED_CALLER_IDENTIFICATION( + "marketplace-nextcaller-advanced-caller-identification" + ), MARKETPLACE_NOMOROBO_SPAM_SCORE("marketplace-nomorobo-spam-score"), - MARKETPLACE_PAYFONE_TCPA_COMPLIANCE("marketplace-payfone-tcpa-compliance"), - MARKETPLACE_REMEETING_AUTOMATIC_SPEECH_RECOGNITION("marketplace-remeeting-automatic-speech-recognition"), - MARKETPLACE_TCPA_DEFENSE_SOLUTIONS_BLACKLIST_FEED("marketplace-tcpa-defense-solutions-blacklist-feed"), + MARKETPLACE_PAYFONE_TCPA_COMPLIANCE( + "marketplace-payfone-tcpa-compliance" + ), + MARKETPLACE_REMEETING_AUTOMATIC_SPEECH_RECOGNITION( + "marketplace-remeeting-automatic-speech-recognition" + ), + MARKETPLACE_TCPA_DEFENSE_SOLUTIONS_BLACKLIST_FEED( + "marketplace-tcpa-defense-solutions-blacklist-feed" + ), MARKETPLACE_TELO_OPENCNAM("marketplace-telo-opencnam"), MARKETPLACE_TRUECNAM_TRUE_SPAM("marketplace-truecnam-true-spam"), - MARKETPLACE_TWILIO_CALLER_NAME_LOOKUP_US("marketplace-twilio-caller-name-lookup-us"), - MARKETPLACE_TWILIO_CARRIER_INFORMATION_LOOKUP("marketplace-twilio-carrier-information-lookup"), + MARKETPLACE_TWILIO_CALLER_NAME_LOOKUP_US( + "marketplace-twilio-caller-name-lookup-us" + ), + MARKETPLACE_TWILIO_CARRIER_INFORMATION_LOOKUP( + "marketplace-twilio-carrier-information-lookup" + ), MARKETPLACE_VOICEBASE_PCI("marketplace-voicebase-pci"), - MARKETPLACE_VOICEBASE_TRANSCRIPTION("marketplace-voicebase-transcription"), - MARKETPLACE_VOICEBASE_TRANSCRIPTION_CUSTOM_VOCABULARY("marketplace-voicebase-transcription-custom-vocabulary"), - MARKETPLACE_WHITEPAGES_PRO_CALLER_IDENTIFICATION("marketplace-whitepages-pro-caller-identification"), - MARKETPLACE_WHITEPAGES_PRO_PHONE_INTELLIGENCE("marketplace-whitepages-pro-phone-intelligence"), - MARKETPLACE_WHITEPAGES_PRO_PHONE_REPUTATION("marketplace-whitepages-pro-phone-reputation"), - MARKETPLACE_WOLFARM_SPOKEN_RESULTS("marketplace-wolfarm-spoken-results"), + MARKETPLACE_VOICEBASE_TRANSCRIPTION( + "marketplace-voicebase-transcription" + ), + MARKETPLACE_VOICEBASE_TRANSCRIPTION_CUSTOM_VOCABULARY( + "marketplace-voicebase-transcription-custom-vocabulary" + ), + MARKETPLACE_WHITEPAGES_PRO_CALLER_IDENTIFICATION( + "marketplace-whitepages-pro-caller-identification" + ), + MARKETPLACE_WHITEPAGES_PRO_PHONE_INTELLIGENCE( + "marketplace-whitepages-pro-phone-intelligence" + ), + MARKETPLACE_WHITEPAGES_PRO_PHONE_REPUTATION( + "marketplace-whitepages-pro-phone-reputation" + ), + MARKETPLACE_WOLFARM_SPOKEN_RESULTS( + "marketplace-wolfarm-spoken-results" + ), MARKETPLACE_WOLFRAM_SHORT_ANSWER("marketplace-wolfram-short-answer"), - MARKETPLACE_YTICA_CONTACT_CENTER_REPORTING_ANALYTICS("marketplace-ytica-contact-center-reporting-analytics"), + MARKETPLACE_YTICA_CONTACT_CENTER_REPORTING_ANALYTICS( + "marketplace-ytica-contact-center-reporting-analytics" + ), MEDIASTORAGE("mediastorage"), MMS("mms"), MMS_INBOUND("mms-inbound"), @@ -198,7 +260,9 @@ public enum Category { NUMBER_FORMAT_LOOKUPS("number-format-lookups"), PCHAT("pchat"), PCHAT_USERS("pchat-users"), - PEER_TO_PEER_ROOMS_PARTICIPANT_MINUTES("peer-to-peer-rooms-participant-minutes"), + PEER_TO_PEER_ROOMS_PARTICIPANT_MINUTES( + "peer-to-peer-rooms-participant-minutes" + ), PFAX("pfax"), PFAX_MINUTES("pfax-minutes"), PFAX_MINUTES_INBOUND("pfax-minutes-inbound"), @@ -245,7 +309,9 @@ public enum Category { SHORTCODES_VANITY("shortcodes-vanity"), SMALL_GROUP_ROOMS("small-group-rooms"), SMALL_GROUP_ROOMS_DATA_TRACK("small-group-rooms-data-track"), - SMALL_GROUP_ROOMS_PARTICIPANT_MINUTES("small-group-rooms-participant-minutes"), + SMALL_GROUP_ROOMS_PARTICIPANT_MINUTES( + "small-group-rooms-participant-minutes" + ), SMS("sms"), SMS_INBOUND("sms-inbound"), SMS_INBOUND_LONGCODE("sms-inbound-longcode"), @@ -262,7 +328,9 @@ public enum Category { SYNC("sync"), SYNC_ACTIONS("sync-actions"), SYNC_ENDPOINT_HOURS("sync-endpoint-hours"), - SYNC_ENDPOINT_HOURS_ABOVE_DAILY_CAP("sync-endpoint-hours-above-daily-cap"), + SYNC_ENDPOINT_HOURS_ABOVE_DAILY_CAP( + "sync-endpoint-hours-above-daily-cap" + ), TASKROUTER_TASKS("taskrouter-tasks"), TOTALPRICE("totalprice"), TRANSCRIPTIONS("transcriptions"), @@ -275,6 +343,7 @@ public enum Category { TRUNKING_RECORDINGS("trunking-recordings"), TRUNKING_SECURE("trunking-secure"), TRUNKING_TERMINATION("trunking-termination"), + TTS_GOOGLE("tts-google"), TURNMEGABYTES("turnmegabytes"), TURNMEGABYTES_AUSTRALIA("turnmegabytes-australia"), TURNMEGABYTES_BRASIL("turnmegabytes-brasil"), @@ -288,14 +357,27 @@ public enum Category { TWILIO_INTERCONNECT("twilio-interconnect"), VERIFY_PUSH("verify-push"), VERIFY_TOTP("verify-totp"), - VERIFY_WHATSAPP_CONVERSATIONS_BUSINESS_INITIATED("verify-whatsapp-conversations-business-initiated"), + VERIFY_WHATSAPP_CONVERSATIONS_BUSINESS_INITIATED( + "verify-whatsapp-conversations-business-initiated" + ), VIDEO_RECORDINGS("video-recordings"), VIRTUAL_AGENT("virtual-agent"), VOICE_INSIGHTS("voice-insights"), - VOICE_INSIGHTS_CLIENT_INSIGHTS_ON_DEMAND_MINUTE("voice-insights-client-insights-on-demand-minute"), - VOICE_INSIGHTS_PTSN_INSIGHTS_ON_DEMAND_MINUTE("voice-insights-ptsn-insights-on-demand-minute"), - VOICE_INSIGHTS_SIP_INTERFACE_INSIGHTS_ON_DEMAND_MINUTE("voice-insights-sip-interface-insights-on-demand-minute"), - VOICE_INSIGHTS_SIP_TRUNKING_INSIGHTS_ON_DEMAND_MINUTE("voice-insights-sip-trunking-insights-on-demand-minute"), + VOICE_INSIGHTS_CLIENT_INSIGHTS_ON_DEMAND_MINUTE( + "voice-insights-client-insights-on-demand-minute" + ), + VOICE_INSIGHTS_PTSN_INSIGHTS_ON_DEMAND_MINUTE( + "voice-insights-ptsn-insights-on-demand-minute" + ), + VOICE_INSIGHTS_SIP_INTERFACE_INSIGHTS_ON_DEMAND_MINUTE( + "voice-insights-sip-interface-insights-on-demand-minute" + ), + VOICE_INSIGHTS_SIP_TRUNKING_INSIGHTS_ON_DEMAND_MINUTE( + "voice-insights-sip-trunking-insights-on-demand-minute" + ), + VOICE_INTELLIGENCE("voice-intelligence"), + VOICE_INTELLIGENCE_TRANSCRIPTION("voice-intelligence-transcription"), + VOICE_INTELLIGENCE_OPERATORS("voice-intelligence-operators"), WIRELESS("wireless"), WIRELESS_ORDERS("wireless-orders"), WIRELESS_ORDERS_ARTWORK("wireless-orders-artwork"), @@ -306,29 +388,53 @@ public enum Category { WIRELESS_USAGE_COMMANDS("wireless-usage-commands"), WIRELESS_USAGE_COMMANDS_AFRICA("wireless-usage-commands-africa"), WIRELESS_USAGE_COMMANDS_ASIA("wireless-usage-commands-asia"), - WIRELESS_USAGE_COMMANDS_CENTRALANDSOUTHAMERICA("wireless-usage-commands-centralandsouthamerica"), + WIRELESS_USAGE_COMMANDS_CENTRALANDSOUTHAMERICA( + "wireless-usage-commands-centralandsouthamerica" + ), WIRELESS_USAGE_COMMANDS_EUROPE("wireless-usage-commands-europe"), WIRELESS_USAGE_COMMANDS_HOME("wireless-usage-commands-home"), - WIRELESS_USAGE_COMMANDS_NORTHAMERICA("wireless-usage-commands-northamerica"), + WIRELESS_USAGE_COMMANDS_NORTHAMERICA( + "wireless-usage-commands-northamerica" + ), WIRELESS_USAGE_COMMANDS_OCEANIA("wireless-usage-commands-oceania"), WIRELESS_USAGE_COMMANDS_ROAMING("wireless-usage-commands-roaming"), WIRELESS_USAGE_DATA("wireless-usage-data"), WIRELESS_USAGE_DATA_AFRICA("wireless-usage-data-africa"), WIRELESS_USAGE_DATA_ASIA("wireless-usage-data-asia"), - WIRELESS_USAGE_DATA_CENTRALANDSOUTHAMERICA("wireless-usage-data-centralandsouthamerica"), - WIRELESS_USAGE_DATA_CUSTOM_ADDITIONALMB("wireless-usage-data-custom-additionalmb"), - WIRELESS_USAGE_DATA_CUSTOM_FIRST5MB("wireless-usage-data-custom-first5mb"), - WIRELESS_USAGE_DATA_DOMESTIC_ROAMING("wireless-usage-data-domestic-roaming"), + WIRELESS_USAGE_DATA_CENTRALANDSOUTHAMERICA( + "wireless-usage-data-centralandsouthamerica" + ), + WIRELESS_USAGE_DATA_CUSTOM_ADDITIONALMB( + "wireless-usage-data-custom-additionalmb" + ), + WIRELESS_USAGE_DATA_CUSTOM_FIRST5MB( + "wireless-usage-data-custom-first5mb" + ), + WIRELESS_USAGE_DATA_DOMESTIC_ROAMING( + "wireless-usage-data-domestic-roaming" + ), WIRELESS_USAGE_DATA_EUROPE("wireless-usage-data-europe"), - WIRELESS_USAGE_DATA_INDIVIDUAL_ADDITIONALGB("wireless-usage-data-individual-additionalgb"), - WIRELESS_USAGE_DATA_INDIVIDUAL_FIRSTGB("wireless-usage-data-individual-firstgb"), - WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_CANADA("wireless-usage-data-international-roaming-canada"), - WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_INDIA("wireless-usage-data-international-roaming-india"), - WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_MEXICO("wireless-usage-data-international-roaming-mexico"), + WIRELESS_USAGE_DATA_INDIVIDUAL_ADDITIONALGB( + "wireless-usage-data-individual-additionalgb" + ), + WIRELESS_USAGE_DATA_INDIVIDUAL_FIRSTGB( + "wireless-usage-data-individual-firstgb" + ), + WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_CANADA( + "wireless-usage-data-international-roaming-canada" + ), + WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_INDIA( + "wireless-usage-data-international-roaming-india" + ), + WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_MEXICO( + "wireless-usage-data-international-roaming-mexico" + ), WIRELESS_USAGE_DATA_NORTHAMERICA("wireless-usage-data-northamerica"), WIRELESS_USAGE_DATA_OCEANIA("wireless-usage-data-oceania"), WIRELESS_USAGE_DATA_POOLED("wireless-usage-data-pooled"), - WIRELESS_USAGE_DATA_POOLED_DOWNLINK("wireless-usage-data-pooled-downlink"), + WIRELESS_USAGE_DATA_POOLED_DOWNLINK( + "wireless-usage-data-pooled-downlink" + ), WIRELESS_USAGE_DATA_POOLED_UPLINK("wireless-usage-data-pooled-uplink"), WIRELESS_USAGE_MRC("wireless-usage-mrc"), WIRELESS_USAGE_MRC_CUSTOM("wireless-usage-mrc-custom"), @@ -372,51 +478,25 @@ public static Category forValue(final String value) { @JsonCreator private Record( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("api_version") - final String apiVersion, - - @JsonProperty("as_of") - final String asOf, - - @JsonProperty("category") - final Record.Category category, - - @JsonProperty("count") - final String count, - - @JsonProperty("count_unit") - final String countUnit, - - @JsonProperty("description") - final String description, - - @JsonProperty("end_date") - final String endDate, - - @JsonProperty("price") - final BigDecimal price, - - @JsonProperty("price_unit") - @JsonDeserialize(using = com.twilio.converter.CurrencyDeserializer.class) - final Currency priceUnit, - - @JsonProperty("start_date") - final String startDate, - - @JsonProperty("subresource_uris") - final Map subresourceUris, - - @JsonProperty("uri") - final String uri, - - @JsonProperty("usage") - final String usage, - - @JsonProperty("usage_unit") - final String usageUnit + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("api_version") final String apiVersion, + @JsonProperty("as_of") final String asOf, + @JsonProperty("category") final Record.Category category, + @JsonProperty("count") final String count, + @JsonProperty("count_unit") final String countUnit, + @JsonProperty("description") final String description, + @JsonProperty("end_date") final String endDate, + @JsonProperty("price") final BigDecimal price, + @JsonProperty("price_unit") @JsonDeserialize( + using = com.twilio.converter.CurrencyDeserializer.class + ) final Currency priceUnit, + @JsonProperty("start_date") final String startDate, + @JsonProperty( + "subresource_uris" + ) final Map subresourceUris, + @JsonProperty("uri") final String uri, + @JsonProperty("usage") final String usage, + @JsonProperty("usage_unit") final String usageUnit ) { this.accountSid = accountSid; this.apiVersion = apiVersion; @@ -435,55 +515,69 @@ private Record( this.usageUnit = usageUnit; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getApiVersion() { - return this.apiVersion; - } - public final String getAsOf() { - return this.asOf; - } - public final Record.Category getCategory() { - return this.category; - } - public final String getCount() { - return this.count; - } - public final String getCountUnit() { - return this.countUnit; - } - public final String getDescription() { - return this.description; - } - public final LocalDate getEndDate() { - return this.endDate; - } - public final BigDecimal getPrice() { - return this.price; - } - public final Currency getPriceUnit() { - return this.priceUnit; - } - public final LocalDate getStartDate() { - return this.startDate; - } - public final Map getSubresourceUris() { - return this.subresourceUris; - } - public final String getUri() { - return this.uri; - } - public final String getUsage() { - return this.usage; - } - public final String getUsageUnit() { - return this.usageUnit; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getApiVersion() { + return this.apiVersion; + } + + public final String getAsOf() { + return this.asOf; + } + + public final Record.Category getCategory() { + return this.category; + } + + public final String getCount() { + return this.count; + } + + public final String getCountUnit() { + return this.countUnit; + } + + public final String getDescription() { + return this.description; + } + + public final LocalDate getEndDate() { + return this.endDate; + } + + public final BigDecimal getPrice() { + return this.price; + } + + public final Currency getPriceUnit() { + return this.priceUnit; + } + + public final LocalDate getStartDate() { + return this.startDate; + } + + public final Map getSubresourceUris() { + return this.subresourceUris; + } + + public final String getUri() { + return this.uri; + } + + public final String getUsage() { + return this.usage; + } + + public final String getUsageUnit() { + return this.usageUnit; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -493,13 +587,43 @@ public boolean equals(final Object o) { Record other = (Record) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(apiVersion, other.apiVersion) && Objects.equals(asOf, other.asOf) && Objects.equals(category, other.category) && Objects.equals(count, other.count) && Objects.equals(countUnit, other.countUnit) && Objects.equals(description, other.description) && Objects.equals(endDate, other.endDate) && Objects.equals(price, other.price) && Objects.equals(priceUnit, other.priceUnit) && Objects.equals(startDate, other.startDate) && Objects.equals(subresourceUris, other.subresourceUris) && Objects.equals(uri, other.uri) && Objects.equals(usage, other.usage) && Objects.equals(usageUnit, other.usageUnit) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(apiVersion, other.apiVersion) && + Objects.equals(asOf, other.asOf) && + Objects.equals(category, other.category) && + Objects.equals(count, other.count) && + Objects.equals(countUnit, other.countUnit) && + Objects.equals(description, other.description) && + Objects.equals(endDate, other.endDate) && + Objects.equals(price, other.price) && + Objects.equals(priceUnit, other.priceUnit) && + Objects.equals(startDate, other.startDate) && + Objects.equals(subresourceUris, other.subresourceUris) && + Objects.equals(uri, other.uri) && + Objects.equals(usage, other.usage) && + Objects.equals(usageUnit, other.usageUnit) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, apiVersion, asOf, category, count, countUnit, description, endDate, price, priceUnit, startDate, subresourceUris, uri, usage, usageUnit); + return Objects.hash( + accountSid, + apiVersion, + asOf, + category, + count, + countUnit, + description, + endDate, + price, + priceUnit, + startDate, + subresourceUris, + uri, + usage, + usageUnit + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/usage/RecordReader.java b/src/main/java/com/twilio/rest/api/v2010/account/usage/RecordReader.java index c39145d71e..b509fdde08 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/usage/RecordReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/usage/RecordReader.java @@ -14,8 +14,10 @@ package com.twilio.rest.api.v2010.account.usage; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,13 +26,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; import java.time.LocalDate; -import com.twilio.converter.DateConverter; - - public class RecordReader extends Reader { + private String pathAccountSid; private Record.Category category; private LocalDate startDate; @@ -38,29 +37,35 @@ public class RecordReader extends Reader { private Boolean includeSubaccounts; private Integer pageSize; - public RecordReader(){ - } - public RecordReader(final String pathAccountSid){ + public RecordReader() {} + + public RecordReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - public RecordReader setCategory(final Record.Category category){ + public RecordReader setCategory(final Record.Category category) { this.category = category; return this; } - public RecordReader setStartDate(final LocalDate startDate){ + + public RecordReader setStartDate(final LocalDate startDate) { this.startDate = startDate; return this; } - public RecordReader setEndDate(final LocalDate endDate){ + + public RecordReader setEndDate(final LocalDate endDate) { this.endDate = endDate; return this; } - public RecordReader setIncludeSubaccounts(final Boolean includeSubaccounts){ + + public RecordReader setIncludeSubaccounts( + final Boolean includeSubaccounts + ) { this.includeSubaccounts = includeSubaccounts; return this; } - public RecordReader setPageSize(final Integer pageSize){ + + public RecordReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -72,8 +77,15 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/2010-04-01/Accounts/{AccountSid}/Usage/Records.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -85,13 +97,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Record read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Record read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -107,7 +127,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.API.toString()) @@ -115,9 +138,11 @@ public Page previousPage(final Page page, final TwilioRestClient return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.API.toString()) @@ -126,37 +151,44 @@ public Page nextPage(final Page page, final TwilioRestClient cli } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (category != null) { - request.addQueryParam("Category", category.toString()); } if (startDate != null) { - request.addQueryParam("StartDate", DateConverter.dateStringFromLocalDate(startDate)); + request.addQueryParam( + "StartDate", + DateConverter.dateStringFromLocalDate(startDate) + ); } if (endDate != null) { - request.addQueryParam("EndDate", DateConverter.dateStringFromLocalDate(endDate)); + request.addQueryParam( + "EndDate", + DateConverter.dateStringFromLocalDate(endDate) + ); } if (includeSubaccounts != null) { - - request.addQueryParam("IncludeSubaccounts", includeSubaccounts.toString()); + request.addQueryParam( + "IncludeSubaccounts", + includeSubaccounts.toString() + ); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/usage/Trigger.java b/src/main/java/com/twilio/rest/api/v2010/account/usage/Trigger.java index 1d2629b1c5..6c4ddd90b8 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/usage/Trigger.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/usage/Trigger.java @@ -24,69 +24,96 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; import com.twilio.http.HttpMethod; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Trigger extends Resource { + private static final long serialVersionUID = 180476898929579L; - public static TriggerCreator creator(final URI callbackUrl, final String triggerValue, final Trigger.UsageCategory usageCategory){ + public static TriggerCreator creator( + final URI callbackUrl, + final String triggerValue, + final Trigger.UsageCategory usageCategory + ) { return new TriggerCreator(callbackUrl, triggerValue, usageCategory); } - public static TriggerCreator creator(final String pathAccountSid, final URI callbackUrl, final String triggerValue, final Trigger.UsageCategory usageCategory){ - return new TriggerCreator(pathAccountSid, callbackUrl, triggerValue, usageCategory); + + public static TriggerCreator creator( + final String pathAccountSid, + final URI callbackUrl, + final String triggerValue, + final Trigger.UsageCategory usageCategory + ) { + return new TriggerCreator( + pathAccountSid, + callbackUrl, + triggerValue, + usageCategory + ); } - public static TriggerDeleter deleter(final String pathSid){ + public static TriggerDeleter deleter(final String pathSid) { return new TriggerDeleter(pathSid); } - public static TriggerDeleter deleter(final String pathAccountSid, final String pathSid){ + + public static TriggerDeleter deleter( + final String pathAccountSid, + final String pathSid + ) { return new TriggerDeleter(pathAccountSid, pathSid); } - public static TriggerFetcher fetcher(final String pathSid){ + public static TriggerFetcher fetcher(final String pathSid) { return new TriggerFetcher(pathSid); } - public static TriggerFetcher fetcher(final String pathAccountSid, final String pathSid){ + + public static TriggerFetcher fetcher( + final String pathAccountSid, + final String pathSid + ) { return new TriggerFetcher(pathAccountSid, pathSid); } - public static TriggerReader reader(){ + public static TriggerReader reader() { return new TriggerReader(); } - public static TriggerReader reader(final String pathAccountSid){ + + public static TriggerReader reader(final String pathAccountSid) { return new TriggerReader(pathAccountSid); } - public static TriggerUpdater updater(final String pathSid){ + public static TriggerUpdater updater(final String pathSid) { return new TriggerUpdater(pathSid); } - public static TriggerUpdater updater(final String pathAccountSid, final String pathSid){ + + public static TriggerUpdater updater( + final String pathAccountSid, + final String pathSid + ) { return new TriggerUpdater(pathAccountSid, pathSid); } /** - * Converts a JSON String into a Trigger object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Trigger object represented by the provided JSON - */ - public static Trigger fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Trigger object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Trigger object represented by the provided JSON + */ + public static Trigger fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Trigger.class); @@ -98,14 +125,17 @@ public static Trigger fromJson(final String json, final ObjectMapper objectMappe } /** - * Converts a JSON InputStream into a Trigger object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Trigger object represented by the provided JSON - */ - public static Trigger fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Trigger object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Trigger object represented by the provided JSON + */ + public static Trigger fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Trigger.class); @@ -115,6 +145,7 @@ public static Trigger fromJson(final InputStream json, final ObjectMapper object throw new ApiConnectionException(e.getMessage(), e); } } + public enum Recurring { DAILY("daily"), MONTHLY("monthly"), @@ -136,6 +167,7 @@ public static Recurring forValue(final String value) { return Promoter.enumFromString(value, Recurring.values()); } } + public enum TriggerField { COUNT("count"), USAGE("usage"), @@ -156,6 +188,7 @@ public static TriggerField forValue(final String value) { return Promoter.enumFromString(value, TriggerField.values()); } } + public enum UsageCategory { A2P_REGISTRATION_FEES("a2p-registration-fees"), AGENT_CONFERENCE("agent-conference"), @@ -187,7 +220,9 @@ public enum UsageCategory { CONVERSATIONS("conversations"), CONVERSATIONS_API_REQUESTS("conversations-api-requests"), CONVERSATIONS_CONVERSATION_EVENTS("conversations-conversation-events"), - CONVERSATIONS_ENDPOINT_CONNECTIVITY("conversations-endpoint-connectivity"), + CONVERSATIONS_ENDPOINT_CONNECTIVITY( + "conversations-endpoint-connectivity" + ), CONVERSATIONS_EVENTS("conversations-events"), CONVERSATIONS_PARTICIPANT_EVENTS("conversations-participant-events"), CONVERSATIONS_PARTICIPANTS("conversations-participants"), @@ -196,7 +231,9 @@ public enum UsageCategory { FRAUD_LOOKUPS("fraud-lookups"), GROUP_ROOMS("group-rooms"), GROUP_ROOMS_DATA_TRACK("group-rooms-data-track"), - GROUP_ROOMS_ENCRYPTED_MEDIA_RECORDED("group-rooms-encrypted-media-recorded"), + GROUP_ROOMS_ENCRYPTED_MEDIA_RECORDED( + "group-rooms-encrypted-media-recorded" + ), GROUP_ROOMS_MEDIA_DOWNLOADED("group-rooms-media-downloaded"), GROUP_ROOMS_MEDIA_RECORDED("group-rooms-media-recorded"), GROUP_ROOMS_MEDIA_ROUTED("group-rooms-media-routed"), @@ -206,45 +243,99 @@ public enum UsageCategory { IMP_V1_USAGE("imp-v1-usage"), LOOKUPS("lookups"), MARKETPLACE("marketplace"), - MARKETPLACE_ALGORITHMIA_NAMED_ENTITY_RECOGNITION("marketplace-algorithmia-named-entity-recognition"), + MARKETPLACE_ALGORITHMIA_NAMED_ENTITY_RECOGNITION( + "marketplace-algorithmia-named-entity-recognition" + ), MARKETPLACE_CADENCE_TRANSCRIPTION("marketplace-cadence-transcription"), MARKETPLACE_CADENCE_TRANSLATION("marketplace-cadence-translation"), MARKETPLACE_CAPIO_SPEECH_TO_TEXT("marketplace-capio-speech-to-text"), MARKETPLACE_CONVRIZA_ABABA("marketplace-convriza-ababa"), - MARKETPLACE_DEEPGRAM_PHRASE_DETECTOR("marketplace-deepgram-phrase-detector"), - MARKETPLACE_DIGITAL_SEGMENT_BUSINESS_INFO("marketplace-digital-segment-business-info"), - MARKETPLACE_FACEBOOK_OFFLINE_CONVERSIONS("marketplace-facebook-offline-conversions"), + MARKETPLACE_DEEPGRAM_PHRASE_DETECTOR( + "marketplace-deepgram-phrase-detector" + ), + MARKETPLACE_DIGITAL_SEGMENT_BUSINESS_INFO( + "marketplace-digital-segment-business-info" + ), + MARKETPLACE_FACEBOOK_OFFLINE_CONVERSIONS( + "marketplace-facebook-offline-conversions" + ), MARKETPLACE_GOOGLE_SPEECH_TO_TEXT("marketplace-google-speech-to-text"), - MARKETPLACE_IBM_WATSON_MESSAGE_INSIGHTS("marketplace-ibm-watson-message-insights"), - MARKETPLACE_IBM_WATSON_MESSAGE_SENTIMENT("marketplace-ibm-watson-message-sentiment"), - MARKETPLACE_IBM_WATSON_RECORDING_ANALYSIS("marketplace-ibm-watson-recording-analysis"), - MARKETPLACE_IBM_WATSON_TONE_ANALYZER("marketplace-ibm-watson-tone-analyzer"), + MARKETPLACE_IBM_WATSON_MESSAGE_INSIGHTS( + "marketplace-ibm-watson-message-insights" + ), + MARKETPLACE_IBM_WATSON_MESSAGE_SENTIMENT( + "marketplace-ibm-watson-message-sentiment" + ), + MARKETPLACE_IBM_WATSON_RECORDING_ANALYSIS( + "marketplace-ibm-watson-recording-analysis" + ), + MARKETPLACE_IBM_WATSON_TONE_ANALYZER( + "marketplace-ibm-watson-tone-analyzer" + ), MARKETPLACE_ICEHOOK_SYSTEMS_SCOUT("marketplace-icehook-systems-scout"), - MARKETPLACE_INFOGROUP_DATAAXLE_BIZINFO("marketplace-infogroup-dataaxle-bizinfo"), - MARKETPLACE_KEEN_IO_CONTACT_CENTER_ANALYTICS("marketplace-keen-io-contact-center-analytics"), + MARKETPLACE_INFOGROUP_DATAAXLE_BIZINFO( + "marketplace-infogroup-dataaxle-bizinfo" + ), + MARKETPLACE_KEEN_IO_CONTACT_CENTER_ANALYTICS( + "marketplace-keen-io-contact-center-analytics" + ), MARKETPLACE_MARCHEX_CLEANCALL("marketplace-marchex-cleancall"), - MARKETPLACE_MARCHEX_SENTIMENT_ANALYSIS_FOR_SMS("marketplace-marchex-sentiment-analysis-for-sms"), - MARKETPLACE_MARKETPLACE_NEXTCALLER_SOCIAL_ID("marketplace-marketplace-nextcaller-social-id"), - MARKETPLACE_MOBILE_COMMONS_OPT_OUT_CLASSIFIER("marketplace-mobile-commons-opt-out-classifier"), - MARKETPLACE_NEXIWAVE_VOICEMAIL_TO_TEXT("marketplace-nexiwave-voicemail-to-text"), - MARKETPLACE_NEXTCALLER_ADVANCED_CALLER_IDENTIFICATION("marketplace-nextcaller-advanced-caller-identification"), + MARKETPLACE_MARCHEX_SENTIMENT_ANALYSIS_FOR_SMS( + "marketplace-marchex-sentiment-analysis-for-sms" + ), + MARKETPLACE_MARKETPLACE_NEXTCALLER_SOCIAL_ID( + "marketplace-marketplace-nextcaller-social-id" + ), + MARKETPLACE_MOBILE_COMMONS_OPT_OUT_CLASSIFIER( + "marketplace-mobile-commons-opt-out-classifier" + ), + MARKETPLACE_NEXIWAVE_VOICEMAIL_TO_TEXT( + "marketplace-nexiwave-voicemail-to-text" + ), + MARKETPLACE_NEXTCALLER_ADVANCED_CALLER_IDENTIFICATION( + "marketplace-nextcaller-advanced-caller-identification" + ), MARKETPLACE_NOMOROBO_SPAM_SCORE("marketplace-nomorobo-spam-score"), - MARKETPLACE_PAYFONE_TCPA_COMPLIANCE("marketplace-payfone-tcpa-compliance"), - MARKETPLACE_REMEETING_AUTOMATIC_SPEECH_RECOGNITION("marketplace-remeeting-automatic-speech-recognition"), - MARKETPLACE_TCPA_DEFENSE_SOLUTIONS_BLACKLIST_FEED("marketplace-tcpa-defense-solutions-blacklist-feed"), + MARKETPLACE_PAYFONE_TCPA_COMPLIANCE( + "marketplace-payfone-tcpa-compliance" + ), + MARKETPLACE_REMEETING_AUTOMATIC_SPEECH_RECOGNITION( + "marketplace-remeeting-automatic-speech-recognition" + ), + MARKETPLACE_TCPA_DEFENSE_SOLUTIONS_BLACKLIST_FEED( + "marketplace-tcpa-defense-solutions-blacklist-feed" + ), MARKETPLACE_TELO_OPENCNAM("marketplace-telo-opencnam"), MARKETPLACE_TRUECNAM_TRUE_SPAM("marketplace-truecnam-true-spam"), - MARKETPLACE_TWILIO_CALLER_NAME_LOOKUP_US("marketplace-twilio-caller-name-lookup-us"), - MARKETPLACE_TWILIO_CARRIER_INFORMATION_LOOKUP("marketplace-twilio-carrier-information-lookup"), + MARKETPLACE_TWILIO_CALLER_NAME_LOOKUP_US( + "marketplace-twilio-caller-name-lookup-us" + ), + MARKETPLACE_TWILIO_CARRIER_INFORMATION_LOOKUP( + "marketplace-twilio-carrier-information-lookup" + ), MARKETPLACE_VOICEBASE_PCI("marketplace-voicebase-pci"), - MARKETPLACE_VOICEBASE_TRANSCRIPTION("marketplace-voicebase-transcription"), - MARKETPLACE_VOICEBASE_TRANSCRIPTION_CUSTOM_VOCABULARY("marketplace-voicebase-transcription-custom-vocabulary"), - MARKETPLACE_WHITEPAGES_PRO_CALLER_IDENTIFICATION("marketplace-whitepages-pro-caller-identification"), - MARKETPLACE_WHITEPAGES_PRO_PHONE_INTELLIGENCE("marketplace-whitepages-pro-phone-intelligence"), - MARKETPLACE_WHITEPAGES_PRO_PHONE_REPUTATION("marketplace-whitepages-pro-phone-reputation"), - MARKETPLACE_WOLFARM_SPOKEN_RESULTS("marketplace-wolfarm-spoken-results"), + MARKETPLACE_VOICEBASE_TRANSCRIPTION( + "marketplace-voicebase-transcription" + ), + MARKETPLACE_VOICEBASE_TRANSCRIPTION_CUSTOM_VOCABULARY( + "marketplace-voicebase-transcription-custom-vocabulary" + ), + MARKETPLACE_WHITEPAGES_PRO_CALLER_IDENTIFICATION( + "marketplace-whitepages-pro-caller-identification" + ), + MARKETPLACE_WHITEPAGES_PRO_PHONE_INTELLIGENCE( + "marketplace-whitepages-pro-phone-intelligence" + ), + MARKETPLACE_WHITEPAGES_PRO_PHONE_REPUTATION( + "marketplace-whitepages-pro-phone-reputation" + ), + MARKETPLACE_WOLFARM_SPOKEN_RESULTS( + "marketplace-wolfarm-spoken-results" + ), MARKETPLACE_WOLFRAM_SHORT_ANSWER("marketplace-wolfram-short-answer"), - MARKETPLACE_YTICA_CONTACT_CENTER_REPORTING_ANALYTICS("marketplace-ytica-contact-center-reporting-analytics"), + MARKETPLACE_YTICA_CONTACT_CENTER_REPORTING_ANALYTICS( + "marketplace-ytica-contact-center-reporting-analytics" + ), MEDIASTORAGE("mediastorage"), MMS("mms"), MMS_INBOUND("mms-inbound"), @@ -263,7 +354,9 @@ public enum UsageCategory { NUMBER_FORMAT_LOOKUPS("number-format-lookups"), PCHAT("pchat"), PCHAT_USERS("pchat-users"), - PEER_TO_PEER_ROOMS_PARTICIPANT_MINUTES("peer-to-peer-rooms-participant-minutes"), + PEER_TO_PEER_ROOMS_PARTICIPANT_MINUTES( + "peer-to-peer-rooms-participant-minutes" + ), PFAX("pfax"), PFAX_MINUTES("pfax-minutes"), PFAX_MINUTES_INBOUND("pfax-minutes-inbound"), @@ -310,7 +403,9 @@ public enum UsageCategory { SHORTCODES_VANITY("shortcodes-vanity"), SMALL_GROUP_ROOMS("small-group-rooms"), SMALL_GROUP_ROOMS_DATA_TRACK("small-group-rooms-data-track"), - SMALL_GROUP_ROOMS_PARTICIPANT_MINUTES("small-group-rooms-participant-minutes"), + SMALL_GROUP_ROOMS_PARTICIPANT_MINUTES( + "small-group-rooms-participant-minutes" + ), SMS("sms"), SMS_INBOUND("sms-inbound"), SMS_INBOUND_LONGCODE("sms-inbound-longcode"), @@ -327,7 +422,9 @@ public enum UsageCategory { SYNC("sync"), SYNC_ACTIONS("sync-actions"), SYNC_ENDPOINT_HOURS("sync-endpoint-hours"), - SYNC_ENDPOINT_HOURS_ABOVE_DAILY_CAP("sync-endpoint-hours-above-daily-cap"), + SYNC_ENDPOINT_HOURS_ABOVE_DAILY_CAP( + "sync-endpoint-hours-above-daily-cap" + ), TASKROUTER_TASKS("taskrouter-tasks"), TOTALPRICE("totalprice"), TRANSCRIPTIONS("transcriptions"), @@ -340,6 +437,7 @@ public enum UsageCategory { TRUNKING_RECORDINGS("trunking-recordings"), TRUNKING_SECURE("trunking-secure"), TRUNKING_TERMINATION("trunking-termination"), + TTS_GOOGLE("tts-google"), TURNMEGABYTES("turnmegabytes"), TURNMEGABYTES_AUSTRALIA("turnmegabytes-australia"), TURNMEGABYTES_BRASIL("turnmegabytes-brasil"), @@ -353,14 +451,27 @@ public enum UsageCategory { TWILIO_INTERCONNECT("twilio-interconnect"), VERIFY_PUSH("verify-push"), VERIFY_TOTP("verify-totp"), - VERIFY_WHATSAPP_CONVERSATIONS_BUSINESS_INITIATED("verify-whatsapp-conversations-business-initiated"), + VERIFY_WHATSAPP_CONVERSATIONS_BUSINESS_INITIATED( + "verify-whatsapp-conversations-business-initiated" + ), VIDEO_RECORDINGS("video-recordings"), VIRTUAL_AGENT("virtual-agent"), VOICE_INSIGHTS("voice-insights"), - VOICE_INSIGHTS_CLIENT_INSIGHTS_ON_DEMAND_MINUTE("voice-insights-client-insights-on-demand-minute"), - VOICE_INSIGHTS_PTSN_INSIGHTS_ON_DEMAND_MINUTE("voice-insights-ptsn-insights-on-demand-minute"), - VOICE_INSIGHTS_SIP_INTERFACE_INSIGHTS_ON_DEMAND_MINUTE("voice-insights-sip-interface-insights-on-demand-minute"), - VOICE_INSIGHTS_SIP_TRUNKING_INSIGHTS_ON_DEMAND_MINUTE("voice-insights-sip-trunking-insights-on-demand-minute"), + VOICE_INSIGHTS_CLIENT_INSIGHTS_ON_DEMAND_MINUTE( + "voice-insights-client-insights-on-demand-minute" + ), + VOICE_INSIGHTS_PTSN_INSIGHTS_ON_DEMAND_MINUTE( + "voice-insights-ptsn-insights-on-demand-minute" + ), + VOICE_INSIGHTS_SIP_INTERFACE_INSIGHTS_ON_DEMAND_MINUTE( + "voice-insights-sip-interface-insights-on-demand-minute" + ), + VOICE_INSIGHTS_SIP_TRUNKING_INSIGHTS_ON_DEMAND_MINUTE( + "voice-insights-sip-trunking-insights-on-demand-minute" + ), + VOICE_INTELLIGENCE("voice-intelligence"), + VOICE_INTELLIGENCE_TRANSCRIPTION("voice-intelligence-transcription"), + VOICE_INTELLIGENCE_OPERATORS("voice-intelligence-operators"), WIRELESS("wireless"), WIRELESS_ORDERS("wireless-orders"), WIRELESS_ORDERS_ARTWORK("wireless-orders-artwork"), @@ -371,29 +482,53 @@ public enum UsageCategory { WIRELESS_USAGE_COMMANDS("wireless-usage-commands"), WIRELESS_USAGE_COMMANDS_AFRICA("wireless-usage-commands-africa"), WIRELESS_USAGE_COMMANDS_ASIA("wireless-usage-commands-asia"), - WIRELESS_USAGE_COMMANDS_CENTRALANDSOUTHAMERICA("wireless-usage-commands-centralandsouthamerica"), + WIRELESS_USAGE_COMMANDS_CENTRALANDSOUTHAMERICA( + "wireless-usage-commands-centralandsouthamerica" + ), WIRELESS_USAGE_COMMANDS_EUROPE("wireless-usage-commands-europe"), WIRELESS_USAGE_COMMANDS_HOME("wireless-usage-commands-home"), - WIRELESS_USAGE_COMMANDS_NORTHAMERICA("wireless-usage-commands-northamerica"), + WIRELESS_USAGE_COMMANDS_NORTHAMERICA( + "wireless-usage-commands-northamerica" + ), WIRELESS_USAGE_COMMANDS_OCEANIA("wireless-usage-commands-oceania"), WIRELESS_USAGE_COMMANDS_ROAMING("wireless-usage-commands-roaming"), WIRELESS_USAGE_DATA("wireless-usage-data"), WIRELESS_USAGE_DATA_AFRICA("wireless-usage-data-africa"), WIRELESS_USAGE_DATA_ASIA("wireless-usage-data-asia"), - WIRELESS_USAGE_DATA_CENTRALANDSOUTHAMERICA("wireless-usage-data-centralandsouthamerica"), - WIRELESS_USAGE_DATA_CUSTOM_ADDITIONALMB("wireless-usage-data-custom-additionalmb"), - WIRELESS_USAGE_DATA_CUSTOM_FIRST5MB("wireless-usage-data-custom-first5mb"), - WIRELESS_USAGE_DATA_DOMESTIC_ROAMING("wireless-usage-data-domestic-roaming"), + WIRELESS_USAGE_DATA_CENTRALANDSOUTHAMERICA( + "wireless-usage-data-centralandsouthamerica" + ), + WIRELESS_USAGE_DATA_CUSTOM_ADDITIONALMB( + "wireless-usage-data-custom-additionalmb" + ), + WIRELESS_USAGE_DATA_CUSTOM_FIRST5MB( + "wireless-usage-data-custom-first5mb" + ), + WIRELESS_USAGE_DATA_DOMESTIC_ROAMING( + "wireless-usage-data-domestic-roaming" + ), WIRELESS_USAGE_DATA_EUROPE("wireless-usage-data-europe"), - WIRELESS_USAGE_DATA_INDIVIDUAL_ADDITIONALGB("wireless-usage-data-individual-additionalgb"), - WIRELESS_USAGE_DATA_INDIVIDUAL_FIRSTGB("wireless-usage-data-individual-firstgb"), - WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_CANADA("wireless-usage-data-international-roaming-canada"), - WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_INDIA("wireless-usage-data-international-roaming-india"), - WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_MEXICO("wireless-usage-data-international-roaming-mexico"), + WIRELESS_USAGE_DATA_INDIVIDUAL_ADDITIONALGB( + "wireless-usage-data-individual-additionalgb" + ), + WIRELESS_USAGE_DATA_INDIVIDUAL_FIRSTGB( + "wireless-usage-data-individual-firstgb" + ), + WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_CANADA( + "wireless-usage-data-international-roaming-canada" + ), + WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_INDIA( + "wireless-usage-data-international-roaming-india" + ), + WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_MEXICO( + "wireless-usage-data-international-roaming-mexico" + ), WIRELESS_USAGE_DATA_NORTHAMERICA("wireless-usage-data-northamerica"), WIRELESS_USAGE_DATA_OCEANIA("wireless-usage-data-oceania"), WIRELESS_USAGE_DATA_POOLED("wireless-usage-data-pooled"), - WIRELESS_USAGE_DATA_POOLED_DOWNLINK("wireless-usage-data-pooled-downlink"), + WIRELESS_USAGE_DATA_POOLED_DOWNLINK( + "wireless-usage-data-pooled-downlink" + ), WIRELESS_USAGE_DATA_POOLED_UPLINK("wireless-usage-data-pooled-uplink"), WIRELESS_USAGE_MRC("wireless-usage-mrc"), WIRELESS_USAGE_MRC_CUSTOM("wireless-usage-mrc-custom"), @@ -438,53 +573,24 @@ public static UsageCategory forValue(final String value) { @JsonCreator private Trigger( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("api_version") - final String apiVersion, - - @JsonProperty("callback_method") - final HttpMethod callbackMethod, - - @JsonProperty("callback_url") - final URI callbackUrl, - - @JsonProperty("current_value") - final String currentValue, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_fired") - final String dateFired, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("recurring") - final Trigger.Recurring recurring, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("trigger_by") - final Trigger.TriggerField triggerBy, - - @JsonProperty("trigger_value") - final String triggerValue, - - @JsonProperty("uri") - final String uri, - - @JsonProperty("usage_category") - final Trigger.UsageCategory usageCategory, - - @JsonProperty("usage_record_uri") - final String usageRecordUri + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("api_version") final String apiVersion, + @JsonProperty("callback_method") final HttpMethod callbackMethod, + @JsonProperty("callback_url") final URI callbackUrl, + @JsonProperty("current_value") final String currentValue, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_fired") final String dateFired, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("recurring") final Trigger.Recurring recurring, + @JsonProperty("sid") final String sid, + @JsonProperty("trigger_by") final Trigger.TriggerField triggerBy, + @JsonProperty("trigger_value") final String triggerValue, + @JsonProperty("uri") final String uri, + @JsonProperty( + "usage_category" + ) final Trigger.UsageCategory usageCategory, + @JsonProperty("usage_record_uri") final String usageRecordUri ) { this.accountSid = accountSid; this.apiVersion = apiVersion; @@ -504,58 +610,73 @@ private Trigger( this.usageRecordUri = usageRecordUri; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getApiVersion() { - return this.apiVersion; - } - public final HttpMethod getCallbackMethod() { - return this.callbackMethod; - } - public final URI getCallbackUrl() { - return this.callbackUrl; - } - public final String getCurrentValue() { - return this.currentValue; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateFired() { - return this.dateFired; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final Trigger.Recurring getRecurring() { - return this.recurring; - } - public final String getSid() { - return this.sid; - } - public final Trigger.TriggerField getTriggerBy() { - return this.triggerBy; - } - public final String getTriggerValue() { - return this.triggerValue; - } - public final String getUri() { - return this.uri; - } - public final Trigger.UsageCategory getUsageCategory() { - return this.usageCategory; - } - public final String getUsageRecordUri() { - return this.usageRecordUri; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getApiVersion() { + return this.apiVersion; + } + + public final HttpMethod getCallbackMethod() { + return this.callbackMethod; + } + + public final URI getCallbackUrl() { + return this.callbackUrl; + } + + public final String getCurrentValue() { + return this.currentValue; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateFired() { + return this.dateFired; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final Trigger.Recurring getRecurring() { + return this.recurring; + } + + public final String getSid() { + return this.sid; + } + + public final Trigger.TriggerField getTriggerBy() { + return this.triggerBy; + } + + public final String getTriggerValue() { + return this.triggerValue; + } + + public final String getUri() { + return this.uri; + } + + public final Trigger.UsageCategory getUsageCategory() { + return this.usageCategory; + } + + public final String getUsageRecordUri() { + return this.usageRecordUri; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -565,13 +686,45 @@ public boolean equals(final Object o) { Trigger other = (Trigger) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(apiVersion, other.apiVersion) && Objects.equals(callbackMethod, other.callbackMethod) && Objects.equals(callbackUrl, other.callbackUrl) && Objects.equals(currentValue, other.currentValue) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateFired, other.dateFired) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(recurring, other.recurring) && Objects.equals(sid, other.sid) && Objects.equals(triggerBy, other.triggerBy) && Objects.equals(triggerValue, other.triggerValue) && Objects.equals(uri, other.uri) && Objects.equals(usageCategory, other.usageCategory) && Objects.equals(usageRecordUri, other.usageRecordUri) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(apiVersion, other.apiVersion) && + Objects.equals(callbackMethod, other.callbackMethod) && + Objects.equals(callbackUrl, other.callbackUrl) && + Objects.equals(currentValue, other.currentValue) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateFired, other.dateFired) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(recurring, other.recurring) && + Objects.equals(sid, other.sid) && + Objects.equals(triggerBy, other.triggerBy) && + Objects.equals(triggerValue, other.triggerValue) && + Objects.equals(uri, other.uri) && + Objects.equals(usageCategory, other.usageCategory) && + Objects.equals(usageRecordUri, other.usageRecordUri) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, apiVersion, callbackMethod, callbackUrl, currentValue, dateCreated, dateFired, dateUpdated, friendlyName, recurring, sid, triggerBy, triggerValue, uri, usageCategory, usageRecordUri); + return Objects.hash( + accountSid, + apiVersion, + callbackMethod, + callbackUrl, + currentValue, + dateCreated, + dateFired, + dateUpdated, + friendlyName, + recurring, + sid, + triggerBy, + triggerValue, + uri, + usageCategory, + usageRecordUri + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/usage/TriggerCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/usage/TriggerCreator.java index ac421447fa..1bc919140a 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/usage/TriggerCreator.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/usage/TriggerCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010.account.usage; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -25,12 +26,10 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.net.URI; - - - import java.net.URI; -public class TriggerCreator extends Creator{ +public class TriggerCreator extends Creator { + private URI callbackUrl; private String triggerValue; private Trigger.UsageCategory usageCategory; @@ -40,72 +39,115 @@ public class TriggerCreator extends Creator{ private Trigger.Recurring recurring; private Trigger.TriggerField triggerBy; - public TriggerCreator(final URI callbackUrl, final String triggerValue, final Trigger.UsageCategory usageCategory) { + public TriggerCreator( + final URI callbackUrl, + final String triggerValue, + final Trigger.UsageCategory usageCategory + ) { this.callbackUrl = callbackUrl; this.triggerValue = triggerValue; this.usageCategory = usageCategory; } - public TriggerCreator(final String pathAccountSid, final URI callbackUrl, final String triggerValue, final Trigger.UsageCategory usageCategory) { + + public TriggerCreator( + final String pathAccountSid, + final URI callbackUrl, + final String triggerValue, + final Trigger.UsageCategory usageCategory + ) { this.pathAccountSid = pathAccountSid; this.callbackUrl = callbackUrl; this.triggerValue = triggerValue; this.usageCategory = usageCategory; } - public TriggerCreator setCallbackUrl(final URI callbackUrl){ + public TriggerCreator setCallbackUrl(final URI callbackUrl) { this.callbackUrl = callbackUrl; return this; } - public TriggerCreator setCallbackUrl(final String callbackUrl){ + public TriggerCreator setCallbackUrl(final String callbackUrl) { return setCallbackUrl(Promoter.uriFromString(callbackUrl)); } - public TriggerCreator setTriggerValue(final String triggerValue){ + + public TriggerCreator setTriggerValue(final String triggerValue) { this.triggerValue = triggerValue; return this; } - public TriggerCreator setUsageCategory(final Trigger.UsageCategory usageCategory){ + + public TriggerCreator setUsageCategory( + final Trigger.UsageCategory usageCategory + ) { this.usageCategory = usageCategory; return this; } - public TriggerCreator setCallbackMethod(final HttpMethod callbackMethod){ + + public TriggerCreator setCallbackMethod(final HttpMethod callbackMethod) { this.callbackMethod = callbackMethod; return this; } - public TriggerCreator setFriendlyName(final String friendlyName){ + + public TriggerCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public TriggerCreator setRecurring(final Trigger.Recurring recurring){ + + public TriggerCreator setRecurring(final Trigger.Recurring recurring) { this.recurring = recurring; return this; } - public TriggerCreator setTriggerBy(final Trigger.TriggerField triggerBy){ + + public TriggerCreator setTriggerBy(final Trigger.TriggerField triggerBy) { this.triggerBy = triggerBy; return this; } @Override - public Trigger create(final TwilioRestClient client){ + public Trigger create(final TwilioRestClient client) { String path = "/2010-04-01/Accounts/{AccountSid}/Usage/Triggers.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"CallbackUrl"+"}", this.callbackUrl.toString()); - path = path.replace("{"+"TriggerValue"+"}", this.triggerValue.toString()); - path = path.replace("{"+"UsageCategory"+"}", this.usageCategory.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "CallbackUrl" + "}", + this.callbackUrl.toString() + ); + path = + path.replace( + "{" + "TriggerValue" + "}", + this.triggerValue.toString() + ); + path = + path.replace( + "{" + "UsageCategory" + "}", + this.usageCategory.toString() + ); Request request = new Request( HttpMethod.POST, Domains.API.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Trigger creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Trigger creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -114,34 +156,28 @@ public Trigger create(final TwilioRestClient client){ return Trigger.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (callbackUrl != null) { request.addPostParam("CallbackUrl", callbackUrl.toString()); - } if (triggerValue != null) { request.addPostParam("TriggerValue", triggerValue); - } if (usageCategory != null) { request.addPostParam("UsageCategory", usageCategory.toString()); - } if (callbackMethod != null) { request.addPostParam("CallbackMethod", callbackMethod.toString()); - } if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (recurring != null) { request.addPostParam("Recurring", recurring.toString()); - } if (triggerBy != null) { request.addPostParam("TriggerBy", triggerBy.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/usage/TriggerDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/usage/TriggerDeleter.java index 93afbd0bd5..b2508e5b2f 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/usage/TriggerDeleter.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/usage/TriggerDeleter.java @@ -24,28 +24,35 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class TriggerDeleter extends Deleter { + private String pathSid; private String pathAccountSid; - public TriggerDeleter(final String pathSid){ + public TriggerDeleter(final String pathSid) { this.pathSid = pathSid; } - public TriggerDeleter(final String pathAccountSid, final String pathSid){ + + public TriggerDeleter(final String pathAccountSid, final String pathSid) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/Usage/Triggers/{Sid}.json"; + String path = + "/2010-04-01/Accounts/{AccountSid}/Usage/Triggers/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -55,9 +62,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Trigger delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Trigger delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/usage/TriggerFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/usage/TriggerFetcher.java index 7e81300838..090d09cde4 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/usage/TriggerFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/usage/TriggerFetcher.java @@ -24,29 +24,35 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class TriggerFetcher extends Fetcher { + private String pathSid; private String pathAccountSid; - public TriggerFetcher(final String pathSid){ + public TriggerFetcher(final String pathSid) { this.pathSid = pathSid; } - public TriggerFetcher(final String pathAccountSid, final String pathSid){ + + public TriggerFetcher(final String pathAccountSid, final String pathSid) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - @Override public Trigger fetch(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/Usage/Triggers/{Sid}.json"; + String path = + "/2010-04-01/Accounts/{AccountSid}/Usage/Triggers/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -56,9 +62,14 @@ public Trigger fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Trigger fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Trigger fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/usage/TriggerReader.java b/src/main/java/com/twilio/rest/api/v2010/account/usage/TriggerReader.java index 1451c2d621..c0f3fad1bb 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/usage/TriggerReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/usage/TriggerReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.api.v2010.account.usage; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,36 +25,39 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class TriggerReader extends Reader { + private String pathAccountSid; private Trigger.Recurring recurring; private Trigger.TriggerField triggerBy; private Trigger.UsageCategory usageCategory; private Integer pageSize; - public TriggerReader(){ - } - public TriggerReader(final String pathAccountSid){ + public TriggerReader() {} + + public TriggerReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - public TriggerReader setRecurring(final Trigger.Recurring recurring){ + public TriggerReader setRecurring(final Trigger.Recurring recurring) { this.recurring = recurring; return this; } - public TriggerReader setTriggerBy(final Trigger.TriggerField triggerBy){ + + public TriggerReader setTriggerBy(final Trigger.TriggerField triggerBy) { this.triggerBy = triggerBy; return this; } - public TriggerReader setUsageCategory(final Trigger.UsageCategory usageCategory){ + + public TriggerReader setUsageCategory( + final Trigger.UsageCategory usageCategory + ) { this.usageCategory = usageCategory; return this; } - public TriggerReader setPageSize(final Integer pageSize){ + + public TriggerReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -65,8 +69,15 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/2010-04-01/Accounts/{AccountSid}/Usage/Triggers.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -78,13 +89,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Trigger read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Trigger read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -100,7 +119,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reques } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.API.toString()) @@ -108,9 +130,11 @@ public Page previousPage(final Page page, final TwilioRestClie return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.API.toString()) @@ -119,33 +143,30 @@ public Page nextPage(final Page page, final TwilioRestClient c } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (recurring != null) { - request.addQueryParam("Recurring", recurring.toString()); } if (triggerBy != null) { - request.addQueryParam("TriggerBy", triggerBy.toString()); } if (usageCategory != null) { - request.addQueryParam("UsageCategory", usageCategory.toString()); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/usage/TriggerUpdater.java b/src/main/java/com/twilio/rest/api/v2010/account/usage/TriggerUpdater.java index 547159128c..018e9445bf 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/usage/TriggerUpdater.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/usage/TriggerUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010.account.usage; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -24,62 +25,77 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.net.URI; +public class TriggerUpdater extends Updater { - -public class TriggerUpdater extends Updater{ private String pathSid; private String pathAccountSid; private HttpMethod callbackMethod; private URI callbackUrl; private String friendlyName; - public TriggerUpdater(final String pathSid){ + public TriggerUpdater(final String pathSid) { this.pathSid = pathSid; } - public TriggerUpdater(final String pathAccountSid, final String pathSid){ + + public TriggerUpdater(final String pathAccountSid, final String pathSid) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - public TriggerUpdater setCallbackMethod(final HttpMethod callbackMethod){ + public TriggerUpdater setCallbackMethod(final HttpMethod callbackMethod) { this.callbackMethod = callbackMethod; return this; } - public TriggerUpdater setCallbackUrl(final URI callbackUrl){ + + public TriggerUpdater setCallbackUrl(final URI callbackUrl) { this.callbackUrl = callbackUrl; return this; } - public TriggerUpdater setCallbackUrl(final String callbackUrl){ + public TriggerUpdater setCallbackUrl(final String callbackUrl) { return setCallbackUrl(Promoter.uriFromString(callbackUrl)); } - public TriggerUpdater setFriendlyName(final String friendlyName){ + + public TriggerUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } @Override - public Trigger update(final TwilioRestClient client){ - String path = "/2010-04-01/Accounts/{AccountSid}/Usage/Triggers/{Sid}.json"; + public Trigger update(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Usage/Triggers/{Sid}.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.API.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Trigger update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Trigger update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -88,18 +104,16 @@ public Trigger update(final TwilioRestClient client){ return Trigger.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (callbackMethod != null) { request.addPostParam("CallbackMethod", callbackMethod.toString()); - } if (callbackUrl != null) { request.addPostParam("CallbackUrl", callbackUrl.toString()); - } if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/AllTime.java b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/AllTime.java index 9fe8ffbf1b..a92e5f617b 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/AllTime.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/AllTime.java @@ -20,49 +20,49 @@ import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.twilio.base.Resource; -import java.util.Currency; +import com.twilio.converter.CurrencyDeserializer; import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; -import com.twilio.converter.CurrencyDeserializer; import com.twilio.exception.ApiConnectionException; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; - +import java.math.BigDecimal; +import java.time.LocalDate; +import java.util.Currency; import java.util.Map; -import java.util.Objects; - - import java.util.Map; -import java.time.LocalDate; -import java.math.BigDecimal; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class AllTime extends Resource { + private static final long serialVersionUID = 119534363835835L; - public static AllTimeReader reader(){ + public static AllTimeReader reader() { return new AllTimeReader(); } - public static AllTimeReader reader(final String pathAccountSid){ + + public static AllTimeReader reader(final String pathAccountSid) { return new AllTimeReader(pathAccountSid); } /** - * Converts a JSON String into a AllTime object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return AllTime object represented by the provided JSON - */ - public static AllTime fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a AllTime object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return AllTime object represented by the provided JSON + */ + public static AllTime fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, AllTime.class); @@ -74,14 +74,17 @@ public static AllTime fromJson(final String json, final ObjectMapper objectMappe } /** - * Converts a JSON InputStream into a AllTime object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return AllTime object represented by the provided JSON - */ - public static AllTime fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a AllTime object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return AllTime object represented by the provided JSON + */ + public static AllTime fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, AllTime.class); @@ -91,6 +94,7 @@ public static AllTime fromJson(final InputStream json, final ObjectMapper object throw new ApiConnectionException(e.getMessage(), e); } } + public enum Category { A2P_REGISTRATION_FEES("a2p-registration-fees"), AGENT_CONFERENCE("agent-conference"), @@ -122,7 +126,9 @@ public enum Category { CONVERSATIONS("conversations"), CONVERSATIONS_API_REQUESTS("conversations-api-requests"), CONVERSATIONS_CONVERSATION_EVENTS("conversations-conversation-events"), - CONVERSATIONS_ENDPOINT_CONNECTIVITY("conversations-endpoint-connectivity"), + CONVERSATIONS_ENDPOINT_CONNECTIVITY( + "conversations-endpoint-connectivity" + ), CONVERSATIONS_EVENTS("conversations-events"), CONVERSATIONS_PARTICIPANT_EVENTS("conversations-participant-events"), CONVERSATIONS_PARTICIPANTS("conversations-participants"), @@ -131,7 +137,9 @@ public enum Category { FRAUD_LOOKUPS("fraud-lookups"), GROUP_ROOMS("group-rooms"), GROUP_ROOMS_DATA_TRACK("group-rooms-data-track"), - GROUP_ROOMS_ENCRYPTED_MEDIA_RECORDED("group-rooms-encrypted-media-recorded"), + GROUP_ROOMS_ENCRYPTED_MEDIA_RECORDED( + "group-rooms-encrypted-media-recorded" + ), GROUP_ROOMS_MEDIA_DOWNLOADED("group-rooms-media-downloaded"), GROUP_ROOMS_MEDIA_RECORDED("group-rooms-media-recorded"), GROUP_ROOMS_MEDIA_ROUTED("group-rooms-media-routed"), @@ -141,45 +149,99 @@ public enum Category { IMP_V1_USAGE("imp-v1-usage"), LOOKUPS("lookups"), MARKETPLACE("marketplace"), - MARKETPLACE_ALGORITHMIA_NAMED_ENTITY_RECOGNITION("marketplace-algorithmia-named-entity-recognition"), + MARKETPLACE_ALGORITHMIA_NAMED_ENTITY_RECOGNITION( + "marketplace-algorithmia-named-entity-recognition" + ), MARKETPLACE_CADENCE_TRANSCRIPTION("marketplace-cadence-transcription"), MARKETPLACE_CADENCE_TRANSLATION("marketplace-cadence-translation"), MARKETPLACE_CAPIO_SPEECH_TO_TEXT("marketplace-capio-speech-to-text"), MARKETPLACE_CONVRIZA_ABABA("marketplace-convriza-ababa"), - MARKETPLACE_DEEPGRAM_PHRASE_DETECTOR("marketplace-deepgram-phrase-detector"), - MARKETPLACE_DIGITAL_SEGMENT_BUSINESS_INFO("marketplace-digital-segment-business-info"), - MARKETPLACE_FACEBOOK_OFFLINE_CONVERSIONS("marketplace-facebook-offline-conversions"), + MARKETPLACE_DEEPGRAM_PHRASE_DETECTOR( + "marketplace-deepgram-phrase-detector" + ), + MARKETPLACE_DIGITAL_SEGMENT_BUSINESS_INFO( + "marketplace-digital-segment-business-info" + ), + MARKETPLACE_FACEBOOK_OFFLINE_CONVERSIONS( + "marketplace-facebook-offline-conversions" + ), MARKETPLACE_GOOGLE_SPEECH_TO_TEXT("marketplace-google-speech-to-text"), - MARKETPLACE_IBM_WATSON_MESSAGE_INSIGHTS("marketplace-ibm-watson-message-insights"), - MARKETPLACE_IBM_WATSON_MESSAGE_SENTIMENT("marketplace-ibm-watson-message-sentiment"), - MARKETPLACE_IBM_WATSON_RECORDING_ANALYSIS("marketplace-ibm-watson-recording-analysis"), - MARKETPLACE_IBM_WATSON_TONE_ANALYZER("marketplace-ibm-watson-tone-analyzer"), + MARKETPLACE_IBM_WATSON_MESSAGE_INSIGHTS( + "marketplace-ibm-watson-message-insights" + ), + MARKETPLACE_IBM_WATSON_MESSAGE_SENTIMENT( + "marketplace-ibm-watson-message-sentiment" + ), + MARKETPLACE_IBM_WATSON_RECORDING_ANALYSIS( + "marketplace-ibm-watson-recording-analysis" + ), + MARKETPLACE_IBM_WATSON_TONE_ANALYZER( + "marketplace-ibm-watson-tone-analyzer" + ), MARKETPLACE_ICEHOOK_SYSTEMS_SCOUT("marketplace-icehook-systems-scout"), - MARKETPLACE_INFOGROUP_DATAAXLE_BIZINFO("marketplace-infogroup-dataaxle-bizinfo"), - MARKETPLACE_KEEN_IO_CONTACT_CENTER_ANALYTICS("marketplace-keen-io-contact-center-analytics"), + MARKETPLACE_INFOGROUP_DATAAXLE_BIZINFO( + "marketplace-infogroup-dataaxle-bizinfo" + ), + MARKETPLACE_KEEN_IO_CONTACT_CENTER_ANALYTICS( + "marketplace-keen-io-contact-center-analytics" + ), MARKETPLACE_MARCHEX_CLEANCALL("marketplace-marchex-cleancall"), - MARKETPLACE_MARCHEX_SENTIMENT_ANALYSIS_FOR_SMS("marketplace-marchex-sentiment-analysis-for-sms"), - MARKETPLACE_MARKETPLACE_NEXTCALLER_SOCIAL_ID("marketplace-marketplace-nextcaller-social-id"), - MARKETPLACE_MOBILE_COMMONS_OPT_OUT_CLASSIFIER("marketplace-mobile-commons-opt-out-classifier"), - MARKETPLACE_NEXIWAVE_VOICEMAIL_TO_TEXT("marketplace-nexiwave-voicemail-to-text"), - MARKETPLACE_NEXTCALLER_ADVANCED_CALLER_IDENTIFICATION("marketplace-nextcaller-advanced-caller-identification"), + MARKETPLACE_MARCHEX_SENTIMENT_ANALYSIS_FOR_SMS( + "marketplace-marchex-sentiment-analysis-for-sms" + ), + MARKETPLACE_MARKETPLACE_NEXTCALLER_SOCIAL_ID( + "marketplace-marketplace-nextcaller-social-id" + ), + MARKETPLACE_MOBILE_COMMONS_OPT_OUT_CLASSIFIER( + "marketplace-mobile-commons-opt-out-classifier" + ), + MARKETPLACE_NEXIWAVE_VOICEMAIL_TO_TEXT( + "marketplace-nexiwave-voicemail-to-text" + ), + MARKETPLACE_NEXTCALLER_ADVANCED_CALLER_IDENTIFICATION( + "marketplace-nextcaller-advanced-caller-identification" + ), MARKETPLACE_NOMOROBO_SPAM_SCORE("marketplace-nomorobo-spam-score"), - MARKETPLACE_PAYFONE_TCPA_COMPLIANCE("marketplace-payfone-tcpa-compliance"), - MARKETPLACE_REMEETING_AUTOMATIC_SPEECH_RECOGNITION("marketplace-remeeting-automatic-speech-recognition"), - MARKETPLACE_TCPA_DEFENSE_SOLUTIONS_BLACKLIST_FEED("marketplace-tcpa-defense-solutions-blacklist-feed"), + MARKETPLACE_PAYFONE_TCPA_COMPLIANCE( + "marketplace-payfone-tcpa-compliance" + ), + MARKETPLACE_REMEETING_AUTOMATIC_SPEECH_RECOGNITION( + "marketplace-remeeting-automatic-speech-recognition" + ), + MARKETPLACE_TCPA_DEFENSE_SOLUTIONS_BLACKLIST_FEED( + "marketplace-tcpa-defense-solutions-blacklist-feed" + ), MARKETPLACE_TELO_OPENCNAM("marketplace-telo-opencnam"), MARKETPLACE_TRUECNAM_TRUE_SPAM("marketplace-truecnam-true-spam"), - MARKETPLACE_TWILIO_CALLER_NAME_LOOKUP_US("marketplace-twilio-caller-name-lookup-us"), - MARKETPLACE_TWILIO_CARRIER_INFORMATION_LOOKUP("marketplace-twilio-carrier-information-lookup"), + MARKETPLACE_TWILIO_CALLER_NAME_LOOKUP_US( + "marketplace-twilio-caller-name-lookup-us" + ), + MARKETPLACE_TWILIO_CARRIER_INFORMATION_LOOKUP( + "marketplace-twilio-carrier-information-lookup" + ), MARKETPLACE_VOICEBASE_PCI("marketplace-voicebase-pci"), - MARKETPLACE_VOICEBASE_TRANSCRIPTION("marketplace-voicebase-transcription"), - MARKETPLACE_VOICEBASE_TRANSCRIPTION_CUSTOM_VOCABULARY("marketplace-voicebase-transcription-custom-vocabulary"), - MARKETPLACE_WHITEPAGES_PRO_CALLER_IDENTIFICATION("marketplace-whitepages-pro-caller-identification"), - MARKETPLACE_WHITEPAGES_PRO_PHONE_INTELLIGENCE("marketplace-whitepages-pro-phone-intelligence"), - MARKETPLACE_WHITEPAGES_PRO_PHONE_REPUTATION("marketplace-whitepages-pro-phone-reputation"), - MARKETPLACE_WOLFARM_SPOKEN_RESULTS("marketplace-wolfarm-spoken-results"), + MARKETPLACE_VOICEBASE_TRANSCRIPTION( + "marketplace-voicebase-transcription" + ), + MARKETPLACE_VOICEBASE_TRANSCRIPTION_CUSTOM_VOCABULARY( + "marketplace-voicebase-transcription-custom-vocabulary" + ), + MARKETPLACE_WHITEPAGES_PRO_CALLER_IDENTIFICATION( + "marketplace-whitepages-pro-caller-identification" + ), + MARKETPLACE_WHITEPAGES_PRO_PHONE_INTELLIGENCE( + "marketplace-whitepages-pro-phone-intelligence" + ), + MARKETPLACE_WHITEPAGES_PRO_PHONE_REPUTATION( + "marketplace-whitepages-pro-phone-reputation" + ), + MARKETPLACE_WOLFARM_SPOKEN_RESULTS( + "marketplace-wolfarm-spoken-results" + ), MARKETPLACE_WOLFRAM_SHORT_ANSWER("marketplace-wolfram-short-answer"), - MARKETPLACE_YTICA_CONTACT_CENTER_REPORTING_ANALYTICS("marketplace-ytica-contact-center-reporting-analytics"), + MARKETPLACE_YTICA_CONTACT_CENTER_REPORTING_ANALYTICS( + "marketplace-ytica-contact-center-reporting-analytics" + ), MEDIASTORAGE("mediastorage"), MMS("mms"), MMS_INBOUND("mms-inbound"), @@ -198,7 +260,9 @@ public enum Category { NUMBER_FORMAT_LOOKUPS("number-format-lookups"), PCHAT("pchat"), PCHAT_USERS("pchat-users"), - PEER_TO_PEER_ROOMS_PARTICIPANT_MINUTES("peer-to-peer-rooms-participant-minutes"), + PEER_TO_PEER_ROOMS_PARTICIPANT_MINUTES( + "peer-to-peer-rooms-participant-minutes" + ), PFAX("pfax"), PFAX_MINUTES("pfax-minutes"), PFAX_MINUTES_INBOUND("pfax-minutes-inbound"), @@ -245,7 +309,9 @@ public enum Category { SHORTCODES_VANITY("shortcodes-vanity"), SMALL_GROUP_ROOMS("small-group-rooms"), SMALL_GROUP_ROOMS_DATA_TRACK("small-group-rooms-data-track"), - SMALL_GROUP_ROOMS_PARTICIPANT_MINUTES("small-group-rooms-participant-minutes"), + SMALL_GROUP_ROOMS_PARTICIPANT_MINUTES( + "small-group-rooms-participant-minutes" + ), SMS("sms"), SMS_INBOUND("sms-inbound"), SMS_INBOUND_LONGCODE("sms-inbound-longcode"), @@ -262,7 +328,9 @@ public enum Category { SYNC("sync"), SYNC_ACTIONS("sync-actions"), SYNC_ENDPOINT_HOURS("sync-endpoint-hours"), - SYNC_ENDPOINT_HOURS_ABOVE_DAILY_CAP("sync-endpoint-hours-above-daily-cap"), + SYNC_ENDPOINT_HOURS_ABOVE_DAILY_CAP( + "sync-endpoint-hours-above-daily-cap" + ), TASKROUTER_TASKS("taskrouter-tasks"), TOTALPRICE("totalprice"), TRANSCRIPTIONS("transcriptions"), @@ -275,6 +343,7 @@ public enum Category { TRUNKING_RECORDINGS("trunking-recordings"), TRUNKING_SECURE("trunking-secure"), TRUNKING_TERMINATION("trunking-termination"), + TTS_GOOGLE("tts-google"), TURNMEGABYTES("turnmegabytes"), TURNMEGABYTES_AUSTRALIA("turnmegabytes-australia"), TURNMEGABYTES_BRASIL("turnmegabytes-brasil"), @@ -288,14 +357,27 @@ public enum Category { TWILIO_INTERCONNECT("twilio-interconnect"), VERIFY_PUSH("verify-push"), VERIFY_TOTP("verify-totp"), - VERIFY_WHATSAPP_CONVERSATIONS_BUSINESS_INITIATED("verify-whatsapp-conversations-business-initiated"), + VERIFY_WHATSAPP_CONVERSATIONS_BUSINESS_INITIATED( + "verify-whatsapp-conversations-business-initiated" + ), VIDEO_RECORDINGS("video-recordings"), VIRTUAL_AGENT("virtual-agent"), VOICE_INSIGHTS("voice-insights"), - VOICE_INSIGHTS_CLIENT_INSIGHTS_ON_DEMAND_MINUTE("voice-insights-client-insights-on-demand-minute"), - VOICE_INSIGHTS_PTSN_INSIGHTS_ON_DEMAND_MINUTE("voice-insights-ptsn-insights-on-demand-minute"), - VOICE_INSIGHTS_SIP_INTERFACE_INSIGHTS_ON_DEMAND_MINUTE("voice-insights-sip-interface-insights-on-demand-minute"), - VOICE_INSIGHTS_SIP_TRUNKING_INSIGHTS_ON_DEMAND_MINUTE("voice-insights-sip-trunking-insights-on-demand-minute"), + VOICE_INSIGHTS_CLIENT_INSIGHTS_ON_DEMAND_MINUTE( + "voice-insights-client-insights-on-demand-minute" + ), + VOICE_INSIGHTS_PTSN_INSIGHTS_ON_DEMAND_MINUTE( + "voice-insights-ptsn-insights-on-demand-minute" + ), + VOICE_INSIGHTS_SIP_INTERFACE_INSIGHTS_ON_DEMAND_MINUTE( + "voice-insights-sip-interface-insights-on-demand-minute" + ), + VOICE_INSIGHTS_SIP_TRUNKING_INSIGHTS_ON_DEMAND_MINUTE( + "voice-insights-sip-trunking-insights-on-demand-minute" + ), + VOICE_INTELLIGENCE("voice-intelligence"), + VOICE_INTELLIGENCE_TRANSCRIPTION("voice-intelligence-transcription"), + VOICE_INTELLIGENCE_OPERATORS("voice-intelligence-operators"), WIRELESS("wireless"), WIRELESS_ORDERS("wireless-orders"), WIRELESS_ORDERS_ARTWORK("wireless-orders-artwork"), @@ -306,29 +388,53 @@ public enum Category { WIRELESS_USAGE_COMMANDS("wireless-usage-commands"), WIRELESS_USAGE_COMMANDS_AFRICA("wireless-usage-commands-africa"), WIRELESS_USAGE_COMMANDS_ASIA("wireless-usage-commands-asia"), - WIRELESS_USAGE_COMMANDS_CENTRALANDSOUTHAMERICA("wireless-usage-commands-centralandsouthamerica"), + WIRELESS_USAGE_COMMANDS_CENTRALANDSOUTHAMERICA( + "wireless-usage-commands-centralandsouthamerica" + ), WIRELESS_USAGE_COMMANDS_EUROPE("wireless-usage-commands-europe"), WIRELESS_USAGE_COMMANDS_HOME("wireless-usage-commands-home"), - WIRELESS_USAGE_COMMANDS_NORTHAMERICA("wireless-usage-commands-northamerica"), + WIRELESS_USAGE_COMMANDS_NORTHAMERICA( + "wireless-usage-commands-northamerica" + ), WIRELESS_USAGE_COMMANDS_OCEANIA("wireless-usage-commands-oceania"), WIRELESS_USAGE_COMMANDS_ROAMING("wireless-usage-commands-roaming"), WIRELESS_USAGE_DATA("wireless-usage-data"), WIRELESS_USAGE_DATA_AFRICA("wireless-usage-data-africa"), WIRELESS_USAGE_DATA_ASIA("wireless-usage-data-asia"), - WIRELESS_USAGE_DATA_CENTRALANDSOUTHAMERICA("wireless-usage-data-centralandsouthamerica"), - WIRELESS_USAGE_DATA_CUSTOM_ADDITIONALMB("wireless-usage-data-custom-additionalmb"), - WIRELESS_USAGE_DATA_CUSTOM_FIRST5MB("wireless-usage-data-custom-first5mb"), - WIRELESS_USAGE_DATA_DOMESTIC_ROAMING("wireless-usage-data-domestic-roaming"), + WIRELESS_USAGE_DATA_CENTRALANDSOUTHAMERICA( + "wireless-usage-data-centralandsouthamerica" + ), + WIRELESS_USAGE_DATA_CUSTOM_ADDITIONALMB( + "wireless-usage-data-custom-additionalmb" + ), + WIRELESS_USAGE_DATA_CUSTOM_FIRST5MB( + "wireless-usage-data-custom-first5mb" + ), + WIRELESS_USAGE_DATA_DOMESTIC_ROAMING( + "wireless-usage-data-domestic-roaming" + ), WIRELESS_USAGE_DATA_EUROPE("wireless-usage-data-europe"), - WIRELESS_USAGE_DATA_INDIVIDUAL_ADDITIONALGB("wireless-usage-data-individual-additionalgb"), - WIRELESS_USAGE_DATA_INDIVIDUAL_FIRSTGB("wireless-usage-data-individual-firstgb"), - WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_CANADA("wireless-usage-data-international-roaming-canada"), - WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_INDIA("wireless-usage-data-international-roaming-india"), - WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_MEXICO("wireless-usage-data-international-roaming-mexico"), + WIRELESS_USAGE_DATA_INDIVIDUAL_ADDITIONALGB( + "wireless-usage-data-individual-additionalgb" + ), + WIRELESS_USAGE_DATA_INDIVIDUAL_FIRSTGB( + "wireless-usage-data-individual-firstgb" + ), + WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_CANADA( + "wireless-usage-data-international-roaming-canada" + ), + WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_INDIA( + "wireless-usage-data-international-roaming-india" + ), + WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_MEXICO( + "wireless-usage-data-international-roaming-mexico" + ), WIRELESS_USAGE_DATA_NORTHAMERICA("wireless-usage-data-northamerica"), WIRELESS_USAGE_DATA_OCEANIA("wireless-usage-data-oceania"), WIRELESS_USAGE_DATA_POOLED("wireless-usage-data-pooled"), - WIRELESS_USAGE_DATA_POOLED_DOWNLINK("wireless-usage-data-pooled-downlink"), + WIRELESS_USAGE_DATA_POOLED_DOWNLINK( + "wireless-usage-data-pooled-downlink" + ), WIRELESS_USAGE_DATA_POOLED_UPLINK("wireless-usage-data-pooled-uplink"), WIRELESS_USAGE_MRC("wireless-usage-mrc"), WIRELESS_USAGE_MRC_CUSTOM("wireless-usage-mrc-custom"), @@ -372,51 +478,25 @@ public static Category forValue(final String value) { @JsonCreator private AllTime( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("api_version") - final String apiVersion, - - @JsonProperty("as_of") - final String asOf, - - @JsonProperty("category") - final AllTime.Category category, - - @JsonProperty("count") - final String count, - - @JsonProperty("count_unit") - final String countUnit, - - @JsonProperty("description") - final String description, - - @JsonProperty("end_date") - final String endDate, - - @JsonProperty("price") - final BigDecimal price, - - @JsonProperty("price_unit") - @JsonDeserialize(using = com.twilio.converter.CurrencyDeserializer.class) - final Currency priceUnit, - - @JsonProperty("start_date") - final String startDate, - - @JsonProperty("subresource_uris") - final Map subresourceUris, - - @JsonProperty("uri") - final String uri, - - @JsonProperty("usage") - final String usage, - - @JsonProperty("usage_unit") - final String usageUnit + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("api_version") final String apiVersion, + @JsonProperty("as_of") final String asOf, + @JsonProperty("category") final AllTime.Category category, + @JsonProperty("count") final String count, + @JsonProperty("count_unit") final String countUnit, + @JsonProperty("description") final String description, + @JsonProperty("end_date") final String endDate, + @JsonProperty("price") final BigDecimal price, + @JsonProperty("price_unit") @JsonDeserialize( + using = com.twilio.converter.CurrencyDeserializer.class + ) final Currency priceUnit, + @JsonProperty("start_date") final String startDate, + @JsonProperty( + "subresource_uris" + ) final Map subresourceUris, + @JsonProperty("uri") final String uri, + @JsonProperty("usage") final String usage, + @JsonProperty("usage_unit") final String usageUnit ) { this.accountSid = accountSid; this.apiVersion = apiVersion; @@ -435,55 +515,69 @@ private AllTime( this.usageUnit = usageUnit; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getApiVersion() { - return this.apiVersion; - } - public final String getAsOf() { - return this.asOf; - } - public final AllTime.Category getCategory() { - return this.category; - } - public final String getCount() { - return this.count; - } - public final String getCountUnit() { - return this.countUnit; - } - public final String getDescription() { - return this.description; - } - public final LocalDate getEndDate() { - return this.endDate; - } - public final BigDecimal getPrice() { - return this.price; - } - public final Currency getPriceUnit() { - return this.priceUnit; - } - public final LocalDate getStartDate() { - return this.startDate; - } - public final Map getSubresourceUris() { - return this.subresourceUris; - } - public final String getUri() { - return this.uri; - } - public final String getUsage() { - return this.usage; - } - public final String getUsageUnit() { - return this.usageUnit; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getApiVersion() { + return this.apiVersion; + } + + public final String getAsOf() { + return this.asOf; + } + + public final AllTime.Category getCategory() { + return this.category; + } + + public final String getCount() { + return this.count; + } + + public final String getCountUnit() { + return this.countUnit; + } + + public final String getDescription() { + return this.description; + } + + public final LocalDate getEndDate() { + return this.endDate; + } + + public final BigDecimal getPrice() { + return this.price; + } + + public final Currency getPriceUnit() { + return this.priceUnit; + } + + public final LocalDate getStartDate() { + return this.startDate; + } + + public final Map getSubresourceUris() { + return this.subresourceUris; + } + + public final String getUri() { + return this.uri; + } + + public final String getUsage() { + return this.usage; + } + + public final String getUsageUnit() { + return this.usageUnit; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -493,13 +587,43 @@ public boolean equals(final Object o) { AllTime other = (AllTime) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(apiVersion, other.apiVersion) && Objects.equals(asOf, other.asOf) && Objects.equals(category, other.category) && Objects.equals(count, other.count) && Objects.equals(countUnit, other.countUnit) && Objects.equals(description, other.description) && Objects.equals(endDate, other.endDate) && Objects.equals(price, other.price) && Objects.equals(priceUnit, other.priceUnit) && Objects.equals(startDate, other.startDate) && Objects.equals(subresourceUris, other.subresourceUris) && Objects.equals(uri, other.uri) && Objects.equals(usage, other.usage) && Objects.equals(usageUnit, other.usageUnit) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(apiVersion, other.apiVersion) && + Objects.equals(asOf, other.asOf) && + Objects.equals(category, other.category) && + Objects.equals(count, other.count) && + Objects.equals(countUnit, other.countUnit) && + Objects.equals(description, other.description) && + Objects.equals(endDate, other.endDate) && + Objects.equals(price, other.price) && + Objects.equals(priceUnit, other.priceUnit) && + Objects.equals(startDate, other.startDate) && + Objects.equals(subresourceUris, other.subresourceUris) && + Objects.equals(uri, other.uri) && + Objects.equals(usage, other.usage) && + Objects.equals(usageUnit, other.usageUnit) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, apiVersion, asOf, category, count, countUnit, description, endDate, price, priceUnit, startDate, subresourceUris, uri, usage, usageUnit); + return Objects.hash( + accountSid, + apiVersion, + asOf, + category, + count, + countUnit, + description, + endDate, + price, + priceUnit, + startDate, + subresourceUris, + uri, + usage, + usageUnit + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/AllTimeReader.java b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/AllTimeReader.java index fd82157b34..2fa4aca6c4 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/AllTimeReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/AllTimeReader.java @@ -14,8 +14,10 @@ package com.twilio.rest.api.v2010.account.usage.record; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,13 +26,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; import java.time.LocalDate; -import com.twilio.converter.DateConverter; - - public class AllTimeReader extends Reader { + private String pathAccountSid; private AllTime.Category category; private LocalDate startDate; @@ -38,29 +37,35 @@ public class AllTimeReader extends Reader { private Boolean includeSubaccounts; private Integer pageSize; - public AllTimeReader(){ - } - public AllTimeReader(final String pathAccountSid){ + public AllTimeReader() {} + + public AllTimeReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - public AllTimeReader setCategory(final AllTime.Category category){ + public AllTimeReader setCategory(final AllTime.Category category) { this.category = category; return this; } - public AllTimeReader setStartDate(final LocalDate startDate){ + + public AllTimeReader setStartDate(final LocalDate startDate) { this.startDate = startDate; return this; } - public AllTimeReader setEndDate(final LocalDate endDate){ + + public AllTimeReader setEndDate(final LocalDate endDate) { this.endDate = endDate; return this; } - public AllTimeReader setIncludeSubaccounts(final Boolean includeSubaccounts){ + + public AllTimeReader setIncludeSubaccounts( + final Boolean includeSubaccounts + ) { this.includeSubaccounts = includeSubaccounts; return this; } - public AllTimeReader setPageSize(final Integer pageSize){ + + public AllTimeReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -71,9 +76,17 @@ public ResourceSet read(final TwilioRestClient client) { } public Page firstPage(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/Usage/Records/AllTime.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); + String path = + "/2010-04-01/Accounts/{AccountSid}/Usage/Records/AllTime.json"; + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -85,13 +98,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AllTime read failed: Unable to connect to server"); + throw new ApiConnectionException( + "AllTime read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -107,7 +128,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reques } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.API.toString()) @@ -115,9 +139,11 @@ public Page previousPage(final Page page, final TwilioRestClie return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.API.toString()) @@ -126,37 +152,44 @@ public Page nextPage(final Page page, final TwilioRestClient c } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (category != null) { - request.addQueryParam("Category", category.toString()); } if (startDate != null) { - request.addQueryParam("StartDate", DateConverter.dateStringFromLocalDate(startDate)); + request.addQueryParam( + "StartDate", + DateConverter.dateStringFromLocalDate(startDate) + ); } if (endDate != null) { - request.addQueryParam("EndDate", DateConverter.dateStringFromLocalDate(endDate)); + request.addQueryParam( + "EndDate", + DateConverter.dateStringFromLocalDate(endDate) + ); } if (includeSubaccounts != null) { - - request.addQueryParam("IncludeSubaccounts", includeSubaccounts.toString()); + request.addQueryParam( + "IncludeSubaccounts", + includeSubaccounts.toString() + ); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/Daily.java b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/Daily.java index 95a568e30f..e76d7fd0b5 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/Daily.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/Daily.java @@ -20,49 +20,49 @@ import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.twilio.base.Resource; -import java.util.Currency; +import com.twilio.converter.CurrencyDeserializer; import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; -import com.twilio.converter.CurrencyDeserializer; import com.twilio.exception.ApiConnectionException; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; - +import java.math.BigDecimal; +import java.time.LocalDate; +import java.util.Currency; import java.util.Map; -import java.util.Objects; - - import java.util.Map; -import java.time.LocalDate; -import java.math.BigDecimal; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Daily extends Resource { + private static final long serialVersionUID = 73710721233963L; - public static DailyReader reader(){ + public static DailyReader reader() { return new DailyReader(); } - public static DailyReader reader(final String pathAccountSid){ + + public static DailyReader reader(final String pathAccountSid) { return new DailyReader(pathAccountSid); } /** - * Converts a JSON String into a Daily object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Daily object represented by the provided JSON - */ - public static Daily fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Daily object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Daily object represented by the provided JSON + */ + public static Daily fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Daily.class); @@ -74,14 +74,17 @@ public static Daily fromJson(final String json, final ObjectMapper objectMapper) } /** - * Converts a JSON InputStream into a Daily object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Daily object represented by the provided JSON - */ - public static Daily fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Daily object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Daily object represented by the provided JSON + */ + public static Daily fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Daily.class); @@ -91,6 +94,7 @@ public static Daily fromJson(final InputStream json, final ObjectMapper objectMa throw new ApiConnectionException(e.getMessage(), e); } } + public enum Category { A2P_REGISTRATION_FEES("a2p-registration-fees"), AGENT_CONFERENCE("agent-conference"), @@ -122,7 +126,9 @@ public enum Category { CONVERSATIONS("conversations"), CONVERSATIONS_API_REQUESTS("conversations-api-requests"), CONVERSATIONS_CONVERSATION_EVENTS("conversations-conversation-events"), - CONVERSATIONS_ENDPOINT_CONNECTIVITY("conversations-endpoint-connectivity"), + CONVERSATIONS_ENDPOINT_CONNECTIVITY( + "conversations-endpoint-connectivity" + ), CONVERSATIONS_EVENTS("conversations-events"), CONVERSATIONS_PARTICIPANT_EVENTS("conversations-participant-events"), CONVERSATIONS_PARTICIPANTS("conversations-participants"), @@ -131,7 +137,9 @@ public enum Category { FRAUD_LOOKUPS("fraud-lookups"), GROUP_ROOMS("group-rooms"), GROUP_ROOMS_DATA_TRACK("group-rooms-data-track"), - GROUP_ROOMS_ENCRYPTED_MEDIA_RECORDED("group-rooms-encrypted-media-recorded"), + GROUP_ROOMS_ENCRYPTED_MEDIA_RECORDED( + "group-rooms-encrypted-media-recorded" + ), GROUP_ROOMS_MEDIA_DOWNLOADED("group-rooms-media-downloaded"), GROUP_ROOMS_MEDIA_RECORDED("group-rooms-media-recorded"), GROUP_ROOMS_MEDIA_ROUTED("group-rooms-media-routed"), @@ -141,45 +149,99 @@ public enum Category { IMP_V1_USAGE("imp-v1-usage"), LOOKUPS("lookups"), MARKETPLACE("marketplace"), - MARKETPLACE_ALGORITHMIA_NAMED_ENTITY_RECOGNITION("marketplace-algorithmia-named-entity-recognition"), + MARKETPLACE_ALGORITHMIA_NAMED_ENTITY_RECOGNITION( + "marketplace-algorithmia-named-entity-recognition" + ), MARKETPLACE_CADENCE_TRANSCRIPTION("marketplace-cadence-transcription"), MARKETPLACE_CADENCE_TRANSLATION("marketplace-cadence-translation"), MARKETPLACE_CAPIO_SPEECH_TO_TEXT("marketplace-capio-speech-to-text"), MARKETPLACE_CONVRIZA_ABABA("marketplace-convriza-ababa"), - MARKETPLACE_DEEPGRAM_PHRASE_DETECTOR("marketplace-deepgram-phrase-detector"), - MARKETPLACE_DIGITAL_SEGMENT_BUSINESS_INFO("marketplace-digital-segment-business-info"), - MARKETPLACE_FACEBOOK_OFFLINE_CONVERSIONS("marketplace-facebook-offline-conversions"), + MARKETPLACE_DEEPGRAM_PHRASE_DETECTOR( + "marketplace-deepgram-phrase-detector" + ), + MARKETPLACE_DIGITAL_SEGMENT_BUSINESS_INFO( + "marketplace-digital-segment-business-info" + ), + MARKETPLACE_FACEBOOK_OFFLINE_CONVERSIONS( + "marketplace-facebook-offline-conversions" + ), MARKETPLACE_GOOGLE_SPEECH_TO_TEXT("marketplace-google-speech-to-text"), - MARKETPLACE_IBM_WATSON_MESSAGE_INSIGHTS("marketplace-ibm-watson-message-insights"), - MARKETPLACE_IBM_WATSON_MESSAGE_SENTIMENT("marketplace-ibm-watson-message-sentiment"), - MARKETPLACE_IBM_WATSON_RECORDING_ANALYSIS("marketplace-ibm-watson-recording-analysis"), - MARKETPLACE_IBM_WATSON_TONE_ANALYZER("marketplace-ibm-watson-tone-analyzer"), + MARKETPLACE_IBM_WATSON_MESSAGE_INSIGHTS( + "marketplace-ibm-watson-message-insights" + ), + MARKETPLACE_IBM_WATSON_MESSAGE_SENTIMENT( + "marketplace-ibm-watson-message-sentiment" + ), + MARKETPLACE_IBM_WATSON_RECORDING_ANALYSIS( + "marketplace-ibm-watson-recording-analysis" + ), + MARKETPLACE_IBM_WATSON_TONE_ANALYZER( + "marketplace-ibm-watson-tone-analyzer" + ), MARKETPLACE_ICEHOOK_SYSTEMS_SCOUT("marketplace-icehook-systems-scout"), - MARKETPLACE_INFOGROUP_DATAAXLE_BIZINFO("marketplace-infogroup-dataaxle-bizinfo"), - MARKETPLACE_KEEN_IO_CONTACT_CENTER_ANALYTICS("marketplace-keen-io-contact-center-analytics"), + MARKETPLACE_INFOGROUP_DATAAXLE_BIZINFO( + "marketplace-infogroup-dataaxle-bizinfo" + ), + MARKETPLACE_KEEN_IO_CONTACT_CENTER_ANALYTICS( + "marketplace-keen-io-contact-center-analytics" + ), MARKETPLACE_MARCHEX_CLEANCALL("marketplace-marchex-cleancall"), - MARKETPLACE_MARCHEX_SENTIMENT_ANALYSIS_FOR_SMS("marketplace-marchex-sentiment-analysis-for-sms"), - MARKETPLACE_MARKETPLACE_NEXTCALLER_SOCIAL_ID("marketplace-marketplace-nextcaller-social-id"), - MARKETPLACE_MOBILE_COMMONS_OPT_OUT_CLASSIFIER("marketplace-mobile-commons-opt-out-classifier"), - MARKETPLACE_NEXIWAVE_VOICEMAIL_TO_TEXT("marketplace-nexiwave-voicemail-to-text"), - MARKETPLACE_NEXTCALLER_ADVANCED_CALLER_IDENTIFICATION("marketplace-nextcaller-advanced-caller-identification"), + MARKETPLACE_MARCHEX_SENTIMENT_ANALYSIS_FOR_SMS( + "marketplace-marchex-sentiment-analysis-for-sms" + ), + MARKETPLACE_MARKETPLACE_NEXTCALLER_SOCIAL_ID( + "marketplace-marketplace-nextcaller-social-id" + ), + MARKETPLACE_MOBILE_COMMONS_OPT_OUT_CLASSIFIER( + "marketplace-mobile-commons-opt-out-classifier" + ), + MARKETPLACE_NEXIWAVE_VOICEMAIL_TO_TEXT( + "marketplace-nexiwave-voicemail-to-text" + ), + MARKETPLACE_NEXTCALLER_ADVANCED_CALLER_IDENTIFICATION( + "marketplace-nextcaller-advanced-caller-identification" + ), MARKETPLACE_NOMOROBO_SPAM_SCORE("marketplace-nomorobo-spam-score"), - MARKETPLACE_PAYFONE_TCPA_COMPLIANCE("marketplace-payfone-tcpa-compliance"), - MARKETPLACE_REMEETING_AUTOMATIC_SPEECH_RECOGNITION("marketplace-remeeting-automatic-speech-recognition"), - MARKETPLACE_TCPA_DEFENSE_SOLUTIONS_BLACKLIST_FEED("marketplace-tcpa-defense-solutions-blacklist-feed"), + MARKETPLACE_PAYFONE_TCPA_COMPLIANCE( + "marketplace-payfone-tcpa-compliance" + ), + MARKETPLACE_REMEETING_AUTOMATIC_SPEECH_RECOGNITION( + "marketplace-remeeting-automatic-speech-recognition" + ), + MARKETPLACE_TCPA_DEFENSE_SOLUTIONS_BLACKLIST_FEED( + "marketplace-tcpa-defense-solutions-blacklist-feed" + ), MARKETPLACE_TELO_OPENCNAM("marketplace-telo-opencnam"), MARKETPLACE_TRUECNAM_TRUE_SPAM("marketplace-truecnam-true-spam"), - MARKETPLACE_TWILIO_CALLER_NAME_LOOKUP_US("marketplace-twilio-caller-name-lookup-us"), - MARKETPLACE_TWILIO_CARRIER_INFORMATION_LOOKUP("marketplace-twilio-carrier-information-lookup"), + MARKETPLACE_TWILIO_CALLER_NAME_LOOKUP_US( + "marketplace-twilio-caller-name-lookup-us" + ), + MARKETPLACE_TWILIO_CARRIER_INFORMATION_LOOKUP( + "marketplace-twilio-carrier-information-lookup" + ), MARKETPLACE_VOICEBASE_PCI("marketplace-voicebase-pci"), - MARKETPLACE_VOICEBASE_TRANSCRIPTION("marketplace-voicebase-transcription"), - MARKETPLACE_VOICEBASE_TRANSCRIPTION_CUSTOM_VOCABULARY("marketplace-voicebase-transcription-custom-vocabulary"), - MARKETPLACE_WHITEPAGES_PRO_CALLER_IDENTIFICATION("marketplace-whitepages-pro-caller-identification"), - MARKETPLACE_WHITEPAGES_PRO_PHONE_INTELLIGENCE("marketplace-whitepages-pro-phone-intelligence"), - MARKETPLACE_WHITEPAGES_PRO_PHONE_REPUTATION("marketplace-whitepages-pro-phone-reputation"), - MARKETPLACE_WOLFARM_SPOKEN_RESULTS("marketplace-wolfarm-spoken-results"), + MARKETPLACE_VOICEBASE_TRANSCRIPTION( + "marketplace-voicebase-transcription" + ), + MARKETPLACE_VOICEBASE_TRANSCRIPTION_CUSTOM_VOCABULARY( + "marketplace-voicebase-transcription-custom-vocabulary" + ), + MARKETPLACE_WHITEPAGES_PRO_CALLER_IDENTIFICATION( + "marketplace-whitepages-pro-caller-identification" + ), + MARKETPLACE_WHITEPAGES_PRO_PHONE_INTELLIGENCE( + "marketplace-whitepages-pro-phone-intelligence" + ), + MARKETPLACE_WHITEPAGES_PRO_PHONE_REPUTATION( + "marketplace-whitepages-pro-phone-reputation" + ), + MARKETPLACE_WOLFARM_SPOKEN_RESULTS( + "marketplace-wolfarm-spoken-results" + ), MARKETPLACE_WOLFRAM_SHORT_ANSWER("marketplace-wolfram-short-answer"), - MARKETPLACE_YTICA_CONTACT_CENTER_REPORTING_ANALYTICS("marketplace-ytica-contact-center-reporting-analytics"), + MARKETPLACE_YTICA_CONTACT_CENTER_REPORTING_ANALYTICS( + "marketplace-ytica-contact-center-reporting-analytics" + ), MEDIASTORAGE("mediastorage"), MMS("mms"), MMS_INBOUND("mms-inbound"), @@ -198,7 +260,9 @@ public enum Category { NUMBER_FORMAT_LOOKUPS("number-format-lookups"), PCHAT("pchat"), PCHAT_USERS("pchat-users"), - PEER_TO_PEER_ROOMS_PARTICIPANT_MINUTES("peer-to-peer-rooms-participant-minutes"), + PEER_TO_PEER_ROOMS_PARTICIPANT_MINUTES( + "peer-to-peer-rooms-participant-minutes" + ), PFAX("pfax"), PFAX_MINUTES("pfax-minutes"), PFAX_MINUTES_INBOUND("pfax-minutes-inbound"), @@ -245,7 +309,9 @@ public enum Category { SHORTCODES_VANITY("shortcodes-vanity"), SMALL_GROUP_ROOMS("small-group-rooms"), SMALL_GROUP_ROOMS_DATA_TRACK("small-group-rooms-data-track"), - SMALL_GROUP_ROOMS_PARTICIPANT_MINUTES("small-group-rooms-participant-minutes"), + SMALL_GROUP_ROOMS_PARTICIPANT_MINUTES( + "small-group-rooms-participant-minutes" + ), SMS("sms"), SMS_INBOUND("sms-inbound"), SMS_INBOUND_LONGCODE("sms-inbound-longcode"), @@ -262,7 +328,9 @@ public enum Category { SYNC("sync"), SYNC_ACTIONS("sync-actions"), SYNC_ENDPOINT_HOURS("sync-endpoint-hours"), - SYNC_ENDPOINT_HOURS_ABOVE_DAILY_CAP("sync-endpoint-hours-above-daily-cap"), + SYNC_ENDPOINT_HOURS_ABOVE_DAILY_CAP( + "sync-endpoint-hours-above-daily-cap" + ), TASKROUTER_TASKS("taskrouter-tasks"), TOTALPRICE("totalprice"), TRANSCRIPTIONS("transcriptions"), @@ -275,6 +343,7 @@ public enum Category { TRUNKING_RECORDINGS("trunking-recordings"), TRUNKING_SECURE("trunking-secure"), TRUNKING_TERMINATION("trunking-termination"), + TTS_GOOGLE("tts-google"), TURNMEGABYTES("turnmegabytes"), TURNMEGABYTES_AUSTRALIA("turnmegabytes-australia"), TURNMEGABYTES_BRASIL("turnmegabytes-brasil"), @@ -288,14 +357,27 @@ public enum Category { TWILIO_INTERCONNECT("twilio-interconnect"), VERIFY_PUSH("verify-push"), VERIFY_TOTP("verify-totp"), - VERIFY_WHATSAPP_CONVERSATIONS_BUSINESS_INITIATED("verify-whatsapp-conversations-business-initiated"), + VERIFY_WHATSAPP_CONVERSATIONS_BUSINESS_INITIATED( + "verify-whatsapp-conversations-business-initiated" + ), VIDEO_RECORDINGS("video-recordings"), VIRTUAL_AGENT("virtual-agent"), VOICE_INSIGHTS("voice-insights"), - VOICE_INSIGHTS_CLIENT_INSIGHTS_ON_DEMAND_MINUTE("voice-insights-client-insights-on-demand-minute"), - VOICE_INSIGHTS_PTSN_INSIGHTS_ON_DEMAND_MINUTE("voice-insights-ptsn-insights-on-demand-minute"), - VOICE_INSIGHTS_SIP_INTERFACE_INSIGHTS_ON_DEMAND_MINUTE("voice-insights-sip-interface-insights-on-demand-minute"), - VOICE_INSIGHTS_SIP_TRUNKING_INSIGHTS_ON_DEMAND_MINUTE("voice-insights-sip-trunking-insights-on-demand-minute"), + VOICE_INSIGHTS_CLIENT_INSIGHTS_ON_DEMAND_MINUTE( + "voice-insights-client-insights-on-demand-minute" + ), + VOICE_INSIGHTS_PTSN_INSIGHTS_ON_DEMAND_MINUTE( + "voice-insights-ptsn-insights-on-demand-minute" + ), + VOICE_INSIGHTS_SIP_INTERFACE_INSIGHTS_ON_DEMAND_MINUTE( + "voice-insights-sip-interface-insights-on-demand-minute" + ), + VOICE_INSIGHTS_SIP_TRUNKING_INSIGHTS_ON_DEMAND_MINUTE( + "voice-insights-sip-trunking-insights-on-demand-minute" + ), + VOICE_INTELLIGENCE("voice-intelligence"), + VOICE_INTELLIGENCE_TRANSCRIPTION("voice-intelligence-transcription"), + VOICE_INTELLIGENCE_OPERATORS("voice-intelligence-operators"), WIRELESS("wireless"), WIRELESS_ORDERS("wireless-orders"), WIRELESS_ORDERS_ARTWORK("wireless-orders-artwork"), @@ -306,29 +388,53 @@ public enum Category { WIRELESS_USAGE_COMMANDS("wireless-usage-commands"), WIRELESS_USAGE_COMMANDS_AFRICA("wireless-usage-commands-africa"), WIRELESS_USAGE_COMMANDS_ASIA("wireless-usage-commands-asia"), - WIRELESS_USAGE_COMMANDS_CENTRALANDSOUTHAMERICA("wireless-usage-commands-centralandsouthamerica"), + WIRELESS_USAGE_COMMANDS_CENTRALANDSOUTHAMERICA( + "wireless-usage-commands-centralandsouthamerica" + ), WIRELESS_USAGE_COMMANDS_EUROPE("wireless-usage-commands-europe"), WIRELESS_USAGE_COMMANDS_HOME("wireless-usage-commands-home"), - WIRELESS_USAGE_COMMANDS_NORTHAMERICA("wireless-usage-commands-northamerica"), + WIRELESS_USAGE_COMMANDS_NORTHAMERICA( + "wireless-usage-commands-northamerica" + ), WIRELESS_USAGE_COMMANDS_OCEANIA("wireless-usage-commands-oceania"), WIRELESS_USAGE_COMMANDS_ROAMING("wireless-usage-commands-roaming"), WIRELESS_USAGE_DATA("wireless-usage-data"), WIRELESS_USAGE_DATA_AFRICA("wireless-usage-data-africa"), WIRELESS_USAGE_DATA_ASIA("wireless-usage-data-asia"), - WIRELESS_USAGE_DATA_CENTRALANDSOUTHAMERICA("wireless-usage-data-centralandsouthamerica"), - WIRELESS_USAGE_DATA_CUSTOM_ADDITIONALMB("wireless-usage-data-custom-additionalmb"), - WIRELESS_USAGE_DATA_CUSTOM_FIRST5MB("wireless-usage-data-custom-first5mb"), - WIRELESS_USAGE_DATA_DOMESTIC_ROAMING("wireless-usage-data-domestic-roaming"), + WIRELESS_USAGE_DATA_CENTRALANDSOUTHAMERICA( + "wireless-usage-data-centralandsouthamerica" + ), + WIRELESS_USAGE_DATA_CUSTOM_ADDITIONALMB( + "wireless-usage-data-custom-additionalmb" + ), + WIRELESS_USAGE_DATA_CUSTOM_FIRST5MB( + "wireless-usage-data-custom-first5mb" + ), + WIRELESS_USAGE_DATA_DOMESTIC_ROAMING( + "wireless-usage-data-domestic-roaming" + ), WIRELESS_USAGE_DATA_EUROPE("wireless-usage-data-europe"), - WIRELESS_USAGE_DATA_INDIVIDUAL_ADDITIONALGB("wireless-usage-data-individual-additionalgb"), - WIRELESS_USAGE_DATA_INDIVIDUAL_FIRSTGB("wireless-usage-data-individual-firstgb"), - WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_CANADA("wireless-usage-data-international-roaming-canada"), - WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_INDIA("wireless-usage-data-international-roaming-india"), - WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_MEXICO("wireless-usage-data-international-roaming-mexico"), + WIRELESS_USAGE_DATA_INDIVIDUAL_ADDITIONALGB( + "wireless-usage-data-individual-additionalgb" + ), + WIRELESS_USAGE_DATA_INDIVIDUAL_FIRSTGB( + "wireless-usage-data-individual-firstgb" + ), + WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_CANADA( + "wireless-usage-data-international-roaming-canada" + ), + WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_INDIA( + "wireless-usage-data-international-roaming-india" + ), + WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_MEXICO( + "wireless-usage-data-international-roaming-mexico" + ), WIRELESS_USAGE_DATA_NORTHAMERICA("wireless-usage-data-northamerica"), WIRELESS_USAGE_DATA_OCEANIA("wireless-usage-data-oceania"), WIRELESS_USAGE_DATA_POOLED("wireless-usage-data-pooled"), - WIRELESS_USAGE_DATA_POOLED_DOWNLINK("wireless-usage-data-pooled-downlink"), + WIRELESS_USAGE_DATA_POOLED_DOWNLINK( + "wireless-usage-data-pooled-downlink" + ), WIRELESS_USAGE_DATA_POOLED_UPLINK("wireless-usage-data-pooled-uplink"), WIRELESS_USAGE_MRC("wireless-usage-mrc"), WIRELESS_USAGE_MRC_CUSTOM("wireless-usage-mrc-custom"), @@ -372,51 +478,25 @@ public static Category forValue(final String value) { @JsonCreator private Daily( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("api_version") - final String apiVersion, - - @JsonProperty("as_of") - final String asOf, - - @JsonProperty("category") - final Daily.Category category, - - @JsonProperty("count") - final String count, - - @JsonProperty("count_unit") - final String countUnit, - - @JsonProperty("description") - final String description, - - @JsonProperty("end_date") - final String endDate, - - @JsonProperty("price") - final BigDecimal price, - - @JsonProperty("price_unit") - @JsonDeserialize(using = com.twilio.converter.CurrencyDeserializer.class) - final Currency priceUnit, - - @JsonProperty("start_date") - final String startDate, - - @JsonProperty("subresource_uris") - final Map subresourceUris, - - @JsonProperty("uri") - final String uri, - - @JsonProperty("usage") - final String usage, - - @JsonProperty("usage_unit") - final String usageUnit + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("api_version") final String apiVersion, + @JsonProperty("as_of") final String asOf, + @JsonProperty("category") final Daily.Category category, + @JsonProperty("count") final String count, + @JsonProperty("count_unit") final String countUnit, + @JsonProperty("description") final String description, + @JsonProperty("end_date") final String endDate, + @JsonProperty("price") final BigDecimal price, + @JsonProperty("price_unit") @JsonDeserialize( + using = com.twilio.converter.CurrencyDeserializer.class + ) final Currency priceUnit, + @JsonProperty("start_date") final String startDate, + @JsonProperty( + "subresource_uris" + ) final Map subresourceUris, + @JsonProperty("uri") final String uri, + @JsonProperty("usage") final String usage, + @JsonProperty("usage_unit") final String usageUnit ) { this.accountSid = accountSid; this.apiVersion = apiVersion; @@ -435,55 +515,69 @@ private Daily( this.usageUnit = usageUnit; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getApiVersion() { - return this.apiVersion; - } - public final String getAsOf() { - return this.asOf; - } - public final Daily.Category getCategory() { - return this.category; - } - public final String getCount() { - return this.count; - } - public final String getCountUnit() { - return this.countUnit; - } - public final String getDescription() { - return this.description; - } - public final LocalDate getEndDate() { - return this.endDate; - } - public final BigDecimal getPrice() { - return this.price; - } - public final Currency getPriceUnit() { - return this.priceUnit; - } - public final LocalDate getStartDate() { - return this.startDate; - } - public final Map getSubresourceUris() { - return this.subresourceUris; - } - public final String getUri() { - return this.uri; - } - public final String getUsage() { - return this.usage; - } - public final String getUsageUnit() { - return this.usageUnit; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getApiVersion() { + return this.apiVersion; + } + + public final String getAsOf() { + return this.asOf; + } + + public final Daily.Category getCategory() { + return this.category; + } + + public final String getCount() { + return this.count; + } + + public final String getCountUnit() { + return this.countUnit; + } + + public final String getDescription() { + return this.description; + } + + public final LocalDate getEndDate() { + return this.endDate; + } + + public final BigDecimal getPrice() { + return this.price; + } + + public final Currency getPriceUnit() { + return this.priceUnit; + } + + public final LocalDate getStartDate() { + return this.startDate; + } + + public final Map getSubresourceUris() { + return this.subresourceUris; + } + + public final String getUri() { + return this.uri; + } + + public final String getUsage() { + return this.usage; + } + + public final String getUsageUnit() { + return this.usageUnit; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -493,13 +587,43 @@ public boolean equals(final Object o) { Daily other = (Daily) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(apiVersion, other.apiVersion) && Objects.equals(asOf, other.asOf) && Objects.equals(category, other.category) && Objects.equals(count, other.count) && Objects.equals(countUnit, other.countUnit) && Objects.equals(description, other.description) && Objects.equals(endDate, other.endDate) && Objects.equals(price, other.price) && Objects.equals(priceUnit, other.priceUnit) && Objects.equals(startDate, other.startDate) && Objects.equals(subresourceUris, other.subresourceUris) && Objects.equals(uri, other.uri) && Objects.equals(usage, other.usage) && Objects.equals(usageUnit, other.usageUnit) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(apiVersion, other.apiVersion) && + Objects.equals(asOf, other.asOf) && + Objects.equals(category, other.category) && + Objects.equals(count, other.count) && + Objects.equals(countUnit, other.countUnit) && + Objects.equals(description, other.description) && + Objects.equals(endDate, other.endDate) && + Objects.equals(price, other.price) && + Objects.equals(priceUnit, other.priceUnit) && + Objects.equals(startDate, other.startDate) && + Objects.equals(subresourceUris, other.subresourceUris) && + Objects.equals(uri, other.uri) && + Objects.equals(usage, other.usage) && + Objects.equals(usageUnit, other.usageUnit) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, apiVersion, asOf, category, count, countUnit, description, endDate, price, priceUnit, startDate, subresourceUris, uri, usage, usageUnit); + return Objects.hash( + accountSid, + apiVersion, + asOf, + category, + count, + countUnit, + description, + endDate, + price, + priceUnit, + startDate, + subresourceUris, + uri, + usage, + usageUnit + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/DailyReader.java b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/DailyReader.java index fd0eff6e10..d6621a454f 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/DailyReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/DailyReader.java @@ -14,8 +14,10 @@ package com.twilio.rest.api.v2010.account.usage.record; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,13 +26,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; import java.time.LocalDate; -import com.twilio.converter.DateConverter; - - public class DailyReader extends Reader { + private String pathAccountSid; private Daily.Category category; private LocalDate startDate; @@ -38,29 +37,33 @@ public class DailyReader extends Reader { private Boolean includeSubaccounts; private Integer pageSize; - public DailyReader(){ - } - public DailyReader(final String pathAccountSid){ + public DailyReader() {} + + public DailyReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - public DailyReader setCategory(final Daily.Category category){ + public DailyReader setCategory(final Daily.Category category) { this.category = category; return this; } - public DailyReader setStartDate(final LocalDate startDate){ + + public DailyReader setStartDate(final LocalDate startDate) { this.startDate = startDate; return this; } - public DailyReader setEndDate(final LocalDate endDate){ + + public DailyReader setEndDate(final LocalDate endDate) { this.endDate = endDate; return this; } - public DailyReader setIncludeSubaccounts(final Boolean includeSubaccounts){ + + public DailyReader setIncludeSubaccounts(final Boolean includeSubaccounts) { this.includeSubaccounts = includeSubaccounts; return this; } - public DailyReader setPageSize(final Integer pageSize){ + + public DailyReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -71,9 +74,17 @@ public ResourceSet read(final TwilioRestClient client) { } public Page firstPage(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/Usage/Records/Daily.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); + String path = + "/2010-04-01/Accounts/{AccountSid}/Usage/Records/Daily.json"; + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -85,13 +96,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Daily read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Daily read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -107,7 +126,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.API.toString()) @@ -115,9 +137,11 @@ public Page previousPage(final Page page, final TwilioRestClient c return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.API.toString()) @@ -126,37 +150,44 @@ public Page nextPage(final Page page, final TwilioRestClient clien } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (category != null) { - request.addQueryParam("Category", category.toString()); } if (startDate != null) { - request.addQueryParam("StartDate", DateConverter.dateStringFromLocalDate(startDate)); + request.addQueryParam( + "StartDate", + DateConverter.dateStringFromLocalDate(startDate) + ); } if (endDate != null) { - request.addQueryParam("EndDate", DateConverter.dateStringFromLocalDate(endDate)); + request.addQueryParam( + "EndDate", + DateConverter.dateStringFromLocalDate(endDate) + ); } if (includeSubaccounts != null) { - - request.addQueryParam("IncludeSubaccounts", includeSubaccounts.toString()); + request.addQueryParam( + "IncludeSubaccounts", + includeSubaccounts.toString() + ); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/LastMonth.java b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/LastMonth.java index a8a1e6fc5e..2e2a2c5d1e 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/LastMonth.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/LastMonth.java @@ -20,49 +20,49 @@ import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.twilio.base.Resource; -import java.util.Currency; +import com.twilio.converter.CurrencyDeserializer; import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; -import com.twilio.converter.CurrencyDeserializer; import com.twilio.exception.ApiConnectionException; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; - +import java.math.BigDecimal; +import java.time.LocalDate; +import java.util.Currency; import java.util.Map; -import java.util.Objects; - - import java.util.Map; -import java.time.LocalDate; -import java.math.BigDecimal; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class LastMonth extends Resource { + private static final long serialVersionUID = 240801278405798L; - public static LastMonthReader reader(){ + public static LastMonthReader reader() { return new LastMonthReader(); } - public static LastMonthReader reader(final String pathAccountSid){ + + public static LastMonthReader reader(final String pathAccountSid) { return new LastMonthReader(pathAccountSid); } /** - * Converts a JSON String into a LastMonth object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return LastMonth object represented by the provided JSON - */ - public static LastMonth fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a LastMonth object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return LastMonth object represented by the provided JSON + */ + public static LastMonth fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, LastMonth.class); @@ -74,14 +74,17 @@ public static LastMonth fromJson(final String json, final ObjectMapper objectMap } /** - * Converts a JSON InputStream into a LastMonth object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return LastMonth object represented by the provided JSON - */ - public static LastMonth fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a LastMonth object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return LastMonth object represented by the provided JSON + */ + public static LastMonth fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, LastMonth.class); @@ -91,6 +94,7 @@ public static LastMonth fromJson(final InputStream json, final ObjectMapper obje throw new ApiConnectionException(e.getMessage(), e); } } + public enum Category { A2P_REGISTRATION_FEES("a2p-registration-fees"), AGENT_CONFERENCE("agent-conference"), @@ -122,7 +126,9 @@ public enum Category { CONVERSATIONS("conversations"), CONVERSATIONS_API_REQUESTS("conversations-api-requests"), CONVERSATIONS_CONVERSATION_EVENTS("conversations-conversation-events"), - CONVERSATIONS_ENDPOINT_CONNECTIVITY("conversations-endpoint-connectivity"), + CONVERSATIONS_ENDPOINT_CONNECTIVITY( + "conversations-endpoint-connectivity" + ), CONVERSATIONS_EVENTS("conversations-events"), CONVERSATIONS_PARTICIPANT_EVENTS("conversations-participant-events"), CONVERSATIONS_PARTICIPANTS("conversations-participants"), @@ -131,7 +137,9 @@ public enum Category { FRAUD_LOOKUPS("fraud-lookups"), GROUP_ROOMS("group-rooms"), GROUP_ROOMS_DATA_TRACK("group-rooms-data-track"), - GROUP_ROOMS_ENCRYPTED_MEDIA_RECORDED("group-rooms-encrypted-media-recorded"), + GROUP_ROOMS_ENCRYPTED_MEDIA_RECORDED( + "group-rooms-encrypted-media-recorded" + ), GROUP_ROOMS_MEDIA_DOWNLOADED("group-rooms-media-downloaded"), GROUP_ROOMS_MEDIA_RECORDED("group-rooms-media-recorded"), GROUP_ROOMS_MEDIA_ROUTED("group-rooms-media-routed"), @@ -141,45 +149,99 @@ public enum Category { IMP_V1_USAGE("imp-v1-usage"), LOOKUPS("lookups"), MARKETPLACE("marketplace"), - MARKETPLACE_ALGORITHMIA_NAMED_ENTITY_RECOGNITION("marketplace-algorithmia-named-entity-recognition"), + MARKETPLACE_ALGORITHMIA_NAMED_ENTITY_RECOGNITION( + "marketplace-algorithmia-named-entity-recognition" + ), MARKETPLACE_CADENCE_TRANSCRIPTION("marketplace-cadence-transcription"), MARKETPLACE_CADENCE_TRANSLATION("marketplace-cadence-translation"), MARKETPLACE_CAPIO_SPEECH_TO_TEXT("marketplace-capio-speech-to-text"), MARKETPLACE_CONVRIZA_ABABA("marketplace-convriza-ababa"), - MARKETPLACE_DEEPGRAM_PHRASE_DETECTOR("marketplace-deepgram-phrase-detector"), - MARKETPLACE_DIGITAL_SEGMENT_BUSINESS_INFO("marketplace-digital-segment-business-info"), - MARKETPLACE_FACEBOOK_OFFLINE_CONVERSIONS("marketplace-facebook-offline-conversions"), + MARKETPLACE_DEEPGRAM_PHRASE_DETECTOR( + "marketplace-deepgram-phrase-detector" + ), + MARKETPLACE_DIGITAL_SEGMENT_BUSINESS_INFO( + "marketplace-digital-segment-business-info" + ), + MARKETPLACE_FACEBOOK_OFFLINE_CONVERSIONS( + "marketplace-facebook-offline-conversions" + ), MARKETPLACE_GOOGLE_SPEECH_TO_TEXT("marketplace-google-speech-to-text"), - MARKETPLACE_IBM_WATSON_MESSAGE_INSIGHTS("marketplace-ibm-watson-message-insights"), - MARKETPLACE_IBM_WATSON_MESSAGE_SENTIMENT("marketplace-ibm-watson-message-sentiment"), - MARKETPLACE_IBM_WATSON_RECORDING_ANALYSIS("marketplace-ibm-watson-recording-analysis"), - MARKETPLACE_IBM_WATSON_TONE_ANALYZER("marketplace-ibm-watson-tone-analyzer"), + MARKETPLACE_IBM_WATSON_MESSAGE_INSIGHTS( + "marketplace-ibm-watson-message-insights" + ), + MARKETPLACE_IBM_WATSON_MESSAGE_SENTIMENT( + "marketplace-ibm-watson-message-sentiment" + ), + MARKETPLACE_IBM_WATSON_RECORDING_ANALYSIS( + "marketplace-ibm-watson-recording-analysis" + ), + MARKETPLACE_IBM_WATSON_TONE_ANALYZER( + "marketplace-ibm-watson-tone-analyzer" + ), MARKETPLACE_ICEHOOK_SYSTEMS_SCOUT("marketplace-icehook-systems-scout"), - MARKETPLACE_INFOGROUP_DATAAXLE_BIZINFO("marketplace-infogroup-dataaxle-bizinfo"), - MARKETPLACE_KEEN_IO_CONTACT_CENTER_ANALYTICS("marketplace-keen-io-contact-center-analytics"), + MARKETPLACE_INFOGROUP_DATAAXLE_BIZINFO( + "marketplace-infogroup-dataaxle-bizinfo" + ), + MARKETPLACE_KEEN_IO_CONTACT_CENTER_ANALYTICS( + "marketplace-keen-io-contact-center-analytics" + ), MARKETPLACE_MARCHEX_CLEANCALL("marketplace-marchex-cleancall"), - MARKETPLACE_MARCHEX_SENTIMENT_ANALYSIS_FOR_SMS("marketplace-marchex-sentiment-analysis-for-sms"), - MARKETPLACE_MARKETPLACE_NEXTCALLER_SOCIAL_ID("marketplace-marketplace-nextcaller-social-id"), - MARKETPLACE_MOBILE_COMMONS_OPT_OUT_CLASSIFIER("marketplace-mobile-commons-opt-out-classifier"), - MARKETPLACE_NEXIWAVE_VOICEMAIL_TO_TEXT("marketplace-nexiwave-voicemail-to-text"), - MARKETPLACE_NEXTCALLER_ADVANCED_CALLER_IDENTIFICATION("marketplace-nextcaller-advanced-caller-identification"), + MARKETPLACE_MARCHEX_SENTIMENT_ANALYSIS_FOR_SMS( + "marketplace-marchex-sentiment-analysis-for-sms" + ), + MARKETPLACE_MARKETPLACE_NEXTCALLER_SOCIAL_ID( + "marketplace-marketplace-nextcaller-social-id" + ), + MARKETPLACE_MOBILE_COMMONS_OPT_OUT_CLASSIFIER( + "marketplace-mobile-commons-opt-out-classifier" + ), + MARKETPLACE_NEXIWAVE_VOICEMAIL_TO_TEXT( + "marketplace-nexiwave-voicemail-to-text" + ), + MARKETPLACE_NEXTCALLER_ADVANCED_CALLER_IDENTIFICATION( + "marketplace-nextcaller-advanced-caller-identification" + ), MARKETPLACE_NOMOROBO_SPAM_SCORE("marketplace-nomorobo-spam-score"), - MARKETPLACE_PAYFONE_TCPA_COMPLIANCE("marketplace-payfone-tcpa-compliance"), - MARKETPLACE_REMEETING_AUTOMATIC_SPEECH_RECOGNITION("marketplace-remeeting-automatic-speech-recognition"), - MARKETPLACE_TCPA_DEFENSE_SOLUTIONS_BLACKLIST_FEED("marketplace-tcpa-defense-solutions-blacklist-feed"), + MARKETPLACE_PAYFONE_TCPA_COMPLIANCE( + "marketplace-payfone-tcpa-compliance" + ), + MARKETPLACE_REMEETING_AUTOMATIC_SPEECH_RECOGNITION( + "marketplace-remeeting-automatic-speech-recognition" + ), + MARKETPLACE_TCPA_DEFENSE_SOLUTIONS_BLACKLIST_FEED( + "marketplace-tcpa-defense-solutions-blacklist-feed" + ), MARKETPLACE_TELO_OPENCNAM("marketplace-telo-opencnam"), MARKETPLACE_TRUECNAM_TRUE_SPAM("marketplace-truecnam-true-spam"), - MARKETPLACE_TWILIO_CALLER_NAME_LOOKUP_US("marketplace-twilio-caller-name-lookup-us"), - MARKETPLACE_TWILIO_CARRIER_INFORMATION_LOOKUP("marketplace-twilio-carrier-information-lookup"), + MARKETPLACE_TWILIO_CALLER_NAME_LOOKUP_US( + "marketplace-twilio-caller-name-lookup-us" + ), + MARKETPLACE_TWILIO_CARRIER_INFORMATION_LOOKUP( + "marketplace-twilio-carrier-information-lookup" + ), MARKETPLACE_VOICEBASE_PCI("marketplace-voicebase-pci"), - MARKETPLACE_VOICEBASE_TRANSCRIPTION("marketplace-voicebase-transcription"), - MARKETPLACE_VOICEBASE_TRANSCRIPTION_CUSTOM_VOCABULARY("marketplace-voicebase-transcription-custom-vocabulary"), - MARKETPLACE_WHITEPAGES_PRO_CALLER_IDENTIFICATION("marketplace-whitepages-pro-caller-identification"), - MARKETPLACE_WHITEPAGES_PRO_PHONE_INTELLIGENCE("marketplace-whitepages-pro-phone-intelligence"), - MARKETPLACE_WHITEPAGES_PRO_PHONE_REPUTATION("marketplace-whitepages-pro-phone-reputation"), - MARKETPLACE_WOLFARM_SPOKEN_RESULTS("marketplace-wolfarm-spoken-results"), + MARKETPLACE_VOICEBASE_TRANSCRIPTION( + "marketplace-voicebase-transcription" + ), + MARKETPLACE_VOICEBASE_TRANSCRIPTION_CUSTOM_VOCABULARY( + "marketplace-voicebase-transcription-custom-vocabulary" + ), + MARKETPLACE_WHITEPAGES_PRO_CALLER_IDENTIFICATION( + "marketplace-whitepages-pro-caller-identification" + ), + MARKETPLACE_WHITEPAGES_PRO_PHONE_INTELLIGENCE( + "marketplace-whitepages-pro-phone-intelligence" + ), + MARKETPLACE_WHITEPAGES_PRO_PHONE_REPUTATION( + "marketplace-whitepages-pro-phone-reputation" + ), + MARKETPLACE_WOLFARM_SPOKEN_RESULTS( + "marketplace-wolfarm-spoken-results" + ), MARKETPLACE_WOLFRAM_SHORT_ANSWER("marketplace-wolfram-short-answer"), - MARKETPLACE_YTICA_CONTACT_CENTER_REPORTING_ANALYTICS("marketplace-ytica-contact-center-reporting-analytics"), + MARKETPLACE_YTICA_CONTACT_CENTER_REPORTING_ANALYTICS( + "marketplace-ytica-contact-center-reporting-analytics" + ), MEDIASTORAGE("mediastorage"), MMS("mms"), MMS_INBOUND("mms-inbound"), @@ -198,7 +260,9 @@ public enum Category { NUMBER_FORMAT_LOOKUPS("number-format-lookups"), PCHAT("pchat"), PCHAT_USERS("pchat-users"), - PEER_TO_PEER_ROOMS_PARTICIPANT_MINUTES("peer-to-peer-rooms-participant-minutes"), + PEER_TO_PEER_ROOMS_PARTICIPANT_MINUTES( + "peer-to-peer-rooms-participant-minutes" + ), PFAX("pfax"), PFAX_MINUTES("pfax-minutes"), PFAX_MINUTES_INBOUND("pfax-minutes-inbound"), @@ -245,7 +309,9 @@ public enum Category { SHORTCODES_VANITY("shortcodes-vanity"), SMALL_GROUP_ROOMS("small-group-rooms"), SMALL_GROUP_ROOMS_DATA_TRACK("small-group-rooms-data-track"), - SMALL_GROUP_ROOMS_PARTICIPANT_MINUTES("small-group-rooms-participant-minutes"), + SMALL_GROUP_ROOMS_PARTICIPANT_MINUTES( + "small-group-rooms-participant-minutes" + ), SMS("sms"), SMS_INBOUND("sms-inbound"), SMS_INBOUND_LONGCODE("sms-inbound-longcode"), @@ -262,7 +328,9 @@ public enum Category { SYNC("sync"), SYNC_ACTIONS("sync-actions"), SYNC_ENDPOINT_HOURS("sync-endpoint-hours"), - SYNC_ENDPOINT_HOURS_ABOVE_DAILY_CAP("sync-endpoint-hours-above-daily-cap"), + SYNC_ENDPOINT_HOURS_ABOVE_DAILY_CAP( + "sync-endpoint-hours-above-daily-cap" + ), TASKROUTER_TASKS("taskrouter-tasks"), TOTALPRICE("totalprice"), TRANSCRIPTIONS("transcriptions"), @@ -275,6 +343,7 @@ public enum Category { TRUNKING_RECORDINGS("trunking-recordings"), TRUNKING_SECURE("trunking-secure"), TRUNKING_TERMINATION("trunking-termination"), + TTS_GOOGLE("tts-google"), TURNMEGABYTES("turnmegabytes"), TURNMEGABYTES_AUSTRALIA("turnmegabytes-australia"), TURNMEGABYTES_BRASIL("turnmegabytes-brasil"), @@ -288,14 +357,27 @@ public enum Category { TWILIO_INTERCONNECT("twilio-interconnect"), VERIFY_PUSH("verify-push"), VERIFY_TOTP("verify-totp"), - VERIFY_WHATSAPP_CONVERSATIONS_BUSINESS_INITIATED("verify-whatsapp-conversations-business-initiated"), + VERIFY_WHATSAPP_CONVERSATIONS_BUSINESS_INITIATED( + "verify-whatsapp-conversations-business-initiated" + ), VIDEO_RECORDINGS("video-recordings"), VIRTUAL_AGENT("virtual-agent"), VOICE_INSIGHTS("voice-insights"), - VOICE_INSIGHTS_CLIENT_INSIGHTS_ON_DEMAND_MINUTE("voice-insights-client-insights-on-demand-minute"), - VOICE_INSIGHTS_PTSN_INSIGHTS_ON_DEMAND_MINUTE("voice-insights-ptsn-insights-on-demand-minute"), - VOICE_INSIGHTS_SIP_INTERFACE_INSIGHTS_ON_DEMAND_MINUTE("voice-insights-sip-interface-insights-on-demand-minute"), - VOICE_INSIGHTS_SIP_TRUNKING_INSIGHTS_ON_DEMAND_MINUTE("voice-insights-sip-trunking-insights-on-demand-minute"), + VOICE_INSIGHTS_CLIENT_INSIGHTS_ON_DEMAND_MINUTE( + "voice-insights-client-insights-on-demand-minute" + ), + VOICE_INSIGHTS_PTSN_INSIGHTS_ON_DEMAND_MINUTE( + "voice-insights-ptsn-insights-on-demand-minute" + ), + VOICE_INSIGHTS_SIP_INTERFACE_INSIGHTS_ON_DEMAND_MINUTE( + "voice-insights-sip-interface-insights-on-demand-minute" + ), + VOICE_INSIGHTS_SIP_TRUNKING_INSIGHTS_ON_DEMAND_MINUTE( + "voice-insights-sip-trunking-insights-on-demand-minute" + ), + VOICE_INTELLIGENCE("voice-intelligence"), + VOICE_INTELLIGENCE_TRANSCRIPTION("voice-intelligence-transcription"), + VOICE_INTELLIGENCE_OPERATORS("voice-intelligence-operators"), WIRELESS("wireless"), WIRELESS_ORDERS("wireless-orders"), WIRELESS_ORDERS_ARTWORK("wireless-orders-artwork"), @@ -306,29 +388,53 @@ public enum Category { WIRELESS_USAGE_COMMANDS("wireless-usage-commands"), WIRELESS_USAGE_COMMANDS_AFRICA("wireless-usage-commands-africa"), WIRELESS_USAGE_COMMANDS_ASIA("wireless-usage-commands-asia"), - WIRELESS_USAGE_COMMANDS_CENTRALANDSOUTHAMERICA("wireless-usage-commands-centralandsouthamerica"), + WIRELESS_USAGE_COMMANDS_CENTRALANDSOUTHAMERICA( + "wireless-usage-commands-centralandsouthamerica" + ), WIRELESS_USAGE_COMMANDS_EUROPE("wireless-usage-commands-europe"), WIRELESS_USAGE_COMMANDS_HOME("wireless-usage-commands-home"), - WIRELESS_USAGE_COMMANDS_NORTHAMERICA("wireless-usage-commands-northamerica"), + WIRELESS_USAGE_COMMANDS_NORTHAMERICA( + "wireless-usage-commands-northamerica" + ), WIRELESS_USAGE_COMMANDS_OCEANIA("wireless-usage-commands-oceania"), WIRELESS_USAGE_COMMANDS_ROAMING("wireless-usage-commands-roaming"), WIRELESS_USAGE_DATA("wireless-usage-data"), WIRELESS_USAGE_DATA_AFRICA("wireless-usage-data-africa"), WIRELESS_USAGE_DATA_ASIA("wireless-usage-data-asia"), - WIRELESS_USAGE_DATA_CENTRALANDSOUTHAMERICA("wireless-usage-data-centralandsouthamerica"), - WIRELESS_USAGE_DATA_CUSTOM_ADDITIONALMB("wireless-usage-data-custom-additionalmb"), - WIRELESS_USAGE_DATA_CUSTOM_FIRST5MB("wireless-usage-data-custom-first5mb"), - WIRELESS_USAGE_DATA_DOMESTIC_ROAMING("wireless-usage-data-domestic-roaming"), + WIRELESS_USAGE_DATA_CENTRALANDSOUTHAMERICA( + "wireless-usage-data-centralandsouthamerica" + ), + WIRELESS_USAGE_DATA_CUSTOM_ADDITIONALMB( + "wireless-usage-data-custom-additionalmb" + ), + WIRELESS_USAGE_DATA_CUSTOM_FIRST5MB( + "wireless-usage-data-custom-first5mb" + ), + WIRELESS_USAGE_DATA_DOMESTIC_ROAMING( + "wireless-usage-data-domestic-roaming" + ), WIRELESS_USAGE_DATA_EUROPE("wireless-usage-data-europe"), - WIRELESS_USAGE_DATA_INDIVIDUAL_ADDITIONALGB("wireless-usage-data-individual-additionalgb"), - WIRELESS_USAGE_DATA_INDIVIDUAL_FIRSTGB("wireless-usage-data-individual-firstgb"), - WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_CANADA("wireless-usage-data-international-roaming-canada"), - WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_INDIA("wireless-usage-data-international-roaming-india"), - WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_MEXICO("wireless-usage-data-international-roaming-mexico"), + WIRELESS_USAGE_DATA_INDIVIDUAL_ADDITIONALGB( + "wireless-usage-data-individual-additionalgb" + ), + WIRELESS_USAGE_DATA_INDIVIDUAL_FIRSTGB( + "wireless-usage-data-individual-firstgb" + ), + WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_CANADA( + "wireless-usage-data-international-roaming-canada" + ), + WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_INDIA( + "wireless-usage-data-international-roaming-india" + ), + WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_MEXICO( + "wireless-usage-data-international-roaming-mexico" + ), WIRELESS_USAGE_DATA_NORTHAMERICA("wireless-usage-data-northamerica"), WIRELESS_USAGE_DATA_OCEANIA("wireless-usage-data-oceania"), WIRELESS_USAGE_DATA_POOLED("wireless-usage-data-pooled"), - WIRELESS_USAGE_DATA_POOLED_DOWNLINK("wireless-usage-data-pooled-downlink"), + WIRELESS_USAGE_DATA_POOLED_DOWNLINK( + "wireless-usage-data-pooled-downlink" + ), WIRELESS_USAGE_DATA_POOLED_UPLINK("wireless-usage-data-pooled-uplink"), WIRELESS_USAGE_MRC("wireless-usage-mrc"), WIRELESS_USAGE_MRC_CUSTOM("wireless-usage-mrc-custom"), @@ -372,51 +478,25 @@ public static Category forValue(final String value) { @JsonCreator private LastMonth( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("api_version") - final String apiVersion, - - @JsonProperty("as_of") - final String asOf, - - @JsonProperty("category") - final LastMonth.Category category, - - @JsonProperty("count") - final String count, - - @JsonProperty("count_unit") - final String countUnit, - - @JsonProperty("description") - final String description, - - @JsonProperty("end_date") - final String endDate, - - @JsonProperty("price") - final BigDecimal price, - - @JsonProperty("price_unit") - @JsonDeserialize(using = com.twilio.converter.CurrencyDeserializer.class) - final Currency priceUnit, - - @JsonProperty("start_date") - final String startDate, - - @JsonProperty("subresource_uris") - final Map subresourceUris, - - @JsonProperty("uri") - final String uri, - - @JsonProperty("usage") - final String usage, - - @JsonProperty("usage_unit") - final String usageUnit + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("api_version") final String apiVersion, + @JsonProperty("as_of") final String asOf, + @JsonProperty("category") final LastMonth.Category category, + @JsonProperty("count") final String count, + @JsonProperty("count_unit") final String countUnit, + @JsonProperty("description") final String description, + @JsonProperty("end_date") final String endDate, + @JsonProperty("price") final BigDecimal price, + @JsonProperty("price_unit") @JsonDeserialize( + using = com.twilio.converter.CurrencyDeserializer.class + ) final Currency priceUnit, + @JsonProperty("start_date") final String startDate, + @JsonProperty( + "subresource_uris" + ) final Map subresourceUris, + @JsonProperty("uri") final String uri, + @JsonProperty("usage") final String usage, + @JsonProperty("usage_unit") final String usageUnit ) { this.accountSid = accountSid; this.apiVersion = apiVersion; @@ -435,55 +515,69 @@ private LastMonth( this.usageUnit = usageUnit; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getApiVersion() { - return this.apiVersion; - } - public final String getAsOf() { - return this.asOf; - } - public final LastMonth.Category getCategory() { - return this.category; - } - public final String getCount() { - return this.count; - } - public final String getCountUnit() { - return this.countUnit; - } - public final String getDescription() { - return this.description; - } - public final LocalDate getEndDate() { - return this.endDate; - } - public final BigDecimal getPrice() { - return this.price; - } - public final Currency getPriceUnit() { - return this.priceUnit; - } - public final LocalDate getStartDate() { - return this.startDate; - } - public final Map getSubresourceUris() { - return this.subresourceUris; - } - public final String getUri() { - return this.uri; - } - public final String getUsage() { - return this.usage; - } - public final String getUsageUnit() { - return this.usageUnit; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getApiVersion() { + return this.apiVersion; + } + + public final String getAsOf() { + return this.asOf; + } + + public final LastMonth.Category getCategory() { + return this.category; + } + + public final String getCount() { + return this.count; + } + + public final String getCountUnit() { + return this.countUnit; + } + + public final String getDescription() { + return this.description; + } + + public final LocalDate getEndDate() { + return this.endDate; + } + + public final BigDecimal getPrice() { + return this.price; + } + + public final Currency getPriceUnit() { + return this.priceUnit; + } + + public final LocalDate getStartDate() { + return this.startDate; + } + + public final Map getSubresourceUris() { + return this.subresourceUris; + } + + public final String getUri() { + return this.uri; + } + + public final String getUsage() { + return this.usage; + } + + public final String getUsageUnit() { + return this.usageUnit; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -493,13 +587,43 @@ public boolean equals(final Object o) { LastMonth other = (LastMonth) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(apiVersion, other.apiVersion) && Objects.equals(asOf, other.asOf) && Objects.equals(category, other.category) && Objects.equals(count, other.count) && Objects.equals(countUnit, other.countUnit) && Objects.equals(description, other.description) && Objects.equals(endDate, other.endDate) && Objects.equals(price, other.price) && Objects.equals(priceUnit, other.priceUnit) && Objects.equals(startDate, other.startDate) && Objects.equals(subresourceUris, other.subresourceUris) && Objects.equals(uri, other.uri) && Objects.equals(usage, other.usage) && Objects.equals(usageUnit, other.usageUnit) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(apiVersion, other.apiVersion) && + Objects.equals(asOf, other.asOf) && + Objects.equals(category, other.category) && + Objects.equals(count, other.count) && + Objects.equals(countUnit, other.countUnit) && + Objects.equals(description, other.description) && + Objects.equals(endDate, other.endDate) && + Objects.equals(price, other.price) && + Objects.equals(priceUnit, other.priceUnit) && + Objects.equals(startDate, other.startDate) && + Objects.equals(subresourceUris, other.subresourceUris) && + Objects.equals(uri, other.uri) && + Objects.equals(usage, other.usage) && + Objects.equals(usageUnit, other.usageUnit) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, apiVersion, asOf, category, count, countUnit, description, endDate, price, priceUnit, startDate, subresourceUris, uri, usage, usageUnit); + return Objects.hash( + accountSid, + apiVersion, + asOf, + category, + count, + countUnit, + description, + endDate, + price, + priceUnit, + startDate, + subresourceUris, + uri, + usage, + usageUnit + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/LastMonthReader.java b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/LastMonthReader.java index 1edfaa150a..991cf739eb 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/LastMonthReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/LastMonthReader.java @@ -14,8 +14,10 @@ package com.twilio.rest.api.v2010.account.usage.record; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,13 +26,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; import java.time.LocalDate; -import com.twilio.converter.DateConverter; - - public class LastMonthReader extends Reader { + private String pathAccountSid; private LastMonth.Category category; private LocalDate startDate; @@ -38,29 +37,35 @@ public class LastMonthReader extends Reader { private Boolean includeSubaccounts; private Integer pageSize; - public LastMonthReader(){ - } - public LastMonthReader(final String pathAccountSid){ + public LastMonthReader() {} + + public LastMonthReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - public LastMonthReader setCategory(final LastMonth.Category category){ + public LastMonthReader setCategory(final LastMonth.Category category) { this.category = category; return this; } - public LastMonthReader setStartDate(final LocalDate startDate){ + + public LastMonthReader setStartDate(final LocalDate startDate) { this.startDate = startDate; return this; } - public LastMonthReader setEndDate(final LocalDate endDate){ + + public LastMonthReader setEndDate(final LocalDate endDate) { this.endDate = endDate; return this; } - public LastMonthReader setIncludeSubaccounts(final Boolean includeSubaccounts){ + + public LastMonthReader setIncludeSubaccounts( + final Boolean includeSubaccounts + ) { this.includeSubaccounts = includeSubaccounts; return this; } - public LastMonthReader setPageSize(final Integer pageSize){ + + public LastMonthReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -71,9 +76,17 @@ public ResourceSet read(final TwilioRestClient client) { } public Page firstPage(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/Usage/Records/LastMonth.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); + String path = + "/2010-04-01/Accounts/{AccountSid}/Usage/Records/LastMonth.json"; + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -85,13 +98,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("LastMonth read failed: Unable to connect to server"); + throw new ApiConnectionException( + "LastMonth read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -107,7 +128,10 @@ private Page pageForRequest(final TwilioRestClient client, final Requ } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.API.toString()) @@ -115,9 +139,11 @@ public Page previousPage(final Page page, final TwilioRest return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.API.toString()) @@ -126,37 +152,44 @@ public Page nextPage(final Page page, final TwilioRestClie } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (category != null) { - request.addQueryParam("Category", category.toString()); } if (startDate != null) { - request.addQueryParam("StartDate", DateConverter.dateStringFromLocalDate(startDate)); + request.addQueryParam( + "StartDate", + DateConverter.dateStringFromLocalDate(startDate) + ); } if (endDate != null) { - request.addQueryParam("EndDate", DateConverter.dateStringFromLocalDate(endDate)); + request.addQueryParam( + "EndDate", + DateConverter.dateStringFromLocalDate(endDate) + ); } if (includeSubaccounts != null) { - - request.addQueryParam("IncludeSubaccounts", includeSubaccounts.toString()); + request.addQueryParam( + "IncludeSubaccounts", + includeSubaccounts.toString() + ); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/Monthly.java b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/Monthly.java index 381e059bf5..b9c9291424 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/Monthly.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/Monthly.java @@ -20,49 +20,49 @@ import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.twilio.base.Resource; -import java.util.Currency; +import com.twilio.converter.CurrencyDeserializer; import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; -import com.twilio.converter.CurrencyDeserializer; import com.twilio.exception.ApiConnectionException; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; - +import java.math.BigDecimal; +import java.time.LocalDate; +import java.util.Currency; import java.util.Map; -import java.util.Objects; - - import java.util.Map; -import java.time.LocalDate; -import java.math.BigDecimal; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Monthly extends Resource { + private static final long serialVersionUID = 22373500842023L; - public static MonthlyReader reader(){ + public static MonthlyReader reader() { return new MonthlyReader(); } - public static MonthlyReader reader(final String pathAccountSid){ + + public static MonthlyReader reader(final String pathAccountSid) { return new MonthlyReader(pathAccountSid); } /** - * Converts a JSON String into a Monthly object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Monthly object represented by the provided JSON - */ - public static Monthly fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Monthly object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Monthly object represented by the provided JSON + */ + public static Monthly fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Monthly.class); @@ -74,14 +74,17 @@ public static Monthly fromJson(final String json, final ObjectMapper objectMappe } /** - * Converts a JSON InputStream into a Monthly object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Monthly object represented by the provided JSON - */ - public static Monthly fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Monthly object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Monthly object represented by the provided JSON + */ + public static Monthly fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Monthly.class); @@ -91,6 +94,7 @@ public static Monthly fromJson(final InputStream json, final ObjectMapper object throw new ApiConnectionException(e.getMessage(), e); } } + public enum Category { A2P_REGISTRATION_FEES("a2p-registration-fees"), AGENT_CONFERENCE("agent-conference"), @@ -122,7 +126,9 @@ public enum Category { CONVERSATIONS("conversations"), CONVERSATIONS_API_REQUESTS("conversations-api-requests"), CONVERSATIONS_CONVERSATION_EVENTS("conversations-conversation-events"), - CONVERSATIONS_ENDPOINT_CONNECTIVITY("conversations-endpoint-connectivity"), + CONVERSATIONS_ENDPOINT_CONNECTIVITY( + "conversations-endpoint-connectivity" + ), CONVERSATIONS_EVENTS("conversations-events"), CONVERSATIONS_PARTICIPANT_EVENTS("conversations-participant-events"), CONVERSATIONS_PARTICIPANTS("conversations-participants"), @@ -131,7 +137,9 @@ public enum Category { FRAUD_LOOKUPS("fraud-lookups"), GROUP_ROOMS("group-rooms"), GROUP_ROOMS_DATA_TRACK("group-rooms-data-track"), - GROUP_ROOMS_ENCRYPTED_MEDIA_RECORDED("group-rooms-encrypted-media-recorded"), + GROUP_ROOMS_ENCRYPTED_MEDIA_RECORDED( + "group-rooms-encrypted-media-recorded" + ), GROUP_ROOMS_MEDIA_DOWNLOADED("group-rooms-media-downloaded"), GROUP_ROOMS_MEDIA_RECORDED("group-rooms-media-recorded"), GROUP_ROOMS_MEDIA_ROUTED("group-rooms-media-routed"), @@ -141,45 +149,99 @@ public enum Category { IMP_V1_USAGE("imp-v1-usage"), LOOKUPS("lookups"), MARKETPLACE("marketplace"), - MARKETPLACE_ALGORITHMIA_NAMED_ENTITY_RECOGNITION("marketplace-algorithmia-named-entity-recognition"), + MARKETPLACE_ALGORITHMIA_NAMED_ENTITY_RECOGNITION( + "marketplace-algorithmia-named-entity-recognition" + ), MARKETPLACE_CADENCE_TRANSCRIPTION("marketplace-cadence-transcription"), MARKETPLACE_CADENCE_TRANSLATION("marketplace-cadence-translation"), MARKETPLACE_CAPIO_SPEECH_TO_TEXT("marketplace-capio-speech-to-text"), MARKETPLACE_CONVRIZA_ABABA("marketplace-convriza-ababa"), - MARKETPLACE_DEEPGRAM_PHRASE_DETECTOR("marketplace-deepgram-phrase-detector"), - MARKETPLACE_DIGITAL_SEGMENT_BUSINESS_INFO("marketplace-digital-segment-business-info"), - MARKETPLACE_FACEBOOK_OFFLINE_CONVERSIONS("marketplace-facebook-offline-conversions"), + MARKETPLACE_DEEPGRAM_PHRASE_DETECTOR( + "marketplace-deepgram-phrase-detector" + ), + MARKETPLACE_DIGITAL_SEGMENT_BUSINESS_INFO( + "marketplace-digital-segment-business-info" + ), + MARKETPLACE_FACEBOOK_OFFLINE_CONVERSIONS( + "marketplace-facebook-offline-conversions" + ), MARKETPLACE_GOOGLE_SPEECH_TO_TEXT("marketplace-google-speech-to-text"), - MARKETPLACE_IBM_WATSON_MESSAGE_INSIGHTS("marketplace-ibm-watson-message-insights"), - MARKETPLACE_IBM_WATSON_MESSAGE_SENTIMENT("marketplace-ibm-watson-message-sentiment"), - MARKETPLACE_IBM_WATSON_RECORDING_ANALYSIS("marketplace-ibm-watson-recording-analysis"), - MARKETPLACE_IBM_WATSON_TONE_ANALYZER("marketplace-ibm-watson-tone-analyzer"), + MARKETPLACE_IBM_WATSON_MESSAGE_INSIGHTS( + "marketplace-ibm-watson-message-insights" + ), + MARKETPLACE_IBM_WATSON_MESSAGE_SENTIMENT( + "marketplace-ibm-watson-message-sentiment" + ), + MARKETPLACE_IBM_WATSON_RECORDING_ANALYSIS( + "marketplace-ibm-watson-recording-analysis" + ), + MARKETPLACE_IBM_WATSON_TONE_ANALYZER( + "marketplace-ibm-watson-tone-analyzer" + ), MARKETPLACE_ICEHOOK_SYSTEMS_SCOUT("marketplace-icehook-systems-scout"), - MARKETPLACE_INFOGROUP_DATAAXLE_BIZINFO("marketplace-infogroup-dataaxle-bizinfo"), - MARKETPLACE_KEEN_IO_CONTACT_CENTER_ANALYTICS("marketplace-keen-io-contact-center-analytics"), + MARKETPLACE_INFOGROUP_DATAAXLE_BIZINFO( + "marketplace-infogroup-dataaxle-bizinfo" + ), + MARKETPLACE_KEEN_IO_CONTACT_CENTER_ANALYTICS( + "marketplace-keen-io-contact-center-analytics" + ), MARKETPLACE_MARCHEX_CLEANCALL("marketplace-marchex-cleancall"), - MARKETPLACE_MARCHEX_SENTIMENT_ANALYSIS_FOR_SMS("marketplace-marchex-sentiment-analysis-for-sms"), - MARKETPLACE_MARKETPLACE_NEXTCALLER_SOCIAL_ID("marketplace-marketplace-nextcaller-social-id"), - MARKETPLACE_MOBILE_COMMONS_OPT_OUT_CLASSIFIER("marketplace-mobile-commons-opt-out-classifier"), - MARKETPLACE_NEXIWAVE_VOICEMAIL_TO_TEXT("marketplace-nexiwave-voicemail-to-text"), - MARKETPLACE_NEXTCALLER_ADVANCED_CALLER_IDENTIFICATION("marketplace-nextcaller-advanced-caller-identification"), + MARKETPLACE_MARCHEX_SENTIMENT_ANALYSIS_FOR_SMS( + "marketplace-marchex-sentiment-analysis-for-sms" + ), + MARKETPLACE_MARKETPLACE_NEXTCALLER_SOCIAL_ID( + "marketplace-marketplace-nextcaller-social-id" + ), + MARKETPLACE_MOBILE_COMMONS_OPT_OUT_CLASSIFIER( + "marketplace-mobile-commons-opt-out-classifier" + ), + MARKETPLACE_NEXIWAVE_VOICEMAIL_TO_TEXT( + "marketplace-nexiwave-voicemail-to-text" + ), + MARKETPLACE_NEXTCALLER_ADVANCED_CALLER_IDENTIFICATION( + "marketplace-nextcaller-advanced-caller-identification" + ), MARKETPLACE_NOMOROBO_SPAM_SCORE("marketplace-nomorobo-spam-score"), - MARKETPLACE_PAYFONE_TCPA_COMPLIANCE("marketplace-payfone-tcpa-compliance"), - MARKETPLACE_REMEETING_AUTOMATIC_SPEECH_RECOGNITION("marketplace-remeeting-automatic-speech-recognition"), - MARKETPLACE_TCPA_DEFENSE_SOLUTIONS_BLACKLIST_FEED("marketplace-tcpa-defense-solutions-blacklist-feed"), + MARKETPLACE_PAYFONE_TCPA_COMPLIANCE( + "marketplace-payfone-tcpa-compliance" + ), + MARKETPLACE_REMEETING_AUTOMATIC_SPEECH_RECOGNITION( + "marketplace-remeeting-automatic-speech-recognition" + ), + MARKETPLACE_TCPA_DEFENSE_SOLUTIONS_BLACKLIST_FEED( + "marketplace-tcpa-defense-solutions-blacklist-feed" + ), MARKETPLACE_TELO_OPENCNAM("marketplace-telo-opencnam"), MARKETPLACE_TRUECNAM_TRUE_SPAM("marketplace-truecnam-true-spam"), - MARKETPLACE_TWILIO_CALLER_NAME_LOOKUP_US("marketplace-twilio-caller-name-lookup-us"), - MARKETPLACE_TWILIO_CARRIER_INFORMATION_LOOKUP("marketplace-twilio-carrier-information-lookup"), + MARKETPLACE_TWILIO_CALLER_NAME_LOOKUP_US( + "marketplace-twilio-caller-name-lookup-us" + ), + MARKETPLACE_TWILIO_CARRIER_INFORMATION_LOOKUP( + "marketplace-twilio-carrier-information-lookup" + ), MARKETPLACE_VOICEBASE_PCI("marketplace-voicebase-pci"), - MARKETPLACE_VOICEBASE_TRANSCRIPTION("marketplace-voicebase-transcription"), - MARKETPLACE_VOICEBASE_TRANSCRIPTION_CUSTOM_VOCABULARY("marketplace-voicebase-transcription-custom-vocabulary"), - MARKETPLACE_WHITEPAGES_PRO_CALLER_IDENTIFICATION("marketplace-whitepages-pro-caller-identification"), - MARKETPLACE_WHITEPAGES_PRO_PHONE_INTELLIGENCE("marketplace-whitepages-pro-phone-intelligence"), - MARKETPLACE_WHITEPAGES_PRO_PHONE_REPUTATION("marketplace-whitepages-pro-phone-reputation"), - MARKETPLACE_WOLFARM_SPOKEN_RESULTS("marketplace-wolfarm-spoken-results"), + MARKETPLACE_VOICEBASE_TRANSCRIPTION( + "marketplace-voicebase-transcription" + ), + MARKETPLACE_VOICEBASE_TRANSCRIPTION_CUSTOM_VOCABULARY( + "marketplace-voicebase-transcription-custom-vocabulary" + ), + MARKETPLACE_WHITEPAGES_PRO_CALLER_IDENTIFICATION( + "marketplace-whitepages-pro-caller-identification" + ), + MARKETPLACE_WHITEPAGES_PRO_PHONE_INTELLIGENCE( + "marketplace-whitepages-pro-phone-intelligence" + ), + MARKETPLACE_WHITEPAGES_PRO_PHONE_REPUTATION( + "marketplace-whitepages-pro-phone-reputation" + ), + MARKETPLACE_WOLFARM_SPOKEN_RESULTS( + "marketplace-wolfarm-spoken-results" + ), MARKETPLACE_WOLFRAM_SHORT_ANSWER("marketplace-wolfram-short-answer"), - MARKETPLACE_YTICA_CONTACT_CENTER_REPORTING_ANALYTICS("marketplace-ytica-contact-center-reporting-analytics"), + MARKETPLACE_YTICA_CONTACT_CENTER_REPORTING_ANALYTICS( + "marketplace-ytica-contact-center-reporting-analytics" + ), MEDIASTORAGE("mediastorage"), MMS("mms"), MMS_INBOUND("mms-inbound"), @@ -198,7 +260,9 @@ public enum Category { NUMBER_FORMAT_LOOKUPS("number-format-lookups"), PCHAT("pchat"), PCHAT_USERS("pchat-users"), - PEER_TO_PEER_ROOMS_PARTICIPANT_MINUTES("peer-to-peer-rooms-participant-minutes"), + PEER_TO_PEER_ROOMS_PARTICIPANT_MINUTES( + "peer-to-peer-rooms-participant-minutes" + ), PFAX("pfax"), PFAX_MINUTES("pfax-minutes"), PFAX_MINUTES_INBOUND("pfax-minutes-inbound"), @@ -245,7 +309,9 @@ public enum Category { SHORTCODES_VANITY("shortcodes-vanity"), SMALL_GROUP_ROOMS("small-group-rooms"), SMALL_GROUP_ROOMS_DATA_TRACK("small-group-rooms-data-track"), - SMALL_GROUP_ROOMS_PARTICIPANT_MINUTES("small-group-rooms-participant-minutes"), + SMALL_GROUP_ROOMS_PARTICIPANT_MINUTES( + "small-group-rooms-participant-minutes" + ), SMS("sms"), SMS_INBOUND("sms-inbound"), SMS_INBOUND_LONGCODE("sms-inbound-longcode"), @@ -262,7 +328,9 @@ public enum Category { SYNC("sync"), SYNC_ACTIONS("sync-actions"), SYNC_ENDPOINT_HOURS("sync-endpoint-hours"), - SYNC_ENDPOINT_HOURS_ABOVE_DAILY_CAP("sync-endpoint-hours-above-daily-cap"), + SYNC_ENDPOINT_HOURS_ABOVE_DAILY_CAP( + "sync-endpoint-hours-above-daily-cap" + ), TASKROUTER_TASKS("taskrouter-tasks"), TOTALPRICE("totalprice"), TRANSCRIPTIONS("transcriptions"), @@ -275,6 +343,7 @@ public enum Category { TRUNKING_RECORDINGS("trunking-recordings"), TRUNKING_SECURE("trunking-secure"), TRUNKING_TERMINATION("trunking-termination"), + TTS_GOOGLE("tts-google"), TURNMEGABYTES("turnmegabytes"), TURNMEGABYTES_AUSTRALIA("turnmegabytes-australia"), TURNMEGABYTES_BRASIL("turnmegabytes-brasil"), @@ -288,14 +357,27 @@ public enum Category { TWILIO_INTERCONNECT("twilio-interconnect"), VERIFY_PUSH("verify-push"), VERIFY_TOTP("verify-totp"), - VERIFY_WHATSAPP_CONVERSATIONS_BUSINESS_INITIATED("verify-whatsapp-conversations-business-initiated"), + VERIFY_WHATSAPP_CONVERSATIONS_BUSINESS_INITIATED( + "verify-whatsapp-conversations-business-initiated" + ), VIDEO_RECORDINGS("video-recordings"), VIRTUAL_AGENT("virtual-agent"), VOICE_INSIGHTS("voice-insights"), - VOICE_INSIGHTS_CLIENT_INSIGHTS_ON_DEMAND_MINUTE("voice-insights-client-insights-on-demand-minute"), - VOICE_INSIGHTS_PTSN_INSIGHTS_ON_DEMAND_MINUTE("voice-insights-ptsn-insights-on-demand-minute"), - VOICE_INSIGHTS_SIP_INTERFACE_INSIGHTS_ON_DEMAND_MINUTE("voice-insights-sip-interface-insights-on-demand-minute"), - VOICE_INSIGHTS_SIP_TRUNKING_INSIGHTS_ON_DEMAND_MINUTE("voice-insights-sip-trunking-insights-on-demand-minute"), + VOICE_INSIGHTS_CLIENT_INSIGHTS_ON_DEMAND_MINUTE( + "voice-insights-client-insights-on-demand-minute" + ), + VOICE_INSIGHTS_PTSN_INSIGHTS_ON_DEMAND_MINUTE( + "voice-insights-ptsn-insights-on-demand-minute" + ), + VOICE_INSIGHTS_SIP_INTERFACE_INSIGHTS_ON_DEMAND_MINUTE( + "voice-insights-sip-interface-insights-on-demand-minute" + ), + VOICE_INSIGHTS_SIP_TRUNKING_INSIGHTS_ON_DEMAND_MINUTE( + "voice-insights-sip-trunking-insights-on-demand-minute" + ), + VOICE_INTELLIGENCE("voice-intelligence"), + VOICE_INTELLIGENCE_TRANSCRIPTION("voice-intelligence-transcription"), + VOICE_INTELLIGENCE_OPERATORS("voice-intelligence-operators"), WIRELESS("wireless"), WIRELESS_ORDERS("wireless-orders"), WIRELESS_ORDERS_ARTWORK("wireless-orders-artwork"), @@ -306,29 +388,53 @@ public enum Category { WIRELESS_USAGE_COMMANDS("wireless-usage-commands"), WIRELESS_USAGE_COMMANDS_AFRICA("wireless-usage-commands-africa"), WIRELESS_USAGE_COMMANDS_ASIA("wireless-usage-commands-asia"), - WIRELESS_USAGE_COMMANDS_CENTRALANDSOUTHAMERICA("wireless-usage-commands-centralandsouthamerica"), + WIRELESS_USAGE_COMMANDS_CENTRALANDSOUTHAMERICA( + "wireless-usage-commands-centralandsouthamerica" + ), WIRELESS_USAGE_COMMANDS_EUROPE("wireless-usage-commands-europe"), WIRELESS_USAGE_COMMANDS_HOME("wireless-usage-commands-home"), - WIRELESS_USAGE_COMMANDS_NORTHAMERICA("wireless-usage-commands-northamerica"), + WIRELESS_USAGE_COMMANDS_NORTHAMERICA( + "wireless-usage-commands-northamerica" + ), WIRELESS_USAGE_COMMANDS_OCEANIA("wireless-usage-commands-oceania"), WIRELESS_USAGE_COMMANDS_ROAMING("wireless-usage-commands-roaming"), WIRELESS_USAGE_DATA("wireless-usage-data"), WIRELESS_USAGE_DATA_AFRICA("wireless-usage-data-africa"), WIRELESS_USAGE_DATA_ASIA("wireless-usage-data-asia"), - WIRELESS_USAGE_DATA_CENTRALANDSOUTHAMERICA("wireless-usage-data-centralandsouthamerica"), - WIRELESS_USAGE_DATA_CUSTOM_ADDITIONALMB("wireless-usage-data-custom-additionalmb"), - WIRELESS_USAGE_DATA_CUSTOM_FIRST5MB("wireless-usage-data-custom-first5mb"), - WIRELESS_USAGE_DATA_DOMESTIC_ROAMING("wireless-usage-data-domestic-roaming"), + WIRELESS_USAGE_DATA_CENTRALANDSOUTHAMERICA( + "wireless-usage-data-centralandsouthamerica" + ), + WIRELESS_USAGE_DATA_CUSTOM_ADDITIONALMB( + "wireless-usage-data-custom-additionalmb" + ), + WIRELESS_USAGE_DATA_CUSTOM_FIRST5MB( + "wireless-usage-data-custom-first5mb" + ), + WIRELESS_USAGE_DATA_DOMESTIC_ROAMING( + "wireless-usage-data-domestic-roaming" + ), WIRELESS_USAGE_DATA_EUROPE("wireless-usage-data-europe"), - WIRELESS_USAGE_DATA_INDIVIDUAL_ADDITIONALGB("wireless-usage-data-individual-additionalgb"), - WIRELESS_USAGE_DATA_INDIVIDUAL_FIRSTGB("wireless-usage-data-individual-firstgb"), - WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_CANADA("wireless-usage-data-international-roaming-canada"), - WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_INDIA("wireless-usage-data-international-roaming-india"), - WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_MEXICO("wireless-usage-data-international-roaming-mexico"), + WIRELESS_USAGE_DATA_INDIVIDUAL_ADDITIONALGB( + "wireless-usage-data-individual-additionalgb" + ), + WIRELESS_USAGE_DATA_INDIVIDUAL_FIRSTGB( + "wireless-usage-data-individual-firstgb" + ), + WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_CANADA( + "wireless-usage-data-international-roaming-canada" + ), + WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_INDIA( + "wireless-usage-data-international-roaming-india" + ), + WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_MEXICO( + "wireless-usage-data-international-roaming-mexico" + ), WIRELESS_USAGE_DATA_NORTHAMERICA("wireless-usage-data-northamerica"), WIRELESS_USAGE_DATA_OCEANIA("wireless-usage-data-oceania"), WIRELESS_USAGE_DATA_POOLED("wireless-usage-data-pooled"), - WIRELESS_USAGE_DATA_POOLED_DOWNLINK("wireless-usage-data-pooled-downlink"), + WIRELESS_USAGE_DATA_POOLED_DOWNLINK( + "wireless-usage-data-pooled-downlink" + ), WIRELESS_USAGE_DATA_POOLED_UPLINK("wireless-usage-data-pooled-uplink"), WIRELESS_USAGE_MRC("wireless-usage-mrc"), WIRELESS_USAGE_MRC_CUSTOM("wireless-usage-mrc-custom"), @@ -372,51 +478,25 @@ public static Category forValue(final String value) { @JsonCreator private Monthly( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("api_version") - final String apiVersion, - - @JsonProperty("as_of") - final String asOf, - - @JsonProperty("category") - final Monthly.Category category, - - @JsonProperty("count") - final String count, - - @JsonProperty("count_unit") - final String countUnit, - - @JsonProperty("description") - final String description, - - @JsonProperty("end_date") - final String endDate, - - @JsonProperty("price") - final BigDecimal price, - - @JsonProperty("price_unit") - @JsonDeserialize(using = com.twilio.converter.CurrencyDeserializer.class) - final Currency priceUnit, - - @JsonProperty("start_date") - final String startDate, - - @JsonProperty("subresource_uris") - final Map subresourceUris, - - @JsonProperty("uri") - final String uri, - - @JsonProperty("usage") - final String usage, - - @JsonProperty("usage_unit") - final String usageUnit + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("api_version") final String apiVersion, + @JsonProperty("as_of") final String asOf, + @JsonProperty("category") final Monthly.Category category, + @JsonProperty("count") final String count, + @JsonProperty("count_unit") final String countUnit, + @JsonProperty("description") final String description, + @JsonProperty("end_date") final String endDate, + @JsonProperty("price") final BigDecimal price, + @JsonProperty("price_unit") @JsonDeserialize( + using = com.twilio.converter.CurrencyDeserializer.class + ) final Currency priceUnit, + @JsonProperty("start_date") final String startDate, + @JsonProperty( + "subresource_uris" + ) final Map subresourceUris, + @JsonProperty("uri") final String uri, + @JsonProperty("usage") final String usage, + @JsonProperty("usage_unit") final String usageUnit ) { this.accountSid = accountSid; this.apiVersion = apiVersion; @@ -435,55 +515,69 @@ private Monthly( this.usageUnit = usageUnit; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getApiVersion() { - return this.apiVersion; - } - public final String getAsOf() { - return this.asOf; - } - public final Monthly.Category getCategory() { - return this.category; - } - public final String getCount() { - return this.count; - } - public final String getCountUnit() { - return this.countUnit; - } - public final String getDescription() { - return this.description; - } - public final LocalDate getEndDate() { - return this.endDate; - } - public final BigDecimal getPrice() { - return this.price; - } - public final Currency getPriceUnit() { - return this.priceUnit; - } - public final LocalDate getStartDate() { - return this.startDate; - } - public final Map getSubresourceUris() { - return this.subresourceUris; - } - public final String getUri() { - return this.uri; - } - public final String getUsage() { - return this.usage; - } - public final String getUsageUnit() { - return this.usageUnit; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getApiVersion() { + return this.apiVersion; + } + + public final String getAsOf() { + return this.asOf; + } + + public final Monthly.Category getCategory() { + return this.category; + } + + public final String getCount() { + return this.count; + } + + public final String getCountUnit() { + return this.countUnit; + } + + public final String getDescription() { + return this.description; + } + + public final LocalDate getEndDate() { + return this.endDate; + } + + public final BigDecimal getPrice() { + return this.price; + } + + public final Currency getPriceUnit() { + return this.priceUnit; + } + + public final LocalDate getStartDate() { + return this.startDate; + } + + public final Map getSubresourceUris() { + return this.subresourceUris; + } + + public final String getUri() { + return this.uri; + } + + public final String getUsage() { + return this.usage; + } + + public final String getUsageUnit() { + return this.usageUnit; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -493,13 +587,43 @@ public boolean equals(final Object o) { Monthly other = (Monthly) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(apiVersion, other.apiVersion) && Objects.equals(asOf, other.asOf) && Objects.equals(category, other.category) && Objects.equals(count, other.count) && Objects.equals(countUnit, other.countUnit) && Objects.equals(description, other.description) && Objects.equals(endDate, other.endDate) && Objects.equals(price, other.price) && Objects.equals(priceUnit, other.priceUnit) && Objects.equals(startDate, other.startDate) && Objects.equals(subresourceUris, other.subresourceUris) && Objects.equals(uri, other.uri) && Objects.equals(usage, other.usage) && Objects.equals(usageUnit, other.usageUnit) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(apiVersion, other.apiVersion) && + Objects.equals(asOf, other.asOf) && + Objects.equals(category, other.category) && + Objects.equals(count, other.count) && + Objects.equals(countUnit, other.countUnit) && + Objects.equals(description, other.description) && + Objects.equals(endDate, other.endDate) && + Objects.equals(price, other.price) && + Objects.equals(priceUnit, other.priceUnit) && + Objects.equals(startDate, other.startDate) && + Objects.equals(subresourceUris, other.subresourceUris) && + Objects.equals(uri, other.uri) && + Objects.equals(usage, other.usage) && + Objects.equals(usageUnit, other.usageUnit) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, apiVersion, asOf, category, count, countUnit, description, endDate, price, priceUnit, startDate, subresourceUris, uri, usage, usageUnit); + return Objects.hash( + accountSid, + apiVersion, + asOf, + category, + count, + countUnit, + description, + endDate, + price, + priceUnit, + startDate, + subresourceUris, + uri, + usage, + usageUnit + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/MonthlyReader.java b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/MonthlyReader.java index 4a67f6e911..41057a0eab 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/MonthlyReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/MonthlyReader.java @@ -14,8 +14,10 @@ package com.twilio.rest.api.v2010.account.usage.record; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,13 +26,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; import java.time.LocalDate; -import com.twilio.converter.DateConverter; - - public class MonthlyReader extends Reader { + private String pathAccountSid; private Monthly.Category category; private LocalDate startDate; @@ -38,29 +37,35 @@ public class MonthlyReader extends Reader { private Boolean includeSubaccounts; private Integer pageSize; - public MonthlyReader(){ - } - public MonthlyReader(final String pathAccountSid){ + public MonthlyReader() {} + + public MonthlyReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - public MonthlyReader setCategory(final Monthly.Category category){ + public MonthlyReader setCategory(final Monthly.Category category) { this.category = category; return this; } - public MonthlyReader setStartDate(final LocalDate startDate){ + + public MonthlyReader setStartDate(final LocalDate startDate) { this.startDate = startDate; return this; } - public MonthlyReader setEndDate(final LocalDate endDate){ + + public MonthlyReader setEndDate(final LocalDate endDate) { this.endDate = endDate; return this; } - public MonthlyReader setIncludeSubaccounts(final Boolean includeSubaccounts){ + + public MonthlyReader setIncludeSubaccounts( + final Boolean includeSubaccounts + ) { this.includeSubaccounts = includeSubaccounts; return this; } - public MonthlyReader setPageSize(final Integer pageSize){ + + public MonthlyReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -71,9 +76,17 @@ public ResourceSet read(final TwilioRestClient client) { } public Page firstPage(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/Usage/Records/Monthly.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); + String path = + "/2010-04-01/Accounts/{AccountSid}/Usage/Records/Monthly.json"; + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -85,13 +98,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Monthly read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Monthly read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -107,7 +128,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reques } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.API.toString()) @@ -115,9 +139,11 @@ public Page previousPage(final Page page, final TwilioRestClie return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.API.toString()) @@ -126,37 +152,44 @@ public Page nextPage(final Page page, final TwilioRestClient c } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (category != null) { - request.addQueryParam("Category", category.toString()); } if (startDate != null) { - request.addQueryParam("StartDate", DateConverter.dateStringFromLocalDate(startDate)); + request.addQueryParam( + "StartDate", + DateConverter.dateStringFromLocalDate(startDate) + ); } if (endDate != null) { - request.addQueryParam("EndDate", DateConverter.dateStringFromLocalDate(endDate)); + request.addQueryParam( + "EndDate", + DateConverter.dateStringFromLocalDate(endDate) + ); } if (includeSubaccounts != null) { - - request.addQueryParam("IncludeSubaccounts", includeSubaccounts.toString()); + request.addQueryParam( + "IncludeSubaccounts", + includeSubaccounts.toString() + ); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/ThisMonth.java b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/ThisMonth.java index 2c4e5bc97f..98337d0ed3 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/ThisMonth.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/ThisMonth.java @@ -20,49 +20,49 @@ import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.twilio.base.Resource; -import java.util.Currency; +import com.twilio.converter.CurrencyDeserializer; import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; -import com.twilio.converter.CurrencyDeserializer; import com.twilio.exception.ApiConnectionException; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; - +import java.math.BigDecimal; +import java.time.LocalDate; +import java.util.Currency; import java.util.Map; -import java.util.Objects; - - import java.util.Map; -import java.time.LocalDate; -import java.math.BigDecimal; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class ThisMonth extends Resource { + private static final long serialVersionUID = 273687321693897L; - public static ThisMonthReader reader(){ + public static ThisMonthReader reader() { return new ThisMonthReader(); } - public static ThisMonthReader reader(final String pathAccountSid){ + + public static ThisMonthReader reader(final String pathAccountSid) { return new ThisMonthReader(pathAccountSid); } /** - * Converts a JSON String into a ThisMonth object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return ThisMonth object represented by the provided JSON - */ - public static ThisMonth fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a ThisMonth object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return ThisMonth object represented by the provided JSON + */ + public static ThisMonth fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, ThisMonth.class); @@ -74,14 +74,17 @@ public static ThisMonth fromJson(final String json, final ObjectMapper objectMap } /** - * Converts a JSON InputStream into a ThisMonth object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return ThisMonth object represented by the provided JSON - */ - public static ThisMonth fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a ThisMonth object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return ThisMonth object represented by the provided JSON + */ + public static ThisMonth fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, ThisMonth.class); @@ -91,6 +94,7 @@ public static ThisMonth fromJson(final InputStream json, final ObjectMapper obje throw new ApiConnectionException(e.getMessage(), e); } } + public enum Category { A2P_REGISTRATION_FEES("a2p-registration-fees"), AGENT_CONFERENCE("agent-conference"), @@ -122,7 +126,9 @@ public enum Category { CONVERSATIONS("conversations"), CONVERSATIONS_API_REQUESTS("conversations-api-requests"), CONVERSATIONS_CONVERSATION_EVENTS("conversations-conversation-events"), - CONVERSATIONS_ENDPOINT_CONNECTIVITY("conversations-endpoint-connectivity"), + CONVERSATIONS_ENDPOINT_CONNECTIVITY( + "conversations-endpoint-connectivity" + ), CONVERSATIONS_EVENTS("conversations-events"), CONVERSATIONS_PARTICIPANT_EVENTS("conversations-participant-events"), CONVERSATIONS_PARTICIPANTS("conversations-participants"), @@ -131,7 +137,9 @@ public enum Category { FRAUD_LOOKUPS("fraud-lookups"), GROUP_ROOMS("group-rooms"), GROUP_ROOMS_DATA_TRACK("group-rooms-data-track"), - GROUP_ROOMS_ENCRYPTED_MEDIA_RECORDED("group-rooms-encrypted-media-recorded"), + GROUP_ROOMS_ENCRYPTED_MEDIA_RECORDED( + "group-rooms-encrypted-media-recorded" + ), GROUP_ROOMS_MEDIA_DOWNLOADED("group-rooms-media-downloaded"), GROUP_ROOMS_MEDIA_RECORDED("group-rooms-media-recorded"), GROUP_ROOMS_MEDIA_ROUTED("group-rooms-media-routed"), @@ -141,45 +149,99 @@ public enum Category { IMP_V1_USAGE("imp-v1-usage"), LOOKUPS("lookups"), MARKETPLACE("marketplace"), - MARKETPLACE_ALGORITHMIA_NAMED_ENTITY_RECOGNITION("marketplace-algorithmia-named-entity-recognition"), + MARKETPLACE_ALGORITHMIA_NAMED_ENTITY_RECOGNITION( + "marketplace-algorithmia-named-entity-recognition" + ), MARKETPLACE_CADENCE_TRANSCRIPTION("marketplace-cadence-transcription"), MARKETPLACE_CADENCE_TRANSLATION("marketplace-cadence-translation"), MARKETPLACE_CAPIO_SPEECH_TO_TEXT("marketplace-capio-speech-to-text"), MARKETPLACE_CONVRIZA_ABABA("marketplace-convriza-ababa"), - MARKETPLACE_DEEPGRAM_PHRASE_DETECTOR("marketplace-deepgram-phrase-detector"), - MARKETPLACE_DIGITAL_SEGMENT_BUSINESS_INFO("marketplace-digital-segment-business-info"), - MARKETPLACE_FACEBOOK_OFFLINE_CONVERSIONS("marketplace-facebook-offline-conversions"), + MARKETPLACE_DEEPGRAM_PHRASE_DETECTOR( + "marketplace-deepgram-phrase-detector" + ), + MARKETPLACE_DIGITAL_SEGMENT_BUSINESS_INFO( + "marketplace-digital-segment-business-info" + ), + MARKETPLACE_FACEBOOK_OFFLINE_CONVERSIONS( + "marketplace-facebook-offline-conversions" + ), MARKETPLACE_GOOGLE_SPEECH_TO_TEXT("marketplace-google-speech-to-text"), - MARKETPLACE_IBM_WATSON_MESSAGE_INSIGHTS("marketplace-ibm-watson-message-insights"), - MARKETPLACE_IBM_WATSON_MESSAGE_SENTIMENT("marketplace-ibm-watson-message-sentiment"), - MARKETPLACE_IBM_WATSON_RECORDING_ANALYSIS("marketplace-ibm-watson-recording-analysis"), - MARKETPLACE_IBM_WATSON_TONE_ANALYZER("marketplace-ibm-watson-tone-analyzer"), + MARKETPLACE_IBM_WATSON_MESSAGE_INSIGHTS( + "marketplace-ibm-watson-message-insights" + ), + MARKETPLACE_IBM_WATSON_MESSAGE_SENTIMENT( + "marketplace-ibm-watson-message-sentiment" + ), + MARKETPLACE_IBM_WATSON_RECORDING_ANALYSIS( + "marketplace-ibm-watson-recording-analysis" + ), + MARKETPLACE_IBM_WATSON_TONE_ANALYZER( + "marketplace-ibm-watson-tone-analyzer" + ), MARKETPLACE_ICEHOOK_SYSTEMS_SCOUT("marketplace-icehook-systems-scout"), - MARKETPLACE_INFOGROUP_DATAAXLE_BIZINFO("marketplace-infogroup-dataaxle-bizinfo"), - MARKETPLACE_KEEN_IO_CONTACT_CENTER_ANALYTICS("marketplace-keen-io-contact-center-analytics"), + MARKETPLACE_INFOGROUP_DATAAXLE_BIZINFO( + "marketplace-infogroup-dataaxle-bizinfo" + ), + MARKETPLACE_KEEN_IO_CONTACT_CENTER_ANALYTICS( + "marketplace-keen-io-contact-center-analytics" + ), MARKETPLACE_MARCHEX_CLEANCALL("marketplace-marchex-cleancall"), - MARKETPLACE_MARCHEX_SENTIMENT_ANALYSIS_FOR_SMS("marketplace-marchex-sentiment-analysis-for-sms"), - MARKETPLACE_MARKETPLACE_NEXTCALLER_SOCIAL_ID("marketplace-marketplace-nextcaller-social-id"), - MARKETPLACE_MOBILE_COMMONS_OPT_OUT_CLASSIFIER("marketplace-mobile-commons-opt-out-classifier"), - MARKETPLACE_NEXIWAVE_VOICEMAIL_TO_TEXT("marketplace-nexiwave-voicemail-to-text"), - MARKETPLACE_NEXTCALLER_ADVANCED_CALLER_IDENTIFICATION("marketplace-nextcaller-advanced-caller-identification"), + MARKETPLACE_MARCHEX_SENTIMENT_ANALYSIS_FOR_SMS( + "marketplace-marchex-sentiment-analysis-for-sms" + ), + MARKETPLACE_MARKETPLACE_NEXTCALLER_SOCIAL_ID( + "marketplace-marketplace-nextcaller-social-id" + ), + MARKETPLACE_MOBILE_COMMONS_OPT_OUT_CLASSIFIER( + "marketplace-mobile-commons-opt-out-classifier" + ), + MARKETPLACE_NEXIWAVE_VOICEMAIL_TO_TEXT( + "marketplace-nexiwave-voicemail-to-text" + ), + MARKETPLACE_NEXTCALLER_ADVANCED_CALLER_IDENTIFICATION( + "marketplace-nextcaller-advanced-caller-identification" + ), MARKETPLACE_NOMOROBO_SPAM_SCORE("marketplace-nomorobo-spam-score"), - MARKETPLACE_PAYFONE_TCPA_COMPLIANCE("marketplace-payfone-tcpa-compliance"), - MARKETPLACE_REMEETING_AUTOMATIC_SPEECH_RECOGNITION("marketplace-remeeting-automatic-speech-recognition"), - MARKETPLACE_TCPA_DEFENSE_SOLUTIONS_BLACKLIST_FEED("marketplace-tcpa-defense-solutions-blacklist-feed"), + MARKETPLACE_PAYFONE_TCPA_COMPLIANCE( + "marketplace-payfone-tcpa-compliance" + ), + MARKETPLACE_REMEETING_AUTOMATIC_SPEECH_RECOGNITION( + "marketplace-remeeting-automatic-speech-recognition" + ), + MARKETPLACE_TCPA_DEFENSE_SOLUTIONS_BLACKLIST_FEED( + "marketplace-tcpa-defense-solutions-blacklist-feed" + ), MARKETPLACE_TELO_OPENCNAM("marketplace-telo-opencnam"), MARKETPLACE_TRUECNAM_TRUE_SPAM("marketplace-truecnam-true-spam"), - MARKETPLACE_TWILIO_CALLER_NAME_LOOKUP_US("marketplace-twilio-caller-name-lookup-us"), - MARKETPLACE_TWILIO_CARRIER_INFORMATION_LOOKUP("marketplace-twilio-carrier-information-lookup"), + MARKETPLACE_TWILIO_CALLER_NAME_LOOKUP_US( + "marketplace-twilio-caller-name-lookup-us" + ), + MARKETPLACE_TWILIO_CARRIER_INFORMATION_LOOKUP( + "marketplace-twilio-carrier-information-lookup" + ), MARKETPLACE_VOICEBASE_PCI("marketplace-voicebase-pci"), - MARKETPLACE_VOICEBASE_TRANSCRIPTION("marketplace-voicebase-transcription"), - MARKETPLACE_VOICEBASE_TRANSCRIPTION_CUSTOM_VOCABULARY("marketplace-voicebase-transcription-custom-vocabulary"), - MARKETPLACE_WHITEPAGES_PRO_CALLER_IDENTIFICATION("marketplace-whitepages-pro-caller-identification"), - MARKETPLACE_WHITEPAGES_PRO_PHONE_INTELLIGENCE("marketplace-whitepages-pro-phone-intelligence"), - MARKETPLACE_WHITEPAGES_PRO_PHONE_REPUTATION("marketplace-whitepages-pro-phone-reputation"), - MARKETPLACE_WOLFARM_SPOKEN_RESULTS("marketplace-wolfarm-spoken-results"), + MARKETPLACE_VOICEBASE_TRANSCRIPTION( + "marketplace-voicebase-transcription" + ), + MARKETPLACE_VOICEBASE_TRANSCRIPTION_CUSTOM_VOCABULARY( + "marketplace-voicebase-transcription-custom-vocabulary" + ), + MARKETPLACE_WHITEPAGES_PRO_CALLER_IDENTIFICATION( + "marketplace-whitepages-pro-caller-identification" + ), + MARKETPLACE_WHITEPAGES_PRO_PHONE_INTELLIGENCE( + "marketplace-whitepages-pro-phone-intelligence" + ), + MARKETPLACE_WHITEPAGES_PRO_PHONE_REPUTATION( + "marketplace-whitepages-pro-phone-reputation" + ), + MARKETPLACE_WOLFARM_SPOKEN_RESULTS( + "marketplace-wolfarm-spoken-results" + ), MARKETPLACE_WOLFRAM_SHORT_ANSWER("marketplace-wolfram-short-answer"), - MARKETPLACE_YTICA_CONTACT_CENTER_REPORTING_ANALYTICS("marketplace-ytica-contact-center-reporting-analytics"), + MARKETPLACE_YTICA_CONTACT_CENTER_REPORTING_ANALYTICS( + "marketplace-ytica-contact-center-reporting-analytics" + ), MEDIASTORAGE("mediastorage"), MMS("mms"), MMS_INBOUND("mms-inbound"), @@ -198,7 +260,9 @@ public enum Category { NUMBER_FORMAT_LOOKUPS("number-format-lookups"), PCHAT("pchat"), PCHAT_USERS("pchat-users"), - PEER_TO_PEER_ROOMS_PARTICIPANT_MINUTES("peer-to-peer-rooms-participant-minutes"), + PEER_TO_PEER_ROOMS_PARTICIPANT_MINUTES( + "peer-to-peer-rooms-participant-minutes" + ), PFAX("pfax"), PFAX_MINUTES("pfax-minutes"), PFAX_MINUTES_INBOUND("pfax-minutes-inbound"), @@ -245,7 +309,9 @@ public enum Category { SHORTCODES_VANITY("shortcodes-vanity"), SMALL_GROUP_ROOMS("small-group-rooms"), SMALL_GROUP_ROOMS_DATA_TRACK("small-group-rooms-data-track"), - SMALL_GROUP_ROOMS_PARTICIPANT_MINUTES("small-group-rooms-participant-minutes"), + SMALL_GROUP_ROOMS_PARTICIPANT_MINUTES( + "small-group-rooms-participant-minutes" + ), SMS("sms"), SMS_INBOUND("sms-inbound"), SMS_INBOUND_LONGCODE("sms-inbound-longcode"), @@ -262,7 +328,9 @@ public enum Category { SYNC("sync"), SYNC_ACTIONS("sync-actions"), SYNC_ENDPOINT_HOURS("sync-endpoint-hours"), - SYNC_ENDPOINT_HOURS_ABOVE_DAILY_CAP("sync-endpoint-hours-above-daily-cap"), + SYNC_ENDPOINT_HOURS_ABOVE_DAILY_CAP( + "sync-endpoint-hours-above-daily-cap" + ), TASKROUTER_TASKS("taskrouter-tasks"), TOTALPRICE("totalprice"), TRANSCRIPTIONS("transcriptions"), @@ -275,6 +343,7 @@ public enum Category { TRUNKING_RECORDINGS("trunking-recordings"), TRUNKING_SECURE("trunking-secure"), TRUNKING_TERMINATION("trunking-termination"), + TTS_GOOGLE("tts-google"), TURNMEGABYTES("turnmegabytes"), TURNMEGABYTES_AUSTRALIA("turnmegabytes-australia"), TURNMEGABYTES_BRASIL("turnmegabytes-brasil"), @@ -288,14 +357,27 @@ public enum Category { TWILIO_INTERCONNECT("twilio-interconnect"), VERIFY_PUSH("verify-push"), VERIFY_TOTP("verify-totp"), - VERIFY_WHATSAPP_CONVERSATIONS_BUSINESS_INITIATED("verify-whatsapp-conversations-business-initiated"), + VERIFY_WHATSAPP_CONVERSATIONS_BUSINESS_INITIATED( + "verify-whatsapp-conversations-business-initiated" + ), VIDEO_RECORDINGS("video-recordings"), VIRTUAL_AGENT("virtual-agent"), VOICE_INSIGHTS("voice-insights"), - VOICE_INSIGHTS_CLIENT_INSIGHTS_ON_DEMAND_MINUTE("voice-insights-client-insights-on-demand-minute"), - VOICE_INSIGHTS_PTSN_INSIGHTS_ON_DEMAND_MINUTE("voice-insights-ptsn-insights-on-demand-minute"), - VOICE_INSIGHTS_SIP_INTERFACE_INSIGHTS_ON_DEMAND_MINUTE("voice-insights-sip-interface-insights-on-demand-minute"), - VOICE_INSIGHTS_SIP_TRUNKING_INSIGHTS_ON_DEMAND_MINUTE("voice-insights-sip-trunking-insights-on-demand-minute"), + VOICE_INSIGHTS_CLIENT_INSIGHTS_ON_DEMAND_MINUTE( + "voice-insights-client-insights-on-demand-minute" + ), + VOICE_INSIGHTS_PTSN_INSIGHTS_ON_DEMAND_MINUTE( + "voice-insights-ptsn-insights-on-demand-minute" + ), + VOICE_INSIGHTS_SIP_INTERFACE_INSIGHTS_ON_DEMAND_MINUTE( + "voice-insights-sip-interface-insights-on-demand-minute" + ), + VOICE_INSIGHTS_SIP_TRUNKING_INSIGHTS_ON_DEMAND_MINUTE( + "voice-insights-sip-trunking-insights-on-demand-minute" + ), + VOICE_INTELLIGENCE("voice-intelligence"), + VOICE_INTELLIGENCE_TRANSCRIPTION("voice-intelligence-transcription"), + VOICE_INTELLIGENCE_OPERATORS("voice-intelligence-operators"), WIRELESS("wireless"), WIRELESS_ORDERS("wireless-orders"), WIRELESS_ORDERS_ARTWORK("wireless-orders-artwork"), @@ -306,29 +388,53 @@ public enum Category { WIRELESS_USAGE_COMMANDS("wireless-usage-commands"), WIRELESS_USAGE_COMMANDS_AFRICA("wireless-usage-commands-africa"), WIRELESS_USAGE_COMMANDS_ASIA("wireless-usage-commands-asia"), - WIRELESS_USAGE_COMMANDS_CENTRALANDSOUTHAMERICA("wireless-usage-commands-centralandsouthamerica"), + WIRELESS_USAGE_COMMANDS_CENTRALANDSOUTHAMERICA( + "wireless-usage-commands-centralandsouthamerica" + ), WIRELESS_USAGE_COMMANDS_EUROPE("wireless-usage-commands-europe"), WIRELESS_USAGE_COMMANDS_HOME("wireless-usage-commands-home"), - WIRELESS_USAGE_COMMANDS_NORTHAMERICA("wireless-usage-commands-northamerica"), + WIRELESS_USAGE_COMMANDS_NORTHAMERICA( + "wireless-usage-commands-northamerica" + ), WIRELESS_USAGE_COMMANDS_OCEANIA("wireless-usage-commands-oceania"), WIRELESS_USAGE_COMMANDS_ROAMING("wireless-usage-commands-roaming"), WIRELESS_USAGE_DATA("wireless-usage-data"), WIRELESS_USAGE_DATA_AFRICA("wireless-usage-data-africa"), WIRELESS_USAGE_DATA_ASIA("wireless-usage-data-asia"), - WIRELESS_USAGE_DATA_CENTRALANDSOUTHAMERICA("wireless-usage-data-centralandsouthamerica"), - WIRELESS_USAGE_DATA_CUSTOM_ADDITIONALMB("wireless-usage-data-custom-additionalmb"), - WIRELESS_USAGE_DATA_CUSTOM_FIRST5MB("wireless-usage-data-custom-first5mb"), - WIRELESS_USAGE_DATA_DOMESTIC_ROAMING("wireless-usage-data-domestic-roaming"), + WIRELESS_USAGE_DATA_CENTRALANDSOUTHAMERICA( + "wireless-usage-data-centralandsouthamerica" + ), + WIRELESS_USAGE_DATA_CUSTOM_ADDITIONALMB( + "wireless-usage-data-custom-additionalmb" + ), + WIRELESS_USAGE_DATA_CUSTOM_FIRST5MB( + "wireless-usage-data-custom-first5mb" + ), + WIRELESS_USAGE_DATA_DOMESTIC_ROAMING( + "wireless-usage-data-domestic-roaming" + ), WIRELESS_USAGE_DATA_EUROPE("wireless-usage-data-europe"), - WIRELESS_USAGE_DATA_INDIVIDUAL_ADDITIONALGB("wireless-usage-data-individual-additionalgb"), - WIRELESS_USAGE_DATA_INDIVIDUAL_FIRSTGB("wireless-usage-data-individual-firstgb"), - WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_CANADA("wireless-usage-data-international-roaming-canada"), - WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_INDIA("wireless-usage-data-international-roaming-india"), - WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_MEXICO("wireless-usage-data-international-roaming-mexico"), + WIRELESS_USAGE_DATA_INDIVIDUAL_ADDITIONALGB( + "wireless-usage-data-individual-additionalgb" + ), + WIRELESS_USAGE_DATA_INDIVIDUAL_FIRSTGB( + "wireless-usage-data-individual-firstgb" + ), + WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_CANADA( + "wireless-usage-data-international-roaming-canada" + ), + WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_INDIA( + "wireless-usage-data-international-roaming-india" + ), + WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_MEXICO( + "wireless-usage-data-international-roaming-mexico" + ), WIRELESS_USAGE_DATA_NORTHAMERICA("wireless-usage-data-northamerica"), WIRELESS_USAGE_DATA_OCEANIA("wireless-usage-data-oceania"), WIRELESS_USAGE_DATA_POOLED("wireless-usage-data-pooled"), - WIRELESS_USAGE_DATA_POOLED_DOWNLINK("wireless-usage-data-pooled-downlink"), + WIRELESS_USAGE_DATA_POOLED_DOWNLINK( + "wireless-usage-data-pooled-downlink" + ), WIRELESS_USAGE_DATA_POOLED_UPLINK("wireless-usage-data-pooled-uplink"), WIRELESS_USAGE_MRC("wireless-usage-mrc"), WIRELESS_USAGE_MRC_CUSTOM("wireless-usage-mrc-custom"), @@ -372,51 +478,25 @@ public static Category forValue(final String value) { @JsonCreator private ThisMonth( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("api_version") - final String apiVersion, - - @JsonProperty("as_of") - final String asOf, - - @JsonProperty("category") - final ThisMonth.Category category, - - @JsonProperty("count") - final String count, - - @JsonProperty("count_unit") - final String countUnit, - - @JsonProperty("description") - final String description, - - @JsonProperty("end_date") - final String endDate, - - @JsonProperty("price") - final BigDecimal price, - - @JsonProperty("price_unit") - @JsonDeserialize(using = com.twilio.converter.CurrencyDeserializer.class) - final Currency priceUnit, - - @JsonProperty("start_date") - final String startDate, - - @JsonProperty("subresource_uris") - final Map subresourceUris, - - @JsonProperty("uri") - final String uri, - - @JsonProperty("usage") - final String usage, - - @JsonProperty("usage_unit") - final String usageUnit + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("api_version") final String apiVersion, + @JsonProperty("as_of") final String asOf, + @JsonProperty("category") final ThisMonth.Category category, + @JsonProperty("count") final String count, + @JsonProperty("count_unit") final String countUnit, + @JsonProperty("description") final String description, + @JsonProperty("end_date") final String endDate, + @JsonProperty("price") final BigDecimal price, + @JsonProperty("price_unit") @JsonDeserialize( + using = com.twilio.converter.CurrencyDeserializer.class + ) final Currency priceUnit, + @JsonProperty("start_date") final String startDate, + @JsonProperty( + "subresource_uris" + ) final Map subresourceUris, + @JsonProperty("uri") final String uri, + @JsonProperty("usage") final String usage, + @JsonProperty("usage_unit") final String usageUnit ) { this.accountSid = accountSid; this.apiVersion = apiVersion; @@ -435,55 +515,69 @@ private ThisMonth( this.usageUnit = usageUnit; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getApiVersion() { - return this.apiVersion; - } - public final String getAsOf() { - return this.asOf; - } - public final ThisMonth.Category getCategory() { - return this.category; - } - public final String getCount() { - return this.count; - } - public final String getCountUnit() { - return this.countUnit; - } - public final String getDescription() { - return this.description; - } - public final LocalDate getEndDate() { - return this.endDate; - } - public final BigDecimal getPrice() { - return this.price; - } - public final Currency getPriceUnit() { - return this.priceUnit; - } - public final LocalDate getStartDate() { - return this.startDate; - } - public final Map getSubresourceUris() { - return this.subresourceUris; - } - public final String getUri() { - return this.uri; - } - public final String getUsage() { - return this.usage; - } - public final String getUsageUnit() { - return this.usageUnit; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getApiVersion() { + return this.apiVersion; + } + + public final String getAsOf() { + return this.asOf; + } + + public final ThisMonth.Category getCategory() { + return this.category; + } + + public final String getCount() { + return this.count; + } + + public final String getCountUnit() { + return this.countUnit; + } + + public final String getDescription() { + return this.description; + } + + public final LocalDate getEndDate() { + return this.endDate; + } + + public final BigDecimal getPrice() { + return this.price; + } + + public final Currency getPriceUnit() { + return this.priceUnit; + } + + public final LocalDate getStartDate() { + return this.startDate; + } + + public final Map getSubresourceUris() { + return this.subresourceUris; + } + + public final String getUri() { + return this.uri; + } + + public final String getUsage() { + return this.usage; + } + + public final String getUsageUnit() { + return this.usageUnit; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -493,13 +587,43 @@ public boolean equals(final Object o) { ThisMonth other = (ThisMonth) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(apiVersion, other.apiVersion) && Objects.equals(asOf, other.asOf) && Objects.equals(category, other.category) && Objects.equals(count, other.count) && Objects.equals(countUnit, other.countUnit) && Objects.equals(description, other.description) && Objects.equals(endDate, other.endDate) && Objects.equals(price, other.price) && Objects.equals(priceUnit, other.priceUnit) && Objects.equals(startDate, other.startDate) && Objects.equals(subresourceUris, other.subresourceUris) && Objects.equals(uri, other.uri) && Objects.equals(usage, other.usage) && Objects.equals(usageUnit, other.usageUnit) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(apiVersion, other.apiVersion) && + Objects.equals(asOf, other.asOf) && + Objects.equals(category, other.category) && + Objects.equals(count, other.count) && + Objects.equals(countUnit, other.countUnit) && + Objects.equals(description, other.description) && + Objects.equals(endDate, other.endDate) && + Objects.equals(price, other.price) && + Objects.equals(priceUnit, other.priceUnit) && + Objects.equals(startDate, other.startDate) && + Objects.equals(subresourceUris, other.subresourceUris) && + Objects.equals(uri, other.uri) && + Objects.equals(usage, other.usage) && + Objects.equals(usageUnit, other.usageUnit) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, apiVersion, asOf, category, count, countUnit, description, endDate, price, priceUnit, startDate, subresourceUris, uri, usage, usageUnit); + return Objects.hash( + accountSid, + apiVersion, + asOf, + category, + count, + countUnit, + description, + endDate, + price, + priceUnit, + startDate, + subresourceUris, + uri, + usage, + usageUnit + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/ThisMonthReader.java b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/ThisMonthReader.java index 17b98ca143..2bf49c7d91 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/ThisMonthReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/ThisMonthReader.java @@ -14,8 +14,10 @@ package com.twilio.rest.api.v2010.account.usage.record; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,13 +26,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; import java.time.LocalDate; -import com.twilio.converter.DateConverter; - - public class ThisMonthReader extends Reader { + private String pathAccountSid; private ThisMonth.Category category; private LocalDate startDate; @@ -38,29 +37,35 @@ public class ThisMonthReader extends Reader { private Boolean includeSubaccounts; private Integer pageSize; - public ThisMonthReader(){ - } - public ThisMonthReader(final String pathAccountSid){ + public ThisMonthReader() {} + + public ThisMonthReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - public ThisMonthReader setCategory(final ThisMonth.Category category){ + public ThisMonthReader setCategory(final ThisMonth.Category category) { this.category = category; return this; } - public ThisMonthReader setStartDate(final LocalDate startDate){ + + public ThisMonthReader setStartDate(final LocalDate startDate) { this.startDate = startDate; return this; } - public ThisMonthReader setEndDate(final LocalDate endDate){ + + public ThisMonthReader setEndDate(final LocalDate endDate) { this.endDate = endDate; return this; } - public ThisMonthReader setIncludeSubaccounts(final Boolean includeSubaccounts){ + + public ThisMonthReader setIncludeSubaccounts( + final Boolean includeSubaccounts + ) { this.includeSubaccounts = includeSubaccounts; return this; } - public ThisMonthReader setPageSize(final Integer pageSize){ + + public ThisMonthReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -71,9 +76,17 @@ public ResourceSet read(final TwilioRestClient client) { } public Page firstPage(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/Usage/Records/ThisMonth.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); + String path = + "/2010-04-01/Accounts/{AccountSid}/Usage/Records/ThisMonth.json"; + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -85,13 +98,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("ThisMonth read failed: Unable to connect to server"); + throw new ApiConnectionException( + "ThisMonth read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -107,7 +128,10 @@ private Page pageForRequest(final TwilioRestClient client, final Requ } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.API.toString()) @@ -115,9 +139,11 @@ public Page previousPage(final Page page, final TwilioRest return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.API.toString()) @@ -126,37 +152,44 @@ public Page nextPage(final Page page, final TwilioRestClie } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (category != null) { - request.addQueryParam("Category", category.toString()); } if (startDate != null) { - request.addQueryParam("StartDate", DateConverter.dateStringFromLocalDate(startDate)); + request.addQueryParam( + "StartDate", + DateConverter.dateStringFromLocalDate(startDate) + ); } if (endDate != null) { - request.addQueryParam("EndDate", DateConverter.dateStringFromLocalDate(endDate)); + request.addQueryParam( + "EndDate", + DateConverter.dateStringFromLocalDate(endDate) + ); } if (includeSubaccounts != null) { - - request.addQueryParam("IncludeSubaccounts", includeSubaccounts.toString()); + request.addQueryParam( + "IncludeSubaccounts", + includeSubaccounts.toString() + ); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/Today.java b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/Today.java index 252afd868a..2d7b96d9ee 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/Today.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/Today.java @@ -20,49 +20,49 @@ import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.twilio.base.Resource; -import java.util.Currency; +import com.twilio.converter.CurrencyDeserializer; import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; -import com.twilio.converter.CurrencyDeserializer; import com.twilio.exception.ApiConnectionException; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; - +import java.math.BigDecimal; +import java.time.LocalDate; +import java.util.Currency; import java.util.Map; -import java.util.Objects; - - import java.util.Map; -import java.time.LocalDate; -import java.math.BigDecimal; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Today extends Resource { + private static final long serialVersionUID = 120182361368915L; - public static TodayReader reader(){ + public static TodayReader reader() { return new TodayReader(); } - public static TodayReader reader(final String pathAccountSid){ + + public static TodayReader reader(final String pathAccountSid) { return new TodayReader(pathAccountSid); } /** - * Converts a JSON String into a Today object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Today object represented by the provided JSON - */ - public static Today fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Today object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Today object represented by the provided JSON + */ + public static Today fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Today.class); @@ -74,14 +74,17 @@ public static Today fromJson(final String json, final ObjectMapper objectMapper) } /** - * Converts a JSON InputStream into a Today object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Today object represented by the provided JSON - */ - public static Today fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Today object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Today object represented by the provided JSON + */ + public static Today fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Today.class); @@ -91,6 +94,7 @@ public static Today fromJson(final InputStream json, final ObjectMapper objectMa throw new ApiConnectionException(e.getMessage(), e); } } + public enum Category { A2P_REGISTRATION_FEES("a2p-registration-fees"), AGENT_CONFERENCE("agent-conference"), @@ -122,7 +126,9 @@ public enum Category { CONVERSATIONS("conversations"), CONVERSATIONS_API_REQUESTS("conversations-api-requests"), CONVERSATIONS_CONVERSATION_EVENTS("conversations-conversation-events"), - CONVERSATIONS_ENDPOINT_CONNECTIVITY("conversations-endpoint-connectivity"), + CONVERSATIONS_ENDPOINT_CONNECTIVITY( + "conversations-endpoint-connectivity" + ), CONVERSATIONS_EVENTS("conversations-events"), CONVERSATIONS_PARTICIPANT_EVENTS("conversations-participant-events"), CONVERSATIONS_PARTICIPANTS("conversations-participants"), @@ -131,7 +137,9 @@ public enum Category { FRAUD_LOOKUPS("fraud-lookups"), GROUP_ROOMS("group-rooms"), GROUP_ROOMS_DATA_TRACK("group-rooms-data-track"), - GROUP_ROOMS_ENCRYPTED_MEDIA_RECORDED("group-rooms-encrypted-media-recorded"), + GROUP_ROOMS_ENCRYPTED_MEDIA_RECORDED( + "group-rooms-encrypted-media-recorded" + ), GROUP_ROOMS_MEDIA_DOWNLOADED("group-rooms-media-downloaded"), GROUP_ROOMS_MEDIA_RECORDED("group-rooms-media-recorded"), GROUP_ROOMS_MEDIA_ROUTED("group-rooms-media-routed"), @@ -141,45 +149,99 @@ public enum Category { IMP_V1_USAGE("imp-v1-usage"), LOOKUPS("lookups"), MARKETPLACE("marketplace"), - MARKETPLACE_ALGORITHMIA_NAMED_ENTITY_RECOGNITION("marketplace-algorithmia-named-entity-recognition"), + MARKETPLACE_ALGORITHMIA_NAMED_ENTITY_RECOGNITION( + "marketplace-algorithmia-named-entity-recognition" + ), MARKETPLACE_CADENCE_TRANSCRIPTION("marketplace-cadence-transcription"), MARKETPLACE_CADENCE_TRANSLATION("marketplace-cadence-translation"), MARKETPLACE_CAPIO_SPEECH_TO_TEXT("marketplace-capio-speech-to-text"), MARKETPLACE_CONVRIZA_ABABA("marketplace-convriza-ababa"), - MARKETPLACE_DEEPGRAM_PHRASE_DETECTOR("marketplace-deepgram-phrase-detector"), - MARKETPLACE_DIGITAL_SEGMENT_BUSINESS_INFO("marketplace-digital-segment-business-info"), - MARKETPLACE_FACEBOOK_OFFLINE_CONVERSIONS("marketplace-facebook-offline-conversions"), + MARKETPLACE_DEEPGRAM_PHRASE_DETECTOR( + "marketplace-deepgram-phrase-detector" + ), + MARKETPLACE_DIGITAL_SEGMENT_BUSINESS_INFO( + "marketplace-digital-segment-business-info" + ), + MARKETPLACE_FACEBOOK_OFFLINE_CONVERSIONS( + "marketplace-facebook-offline-conversions" + ), MARKETPLACE_GOOGLE_SPEECH_TO_TEXT("marketplace-google-speech-to-text"), - MARKETPLACE_IBM_WATSON_MESSAGE_INSIGHTS("marketplace-ibm-watson-message-insights"), - MARKETPLACE_IBM_WATSON_MESSAGE_SENTIMENT("marketplace-ibm-watson-message-sentiment"), - MARKETPLACE_IBM_WATSON_RECORDING_ANALYSIS("marketplace-ibm-watson-recording-analysis"), - MARKETPLACE_IBM_WATSON_TONE_ANALYZER("marketplace-ibm-watson-tone-analyzer"), + MARKETPLACE_IBM_WATSON_MESSAGE_INSIGHTS( + "marketplace-ibm-watson-message-insights" + ), + MARKETPLACE_IBM_WATSON_MESSAGE_SENTIMENT( + "marketplace-ibm-watson-message-sentiment" + ), + MARKETPLACE_IBM_WATSON_RECORDING_ANALYSIS( + "marketplace-ibm-watson-recording-analysis" + ), + MARKETPLACE_IBM_WATSON_TONE_ANALYZER( + "marketplace-ibm-watson-tone-analyzer" + ), MARKETPLACE_ICEHOOK_SYSTEMS_SCOUT("marketplace-icehook-systems-scout"), - MARKETPLACE_INFOGROUP_DATAAXLE_BIZINFO("marketplace-infogroup-dataaxle-bizinfo"), - MARKETPLACE_KEEN_IO_CONTACT_CENTER_ANALYTICS("marketplace-keen-io-contact-center-analytics"), + MARKETPLACE_INFOGROUP_DATAAXLE_BIZINFO( + "marketplace-infogroup-dataaxle-bizinfo" + ), + MARKETPLACE_KEEN_IO_CONTACT_CENTER_ANALYTICS( + "marketplace-keen-io-contact-center-analytics" + ), MARKETPLACE_MARCHEX_CLEANCALL("marketplace-marchex-cleancall"), - MARKETPLACE_MARCHEX_SENTIMENT_ANALYSIS_FOR_SMS("marketplace-marchex-sentiment-analysis-for-sms"), - MARKETPLACE_MARKETPLACE_NEXTCALLER_SOCIAL_ID("marketplace-marketplace-nextcaller-social-id"), - MARKETPLACE_MOBILE_COMMONS_OPT_OUT_CLASSIFIER("marketplace-mobile-commons-opt-out-classifier"), - MARKETPLACE_NEXIWAVE_VOICEMAIL_TO_TEXT("marketplace-nexiwave-voicemail-to-text"), - MARKETPLACE_NEXTCALLER_ADVANCED_CALLER_IDENTIFICATION("marketplace-nextcaller-advanced-caller-identification"), + MARKETPLACE_MARCHEX_SENTIMENT_ANALYSIS_FOR_SMS( + "marketplace-marchex-sentiment-analysis-for-sms" + ), + MARKETPLACE_MARKETPLACE_NEXTCALLER_SOCIAL_ID( + "marketplace-marketplace-nextcaller-social-id" + ), + MARKETPLACE_MOBILE_COMMONS_OPT_OUT_CLASSIFIER( + "marketplace-mobile-commons-opt-out-classifier" + ), + MARKETPLACE_NEXIWAVE_VOICEMAIL_TO_TEXT( + "marketplace-nexiwave-voicemail-to-text" + ), + MARKETPLACE_NEXTCALLER_ADVANCED_CALLER_IDENTIFICATION( + "marketplace-nextcaller-advanced-caller-identification" + ), MARKETPLACE_NOMOROBO_SPAM_SCORE("marketplace-nomorobo-spam-score"), - MARKETPLACE_PAYFONE_TCPA_COMPLIANCE("marketplace-payfone-tcpa-compliance"), - MARKETPLACE_REMEETING_AUTOMATIC_SPEECH_RECOGNITION("marketplace-remeeting-automatic-speech-recognition"), - MARKETPLACE_TCPA_DEFENSE_SOLUTIONS_BLACKLIST_FEED("marketplace-tcpa-defense-solutions-blacklist-feed"), + MARKETPLACE_PAYFONE_TCPA_COMPLIANCE( + "marketplace-payfone-tcpa-compliance" + ), + MARKETPLACE_REMEETING_AUTOMATIC_SPEECH_RECOGNITION( + "marketplace-remeeting-automatic-speech-recognition" + ), + MARKETPLACE_TCPA_DEFENSE_SOLUTIONS_BLACKLIST_FEED( + "marketplace-tcpa-defense-solutions-blacklist-feed" + ), MARKETPLACE_TELO_OPENCNAM("marketplace-telo-opencnam"), MARKETPLACE_TRUECNAM_TRUE_SPAM("marketplace-truecnam-true-spam"), - MARKETPLACE_TWILIO_CALLER_NAME_LOOKUP_US("marketplace-twilio-caller-name-lookup-us"), - MARKETPLACE_TWILIO_CARRIER_INFORMATION_LOOKUP("marketplace-twilio-carrier-information-lookup"), + MARKETPLACE_TWILIO_CALLER_NAME_LOOKUP_US( + "marketplace-twilio-caller-name-lookup-us" + ), + MARKETPLACE_TWILIO_CARRIER_INFORMATION_LOOKUP( + "marketplace-twilio-carrier-information-lookup" + ), MARKETPLACE_VOICEBASE_PCI("marketplace-voicebase-pci"), - MARKETPLACE_VOICEBASE_TRANSCRIPTION("marketplace-voicebase-transcription"), - MARKETPLACE_VOICEBASE_TRANSCRIPTION_CUSTOM_VOCABULARY("marketplace-voicebase-transcription-custom-vocabulary"), - MARKETPLACE_WHITEPAGES_PRO_CALLER_IDENTIFICATION("marketplace-whitepages-pro-caller-identification"), - MARKETPLACE_WHITEPAGES_PRO_PHONE_INTELLIGENCE("marketplace-whitepages-pro-phone-intelligence"), - MARKETPLACE_WHITEPAGES_PRO_PHONE_REPUTATION("marketplace-whitepages-pro-phone-reputation"), - MARKETPLACE_WOLFARM_SPOKEN_RESULTS("marketplace-wolfarm-spoken-results"), + MARKETPLACE_VOICEBASE_TRANSCRIPTION( + "marketplace-voicebase-transcription" + ), + MARKETPLACE_VOICEBASE_TRANSCRIPTION_CUSTOM_VOCABULARY( + "marketplace-voicebase-transcription-custom-vocabulary" + ), + MARKETPLACE_WHITEPAGES_PRO_CALLER_IDENTIFICATION( + "marketplace-whitepages-pro-caller-identification" + ), + MARKETPLACE_WHITEPAGES_PRO_PHONE_INTELLIGENCE( + "marketplace-whitepages-pro-phone-intelligence" + ), + MARKETPLACE_WHITEPAGES_PRO_PHONE_REPUTATION( + "marketplace-whitepages-pro-phone-reputation" + ), + MARKETPLACE_WOLFARM_SPOKEN_RESULTS( + "marketplace-wolfarm-spoken-results" + ), MARKETPLACE_WOLFRAM_SHORT_ANSWER("marketplace-wolfram-short-answer"), - MARKETPLACE_YTICA_CONTACT_CENTER_REPORTING_ANALYTICS("marketplace-ytica-contact-center-reporting-analytics"), + MARKETPLACE_YTICA_CONTACT_CENTER_REPORTING_ANALYTICS( + "marketplace-ytica-contact-center-reporting-analytics" + ), MEDIASTORAGE("mediastorage"), MMS("mms"), MMS_INBOUND("mms-inbound"), @@ -198,7 +260,9 @@ public enum Category { NUMBER_FORMAT_LOOKUPS("number-format-lookups"), PCHAT("pchat"), PCHAT_USERS("pchat-users"), - PEER_TO_PEER_ROOMS_PARTICIPANT_MINUTES("peer-to-peer-rooms-participant-minutes"), + PEER_TO_PEER_ROOMS_PARTICIPANT_MINUTES( + "peer-to-peer-rooms-participant-minutes" + ), PFAX("pfax"), PFAX_MINUTES("pfax-minutes"), PFAX_MINUTES_INBOUND("pfax-minutes-inbound"), @@ -245,7 +309,9 @@ public enum Category { SHORTCODES_VANITY("shortcodes-vanity"), SMALL_GROUP_ROOMS("small-group-rooms"), SMALL_GROUP_ROOMS_DATA_TRACK("small-group-rooms-data-track"), - SMALL_GROUP_ROOMS_PARTICIPANT_MINUTES("small-group-rooms-participant-minutes"), + SMALL_GROUP_ROOMS_PARTICIPANT_MINUTES( + "small-group-rooms-participant-minutes" + ), SMS("sms"), SMS_INBOUND("sms-inbound"), SMS_INBOUND_LONGCODE("sms-inbound-longcode"), @@ -262,7 +328,9 @@ public enum Category { SYNC("sync"), SYNC_ACTIONS("sync-actions"), SYNC_ENDPOINT_HOURS("sync-endpoint-hours"), - SYNC_ENDPOINT_HOURS_ABOVE_DAILY_CAP("sync-endpoint-hours-above-daily-cap"), + SYNC_ENDPOINT_HOURS_ABOVE_DAILY_CAP( + "sync-endpoint-hours-above-daily-cap" + ), TASKROUTER_TASKS("taskrouter-tasks"), TOTALPRICE("totalprice"), TRANSCRIPTIONS("transcriptions"), @@ -275,6 +343,7 @@ public enum Category { TRUNKING_RECORDINGS("trunking-recordings"), TRUNKING_SECURE("trunking-secure"), TRUNKING_TERMINATION("trunking-termination"), + TTS_GOOGLE("tts-google"), TURNMEGABYTES("turnmegabytes"), TURNMEGABYTES_AUSTRALIA("turnmegabytes-australia"), TURNMEGABYTES_BRASIL("turnmegabytes-brasil"), @@ -288,14 +357,27 @@ public enum Category { TWILIO_INTERCONNECT("twilio-interconnect"), VERIFY_PUSH("verify-push"), VERIFY_TOTP("verify-totp"), - VERIFY_WHATSAPP_CONVERSATIONS_BUSINESS_INITIATED("verify-whatsapp-conversations-business-initiated"), + VERIFY_WHATSAPP_CONVERSATIONS_BUSINESS_INITIATED( + "verify-whatsapp-conversations-business-initiated" + ), VIDEO_RECORDINGS("video-recordings"), VIRTUAL_AGENT("virtual-agent"), VOICE_INSIGHTS("voice-insights"), - VOICE_INSIGHTS_CLIENT_INSIGHTS_ON_DEMAND_MINUTE("voice-insights-client-insights-on-demand-minute"), - VOICE_INSIGHTS_PTSN_INSIGHTS_ON_DEMAND_MINUTE("voice-insights-ptsn-insights-on-demand-minute"), - VOICE_INSIGHTS_SIP_INTERFACE_INSIGHTS_ON_DEMAND_MINUTE("voice-insights-sip-interface-insights-on-demand-minute"), - VOICE_INSIGHTS_SIP_TRUNKING_INSIGHTS_ON_DEMAND_MINUTE("voice-insights-sip-trunking-insights-on-demand-minute"), + VOICE_INSIGHTS_CLIENT_INSIGHTS_ON_DEMAND_MINUTE( + "voice-insights-client-insights-on-demand-minute" + ), + VOICE_INSIGHTS_PTSN_INSIGHTS_ON_DEMAND_MINUTE( + "voice-insights-ptsn-insights-on-demand-minute" + ), + VOICE_INSIGHTS_SIP_INTERFACE_INSIGHTS_ON_DEMAND_MINUTE( + "voice-insights-sip-interface-insights-on-demand-minute" + ), + VOICE_INSIGHTS_SIP_TRUNKING_INSIGHTS_ON_DEMAND_MINUTE( + "voice-insights-sip-trunking-insights-on-demand-minute" + ), + VOICE_INTELLIGENCE("voice-intelligence"), + VOICE_INTELLIGENCE_TRANSCRIPTION("voice-intelligence-transcription"), + VOICE_INTELLIGENCE_OPERATORS("voice-intelligence-operators"), WIRELESS("wireless"), WIRELESS_ORDERS("wireless-orders"), WIRELESS_ORDERS_ARTWORK("wireless-orders-artwork"), @@ -306,29 +388,53 @@ public enum Category { WIRELESS_USAGE_COMMANDS("wireless-usage-commands"), WIRELESS_USAGE_COMMANDS_AFRICA("wireless-usage-commands-africa"), WIRELESS_USAGE_COMMANDS_ASIA("wireless-usage-commands-asia"), - WIRELESS_USAGE_COMMANDS_CENTRALANDSOUTHAMERICA("wireless-usage-commands-centralandsouthamerica"), + WIRELESS_USAGE_COMMANDS_CENTRALANDSOUTHAMERICA( + "wireless-usage-commands-centralandsouthamerica" + ), WIRELESS_USAGE_COMMANDS_EUROPE("wireless-usage-commands-europe"), WIRELESS_USAGE_COMMANDS_HOME("wireless-usage-commands-home"), - WIRELESS_USAGE_COMMANDS_NORTHAMERICA("wireless-usage-commands-northamerica"), + WIRELESS_USAGE_COMMANDS_NORTHAMERICA( + "wireless-usage-commands-northamerica" + ), WIRELESS_USAGE_COMMANDS_OCEANIA("wireless-usage-commands-oceania"), WIRELESS_USAGE_COMMANDS_ROAMING("wireless-usage-commands-roaming"), WIRELESS_USAGE_DATA("wireless-usage-data"), WIRELESS_USAGE_DATA_AFRICA("wireless-usage-data-africa"), WIRELESS_USAGE_DATA_ASIA("wireless-usage-data-asia"), - WIRELESS_USAGE_DATA_CENTRALANDSOUTHAMERICA("wireless-usage-data-centralandsouthamerica"), - WIRELESS_USAGE_DATA_CUSTOM_ADDITIONALMB("wireless-usage-data-custom-additionalmb"), - WIRELESS_USAGE_DATA_CUSTOM_FIRST5MB("wireless-usage-data-custom-first5mb"), - WIRELESS_USAGE_DATA_DOMESTIC_ROAMING("wireless-usage-data-domestic-roaming"), + WIRELESS_USAGE_DATA_CENTRALANDSOUTHAMERICA( + "wireless-usage-data-centralandsouthamerica" + ), + WIRELESS_USAGE_DATA_CUSTOM_ADDITIONALMB( + "wireless-usage-data-custom-additionalmb" + ), + WIRELESS_USAGE_DATA_CUSTOM_FIRST5MB( + "wireless-usage-data-custom-first5mb" + ), + WIRELESS_USAGE_DATA_DOMESTIC_ROAMING( + "wireless-usage-data-domestic-roaming" + ), WIRELESS_USAGE_DATA_EUROPE("wireless-usage-data-europe"), - WIRELESS_USAGE_DATA_INDIVIDUAL_ADDITIONALGB("wireless-usage-data-individual-additionalgb"), - WIRELESS_USAGE_DATA_INDIVIDUAL_FIRSTGB("wireless-usage-data-individual-firstgb"), - WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_CANADA("wireless-usage-data-international-roaming-canada"), - WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_INDIA("wireless-usage-data-international-roaming-india"), - WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_MEXICO("wireless-usage-data-international-roaming-mexico"), + WIRELESS_USAGE_DATA_INDIVIDUAL_ADDITIONALGB( + "wireless-usage-data-individual-additionalgb" + ), + WIRELESS_USAGE_DATA_INDIVIDUAL_FIRSTGB( + "wireless-usage-data-individual-firstgb" + ), + WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_CANADA( + "wireless-usage-data-international-roaming-canada" + ), + WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_INDIA( + "wireless-usage-data-international-roaming-india" + ), + WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_MEXICO( + "wireless-usage-data-international-roaming-mexico" + ), WIRELESS_USAGE_DATA_NORTHAMERICA("wireless-usage-data-northamerica"), WIRELESS_USAGE_DATA_OCEANIA("wireless-usage-data-oceania"), WIRELESS_USAGE_DATA_POOLED("wireless-usage-data-pooled"), - WIRELESS_USAGE_DATA_POOLED_DOWNLINK("wireless-usage-data-pooled-downlink"), + WIRELESS_USAGE_DATA_POOLED_DOWNLINK( + "wireless-usage-data-pooled-downlink" + ), WIRELESS_USAGE_DATA_POOLED_UPLINK("wireless-usage-data-pooled-uplink"), WIRELESS_USAGE_MRC("wireless-usage-mrc"), WIRELESS_USAGE_MRC_CUSTOM("wireless-usage-mrc-custom"), @@ -372,51 +478,25 @@ public static Category forValue(final String value) { @JsonCreator private Today( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("api_version") - final String apiVersion, - - @JsonProperty("as_of") - final String asOf, - - @JsonProperty("category") - final Today.Category category, - - @JsonProperty("count") - final String count, - - @JsonProperty("count_unit") - final String countUnit, - - @JsonProperty("description") - final String description, - - @JsonProperty("end_date") - final String endDate, - - @JsonProperty("price") - final BigDecimal price, - - @JsonProperty("price_unit") - @JsonDeserialize(using = com.twilio.converter.CurrencyDeserializer.class) - final Currency priceUnit, - - @JsonProperty("start_date") - final String startDate, - - @JsonProperty("subresource_uris") - final Map subresourceUris, - - @JsonProperty("uri") - final String uri, - - @JsonProperty("usage") - final String usage, - - @JsonProperty("usage_unit") - final String usageUnit + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("api_version") final String apiVersion, + @JsonProperty("as_of") final String asOf, + @JsonProperty("category") final Today.Category category, + @JsonProperty("count") final String count, + @JsonProperty("count_unit") final String countUnit, + @JsonProperty("description") final String description, + @JsonProperty("end_date") final String endDate, + @JsonProperty("price") final BigDecimal price, + @JsonProperty("price_unit") @JsonDeserialize( + using = com.twilio.converter.CurrencyDeserializer.class + ) final Currency priceUnit, + @JsonProperty("start_date") final String startDate, + @JsonProperty( + "subresource_uris" + ) final Map subresourceUris, + @JsonProperty("uri") final String uri, + @JsonProperty("usage") final String usage, + @JsonProperty("usage_unit") final String usageUnit ) { this.accountSid = accountSid; this.apiVersion = apiVersion; @@ -435,55 +515,69 @@ private Today( this.usageUnit = usageUnit; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getApiVersion() { - return this.apiVersion; - } - public final String getAsOf() { - return this.asOf; - } - public final Today.Category getCategory() { - return this.category; - } - public final String getCount() { - return this.count; - } - public final String getCountUnit() { - return this.countUnit; - } - public final String getDescription() { - return this.description; - } - public final LocalDate getEndDate() { - return this.endDate; - } - public final BigDecimal getPrice() { - return this.price; - } - public final Currency getPriceUnit() { - return this.priceUnit; - } - public final LocalDate getStartDate() { - return this.startDate; - } - public final Map getSubresourceUris() { - return this.subresourceUris; - } - public final String getUri() { - return this.uri; - } - public final String getUsage() { - return this.usage; - } - public final String getUsageUnit() { - return this.usageUnit; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getApiVersion() { + return this.apiVersion; + } + + public final String getAsOf() { + return this.asOf; + } + + public final Today.Category getCategory() { + return this.category; + } + + public final String getCount() { + return this.count; + } + + public final String getCountUnit() { + return this.countUnit; + } + + public final String getDescription() { + return this.description; + } + + public final LocalDate getEndDate() { + return this.endDate; + } + + public final BigDecimal getPrice() { + return this.price; + } + + public final Currency getPriceUnit() { + return this.priceUnit; + } + + public final LocalDate getStartDate() { + return this.startDate; + } + + public final Map getSubresourceUris() { + return this.subresourceUris; + } + + public final String getUri() { + return this.uri; + } + + public final String getUsage() { + return this.usage; + } + + public final String getUsageUnit() { + return this.usageUnit; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -493,13 +587,43 @@ public boolean equals(final Object o) { Today other = (Today) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(apiVersion, other.apiVersion) && Objects.equals(asOf, other.asOf) && Objects.equals(category, other.category) && Objects.equals(count, other.count) && Objects.equals(countUnit, other.countUnit) && Objects.equals(description, other.description) && Objects.equals(endDate, other.endDate) && Objects.equals(price, other.price) && Objects.equals(priceUnit, other.priceUnit) && Objects.equals(startDate, other.startDate) && Objects.equals(subresourceUris, other.subresourceUris) && Objects.equals(uri, other.uri) && Objects.equals(usage, other.usage) && Objects.equals(usageUnit, other.usageUnit) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(apiVersion, other.apiVersion) && + Objects.equals(asOf, other.asOf) && + Objects.equals(category, other.category) && + Objects.equals(count, other.count) && + Objects.equals(countUnit, other.countUnit) && + Objects.equals(description, other.description) && + Objects.equals(endDate, other.endDate) && + Objects.equals(price, other.price) && + Objects.equals(priceUnit, other.priceUnit) && + Objects.equals(startDate, other.startDate) && + Objects.equals(subresourceUris, other.subresourceUris) && + Objects.equals(uri, other.uri) && + Objects.equals(usage, other.usage) && + Objects.equals(usageUnit, other.usageUnit) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, apiVersion, asOf, category, count, countUnit, description, endDate, price, priceUnit, startDate, subresourceUris, uri, usage, usageUnit); + return Objects.hash( + accountSid, + apiVersion, + asOf, + category, + count, + countUnit, + description, + endDate, + price, + priceUnit, + startDate, + subresourceUris, + uri, + usage, + usageUnit + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/TodayReader.java b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/TodayReader.java index 66ae1e4093..59be068e50 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/TodayReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/TodayReader.java @@ -14,8 +14,10 @@ package com.twilio.rest.api.v2010.account.usage.record; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,13 +26,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; import java.time.LocalDate; -import com.twilio.converter.DateConverter; - - public class TodayReader extends Reader { + private String pathAccountSid; private Today.Category category; private LocalDate startDate; @@ -38,29 +37,33 @@ public class TodayReader extends Reader { private Boolean includeSubaccounts; private Integer pageSize; - public TodayReader(){ - } - public TodayReader(final String pathAccountSid){ + public TodayReader() {} + + public TodayReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - public TodayReader setCategory(final Today.Category category){ + public TodayReader setCategory(final Today.Category category) { this.category = category; return this; } - public TodayReader setStartDate(final LocalDate startDate){ + + public TodayReader setStartDate(final LocalDate startDate) { this.startDate = startDate; return this; } - public TodayReader setEndDate(final LocalDate endDate){ + + public TodayReader setEndDate(final LocalDate endDate) { this.endDate = endDate; return this; } - public TodayReader setIncludeSubaccounts(final Boolean includeSubaccounts){ + + public TodayReader setIncludeSubaccounts(final Boolean includeSubaccounts) { this.includeSubaccounts = includeSubaccounts; return this; } - public TodayReader setPageSize(final Integer pageSize){ + + public TodayReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -71,9 +74,17 @@ public ResourceSet read(final TwilioRestClient client) { } public Page firstPage(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/Usage/Records/Today.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); + String path = + "/2010-04-01/Accounts/{AccountSid}/Usage/Records/Today.json"; + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -85,13 +96,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Today read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Today read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -107,7 +126,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.API.toString()) @@ -115,9 +137,11 @@ public Page previousPage(final Page page, final TwilioRestClient c return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.API.toString()) @@ -126,37 +150,44 @@ public Page nextPage(final Page page, final TwilioRestClient clien } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (category != null) { - request.addQueryParam("Category", category.toString()); } if (startDate != null) { - request.addQueryParam("StartDate", DateConverter.dateStringFromLocalDate(startDate)); + request.addQueryParam( + "StartDate", + DateConverter.dateStringFromLocalDate(startDate) + ); } if (endDate != null) { - request.addQueryParam("EndDate", DateConverter.dateStringFromLocalDate(endDate)); + request.addQueryParam( + "EndDate", + DateConverter.dateStringFromLocalDate(endDate) + ); } if (includeSubaccounts != null) { - - request.addQueryParam("IncludeSubaccounts", includeSubaccounts.toString()); + request.addQueryParam( + "IncludeSubaccounts", + includeSubaccounts.toString() + ); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/Yearly.java b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/Yearly.java index 76764ce02c..c7f7535493 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/Yearly.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/Yearly.java @@ -20,49 +20,49 @@ import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.twilio.base.Resource; -import java.util.Currency; +import com.twilio.converter.CurrencyDeserializer; import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; -import com.twilio.converter.CurrencyDeserializer; import com.twilio.exception.ApiConnectionException; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; - +import java.math.BigDecimal; +import java.time.LocalDate; +import java.util.Currency; import java.util.Map; -import java.util.Objects; - - import java.util.Map; -import java.time.LocalDate; -import java.math.BigDecimal; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Yearly extends Resource { + private static final long serialVersionUID = 266687924235941L; - public static YearlyReader reader(){ + public static YearlyReader reader() { return new YearlyReader(); } - public static YearlyReader reader(final String pathAccountSid){ + + public static YearlyReader reader(final String pathAccountSid) { return new YearlyReader(pathAccountSid); } /** - * Converts a JSON String into a Yearly object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Yearly object represented by the provided JSON - */ - public static Yearly fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Yearly object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Yearly object represented by the provided JSON + */ + public static Yearly fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Yearly.class); @@ -74,14 +74,17 @@ public static Yearly fromJson(final String json, final ObjectMapper objectMapper } /** - * Converts a JSON InputStream into a Yearly object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Yearly object represented by the provided JSON - */ - public static Yearly fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Yearly object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Yearly object represented by the provided JSON + */ + public static Yearly fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Yearly.class); @@ -91,6 +94,7 @@ public static Yearly fromJson(final InputStream json, final ObjectMapper objectM throw new ApiConnectionException(e.getMessage(), e); } } + public enum Category { A2P_REGISTRATION_FEES("a2p-registration-fees"), AGENT_CONFERENCE("agent-conference"), @@ -122,7 +126,9 @@ public enum Category { CONVERSATIONS("conversations"), CONVERSATIONS_API_REQUESTS("conversations-api-requests"), CONVERSATIONS_CONVERSATION_EVENTS("conversations-conversation-events"), - CONVERSATIONS_ENDPOINT_CONNECTIVITY("conversations-endpoint-connectivity"), + CONVERSATIONS_ENDPOINT_CONNECTIVITY( + "conversations-endpoint-connectivity" + ), CONVERSATIONS_EVENTS("conversations-events"), CONVERSATIONS_PARTICIPANT_EVENTS("conversations-participant-events"), CONVERSATIONS_PARTICIPANTS("conversations-participants"), @@ -131,7 +137,9 @@ public enum Category { FRAUD_LOOKUPS("fraud-lookups"), GROUP_ROOMS("group-rooms"), GROUP_ROOMS_DATA_TRACK("group-rooms-data-track"), - GROUP_ROOMS_ENCRYPTED_MEDIA_RECORDED("group-rooms-encrypted-media-recorded"), + GROUP_ROOMS_ENCRYPTED_MEDIA_RECORDED( + "group-rooms-encrypted-media-recorded" + ), GROUP_ROOMS_MEDIA_DOWNLOADED("group-rooms-media-downloaded"), GROUP_ROOMS_MEDIA_RECORDED("group-rooms-media-recorded"), GROUP_ROOMS_MEDIA_ROUTED("group-rooms-media-routed"), @@ -141,45 +149,99 @@ public enum Category { IMP_V1_USAGE("imp-v1-usage"), LOOKUPS("lookups"), MARKETPLACE("marketplace"), - MARKETPLACE_ALGORITHMIA_NAMED_ENTITY_RECOGNITION("marketplace-algorithmia-named-entity-recognition"), + MARKETPLACE_ALGORITHMIA_NAMED_ENTITY_RECOGNITION( + "marketplace-algorithmia-named-entity-recognition" + ), MARKETPLACE_CADENCE_TRANSCRIPTION("marketplace-cadence-transcription"), MARKETPLACE_CADENCE_TRANSLATION("marketplace-cadence-translation"), MARKETPLACE_CAPIO_SPEECH_TO_TEXT("marketplace-capio-speech-to-text"), MARKETPLACE_CONVRIZA_ABABA("marketplace-convriza-ababa"), - MARKETPLACE_DEEPGRAM_PHRASE_DETECTOR("marketplace-deepgram-phrase-detector"), - MARKETPLACE_DIGITAL_SEGMENT_BUSINESS_INFO("marketplace-digital-segment-business-info"), - MARKETPLACE_FACEBOOK_OFFLINE_CONVERSIONS("marketplace-facebook-offline-conversions"), + MARKETPLACE_DEEPGRAM_PHRASE_DETECTOR( + "marketplace-deepgram-phrase-detector" + ), + MARKETPLACE_DIGITAL_SEGMENT_BUSINESS_INFO( + "marketplace-digital-segment-business-info" + ), + MARKETPLACE_FACEBOOK_OFFLINE_CONVERSIONS( + "marketplace-facebook-offline-conversions" + ), MARKETPLACE_GOOGLE_SPEECH_TO_TEXT("marketplace-google-speech-to-text"), - MARKETPLACE_IBM_WATSON_MESSAGE_INSIGHTS("marketplace-ibm-watson-message-insights"), - MARKETPLACE_IBM_WATSON_MESSAGE_SENTIMENT("marketplace-ibm-watson-message-sentiment"), - MARKETPLACE_IBM_WATSON_RECORDING_ANALYSIS("marketplace-ibm-watson-recording-analysis"), - MARKETPLACE_IBM_WATSON_TONE_ANALYZER("marketplace-ibm-watson-tone-analyzer"), + MARKETPLACE_IBM_WATSON_MESSAGE_INSIGHTS( + "marketplace-ibm-watson-message-insights" + ), + MARKETPLACE_IBM_WATSON_MESSAGE_SENTIMENT( + "marketplace-ibm-watson-message-sentiment" + ), + MARKETPLACE_IBM_WATSON_RECORDING_ANALYSIS( + "marketplace-ibm-watson-recording-analysis" + ), + MARKETPLACE_IBM_WATSON_TONE_ANALYZER( + "marketplace-ibm-watson-tone-analyzer" + ), MARKETPLACE_ICEHOOK_SYSTEMS_SCOUT("marketplace-icehook-systems-scout"), - MARKETPLACE_INFOGROUP_DATAAXLE_BIZINFO("marketplace-infogroup-dataaxle-bizinfo"), - MARKETPLACE_KEEN_IO_CONTACT_CENTER_ANALYTICS("marketplace-keen-io-contact-center-analytics"), + MARKETPLACE_INFOGROUP_DATAAXLE_BIZINFO( + "marketplace-infogroup-dataaxle-bizinfo" + ), + MARKETPLACE_KEEN_IO_CONTACT_CENTER_ANALYTICS( + "marketplace-keen-io-contact-center-analytics" + ), MARKETPLACE_MARCHEX_CLEANCALL("marketplace-marchex-cleancall"), - MARKETPLACE_MARCHEX_SENTIMENT_ANALYSIS_FOR_SMS("marketplace-marchex-sentiment-analysis-for-sms"), - MARKETPLACE_MARKETPLACE_NEXTCALLER_SOCIAL_ID("marketplace-marketplace-nextcaller-social-id"), - MARKETPLACE_MOBILE_COMMONS_OPT_OUT_CLASSIFIER("marketplace-mobile-commons-opt-out-classifier"), - MARKETPLACE_NEXIWAVE_VOICEMAIL_TO_TEXT("marketplace-nexiwave-voicemail-to-text"), - MARKETPLACE_NEXTCALLER_ADVANCED_CALLER_IDENTIFICATION("marketplace-nextcaller-advanced-caller-identification"), + MARKETPLACE_MARCHEX_SENTIMENT_ANALYSIS_FOR_SMS( + "marketplace-marchex-sentiment-analysis-for-sms" + ), + MARKETPLACE_MARKETPLACE_NEXTCALLER_SOCIAL_ID( + "marketplace-marketplace-nextcaller-social-id" + ), + MARKETPLACE_MOBILE_COMMONS_OPT_OUT_CLASSIFIER( + "marketplace-mobile-commons-opt-out-classifier" + ), + MARKETPLACE_NEXIWAVE_VOICEMAIL_TO_TEXT( + "marketplace-nexiwave-voicemail-to-text" + ), + MARKETPLACE_NEXTCALLER_ADVANCED_CALLER_IDENTIFICATION( + "marketplace-nextcaller-advanced-caller-identification" + ), MARKETPLACE_NOMOROBO_SPAM_SCORE("marketplace-nomorobo-spam-score"), - MARKETPLACE_PAYFONE_TCPA_COMPLIANCE("marketplace-payfone-tcpa-compliance"), - MARKETPLACE_REMEETING_AUTOMATIC_SPEECH_RECOGNITION("marketplace-remeeting-automatic-speech-recognition"), - MARKETPLACE_TCPA_DEFENSE_SOLUTIONS_BLACKLIST_FEED("marketplace-tcpa-defense-solutions-blacklist-feed"), + MARKETPLACE_PAYFONE_TCPA_COMPLIANCE( + "marketplace-payfone-tcpa-compliance" + ), + MARKETPLACE_REMEETING_AUTOMATIC_SPEECH_RECOGNITION( + "marketplace-remeeting-automatic-speech-recognition" + ), + MARKETPLACE_TCPA_DEFENSE_SOLUTIONS_BLACKLIST_FEED( + "marketplace-tcpa-defense-solutions-blacklist-feed" + ), MARKETPLACE_TELO_OPENCNAM("marketplace-telo-opencnam"), MARKETPLACE_TRUECNAM_TRUE_SPAM("marketplace-truecnam-true-spam"), - MARKETPLACE_TWILIO_CALLER_NAME_LOOKUP_US("marketplace-twilio-caller-name-lookup-us"), - MARKETPLACE_TWILIO_CARRIER_INFORMATION_LOOKUP("marketplace-twilio-carrier-information-lookup"), + MARKETPLACE_TWILIO_CALLER_NAME_LOOKUP_US( + "marketplace-twilio-caller-name-lookup-us" + ), + MARKETPLACE_TWILIO_CARRIER_INFORMATION_LOOKUP( + "marketplace-twilio-carrier-information-lookup" + ), MARKETPLACE_VOICEBASE_PCI("marketplace-voicebase-pci"), - MARKETPLACE_VOICEBASE_TRANSCRIPTION("marketplace-voicebase-transcription"), - MARKETPLACE_VOICEBASE_TRANSCRIPTION_CUSTOM_VOCABULARY("marketplace-voicebase-transcription-custom-vocabulary"), - MARKETPLACE_WHITEPAGES_PRO_CALLER_IDENTIFICATION("marketplace-whitepages-pro-caller-identification"), - MARKETPLACE_WHITEPAGES_PRO_PHONE_INTELLIGENCE("marketplace-whitepages-pro-phone-intelligence"), - MARKETPLACE_WHITEPAGES_PRO_PHONE_REPUTATION("marketplace-whitepages-pro-phone-reputation"), - MARKETPLACE_WOLFARM_SPOKEN_RESULTS("marketplace-wolfarm-spoken-results"), + MARKETPLACE_VOICEBASE_TRANSCRIPTION( + "marketplace-voicebase-transcription" + ), + MARKETPLACE_VOICEBASE_TRANSCRIPTION_CUSTOM_VOCABULARY( + "marketplace-voicebase-transcription-custom-vocabulary" + ), + MARKETPLACE_WHITEPAGES_PRO_CALLER_IDENTIFICATION( + "marketplace-whitepages-pro-caller-identification" + ), + MARKETPLACE_WHITEPAGES_PRO_PHONE_INTELLIGENCE( + "marketplace-whitepages-pro-phone-intelligence" + ), + MARKETPLACE_WHITEPAGES_PRO_PHONE_REPUTATION( + "marketplace-whitepages-pro-phone-reputation" + ), + MARKETPLACE_WOLFARM_SPOKEN_RESULTS( + "marketplace-wolfarm-spoken-results" + ), MARKETPLACE_WOLFRAM_SHORT_ANSWER("marketplace-wolfram-short-answer"), - MARKETPLACE_YTICA_CONTACT_CENTER_REPORTING_ANALYTICS("marketplace-ytica-contact-center-reporting-analytics"), + MARKETPLACE_YTICA_CONTACT_CENTER_REPORTING_ANALYTICS( + "marketplace-ytica-contact-center-reporting-analytics" + ), MEDIASTORAGE("mediastorage"), MMS("mms"), MMS_INBOUND("mms-inbound"), @@ -198,7 +260,9 @@ public enum Category { NUMBER_FORMAT_LOOKUPS("number-format-lookups"), PCHAT("pchat"), PCHAT_USERS("pchat-users"), - PEER_TO_PEER_ROOMS_PARTICIPANT_MINUTES("peer-to-peer-rooms-participant-minutes"), + PEER_TO_PEER_ROOMS_PARTICIPANT_MINUTES( + "peer-to-peer-rooms-participant-minutes" + ), PFAX("pfax"), PFAX_MINUTES("pfax-minutes"), PFAX_MINUTES_INBOUND("pfax-minutes-inbound"), @@ -245,7 +309,9 @@ public enum Category { SHORTCODES_VANITY("shortcodes-vanity"), SMALL_GROUP_ROOMS("small-group-rooms"), SMALL_GROUP_ROOMS_DATA_TRACK("small-group-rooms-data-track"), - SMALL_GROUP_ROOMS_PARTICIPANT_MINUTES("small-group-rooms-participant-minutes"), + SMALL_GROUP_ROOMS_PARTICIPANT_MINUTES( + "small-group-rooms-participant-minutes" + ), SMS("sms"), SMS_INBOUND("sms-inbound"), SMS_INBOUND_LONGCODE("sms-inbound-longcode"), @@ -262,7 +328,9 @@ public enum Category { SYNC("sync"), SYNC_ACTIONS("sync-actions"), SYNC_ENDPOINT_HOURS("sync-endpoint-hours"), - SYNC_ENDPOINT_HOURS_ABOVE_DAILY_CAP("sync-endpoint-hours-above-daily-cap"), + SYNC_ENDPOINT_HOURS_ABOVE_DAILY_CAP( + "sync-endpoint-hours-above-daily-cap" + ), TASKROUTER_TASKS("taskrouter-tasks"), TOTALPRICE("totalprice"), TRANSCRIPTIONS("transcriptions"), @@ -275,6 +343,7 @@ public enum Category { TRUNKING_RECORDINGS("trunking-recordings"), TRUNKING_SECURE("trunking-secure"), TRUNKING_TERMINATION("trunking-termination"), + TTS_GOOGLE("tts-google"), TURNMEGABYTES("turnmegabytes"), TURNMEGABYTES_AUSTRALIA("turnmegabytes-australia"), TURNMEGABYTES_BRASIL("turnmegabytes-brasil"), @@ -288,14 +357,27 @@ public enum Category { TWILIO_INTERCONNECT("twilio-interconnect"), VERIFY_PUSH("verify-push"), VERIFY_TOTP("verify-totp"), - VERIFY_WHATSAPP_CONVERSATIONS_BUSINESS_INITIATED("verify-whatsapp-conversations-business-initiated"), + VERIFY_WHATSAPP_CONVERSATIONS_BUSINESS_INITIATED( + "verify-whatsapp-conversations-business-initiated" + ), VIDEO_RECORDINGS("video-recordings"), VIRTUAL_AGENT("virtual-agent"), VOICE_INSIGHTS("voice-insights"), - VOICE_INSIGHTS_CLIENT_INSIGHTS_ON_DEMAND_MINUTE("voice-insights-client-insights-on-demand-minute"), - VOICE_INSIGHTS_PTSN_INSIGHTS_ON_DEMAND_MINUTE("voice-insights-ptsn-insights-on-demand-minute"), - VOICE_INSIGHTS_SIP_INTERFACE_INSIGHTS_ON_DEMAND_MINUTE("voice-insights-sip-interface-insights-on-demand-minute"), - VOICE_INSIGHTS_SIP_TRUNKING_INSIGHTS_ON_DEMAND_MINUTE("voice-insights-sip-trunking-insights-on-demand-minute"), + VOICE_INSIGHTS_CLIENT_INSIGHTS_ON_DEMAND_MINUTE( + "voice-insights-client-insights-on-demand-minute" + ), + VOICE_INSIGHTS_PTSN_INSIGHTS_ON_DEMAND_MINUTE( + "voice-insights-ptsn-insights-on-demand-minute" + ), + VOICE_INSIGHTS_SIP_INTERFACE_INSIGHTS_ON_DEMAND_MINUTE( + "voice-insights-sip-interface-insights-on-demand-minute" + ), + VOICE_INSIGHTS_SIP_TRUNKING_INSIGHTS_ON_DEMAND_MINUTE( + "voice-insights-sip-trunking-insights-on-demand-minute" + ), + VOICE_INTELLIGENCE("voice-intelligence"), + VOICE_INTELLIGENCE_TRANSCRIPTION("voice-intelligence-transcription"), + VOICE_INTELLIGENCE_OPERATORS("voice-intelligence-operators"), WIRELESS("wireless"), WIRELESS_ORDERS("wireless-orders"), WIRELESS_ORDERS_ARTWORK("wireless-orders-artwork"), @@ -306,29 +388,53 @@ public enum Category { WIRELESS_USAGE_COMMANDS("wireless-usage-commands"), WIRELESS_USAGE_COMMANDS_AFRICA("wireless-usage-commands-africa"), WIRELESS_USAGE_COMMANDS_ASIA("wireless-usage-commands-asia"), - WIRELESS_USAGE_COMMANDS_CENTRALANDSOUTHAMERICA("wireless-usage-commands-centralandsouthamerica"), + WIRELESS_USAGE_COMMANDS_CENTRALANDSOUTHAMERICA( + "wireless-usage-commands-centralandsouthamerica" + ), WIRELESS_USAGE_COMMANDS_EUROPE("wireless-usage-commands-europe"), WIRELESS_USAGE_COMMANDS_HOME("wireless-usage-commands-home"), - WIRELESS_USAGE_COMMANDS_NORTHAMERICA("wireless-usage-commands-northamerica"), + WIRELESS_USAGE_COMMANDS_NORTHAMERICA( + "wireless-usage-commands-northamerica" + ), WIRELESS_USAGE_COMMANDS_OCEANIA("wireless-usage-commands-oceania"), WIRELESS_USAGE_COMMANDS_ROAMING("wireless-usage-commands-roaming"), WIRELESS_USAGE_DATA("wireless-usage-data"), WIRELESS_USAGE_DATA_AFRICA("wireless-usage-data-africa"), WIRELESS_USAGE_DATA_ASIA("wireless-usage-data-asia"), - WIRELESS_USAGE_DATA_CENTRALANDSOUTHAMERICA("wireless-usage-data-centralandsouthamerica"), - WIRELESS_USAGE_DATA_CUSTOM_ADDITIONALMB("wireless-usage-data-custom-additionalmb"), - WIRELESS_USAGE_DATA_CUSTOM_FIRST5MB("wireless-usage-data-custom-first5mb"), - WIRELESS_USAGE_DATA_DOMESTIC_ROAMING("wireless-usage-data-domestic-roaming"), + WIRELESS_USAGE_DATA_CENTRALANDSOUTHAMERICA( + "wireless-usage-data-centralandsouthamerica" + ), + WIRELESS_USAGE_DATA_CUSTOM_ADDITIONALMB( + "wireless-usage-data-custom-additionalmb" + ), + WIRELESS_USAGE_DATA_CUSTOM_FIRST5MB( + "wireless-usage-data-custom-first5mb" + ), + WIRELESS_USAGE_DATA_DOMESTIC_ROAMING( + "wireless-usage-data-domestic-roaming" + ), WIRELESS_USAGE_DATA_EUROPE("wireless-usage-data-europe"), - WIRELESS_USAGE_DATA_INDIVIDUAL_ADDITIONALGB("wireless-usage-data-individual-additionalgb"), - WIRELESS_USAGE_DATA_INDIVIDUAL_FIRSTGB("wireless-usage-data-individual-firstgb"), - WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_CANADA("wireless-usage-data-international-roaming-canada"), - WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_INDIA("wireless-usage-data-international-roaming-india"), - WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_MEXICO("wireless-usage-data-international-roaming-mexico"), + WIRELESS_USAGE_DATA_INDIVIDUAL_ADDITIONALGB( + "wireless-usage-data-individual-additionalgb" + ), + WIRELESS_USAGE_DATA_INDIVIDUAL_FIRSTGB( + "wireless-usage-data-individual-firstgb" + ), + WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_CANADA( + "wireless-usage-data-international-roaming-canada" + ), + WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_INDIA( + "wireless-usage-data-international-roaming-india" + ), + WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_MEXICO( + "wireless-usage-data-international-roaming-mexico" + ), WIRELESS_USAGE_DATA_NORTHAMERICA("wireless-usage-data-northamerica"), WIRELESS_USAGE_DATA_OCEANIA("wireless-usage-data-oceania"), WIRELESS_USAGE_DATA_POOLED("wireless-usage-data-pooled"), - WIRELESS_USAGE_DATA_POOLED_DOWNLINK("wireless-usage-data-pooled-downlink"), + WIRELESS_USAGE_DATA_POOLED_DOWNLINK( + "wireless-usage-data-pooled-downlink" + ), WIRELESS_USAGE_DATA_POOLED_UPLINK("wireless-usage-data-pooled-uplink"), WIRELESS_USAGE_MRC("wireless-usage-mrc"), WIRELESS_USAGE_MRC_CUSTOM("wireless-usage-mrc-custom"), @@ -372,51 +478,25 @@ public static Category forValue(final String value) { @JsonCreator private Yearly( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("api_version") - final String apiVersion, - - @JsonProperty("as_of") - final String asOf, - - @JsonProperty("category") - final Yearly.Category category, - - @JsonProperty("count") - final String count, - - @JsonProperty("count_unit") - final String countUnit, - - @JsonProperty("description") - final String description, - - @JsonProperty("end_date") - final String endDate, - - @JsonProperty("price") - final BigDecimal price, - - @JsonProperty("price_unit") - @JsonDeserialize(using = com.twilio.converter.CurrencyDeserializer.class) - final Currency priceUnit, - - @JsonProperty("start_date") - final String startDate, - - @JsonProperty("subresource_uris") - final Map subresourceUris, - - @JsonProperty("uri") - final String uri, - - @JsonProperty("usage") - final String usage, - - @JsonProperty("usage_unit") - final String usageUnit + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("api_version") final String apiVersion, + @JsonProperty("as_of") final String asOf, + @JsonProperty("category") final Yearly.Category category, + @JsonProperty("count") final String count, + @JsonProperty("count_unit") final String countUnit, + @JsonProperty("description") final String description, + @JsonProperty("end_date") final String endDate, + @JsonProperty("price") final BigDecimal price, + @JsonProperty("price_unit") @JsonDeserialize( + using = com.twilio.converter.CurrencyDeserializer.class + ) final Currency priceUnit, + @JsonProperty("start_date") final String startDate, + @JsonProperty( + "subresource_uris" + ) final Map subresourceUris, + @JsonProperty("uri") final String uri, + @JsonProperty("usage") final String usage, + @JsonProperty("usage_unit") final String usageUnit ) { this.accountSid = accountSid; this.apiVersion = apiVersion; @@ -435,55 +515,69 @@ private Yearly( this.usageUnit = usageUnit; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getApiVersion() { - return this.apiVersion; - } - public final String getAsOf() { - return this.asOf; - } - public final Yearly.Category getCategory() { - return this.category; - } - public final String getCount() { - return this.count; - } - public final String getCountUnit() { - return this.countUnit; - } - public final String getDescription() { - return this.description; - } - public final LocalDate getEndDate() { - return this.endDate; - } - public final BigDecimal getPrice() { - return this.price; - } - public final Currency getPriceUnit() { - return this.priceUnit; - } - public final LocalDate getStartDate() { - return this.startDate; - } - public final Map getSubresourceUris() { - return this.subresourceUris; - } - public final String getUri() { - return this.uri; - } - public final String getUsage() { - return this.usage; - } - public final String getUsageUnit() { - return this.usageUnit; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getApiVersion() { + return this.apiVersion; + } + + public final String getAsOf() { + return this.asOf; + } + + public final Yearly.Category getCategory() { + return this.category; + } + + public final String getCount() { + return this.count; + } + + public final String getCountUnit() { + return this.countUnit; + } + + public final String getDescription() { + return this.description; + } + + public final LocalDate getEndDate() { + return this.endDate; + } + + public final BigDecimal getPrice() { + return this.price; + } + + public final Currency getPriceUnit() { + return this.priceUnit; + } + + public final LocalDate getStartDate() { + return this.startDate; + } + + public final Map getSubresourceUris() { + return this.subresourceUris; + } + + public final String getUri() { + return this.uri; + } + + public final String getUsage() { + return this.usage; + } + + public final String getUsageUnit() { + return this.usageUnit; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -493,13 +587,43 @@ public boolean equals(final Object o) { Yearly other = (Yearly) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(apiVersion, other.apiVersion) && Objects.equals(asOf, other.asOf) && Objects.equals(category, other.category) && Objects.equals(count, other.count) && Objects.equals(countUnit, other.countUnit) && Objects.equals(description, other.description) && Objects.equals(endDate, other.endDate) && Objects.equals(price, other.price) && Objects.equals(priceUnit, other.priceUnit) && Objects.equals(startDate, other.startDate) && Objects.equals(subresourceUris, other.subresourceUris) && Objects.equals(uri, other.uri) && Objects.equals(usage, other.usage) && Objects.equals(usageUnit, other.usageUnit) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(apiVersion, other.apiVersion) && + Objects.equals(asOf, other.asOf) && + Objects.equals(category, other.category) && + Objects.equals(count, other.count) && + Objects.equals(countUnit, other.countUnit) && + Objects.equals(description, other.description) && + Objects.equals(endDate, other.endDate) && + Objects.equals(price, other.price) && + Objects.equals(priceUnit, other.priceUnit) && + Objects.equals(startDate, other.startDate) && + Objects.equals(subresourceUris, other.subresourceUris) && + Objects.equals(uri, other.uri) && + Objects.equals(usage, other.usage) && + Objects.equals(usageUnit, other.usageUnit) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, apiVersion, asOf, category, count, countUnit, description, endDate, price, priceUnit, startDate, subresourceUris, uri, usage, usageUnit); + return Objects.hash( + accountSid, + apiVersion, + asOf, + category, + count, + countUnit, + description, + endDate, + price, + priceUnit, + startDate, + subresourceUris, + uri, + usage, + usageUnit + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/YearlyReader.java b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/YearlyReader.java index 26a3f84c8c..e40569da65 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/YearlyReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/YearlyReader.java @@ -14,8 +14,10 @@ package com.twilio.rest.api.v2010.account.usage.record; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,13 +26,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; import java.time.LocalDate; -import com.twilio.converter.DateConverter; - - public class YearlyReader extends Reader { + private String pathAccountSid; private Yearly.Category category; private LocalDate startDate; @@ -38,29 +37,35 @@ public class YearlyReader extends Reader { private Boolean includeSubaccounts; private Integer pageSize; - public YearlyReader(){ - } - public YearlyReader(final String pathAccountSid){ + public YearlyReader() {} + + public YearlyReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - public YearlyReader setCategory(final Yearly.Category category){ + public YearlyReader setCategory(final Yearly.Category category) { this.category = category; return this; } - public YearlyReader setStartDate(final LocalDate startDate){ + + public YearlyReader setStartDate(final LocalDate startDate) { this.startDate = startDate; return this; } - public YearlyReader setEndDate(final LocalDate endDate){ + + public YearlyReader setEndDate(final LocalDate endDate) { this.endDate = endDate; return this; } - public YearlyReader setIncludeSubaccounts(final Boolean includeSubaccounts){ + + public YearlyReader setIncludeSubaccounts( + final Boolean includeSubaccounts + ) { this.includeSubaccounts = includeSubaccounts; return this; } - public YearlyReader setPageSize(final Integer pageSize){ + + public YearlyReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -71,9 +76,17 @@ public ResourceSet read(final TwilioRestClient client) { } public Page firstPage(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/Usage/Records/Yearly.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); + String path = + "/2010-04-01/Accounts/{AccountSid}/Usage/Records/Yearly.json"; + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -85,13 +98,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Yearly read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Yearly read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -107,7 +128,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.API.toString()) @@ -115,9 +139,11 @@ public Page previousPage(final Page page, final TwilioRestClient return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.API.toString()) @@ -126,37 +152,44 @@ public Page nextPage(final Page page, final TwilioRestClient cli } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (category != null) { - request.addQueryParam("Category", category.toString()); } if (startDate != null) { - request.addQueryParam("StartDate", DateConverter.dateStringFromLocalDate(startDate)); + request.addQueryParam( + "StartDate", + DateConverter.dateStringFromLocalDate(startDate) + ); } if (endDate != null) { - request.addQueryParam("EndDate", DateConverter.dateStringFromLocalDate(endDate)); + request.addQueryParam( + "EndDate", + DateConverter.dateStringFromLocalDate(endDate) + ); } if (includeSubaccounts != null) { - - request.addQueryParam("IncludeSubaccounts", includeSubaccounts.toString()); + request.addQueryParam( + "IncludeSubaccounts", + includeSubaccounts.toString() + ); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/Yesterday.java b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/Yesterday.java index f45439194a..2de34112f6 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/Yesterday.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/Yesterday.java @@ -20,49 +20,49 @@ import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.twilio.base.Resource; -import java.util.Currency; +import com.twilio.converter.CurrencyDeserializer; import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; -import com.twilio.converter.CurrencyDeserializer; import com.twilio.exception.ApiConnectionException; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; - +import java.math.BigDecimal; +import java.time.LocalDate; +import java.util.Currency; import java.util.Map; -import java.util.Objects; - - import java.util.Map; -import java.time.LocalDate; -import java.math.BigDecimal; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Yesterday extends Resource { + private static final long serialVersionUID = 252061486411277L; - public static YesterdayReader reader(){ + public static YesterdayReader reader() { return new YesterdayReader(); } - public static YesterdayReader reader(final String pathAccountSid){ + + public static YesterdayReader reader(final String pathAccountSid) { return new YesterdayReader(pathAccountSid); } /** - * Converts a JSON String into a Yesterday object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Yesterday object represented by the provided JSON - */ - public static Yesterday fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Yesterday object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Yesterday object represented by the provided JSON + */ + public static Yesterday fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Yesterday.class); @@ -74,14 +74,17 @@ public static Yesterday fromJson(final String json, final ObjectMapper objectMap } /** - * Converts a JSON InputStream into a Yesterday object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Yesterday object represented by the provided JSON - */ - public static Yesterday fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Yesterday object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Yesterday object represented by the provided JSON + */ + public static Yesterday fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Yesterday.class); @@ -91,6 +94,7 @@ public static Yesterday fromJson(final InputStream json, final ObjectMapper obje throw new ApiConnectionException(e.getMessage(), e); } } + public enum Category { A2P_REGISTRATION_FEES("a2p-registration-fees"), AGENT_CONFERENCE("agent-conference"), @@ -122,7 +126,9 @@ public enum Category { CONVERSATIONS("conversations"), CONVERSATIONS_API_REQUESTS("conversations-api-requests"), CONVERSATIONS_CONVERSATION_EVENTS("conversations-conversation-events"), - CONVERSATIONS_ENDPOINT_CONNECTIVITY("conversations-endpoint-connectivity"), + CONVERSATIONS_ENDPOINT_CONNECTIVITY( + "conversations-endpoint-connectivity" + ), CONVERSATIONS_EVENTS("conversations-events"), CONVERSATIONS_PARTICIPANT_EVENTS("conversations-participant-events"), CONVERSATIONS_PARTICIPANTS("conversations-participants"), @@ -131,7 +137,9 @@ public enum Category { FRAUD_LOOKUPS("fraud-lookups"), GROUP_ROOMS("group-rooms"), GROUP_ROOMS_DATA_TRACK("group-rooms-data-track"), - GROUP_ROOMS_ENCRYPTED_MEDIA_RECORDED("group-rooms-encrypted-media-recorded"), + GROUP_ROOMS_ENCRYPTED_MEDIA_RECORDED( + "group-rooms-encrypted-media-recorded" + ), GROUP_ROOMS_MEDIA_DOWNLOADED("group-rooms-media-downloaded"), GROUP_ROOMS_MEDIA_RECORDED("group-rooms-media-recorded"), GROUP_ROOMS_MEDIA_ROUTED("group-rooms-media-routed"), @@ -141,45 +149,99 @@ public enum Category { IMP_V1_USAGE("imp-v1-usage"), LOOKUPS("lookups"), MARKETPLACE("marketplace"), - MARKETPLACE_ALGORITHMIA_NAMED_ENTITY_RECOGNITION("marketplace-algorithmia-named-entity-recognition"), + MARKETPLACE_ALGORITHMIA_NAMED_ENTITY_RECOGNITION( + "marketplace-algorithmia-named-entity-recognition" + ), MARKETPLACE_CADENCE_TRANSCRIPTION("marketplace-cadence-transcription"), MARKETPLACE_CADENCE_TRANSLATION("marketplace-cadence-translation"), MARKETPLACE_CAPIO_SPEECH_TO_TEXT("marketplace-capio-speech-to-text"), MARKETPLACE_CONVRIZA_ABABA("marketplace-convriza-ababa"), - MARKETPLACE_DEEPGRAM_PHRASE_DETECTOR("marketplace-deepgram-phrase-detector"), - MARKETPLACE_DIGITAL_SEGMENT_BUSINESS_INFO("marketplace-digital-segment-business-info"), - MARKETPLACE_FACEBOOK_OFFLINE_CONVERSIONS("marketplace-facebook-offline-conversions"), + MARKETPLACE_DEEPGRAM_PHRASE_DETECTOR( + "marketplace-deepgram-phrase-detector" + ), + MARKETPLACE_DIGITAL_SEGMENT_BUSINESS_INFO( + "marketplace-digital-segment-business-info" + ), + MARKETPLACE_FACEBOOK_OFFLINE_CONVERSIONS( + "marketplace-facebook-offline-conversions" + ), MARKETPLACE_GOOGLE_SPEECH_TO_TEXT("marketplace-google-speech-to-text"), - MARKETPLACE_IBM_WATSON_MESSAGE_INSIGHTS("marketplace-ibm-watson-message-insights"), - MARKETPLACE_IBM_WATSON_MESSAGE_SENTIMENT("marketplace-ibm-watson-message-sentiment"), - MARKETPLACE_IBM_WATSON_RECORDING_ANALYSIS("marketplace-ibm-watson-recording-analysis"), - MARKETPLACE_IBM_WATSON_TONE_ANALYZER("marketplace-ibm-watson-tone-analyzer"), + MARKETPLACE_IBM_WATSON_MESSAGE_INSIGHTS( + "marketplace-ibm-watson-message-insights" + ), + MARKETPLACE_IBM_WATSON_MESSAGE_SENTIMENT( + "marketplace-ibm-watson-message-sentiment" + ), + MARKETPLACE_IBM_WATSON_RECORDING_ANALYSIS( + "marketplace-ibm-watson-recording-analysis" + ), + MARKETPLACE_IBM_WATSON_TONE_ANALYZER( + "marketplace-ibm-watson-tone-analyzer" + ), MARKETPLACE_ICEHOOK_SYSTEMS_SCOUT("marketplace-icehook-systems-scout"), - MARKETPLACE_INFOGROUP_DATAAXLE_BIZINFO("marketplace-infogroup-dataaxle-bizinfo"), - MARKETPLACE_KEEN_IO_CONTACT_CENTER_ANALYTICS("marketplace-keen-io-contact-center-analytics"), + MARKETPLACE_INFOGROUP_DATAAXLE_BIZINFO( + "marketplace-infogroup-dataaxle-bizinfo" + ), + MARKETPLACE_KEEN_IO_CONTACT_CENTER_ANALYTICS( + "marketplace-keen-io-contact-center-analytics" + ), MARKETPLACE_MARCHEX_CLEANCALL("marketplace-marchex-cleancall"), - MARKETPLACE_MARCHEX_SENTIMENT_ANALYSIS_FOR_SMS("marketplace-marchex-sentiment-analysis-for-sms"), - MARKETPLACE_MARKETPLACE_NEXTCALLER_SOCIAL_ID("marketplace-marketplace-nextcaller-social-id"), - MARKETPLACE_MOBILE_COMMONS_OPT_OUT_CLASSIFIER("marketplace-mobile-commons-opt-out-classifier"), - MARKETPLACE_NEXIWAVE_VOICEMAIL_TO_TEXT("marketplace-nexiwave-voicemail-to-text"), - MARKETPLACE_NEXTCALLER_ADVANCED_CALLER_IDENTIFICATION("marketplace-nextcaller-advanced-caller-identification"), + MARKETPLACE_MARCHEX_SENTIMENT_ANALYSIS_FOR_SMS( + "marketplace-marchex-sentiment-analysis-for-sms" + ), + MARKETPLACE_MARKETPLACE_NEXTCALLER_SOCIAL_ID( + "marketplace-marketplace-nextcaller-social-id" + ), + MARKETPLACE_MOBILE_COMMONS_OPT_OUT_CLASSIFIER( + "marketplace-mobile-commons-opt-out-classifier" + ), + MARKETPLACE_NEXIWAVE_VOICEMAIL_TO_TEXT( + "marketplace-nexiwave-voicemail-to-text" + ), + MARKETPLACE_NEXTCALLER_ADVANCED_CALLER_IDENTIFICATION( + "marketplace-nextcaller-advanced-caller-identification" + ), MARKETPLACE_NOMOROBO_SPAM_SCORE("marketplace-nomorobo-spam-score"), - MARKETPLACE_PAYFONE_TCPA_COMPLIANCE("marketplace-payfone-tcpa-compliance"), - MARKETPLACE_REMEETING_AUTOMATIC_SPEECH_RECOGNITION("marketplace-remeeting-automatic-speech-recognition"), - MARKETPLACE_TCPA_DEFENSE_SOLUTIONS_BLACKLIST_FEED("marketplace-tcpa-defense-solutions-blacklist-feed"), + MARKETPLACE_PAYFONE_TCPA_COMPLIANCE( + "marketplace-payfone-tcpa-compliance" + ), + MARKETPLACE_REMEETING_AUTOMATIC_SPEECH_RECOGNITION( + "marketplace-remeeting-automatic-speech-recognition" + ), + MARKETPLACE_TCPA_DEFENSE_SOLUTIONS_BLACKLIST_FEED( + "marketplace-tcpa-defense-solutions-blacklist-feed" + ), MARKETPLACE_TELO_OPENCNAM("marketplace-telo-opencnam"), MARKETPLACE_TRUECNAM_TRUE_SPAM("marketplace-truecnam-true-spam"), - MARKETPLACE_TWILIO_CALLER_NAME_LOOKUP_US("marketplace-twilio-caller-name-lookup-us"), - MARKETPLACE_TWILIO_CARRIER_INFORMATION_LOOKUP("marketplace-twilio-carrier-information-lookup"), + MARKETPLACE_TWILIO_CALLER_NAME_LOOKUP_US( + "marketplace-twilio-caller-name-lookup-us" + ), + MARKETPLACE_TWILIO_CARRIER_INFORMATION_LOOKUP( + "marketplace-twilio-carrier-information-lookup" + ), MARKETPLACE_VOICEBASE_PCI("marketplace-voicebase-pci"), - MARKETPLACE_VOICEBASE_TRANSCRIPTION("marketplace-voicebase-transcription"), - MARKETPLACE_VOICEBASE_TRANSCRIPTION_CUSTOM_VOCABULARY("marketplace-voicebase-transcription-custom-vocabulary"), - MARKETPLACE_WHITEPAGES_PRO_CALLER_IDENTIFICATION("marketplace-whitepages-pro-caller-identification"), - MARKETPLACE_WHITEPAGES_PRO_PHONE_INTELLIGENCE("marketplace-whitepages-pro-phone-intelligence"), - MARKETPLACE_WHITEPAGES_PRO_PHONE_REPUTATION("marketplace-whitepages-pro-phone-reputation"), - MARKETPLACE_WOLFARM_SPOKEN_RESULTS("marketplace-wolfarm-spoken-results"), + MARKETPLACE_VOICEBASE_TRANSCRIPTION( + "marketplace-voicebase-transcription" + ), + MARKETPLACE_VOICEBASE_TRANSCRIPTION_CUSTOM_VOCABULARY( + "marketplace-voicebase-transcription-custom-vocabulary" + ), + MARKETPLACE_WHITEPAGES_PRO_CALLER_IDENTIFICATION( + "marketplace-whitepages-pro-caller-identification" + ), + MARKETPLACE_WHITEPAGES_PRO_PHONE_INTELLIGENCE( + "marketplace-whitepages-pro-phone-intelligence" + ), + MARKETPLACE_WHITEPAGES_PRO_PHONE_REPUTATION( + "marketplace-whitepages-pro-phone-reputation" + ), + MARKETPLACE_WOLFARM_SPOKEN_RESULTS( + "marketplace-wolfarm-spoken-results" + ), MARKETPLACE_WOLFRAM_SHORT_ANSWER("marketplace-wolfram-short-answer"), - MARKETPLACE_YTICA_CONTACT_CENTER_REPORTING_ANALYTICS("marketplace-ytica-contact-center-reporting-analytics"), + MARKETPLACE_YTICA_CONTACT_CENTER_REPORTING_ANALYTICS( + "marketplace-ytica-contact-center-reporting-analytics" + ), MEDIASTORAGE("mediastorage"), MMS("mms"), MMS_INBOUND("mms-inbound"), @@ -198,7 +260,9 @@ public enum Category { NUMBER_FORMAT_LOOKUPS("number-format-lookups"), PCHAT("pchat"), PCHAT_USERS("pchat-users"), - PEER_TO_PEER_ROOMS_PARTICIPANT_MINUTES("peer-to-peer-rooms-participant-minutes"), + PEER_TO_PEER_ROOMS_PARTICIPANT_MINUTES( + "peer-to-peer-rooms-participant-minutes" + ), PFAX("pfax"), PFAX_MINUTES("pfax-minutes"), PFAX_MINUTES_INBOUND("pfax-minutes-inbound"), @@ -245,7 +309,9 @@ public enum Category { SHORTCODES_VANITY("shortcodes-vanity"), SMALL_GROUP_ROOMS("small-group-rooms"), SMALL_GROUP_ROOMS_DATA_TRACK("small-group-rooms-data-track"), - SMALL_GROUP_ROOMS_PARTICIPANT_MINUTES("small-group-rooms-participant-minutes"), + SMALL_GROUP_ROOMS_PARTICIPANT_MINUTES( + "small-group-rooms-participant-minutes" + ), SMS("sms"), SMS_INBOUND("sms-inbound"), SMS_INBOUND_LONGCODE("sms-inbound-longcode"), @@ -262,7 +328,9 @@ public enum Category { SYNC("sync"), SYNC_ACTIONS("sync-actions"), SYNC_ENDPOINT_HOURS("sync-endpoint-hours"), - SYNC_ENDPOINT_HOURS_ABOVE_DAILY_CAP("sync-endpoint-hours-above-daily-cap"), + SYNC_ENDPOINT_HOURS_ABOVE_DAILY_CAP( + "sync-endpoint-hours-above-daily-cap" + ), TASKROUTER_TASKS("taskrouter-tasks"), TOTALPRICE("totalprice"), TRANSCRIPTIONS("transcriptions"), @@ -275,6 +343,7 @@ public enum Category { TRUNKING_RECORDINGS("trunking-recordings"), TRUNKING_SECURE("trunking-secure"), TRUNKING_TERMINATION("trunking-termination"), + TTS_GOOGLE("tts-google"), TURNMEGABYTES("turnmegabytes"), TURNMEGABYTES_AUSTRALIA("turnmegabytes-australia"), TURNMEGABYTES_BRASIL("turnmegabytes-brasil"), @@ -288,14 +357,27 @@ public enum Category { TWILIO_INTERCONNECT("twilio-interconnect"), VERIFY_PUSH("verify-push"), VERIFY_TOTP("verify-totp"), - VERIFY_WHATSAPP_CONVERSATIONS_BUSINESS_INITIATED("verify-whatsapp-conversations-business-initiated"), + VERIFY_WHATSAPP_CONVERSATIONS_BUSINESS_INITIATED( + "verify-whatsapp-conversations-business-initiated" + ), VIDEO_RECORDINGS("video-recordings"), VIRTUAL_AGENT("virtual-agent"), VOICE_INSIGHTS("voice-insights"), - VOICE_INSIGHTS_CLIENT_INSIGHTS_ON_DEMAND_MINUTE("voice-insights-client-insights-on-demand-minute"), - VOICE_INSIGHTS_PTSN_INSIGHTS_ON_DEMAND_MINUTE("voice-insights-ptsn-insights-on-demand-minute"), - VOICE_INSIGHTS_SIP_INTERFACE_INSIGHTS_ON_DEMAND_MINUTE("voice-insights-sip-interface-insights-on-demand-minute"), - VOICE_INSIGHTS_SIP_TRUNKING_INSIGHTS_ON_DEMAND_MINUTE("voice-insights-sip-trunking-insights-on-demand-minute"), + VOICE_INSIGHTS_CLIENT_INSIGHTS_ON_DEMAND_MINUTE( + "voice-insights-client-insights-on-demand-minute" + ), + VOICE_INSIGHTS_PTSN_INSIGHTS_ON_DEMAND_MINUTE( + "voice-insights-ptsn-insights-on-demand-minute" + ), + VOICE_INSIGHTS_SIP_INTERFACE_INSIGHTS_ON_DEMAND_MINUTE( + "voice-insights-sip-interface-insights-on-demand-minute" + ), + VOICE_INSIGHTS_SIP_TRUNKING_INSIGHTS_ON_DEMAND_MINUTE( + "voice-insights-sip-trunking-insights-on-demand-minute" + ), + VOICE_INTELLIGENCE("voice-intelligence"), + VOICE_INTELLIGENCE_TRANSCRIPTION("voice-intelligence-transcription"), + VOICE_INTELLIGENCE_OPERATORS("voice-intelligence-operators"), WIRELESS("wireless"), WIRELESS_ORDERS("wireless-orders"), WIRELESS_ORDERS_ARTWORK("wireless-orders-artwork"), @@ -306,29 +388,53 @@ public enum Category { WIRELESS_USAGE_COMMANDS("wireless-usage-commands"), WIRELESS_USAGE_COMMANDS_AFRICA("wireless-usage-commands-africa"), WIRELESS_USAGE_COMMANDS_ASIA("wireless-usage-commands-asia"), - WIRELESS_USAGE_COMMANDS_CENTRALANDSOUTHAMERICA("wireless-usage-commands-centralandsouthamerica"), + WIRELESS_USAGE_COMMANDS_CENTRALANDSOUTHAMERICA( + "wireless-usage-commands-centralandsouthamerica" + ), WIRELESS_USAGE_COMMANDS_EUROPE("wireless-usage-commands-europe"), WIRELESS_USAGE_COMMANDS_HOME("wireless-usage-commands-home"), - WIRELESS_USAGE_COMMANDS_NORTHAMERICA("wireless-usage-commands-northamerica"), + WIRELESS_USAGE_COMMANDS_NORTHAMERICA( + "wireless-usage-commands-northamerica" + ), WIRELESS_USAGE_COMMANDS_OCEANIA("wireless-usage-commands-oceania"), WIRELESS_USAGE_COMMANDS_ROAMING("wireless-usage-commands-roaming"), WIRELESS_USAGE_DATA("wireless-usage-data"), WIRELESS_USAGE_DATA_AFRICA("wireless-usage-data-africa"), WIRELESS_USAGE_DATA_ASIA("wireless-usage-data-asia"), - WIRELESS_USAGE_DATA_CENTRALANDSOUTHAMERICA("wireless-usage-data-centralandsouthamerica"), - WIRELESS_USAGE_DATA_CUSTOM_ADDITIONALMB("wireless-usage-data-custom-additionalmb"), - WIRELESS_USAGE_DATA_CUSTOM_FIRST5MB("wireless-usage-data-custom-first5mb"), - WIRELESS_USAGE_DATA_DOMESTIC_ROAMING("wireless-usage-data-domestic-roaming"), + WIRELESS_USAGE_DATA_CENTRALANDSOUTHAMERICA( + "wireless-usage-data-centralandsouthamerica" + ), + WIRELESS_USAGE_DATA_CUSTOM_ADDITIONALMB( + "wireless-usage-data-custom-additionalmb" + ), + WIRELESS_USAGE_DATA_CUSTOM_FIRST5MB( + "wireless-usage-data-custom-first5mb" + ), + WIRELESS_USAGE_DATA_DOMESTIC_ROAMING( + "wireless-usage-data-domestic-roaming" + ), WIRELESS_USAGE_DATA_EUROPE("wireless-usage-data-europe"), - WIRELESS_USAGE_DATA_INDIVIDUAL_ADDITIONALGB("wireless-usage-data-individual-additionalgb"), - WIRELESS_USAGE_DATA_INDIVIDUAL_FIRSTGB("wireless-usage-data-individual-firstgb"), - WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_CANADA("wireless-usage-data-international-roaming-canada"), - WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_INDIA("wireless-usage-data-international-roaming-india"), - WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_MEXICO("wireless-usage-data-international-roaming-mexico"), + WIRELESS_USAGE_DATA_INDIVIDUAL_ADDITIONALGB( + "wireless-usage-data-individual-additionalgb" + ), + WIRELESS_USAGE_DATA_INDIVIDUAL_FIRSTGB( + "wireless-usage-data-individual-firstgb" + ), + WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_CANADA( + "wireless-usage-data-international-roaming-canada" + ), + WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_INDIA( + "wireless-usage-data-international-roaming-india" + ), + WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_MEXICO( + "wireless-usage-data-international-roaming-mexico" + ), WIRELESS_USAGE_DATA_NORTHAMERICA("wireless-usage-data-northamerica"), WIRELESS_USAGE_DATA_OCEANIA("wireless-usage-data-oceania"), WIRELESS_USAGE_DATA_POOLED("wireless-usage-data-pooled"), - WIRELESS_USAGE_DATA_POOLED_DOWNLINK("wireless-usage-data-pooled-downlink"), + WIRELESS_USAGE_DATA_POOLED_DOWNLINK( + "wireless-usage-data-pooled-downlink" + ), WIRELESS_USAGE_DATA_POOLED_UPLINK("wireless-usage-data-pooled-uplink"), WIRELESS_USAGE_MRC("wireless-usage-mrc"), WIRELESS_USAGE_MRC_CUSTOM("wireless-usage-mrc-custom"), @@ -372,51 +478,25 @@ public static Category forValue(final String value) { @JsonCreator private Yesterday( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("api_version") - final String apiVersion, - - @JsonProperty("as_of") - final String asOf, - - @JsonProperty("category") - final Yesterday.Category category, - - @JsonProperty("count") - final String count, - - @JsonProperty("count_unit") - final String countUnit, - - @JsonProperty("description") - final String description, - - @JsonProperty("end_date") - final String endDate, - - @JsonProperty("price") - final BigDecimal price, - - @JsonProperty("price_unit") - @JsonDeserialize(using = com.twilio.converter.CurrencyDeserializer.class) - final Currency priceUnit, - - @JsonProperty("start_date") - final String startDate, - - @JsonProperty("subresource_uris") - final Map subresourceUris, - - @JsonProperty("uri") - final String uri, - - @JsonProperty("usage") - final String usage, - - @JsonProperty("usage_unit") - final String usageUnit + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("api_version") final String apiVersion, + @JsonProperty("as_of") final String asOf, + @JsonProperty("category") final Yesterday.Category category, + @JsonProperty("count") final String count, + @JsonProperty("count_unit") final String countUnit, + @JsonProperty("description") final String description, + @JsonProperty("end_date") final String endDate, + @JsonProperty("price") final BigDecimal price, + @JsonProperty("price_unit") @JsonDeserialize( + using = com.twilio.converter.CurrencyDeserializer.class + ) final Currency priceUnit, + @JsonProperty("start_date") final String startDate, + @JsonProperty( + "subresource_uris" + ) final Map subresourceUris, + @JsonProperty("uri") final String uri, + @JsonProperty("usage") final String usage, + @JsonProperty("usage_unit") final String usageUnit ) { this.accountSid = accountSid; this.apiVersion = apiVersion; @@ -435,55 +515,69 @@ private Yesterday( this.usageUnit = usageUnit; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getApiVersion() { - return this.apiVersion; - } - public final String getAsOf() { - return this.asOf; - } - public final Yesterday.Category getCategory() { - return this.category; - } - public final String getCount() { - return this.count; - } - public final String getCountUnit() { - return this.countUnit; - } - public final String getDescription() { - return this.description; - } - public final LocalDate getEndDate() { - return this.endDate; - } - public final BigDecimal getPrice() { - return this.price; - } - public final Currency getPriceUnit() { - return this.priceUnit; - } - public final LocalDate getStartDate() { - return this.startDate; - } - public final Map getSubresourceUris() { - return this.subresourceUris; - } - public final String getUri() { - return this.uri; - } - public final String getUsage() { - return this.usage; - } - public final String getUsageUnit() { - return this.usageUnit; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getApiVersion() { + return this.apiVersion; + } + + public final String getAsOf() { + return this.asOf; + } + + public final Yesterday.Category getCategory() { + return this.category; + } + + public final String getCount() { + return this.count; + } + + public final String getCountUnit() { + return this.countUnit; + } + + public final String getDescription() { + return this.description; + } + + public final LocalDate getEndDate() { + return this.endDate; + } + + public final BigDecimal getPrice() { + return this.price; + } + + public final Currency getPriceUnit() { + return this.priceUnit; + } + + public final LocalDate getStartDate() { + return this.startDate; + } + + public final Map getSubresourceUris() { + return this.subresourceUris; + } + + public final String getUri() { + return this.uri; + } + + public final String getUsage() { + return this.usage; + } + + public final String getUsageUnit() { + return this.usageUnit; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -493,13 +587,43 @@ public boolean equals(final Object o) { Yesterday other = (Yesterday) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(apiVersion, other.apiVersion) && Objects.equals(asOf, other.asOf) && Objects.equals(category, other.category) && Objects.equals(count, other.count) && Objects.equals(countUnit, other.countUnit) && Objects.equals(description, other.description) && Objects.equals(endDate, other.endDate) && Objects.equals(price, other.price) && Objects.equals(priceUnit, other.priceUnit) && Objects.equals(startDate, other.startDate) && Objects.equals(subresourceUris, other.subresourceUris) && Objects.equals(uri, other.uri) && Objects.equals(usage, other.usage) && Objects.equals(usageUnit, other.usageUnit) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(apiVersion, other.apiVersion) && + Objects.equals(asOf, other.asOf) && + Objects.equals(category, other.category) && + Objects.equals(count, other.count) && + Objects.equals(countUnit, other.countUnit) && + Objects.equals(description, other.description) && + Objects.equals(endDate, other.endDate) && + Objects.equals(price, other.price) && + Objects.equals(priceUnit, other.priceUnit) && + Objects.equals(startDate, other.startDate) && + Objects.equals(subresourceUris, other.subresourceUris) && + Objects.equals(uri, other.uri) && + Objects.equals(usage, other.usage) && + Objects.equals(usageUnit, other.usageUnit) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, apiVersion, asOf, category, count, countUnit, description, endDate, price, priceUnit, startDate, subresourceUris, uri, usage, usageUnit); + return Objects.hash( + accountSid, + apiVersion, + asOf, + category, + count, + countUnit, + description, + endDate, + price, + priceUnit, + startDate, + subresourceUris, + uri, + usage, + usageUnit + ); } - } - diff --git a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/YesterdayReader.java b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/YesterdayReader.java index f7d47843af..d848d0c03e 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/YesterdayReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/YesterdayReader.java @@ -14,8 +14,10 @@ package com.twilio.rest.api.v2010.account.usage.record; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,13 +26,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; import java.time.LocalDate; -import com.twilio.converter.DateConverter; - - public class YesterdayReader extends Reader { + private String pathAccountSid; private Yesterday.Category category; private LocalDate startDate; @@ -38,29 +37,35 @@ public class YesterdayReader extends Reader { private Boolean includeSubaccounts; private Integer pageSize; - public YesterdayReader(){ - } - public YesterdayReader(final String pathAccountSid){ + public YesterdayReader() {} + + public YesterdayReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - public YesterdayReader setCategory(final Yesterday.Category category){ + public YesterdayReader setCategory(final Yesterday.Category category) { this.category = category; return this; } - public YesterdayReader setStartDate(final LocalDate startDate){ + + public YesterdayReader setStartDate(final LocalDate startDate) { this.startDate = startDate; return this; } - public YesterdayReader setEndDate(final LocalDate endDate){ + + public YesterdayReader setEndDate(final LocalDate endDate) { this.endDate = endDate; return this; } - public YesterdayReader setIncludeSubaccounts(final Boolean includeSubaccounts){ + + public YesterdayReader setIncludeSubaccounts( + final Boolean includeSubaccounts + ) { this.includeSubaccounts = includeSubaccounts; return this; } - public YesterdayReader setPageSize(final Integer pageSize){ + + public YesterdayReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -71,9 +76,17 @@ public ResourceSet read(final TwilioRestClient client) { } public Page firstPage(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/Usage/Records/Yesterday.json"; - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - path = path.replace("{"+"AccountSid"+"}", this.pathAccountSid.toString()); + String path = + "/2010-04-01/Accounts/{AccountSid}/Usage/Records/Yesterday.json"; + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -85,13 +98,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Yesterday read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Yesterday read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -107,7 +128,10 @@ private Page pageForRequest(final TwilioRestClient client, final Requ } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.API.toString()) @@ -115,9 +139,11 @@ public Page previousPage(final Page page, final TwilioRest return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.API.toString()) @@ -126,37 +152,44 @@ public Page nextPage(final Page page, final TwilioRestClie } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (category != null) { - request.addQueryParam("Category", category.toString()); } if (startDate != null) { - request.addQueryParam("StartDate", DateConverter.dateStringFromLocalDate(startDate)); + request.addQueryParam( + "StartDate", + DateConverter.dateStringFromLocalDate(startDate) + ); } if (endDate != null) { - request.addQueryParam("EndDate", DateConverter.dateStringFromLocalDate(endDate)); + request.addQueryParam( + "EndDate", + DateConverter.dateStringFromLocalDate(endDate) + ); } if (includeSubaccounts != null) { - - request.addQueryParam("IncludeSubaccounts", includeSubaccounts.toString()); + request.addQueryParam( + "IncludeSubaccounts", + includeSubaccounts.toString() + ); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/autopilot/v1/Assistant.java b/src/main/java/com/twilio/rest/autopilot/v1/Assistant.java index 0b61f1c078..4779c4f7b4 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/Assistant.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/Assistant.java @@ -23,55 +23,54 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Assistant extends Resource { + private static final long serialVersionUID = 228555803413487L; - public static AssistantCreator creator(){ + public static AssistantCreator creator() { return new AssistantCreator(); } - public static AssistantDeleter deleter(final String pathSid){ + public static AssistantDeleter deleter(final String pathSid) { return new AssistantDeleter(pathSid); } - public static AssistantFetcher fetcher(final String pathSid){ + public static AssistantFetcher fetcher(final String pathSid) { return new AssistantFetcher(pathSid); } - public static AssistantReader reader(){ + public static AssistantReader reader() { return new AssistantReader(); } - public static AssistantUpdater updater(final String pathSid){ + public static AssistantUpdater updater(final String pathSid) { return new AssistantUpdater(pathSid); } /** - * Converts a JSON String into a Assistant object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Assistant object represented by the provided JSON - */ - public static Assistant fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Assistant object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Assistant object represented by the provided JSON + */ + public static Assistant fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Assistant.class); @@ -83,14 +82,17 @@ public static Assistant fromJson(final String json, final ObjectMapper objectMap } /** - * Converts a JSON InputStream into a Assistant object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Assistant object represented by the provided JSON - */ - public static Assistant fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Assistant object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Assistant object represented by the provided JSON + */ + public static Assistant fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Assistant.class); @@ -118,47 +120,22 @@ public static Assistant fromJson(final InputStream json, final ObjectMapper obje @JsonCreator private Assistant( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("latest_model_build_sid") - final String latestModelBuildSid, - - @JsonProperty("links") - final Map links, - - @JsonProperty("log_queries") - final Boolean logQueries, - - @JsonProperty("development_stage") - final String developmentStage, - - @JsonProperty("needs_model_build") - final Boolean needsModelBuild, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("unique_name") - final String uniqueName, - - @JsonProperty("url") - final URI url, - - @JsonProperty("callback_url") - final URI callbackUrl, - - @JsonProperty("callback_events") - final String callbackEvents + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty( + "latest_model_build_sid" + ) final String latestModelBuildSid, + @JsonProperty("links") final Map links, + @JsonProperty("log_queries") final Boolean logQueries, + @JsonProperty("development_stage") final String developmentStage, + @JsonProperty("needs_model_build") final Boolean needsModelBuild, + @JsonProperty("sid") final String sid, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("url") final URI url, + @JsonProperty("callback_url") final URI callbackUrl, + @JsonProperty("callback_events") final String callbackEvents ) { this.accountSid = accountSid; this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); @@ -176,52 +153,65 @@ private Assistant( this.callbackEvents = callbackEvents; } - public final String getAccountSid() { - return this.accountSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getLatestModelBuildSid() { - return this.latestModelBuildSid; - } - public final Map getLinks() { - return this.links; - } - public final Boolean getLogQueries() { - return this.logQueries; - } - public final String getDevelopmentStage() { - return this.developmentStage; - } - public final Boolean getNeedsModelBuild() { - return this.needsModelBuild; - } - public final String getSid() { - return this.sid; - } - public final String getUniqueName() { - return this.uniqueName; - } - public final URI getUrl() { - return this.url; - } - public final URI getCallbackUrl() { - return this.callbackUrl; - } - public final String getCallbackEvents() { - return this.callbackEvents; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getLatestModelBuildSid() { + return this.latestModelBuildSid; + } + + public final Map getLinks() { + return this.links; + } + + public final Boolean getLogQueries() { + return this.logQueries; + } + + public final String getDevelopmentStage() { + return this.developmentStage; + } + + public final Boolean getNeedsModelBuild() { + return this.needsModelBuild; + } + + public final String getSid() { + return this.sid; + } + + public final String getUniqueName() { + return this.uniqueName; + } + + public final URI getUrl() { + return this.url; + } + + public final URI getCallbackUrl() { + return this.callbackUrl; + } + + public final String getCallbackEvents() { + return this.callbackEvents; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -231,13 +221,41 @@ public boolean equals(final Object o) { Assistant other = (Assistant) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(latestModelBuildSid, other.latestModelBuildSid) && Objects.equals(links, other.links) && Objects.equals(logQueries, other.logQueries) && Objects.equals(developmentStage, other.developmentStage) && Objects.equals(needsModelBuild, other.needsModelBuild) && Objects.equals(sid, other.sid) && Objects.equals(uniqueName, other.uniqueName) && Objects.equals(url, other.url) && Objects.equals(callbackUrl, other.callbackUrl) && Objects.equals(callbackEvents, other.callbackEvents) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(latestModelBuildSid, other.latestModelBuildSid) && + Objects.equals(links, other.links) && + Objects.equals(logQueries, other.logQueries) && + Objects.equals(developmentStage, other.developmentStage) && + Objects.equals(needsModelBuild, other.needsModelBuild) && + Objects.equals(sid, other.sid) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(url, other.url) && + Objects.equals(callbackUrl, other.callbackUrl) && + Objects.equals(callbackEvents, other.callbackEvents) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, dateCreated, dateUpdated, friendlyName, latestModelBuildSid, links, logQueries, developmentStage, needsModelBuild, sid, uniqueName, url, callbackUrl, callbackEvents); + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + friendlyName, + latestModelBuildSid, + links, + logQueries, + developmentStage, + needsModelBuild, + sid, + uniqueName, + url, + callbackUrl, + callbackEvents + ); } - } - diff --git a/src/main/java/com/twilio/rest/autopilot/v1/AssistantCreator.java b/src/main/java/com/twilio/rest/autopilot/v1/AssistantCreator.java index e2b4267223..cf31d725cc 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/AssistantCreator.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/AssistantCreator.java @@ -15,9 +15,11 @@ package com.twilio.rest.autopilot.v1; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; +import com.twilio.converter.Converter; +import com.twilio.converter.Converter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; -import com.twilio.converter.Converter; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; @@ -25,16 +27,13 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import java.util.Map; -import com.twilio.converter.Converter; import java.net.URI; - +import java.net.URI; +import java.util.Map; import java.util.Map; +public class AssistantCreator extends Creator { -import java.net.URI; - -public class AssistantCreator extends Creator{ private String friendlyName; private Boolean logQueries; private String uniqueName; @@ -43,94 +42,103 @@ public class AssistantCreator extends Creator{ private Map styleSheet; private Map defaults; - public AssistantCreator() { - } + public AssistantCreator() {} - public AssistantCreator setFriendlyName(final String friendlyName){ + public AssistantCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public AssistantCreator setLogQueries(final Boolean logQueries){ + + public AssistantCreator setLogQueries(final Boolean logQueries) { this.logQueries = logQueries; return this; } - public AssistantCreator setUniqueName(final String uniqueName){ + + public AssistantCreator setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - public AssistantCreator setCallbackUrl(final URI callbackUrl){ + + public AssistantCreator setCallbackUrl(final URI callbackUrl) { this.callbackUrl = callbackUrl; return this; } - public AssistantCreator setCallbackUrl(final String callbackUrl){ + public AssistantCreator setCallbackUrl(final String callbackUrl) { return setCallbackUrl(Promoter.uriFromString(callbackUrl)); } - public AssistantCreator setCallbackEvents(final String callbackEvents){ + + public AssistantCreator setCallbackEvents(final String callbackEvents) { this.callbackEvents = callbackEvents; return this; } - public AssistantCreator setStyleSheet(final Map styleSheet){ + + public AssistantCreator setStyleSheet( + final Map styleSheet + ) { this.styleSheet = styleSheet; return this; } - public AssistantCreator setDefaults(final Map defaults){ + + public AssistantCreator setDefaults(final Map defaults) { this.defaults = defaults; return this; } @Override - public Assistant create(final TwilioRestClient client){ + public Assistant create(final TwilioRestClient client) { String path = "/v1/Assistants"; - Request request = new Request( HttpMethod.POST, Domains.AUTOPILOT.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Assistant creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Assistant creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Assistant.fromJson(response.getStream(), client.getObjectMapper()); + return Assistant.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (logQueries != null) { request.addPostParam("LogQueries", logQueries.toString()); - } if (uniqueName != null) { request.addPostParam("UniqueName", uniqueName); - } if (callbackUrl != null) { request.addPostParam("CallbackUrl", callbackUrl.toString()); - } if (callbackEvents != null) { request.addPostParam("CallbackEvents", callbackEvents); - } if (styleSheet != null) { - request.addPostParam("StyleSheet", Converter.mapToJson(styleSheet)); - + request.addPostParam("StyleSheet", Converter.mapToJson(styleSheet)); } if (defaults != null) { - request.addPostParam("Defaults", Converter.mapToJson(defaults)); - + request.addPostParam("Defaults", Converter.mapToJson(defaults)); } } } diff --git a/src/main/java/com/twilio/rest/autopilot/v1/AssistantDeleter.java b/src/main/java/com/twilio/rest/autopilot/v1/AssistantDeleter.java index dcf957897b..4a8bca6e62 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/AssistantDeleter.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/AssistantDeleter.java @@ -24,21 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class AssistantDeleter extends Deleter { + private String pathSid; - public AssistantDeleter(final String pathSid){ + public AssistantDeleter(final String pathSid) { this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Assistants/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -48,9 +46,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Assistant delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Assistant delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/autopilot/v1/AssistantFetcher.java b/src/main/java/com/twilio/rest/autopilot/v1/AssistantFetcher.java index 32e9f1a616..87f05fc8da 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/AssistantFetcher.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/AssistantFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class AssistantFetcher extends Fetcher { + private String pathSid; - public AssistantFetcher(final String pathSid){ + public AssistantFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public Assistant fetch(final TwilioRestClient client) { String path = "/v1/Assistants/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,15 +46,23 @@ public Assistant fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Assistant fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Assistant fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Assistant.fromJson(response.getStream(), client.getObjectMapper()); + return Assistant.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/autopilot/v1/AssistantReader.java b/src/main/java/com/twilio/rest/autopilot/v1/AssistantReader.java index b291c04ba3..8ea3eaf9c8 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/AssistantReader.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/AssistantReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.autopilot.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,17 +25,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class AssistantReader extends Reader { + private Integer pageSize; - public AssistantReader(){ - } + public AssistantReader() {} - public AssistantReader setPageSize(final Integer pageSize){ + public AssistantReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -57,13 +55,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Assistant read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Assistant read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -79,7 +85,10 @@ private Page pageForRequest(final TwilioRestClient client, final Requ } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.AUTOPILOT.toString()) @@ -87,9 +96,11 @@ public Page previousPage(final Page page, final TwilioRest return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.AUTOPILOT.toString()) @@ -98,21 +109,21 @@ public Page nextPage(final Page page, final TwilioRestClie } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/autopilot/v1/AssistantUpdater.java b/src/main/java/com/twilio/rest/autopilot/v1/AssistantUpdater.java index 34528f71a0..362bde88d7 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/AssistantUpdater.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/AssistantUpdater.java @@ -15,9 +15,10 @@ package com.twilio.rest.autopilot.v1; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.converter.Converter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; -import com.twilio.converter.Converter; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; @@ -25,13 +26,11 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.net.URI; - import java.util.Map; +public class AssistantUpdater extends Updater { -public class AssistantUpdater extends Updater{ private String pathSid; private String friendlyName; private Boolean logQueries; @@ -42,104 +41,115 @@ public class AssistantUpdater extends Updater{ private Map defaults; private String developmentStage; - public AssistantUpdater(final String pathSid){ + public AssistantUpdater(final String pathSid) { this.pathSid = pathSid; } - public AssistantUpdater setFriendlyName(final String friendlyName){ + public AssistantUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public AssistantUpdater setLogQueries(final Boolean logQueries){ + + public AssistantUpdater setLogQueries(final Boolean logQueries) { this.logQueries = logQueries; return this; } - public AssistantUpdater setUniqueName(final String uniqueName){ + + public AssistantUpdater setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - public AssistantUpdater setCallbackUrl(final URI callbackUrl){ + + public AssistantUpdater setCallbackUrl(final URI callbackUrl) { this.callbackUrl = callbackUrl; return this; } - public AssistantUpdater setCallbackUrl(final String callbackUrl){ + public AssistantUpdater setCallbackUrl(final String callbackUrl) { return setCallbackUrl(Promoter.uriFromString(callbackUrl)); } - public AssistantUpdater setCallbackEvents(final String callbackEvents){ + + public AssistantUpdater setCallbackEvents(final String callbackEvents) { this.callbackEvents = callbackEvents; return this; } - public AssistantUpdater setStyleSheet(final Map styleSheet){ + + public AssistantUpdater setStyleSheet( + final Map styleSheet + ) { this.styleSheet = styleSheet; return this; } - public AssistantUpdater setDefaults(final Map defaults){ + + public AssistantUpdater setDefaults(final Map defaults) { this.defaults = defaults; return this; } - public AssistantUpdater setDevelopmentStage(final String developmentStage){ + + public AssistantUpdater setDevelopmentStage(final String developmentStage) { this.developmentStage = developmentStage; return this; } @Override - public Assistant update(final TwilioRestClient client){ + public Assistant update(final TwilioRestClient client) { String path = "/v1/Assistants/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.AUTOPILOT.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Assistant update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Assistant update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Assistant.fromJson(response.getStream(), client.getObjectMapper()); + return Assistant.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (logQueries != null) { request.addPostParam("LogQueries", logQueries.toString()); - } if (uniqueName != null) { request.addPostParam("UniqueName", uniqueName); - } if (callbackUrl != null) { request.addPostParam("CallbackUrl", callbackUrl.toString()); - } if (callbackEvents != null) { request.addPostParam("CallbackEvents", callbackEvents); - } if (styleSheet != null) { - request.addPostParam("StyleSheet", Converter.mapToJson(styleSheet)); - + request.addPostParam("StyleSheet", Converter.mapToJson(styleSheet)); } if (defaults != null) { - request.addPostParam("Defaults", Converter.mapToJson(defaults)); - + request.addPostParam("Defaults", Converter.mapToJson(defaults)); } if (developmentStage != null) { request.addPostParam("DevelopmentStage", developmentStage); - } } } diff --git a/src/main/java/com/twilio/rest/autopilot/v1/RestoreAssistant.java b/src/main/java/com/twilio/rest/autopilot/v1/RestoreAssistant.java index e1fac1f0c5..5ff4db89b8 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/RestoreAssistant.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/RestoreAssistant.java @@ -23,37 +23,36 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class RestoreAssistant extends Resource { + private static final long serialVersionUID = 63917994227032L; - public static RestoreAssistantUpdater updater(final String assistant){ + public static RestoreAssistantUpdater updater(final String assistant) { return new RestoreAssistantUpdater(assistant); } /** - * Converts a JSON String into a RestoreAssistant object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return RestoreAssistant object represented by the provided JSON - */ - public static RestoreAssistant fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a RestoreAssistant object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return RestoreAssistant object represented by the provided JSON + */ + public static RestoreAssistant fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, RestoreAssistant.class); @@ -65,14 +64,17 @@ public static RestoreAssistant fromJson(final String json, final ObjectMapper ob } /** - * Converts a JSON InputStream into a RestoreAssistant object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return RestoreAssistant object represented by the provided JSON - */ - public static RestoreAssistant fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a RestoreAssistant object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return RestoreAssistant object represented by the provided JSON + */ + public static RestoreAssistant fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, RestoreAssistant.class); @@ -98,41 +100,20 @@ public static RestoreAssistant fromJson(final InputStream json, final ObjectMapp @JsonCreator private RestoreAssistant( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("unique_name") - final String uniqueName, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("needs_model_build") - final Boolean needsModelBuild, - - @JsonProperty("latest_model_build_sid") - final String latestModelBuildSid, - - @JsonProperty("log_queries") - final Boolean logQueries, - - @JsonProperty("development_stage") - final String developmentStage, - - @JsonProperty("callback_url") - final URI callbackUrl, - - @JsonProperty("callback_events") - final String callbackEvents + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("sid") final String sid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("needs_model_build") final Boolean needsModelBuild, + @JsonProperty( + "latest_model_build_sid" + ) final String latestModelBuildSid, + @JsonProperty("log_queries") final Boolean logQueries, + @JsonProperty("development_stage") final String developmentStage, + @JsonProperty("callback_url") final URI callbackUrl, + @JsonProperty("callback_events") final String callbackEvents ) { this.accountSid = accountSid; this.sid = sid; @@ -148,46 +129,57 @@ private RestoreAssistant( this.callbackEvents = callbackEvents; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getSid() { - return this.sid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getUniqueName() { - return this.uniqueName; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final Boolean getNeedsModelBuild() { - return this.needsModelBuild; - } - public final String getLatestModelBuildSid() { - return this.latestModelBuildSid; - } - public final Boolean getLogQueries() { - return this.logQueries; - } - public final String getDevelopmentStage() { - return this.developmentStage; - } - public final URI getCallbackUrl() { - return this.callbackUrl; - } - public final String getCallbackEvents() { - return this.callbackEvents; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getSid() { + return this.sid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getUniqueName() { + return this.uniqueName; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final Boolean getNeedsModelBuild() { + return this.needsModelBuild; + } + + public final String getLatestModelBuildSid() { + return this.latestModelBuildSid; + } + + public final Boolean getLogQueries() { + return this.logQueries; + } + + public final String getDevelopmentStage() { + return this.developmentStage; + } + + public final URI getCallbackUrl() { + return this.callbackUrl; + } + + public final String getCallbackEvents() { + return this.callbackEvents; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -197,13 +189,37 @@ public boolean equals(final Object o) { RestoreAssistant other = (RestoreAssistant) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(sid, other.sid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(uniqueName, other.uniqueName) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(needsModelBuild, other.needsModelBuild) && Objects.equals(latestModelBuildSid, other.latestModelBuildSid) && Objects.equals(logQueries, other.logQueries) && Objects.equals(developmentStage, other.developmentStage) && Objects.equals(callbackUrl, other.callbackUrl) && Objects.equals(callbackEvents, other.callbackEvents) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(sid, other.sid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(needsModelBuild, other.needsModelBuild) && + Objects.equals(latestModelBuildSid, other.latestModelBuildSid) && + Objects.equals(logQueries, other.logQueries) && + Objects.equals(developmentStage, other.developmentStage) && + Objects.equals(callbackUrl, other.callbackUrl) && + Objects.equals(callbackEvents, other.callbackEvents) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, sid, dateCreated, dateUpdated, uniqueName, friendlyName, needsModelBuild, latestModelBuildSid, logQueries, developmentStage, callbackUrl, callbackEvents); + return Objects.hash( + accountSid, + sid, + dateCreated, + dateUpdated, + uniqueName, + friendlyName, + needsModelBuild, + latestModelBuildSid, + logQueries, + developmentStage, + callbackUrl, + callbackEvents + ); } - } - diff --git a/src/main/java/com/twilio/rest/autopilot/v1/RestoreAssistantUpdater.java b/src/main/java/com/twilio/rest/autopilot/v1/RestoreAssistantUpdater.java index 6309abd41f..f21abd8621 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/RestoreAssistantUpdater.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/RestoreAssistantUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.autopilot.v1; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,50 +25,57 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class RestoreAssistantUpdater extends Updater { - - -public class RestoreAssistantUpdater extends Updater{ private String assistant; - public RestoreAssistantUpdater(final String assistant){ + public RestoreAssistantUpdater(final String assistant) { this.assistant = assistant; } - public RestoreAssistantUpdater setAssistant(final String assistant){ + public RestoreAssistantUpdater setAssistant(final String assistant) { this.assistant = assistant; return this; } @Override - public RestoreAssistant update(final TwilioRestClient client){ + public RestoreAssistant update(final TwilioRestClient client) { String path = "/v1/Assistants/Restore"; - path = path.replace("{"+"Assistant"+"}", this.assistant.toString()); + path = path.replace("{" + "Assistant" + "}", this.assistant.toString()); Request request = new Request( HttpMethod.POST, Domains.AUTOPILOT.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("RestoreAssistant update failed: Unable to connect to server"); + throw new ApiConnectionException( + "RestoreAssistant update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return RestoreAssistant.fromJson(response.getStream(), client.getObjectMapper()); + return RestoreAssistant.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (assistant != null) { request.addPostParam("Assistant", assistant); - } } } diff --git a/src/main/java/com/twilio/rest/autopilot/v1/assistant/Defaults.java b/src/main/java/com/twilio/rest/autopilot/v1/assistant/Defaults.java index ce94051a46..9b1f901eb0 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/assistant/Defaults.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/assistant/Defaults.java @@ -22,42 +22,41 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Defaults extends Resource { + private static final long serialVersionUID = 52727905251134L; - public static DefaultsFetcher fetcher(final String pathAssistantSid){ + public static DefaultsFetcher fetcher(final String pathAssistantSid) { return new DefaultsFetcher(pathAssistantSid); } - public static DefaultsUpdater updater(final String pathAssistantSid){ + public static DefaultsUpdater updater(final String pathAssistantSid) { return new DefaultsUpdater(pathAssistantSid); } /** - * Converts a JSON String into a Defaults object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Defaults object represented by the provided JSON - */ - public static Defaults fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Defaults object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Defaults object represented by the provided JSON + */ + public static Defaults fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Defaults.class); @@ -69,14 +68,17 @@ public static Defaults fromJson(final String json, final ObjectMapper objectMapp } /** - * Converts a JSON InputStream into a Defaults object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Defaults object represented by the provided JSON - */ - public static Defaults fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Defaults object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Defaults object represented by the provided JSON + */ + public static Defaults fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Defaults.class); @@ -94,17 +96,10 @@ public static Defaults fromJson(final InputStream json, final ObjectMapper objec @JsonCreator private Defaults( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("assistant_sid") - final String assistantSid, - - @JsonProperty("url") - final URI url, - - @JsonProperty("data") - final Map data + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("assistant_sid") final String assistantSid, + @JsonProperty("url") final URI url, + @JsonProperty("data") final Map data ) { this.accountSid = accountSid; this.assistantSid = assistantSid; @@ -112,22 +107,25 @@ private Defaults( this.data = data; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getAssistantSid() { - return this.assistantSid; - } - public final URI getUrl() { - return this.url; - } - public final Map getData() { - return this.data; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getAssistantSid() { + return this.assistantSid; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getData() { + return this.data; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -137,13 +135,16 @@ public boolean equals(final Object o) { Defaults other = (Defaults) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(assistantSid, other.assistantSid) && Objects.equals(url, other.url) && Objects.equals(data, other.data) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(assistantSid, other.assistantSid) && + Objects.equals(url, other.url) && + Objects.equals(data, other.data) + ); } @Override public int hashCode() { return Objects.hash(accountSid, assistantSid, url, data); } - } - diff --git a/src/main/java/com/twilio/rest/autopilot/v1/assistant/DefaultsFetcher.java b/src/main/java/com/twilio/rest/autopilot/v1/assistant/DefaultsFetcher.java index 82e2bdead9..4c9f105f62 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/assistant/DefaultsFetcher.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/assistant/DefaultsFetcher.java @@ -24,22 +24,23 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class DefaultsFetcher extends Fetcher { + private String pathAssistantSid; - public DefaultsFetcher(final String pathAssistantSid){ + public DefaultsFetcher(final String pathAssistantSid) { this.pathAssistantSid = pathAssistantSid; } - @Override public Defaults fetch(final TwilioRestClient client) { String path = "/v1/Assistants/{AssistantSid}/Defaults"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -49,15 +50,23 @@ public Defaults fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Defaults fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Defaults fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Defaults.fromJson(response.getStream(), client.getObjectMapper()); + return Defaults.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/autopilot/v1/assistant/DefaultsUpdater.java b/src/main/java/com/twilio/rest/autopilot/v1/assistant/DefaultsUpdater.java index 505882ac78..9d3ab9c8c5 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/assistant/DefaultsUpdater.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/assistant/DefaultsUpdater.java @@ -15,8 +15,9 @@ package com.twilio.rest.autopilot.v1.assistant; import com.twilio.base.Updater; -import com.twilio.exception.ApiConnectionException; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Converter; +import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; @@ -24,53 +25,64 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - import java.util.Map; +public class DefaultsUpdater extends Updater { -public class DefaultsUpdater extends Updater{ private String pathAssistantSid; private Map defaults; - public DefaultsUpdater(final String pathAssistantSid){ + public DefaultsUpdater(final String pathAssistantSid) { this.pathAssistantSid = pathAssistantSid; } - public DefaultsUpdater setDefaults(final Map defaults){ + public DefaultsUpdater setDefaults(final Map defaults) { this.defaults = defaults; return this; } @Override - public Defaults update(final TwilioRestClient client){ + public Defaults update(final TwilioRestClient client) { String path = "/v1/Assistants/{AssistantSid}/Defaults"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.AUTOPILOT.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Defaults update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Defaults update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Defaults.fromJson(response.getStream(), client.getObjectMapper()); + return Defaults.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (defaults != null) { - request.addPostParam("Defaults", Converter.mapToJson(defaults)); - + request.addPostParam("Defaults", Converter.mapToJson(defaults)); } } } diff --git a/src/main/java/com/twilio/rest/autopilot/v1/assistant/Dialogue.java b/src/main/java/com/twilio/rest/autopilot/v1/assistant/Dialogue.java index a65cf271e0..a51e1a8aea 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/assistant/Dialogue.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/assistant/Dialogue.java @@ -22,38 +22,40 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Dialogue extends Resource { + private static final long serialVersionUID = 270949613735802L; - public static DialogueFetcher fetcher(final String pathAssistantSid, final String pathSid){ + public static DialogueFetcher fetcher( + final String pathAssistantSid, + final String pathSid + ) { return new DialogueFetcher(pathAssistantSid, pathSid); } /** - * Converts a JSON String into a Dialogue object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Dialogue object represented by the provided JSON - */ - public static Dialogue fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Dialogue object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Dialogue object represented by the provided JSON + */ + public static Dialogue fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Dialogue.class); @@ -65,14 +67,17 @@ public static Dialogue fromJson(final String json, final ObjectMapper objectMapp } /** - * Converts a JSON InputStream into a Dialogue object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Dialogue object represented by the provided JSON - */ - public static Dialogue fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Dialogue object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Dialogue object represented by the provided JSON + */ + public static Dialogue fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Dialogue.class); @@ -91,20 +96,11 @@ public static Dialogue fromJson(final InputStream json, final ObjectMapper objec @JsonCreator private Dialogue( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("assistant_sid") - final String assistantSid, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("data") - final Map data, - - @JsonProperty("url") - final URI url + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("assistant_sid") final String assistantSid, + @JsonProperty("sid") final String sid, + @JsonProperty("data") final Map data, + @JsonProperty("url") final URI url ) { this.accountSid = accountSid; this.assistantSid = assistantSid; @@ -113,25 +109,29 @@ private Dialogue( this.url = url; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getAssistantSid() { - return this.assistantSid; - } - public final String getSid() { - return this.sid; - } - public final Map getData() { - return this.data; - } - public final URI getUrl() { - return this.url; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getAssistantSid() { + return this.assistantSid; + } + + public final String getSid() { + return this.sid; + } + + public final Map getData() { + return this.data; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -141,13 +141,17 @@ public boolean equals(final Object o) { Dialogue other = (Dialogue) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(assistantSid, other.assistantSid) && Objects.equals(sid, other.sid) && Objects.equals(data, other.data) && Objects.equals(url, other.url) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(assistantSid, other.assistantSid) && + Objects.equals(sid, other.sid) && + Objects.equals(data, other.data) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { return Objects.hash(accountSid, assistantSid, sid, data, url); } - } - diff --git a/src/main/java/com/twilio/rest/autopilot/v1/assistant/DialogueFetcher.java b/src/main/java/com/twilio/rest/autopilot/v1/assistant/DialogueFetcher.java index 8f73389ca3..04a2dd46be 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/assistant/DialogueFetcher.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/assistant/DialogueFetcher.java @@ -24,25 +24,29 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class DialogueFetcher extends Fetcher { + private String pathAssistantSid; private String pathSid; - public DialogueFetcher(final String pathAssistantSid, final String pathSid){ + public DialogueFetcher( + final String pathAssistantSid, + final String pathSid + ) { this.pathAssistantSid = pathAssistantSid; this.pathSid = pathSid; } - @Override public Dialogue fetch(final TwilioRestClient client) { String path = "/v1/Assistants/{AssistantSid}/Dialogues/{Sid}"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,15 +56,23 @@ public Dialogue fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Dialogue fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Dialogue fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Dialogue.fromJson(response.getStream(), client.getObjectMapper()); + return Dialogue.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/autopilot/v1/assistant/FieldType.java b/src/main/java/com/twilio/rest/autopilot/v1/assistant/FieldType.java index 10885b3d18..65a194610b 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/assistant/FieldType.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/assistant/FieldType.java @@ -23,55 +23,66 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class FieldType extends Resource { + private static final long serialVersionUID = 124097769891823L; - public static FieldTypeCreator creator(final String pathAssistantSid, final String uniqueName){ + public static FieldTypeCreator creator( + final String pathAssistantSid, + final String uniqueName + ) { return new FieldTypeCreator(pathAssistantSid, uniqueName); } - public static FieldTypeDeleter deleter(final String pathAssistantSid, final String pathSid){ + public static FieldTypeDeleter deleter( + final String pathAssistantSid, + final String pathSid + ) { return new FieldTypeDeleter(pathAssistantSid, pathSid); } - public static FieldTypeFetcher fetcher(final String pathAssistantSid, final String pathSid){ + public static FieldTypeFetcher fetcher( + final String pathAssistantSid, + final String pathSid + ) { return new FieldTypeFetcher(pathAssistantSid, pathSid); } - public static FieldTypeReader reader(final String pathAssistantSid){ + public static FieldTypeReader reader(final String pathAssistantSid) { return new FieldTypeReader(pathAssistantSid); } - public static FieldTypeUpdater updater(final String pathAssistantSid, final String pathSid){ + public static FieldTypeUpdater updater( + final String pathAssistantSid, + final String pathSid + ) { return new FieldTypeUpdater(pathAssistantSid, pathSid); } /** - * Converts a JSON String into a FieldType object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return FieldType object represented by the provided JSON - */ - public static FieldType fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a FieldType object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return FieldType object represented by the provided JSON + */ + public static FieldType fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, FieldType.class); @@ -83,14 +94,17 @@ public static FieldType fromJson(final String json, final ObjectMapper objectMap } /** - * Converts a JSON InputStream into a FieldType object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return FieldType object represented by the provided JSON - */ - public static FieldType fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a FieldType object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return FieldType object represented by the provided JSON + */ + public static FieldType fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, FieldType.class); @@ -113,32 +127,15 @@ public static FieldType fromJson(final InputStream json, final ObjectMapper obje @JsonCreator private FieldType( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("links") - final Map links, - - @JsonProperty("assistant_sid") - final String assistantSid, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("unique_name") - final String uniqueName, - - @JsonProperty("url") - final URI url + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("links") final Map links, + @JsonProperty("assistant_sid") final String assistantSid, + @JsonProperty("sid") final String sid, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("url") final URI url ) { this.accountSid = accountSid; this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); @@ -151,37 +148,45 @@ private FieldType( this.url = url; } - public final String getAccountSid() { - return this.accountSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final Map getLinks() { - return this.links; - } - public final String getAssistantSid() { - return this.assistantSid; - } - public final String getSid() { - return this.sid; - } - public final String getUniqueName() { - return this.uniqueName; - } - public final URI getUrl() { - return this.url; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final Map getLinks() { + return this.links; + } + + public final String getAssistantSid() { + return this.assistantSid; + } + + public final String getSid() { + return this.sid; + } + + public final String getUniqueName() { + return this.uniqueName; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -191,13 +196,31 @@ public boolean equals(final Object o) { FieldType other = (FieldType) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(links, other.links) && Objects.equals(assistantSid, other.assistantSid) && Objects.equals(sid, other.sid) && Objects.equals(uniqueName, other.uniqueName) && Objects.equals(url, other.url) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(links, other.links) && + Objects.equals(assistantSid, other.assistantSid) && + Objects.equals(sid, other.sid) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, dateCreated, dateUpdated, friendlyName, links, assistantSid, sid, uniqueName, url); + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + friendlyName, + links, + assistantSid, + sid, + uniqueName, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/autopilot/v1/assistant/FieldTypeCreator.java b/src/main/java/com/twilio/rest/autopilot/v1/assistant/FieldTypeCreator.java index 6981bc52ea..dd6473cf3f 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/assistant/FieldTypeCreator.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/assistant/FieldTypeCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.autopilot.v1.assistant; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,62 +25,77 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class FieldTypeCreator extends Creator { - - -public class FieldTypeCreator extends Creator{ private String pathAssistantSid; private String uniqueName; private String friendlyName; - public FieldTypeCreator(final String pathAssistantSid, final String uniqueName) { + public FieldTypeCreator( + final String pathAssistantSid, + final String uniqueName + ) { this.pathAssistantSid = pathAssistantSid; this.uniqueName = uniqueName; } - public FieldTypeCreator setUniqueName(final String uniqueName){ + public FieldTypeCreator setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - public FieldTypeCreator setFriendlyName(final String friendlyName){ + + public FieldTypeCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } @Override - public FieldType create(final TwilioRestClient client){ + public FieldType create(final TwilioRestClient client) { String path = "/v1/Assistants/{AssistantSid}/FieldTypes"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"UniqueName"+"}", this.uniqueName.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = + path.replace("{" + "UniqueName" + "}", this.uniqueName.toString()); Request request = new Request( HttpMethod.POST, Domains.AUTOPILOT.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("FieldType creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "FieldType creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return FieldType.fromJson(response.getStream(), client.getObjectMapper()); + return FieldType.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (uniqueName != null) { request.addPostParam("UniqueName", uniqueName); - } if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } } } diff --git a/src/main/java/com/twilio/rest/autopilot/v1/assistant/FieldTypeDeleter.java b/src/main/java/com/twilio/rest/autopilot/v1/assistant/FieldTypeDeleter.java index 859cbd635e..ea4ffd27aa 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/assistant/FieldTypeDeleter.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/assistant/FieldTypeDeleter.java @@ -24,24 +24,29 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class FieldTypeDeleter extends Deleter { + private String pathAssistantSid; private String pathSid; - public FieldTypeDeleter(final String pathAssistantSid, final String pathSid){ + public FieldTypeDeleter( + final String pathAssistantSid, + final String pathSid + ) { this.pathAssistantSid = pathAssistantSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Assistants/{AssistantSid}/FieldTypes/{Sid}"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +56,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("FieldType delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "FieldType delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/autopilot/v1/assistant/FieldTypeFetcher.java b/src/main/java/com/twilio/rest/autopilot/v1/assistant/FieldTypeFetcher.java index dc041c820d..77f528857e 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/assistant/FieldTypeFetcher.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/assistant/FieldTypeFetcher.java @@ -24,25 +24,29 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class FieldTypeFetcher extends Fetcher { + private String pathAssistantSid; private String pathSid; - public FieldTypeFetcher(final String pathAssistantSid, final String pathSid){ + public FieldTypeFetcher( + final String pathAssistantSid, + final String pathSid + ) { this.pathAssistantSid = pathAssistantSid; this.pathSid = pathSid; } - @Override public FieldType fetch(final TwilioRestClient client) { String path = "/v1/Assistants/{AssistantSid}/FieldTypes/{Sid}"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,15 +56,23 @@ public FieldType fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("FieldType fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "FieldType fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return FieldType.fromJson(response.getStream(), client.getObjectMapper()); + return FieldType.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/autopilot/v1/assistant/FieldTypeReader.java b/src/main/java/com/twilio/rest/autopilot/v1/assistant/FieldTypeReader.java index 827edecdf2..ea6de484fc 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/assistant/FieldTypeReader.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/assistant/FieldTypeReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.autopilot.v1.assistant; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,19 +25,17 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class FieldTypeReader extends Reader { + private String pathAssistantSid; private Integer pageSize; - public FieldTypeReader(final String pathAssistantSid){ + public FieldTypeReader(final String pathAssistantSid) { this.pathAssistantSid = pathAssistantSid; } - public FieldTypeReader setPageSize(final Integer pageSize){ + public FieldTypeReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -48,7 +47,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Assistants/{AssistantSid}/FieldTypes"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -60,13 +63,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("FieldType read failed: Unable to connect to server"); + throw new ApiConnectionException( + "FieldType read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +93,10 @@ private Page pageForRequest(final TwilioRestClient client, final Requ } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.AUTOPILOT.toString()) @@ -90,9 +104,11 @@ public Page previousPage(final Page page, final TwilioRest return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.AUTOPILOT.toString()) @@ -101,21 +117,21 @@ public Page nextPage(final Page page, final TwilioRestClie } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/autopilot/v1/assistant/FieldTypeUpdater.java b/src/main/java/com/twilio/rest/autopilot/v1/assistant/FieldTypeUpdater.java index 446ed0da66..aaebf8a34c 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/assistant/FieldTypeUpdater.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/assistant/FieldTypeUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.autopilot.v1.assistant; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,63 +25,77 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class FieldTypeUpdater extends Updater { - - -public class FieldTypeUpdater extends Updater{ private String pathAssistantSid; private String pathSid; private String friendlyName; private String uniqueName; - public FieldTypeUpdater(final String pathAssistantSid, final String pathSid){ + public FieldTypeUpdater( + final String pathAssistantSid, + final String pathSid + ) { this.pathAssistantSid = pathAssistantSid; this.pathSid = pathSid; } - public FieldTypeUpdater setFriendlyName(final String friendlyName){ + public FieldTypeUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public FieldTypeUpdater setUniqueName(final String uniqueName){ + + public FieldTypeUpdater setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } @Override - public FieldType update(final TwilioRestClient client){ + public FieldType update(final TwilioRestClient client) { String path = "/v1/Assistants/{AssistantSid}/FieldTypes/{Sid}"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.AUTOPILOT.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("FieldType update failed: Unable to connect to server"); + throw new ApiConnectionException( + "FieldType update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return FieldType.fromJson(response.getStream(), client.getObjectMapper()); + return FieldType.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (uniqueName != null) { request.addPostParam("UniqueName", uniqueName); - } } } diff --git a/src/main/java/com/twilio/rest/autopilot/v1/assistant/ModelBuild.java b/src/main/java/com/twilio/rest/autopilot/v1/assistant/ModelBuild.java index 5f9105f0e5..ee15a1c871 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/assistant/ModelBuild.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/assistant/ModelBuild.java @@ -24,53 +24,61 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class ModelBuild extends Resource { + private static final long serialVersionUID = 226055418389205L; - public static ModelBuildCreator creator(final String pathAssistantSid){ + public static ModelBuildCreator creator(final String pathAssistantSid) { return new ModelBuildCreator(pathAssistantSid); } - public static ModelBuildDeleter deleter(final String pathAssistantSid, final String pathSid){ + public static ModelBuildDeleter deleter( + final String pathAssistantSid, + final String pathSid + ) { return new ModelBuildDeleter(pathAssistantSid, pathSid); } - public static ModelBuildFetcher fetcher(final String pathAssistantSid, final String pathSid){ + public static ModelBuildFetcher fetcher( + final String pathAssistantSid, + final String pathSid + ) { return new ModelBuildFetcher(pathAssistantSid, pathSid); } - public static ModelBuildReader reader(final String pathAssistantSid){ + public static ModelBuildReader reader(final String pathAssistantSid) { return new ModelBuildReader(pathAssistantSid); } - public static ModelBuildUpdater updater(final String pathAssistantSid, final String pathSid){ + public static ModelBuildUpdater updater( + final String pathAssistantSid, + final String pathSid + ) { return new ModelBuildUpdater(pathAssistantSid, pathSid); } /** - * Converts a JSON String into a ModelBuild object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return ModelBuild object represented by the provided JSON - */ - public static ModelBuild fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a ModelBuild object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return ModelBuild object represented by the provided JSON + */ + public static ModelBuild fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, ModelBuild.class); @@ -82,14 +90,17 @@ public static ModelBuild fromJson(final String json, final ObjectMapper objectMa } /** - * Converts a JSON InputStream into a ModelBuild object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return ModelBuild object represented by the provided JSON - */ - public static ModelBuild fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a ModelBuild object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return ModelBuild object represented by the provided JSON + */ + public static ModelBuild fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, ModelBuild.class); @@ -99,6 +110,7 @@ public static ModelBuild fromJson(final InputStream json, final ObjectMapper obj throw new ApiConnectionException(e.getMessage(), e); } } + public enum Status { ENQUEUED("enqueued"), BUILDING("building"), @@ -135,35 +147,16 @@ public static Status forValue(final String value) { @JsonCreator private ModelBuild( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("assistant_sid") - final String assistantSid, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("status") - final ModelBuild.Status status, - - @JsonProperty("unique_name") - final String uniqueName, - - @JsonProperty("url") - final URI url, - - @JsonProperty("build_duration") - final Integer buildDuration, - - @JsonProperty("error_code") - final Integer errorCode + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("assistant_sid") final String assistantSid, + @JsonProperty("sid") final String sid, + @JsonProperty("status") final ModelBuild.Status status, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("url") final URI url, + @JsonProperty("build_duration") final Integer buildDuration, + @JsonProperty("error_code") final Integer errorCode ) { this.accountSid = accountSid; this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); @@ -177,40 +170,49 @@ private ModelBuild( this.errorCode = errorCode; } - public final String getAccountSid() { - return this.accountSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getAssistantSid() { - return this.assistantSid; - } - public final String getSid() { - return this.sid; - } - public final ModelBuild.Status getStatus() { - return this.status; - } - public final String getUniqueName() { - return this.uniqueName; - } - public final URI getUrl() { - return this.url; - } - public final Integer getBuildDuration() { - return this.buildDuration; - } - public final Integer getErrorCode() { - return this.errorCode; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getAssistantSid() { + return this.assistantSid; + } + + public final String getSid() { + return this.sid; + } + + public final ModelBuild.Status getStatus() { + return this.status; + } + + public final String getUniqueName() { + return this.uniqueName; + } + + public final URI getUrl() { + return this.url; + } + + public final Integer getBuildDuration() { + return this.buildDuration; + } + + public final Integer getErrorCode() { + return this.errorCode; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -220,13 +222,33 @@ public boolean equals(final Object o) { ModelBuild other = (ModelBuild) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(assistantSid, other.assistantSid) && Objects.equals(sid, other.sid) && Objects.equals(status, other.status) && Objects.equals(uniqueName, other.uniqueName) && Objects.equals(url, other.url) && Objects.equals(buildDuration, other.buildDuration) && Objects.equals(errorCode, other.errorCode) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(assistantSid, other.assistantSid) && + Objects.equals(sid, other.sid) && + Objects.equals(status, other.status) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(url, other.url) && + Objects.equals(buildDuration, other.buildDuration) && + Objects.equals(errorCode, other.errorCode) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, dateCreated, dateUpdated, assistantSid, sid, status, uniqueName, url, buildDuration, errorCode); + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + assistantSid, + sid, + status, + uniqueName, + url, + buildDuration, + errorCode + ); } - } - diff --git a/src/main/java/com/twilio/rest/autopilot/v1/assistant/ModelBuildCreator.java b/src/main/java/com/twilio/rest/autopilot/v1/assistant/ModelBuildCreator.java index 17162407fc..a183b35982 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/assistant/ModelBuildCreator.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/assistant/ModelBuildCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.autopilot.v1.assistant; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -25,12 +26,10 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.net.URI; - - - import java.net.URI; -public class ModelBuildCreator extends Creator{ +public class ModelBuildCreator extends Creator { + private String pathAssistantSid; private URI statusCallback; private String uniqueName; @@ -39,52 +38,65 @@ public ModelBuildCreator(final String pathAssistantSid) { this.pathAssistantSid = pathAssistantSid; } - public ModelBuildCreator setStatusCallback(final URI statusCallback){ + public ModelBuildCreator setStatusCallback(final URI statusCallback) { this.statusCallback = statusCallback; return this; } - public ModelBuildCreator setStatusCallback(final String statusCallback){ + public ModelBuildCreator setStatusCallback(final String statusCallback) { return setStatusCallback(Promoter.uriFromString(statusCallback)); } - public ModelBuildCreator setUniqueName(final String uniqueName){ + + public ModelBuildCreator setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } @Override - public ModelBuild create(final TwilioRestClient client){ + public ModelBuild create(final TwilioRestClient client) { String path = "/v1/Assistants/{AssistantSid}/ModelBuilds"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.AUTOPILOT.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("ModelBuild creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "ModelBuild creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return ModelBuild.fromJson(response.getStream(), client.getObjectMapper()); + return ModelBuild.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (statusCallback != null) { request.addPostParam("StatusCallback", statusCallback.toString()); - } if (uniqueName != null) { request.addPostParam("UniqueName", uniqueName); - } } } diff --git a/src/main/java/com/twilio/rest/autopilot/v1/assistant/ModelBuildDeleter.java b/src/main/java/com/twilio/rest/autopilot/v1/assistant/ModelBuildDeleter.java index 1b2228e0c8..2b9612726d 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/assistant/ModelBuildDeleter.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/assistant/ModelBuildDeleter.java @@ -24,24 +24,29 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class ModelBuildDeleter extends Deleter { + private String pathAssistantSid; private String pathSid; - public ModelBuildDeleter(final String pathAssistantSid, final String pathSid){ + public ModelBuildDeleter( + final String pathAssistantSid, + final String pathSid + ) { this.pathAssistantSid = pathAssistantSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Assistants/{AssistantSid}/ModelBuilds/{Sid}"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +56,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("ModelBuild delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "ModelBuild delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/autopilot/v1/assistant/ModelBuildFetcher.java b/src/main/java/com/twilio/rest/autopilot/v1/assistant/ModelBuildFetcher.java index 903b252901..9527d867cb 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/assistant/ModelBuildFetcher.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/assistant/ModelBuildFetcher.java @@ -24,25 +24,29 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class ModelBuildFetcher extends Fetcher { + private String pathAssistantSid; private String pathSid; - public ModelBuildFetcher(final String pathAssistantSid, final String pathSid){ + public ModelBuildFetcher( + final String pathAssistantSid, + final String pathSid + ) { this.pathAssistantSid = pathAssistantSid; this.pathSid = pathSid; } - @Override public ModelBuild fetch(final TwilioRestClient client) { String path = "/v1/Assistants/{AssistantSid}/ModelBuilds/{Sid}"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,15 +56,23 @@ public ModelBuild fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("ModelBuild fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "ModelBuild fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return ModelBuild.fromJson(response.getStream(), client.getObjectMapper()); + return ModelBuild.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/autopilot/v1/assistant/ModelBuildReader.java b/src/main/java/com/twilio/rest/autopilot/v1/assistant/ModelBuildReader.java index 18cf276187..148675a103 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/assistant/ModelBuildReader.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/assistant/ModelBuildReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.autopilot.v1.assistant; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,19 +25,17 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class ModelBuildReader extends Reader { + private String pathAssistantSid; private Integer pageSize; - public ModelBuildReader(final String pathAssistantSid){ + public ModelBuildReader(final String pathAssistantSid) { this.pathAssistantSid = pathAssistantSid; } - public ModelBuildReader setPageSize(final Integer pageSize){ + public ModelBuildReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -48,7 +47,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Assistants/{AssistantSid}/ModelBuilds"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -60,13 +63,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("ModelBuild read failed: Unable to connect to server"); + throw new ApiConnectionException( + "ModelBuild read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +93,10 @@ private Page pageForRequest(final TwilioRestClient client, final Req } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.AUTOPILOT.toString()) @@ -90,9 +104,11 @@ public Page previousPage(final Page page, final TwilioRe return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.AUTOPILOT.toString()) @@ -101,21 +117,21 @@ public Page nextPage(final Page page, final TwilioRestCl } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/autopilot/v1/assistant/ModelBuildUpdater.java b/src/main/java/com/twilio/rest/autopilot/v1/assistant/ModelBuildUpdater.java index 4016bbc9ee..3c6bbd772a 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/assistant/ModelBuildUpdater.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/assistant/ModelBuildUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.autopilot.v1.assistant; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,54 +25,68 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class ModelBuildUpdater extends Updater { - - -public class ModelBuildUpdater extends Updater{ private String pathAssistantSid; private String pathSid; private String uniqueName; - public ModelBuildUpdater(final String pathAssistantSid, final String pathSid){ + public ModelBuildUpdater( + final String pathAssistantSid, + final String pathSid + ) { this.pathAssistantSid = pathAssistantSid; this.pathSid = pathSid; } - public ModelBuildUpdater setUniqueName(final String uniqueName){ + public ModelBuildUpdater setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } @Override - public ModelBuild update(final TwilioRestClient client){ + public ModelBuild update(final TwilioRestClient client) { String path = "/v1/Assistants/{AssistantSid}/ModelBuilds/{Sid}"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.AUTOPILOT.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("ModelBuild update failed: Unable to connect to server"); + throw new ApiConnectionException( + "ModelBuild update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return ModelBuild.fromJson(response.getStream(), client.getObjectMapper()); + return ModelBuild.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (uniqueName != null) { request.addPostParam("UniqueName", uniqueName); - } } } diff --git a/src/main/java/com/twilio/rest/autopilot/v1/assistant/Query.java b/src/main/java/com/twilio/rest/autopilot/v1/assistant/Query.java index 0ab8383437..fdede9fe61 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/assistant/Query.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/assistant/Query.java @@ -23,55 +23,67 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Query extends Resource { + private static final long serialVersionUID = 205347249812282L; - public static QueryCreator creator(final String pathAssistantSid, final String language, final String query){ + public static QueryCreator creator( + final String pathAssistantSid, + final String language, + final String query + ) { return new QueryCreator(pathAssistantSid, language, query); } - public static QueryDeleter deleter(final String pathAssistantSid, final String pathSid){ + public static QueryDeleter deleter( + final String pathAssistantSid, + final String pathSid + ) { return new QueryDeleter(pathAssistantSid, pathSid); } - public static QueryFetcher fetcher(final String pathAssistantSid, final String pathSid){ + public static QueryFetcher fetcher( + final String pathAssistantSid, + final String pathSid + ) { return new QueryFetcher(pathAssistantSid, pathSid); } - public static QueryReader reader(final String pathAssistantSid){ + public static QueryReader reader(final String pathAssistantSid) { return new QueryReader(pathAssistantSid); } - public static QueryUpdater updater(final String pathAssistantSid, final String pathSid){ + public static QueryUpdater updater( + final String pathAssistantSid, + final String pathSid + ) { return new QueryUpdater(pathAssistantSid, pathSid); } /** - * Converts a JSON String into a Query object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Query object represented by the provided JSON - */ - public static Query fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Query object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Query object represented by the provided JSON + */ + public static Query fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Query.class); @@ -83,14 +95,17 @@ public static Query fromJson(final String json, final ObjectMapper objectMapper) } /** - * Converts a JSON InputStream into a Query object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Query object represented by the provided JSON - */ - public static Query fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Query object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Query object represented by the provided JSON + */ + public static Query fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Query.class); @@ -118,47 +133,20 @@ public static Query fromJson(final InputStream json, final ObjectMapper objectMa @JsonCreator private Query( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("results") - final Map results, - - @JsonProperty("language") - final String language, - - @JsonProperty("model_build_sid") - final String modelBuildSid, - - @JsonProperty("query") - final String query, - - @JsonProperty("sample_sid") - final String sampleSid, - - @JsonProperty("assistant_sid") - final String assistantSid, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("status") - final String status, - - @JsonProperty("url") - final URI url, - - @JsonProperty("source_channel") - final String sourceChannel, - - @JsonProperty("dialogue_sid") - final String dialogueSid + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("results") final Map results, + @JsonProperty("language") final String language, + @JsonProperty("model_build_sid") final String modelBuildSid, + @JsonProperty("query") final String query, + @JsonProperty("sample_sid") final String sampleSid, + @JsonProperty("assistant_sid") final String assistantSid, + @JsonProperty("sid") final String sid, + @JsonProperty("status") final String status, + @JsonProperty("url") final URI url, + @JsonProperty("source_channel") final String sourceChannel, + @JsonProperty("dialogue_sid") final String dialogueSid ) { this.accountSid = accountSid; this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); @@ -176,52 +164,65 @@ private Query( this.dialogueSid = dialogueSid; } - public final String getAccountSid() { - return this.accountSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final Map getResults() { - return this.results; - } - public final String getLanguage() { - return this.language; - } - public final String getModelBuildSid() { - return this.modelBuildSid; - } - public final String getQuery() { - return this.query; - } - public final String getSampleSid() { - return this.sampleSid; - } - public final String getAssistantSid() { - return this.assistantSid; - } - public final String getSid() { - return this.sid; - } - public final String getStatus() { - return this.status; - } - public final URI getUrl() { - return this.url; - } - public final String getSourceChannel() { - return this.sourceChannel; - } - public final String getDialogueSid() { - return this.dialogueSid; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final Map getResults() { + return this.results; + } + + public final String getLanguage() { + return this.language; + } + + public final String getModelBuildSid() { + return this.modelBuildSid; + } + + public final String getQuery() { + return this.query; + } + + public final String getSampleSid() { + return this.sampleSid; + } + + public final String getAssistantSid() { + return this.assistantSid; + } + + public final String getSid() { + return this.sid; + } + + public final String getStatus() { + return this.status; + } + + public final URI getUrl() { + return this.url; + } + + public final String getSourceChannel() { + return this.sourceChannel; + } + + public final String getDialogueSid() { + return this.dialogueSid; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -231,13 +232,41 @@ public boolean equals(final Object o) { Query other = (Query) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(results, other.results) && Objects.equals(language, other.language) && Objects.equals(modelBuildSid, other.modelBuildSid) && Objects.equals(query, other.query) && Objects.equals(sampleSid, other.sampleSid) && Objects.equals(assistantSid, other.assistantSid) && Objects.equals(sid, other.sid) && Objects.equals(status, other.status) && Objects.equals(url, other.url) && Objects.equals(sourceChannel, other.sourceChannel) && Objects.equals(dialogueSid, other.dialogueSid) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(results, other.results) && + Objects.equals(language, other.language) && + Objects.equals(modelBuildSid, other.modelBuildSid) && + Objects.equals(query, other.query) && + Objects.equals(sampleSid, other.sampleSid) && + Objects.equals(assistantSid, other.assistantSid) && + Objects.equals(sid, other.sid) && + Objects.equals(status, other.status) && + Objects.equals(url, other.url) && + Objects.equals(sourceChannel, other.sourceChannel) && + Objects.equals(dialogueSid, other.dialogueSid) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, dateCreated, dateUpdated, results, language, modelBuildSid, query, sampleSid, assistantSid, sid, status, url, sourceChannel, dialogueSid); + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + results, + language, + modelBuildSid, + query, + sampleSid, + assistantSid, + sid, + status, + url, + sourceChannel, + dialogueSid + ); } - } - diff --git a/src/main/java/com/twilio/rest/autopilot/v1/assistant/QueryCreator.java b/src/main/java/com/twilio/rest/autopilot/v1/assistant/QueryCreator.java index bcc3d5cf4e..cd094bd00c 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/assistant/QueryCreator.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/assistant/QueryCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.autopilot.v1.assistant; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,58 +25,73 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class QueryCreator extends Creator { - - -public class QueryCreator extends Creator{ private String pathAssistantSid; private String language; private String query; private String tasks; private String modelBuild; - public QueryCreator(final String pathAssistantSid, final String language, final String query) { + public QueryCreator( + final String pathAssistantSid, + final String language, + final String query + ) { this.pathAssistantSid = pathAssistantSid; this.language = language; this.query = query; } - public QueryCreator setLanguage(final String language){ + public QueryCreator setLanguage(final String language) { this.language = language; return this; } - public QueryCreator setQuery(final String query){ + + public QueryCreator setQuery(final String query) { this.query = query; return this; } - public QueryCreator setTasks(final String tasks){ + + public QueryCreator setTasks(final String tasks) { this.tasks = tasks; return this; } - public QueryCreator setModelBuild(final String modelBuild){ + + public QueryCreator setModelBuild(final String modelBuild) { this.modelBuild = modelBuild; return this; } @Override - public Query create(final TwilioRestClient client){ + public Query create(final TwilioRestClient client) { String path = "/v1/Assistants/{AssistantSid}/Queries"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"Language"+"}", this.language.toString()); - path = path.replace("{"+"Query"+"}", this.query.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = path.replace("{" + "Language" + "}", this.language.toString()); + path = path.replace("{" + "Query" + "}", this.query.toString()); Request request = new Request( HttpMethod.POST, Domains.AUTOPILOT.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Query creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Query creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -84,22 +100,19 @@ public Query create(final TwilioRestClient client){ return Query.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (language != null) { request.addPostParam("Language", language); - } if (query != null) { request.addPostParam("Query", query); - } if (tasks != null) { request.addPostParam("Tasks", tasks); - } if (modelBuild != null) { request.addPostParam("ModelBuild", modelBuild); - } } } diff --git a/src/main/java/com/twilio/rest/autopilot/v1/assistant/QueryDeleter.java b/src/main/java/com/twilio/rest/autopilot/v1/assistant/QueryDeleter.java index 0a4a987213..a2c2f4dfbc 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/assistant/QueryDeleter.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/assistant/QueryDeleter.java @@ -24,24 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class QueryDeleter extends Deleter { + private String pathAssistantSid; private String pathSid; - public QueryDeleter(final String pathAssistantSid, final String pathSid){ + public QueryDeleter(final String pathAssistantSid, final String pathSid) { this.pathAssistantSid = pathAssistantSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Assistants/{AssistantSid}/Queries/{Sid}"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +53,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Query delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Query delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/autopilot/v1/assistant/QueryFetcher.java b/src/main/java/com/twilio/rest/autopilot/v1/assistant/QueryFetcher.java index 3d19c3fccc..f5cd6f6177 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/assistant/QueryFetcher.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/assistant/QueryFetcher.java @@ -24,25 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class QueryFetcher extends Fetcher { + private String pathAssistantSid; private String pathSid; - public QueryFetcher(final String pathAssistantSid, final String pathSid){ + public QueryFetcher(final String pathAssistantSid, final String pathSid) { this.pathAssistantSid = pathAssistantSid; this.pathSid = pathSid; } - @Override public Query fetch(final TwilioRestClient client) { String path = "/v1/Assistants/{AssistantSid}/Queries/{Sid}"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,9 +53,14 @@ public Query fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Query fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Query fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/autopilot/v1/assistant/QueryReader.java b/src/main/java/com/twilio/rest/autopilot/v1/assistant/QueryReader.java index 096a6c5396..0bb5c2b849 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/assistant/QueryReader.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/assistant/QueryReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.autopilot.v1.assistant; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,11 +25,9 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class QueryReader extends Reader { + private String pathAssistantSid; private String language; private String modelBuild; @@ -36,27 +35,31 @@ public class QueryReader extends Reader { private String dialogueSid; private Integer pageSize; - public QueryReader(final String pathAssistantSid){ + public QueryReader(final String pathAssistantSid) { this.pathAssistantSid = pathAssistantSid; } - public QueryReader setLanguage(final String language){ + public QueryReader setLanguage(final String language) { this.language = language; return this; } - public QueryReader setModelBuild(final String modelBuild){ + + public QueryReader setModelBuild(final String modelBuild) { this.modelBuild = modelBuild; return this; } - public QueryReader setStatus(final String status){ + + public QueryReader setStatus(final String status) { this.status = status; return this; } - public QueryReader setDialogueSid(final String dialogueSid){ + + public QueryReader setDialogueSid(final String dialogueSid) { this.dialogueSid = dialogueSid; return this; } - public QueryReader setPageSize(final Integer pageSize){ + + public QueryReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -68,7 +71,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Assistants/{AssistantSid}/Queries"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -80,13 +87,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Query read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Query read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -102,7 +117,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.AUTOPILOT.toString()) @@ -110,9 +128,11 @@ public Page previousPage(final Page page, final TwilioRestClient c return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.AUTOPILOT.toString()) @@ -121,37 +141,33 @@ public Page nextPage(final Page page, final TwilioRestClient clien } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (language != null) { - request.addQueryParam("Language", language); } if (modelBuild != null) { - request.addQueryParam("ModelBuild", modelBuild); } if (status != null) { - request.addQueryParam("Status", status); } if (dialogueSid != null) { - request.addQueryParam("DialogueSid", dialogueSid); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/autopilot/v1/assistant/QueryUpdater.java b/src/main/java/com/twilio/rest/autopilot/v1/assistant/QueryUpdater.java index d5db610484..52d7d093f3 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/assistant/QueryUpdater.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/assistant/QueryUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.autopilot.v1.assistant; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,47 +25,56 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class QueryUpdater extends Updater { - - -public class QueryUpdater extends Updater{ private String pathAssistantSid; private String pathSid; private String sampleSid; private String status; - public QueryUpdater(final String pathAssistantSid, final String pathSid){ + public QueryUpdater(final String pathAssistantSid, final String pathSid) { this.pathAssistantSid = pathAssistantSid; this.pathSid = pathSid; } - public QueryUpdater setSampleSid(final String sampleSid){ + public QueryUpdater setSampleSid(final String sampleSid) { this.sampleSid = sampleSid; return this; } - public QueryUpdater setStatus(final String status){ + + public QueryUpdater setStatus(final String status) { this.status = status; return this; } @Override - public Query update(final TwilioRestClient client){ + public Query update(final TwilioRestClient client) { String path = "/v1/Assistants/{AssistantSid}/Queries/{Sid}"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.AUTOPILOT.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Query update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Query update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -73,14 +83,13 @@ public Query update(final TwilioRestClient client){ return Query.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (sampleSid != null) { request.addPostParam("SampleSid", sampleSid); - } if (status != null) { request.addPostParam("Status", status); - } } } diff --git a/src/main/java/com/twilio/rest/autopilot/v1/assistant/StyleSheet.java b/src/main/java/com/twilio/rest/autopilot/v1/assistant/StyleSheet.java index 622c627867..2c366c9b67 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/assistant/StyleSheet.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/assistant/StyleSheet.java @@ -22,42 +22,41 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class StyleSheet extends Resource { + private static final long serialVersionUID = 52727905251134L; - public static StyleSheetFetcher fetcher(final String pathAssistantSid){ + public static StyleSheetFetcher fetcher(final String pathAssistantSid) { return new StyleSheetFetcher(pathAssistantSid); } - public static StyleSheetUpdater updater(final String pathAssistantSid){ + public static StyleSheetUpdater updater(final String pathAssistantSid) { return new StyleSheetUpdater(pathAssistantSid); } /** - * Converts a JSON String into a StyleSheet object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return StyleSheet object represented by the provided JSON - */ - public static StyleSheet fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a StyleSheet object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return StyleSheet object represented by the provided JSON + */ + public static StyleSheet fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, StyleSheet.class); @@ -69,14 +68,17 @@ public static StyleSheet fromJson(final String json, final ObjectMapper objectMa } /** - * Converts a JSON InputStream into a StyleSheet object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return StyleSheet object represented by the provided JSON - */ - public static StyleSheet fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a StyleSheet object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return StyleSheet object represented by the provided JSON + */ + public static StyleSheet fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, StyleSheet.class); @@ -94,17 +96,10 @@ public static StyleSheet fromJson(final InputStream json, final ObjectMapper obj @JsonCreator private StyleSheet( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("assistant_sid") - final String assistantSid, - - @JsonProperty("url") - final URI url, - - @JsonProperty("data") - final Map data + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("assistant_sid") final String assistantSid, + @JsonProperty("url") final URI url, + @JsonProperty("data") final Map data ) { this.accountSid = accountSid; this.assistantSid = assistantSid; @@ -112,22 +107,25 @@ private StyleSheet( this.data = data; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getAssistantSid() { - return this.assistantSid; - } - public final URI getUrl() { - return this.url; - } - public final Map getData() { - return this.data; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getAssistantSid() { + return this.assistantSid; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getData() { + return this.data; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -137,13 +135,16 @@ public boolean equals(final Object o) { StyleSheet other = (StyleSheet) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(assistantSid, other.assistantSid) && Objects.equals(url, other.url) && Objects.equals(data, other.data) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(assistantSid, other.assistantSid) && + Objects.equals(url, other.url) && + Objects.equals(data, other.data) + ); } @Override public int hashCode() { return Objects.hash(accountSid, assistantSid, url, data); } - } - diff --git a/src/main/java/com/twilio/rest/autopilot/v1/assistant/StyleSheetFetcher.java b/src/main/java/com/twilio/rest/autopilot/v1/assistant/StyleSheetFetcher.java index f78170a774..dab66db57b 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/assistant/StyleSheetFetcher.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/assistant/StyleSheetFetcher.java @@ -24,22 +24,23 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class StyleSheetFetcher extends Fetcher { + private String pathAssistantSid; - public StyleSheetFetcher(final String pathAssistantSid){ + public StyleSheetFetcher(final String pathAssistantSid) { this.pathAssistantSid = pathAssistantSid; } - @Override public StyleSheet fetch(final TwilioRestClient client) { String path = "/v1/Assistants/{AssistantSid}/StyleSheet"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -49,15 +50,23 @@ public StyleSheet fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("StyleSheet fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "StyleSheet fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return StyleSheet.fromJson(response.getStream(), client.getObjectMapper()); + return StyleSheet.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/autopilot/v1/assistant/StyleSheetUpdater.java b/src/main/java/com/twilio/rest/autopilot/v1/assistant/StyleSheetUpdater.java index 52ef47c983..19ae02875f 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/assistant/StyleSheetUpdater.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/assistant/StyleSheetUpdater.java @@ -15,8 +15,9 @@ package com.twilio.rest.autopilot.v1.assistant; import com.twilio.base.Updater; -import com.twilio.exception.ApiConnectionException; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Converter; +import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; @@ -24,53 +25,66 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - import java.util.Map; +public class StyleSheetUpdater extends Updater { -public class StyleSheetUpdater extends Updater{ private String pathAssistantSid; private Map styleSheet; - public StyleSheetUpdater(final String pathAssistantSid){ + public StyleSheetUpdater(final String pathAssistantSid) { this.pathAssistantSid = pathAssistantSid; } - public StyleSheetUpdater setStyleSheet(final Map styleSheet){ + public StyleSheetUpdater setStyleSheet( + final Map styleSheet + ) { this.styleSheet = styleSheet; return this; } @Override - public StyleSheet update(final TwilioRestClient client){ + public StyleSheet update(final TwilioRestClient client) { String path = "/v1/Assistants/{AssistantSid}/StyleSheet"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.AUTOPILOT.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("StyleSheet update failed: Unable to connect to server"); + throw new ApiConnectionException( + "StyleSheet update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return StyleSheet.fromJson(response.getStream(), client.getObjectMapper()); + return StyleSheet.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (styleSheet != null) { - request.addPostParam("StyleSheet", Converter.mapToJson(styleSheet)); - + request.addPostParam("StyleSheet", Converter.mapToJson(styleSheet)); } } } diff --git a/src/main/java/com/twilio/rest/autopilot/v1/assistant/Task.java b/src/main/java/com/twilio/rest/autopilot/v1/assistant/Task.java index 9f165ff843..4b7c574301 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/assistant/Task.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/assistant/Task.java @@ -23,55 +23,66 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Task extends Resource { + private static final long serialVersionUID = 59959992200143L; - public static TaskCreator creator(final String pathAssistantSid, final String uniqueName){ + public static TaskCreator creator( + final String pathAssistantSid, + final String uniqueName + ) { return new TaskCreator(pathAssistantSid, uniqueName); } - public static TaskDeleter deleter(final String pathAssistantSid, final String pathSid){ + public static TaskDeleter deleter( + final String pathAssistantSid, + final String pathSid + ) { return new TaskDeleter(pathAssistantSid, pathSid); } - public static TaskFetcher fetcher(final String pathAssistantSid, final String pathSid){ + public static TaskFetcher fetcher( + final String pathAssistantSid, + final String pathSid + ) { return new TaskFetcher(pathAssistantSid, pathSid); } - public static TaskReader reader(final String pathAssistantSid){ + public static TaskReader reader(final String pathAssistantSid) { return new TaskReader(pathAssistantSid); } - public static TaskUpdater updater(final String pathAssistantSid, final String pathSid){ + public static TaskUpdater updater( + final String pathAssistantSid, + final String pathSid + ) { return new TaskUpdater(pathAssistantSid, pathSid); } /** - * Converts a JSON String into a Task object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Task object represented by the provided JSON - */ - public static Task fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Task object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Task object represented by the provided JSON + */ + public static Task fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Task.class); @@ -83,14 +94,17 @@ public static Task fromJson(final String json, final ObjectMapper objectMapper) } /** - * Converts a JSON InputStream into a Task object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Task object represented by the provided JSON - */ - public static Task fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Task object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Task object represented by the provided JSON + */ + public static Task fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Task.class); @@ -114,35 +128,16 @@ public static Task fromJson(final InputStream json, final ObjectMapper objectMap @JsonCreator private Task( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("links") - final Map links, - - @JsonProperty("assistant_sid") - final String assistantSid, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("unique_name") - final String uniqueName, - - @JsonProperty("actions_url") - final URI actionsUrl, - - @JsonProperty("url") - final URI url + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("links") final Map links, + @JsonProperty("assistant_sid") final String assistantSid, + @JsonProperty("sid") final String sid, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("actions_url") final URI actionsUrl, + @JsonProperty("url") final URI url ) { this.accountSid = accountSid; this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); @@ -156,40 +151,49 @@ private Task( this.url = url; } - public final String getAccountSid() { - return this.accountSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final Map getLinks() { - return this.links; - } - public final String getAssistantSid() { - return this.assistantSid; - } - public final String getSid() { - return this.sid; - } - public final String getUniqueName() { - return this.uniqueName; - } - public final URI getActionsUrl() { - return this.actionsUrl; - } - public final URI getUrl() { - return this.url; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final Map getLinks() { + return this.links; + } + + public final String getAssistantSid() { + return this.assistantSid; + } + + public final String getSid() { + return this.sid; + } + + public final String getUniqueName() { + return this.uniqueName; + } + + public final URI getActionsUrl() { + return this.actionsUrl; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -199,13 +203,33 @@ public boolean equals(final Object o) { Task other = (Task) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(links, other.links) && Objects.equals(assistantSid, other.assistantSid) && Objects.equals(sid, other.sid) && Objects.equals(uniqueName, other.uniqueName) && Objects.equals(actionsUrl, other.actionsUrl) && Objects.equals(url, other.url) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(links, other.links) && + Objects.equals(assistantSid, other.assistantSid) && + Objects.equals(sid, other.sid) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(actionsUrl, other.actionsUrl) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, dateCreated, dateUpdated, friendlyName, links, assistantSid, sid, uniqueName, actionsUrl, url); + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + friendlyName, + links, + assistantSid, + sid, + uniqueName, + actionsUrl, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/autopilot/v1/assistant/TaskCreator.java b/src/main/java/com/twilio/rest/autopilot/v1/assistant/TaskCreator.java index 905bcf5f1d..2e2eb7e216 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/assistant/TaskCreator.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/assistant/TaskCreator.java @@ -15,9 +15,11 @@ package com.twilio.rest.autopilot.v1.assistant; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; +import com.twilio.converter.Converter; +import com.twilio.converter.Converter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; -import com.twilio.converter.Converter; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; @@ -25,16 +27,13 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import java.util.Map; -import com.twilio.converter.Converter; import java.net.URI; - +import java.net.URI; +import java.util.Map; import java.util.Map; +public class TaskCreator extends Creator { -import java.net.URI; - -public class TaskCreator extends Creator{ private String pathAssistantSid; private String uniqueName; private String friendlyName; @@ -46,45 +45,59 @@ public TaskCreator(final String pathAssistantSid, final String uniqueName) { this.uniqueName = uniqueName; } - public TaskCreator setUniqueName(final String uniqueName){ + public TaskCreator setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - public TaskCreator setFriendlyName(final String friendlyName){ + + public TaskCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public TaskCreator setActions(final Map actions){ + + public TaskCreator setActions(final Map actions) { this.actions = actions; return this; } - public TaskCreator setActionsUrl(final URI actionsUrl){ + + public TaskCreator setActionsUrl(final URI actionsUrl) { this.actionsUrl = actionsUrl; return this; } - public TaskCreator setActionsUrl(final String actionsUrl){ + public TaskCreator setActionsUrl(final String actionsUrl) { return setActionsUrl(Promoter.uriFromString(actionsUrl)); } @Override - public Task create(final TwilioRestClient client){ + public Task create(final TwilioRestClient client) { String path = "/v1/Assistants/{AssistantSid}/Tasks"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"UniqueName"+"}", this.uniqueName.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = + path.replace("{" + "UniqueName" + "}", this.uniqueName.toString()); Request request = new Request( HttpMethod.POST, Domains.AUTOPILOT.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Task creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Task creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -93,22 +106,19 @@ public Task create(final TwilioRestClient client){ return Task.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (uniqueName != null) { request.addPostParam("UniqueName", uniqueName); - } if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (actions != null) { - request.addPostParam("Actions", Converter.mapToJson(actions)); - + request.addPostParam("Actions", Converter.mapToJson(actions)); } if (actionsUrl != null) { request.addPostParam("ActionsUrl", actionsUrl.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/autopilot/v1/assistant/TaskDeleter.java b/src/main/java/com/twilio/rest/autopilot/v1/assistant/TaskDeleter.java index 3c53e33bae..a3d97713b1 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/assistant/TaskDeleter.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/assistant/TaskDeleter.java @@ -24,24 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class TaskDeleter extends Deleter { + private String pathAssistantSid; private String pathSid; - public TaskDeleter(final String pathAssistantSid, final String pathSid){ + public TaskDeleter(final String pathAssistantSid, final String pathSid) { this.pathAssistantSid = pathAssistantSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Assistants/{AssistantSid}/Tasks/{Sid}"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +53,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Task delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Task delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/autopilot/v1/assistant/TaskFetcher.java b/src/main/java/com/twilio/rest/autopilot/v1/assistant/TaskFetcher.java index 6547515a46..0c26b784b8 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/assistant/TaskFetcher.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/assistant/TaskFetcher.java @@ -24,25 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class TaskFetcher extends Fetcher { + private String pathAssistantSid; private String pathSid; - public TaskFetcher(final String pathAssistantSid, final String pathSid){ + public TaskFetcher(final String pathAssistantSid, final String pathSid) { this.pathAssistantSid = pathAssistantSid; this.pathSid = pathSid; } - @Override public Task fetch(final TwilioRestClient client) { String path = "/v1/Assistants/{AssistantSid}/Tasks/{Sid}"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,9 +53,14 @@ public Task fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Task fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Task fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/autopilot/v1/assistant/TaskReader.java b/src/main/java/com/twilio/rest/autopilot/v1/assistant/TaskReader.java index 5b2cf266a2..b88f8fcf59 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/assistant/TaskReader.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/assistant/TaskReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.autopilot.v1.assistant; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,19 +25,17 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class TaskReader extends Reader { + private String pathAssistantSid; private Integer pageSize; - public TaskReader(final String pathAssistantSid){ + public TaskReader(final String pathAssistantSid) { this.pathAssistantSid = pathAssistantSid; } - public TaskReader setPageSize(final Integer pageSize){ + public TaskReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -48,7 +47,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Assistants/{AssistantSid}/Tasks"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -60,13 +63,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Task read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Task read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +93,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request r } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.AUTOPILOT.toString()) @@ -90,9 +104,11 @@ public Page previousPage(final Page page, final TwilioRestClient cli return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.AUTOPILOT.toString()) @@ -101,21 +117,21 @@ public Page nextPage(final Page page, final TwilioRestClient client) } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/autopilot/v1/assistant/TaskUpdater.java b/src/main/java/com/twilio/rest/autopilot/v1/assistant/TaskUpdater.java index 2a569ba9be..6e4d73b87f 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/assistant/TaskUpdater.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/assistant/TaskUpdater.java @@ -15,9 +15,10 @@ package com.twilio.rest.autopilot.v1.assistant; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.converter.Converter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; -import com.twilio.converter.Converter; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; @@ -25,13 +26,11 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.net.URI; - import java.util.Map; +public class TaskUpdater extends Updater { -public class TaskUpdater extends Updater{ private String pathAssistantSid; private String pathSid; private String friendlyName; @@ -39,50 +38,63 @@ public class TaskUpdater extends Updater{ private Map actions; private URI actionsUrl; - public TaskUpdater(final String pathAssistantSid, final String pathSid){ + public TaskUpdater(final String pathAssistantSid, final String pathSid) { this.pathAssistantSid = pathAssistantSid; this.pathSid = pathSid; } - public TaskUpdater setFriendlyName(final String friendlyName){ + public TaskUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public TaskUpdater setUniqueName(final String uniqueName){ + + public TaskUpdater setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - public TaskUpdater setActions(final Map actions){ + + public TaskUpdater setActions(final Map actions) { this.actions = actions; return this; } - public TaskUpdater setActionsUrl(final URI actionsUrl){ + + public TaskUpdater setActionsUrl(final URI actionsUrl) { this.actionsUrl = actionsUrl; return this; } - public TaskUpdater setActionsUrl(final String actionsUrl){ + public TaskUpdater setActionsUrl(final String actionsUrl) { return setActionsUrl(Promoter.uriFromString(actionsUrl)); } @Override - public Task update(final TwilioRestClient client){ + public Task update(final TwilioRestClient client) { String path = "/v1/Assistants/{AssistantSid}/Tasks/{Sid}"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.AUTOPILOT.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Task update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Task update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -91,22 +103,19 @@ public Task update(final TwilioRestClient client){ return Task.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (uniqueName != null) { request.addPostParam("UniqueName", uniqueName); - } if (actions != null) { - request.addPostParam("Actions", Converter.mapToJson(actions)); - + request.addPostParam("Actions", Converter.mapToJson(actions)); } if (actionsUrl != null) { request.addPostParam("ActionsUrl", actionsUrl.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/autopilot/v1/assistant/Webhook.java b/src/main/java/com/twilio/rest/autopilot/v1/assistant/Webhook.java index bd54db5893..8606d167a3 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/assistant/Webhook.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/assistant/Webhook.java @@ -23,53 +23,71 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Webhook extends Resource { + private static final long serialVersionUID = 211848885870919L; - public static WebhookCreator creator(final String pathAssistantSid, final String uniqueName, final String events, final URI webhookUrl){ - return new WebhookCreator(pathAssistantSid, uniqueName, events, webhookUrl); + public static WebhookCreator creator( + final String pathAssistantSid, + final String uniqueName, + final String events, + final URI webhookUrl + ) { + return new WebhookCreator( + pathAssistantSid, + uniqueName, + events, + webhookUrl + ); } - public static WebhookDeleter deleter(final String pathAssistantSid, final String pathSid){ + public static WebhookDeleter deleter( + final String pathAssistantSid, + final String pathSid + ) { return new WebhookDeleter(pathAssistantSid, pathSid); } - public static WebhookFetcher fetcher(final String pathAssistantSid, final String pathSid){ + public static WebhookFetcher fetcher( + final String pathAssistantSid, + final String pathSid + ) { return new WebhookFetcher(pathAssistantSid, pathSid); } - public static WebhookReader reader(final String pathAssistantSid){ + public static WebhookReader reader(final String pathAssistantSid) { return new WebhookReader(pathAssistantSid); } - public static WebhookUpdater updater(final String pathAssistantSid, final String pathSid){ + public static WebhookUpdater updater( + final String pathAssistantSid, + final String pathSid + ) { return new WebhookUpdater(pathAssistantSid, pathSid); } /** - * Converts a JSON String into a Webhook object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Webhook object represented by the provided JSON - */ - public static Webhook fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Webhook object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Webhook object represented by the provided JSON + */ + public static Webhook fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Webhook.class); @@ -81,14 +99,17 @@ public static Webhook fromJson(final String json, final ObjectMapper objectMappe } /** - * Converts a JSON InputStream into a Webhook object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Webhook object represented by the provided JSON - */ - public static Webhook fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Webhook object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Webhook object represented by the provided JSON + */ + public static Webhook fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Webhook.class); @@ -112,35 +133,16 @@ public static Webhook fromJson(final InputStream json, final ObjectMapper object @JsonCreator private Webhook( - @JsonProperty("url") - final URI url, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("assistant_sid") - final String assistantSid, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("unique_name") - final String uniqueName, - - @JsonProperty("events") - final String events, - - @JsonProperty("webhook_url") - final URI webhookUrl, - - @JsonProperty("webhook_method") - final String webhookMethod + @JsonProperty("url") final URI url, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("assistant_sid") final String assistantSid, + @JsonProperty("sid") final String sid, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("events") final String events, + @JsonProperty("webhook_url") final URI webhookUrl, + @JsonProperty("webhook_method") final String webhookMethod ) { this.url = url; this.accountSid = accountSid; @@ -154,40 +156,49 @@ private Webhook( this.webhookMethod = webhookMethod; } - public final URI getUrl() { - return this.url; - } - public final String getAccountSid() { - return this.accountSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getAssistantSid() { - return this.assistantSid; - } - public final String getSid() { - return this.sid; - } - public final String getUniqueName() { - return this.uniqueName; - } - public final String getEvents() { - return this.events; - } - public final URI getWebhookUrl() { - return this.webhookUrl; - } - public final String getWebhookMethod() { - return this.webhookMethod; - } + public final URI getUrl() { + return this.url; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getAssistantSid() { + return this.assistantSid; + } + + public final String getSid() { + return this.sid; + } + + public final String getUniqueName() { + return this.uniqueName; + } + + public final String getEvents() { + return this.events; + } + + public final URI getWebhookUrl() { + return this.webhookUrl; + } + + public final String getWebhookMethod() { + return this.webhookMethod; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -197,13 +208,33 @@ public boolean equals(final Object o) { Webhook other = (Webhook) o; - return Objects.equals(url, other.url) && Objects.equals(accountSid, other.accountSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(assistantSid, other.assistantSid) && Objects.equals(sid, other.sid) && Objects.equals(uniqueName, other.uniqueName) && Objects.equals(events, other.events) && Objects.equals(webhookUrl, other.webhookUrl) && Objects.equals(webhookMethod, other.webhookMethod) ; + return ( + Objects.equals(url, other.url) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(assistantSid, other.assistantSid) && + Objects.equals(sid, other.sid) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(events, other.events) && + Objects.equals(webhookUrl, other.webhookUrl) && + Objects.equals(webhookMethod, other.webhookMethod) + ); } @Override public int hashCode() { - return Objects.hash(url, accountSid, dateCreated, dateUpdated, assistantSid, sid, uniqueName, events, webhookUrl, webhookMethod); + return Objects.hash( + url, + accountSid, + dateCreated, + dateUpdated, + assistantSid, + sid, + uniqueName, + events, + webhookUrl, + webhookMethod + ); } - } - diff --git a/src/main/java/com/twilio/rest/autopilot/v1/assistant/WebhookCreator.java b/src/main/java/com/twilio/rest/autopilot/v1/assistant/WebhookCreator.java index 94bff3f931..8517d8ed4d 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/assistant/WebhookCreator.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/assistant/WebhookCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.autopilot.v1.assistant; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -25,66 +26,84 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.net.URI; - - - import java.net.URI; -public class WebhookCreator extends Creator{ +public class WebhookCreator extends Creator { + private String pathAssistantSid; private String uniqueName; private String events; private URI webhookUrl; private String webhookMethod; - public WebhookCreator(final String pathAssistantSid, final String uniqueName, final String events, final URI webhookUrl) { + public WebhookCreator( + final String pathAssistantSid, + final String uniqueName, + final String events, + final URI webhookUrl + ) { this.pathAssistantSid = pathAssistantSid; this.uniqueName = uniqueName; this.events = events; this.webhookUrl = webhookUrl; } - public WebhookCreator setUniqueName(final String uniqueName){ + public WebhookCreator setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - public WebhookCreator setEvents(final String events){ + + public WebhookCreator setEvents(final String events) { this.events = events; return this; } - public WebhookCreator setWebhookUrl(final URI webhookUrl){ + + public WebhookCreator setWebhookUrl(final URI webhookUrl) { this.webhookUrl = webhookUrl; return this; } - public WebhookCreator setWebhookUrl(final String webhookUrl){ + public WebhookCreator setWebhookUrl(final String webhookUrl) { return setWebhookUrl(Promoter.uriFromString(webhookUrl)); } - public WebhookCreator setWebhookMethod(final String webhookMethod){ + + public WebhookCreator setWebhookMethod(final String webhookMethod) { this.webhookMethod = webhookMethod; return this; } @Override - public Webhook create(final TwilioRestClient client){ + public Webhook create(final TwilioRestClient client) { String path = "/v1/Assistants/{AssistantSid}/Webhooks"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"UniqueName"+"}", this.uniqueName.toString()); - path = path.replace("{"+"Events"+"}", this.events.toString()); - path = path.replace("{"+"WebhookUrl"+"}", this.webhookUrl.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = + path.replace("{" + "UniqueName" + "}", this.uniqueName.toString()); + path = path.replace("{" + "Events" + "}", this.events.toString()); + path = + path.replace("{" + "WebhookUrl" + "}", this.webhookUrl.toString()); Request request = new Request( HttpMethod.POST, Domains.AUTOPILOT.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Webhook creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Webhook creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -93,22 +112,19 @@ public Webhook create(final TwilioRestClient client){ return Webhook.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (uniqueName != null) { request.addPostParam("UniqueName", uniqueName); - } if (events != null) { request.addPostParam("Events", events); - } if (webhookUrl != null) { request.addPostParam("WebhookUrl", webhookUrl.toString()); - } if (webhookMethod != null) { request.addPostParam("WebhookMethod", webhookMethod); - } } } diff --git a/src/main/java/com/twilio/rest/autopilot/v1/assistant/WebhookDeleter.java b/src/main/java/com/twilio/rest/autopilot/v1/assistant/WebhookDeleter.java index 6931cf2505..163f9ddb17 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/assistant/WebhookDeleter.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/assistant/WebhookDeleter.java @@ -24,24 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class WebhookDeleter extends Deleter { + private String pathAssistantSid; private String pathSid; - public WebhookDeleter(final String pathAssistantSid, final String pathSid){ + public WebhookDeleter(final String pathAssistantSid, final String pathSid) { this.pathAssistantSid = pathAssistantSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Assistants/{AssistantSid}/Webhooks/{Sid}"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +53,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Webhook delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Webhook delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/autopilot/v1/assistant/WebhookFetcher.java b/src/main/java/com/twilio/rest/autopilot/v1/assistant/WebhookFetcher.java index c813d88d95..ace7e53996 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/assistant/WebhookFetcher.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/assistant/WebhookFetcher.java @@ -24,25 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class WebhookFetcher extends Fetcher { + private String pathAssistantSid; private String pathSid; - public WebhookFetcher(final String pathAssistantSid, final String pathSid){ + public WebhookFetcher(final String pathAssistantSid, final String pathSid) { this.pathAssistantSid = pathAssistantSid; this.pathSid = pathSid; } - @Override public Webhook fetch(final TwilioRestClient client) { String path = "/v1/Assistants/{AssistantSid}/Webhooks/{Sid}"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,9 +53,14 @@ public Webhook fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Webhook fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Webhook fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/autopilot/v1/assistant/WebhookReader.java b/src/main/java/com/twilio/rest/autopilot/v1/assistant/WebhookReader.java index cfa7e38d34..2688a5109b 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/assistant/WebhookReader.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/assistant/WebhookReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.autopilot.v1.assistant; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,19 +25,17 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class WebhookReader extends Reader { + private String pathAssistantSid; private Integer pageSize; - public WebhookReader(final String pathAssistantSid){ + public WebhookReader(final String pathAssistantSid) { this.pathAssistantSid = pathAssistantSid; } - public WebhookReader setPageSize(final Integer pageSize){ + public WebhookReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -48,7 +47,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Assistants/{AssistantSid}/Webhooks"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -60,13 +63,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Webhook read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Webhook read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +93,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reques } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.AUTOPILOT.toString()) @@ -90,9 +104,11 @@ public Page previousPage(final Page page, final TwilioRestClie return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.AUTOPILOT.toString()) @@ -101,21 +117,21 @@ public Page nextPage(final Page page, final TwilioRestClient c } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/autopilot/v1/assistant/WebhookUpdater.java b/src/main/java/com/twilio/rest/autopilot/v1/assistant/WebhookUpdater.java index c6d2f61a6d..77c57807e6 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/assistant/WebhookUpdater.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/assistant/WebhookUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.autopilot.v1.assistant; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -24,12 +25,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.net.URI; +public class WebhookUpdater extends Updater { - -public class WebhookUpdater extends Updater{ private String pathAssistantSid; private String pathSid; private String uniqueName; @@ -37,50 +36,63 @@ public class WebhookUpdater extends Updater{ private URI webhookUrl; private String webhookMethod; - public WebhookUpdater(final String pathAssistantSid, final String pathSid){ + public WebhookUpdater(final String pathAssistantSid, final String pathSid) { this.pathAssistantSid = pathAssistantSid; this.pathSid = pathSid; } - public WebhookUpdater setUniqueName(final String uniqueName){ + public WebhookUpdater setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - public WebhookUpdater setEvents(final String events){ + + public WebhookUpdater setEvents(final String events) { this.events = events; return this; } - public WebhookUpdater setWebhookUrl(final URI webhookUrl){ + + public WebhookUpdater setWebhookUrl(final URI webhookUrl) { this.webhookUrl = webhookUrl; return this; } - public WebhookUpdater setWebhookUrl(final String webhookUrl){ + public WebhookUpdater setWebhookUrl(final String webhookUrl) { return setWebhookUrl(Promoter.uriFromString(webhookUrl)); } - public WebhookUpdater setWebhookMethod(final String webhookMethod){ + + public WebhookUpdater setWebhookMethod(final String webhookMethod) { this.webhookMethod = webhookMethod; return this; } @Override - public Webhook update(final TwilioRestClient client){ + public Webhook update(final TwilioRestClient client) { String path = "/v1/Assistants/{AssistantSid}/Webhooks/{Sid}"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.AUTOPILOT.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Webhook update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Webhook update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -89,22 +101,19 @@ public Webhook update(final TwilioRestClient client){ return Webhook.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (uniqueName != null) { request.addPostParam("UniqueName", uniqueName); - } if (events != null) { request.addPostParam("Events", events); - } if (webhookUrl != null) { request.addPostParam("WebhookUrl", webhookUrl.toString()); - } if (webhookMethod != null) { request.addPostParam("WebhookMethod", webhookMethod); - } } } diff --git a/src/main/java/com/twilio/rest/autopilot/v1/assistant/fieldtype/FieldValue.java b/src/main/java/com/twilio/rest/autopilot/v1/assistant/fieldtype/FieldValue.java index fd580d5eef..3f7d602130 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/assistant/fieldtype/FieldValue.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/assistant/fieldtype/FieldValue.java @@ -23,49 +23,77 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class FieldValue extends Resource { + private static final long serialVersionUID = 181490262234152L; - public static FieldValueCreator creator(final String pathAssistantSid, final String pathFieldTypeSid, final String language, final String value){ - return new FieldValueCreator(pathAssistantSid, pathFieldTypeSid, language, value); + public static FieldValueCreator creator( + final String pathAssistantSid, + final String pathFieldTypeSid, + final String language, + final String value + ) { + return new FieldValueCreator( + pathAssistantSid, + pathFieldTypeSid, + language, + value + ); } - public static FieldValueDeleter deleter(final String pathAssistantSid, final String pathFieldTypeSid, final String pathSid){ - return new FieldValueDeleter(pathAssistantSid, pathFieldTypeSid, pathSid); + public static FieldValueDeleter deleter( + final String pathAssistantSid, + final String pathFieldTypeSid, + final String pathSid + ) { + return new FieldValueDeleter( + pathAssistantSid, + pathFieldTypeSid, + pathSid + ); } - public static FieldValueFetcher fetcher(final String pathAssistantSid, final String pathFieldTypeSid, final String pathSid){ - return new FieldValueFetcher(pathAssistantSid, pathFieldTypeSid, pathSid); + public static FieldValueFetcher fetcher( + final String pathAssistantSid, + final String pathFieldTypeSid, + final String pathSid + ) { + return new FieldValueFetcher( + pathAssistantSid, + pathFieldTypeSid, + pathSid + ); } - public static FieldValueReader reader(final String pathAssistantSid, final String pathFieldTypeSid){ + public static FieldValueReader reader( + final String pathAssistantSid, + final String pathFieldTypeSid + ) { return new FieldValueReader(pathAssistantSid, pathFieldTypeSid); } /** - * Converts a JSON String into a FieldValue object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return FieldValue object represented by the provided JSON - */ - public static FieldValue fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a FieldValue object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return FieldValue object represented by the provided JSON + */ + public static FieldValue fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, FieldValue.class); @@ -77,14 +105,17 @@ public static FieldValue fromJson(final String json, final ObjectMapper objectMa } /** - * Converts a JSON InputStream into a FieldValue object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return FieldValue object represented by the provided JSON - */ - public static FieldValue fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a FieldValue object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return FieldValue object represented by the provided JSON + */ + public static FieldValue fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, FieldValue.class); @@ -108,35 +139,16 @@ public static FieldValue fromJson(final InputStream json, final ObjectMapper obj @JsonCreator private FieldValue( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("field_type_sid") - final String fieldTypeSid, - - @JsonProperty("language") - final String language, - - @JsonProperty("assistant_sid") - final String assistantSid, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("value") - final String value, - - @JsonProperty("url") - final URI url, - - @JsonProperty("synonym_of") - final String synonymOf + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("field_type_sid") final String fieldTypeSid, + @JsonProperty("language") final String language, + @JsonProperty("assistant_sid") final String assistantSid, + @JsonProperty("sid") final String sid, + @JsonProperty("value") final String value, + @JsonProperty("url") final URI url, + @JsonProperty("synonym_of") final String synonymOf ) { this.accountSid = accountSid; this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); @@ -150,40 +162,49 @@ private FieldValue( this.synonymOf = synonymOf; } - public final String getAccountSid() { - return this.accountSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getFieldTypeSid() { - return this.fieldTypeSid; - } - public final String getLanguage() { - return this.language; - } - public final String getAssistantSid() { - return this.assistantSid; - } - public final String getSid() { - return this.sid; - } - public final String getValue() { - return this.value; - } - public final URI getUrl() { - return this.url; - } - public final String getSynonymOf() { - return this.synonymOf; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getFieldTypeSid() { + return this.fieldTypeSid; + } + + public final String getLanguage() { + return this.language; + } + + public final String getAssistantSid() { + return this.assistantSid; + } + + public final String getSid() { + return this.sid; + } + + public final String getValue() { + return this.value; + } + + public final URI getUrl() { + return this.url; + } + + public final String getSynonymOf() { + return this.synonymOf; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -193,13 +214,33 @@ public boolean equals(final Object o) { FieldValue other = (FieldValue) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(fieldTypeSid, other.fieldTypeSid) && Objects.equals(language, other.language) && Objects.equals(assistantSid, other.assistantSid) && Objects.equals(sid, other.sid) && Objects.equals(value, other.value) && Objects.equals(url, other.url) && Objects.equals(synonymOf, other.synonymOf) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(fieldTypeSid, other.fieldTypeSid) && + Objects.equals(language, other.language) && + Objects.equals(assistantSid, other.assistantSid) && + Objects.equals(sid, other.sid) && + Objects.equals(value, other.value) && + Objects.equals(url, other.url) && + Objects.equals(synonymOf, other.synonymOf) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, dateCreated, dateUpdated, fieldTypeSid, language, assistantSid, sid, value, url, synonymOf); + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + fieldTypeSid, + language, + assistantSid, + sid, + value, + url, + synonymOf + ); } - } - diff --git a/src/main/java/com/twilio/rest/autopilot/v1/assistant/fieldtype/FieldValueCreator.java b/src/main/java/com/twilio/rest/autopilot/v1/assistant/fieldtype/FieldValueCreator.java index a1dccb188b..312759b7bb 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/assistant/fieldtype/FieldValueCreator.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/assistant/fieldtype/FieldValueCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.autopilot.v1.assistant.fieldtype; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,76 +25,97 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class FieldValueCreator extends Creator { - - -public class FieldValueCreator extends Creator{ private String pathAssistantSid; private String pathFieldTypeSid; private String language; private String value; private String synonymOf; - public FieldValueCreator(final String pathAssistantSid, final String pathFieldTypeSid, final String language, final String value) { + public FieldValueCreator( + final String pathAssistantSid, + final String pathFieldTypeSid, + final String language, + final String value + ) { this.pathAssistantSid = pathAssistantSid; this.pathFieldTypeSid = pathFieldTypeSid; this.language = language; this.value = value; } - public FieldValueCreator setLanguage(final String language){ + public FieldValueCreator setLanguage(final String language) { this.language = language; return this; } - public FieldValueCreator setValue(final String value){ + + public FieldValueCreator setValue(final String value) { this.value = value; return this; } - public FieldValueCreator setSynonymOf(final String synonymOf){ + + public FieldValueCreator setSynonymOf(final String synonymOf) { this.synonymOf = synonymOf; return this; } @Override - public FieldValue create(final TwilioRestClient client){ - String path = "/v1/Assistants/{AssistantSid}/FieldTypes/{FieldTypeSid}/FieldValues"; + public FieldValue create(final TwilioRestClient client) { + String path = + "/v1/Assistants/{AssistantSid}/FieldTypes/{FieldTypeSid}/FieldValues"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"FieldTypeSid"+"}", this.pathFieldTypeSid.toString()); - path = path.replace("{"+"Language"+"}", this.language.toString()); - path = path.replace("{"+"Value"+"}", this.value.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = + path.replace( + "{" + "FieldTypeSid" + "}", + this.pathFieldTypeSid.toString() + ); + path = path.replace("{" + "Language" + "}", this.language.toString()); + path = path.replace("{" + "Value" + "}", this.value.toString()); Request request = new Request( HttpMethod.POST, Domains.AUTOPILOT.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("FieldValue creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "FieldValue creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return FieldValue.fromJson(response.getStream(), client.getObjectMapper()); + return FieldValue.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (language != null) { request.addPostParam("Language", language); - } if (value != null) { request.addPostParam("Value", value); - } if (synonymOf != null) { request.addPostParam("SynonymOf", synonymOf); - } } } diff --git a/src/main/java/com/twilio/rest/autopilot/v1/assistant/fieldtype/FieldValueDeleter.java b/src/main/java/com/twilio/rest/autopilot/v1/assistant/fieldtype/FieldValueDeleter.java index 73182069fa..870fda2988 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/assistant/fieldtype/FieldValueDeleter.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/assistant/fieldtype/FieldValueDeleter.java @@ -24,27 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class FieldValueDeleter extends Deleter { + private String pathAssistantSid; private String pathFieldTypeSid; private String pathSid; - public FieldValueDeleter(final String pathAssistantSid, final String pathFieldTypeSid, final String pathSid){ + public FieldValueDeleter( + final String pathAssistantSid, + final String pathFieldTypeSid, + final String pathSid + ) { this.pathAssistantSid = pathAssistantSid; this.pathFieldTypeSid = pathFieldTypeSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/v1/Assistants/{AssistantSid}/FieldTypes/{FieldTypeSid}/FieldValues/{Sid}"; + String path = + "/v1/Assistants/{AssistantSid}/FieldTypes/{FieldTypeSid}/FieldValues/{Sid}"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"FieldTypeSid"+"}", this.pathFieldTypeSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = + path.replace( + "{" + "FieldTypeSid" + "}", + this.pathFieldTypeSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -54,9 +65,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("FieldValue delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "FieldValue delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/autopilot/v1/assistant/fieldtype/FieldValueFetcher.java b/src/main/java/com/twilio/rest/autopilot/v1/assistant/fieldtype/FieldValueFetcher.java index cd334934d4..57a3ba6879 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/assistant/fieldtype/FieldValueFetcher.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/assistant/fieldtype/FieldValueFetcher.java @@ -24,28 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class FieldValueFetcher extends Fetcher { + private String pathAssistantSid; private String pathFieldTypeSid; private String pathSid; - public FieldValueFetcher(final String pathAssistantSid, final String pathFieldTypeSid, final String pathSid){ + public FieldValueFetcher( + final String pathAssistantSid, + final String pathFieldTypeSid, + final String pathSid + ) { this.pathAssistantSid = pathAssistantSid; this.pathFieldTypeSid = pathFieldTypeSid; this.pathSid = pathSid; } - @Override public FieldValue fetch(final TwilioRestClient client) { - String path = "/v1/Assistants/{AssistantSid}/FieldTypes/{FieldTypeSid}/FieldValues/{Sid}"; + String path = + "/v1/Assistants/{AssistantSid}/FieldTypes/{FieldTypeSid}/FieldValues/{Sid}"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"FieldTypeSid"+"}", this.pathFieldTypeSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = + path.replace( + "{" + "FieldTypeSid" + "}", + this.pathFieldTypeSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -55,15 +65,23 @@ public FieldValue fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("FieldValue fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "FieldValue fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return FieldValue.fromJson(response.getStream(), client.getObjectMapper()); + return FieldValue.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/autopilot/v1/assistant/fieldtype/FieldValueReader.java b/src/main/java/com/twilio/rest/autopilot/v1/assistant/fieldtype/FieldValueReader.java index 8a3d5908bf..ab409e082e 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/assistant/fieldtype/FieldValueReader.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/assistant/fieldtype/FieldValueReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.autopilot.v1.assistant.fieldtype; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,26 +25,28 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class FieldValueReader extends Reader { + private String pathAssistantSid; private String pathFieldTypeSid; private String language; private Integer pageSize; - public FieldValueReader(final String pathAssistantSid, final String pathFieldTypeSid){ + public FieldValueReader( + final String pathAssistantSid, + final String pathFieldTypeSid + ) { this.pathAssistantSid = pathAssistantSid; this.pathFieldTypeSid = pathFieldTypeSid; } - public FieldValueReader setLanguage(final String language){ + public FieldValueReader setLanguage(final String language) { this.language = language; return this; } - public FieldValueReader setPageSize(final Integer pageSize){ + + public FieldValueReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -54,9 +57,18 @@ public ResourceSet read(final TwilioRestClient client) { } public Page firstPage(final TwilioRestClient client) { - String path = "/v1/Assistants/{AssistantSid}/FieldTypes/{FieldTypeSid}/FieldValues"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"FieldTypeSid"+"}", this.pathFieldTypeSid.toString()); + String path = + "/v1/Assistants/{AssistantSid}/FieldTypes/{FieldTypeSid}/FieldValues"; + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = + path.replace( + "{" + "FieldTypeSid" + "}", + this.pathFieldTypeSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -68,13 +80,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("FieldValue read failed: Unable to connect to server"); + throw new ApiConnectionException( + "FieldValue read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -90,7 +110,10 @@ private Page pageForRequest(final TwilioRestClient client, final Req } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.AUTOPILOT.toString()) @@ -98,9 +121,11 @@ public Page previousPage(final Page page, final TwilioRe return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.AUTOPILOT.toString()) @@ -109,25 +134,24 @@ public Page nextPage(final Page page, final TwilioRestCl } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (language != null) { - request.addQueryParam("Language", language); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/Field.java b/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/Field.java index b76fe40561..d5b6c23d5c 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/Field.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/Field.java @@ -23,49 +23,69 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Field extends Resource { + private static final long serialVersionUID = 118531839027400L; - public static FieldCreator creator(final String pathAssistantSid, final String pathTaskSid, final String fieldType, final String uniqueName){ - return new FieldCreator(pathAssistantSid, pathTaskSid, fieldType, uniqueName); + public static FieldCreator creator( + final String pathAssistantSid, + final String pathTaskSid, + final String fieldType, + final String uniqueName + ) { + return new FieldCreator( + pathAssistantSid, + pathTaskSid, + fieldType, + uniqueName + ); } - public static FieldDeleter deleter(final String pathAssistantSid, final String pathTaskSid, final String pathSid){ + public static FieldDeleter deleter( + final String pathAssistantSid, + final String pathTaskSid, + final String pathSid + ) { return new FieldDeleter(pathAssistantSid, pathTaskSid, pathSid); } - public static FieldFetcher fetcher(final String pathAssistantSid, final String pathTaskSid, final String pathSid){ + public static FieldFetcher fetcher( + final String pathAssistantSid, + final String pathTaskSid, + final String pathSid + ) { return new FieldFetcher(pathAssistantSid, pathTaskSid, pathSid); } - public static FieldReader reader(final String pathAssistantSid, final String pathTaskSid){ + public static FieldReader reader( + final String pathAssistantSid, + final String pathTaskSid + ) { return new FieldReader(pathAssistantSid, pathTaskSid); } /** - * Converts a JSON String into a Field object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Field object represented by the provided JSON - */ - public static Field fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Field object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Field object represented by the provided JSON + */ + public static Field fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Field.class); @@ -77,14 +97,17 @@ public static Field fromJson(final String json, final ObjectMapper objectMapper) } /** - * Converts a JSON InputStream into a Field object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Field object represented by the provided JSON - */ - public static Field fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Field object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Field object represented by the provided JSON + */ + public static Field fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Field.class); @@ -107,32 +130,15 @@ public static Field fromJson(final InputStream json, final ObjectMapper objectMa @JsonCreator private Field( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("field_type") - final String fieldType, - - @JsonProperty("task_sid") - final String taskSid, - - @JsonProperty("assistant_sid") - final String assistantSid, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("unique_name") - final String uniqueName, - - @JsonProperty("url") - final URI url + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("field_type") final String fieldType, + @JsonProperty("task_sid") final String taskSid, + @JsonProperty("assistant_sid") final String assistantSid, + @JsonProperty("sid") final String sid, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("url") final URI url ) { this.accountSid = accountSid; this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); @@ -145,37 +151,45 @@ private Field( this.url = url; } - public final String getAccountSid() { - return this.accountSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getFieldType() { - return this.fieldType; - } - public final String getTaskSid() { - return this.taskSid; - } - public final String getAssistantSid() { - return this.assistantSid; - } - public final String getSid() { - return this.sid; - } - public final String getUniqueName() { - return this.uniqueName; - } - public final URI getUrl() { - return this.url; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getFieldType() { + return this.fieldType; + } + + public final String getTaskSid() { + return this.taskSid; + } + + public final String getAssistantSid() { + return this.assistantSid; + } + + public final String getSid() { + return this.sid; + } + + public final String getUniqueName() { + return this.uniqueName; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -185,13 +199,31 @@ public boolean equals(final Object o) { Field other = (Field) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(fieldType, other.fieldType) && Objects.equals(taskSid, other.taskSid) && Objects.equals(assistantSid, other.assistantSid) && Objects.equals(sid, other.sid) && Objects.equals(uniqueName, other.uniqueName) && Objects.equals(url, other.url) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(fieldType, other.fieldType) && + Objects.equals(taskSid, other.taskSid) && + Objects.equals(assistantSid, other.assistantSid) && + Objects.equals(sid, other.sid) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, dateCreated, dateUpdated, fieldType, taskSid, assistantSid, sid, uniqueName, url); + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + fieldType, + taskSid, + assistantSid, + sid, + uniqueName, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/FieldCreator.java b/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/FieldCreator.java index 05bce1a107..b5b6ecfc17 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/FieldCreator.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/FieldCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.autopilot.v1.assistant.task; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,51 +25,66 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class FieldCreator extends Creator { - - -public class FieldCreator extends Creator{ private String pathAssistantSid; private String pathTaskSid; private String fieldType; private String uniqueName; - public FieldCreator(final String pathAssistantSid, final String pathTaskSid, final String fieldType, final String uniqueName) { + public FieldCreator( + final String pathAssistantSid, + final String pathTaskSid, + final String fieldType, + final String uniqueName + ) { this.pathAssistantSid = pathAssistantSid; this.pathTaskSid = pathTaskSid; this.fieldType = fieldType; this.uniqueName = uniqueName; } - public FieldCreator setFieldType(final String fieldType){ + public FieldCreator setFieldType(final String fieldType) { this.fieldType = fieldType; return this; } - public FieldCreator setUniqueName(final String uniqueName){ + + public FieldCreator setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } @Override - public Field create(final TwilioRestClient client){ + public Field create(final TwilioRestClient client) { String path = "/v1/Assistants/{AssistantSid}/Tasks/{TaskSid}/Fields"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"TaskSid"+"}", this.pathTaskSid.toString()); - path = path.replace("{"+"FieldType"+"}", this.fieldType.toString()); - path = path.replace("{"+"UniqueName"+"}", this.uniqueName.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = path.replace("{" + "TaskSid" + "}", this.pathTaskSid.toString()); + path = path.replace("{" + "FieldType" + "}", this.fieldType.toString()); + path = + path.replace("{" + "UniqueName" + "}", this.uniqueName.toString()); Request request = new Request( HttpMethod.POST, Domains.AUTOPILOT.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Field creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Field creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -77,14 +93,13 @@ public Field create(final TwilioRestClient client){ return Field.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (fieldType != null) { request.addPostParam("FieldType", fieldType); - } if (uniqueName != null) { request.addPostParam("UniqueName", uniqueName); - } } } diff --git a/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/FieldDeleter.java b/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/FieldDeleter.java index 68d97b4aa4..cd52688f87 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/FieldDeleter.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/FieldDeleter.java @@ -24,27 +24,34 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class FieldDeleter extends Deleter { + private String pathAssistantSid; private String pathTaskSid; private String pathSid; - public FieldDeleter(final String pathAssistantSid, final String pathTaskSid, final String pathSid){ + public FieldDeleter( + final String pathAssistantSid, + final String pathTaskSid, + final String pathSid + ) { this.pathAssistantSid = pathAssistantSid; this.pathTaskSid = pathTaskSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/v1/Assistants/{AssistantSid}/Tasks/{TaskSid}/Fields/{Sid}"; + String path = + "/v1/Assistants/{AssistantSid}/Tasks/{TaskSid}/Fields/{Sid}"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"TaskSid"+"}", this.pathTaskSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = path.replace("{" + "TaskSid" + "}", this.pathTaskSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -54,9 +61,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Field delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Field delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/FieldFetcher.java b/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/FieldFetcher.java index 5b80f0cd98..393dcb882f 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/FieldFetcher.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/FieldFetcher.java @@ -24,28 +24,34 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class FieldFetcher extends Fetcher { + private String pathAssistantSid; private String pathTaskSid; private String pathSid; - public FieldFetcher(final String pathAssistantSid, final String pathTaskSid, final String pathSid){ + public FieldFetcher( + final String pathAssistantSid, + final String pathTaskSid, + final String pathSid + ) { this.pathAssistantSid = pathAssistantSid; this.pathTaskSid = pathTaskSid; this.pathSid = pathSid; } - @Override public Field fetch(final TwilioRestClient client) { - String path = "/v1/Assistants/{AssistantSid}/Tasks/{TaskSid}/Fields/{Sid}"; + String path = + "/v1/Assistants/{AssistantSid}/Tasks/{TaskSid}/Fields/{Sid}"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"TaskSid"+"}", this.pathTaskSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = path.replace("{" + "TaskSid" + "}", this.pathTaskSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -55,9 +61,14 @@ public Field fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Field fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Field fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/FieldReader.java b/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/FieldReader.java index 6861692dca..3a7f712f6c 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/FieldReader.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/FieldReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.autopilot.v1.assistant.task; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,21 +25,22 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class FieldReader extends Reader { + private String pathAssistantSid; private String pathTaskSid; private Integer pageSize; - public FieldReader(final String pathAssistantSid, final String pathTaskSid){ + public FieldReader( + final String pathAssistantSid, + final String pathTaskSid + ) { this.pathAssistantSid = pathAssistantSid; this.pathTaskSid = pathTaskSid; } - public FieldReader setPageSize(final Integer pageSize){ + public FieldReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -50,8 +52,12 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Assistants/{AssistantSid}/Tasks/{TaskSid}/Fields"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"TaskSid"+"}", this.pathTaskSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = path.replace("{" + "TaskSid" + "}", this.pathTaskSid.toString()); Request request = new Request( HttpMethod.GET, @@ -63,13 +69,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Field read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Field read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -85,7 +99,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.AUTOPILOT.toString()) @@ -93,9 +110,11 @@ public Page previousPage(final Page page, final TwilioRestClient c return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.AUTOPILOT.toString()) @@ -104,21 +123,21 @@ public Page nextPage(final Page page, final TwilioRestClient clien } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/Sample.java b/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/Sample.java index 09c80b3b87..0781b85f09 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/Sample.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/Sample.java @@ -23,53 +23,77 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Sample extends Resource { + private static final long serialVersionUID = 197447215274163L; - public static SampleCreator creator(final String pathAssistantSid, final String pathTaskSid, final String language, final String taggedText){ - return new SampleCreator(pathAssistantSid, pathTaskSid, language, taggedText); + public static SampleCreator creator( + final String pathAssistantSid, + final String pathTaskSid, + final String language, + final String taggedText + ) { + return new SampleCreator( + pathAssistantSid, + pathTaskSid, + language, + taggedText + ); } - public static SampleDeleter deleter(final String pathAssistantSid, final String pathTaskSid, final String pathSid){ + public static SampleDeleter deleter( + final String pathAssistantSid, + final String pathTaskSid, + final String pathSid + ) { return new SampleDeleter(pathAssistantSid, pathTaskSid, pathSid); } - public static SampleFetcher fetcher(final String pathAssistantSid, final String pathTaskSid, final String pathSid){ + public static SampleFetcher fetcher( + final String pathAssistantSid, + final String pathTaskSid, + final String pathSid + ) { return new SampleFetcher(pathAssistantSid, pathTaskSid, pathSid); } - public static SampleReader reader(final String pathAssistantSid, final String pathTaskSid){ + public static SampleReader reader( + final String pathAssistantSid, + final String pathTaskSid + ) { return new SampleReader(pathAssistantSid, pathTaskSid); } - public static SampleUpdater updater(final String pathAssistantSid, final String pathTaskSid, final String pathSid){ + public static SampleUpdater updater( + final String pathAssistantSid, + final String pathTaskSid, + final String pathSid + ) { return new SampleUpdater(pathAssistantSid, pathTaskSid, pathSid); } /** - * Converts a JSON String into a Sample object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Sample object represented by the provided JSON - */ - public static Sample fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Sample object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Sample object represented by the provided JSON + */ + public static Sample fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Sample.class); @@ -81,14 +105,17 @@ public static Sample fromJson(final String json, final ObjectMapper objectMapper } /** - * Converts a JSON InputStream into a Sample object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Sample object represented by the provided JSON - */ - public static Sample fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Sample object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Sample object represented by the provided JSON + */ + public static Sample fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Sample.class); @@ -112,35 +139,16 @@ public static Sample fromJson(final InputStream json, final ObjectMapper objectM @JsonCreator private Sample( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("task_sid") - final String taskSid, - - @JsonProperty("language") - final String language, - - @JsonProperty("assistant_sid") - final String assistantSid, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("tagged_text") - final String taggedText, - - @JsonProperty("url") - final URI url, - - @JsonProperty("source_channel") - final String sourceChannel + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("task_sid") final String taskSid, + @JsonProperty("language") final String language, + @JsonProperty("assistant_sid") final String assistantSid, + @JsonProperty("sid") final String sid, + @JsonProperty("tagged_text") final String taggedText, + @JsonProperty("url") final URI url, + @JsonProperty("source_channel") final String sourceChannel ) { this.accountSid = accountSid; this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); @@ -154,40 +162,49 @@ private Sample( this.sourceChannel = sourceChannel; } - public final String getAccountSid() { - return this.accountSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getTaskSid() { - return this.taskSid; - } - public final String getLanguage() { - return this.language; - } - public final String getAssistantSid() { - return this.assistantSid; - } - public final String getSid() { - return this.sid; - } - public final String getTaggedText() { - return this.taggedText; - } - public final URI getUrl() { - return this.url; - } - public final String getSourceChannel() { - return this.sourceChannel; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getTaskSid() { + return this.taskSid; + } + + public final String getLanguage() { + return this.language; + } + + public final String getAssistantSid() { + return this.assistantSid; + } + + public final String getSid() { + return this.sid; + } + + public final String getTaggedText() { + return this.taggedText; + } + + public final URI getUrl() { + return this.url; + } + + public final String getSourceChannel() { + return this.sourceChannel; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -197,13 +214,33 @@ public boolean equals(final Object o) { Sample other = (Sample) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(taskSid, other.taskSid) && Objects.equals(language, other.language) && Objects.equals(assistantSid, other.assistantSid) && Objects.equals(sid, other.sid) && Objects.equals(taggedText, other.taggedText) && Objects.equals(url, other.url) && Objects.equals(sourceChannel, other.sourceChannel) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(taskSid, other.taskSid) && + Objects.equals(language, other.language) && + Objects.equals(assistantSid, other.assistantSid) && + Objects.equals(sid, other.sid) && + Objects.equals(taggedText, other.taggedText) && + Objects.equals(url, other.url) && + Objects.equals(sourceChannel, other.sourceChannel) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, dateCreated, dateUpdated, taskSid, language, assistantSid, sid, taggedText, url, sourceChannel); + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + taskSid, + language, + assistantSid, + sid, + taggedText, + url, + sourceChannel + ); } - } - diff --git a/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/SampleCreator.java b/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/SampleCreator.java index f91d035fc6..6f30abcda1 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/SampleCreator.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/SampleCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.autopilot.v1.assistant.task; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,56 +25,72 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class SampleCreator extends Creator { - - -public class SampleCreator extends Creator{ private String pathAssistantSid; private String pathTaskSid; private String language; private String taggedText; private String sourceChannel; - public SampleCreator(final String pathAssistantSid, final String pathTaskSid, final String language, final String taggedText) { + public SampleCreator( + final String pathAssistantSid, + final String pathTaskSid, + final String language, + final String taggedText + ) { this.pathAssistantSid = pathAssistantSid; this.pathTaskSid = pathTaskSid; this.language = language; this.taggedText = taggedText; } - public SampleCreator setLanguage(final String language){ + public SampleCreator setLanguage(final String language) { this.language = language; return this; } - public SampleCreator setTaggedText(final String taggedText){ + + public SampleCreator setTaggedText(final String taggedText) { this.taggedText = taggedText; return this; } - public SampleCreator setSourceChannel(final String sourceChannel){ + + public SampleCreator setSourceChannel(final String sourceChannel) { this.sourceChannel = sourceChannel; return this; } @Override - public Sample create(final TwilioRestClient client){ + public Sample create(final TwilioRestClient client) { String path = "/v1/Assistants/{AssistantSid}/Tasks/{TaskSid}/Samples"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"TaskSid"+"}", this.pathTaskSid.toString()); - path = path.replace("{"+"Language"+"}", this.language.toString()); - path = path.replace("{"+"TaggedText"+"}", this.taggedText.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = path.replace("{" + "TaskSid" + "}", this.pathTaskSid.toString()); + path = path.replace("{" + "Language" + "}", this.language.toString()); + path = + path.replace("{" + "TaggedText" + "}", this.taggedText.toString()); Request request = new Request( HttpMethod.POST, Domains.AUTOPILOT.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Sample creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Sample creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,18 +99,16 @@ public Sample create(final TwilioRestClient client){ return Sample.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (language != null) { request.addPostParam("Language", language); - } if (taggedText != null) { request.addPostParam("TaggedText", taggedText); - } if (sourceChannel != null) { request.addPostParam("SourceChannel", sourceChannel); - } } } diff --git a/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/SampleDeleter.java b/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/SampleDeleter.java index c3d8aae614..fa58ee04a6 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/SampleDeleter.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/SampleDeleter.java @@ -24,27 +24,34 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class SampleDeleter extends Deleter { + private String pathAssistantSid; private String pathTaskSid; private String pathSid; - public SampleDeleter(final String pathAssistantSid, final String pathTaskSid, final String pathSid){ + public SampleDeleter( + final String pathAssistantSid, + final String pathTaskSid, + final String pathSid + ) { this.pathAssistantSid = pathAssistantSid; this.pathTaskSid = pathTaskSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/v1/Assistants/{AssistantSid}/Tasks/{TaskSid}/Samples/{Sid}"; + String path = + "/v1/Assistants/{AssistantSid}/Tasks/{TaskSid}/Samples/{Sid}"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"TaskSid"+"}", this.pathTaskSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = path.replace("{" + "TaskSid" + "}", this.pathTaskSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -54,9 +61,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Sample delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Sample delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/SampleFetcher.java b/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/SampleFetcher.java index 9322182ae4..8852ee7e57 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/SampleFetcher.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/SampleFetcher.java @@ -24,28 +24,34 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class SampleFetcher extends Fetcher { + private String pathAssistantSid; private String pathTaskSid; private String pathSid; - public SampleFetcher(final String pathAssistantSid, final String pathTaskSid, final String pathSid){ + public SampleFetcher( + final String pathAssistantSid, + final String pathTaskSid, + final String pathSid + ) { this.pathAssistantSid = pathAssistantSid; this.pathTaskSid = pathTaskSid; this.pathSid = pathSid; } - @Override public Sample fetch(final TwilioRestClient client) { - String path = "/v1/Assistants/{AssistantSid}/Tasks/{TaskSid}/Samples/{Sid}"; + String path = + "/v1/Assistants/{AssistantSid}/Tasks/{TaskSid}/Samples/{Sid}"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"TaskSid"+"}", this.pathTaskSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = path.replace("{" + "TaskSid" + "}", this.pathTaskSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -55,9 +61,14 @@ public Sample fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Sample fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Sample fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/SampleReader.java b/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/SampleReader.java index 3ceed3120f..d3ce34cfe6 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/SampleReader.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/SampleReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.autopilot.v1.assistant.task; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,26 +25,28 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class SampleReader extends Reader { + private String pathAssistantSid; private String pathTaskSid; private String language; private Integer pageSize; - public SampleReader(final String pathAssistantSid, final String pathTaskSid){ + public SampleReader( + final String pathAssistantSid, + final String pathTaskSid + ) { this.pathAssistantSid = pathAssistantSid; this.pathTaskSid = pathTaskSid; } - public SampleReader setLanguage(final String language){ + public SampleReader setLanguage(final String language) { this.language = language; return this; } - public SampleReader setPageSize(final Integer pageSize){ + + public SampleReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -55,8 +58,12 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Assistants/{AssistantSid}/Tasks/{TaskSid}/Samples"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"TaskSid"+"}", this.pathTaskSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = path.replace("{" + "TaskSid" + "}", this.pathTaskSid.toString()); Request request = new Request( HttpMethod.GET, @@ -68,13 +75,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Sample read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Sample read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -90,7 +105,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.AUTOPILOT.toString()) @@ -98,9 +116,11 @@ public Page previousPage(final Page page, final TwilioRestClient return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.AUTOPILOT.toString()) @@ -109,25 +129,24 @@ public Page nextPage(final Page page, final TwilioRestClient cli } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (language != null) { - request.addQueryParam("Language", language); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/SampleUpdater.java b/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/SampleUpdater.java index c3bf60d14c..9c70a07b11 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/SampleUpdater.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/SampleUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.autopilot.v1.assistant.task; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class SampleUpdater extends Updater { - - -public class SampleUpdater extends Updater{ private String pathAssistantSid; private String pathTaskSid; private String pathSid; @@ -35,44 +34,61 @@ public class SampleUpdater extends Updater{ private String taggedText; private String sourceChannel; - public SampleUpdater(final String pathAssistantSid, final String pathTaskSid, final String pathSid){ + public SampleUpdater( + final String pathAssistantSid, + final String pathTaskSid, + final String pathSid + ) { this.pathAssistantSid = pathAssistantSid; this.pathTaskSid = pathTaskSid; this.pathSid = pathSid; } - public SampleUpdater setLanguage(final String language){ + public SampleUpdater setLanguage(final String language) { this.language = language; return this; } - public SampleUpdater setTaggedText(final String taggedText){ + + public SampleUpdater setTaggedText(final String taggedText) { this.taggedText = taggedText; return this; } - public SampleUpdater setSourceChannel(final String sourceChannel){ + + public SampleUpdater setSourceChannel(final String sourceChannel) { this.sourceChannel = sourceChannel; return this; } @Override - public Sample update(final TwilioRestClient client){ - String path = "/v1/Assistants/{AssistantSid}/Tasks/{TaskSid}/Samples/{Sid}"; + public Sample update(final TwilioRestClient client) { + String path = + "/v1/Assistants/{AssistantSid}/Tasks/{TaskSid}/Samples/{Sid}"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"TaskSid"+"}", this.pathTaskSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = path.replace("{" + "TaskSid" + "}", this.pathTaskSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.AUTOPILOT.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Sample update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Sample update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -81,18 +97,16 @@ public Sample update(final TwilioRestClient client){ return Sample.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (language != null) { request.addPostParam("Language", language); - } if (taggedText != null) { request.addPostParam("TaggedText", taggedText); - } if (sourceChannel != null) { request.addPostParam("SourceChannel", sourceChannel); - } } } diff --git a/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/TaskActions.java b/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/TaskActions.java index f01d461daa..58501a51f9 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/TaskActions.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/TaskActions.java @@ -22,42 +22,47 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class TaskActions extends Resource { + private static final long serialVersionUID = 36530790788418L; - public static TaskActionsFetcher fetcher(final String pathAssistantSid, final String pathTaskSid){ + public static TaskActionsFetcher fetcher( + final String pathAssistantSid, + final String pathTaskSid + ) { return new TaskActionsFetcher(pathAssistantSid, pathTaskSid); } - public static TaskActionsUpdater updater(final String pathAssistantSid, final String pathTaskSid){ + public static TaskActionsUpdater updater( + final String pathAssistantSid, + final String pathTaskSid + ) { return new TaskActionsUpdater(pathAssistantSid, pathTaskSid); } /** - * Converts a JSON String into a TaskActions object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return TaskActions object represented by the provided JSON - */ - public static TaskActions fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a TaskActions object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return TaskActions object represented by the provided JSON + */ + public static TaskActions fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, TaskActions.class); @@ -69,14 +74,17 @@ public static TaskActions fromJson(final String json, final ObjectMapper objectM } /** - * Converts a JSON InputStream into a TaskActions object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return TaskActions object represented by the provided JSON - */ - public static TaskActions fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a TaskActions object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return TaskActions object represented by the provided JSON + */ + public static TaskActions fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, TaskActions.class); @@ -95,20 +103,11 @@ public static TaskActions fromJson(final InputStream json, final ObjectMapper ob @JsonCreator private TaskActions( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("assistant_sid") - final String assistantSid, - - @JsonProperty("task_sid") - final String taskSid, - - @JsonProperty("url") - final URI url, - - @JsonProperty("data") - final Map data + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("assistant_sid") final String assistantSid, + @JsonProperty("task_sid") final String taskSid, + @JsonProperty("url") final URI url, + @JsonProperty("data") final Map data ) { this.accountSid = accountSid; this.assistantSid = assistantSid; @@ -117,25 +116,29 @@ private TaskActions( this.data = data; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getAssistantSid() { - return this.assistantSid; - } - public final String getTaskSid() { - return this.taskSid; - } - public final URI getUrl() { - return this.url; - } - public final Map getData() { - return this.data; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getAssistantSid() { + return this.assistantSid; + } + + public final String getTaskSid() { + return this.taskSid; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getData() { + return this.data; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -145,13 +148,17 @@ public boolean equals(final Object o) { TaskActions other = (TaskActions) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(assistantSid, other.assistantSid) && Objects.equals(taskSid, other.taskSid) && Objects.equals(url, other.url) && Objects.equals(data, other.data) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(assistantSid, other.assistantSid) && + Objects.equals(taskSid, other.taskSid) && + Objects.equals(url, other.url) && + Objects.equals(data, other.data) + ); } @Override public int hashCode() { return Objects.hash(accountSid, assistantSid, taskSid, url, data); } - } - diff --git a/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/TaskActionsFetcher.java b/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/TaskActionsFetcher.java index 97b60e8cbb..05c27da173 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/TaskActionsFetcher.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/TaskActionsFetcher.java @@ -24,25 +24,29 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class TaskActionsFetcher extends Fetcher { + private String pathAssistantSid; private String pathTaskSid; - public TaskActionsFetcher(final String pathAssistantSid, final String pathTaskSid){ + public TaskActionsFetcher( + final String pathAssistantSid, + final String pathTaskSid + ) { this.pathAssistantSid = pathAssistantSid; this.pathTaskSid = pathTaskSid; } - @Override public TaskActions fetch(final TwilioRestClient client) { String path = "/v1/Assistants/{AssistantSid}/Tasks/{TaskSid}/Actions"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"TaskSid"+"}", this.pathTaskSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = path.replace("{" + "TaskSid" + "}", this.pathTaskSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,15 +56,23 @@ public TaskActions fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("TaskActions fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "TaskActions fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return TaskActions.fromJson(response.getStream(), client.getObjectMapper()); + return TaskActions.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/TaskActionsUpdater.java b/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/TaskActionsUpdater.java index 41bf1b8b25..bdb81e23a0 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/TaskActionsUpdater.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/TaskActionsUpdater.java @@ -15,8 +15,9 @@ package com.twilio.rest.autopilot.v1.assistant.task; import com.twilio.base.Updater; -import com.twilio.exception.ApiConnectionException; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Converter; +import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; @@ -24,56 +25,70 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - import java.util.Map; +public class TaskActionsUpdater extends Updater { -public class TaskActionsUpdater extends Updater{ private String pathAssistantSid; private String pathTaskSid; private Map actions; - public TaskActionsUpdater(final String pathAssistantSid, final String pathTaskSid){ + public TaskActionsUpdater( + final String pathAssistantSid, + final String pathTaskSid + ) { this.pathAssistantSid = pathAssistantSid; this.pathTaskSid = pathTaskSid; } - public TaskActionsUpdater setActions(final Map actions){ + public TaskActionsUpdater setActions(final Map actions) { this.actions = actions; return this; } @Override - public TaskActions update(final TwilioRestClient client){ + public TaskActions update(final TwilioRestClient client) { String path = "/v1/Assistants/{AssistantSid}/Tasks/{TaskSid}/Actions"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"TaskSid"+"}", this.pathTaskSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = path.replace("{" + "TaskSid" + "}", this.pathTaskSid.toString()); Request request = new Request( HttpMethod.POST, Domains.AUTOPILOT.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("TaskActions update failed: Unable to connect to server"); + throw new ApiConnectionException( + "TaskActions update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return TaskActions.fromJson(response.getStream(), client.getObjectMapper()); + return TaskActions.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (actions != null) { - request.addPostParam("Actions", Converter.mapToJson(actions)); - + request.addPostParam("Actions", Converter.mapToJson(actions)); } } } diff --git a/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/TaskStatistics.java b/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/TaskStatistics.java index 5c1c13ccd3..f52556b4e6 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/TaskStatistics.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/TaskStatistics.java @@ -22,36 +22,38 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class TaskStatistics extends Resource { + private static final long serialVersionUID = 99044881135361L; - public static TaskStatisticsFetcher fetcher(final String pathAssistantSid, final String pathTaskSid){ + public static TaskStatisticsFetcher fetcher( + final String pathAssistantSid, + final String pathTaskSid + ) { return new TaskStatisticsFetcher(pathAssistantSid, pathTaskSid); } /** - * Converts a JSON String into a TaskStatistics object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return TaskStatistics object represented by the provided JSON - */ - public static TaskStatistics fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a TaskStatistics object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return TaskStatistics object represented by the provided JSON + */ + public static TaskStatistics fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, TaskStatistics.class); @@ -63,14 +65,17 @@ public static TaskStatistics fromJson(final String json, final ObjectMapper obje } /** - * Converts a JSON InputStream into a TaskStatistics object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return TaskStatistics object represented by the provided JSON - */ - public static TaskStatistics fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a TaskStatistics object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return TaskStatistics object represented by the provided JSON + */ + public static TaskStatistics fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, TaskStatistics.class); @@ -90,23 +95,12 @@ public static TaskStatistics fromJson(final InputStream json, final ObjectMapper @JsonCreator private TaskStatistics( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("assistant_sid") - final String assistantSid, - - @JsonProperty("task_sid") - final String taskSid, - - @JsonProperty("samples_count") - final Integer samplesCount, - - @JsonProperty("fields_count") - final Integer fieldsCount, - - @JsonProperty("url") - final URI url + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("assistant_sid") final String assistantSid, + @JsonProperty("task_sid") final String taskSid, + @JsonProperty("samples_count") final Integer samplesCount, + @JsonProperty("fields_count") final Integer fieldsCount, + @JsonProperty("url") final URI url ) { this.accountSid = accountSid; this.assistantSid = assistantSid; @@ -116,28 +110,33 @@ private TaskStatistics( this.url = url; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getAssistantSid() { - return this.assistantSid; - } - public final String getTaskSid() { - return this.taskSid; - } - public final Integer getSamplesCount() { - return this.samplesCount; - } - public final Integer getFieldsCount() { - return this.fieldsCount; - } - public final URI getUrl() { - return this.url; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getAssistantSid() { + return this.assistantSid; + } + + public final String getTaskSid() { + return this.taskSid; + } + + public final Integer getSamplesCount() { + return this.samplesCount; + } + + public final Integer getFieldsCount() { + return this.fieldsCount; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -147,13 +146,25 @@ public boolean equals(final Object o) { TaskStatistics other = (TaskStatistics) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(assistantSid, other.assistantSid) && Objects.equals(taskSid, other.taskSid) && Objects.equals(samplesCount, other.samplesCount) && Objects.equals(fieldsCount, other.fieldsCount) && Objects.equals(url, other.url) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(assistantSid, other.assistantSid) && + Objects.equals(taskSid, other.taskSid) && + Objects.equals(samplesCount, other.samplesCount) && + Objects.equals(fieldsCount, other.fieldsCount) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, assistantSid, taskSid, samplesCount, fieldsCount, url); + return Objects.hash( + accountSid, + assistantSid, + taskSid, + samplesCount, + fieldsCount, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/TaskStatisticsFetcher.java b/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/TaskStatisticsFetcher.java index 72387095f2..e0eeb638d4 100644 --- a/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/TaskStatisticsFetcher.java +++ b/src/main/java/com/twilio/rest/autopilot/v1/assistant/task/TaskStatisticsFetcher.java @@ -24,25 +24,30 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class TaskStatisticsFetcher extends Fetcher { + private String pathAssistantSid; private String pathTaskSid; - public TaskStatisticsFetcher(final String pathAssistantSid, final String pathTaskSid){ + public TaskStatisticsFetcher( + final String pathAssistantSid, + final String pathTaskSid + ) { this.pathAssistantSid = pathAssistantSid; this.pathTaskSid = pathTaskSid; } - @Override public TaskStatistics fetch(final TwilioRestClient client) { - String path = "/v1/Assistants/{AssistantSid}/Tasks/{TaskSid}/Statistics"; + String path = + "/v1/Assistants/{AssistantSid}/Tasks/{TaskSid}/Statistics"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"TaskSid"+"}", this.pathTaskSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = path.replace("{" + "TaskSid" + "}", this.pathTaskSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,15 +57,23 @@ public TaskStatistics fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("TaskStatistics fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "TaskStatistics fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return TaskStatistics.fromJson(response.getStream(), client.getObjectMapper()); + return TaskStatistics.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/bulkexports/v1/Export.java b/src/main/java/com/twilio/rest/bulkexports/v1/Export.java index e648862e17..79abf7db2b 100644 --- a/src/main/java/com/twilio/rest/bulkexports/v1/Export.java +++ b/src/main/java/com/twilio/rest/bulkexports/v1/Export.java @@ -22,38 +22,37 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Export extends Resource { + private static final long serialVersionUID = 148899891151757L; - public static ExportFetcher fetcher(final String pathResourceType){ + public static ExportFetcher fetcher(final String pathResourceType) { return new ExportFetcher(pathResourceType); } /** - * Converts a JSON String into a Export object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Export object represented by the provided JSON - */ - public static Export fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Export object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Export object represented by the provided JSON + */ + public static Export fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Export.class); @@ -65,14 +64,17 @@ public static Export fromJson(final String json, final ObjectMapper objectMapper } /** - * Converts a JSON InputStream into a Export object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Export object represented by the provided JSON - */ - public static Export fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Export object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Export object represented by the provided JSON + */ + public static Export fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Export.class); @@ -89,33 +91,30 @@ public static Export fromJson(final InputStream json, final ObjectMapper objectM @JsonCreator private Export( - @JsonProperty("resource_type") - final String resourceType, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("resource_type") final String resourceType, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.resourceType = resourceType; this.url = url; this.links = links; } - public final String getResourceType() { - return this.resourceType; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getResourceType() { + return this.resourceType; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -125,13 +124,15 @@ public boolean equals(final Object o) { Export other = (Export) o; - return Objects.equals(resourceType, other.resourceType) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(resourceType, other.resourceType) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { return Objects.hash(resourceType, url, links); } - } - diff --git a/src/main/java/com/twilio/rest/bulkexports/v1/ExportConfiguration.java b/src/main/java/com/twilio/rest/bulkexports/v1/ExportConfiguration.java index cb985f88de..a1c21404ba 100644 --- a/src/main/java/com/twilio/rest/bulkexports/v1/ExportConfiguration.java +++ b/src/main/java/com/twilio/rest/bulkexports/v1/ExportConfiguration.java @@ -22,40 +22,43 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class ExportConfiguration extends Resource { + private static final long serialVersionUID = 268277535772365L; - public static ExportConfigurationFetcher fetcher(final String pathResourceType){ + public static ExportConfigurationFetcher fetcher( + final String pathResourceType + ) { return new ExportConfigurationFetcher(pathResourceType); } - public static ExportConfigurationUpdater updater(final String pathResourceType){ + public static ExportConfigurationUpdater updater( + final String pathResourceType + ) { return new ExportConfigurationUpdater(pathResourceType); } /** - * Converts a JSON String into a ExportConfiguration object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return ExportConfiguration object represented by the provided JSON - */ - public static ExportConfiguration fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a ExportConfiguration object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return ExportConfiguration object represented by the provided JSON + */ + public static ExportConfiguration fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, ExportConfiguration.class); @@ -67,14 +70,17 @@ public static ExportConfiguration fromJson(final String json, final ObjectMapper } /** - * Converts a JSON InputStream into a ExportConfiguration object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return ExportConfiguration object represented by the provided JSON - */ - public static ExportConfiguration fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a ExportConfiguration object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return ExportConfiguration object represented by the provided JSON + */ + public static ExportConfiguration fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, ExportConfiguration.class); @@ -93,20 +99,11 @@ public static ExportConfiguration fromJson(final InputStream json, final ObjectM @JsonCreator private ExportConfiguration( - @JsonProperty("enabled") - final Boolean enabled, - - @JsonProperty("webhook_url") - final URI webhookUrl, - - @JsonProperty("webhook_method") - final String webhookMethod, - - @JsonProperty("resource_type") - final String resourceType, - - @JsonProperty("url") - final URI url + @JsonProperty("enabled") final Boolean enabled, + @JsonProperty("webhook_url") final URI webhookUrl, + @JsonProperty("webhook_method") final String webhookMethod, + @JsonProperty("resource_type") final String resourceType, + @JsonProperty("url") final URI url ) { this.enabled = enabled; this.webhookUrl = webhookUrl; @@ -115,25 +112,29 @@ private ExportConfiguration( this.url = url; } - public final Boolean getEnabled() { - return this.enabled; - } - public final URI getWebhookUrl() { - return this.webhookUrl; - } - public final String getWebhookMethod() { - return this.webhookMethod; - } - public final String getResourceType() { - return this.resourceType; - } - public final URI getUrl() { - return this.url; - } + public final Boolean getEnabled() { + return this.enabled; + } + + public final URI getWebhookUrl() { + return this.webhookUrl; + } + + public final String getWebhookMethod() { + return this.webhookMethod; + } + + public final String getResourceType() { + return this.resourceType; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -143,13 +144,23 @@ public boolean equals(final Object o) { ExportConfiguration other = (ExportConfiguration) o; - return Objects.equals(enabled, other.enabled) && Objects.equals(webhookUrl, other.webhookUrl) && Objects.equals(webhookMethod, other.webhookMethod) && Objects.equals(resourceType, other.resourceType) && Objects.equals(url, other.url) ; + return ( + Objects.equals(enabled, other.enabled) && + Objects.equals(webhookUrl, other.webhookUrl) && + Objects.equals(webhookMethod, other.webhookMethod) && + Objects.equals(resourceType, other.resourceType) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(enabled, webhookUrl, webhookMethod, resourceType, url); + return Objects.hash( + enabled, + webhookUrl, + webhookMethod, + resourceType, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/bulkexports/v1/ExportConfigurationFetcher.java b/src/main/java/com/twilio/rest/bulkexports/v1/ExportConfigurationFetcher.java index 4f46514d72..c9642c4f71 100644 --- a/src/main/java/com/twilio/rest/bulkexports/v1/ExportConfigurationFetcher.java +++ b/src/main/java/com/twilio/rest/bulkexports/v1/ExportConfigurationFetcher.java @@ -24,22 +24,23 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class ExportConfigurationFetcher extends Fetcher { + private String pathResourceType; - public ExportConfigurationFetcher(final String pathResourceType){ + public ExportConfigurationFetcher(final String pathResourceType) { this.pathResourceType = pathResourceType; } - @Override public ExportConfiguration fetch(final TwilioRestClient client) { String path = "/v1/Exports/{ResourceType}/Configuration"; - path = path.replace("{"+"ResourceType"+"}", this.pathResourceType.toString()); + path = + path.replace( + "{" + "ResourceType" + "}", + this.pathResourceType.toString() + ); Request request = new Request( HttpMethod.GET, @@ -49,15 +50,23 @@ public ExportConfiguration fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("ExportConfiguration fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "ExportConfiguration fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return ExportConfiguration.fromJson(response.getStream(), client.getObjectMapper()); + return ExportConfiguration.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/bulkexports/v1/ExportConfigurationUpdater.java b/src/main/java/com/twilio/rest/bulkexports/v1/ExportConfigurationUpdater.java index b25146e5c3..af08ae57ce 100644 --- a/src/main/java/com/twilio/rest/bulkexports/v1/ExportConfigurationUpdater.java +++ b/src/main/java/com/twilio/rest/bulkexports/v1/ExportConfigurationUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.bulkexports.v1; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -24,75 +25,88 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.net.URI; +public class ExportConfigurationUpdater extends Updater { - -public class ExportConfigurationUpdater extends Updater{ private String pathResourceType; private Boolean enabled; private URI webhookUrl; private String webhookMethod; - public ExportConfigurationUpdater(final String pathResourceType){ + public ExportConfigurationUpdater(final String pathResourceType) { this.pathResourceType = pathResourceType; } - public ExportConfigurationUpdater setEnabled(final Boolean enabled){ + public ExportConfigurationUpdater setEnabled(final Boolean enabled) { this.enabled = enabled; return this; } - public ExportConfigurationUpdater setWebhookUrl(final URI webhookUrl){ + + public ExportConfigurationUpdater setWebhookUrl(final URI webhookUrl) { this.webhookUrl = webhookUrl; return this; } - public ExportConfigurationUpdater setWebhookUrl(final String webhookUrl){ + public ExportConfigurationUpdater setWebhookUrl(final String webhookUrl) { return setWebhookUrl(Promoter.uriFromString(webhookUrl)); } - public ExportConfigurationUpdater setWebhookMethod(final String webhookMethod){ + + public ExportConfigurationUpdater setWebhookMethod( + final String webhookMethod + ) { this.webhookMethod = webhookMethod; return this; } @Override - public ExportConfiguration update(final TwilioRestClient client){ + public ExportConfiguration update(final TwilioRestClient client) { String path = "/v1/Exports/{ResourceType}/Configuration"; - path = path.replace("{"+"ResourceType"+"}", this.pathResourceType.toString()); + path = + path.replace( + "{" + "ResourceType" + "}", + this.pathResourceType.toString() + ); Request request = new Request( HttpMethod.POST, Domains.BULKEXPORTS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("ExportConfiguration update failed: Unable to connect to server"); + throw new ApiConnectionException( + "ExportConfiguration update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return ExportConfiguration.fromJson(response.getStream(), client.getObjectMapper()); + return ExportConfiguration.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (enabled != null) { request.addPostParam("Enabled", enabled.toString()); - } if (webhookUrl != null) { request.addPostParam("WebhookUrl", webhookUrl.toString()); - } if (webhookMethod != null) { request.addPostParam("WebhookMethod", webhookMethod); - } } } diff --git a/src/main/java/com/twilio/rest/bulkexports/v1/ExportFetcher.java b/src/main/java/com/twilio/rest/bulkexports/v1/ExportFetcher.java index df65b45d6d..6331d95c21 100644 --- a/src/main/java/com/twilio/rest/bulkexports/v1/ExportFetcher.java +++ b/src/main/java/com/twilio/rest/bulkexports/v1/ExportFetcher.java @@ -24,22 +24,23 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class ExportFetcher extends Fetcher { + private String pathResourceType; - public ExportFetcher(final String pathResourceType){ + public ExportFetcher(final String pathResourceType) { this.pathResourceType = pathResourceType; } - @Override public Export fetch(final TwilioRestClient client) { String path = "/v1/Exports/{ResourceType}"; - path = path.replace("{"+"ResourceType"+"}", this.pathResourceType.toString()); + path = + path.replace( + "{" + "ResourceType" + "}", + this.pathResourceType.toString() + ); Request request = new Request( HttpMethod.GET, @@ -49,9 +50,14 @@ public Export fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Export fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Export fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/bulkexports/v1/export/Day.java b/src/main/java/com/twilio/rest/bulkexports/v1/export/Day.java index 630590cbb6..200be912d9 100644 --- a/src/main/java/com/twilio/rest/bulkexports/v1/export/Day.java +++ b/src/main/java/com/twilio/rest/bulkexports/v1/export/Day.java @@ -22,40 +22,42 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Day extends Resource { + private static final long serialVersionUID = 277630118297206L; - public static DayFetcher fetcher(final String pathResourceType, final String pathDay){ + public static DayFetcher fetcher( + final String pathResourceType, + final String pathDay + ) { return new DayFetcher(pathResourceType, pathDay); } - public static DayReader reader(final String pathResourceType){ + public static DayReader reader(final String pathResourceType) { return new DayReader(pathResourceType); } /** - * Converts a JSON String into a Day object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Day object represented by the provided JSON - */ - public static Day fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Day object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Day object represented by the provided JSON + */ + public static Day fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Day.class); @@ -67,14 +69,17 @@ public static Day fromJson(final String json, final ObjectMapper objectMapper) { } /** - * Converts a JSON InputStream into a Day object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Day object represented by the provided JSON - */ - public static Day fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Day object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Day object represented by the provided JSON + */ + public static Day fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Day.class); @@ -94,23 +99,12 @@ public static Day fromJson(final InputStream json, final ObjectMapper objectMapp @JsonCreator private Day( - @JsonProperty("redirect_to") - final URI redirectTo, - - @JsonProperty("day") - final String day, - - @JsonProperty("size") - final Integer size, - - @JsonProperty("create_date") - final String createDate, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("resource_type") - final String resourceType + @JsonProperty("redirect_to") final URI redirectTo, + @JsonProperty("day") final String day, + @JsonProperty("size") final Integer size, + @JsonProperty("create_date") final String createDate, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("resource_type") final String resourceType ) { this.redirectTo = redirectTo; this.day = day; @@ -120,28 +114,33 @@ private Day( this.resourceType = resourceType; } - public final URI getRedirectTo() { - return this.redirectTo; - } - public final String getDay() { - return this.day; - } - public final Integer getSize() { - return this.size; - } - public final String getCreateDate() { - return this.createDate; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getResourceType() { - return this.resourceType; - } + public final URI getRedirectTo() { + return this.redirectTo; + } + + public final String getDay() { + return this.day; + } + + public final Integer getSize() { + return this.size; + } + + public final String getCreateDate() { + return this.createDate; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getResourceType() { + return this.resourceType; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -151,13 +150,25 @@ public boolean equals(final Object o) { Day other = (Day) o; - return Objects.equals(redirectTo, other.redirectTo) && Objects.equals(day, other.day) && Objects.equals(size, other.size) && Objects.equals(createDate, other.createDate) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(resourceType, other.resourceType) ; + return ( + Objects.equals(redirectTo, other.redirectTo) && + Objects.equals(day, other.day) && + Objects.equals(size, other.size) && + Objects.equals(createDate, other.createDate) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(resourceType, other.resourceType) + ); } @Override public int hashCode() { - return Objects.hash(redirectTo, day, size, createDate, friendlyName, resourceType); + return Objects.hash( + redirectTo, + day, + size, + createDate, + friendlyName, + resourceType + ); } - } - diff --git a/src/main/java/com/twilio/rest/bulkexports/v1/export/DayFetcher.java b/src/main/java/com/twilio/rest/bulkexports/v1/export/DayFetcher.java index 13cee3a77d..fc20f3d163 100644 --- a/src/main/java/com/twilio/rest/bulkexports/v1/export/DayFetcher.java +++ b/src/main/java/com/twilio/rest/bulkexports/v1/export/DayFetcher.java @@ -24,25 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class DayFetcher extends Fetcher { + private String pathResourceType; private String pathDay; - public DayFetcher(final String pathResourceType, final String pathDay){ + public DayFetcher(final String pathResourceType, final String pathDay) { this.pathResourceType = pathResourceType; this.pathDay = pathDay; } - @Override public Day fetch(final TwilioRestClient client) { String path = "/v1/Exports/{ResourceType}/Days/{Day}"; - path = path.replace("{"+"ResourceType"+"}", this.pathResourceType.toString()); - path = path.replace("{"+"Day"+"}", this.pathDay.toString()); + path = + path.replace( + "{" + "ResourceType" + "}", + this.pathResourceType.toString() + ); + path = path.replace("{" + "Day" + "}", this.pathDay.toString()); Request request = new Request( HttpMethod.GET, @@ -52,9 +53,14 @@ public Day fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Day fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Day fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/bulkexports/v1/export/DayReader.java b/src/main/java/com/twilio/rest/bulkexports/v1/export/DayReader.java index acfe76336f..cd8735194b 100644 --- a/src/main/java/com/twilio/rest/bulkexports/v1/export/DayReader.java +++ b/src/main/java/com/twilio/rest/bulkexports/v1/export/DayReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.bulkexports.v1.export; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,19 +25,17 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class DayReader extends Reader { + private String pathResourceType; private Integer pageSize; - public DayReader(final String pathResourceType){ + public DayReader(final String pathResourceType) { this.pathResourceType = pathResourceType; } - public DayReader setPageSize(final Integer pageSize){ + public DayReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -48,7 +47,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Exports/{ResourceType}/Days"; - path = path.replace("{"+"ResourceType"+"}", this.pathResourceType.toString()); + path = + path.replace( + "{" + "ResourceType" + "}", + this.pathResourceType.toString() + ); Request request = new Request( HttpMethod.GET, @@ -60,13 +63,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Day read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Day read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +93,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request re } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.BULKEXPORTS.toString()) @@ -90,9 +104,11 @@ public Page previousPage(final Page page, final TwilioRestClient clien return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.BULKEXPORTS.toString()) @@ -101,21 +117,21 @@ public Page nextPage(final Page page, final TwilioRestClient client) { } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/bulkexports/v1/export/ExportCustomJob.java b/src/main/java/com/twilio/rest/bulkexports/v1/export/ExportCustomJob.java index 8369ad82ec..058ef9a15c 100644 --- a/src/main/java/com/twilio/rest/bulkexports/v1/export/ExportCustomJob.java +++ b/src/main/java/com/twilio/rest/bulkexports/v1/export/ExportCustomJob.java @@ -22,41 +22,50 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class ExportCustomJob extends Resource { + private static final long serialVersionUID = 125242558228L; - public static ExportCustomJobCreator creator(final String pathResourceType, final String startDay, final String endDay, final String friendlyName){ - return new ExportCustomJobCreator(pathResourceType, startDay, endDay, friendlyName); + public static ExportCustomJobCreator creator( + final String pathResourceType, + final String startDay, + final String endDay, + final String friendlyName + ) { + return new ExportCustomJobCreator( + pathResourceType, + startDay, + endDay, + friendlyName + ); } - public static ExportCustomJobReader reader(final String pathResourceType){ + public static ExportCustomJobReader reader(final String pathResourceType) { return new ExportCustomJobReader(pathResourceType); } /** - * Converts a JSON String into a ExportCustomJob object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return ExportCustomJob object represented by the provided JSON - */ - public static ExportCustomJob fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a ExportCustomJob object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return ExportCustomJob object represented by the provided JSON + */ + public static ExportCustomJob fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, ExportCustomJob.class); @@ -68,14 +77,17 @@ public static ExportCustomJob fromJson(final String json, final ObjectMapper obj } /** - * Converts a JSON InputStream into a ExportCustomJob object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return ExportCustomJob object represented by the provided JSON - */ - public static ExportCustomJob fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a ExportCustomJob object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return ExportCustomJob object represented by the provided JSON + */ + public static ExportCustomJob fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, ExportCustomJob.class); @@ -100,38 +112,19 @@ public static ExportCustomJob fromJson(final InputStream json, final ObjectMappe @JsonCreator private ExportCustomJob( - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("resource_type") - final String resourceType, - - @JsonProperty("start_day") - final String startDay, - - @JsonProperty("end_day") - final String endDay, - - @JsonProperty("webhook_url") - final String webhookUrl, - - @JsonProperty("webhook_method") - final String webhookMethod, - - @JsonProperty("email") - final String email, - - @JsonProperty("job_sid") - final String jobSid, - - @JsonProperty("details") - final Map details, - - @JsonProperty("job_queue_position") - final String jobQueuePosition, - - @JsonProperty("estimated_completion_time") - final String estimatedCompletionTime + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("resource_type") final String resourceType, + @JsonProperty("start_day") final String startDay, + @JsonProperty("end_day") final String endDay, + @JsonProperty("webhook_url") final String webhookUrl, + @JsonProperty("webhook_method") final String webhookMethod, + @JsonProperty("email") final String email, + @JsonProperty("job_sid") final String jobSid, + @JsonProperty("details") final Map details, + @JsonProperty("job_queue_position") final String jobQueuePosition, + @JsonProperty( + "estimated_completion_time" + ) final String estimatedCompletionTime ) { this.friendlyName = friendlyName; this.resourceType = resourceType; @@ -146,43 +139,53 @@ private ExportCustomJob( this.estimatedCompletionTime = estimatedCompletionTime; } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getResourceType() { - return this.resourceType; - } - public final String getStartDay() { - return this.startDay; - } - public final String getEndDay() { - return this.endDay; - } - public final String getWebhookUrl() { - return this.webhookUrl; - } - public final String getWebhookMethod() { - return this.webhookMethod; - } - public final String getEmail() { - return this.email; - } - public final String getJobSid() { - return this.jobSid; - } - public final Map getDetails() { - return this.details; - } - public final String getJobQueuePosition() { - return this.jobQueuePosition; - } - public final String getEstimatedCompletionTime() { - return this.estimatedCompletionTime; - } + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getResourceType() { + return this.resourceType; + } + + public final String getStartDay() { + return this.startDay; + } + + public final String getEndDay() { + return this.endDay; + } + + public final String getWebhookUrl() { + return this.webhookUrl; + } + + public final String getWebhookMethod() { + return this.webhookMethod; + } + + public final String getEmail() { + return this.email; + } + + public final String getJobSid() { + return this.jobSid; + } + + public final Map getDetails() { + return this.details; + } + + public final String getJobQueuePosition() { + return this.jobQueuePosition; + } + + public final String getEstimatedCompletionTime() { + return this.estimatedCompletionTime; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -192,13 +195,38 @@ public boolean equals(final Object o) { ExportCustomJob other = (ExportCustomJob) o; - return Objects.equals(friendlyName, other.friendlyName) && Objects.equals(resourceType, other.resourceType) && Objects.equals(startDay, other.startDay) && Objects.equals(endDay, other.endDay) && Objects.equals(webhookUrl, other.webhookUrl) && Objects.equals(webhookMethod, other.webhookMethod) && Objects.equals(email, other.email) && Objects.equals(jobSid, other.jobSid) && Objects.equals(details, other.details) && Objects.equals(jobQueuePosition, other.jobQueuePosition) && Objects.equals(estimatedCompletionTime, other.estimatedCompletionTime) ; + return ( + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(resourceType, other.resourceType) && + Objects.equals(startDay, other.startDay) && + Objects.equals(endDay, other.endDay) && + Objects.equals(webhookUrl, other.webhookUrl) && + Objects.equals(webhookMethod, other.webhookMethod) && + Objects.equals(email, other.email) && + Objects.equals(jobSid, other.jobSid) && + Objects.equals(details, other.details) && + Objects.equals(jobQueuePosition, other.jobQueuePosition) && + Objects.equals( + estimatedCompletionTime, + other.estimatedCompletionTime + ) + ); } @Override public int hashCode() { - return Objects.hash(friendlyName, resourceType, startDay, endDay, webhookUrl, webhookMethod, email, jobSid, details, jobQueuePosition, estimatedCompletionTime); + return Objects.hash( + friendlyName, + resourceType, + startDay, + endDay, + webhookUrl, + webhookMethod, + email, + jobSid, + details, + jobQueuePosition, + estimatedCompletionTime + ); } - } - diff --git a/src/main/java/com/twilio/rest/bulkexports/v1/export/ExportCustomJobCreator.java b/src/main/java/com/twilio/rest/bulkexports/v1/export/ExportCustomJobCreator.java index fc60f302eb..021202f470 100644 --- a/src/main/java/com/twilio/rest/bulkexports/v1/export/ExportCustomJobCreator.java +++ b/src/main/java/com/twilio/rest/bulkexports/v1/export/ExportCustomJobCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.bulkexports.v1.export; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class ExportCustomJobCreator extends Creator { - - -public class ExportCustomJobCreator extends Creator{ private String pathResourceType; private String startDay; private String endDay; @@ -36,90 +35,112 @@ public class ExportCustomJobCreator extends Creator{ private String webhookMethod; private String email; - public ExportCustomJobCreator(final String pathResourceType, final String startDay, final String endDay, final String friendlyName) { + public ExportCustomJobCreator( + final String pathResourceType, + final String startDay, + final String endDay, + final String friendlyName + ) { this.pathResourceType = pathResourceType; this.startDay = startDay; this.endDay = endDay; this.friendlyName = friendlyName; } - public ExportCustomJobCreator setStartDay(final String startDay){ + public ExportCustomJobCreator setStartDay(final String startDay) { this.startDay = startDay; return this; } - public ExportCustomJobCreator setEndDay(final String endDay){ + + public ExportCustomJobCreator setEndDay(final String endDay) { this.endDay = endDay; return this; } - public ExportCustomJobCreator setFriendlyName(final String friendlyName){ + + public ExportCustomJobCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public ExportCustomJobCreator setWebhookUrl(final String webhookUrl){ + + public ExportCustomJobCreator setWebhookUrl(final String webhookUrl) { this.webhookUrl = webhookUrl; return this; } - public ExportCustomJobCreator setWebhookMethod(final String webhookMethod){ + + public ExportCustomJobCreator setWebhookMethod(final String webhookMethod) { this.webhookMethod = webhookMethod; return this; } - public ExportCustomJobCreator setEmail(final String email){ + + public ExportCustomJobCreator setEmail(final String email) { this.email = email; return this; } @Override - public ExportCustomJob create(final TwilioRestClient client){ + public ExportCustomJob create(final TwilioRestClient client) { String path = "/v1/Exports/{ResourceType}/Jobs"; - path = path.replace("{"+"ResourceType"+"}", this.pathResourceType.toString()); - path = path.replace("{"+"StartDay"+"}", this.startDay.toString()); - path = path.replace("{"+"EndDay"+"}", this.endDay.toString()); - path = path.replace("{"+"FriendlyName"+"}", this.friendlyName.toString()); + path = + path.replace( + "{" + "ResourceType" + "}", + this.pathResourceType.toString() + ); + path = path.replace("{" + "StartDay" + "}", this.startDay.toString()); + path = path.replace("{" + "EndDay" + "}", this.endDay.toString()); + path = + path.replace( + "{" + "FriendlyName" + "}", + this.friendlyName.toString() + ); Request request = new Request( HttpMethod.POST, Domains.BULKEXPORTS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("ExportCustomJob creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "ExportCustomJob creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return ExportCustomJob.fromJson(response.getStream(), client.getObjectMapper()); + return ExportCustomJob.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (startDay != null) { request.addPostParam("StartDay", startDay); - } if (endDay != null) { request.addPostParam("EndDay", endDay); - } if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (webhookUrl != null) { request.addPostParam("WebhookUrl", webhookUrl); - } if (webhookMethod != null) { request.addPostParam("WebhookMethod", webhookMethod); - } if (email != null) { request.addPostParam("Email", email); - } } } diff --git a/src/main/java/com/twilio/rest/bulkexports/v1/export/ExportCustomJobReader.java b/src/main/java/com/twilio/rest/bulkexports/v1/export/ExportCustomJobReader.java index ad73881b16..b4989ec149 100644 --- a/src/main/java/com/twilio/rest/bulkexports/v1/export/ExportCustomJobReader.java +++ b/src/main/java/com/twilio/rest/bulkexports/v1/export/ExportCustomJobReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.bulkexports.v1.export; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,19 +25,17 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class ExportCustomJobReader extends Reader { + private String pathResourceType; private Integer pageSize; - public ExportCustomJobReader(final String pathResourceType){ + public ExportCustomJobReader(final String pathResourceType) { this.pathResourceType = pathResourceType; } - public ExportCustomJobReader setPageSize(final Integer pageSize){ + public ExportCustomJobReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -48,7 +47,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Exports/{ResourceType}/Jobs"; - path = path.replace("{"+"ResourceType"+"}", this.pathResourceType.toString()); + path = + path.replace( + "{" + "ResourceType" + "}", + this.pathResourceType.toString() + ); Request request = new Request( HttpMethod.GET, @@ -60,13 +63,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("ExportCustomJob read failed: Unable to connect to server"); + throw new ApiConnectionException( + "ExportCustomJob read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +93,10 @@ private Page pageForRequest(final TwilioRestClient client, fina } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.BULKEXPORTS.toString()) @@ -90,9 +104,11 @@ public Page previousPage(final Page page, fina return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.BULKEXPORTS.toString()) @@ -101,21 +117,21 @@ public Page nextPage(final Page page, final Tw } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/bulkexports/v1/export/Job.java b/src/main/java/com/twilio/rest/bulkexports/v1/export/Job.java index b007d4223b..52fce1b2eb 100644 --- a/src/main/java/com/twilio/rest/bulkexports/v1/export/Job.java +++ b/src/main/java/com/twilio/rest/bulkexports/v1/export/Job.java @@ -22,42 +22,41 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Job extends Resource { + private static final long serialVersionUID = 103628862500013L; - public static JobDeleter deleter(final String pathJobSid){ + public static JobDeleter deleter(final String pathJobSid) { return new JobDeleter(pathJobSid); } - public static JobFetcher fetcher(final String pathJobSid){ + public static JobFetcher fetcher(final String pathJobSid) { return new JobFetcher(pathJobSid); } /** - * Converts a JSON String into a Job object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Job object represented by the provided JSON - */ - public static Job fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Job object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Job object represented by the provided JSON + */ + public static Job fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Job.class); @@ -69,14 +68,17 @@ public static Job fromJson(final String json, final ObjectMapper objectMapper) { } /** - * Converts a JSON InputStream into a Job object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Job object represented by the provided JSON - */ - public static Job fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Job object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Job object represented by the provided JSON + */ + public static Job fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Job.class); @@ -102,41 +104,20 @@ public static Job fromJson(final InputStream json, final ObjectMapper objectMapp @JsonCreator private Job( - @JsonProperty("resource_type") - final String resourceType, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("details") - final Map details, - - @JsonProperty("start_day") - final String startDay, - - @JsonProperty("end_day") - final String endDay, - - @JsonProperty("job_sid") - final String jobSid, - - @JsonProperty("webhook_url") - final String webhookUrl, - - @JsonProperty("webhook_method") - final String webhookMethod, - - @JsonProperty("email") - final String email, - - @JsonProperty("url") - final URI url, - - @JsonProperty("job_queue_position") - final String jobQueuePosition, - - @JsonProperty("estimated_completion_time") - final String estimatedCompletionTime + @JsonProperty("resource_type") final String resourceType, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("details") final Map details, + @JsonProperty("start_day") final String startDay, + @JsonProperty("end_day") final String endDay, + @JsonProperty("job_sid") final String jobSid, + @JsonProperty("webhook_url") final String webhookUrl, + @JsonProperty("webhook_method") final String webhookMethod, + @JsonProperty("email") final String email, + @JsonProperty("url") final URI url, + @JsonProperty("job_queue_position") final String jobQueuePosition, + @JsonProperty( + "estimated_completion_time" + ) final String estimatedCompletionTime ) { this.resourceType = resourceType; this.friendlyName = friendlyName; @@ -152,46 +133,57 @@ private Job( this.estimatedCompletionTime = estimatedCompletionTime; } - public final String getResourceType() { - return this.resourceType; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final Map getDetails() { - return this.details; - } - public final String getStartDay() { - return this.startDay; - } - public final String getEndDay() { - return this.endDay; - } - public final String getJobSid() { - return this.jobSid; - } - public final String getWebhookUrl() { - return this.webhookUrl; - } - public final String getWebhookMethod() { - return this.webhookMethod; - } - public final String getEmail() { - return this.email; - } - public final URI getUrl() { - return this.url; - } - public final String getJobQueuePosition() { - return this.jobQueuePosition; - } - public final String getEstimatedCompletionTime() { - return this.estimatedCompletionTime; - } + public final String getResourceType() { + return this.resourceType; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final Map getDetails() { + return this.details; + } + + public final String getStartDay() { + return this.startDay; + } + + public final String getEndDay() { + return this.endDay; + } + + public final String getJobSid() { + return this.jobSid; + } + + public final String getWebhookUrl() { + return this.webhookUrl; + } + + public final String getWebhookMethod() { + return this.webhookMethod; + } + + public final String getEmail() { + return this.email; + } + + public final URI getUrl() { + return this.url; + } + + public final String getJobQueuePosition() { + return this.jobQueuePosition; + } + + public final String getEstimatedCompletionTime() { + return this.estimatedCompletionTime; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -201,13 +193,40 @@ public boolean equals(final Object o) { Job other = (Job) o; - return Objects.equals(resourceType, other.resourceType) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(details, other.details) && Objects.equals(startDay, other.startDay) && Objects.equals(endDay, other.endDay) && Objects.equals(jobSid, other.jobSid) && Objects.equals(webhookUrl, other.webhookUrl) && Objects.equals(webhookMethod, other.webhookMethod) && Objects.equals(email, other.email) && Objects.equals(url, other.url) && Objects.equals(jobQueuePosition, other.jobQueuePosition) && Objects.equals(estimatedCompletionTime, other.estimatedCompletionTime) ; + return ( + Objects.equals(resourceType, other.resourceType) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(details, other.details) && + Objects.equals(startDay, other.startDay) && + Objects.equals(endDay, other.endDay) && + Objects.equals(jobSid, other.jobSid) && + Objects.equals(webhookUrl, other.webhookUrl) && + Objects.equals(webhookMethod, other.webhookMethod) && + Objects.equals(email, other.email) && + Objects.equals(url, other.url) && + Objects.equals(jobQueuePosition, other.jobQueuePosition) && + Objects.equals( + estimatedCompletionTime, + other.estimatedCompletionTime + ) + ); } @Override public int hashCode() { - return Objects.hash(resourceType, friendlyName, details, startDay, endDay, jobSid, webhookUrl, webhookMethod, email, url, jobQueuePosition, estimatedCompletionTime); + return Objects.hash( + resourceType, + friendlyName, + details, + startDay, + endDay, + jobSid, + webhookUrl, + webhookMethod, + email, + url, + jobQueuePosition, + estimatedCompletionTime + ); } - } - diff --git a/src/main/java/com/twilio/rest/bulkexports/v1/export/JobDeleter.java b/src/main/java/com/twilio/rest/bulkexports/v1/export/JobDeleter.java index 6b718fa08a..f9eb86f326 100644 --- a/src/main/java/com/twilio/rest/bulkexports/v1/export/JobDeleter.java +++ b/src/main/java/com/twilio/rest/bulkexports/v1/export/JobDeleter.java @@ -24,21 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class JobDeleter extends Deleter { + private String pathJobSid; - public JobDeleter(final String pathJobSid){ + public JobDeleter(final String pathJobSid) { this.pathJobSid = pathJobSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Exports/Jobs/{JobSid}"; - path = path.replace("{"+"JobSid"+"}", this.pathJobSid.toString()); + path = path.replace("{" + "JobSid" + "}", this.pathJobSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -48,9 +46,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Job delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Job delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/bulkexports/v1/export/JobFetcher.java b/src/main/java/com/twilio/rest/bulkexports/v1/export/JobFetcher.java index ffa9fdb8c1..4fb11f4e9a 100644 --- a/src/main/java/com/twilio/rest/bulkexports/v1/export/JobFetcher.java +++ b/src/main/java/com/twilio/rest/bulkexports/v1/export/JobFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class JobFetcher extends Fetcher { + private String pathJobSid; - public JobFetcher(final String pathJobSid){ + public JobFetcher(final String pathJobSid) { this.pathJobSid = pathJobSid; } - @Override public Job fetch(final TwilioRestClient client) { String path = "/v1/Exports/Jobs/{JobSid}"; - path = path.replace("{"+"JobSid"+"}", this.pathJobSid.toString()); + path = path.replace("{" + "JobSid" + "}", this.pathJobSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,9 +46,14 @@ public Job fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Job fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Job fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/chat/v1/Credential.java b/src/main/java/com/twilio/rest/chat/v1/Credential.java index 604bc58623..b10b88ab60 100644 --- a/src/main/java/com/twilio/rest/chat/v1/Credential.java +++ b/src/main/java/com/twilio/rest/chat/v1/Credential.java @@ -24,53 +24,52 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Credential extends Resource { + private static final long serialVersionUID = 161183169234848L; - public static CredentialCreator creator(final Credential.PushService type){ + public static CredentialCreator creator(final Credential.PushService type) { return new CredentialCreator(type); } - public static CredentialDeleter deleter(final String pathSid){ + public static CredentialDeleter deleter(final String pathSid) { return new CredentialDeleter(pathSid); } - public static CredentialFetcher fetcher(final String pathSid){ + public static CredentialFetcher fetcher(final String pathSid) { return new CredentialFetcher(pathSid); } - public static CredentialReader reader(){ + public static CredentialReader reader() { return new CredentialReader(); } - public static CredentialUpdater updater(final String pathSid){ + public static CredentialUpdater updater(final String pathSid) { return new CredentialUpdater(pathSid); } /** - * Converts a JSON String into a Credential object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Credential object represented by the provided JSON - */ - public static Credential fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Credential object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Credential object represented by the provided JSON + */ + public static Credential fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Credential.class); @@ -82,14 +81,17 @@ public static Credential fromJson(final String json, final ObjectMapper objectMa } /** - * Converts a JSON InputStream into a Credential object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Credential object represented by the provided JSON - */ - public static Credential fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Credential object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Credential object represented by the provided JSON + */ + public static Credential fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Credential.class); @@ -99,6 +101,7 @@ public static Credential fromJson(final InputStream json, final ObjectMapper obj throw new ApiConnectionException(e.getMessage(), e); } } + public enum PushService { GCM("gcm"), APN("apn"), @@ -131,29 +134,14 @@ public static PushService forValue(final String value) { @JsonCreator private Credential( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("type") - final Credential.PushService type, - - @JsonProperty("sandbox") - final String sandbox, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("type") final Credential.PushService type, + @JsonProperty("sandbox") final String sandbox, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url ) { this.sid = sid; this.accountSid = accountSid; @@ -165,34 +153,41 @@ private Credential( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final Credential.PushService getType() { - return this.type; - } - public final String getSandbox() { - return this.sandbox; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final Credential.PushService getType() { + return this.type; + } + + public final String getSandbox() { + return this.sandbox; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -202,13 +197,29 @@ public boolean equals(final Object o) { Credential other = (Credential) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(type, other.type) && Objects.equals(sandbox, other.sandbox) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(type, other.type) && + Objects.equals(sandbox, other.sandbox) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, friendlyName, type, sandbox, dateCreated, dateUpdated, url); + return Objects.hash( + sid, + accountSid, + friendlyName, + type, + sandbox, + dateCreated, + dateUpdated, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/chat/v1/CredentialCreator.java b/src/main/java/com/twilio/rest/chat/v1/CredentialCreator.java index 7efcc8b36b..39ca948778 100644 --- a/src/main/java/com/twilio/rest/chat/v1/CredentialCreator.java +++ b/src/main/java/com/twilio/rest/chat/v1/CredentialCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.chat.v1; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class CredentialCreator extends Creator { - - -public class CredentialCreator extends Creator{ private Credential.PushService type; private String friendlyName; private String certificate; @@ -40,88 +39,97 @@ public CredentialCreator(final Credential.PushService type) { this.type = type; } - public CredentialCreator setType(final Credential.PushService type){ + public CredentialCreator setType(final Credential.PushService type) { this.type = type; return this; } - public CredentialCreator setFriendlyName(final String friendlyName){ + + public CredentialCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public CredentialCreator setCertificate(final String certificate){ + + public CredentialCreator setCertificate(final String certificate) { this.certificate = certificate; return this; } - public CredentialCreator setPrivateKey(final String privateKey){ + + public CredentialCreator setPrivateKey(final String privateKey) { this.privateKey = privateKey; return this; } - public CredentialCreator setSandbox(final Boolean sandbox){ + + public CredentialCreator setSandbox(final Boolean sandbox) { this.sandbox = sandbox; return this; } - public CredentialCreator setApiKey(final String apiKey){ + + public CredentialCreator setApiKey(final String apiKey) { this.apiKey = apiKey; return this; } - public CredentialCreator setSecret(final String secret){ + + public CredentialCreator setSecret(final String secret) { this.secret = secret; return this; } @Override - public Credential create(final TwilioRestClient client){ + public Credential create(final TwilioRestClient client) { String path = "/v1/Credentials"; - path = path.replace("{"+"Type"+"}", this.type.toString()); + path = path.replace("{" + "Type" + "}", this.type.toString()); Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Credential creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Credential creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Credential.fromJson(response.getStream(), client.getObjectMapper()); + return Credential.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (type != null) { request.addPostParam("Type", type.toString()); - } if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (certificate != null) { request.addPostParam("Certificate", certificate); - } if (privateKey != null) { request.addPostParam("PrivateKey", privateKey); - } if (sandbox != null) { request.addPostParam("Sandbox", sandbox.toString()); - } if (apiKey != null) { request.addPostParam("ApiKey", apiKey); - } if (secret != null) { request.addPostParam("Secret", secret); - } } } diff --git a/src/main/java/com/twilio/rest/chat/v1/CredentialDeleter.java b/src/main/java/com/twilio/rest/chat/v1/CredentialDeleter.java index e96831430f..c27e6335b5 100644 --- a/src/main/java/com/twilio/rest/chat/v1/CredentialDeleter.java +++ b/src/main/java/com/twilio/rest/chat/v1/CredentialDeleter.java @@ -24,21 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class CredentialDeleter extends Deleter { + private String pathSid; - public CredentialDeleter(final String pathSid){ + public CredentialDeleter(final String pathSid) { this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Credentials/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -48,9 +46,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Credential delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Credential delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/chat/v1/CredentialFetcher.java b/src/main/java/com/twilio/rest/chat/v1/CredentialFetcher.java index dadf51ef25..68db4056b7 100644 --- a/src/main/java/com/twilio/rest/chat/v1/CredentialFetcher.java +++ b/src/main/java/com/twilio/rest/chat/v1/CredentialFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class CredentialFetcher extends Fetcher { + private String pathSid; - public CredentialFetcher(final String pathSid){ + public CredentialFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public Credential fetch(final TwilioRestClient client) { String path = "/v1/Credentials/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,15 +46,23 @@ public Credential fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Credential fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Credential fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Credential.fromJson(response.getStream(), client.getObjectMapper()); + return Credential.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/chat/v1/CredentialReader.java b/src/main/java/com/twilio/rest/chat/v1/CredentialReader.java index e4911894d9..d58babcdaf 100644 --- a/src/main/java/com/twilio/rest/chat/v1/CredentialReader.java +++ b/src/main/java/com/twilio/rest/chat/v1/CredentialReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.chat.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,17 +25,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class CredentialReader extends Reader { + private Integer pageSize; - public CredentialReader(){ - } + public CredentialReader() {} - public CredentialReader setPageSize(final Integer pageSize){ + public CredentialReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -57,13 +55,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Credential read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Credential read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -79,7 +85,10 @@ private Page pageForRequest(final TwilioRestClient client, final Req } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.CHAT.toString()) @@ -87,9 +96,11 @@ public Page previousPage(final Page page, final TwilioRe return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.CHAT.toString()) @@ -98,21 +109,21 @@ public Page nextPage(final Page page, final TwilioRestCl } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/chat/v1/CredentialUpdater.java b/src/main/java/com/twilio/rest/chat/v1/CredentialUpdater.java index a37ef56be2..9805386eee 100644 --- a/src/main/java/com/twilio/rest/chat/v1/CredentialUpdater.java +++ b/src/main/java/com/twilio/rest/chat/v1/CredentialUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.chat.v1; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class CredentialUpdater extends Updater { - - -public class CredentialUpdater extends Updater{ private String pathSid; private String friendlyName; private String certificate; @@ -36,84 +35,93 @@ public class CredentialUpdater extends Updater{ private String apiKey; private String secret; - public CredentialUpdater(final String pathSid){ + public CredentialUpdater(final String pathSid) { this.pathSid = pathSid; } - public CredentialUpdater setFriendlyName(final String friendlyName){ + public CredentialUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public CredentialUpdater setCertificate(final String certificate){ + + public CredentialUpdater setCertificate(final String certificate) { this.certificate = certificate; return this; } - public CredentialUpdater setPrivateKey(final String privateKey){ + + public CredentialUpdater setPrivateKey(final String privateKey) { this.privateKey = privateKey; return this; } - public CredentialUpdater setSandbox(final Boolean sandbox){ + + public CredentialUpdater setSandbox(final Boolean sandbox) { this.sandbox = sandbox; return this; } - public CredentialUpdater setApiKey(final String apiKey){ + + public CredentialUpdater setApiKey(final String apiKey) { this.apiKey = apiKey; return this; } - public CredentialUpdater setSecret(final String secret){ + + public CredentialUpdater setSecret(final String secret) { this.secret = secret; return this; } @Override - public Credential update(final TwilioRestClient client){ + public Credential update(final TwilioRestClient client) { String path = "/v1/Credentials/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Credential update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Credential update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Credential.fromJson(response.getStream(), client.getObjectMapper()); + return Credential.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (certificate != null) { request.addPostParam("Certificate", certificate); - } if (privateKey != null) { request.addPostParam("PrivateKey", privateKey); - } if (sandbox != null) { request.addPostParam("Sandbox", sandbox.toString()); - } if (apiKey != null) { request.addPostParam("ApiKey", apiKey); - } if (secret != null) { request.addPostParam("Secret", secret); - } } } diff --git a/src/main/java/com/twilio/rest/chat/v1/Service.java b/src/main/java/com/twilio/rest/chat/v1/Service.java index d88131e833..c018f90a12 100644 --- a/src/main/java/com/twilio/rest/chat/v1/Service.java +++ b/src/main/java/com/twilio/rest/chat/v1/Service.java @@ -23,56 +23,55 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.List; import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Service extends Resource { + private static final long serialVersionUID = 258386577185944L; - public static ServiceCreator creator(final String friendlyName){ + public static ServiceCreator creator(final String friendlyName) { return new ServiceCreator(friendlyName); } - public static ServiceDeleter deleter(final String pathSid){ + public static ServiceDeleter deleter(final String pathSid) { return new ServiceDeleter(pathSid); } - public static ServiceFetcher fetcher(final String pathSid){ + public static ServiceFetcher fetcher(final String pathSid) { return new ServiceFetcher(pathSid); } - public static ServiceReader reader(){ + public static ServiceReader reader() { return new ServiceReader(); } - public static ServiceUpdater updater(final String pathSid){ + public static ServiceUpdater updater(final String pathSid) { return new ServiceUpdater(pathSid); } /** - * Converts a JSON String into a Service object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Service object represented by the provided JSON - */ - public static Service fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Service object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Service object represented by the provided JSON + */ + public static Service fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Service.class); @@ -84,14 +83,17 @@ public static Service fromJson(final String json, final ObjectMapper objectMappe } /** - * Converts a JSON InputStream into a Service object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Service object represented by the provided JSON - */ - public static Service fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Service object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Service object represented by the provided JSON + */ + public static Service fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Service.class); @@ -126,68 +128,37 @@ public static Service fromJson(final InputStream json, final ObjectMapper object @JsonCreator private Service( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("default_service_role_sid") - final String defaultServiceRoleSid, - - @JsonProperty("default_channel_role_sid") - final String defaultChannelRoleSid, - - @JsonProperty("default_channel_creator_role_sid") - final String defaultChannelCreatorRoleSid, - - @JsonProperty("read_status_enabled") - final Boolean readStatusEnabled, - - @JsonProperty("reachability_enabled") - final Boolean reachabilityEnabled, - - @JsonProperty("typing_indicator_timeout") - final Integer typingIndicatorTimeout, - - @JsonProperty("consumption_report_interval") - final Integer consumptionReportInterval, - - @JsonProperty("limits") - final Map limits, - - @JsonProperty("webhooks") - final Map webhooks, - - @JsonProperty("pre_webhook_url") - final String preWebhookUrl, - - @JsonProperty("post_webhook_url") - final String postWebhookUrl, - - @JsonProperty("webhook_method") - final String webhookMethod, - - @JsonProperty("webhook_filters") - final List webhookFilters, - - @JsonProperty("notifications") - final Map notifications, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty( + "default_service_role_sid" + ) final String defaultServiceRoleSid, + @JsonProperty( + "default_channel_role_sid" + ) final String defaultChannelRoleSid, + @JsonProperty( + "default_channel_creator_role_sid" + ) final String defaultChannelCreatorRoleSid, + @JsonProperty("read_status_enabled") final Boolean readStatusEnabled, + @JsonProperty("reachability_enabled") final Boolean reachabilityEnabled, + @JsonProperty( + "typing_indicator_timeout" + ) final Integer typingIndicatorTimeout, + @JsonProperty( + "consumption_report_interval" + ) final Integer consumptionReportInterval, + @JsonProperty("limits") final Map limits, + @JsonProperty("webhooks") final Map webhooks, + @JsonProperty("pre_webhook_url") final String preWebhookUrl, + @JsonProperty("post_webhook_url") final String postWebhookUrl, + @JsonProperty("webhook_method") final String webhookMethod, + @JsonProperty("webhook_filters") final List webhookFilters, + @JsonProperty("notifications") final Map notifications, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.sid = sid; this.accountSid = accountSid; @@ -212,73 +183,93 @@ private Service( this.links = links; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getDefaultServiceRoleSid() { - return this.defaultServiceRoleSid; - } - public final String getDefaultChannelRoleSid() { - return this.defaultChannelRoleSid; - } - public final String getDefaultChannelCreatorRoleSid() { - return this.defaultChannelCreatorRoleSid; - } - public final Boolean getReadStatusEnabled() { - return this.readStatusEnabled; - } - public final Boolean getReachabilityEnabled() { - return this.reachabilityEnabled; - } - public final Integer getTypingIndicatorTimeout() { - return this.typingIndicatorTimeout; - } - public final Integer getConsumptionReportInterval() { - return this.consumptionReportInterval; - } - public final Map getLimits() { - return this.limits; - } - public final Map getWebhooks() { - return this.webhooks; - } - public final String getPreWebhookUrl() { - return this.preWebhookUrl; - } - public final String getPostWebhookUrl() { - return this.postWebhookUrl; - } - public final String getWebhookMethod() { - return this.webhookMethod; - } - public final List getWebhookFilters() { - return this.webhookFilters; - } - public final Map getNotifications() { - return this.notifications; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getDefaultServiceRoleSid() { + return this.defaultServiceRoleSid; + } + + public final String getDefaultChannelRoleSid() { + return this.defaultChannelRoleSid; + } + + public final String getDefaultChannelCreatorRoleSid() { + return this.defaultChannelCreatorRoleSid; + } + + public final Boolean getReadStatusEnabled() { + return this.readStatusEnabled; + } + + public final Boolean getReachabilityEnabled() { + return this.reachabilityEnabled; + } + + public final Integer getTypingIndicatorTimeout() { + return this.typingIndicatorTimeout; + } + + public final Integer getConsumptionReportInterval() { + return this.consumptionReportInterval; + } + + public final Map getLimits() { + return this.limits; + } + + public final Map getWebhooks() { + return this.webhooks; + } + + public final String getPreWebhookUrl() { + return this.preWebhookUrl; + } + + public final String getPostWebhookUrl() { + return this.postWebhookUrl; + } + + public final String getWebhookMethod() { + return this.webhookMethod; + } + + public final List getWebhookFilters() { + return this.webhookFilters; + } + + public final Map getNotifications() { + return this.notifications; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -288,13 +279,70 @@ public boolean equals(final Object o) { Service other = (Service) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(defaultServiceRoleSid, other.defaultServiceRoleSid) && Objects.equals(defaultChannelRoleSid, other.defaultChannelRoleSid) && Objects.equals(defaultChannelCreatorRoleSid, other.defaultChannelCreatorRoleSid) && Objects.equals(readStatusEnabled, other.readStatusEnabled) && Objects.equals(reachabilityEnabled, other.reachabilityEnabled) && Objects.equals(typingIndicatorTimeout, other.typingIndicatorTimeout) && Objects.equals(consumptionReportInterval, other.consumptionReportInterval) && Objects.equals(limits, other.limits) && Objects.equals(webhooks, other.webhooks) && Objects.equals(preWebhookUrl, other.preWebhookUrl) && Objects.equals(postWebhookUrl, other.postWebhookUrl) && Objects.equals(webhookMethod, other.webhookMethod) && Objects.equals(webhookFilters, other.webhookFilters) && Objects.equals(notifications, other.notifications) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals( + defaultServiceRoleSid, + other.defaultServiceRoleSid + ) && + Objects.equals( + defaultChannelRoleSid, + other.defaultChannelRoleSid + ) && + Objects.equals( + defaultChannelCreatorRoleSid, + other.defaultChannelCreatorRoleSid + ) && + Objects.equals(readStatusEnabled, other.readStatusEnabled) && + Objects.equals(reachabilityEnabled, other.reachabilityEnabled) && + Objects.equals( + typingIndicatorTimeout, + other.typingIndicatorTimeout + ) && + Objects.equals( + consumptionReportInterval, + other.consumptionReportInterval + ) && + Objects.equals(limits, other.limits) && + Objects.equals(webhooks, other.webhooks) && + Objects.equals(preWebhookUrl, other.preWebhookUrl) && + Objects.equals(postWebhookUrl, other.postWebhookUrl) && + Objects.equals(webhookMethod, other.webhookMethod) && + Objects.equals(webhookFilters, other.webhookFilters) && + Objects.equals(notifications, other.notifications) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, friendlyName, dateCreated, dateUpdated, defaultServiceRoleSid, defaultChannelRoleSid, defaultChannelCreatorRoleSid, readStatusEnabled, reachabilityEnabled, typingIndicatorTimeout, consumptionReportInterval, limits, webhooks, preWebhookUrl, postWebhookUrl, webhookMethod, webhookFilters, notifications, url, links); + return Objects.hash( + sid, + accountSid, + friendlyName, + dateCreated, + dateUpdated, + defaultServiceRoleSid, + defaultChannelRoleSid, + defaultChannelCreatorRoleSid, + readStatusEnabled, + reachabilityEnabled, + typingIndicatorTimeout, + consumptionReportInterval, + limits, + webhooks, + preWebhookUrl, + postWebhookUrl, + webhookMethod, + webhookFilters, + notifications, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/chat/v1/ServiceCreator.java b/src/main/java/com/twilio/rest/chat/v1/ServiceCreator.java index 1fec9e4e3e..b2a512ffdf 100644 --- a/src/main/java/com/twilio/rest/chat/v1/ServiceCreator.java +++ b/src/main/java/com/twilio/rest/chat/v1/ServiceCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.chat.v1; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,38 +25,46 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class ServiceCreator extends Creator { - - -public class ServiceCreator extends Creator{ private String friendlyName; public ServiceCreator(final String friendlyName) { this.friendlyName = friendlyName; } - public ServiceCreator setFriendlyName(final String friendlyName){ + public ServiceCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } @Override - public Service create(final TwilioRestClient client){ + public Service create(final TwilioRestClient client) { String path = "/v1/Services"; - path = path.replace("{"+"FriendlyName"+"}", this.friendlyName.toString()); + path = + path.replace( + "{" + "FriendlyName" + "}", + this.friendlyName.toString() + ); Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -64,10 +73,10 @@ public Service create(final TwilioRestClient client){ return Service.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } } } diff --git a/src/main/java/com/twilio/rest/chat/v1/ServiceDeleter.java b/src/main/java/com/twilio/rest/chat/v1/ServiceDeleter.java index d22118c356..6a77059098 100644 --- a/src/main/java/com/twilio/rest/chat/v1/ServiceDeleter.java +++ b/src/main/java/com/twilio/rest/chat/v1/ServiceDeleter.java @@ -24,21 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class ServiceDeleter extends Deleter { + private String pathSid; - public ServiceDeleter(final String pathSid){ + public ServiceDeleter(final String pathSid) { this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Services/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -48,9 +46,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/chat/v1/ServiceFetcher.java b/src/main/java/com/twilio/rest/chat/v1/ServiceFetcher.java index 2fecc7f604..00e799779c 100644 --- a/src/main/java/com/twilio/rest/chat/v1/ServiceFetcher.java +++ b/src/main/java/com/twilio/rest/chat/v1/ServiceFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class ServiceFetcher extends Fetcher { + private String pathSid; - public ServiceFetcher(final String pathSid){ + public ServiceFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public Service fetch(final TwilioRestClient client) { String path = "/v1/Services/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,9 +46,14 @@ public Service fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/chat/v1/ServiceReader.java b/src/main/java/com/twilio/rest/chat/v1/ServiceReader.java index 6c21c136bf..f1beb296e6 100644 --- a/src/main/java/com/twilio/rest/chat/v1/ServiceReader.java +++ b/src/main/java/com/twilio/rest/chat/v1/ServiceReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.chat.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,17 +25,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class ServiceReader extends Reader { + private Integer pageSize; - public ServiceReader(){ - } + public ServiceReader() {} - public ServiceReader setPageSize(final Integer pageSize){ + public ServiceReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -57,13 +55,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -79,7 +85,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reques } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.CHAT.toString()) @@ -87,9 +96,11 @@ public Page previousPage(final Page page, final TwilioRestClie return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.CHAT.toString()) @@ -98,21 +109,21 @@ public Page nextPage(final Page page, final TwilioRestClient c } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/chat/v1/ServiceUpdater.java b/src/main/java/com/twilio/rest/chat/v1/ServiceUpdater.java index b6e1d9fd44..55496a3911 100644 --- a/src/main/java/com/twilio/rest/chat/v1/ServiceUpdater.java +++ b/src/main/java/com/twilio/rest/chat/v1/ServiceUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.chat.v1; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -24,13 +25,11 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.net.URI; - import java.util.List; +public class ServiceUpdater extends Updater { -public class ServiceUpdater extends Updater{ private String pathSid; private String friendlyName; private String defaultServiceRoleSid; @@ -87,319 +86,548 @@ public class ServiceUpdater extends Updater{ private Integer limitsChannelMembers; private Integer limitsUserChannels; - public ServiceUpdater(final String pathSid){ + public ServiceUpdater(final String pathSid) { this.pathSid = pathSid; } - public ServiceUpdater setFriendlyName(final String friendlyName){ + public ServiceUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public ServiceUpdater setDefaultServiceRoleSid(final String defaultServiceRoleSid){ + + public ServiceUpdater setDefaultServiceRoleSid( + final String defaultServiceRoleSid + ) { this.defaultServiceRoleSid = defaultServiceRoleSid; return this; } - public ServiceUpdater setDefaultChannelRoleSid(final String defaultChannelRoleSid){ + + public ServiceUpdater setDefaultChannelRoleSid( + final String defaultChannelRoleSid + ) { this.defaultChannelRoleSid = defaultChannelRoleSid; return this; } - public ServiceUpdater setDefaultChannelCreatorRoleSid(final String defaultChannelCreatorRoleSid){ + + public ServiceUpdater setDefaultChannelCreatorRoleSid( + final String defaultChannelCreatorRoleSid + ) { this.defaultChannelCreatorRoleSid = defaultChannelCreatorRoleSid; return this; } - public ServiceUpdater setReadStatusEnabled(final Boolean readStatusEnabled){ + + public ServiceUpdater setReadStatusEnabled( + final Boolean readStatusEnabled + ) { this.readStatusEnabled = readStatusEnabled; return this; } - public ServiceUpdater setReachabilityEnabled(final Boolean reachabilityEnabled){ + + public ServiceUpdater setReachabilityEnabled( + final Boolean reachabilityEnabled + ) { this.reachabilityEnabled = reachabilityEnabled; return this; } - public ServiceUpdater setTypingIndicatorTimeout(final Integer typingIndicatorTimeout){ + + public ServiceUpdater setTypingIndicatorTimeout( + final Integer typingIndicatorTimeout + ) { this.typingIndicatorTimeout = typingIndicatorTimeout; return this; } - public ServiceUpdater setConsumptionReportInterval(final Integer consumptionReportInterval){ + + public ServiceUpdater setConsumptionReportInterval( + final Integer consumptionReportInterval + ) { this.consumptionReportInterval = consumptionReportInterval; return this; } - public ServiceUpdater setNotificationsNewMessageEnabled(final Boolean notificationsNewMessageEnabled){ + + public ServiceUpdater setNotificationsNewMessageEnabled( + final Boolean notificationsNewMessageEnabled + ) { this.notificationsNewMessageEnabled = notificationsNewMessageEnabled; return this; } - public ServiceUpdater setNotificationsNewMessageTemplate(final String notificationsNewMessageTemplate){ + + public ServiceUpdater setNotificationsNewMessageTemplate( + final String notificationsNewMessageTemplate + ) { this.notificationsNewMessageTemplate = notificationsNewMessageTemplate; return this; } - public ServiceUpdater setNotificationsAddedToChannelEnabled(final Boolean notificationsAddedToChannelEnabled){ - this.notificationsAddedToChannelEnabled = notificationsAddedToChannelEnabled; + + public ServiceUpdater setNotificationsAddedToChannelEnabled( + final Boolean notificationsAddedToChannelEnabled + ) { + this.notificationsAddedToChannelEnabled = + notificationsAddedToChannelEnabled; return this; } - public ServiceUpdater setNotificationsAddedToChannelTemplate(final String notificationsAddedToChannelTemplate){ - this.notificationsAddedToChannelTemplate = notificationsAddedToChannelTemplate; + + public ServiceUpdater setNotificationsAddedToChannelTemplate( + final String notificationsAddedToChannelTemplate + ) { + this.notificationsAddedToChannelTemplate = + notificationsAddedToChannelTemplate; return this; } - public ServiceUpdater setNotificationsRemovedFromChannelEnabled(final Boolean notificationsRemovedFromChannelEnabled){ - this.notificationsRemovedFromChannelEnabled = notificationsRemovedFromChannelEnabled; + + public ServiceUpdater setNotificationsRemovedFromChannelEnabled( + final Boolean notificationsRemovedFromChannelEnabled + ) { + this.notificationsRemovedFromChannelEnabled = + notificationsRemovedFromChannelEnabled; return this; } - public ServiceUpdater setNotificationsRemovedFromChannelTemplate(final String notificationsRemovedFromChannelTemplate){ - this.notificationsRemovedFromChannelTemplate = notificationsRemovedFromChannelTemplate; + + public ServiceUpdater setNotificationsRemovedFromChannelTemplate( + final String notificationsRemovedFromChannelTemplate + ) { + this.notificationsRemovedFromChannelTemplate = + notificationsRemovedFromChannelTemplate; return this; } - public ServiceUpdater setNotificationsInvitedToChannelEnabled(final Boolean notificationsInvitedToChannelEnabled){ - this.notificationsInvitedToChannelEnabled = notificationsInvitedToChannelEnabled; + + public ServiceUpdater setNotificationsInvitedToChannelEnabled( + final Boolean notificationsInvitedToChannelEnabled + ) { + this.notificationsInvitedToChannelEnabled = + notificationsInvitedToChannelEnabled; return this; } - public ServiceUpdater setNotificationsInvitedToChannelTemplate(final String notificationsInvitedToChannelTemplate){ - this.notificationsInvitedToChannelTemplate = notificationsInvitedToChannelTemplate; + + public ServiceUpdater setNotificationsInvitedToChannelTemplate( + final String notificationsInvitedToChannelTemplate + ) { + this.notificationsInvitedToChannelTemplate = + notificationsInvitedToChannelTemplate; return this; } - public ServiceUpdater setPreWebhookUrl(final URI preWebhookUrl){ + + public ServiceUpdater setPreWebhookUrl(final URI preWebhookUrl) { this.preWebhookUrl = preWebhookUrl; return this; } - public ServiceUpdater setPreWebhookUrl(final String preWebhookUrl){ + public ServiceUpdater setPreWebhookUrl(final String preWebhookUrl) { return setPreWebhookUrl(Promoter.uriFromString(preWebhookUrl)); } - public ServiceUpdater setPostWebhookUrl(final URI postWebhookUrl){ + + public ServiceUpdater setPostWebhookUrl(final URI postWebhookUrl) { this.postWebhookUrl = postWebhookUrl; return this; } - public ServiceUpdater setPostWebhookUrl(final String postWebhookUrl){ + public ServiceUpdater setPostWebhookUrl(final String postWebhookUrl) { return setPostWebhookUrl(Promoter.uriFromString(postWebhookUrl)); } - public ServiceUpdater setWebhookMethod(final HttpMethod webhookMethod){ + + public ServiceUpdater setWebhookMethod(final HttpMethod webhookMethod) { this.webhookMethod = webhookMethod; return this; } - public ServiceUpdater setWebhookFilters(final List webhookFilters){ + + public ServiceUpdater setWebhookFilters(final List webhookFilters) { this.webhookFilters = webhookFilters; return this; } - public ServiceUpdater setWebhookFilters(final String webhookFilters){ + + public ServiceUpdater setWebhookFilters(final String webhookFilters) { return setWebhookFilters(Promoter.listOfOne(webhookFilters)); } - public ServiceUpdater setWebhooksOnMessageSendUrl(final URI webhooksOnMessageSendUrl){ + + public ServiceUpdater setWebhooksOnMessageSendUrl( + final URI webhooksOnMessageSendUrl + ) { this.webhooksOnMessageSendUrl = webhooksOnMessageSendUrl; return this; } - public ServiceUpdater setWebhooksOnMessageSendUrl(final String webhooksOnMessageSendUrl){ - return setWebhooksOnMessageSendUrl(Promoter.uriFromString(webhooksOnMessageSendUrl)); + public ServiceUpdater setWebhooksOnMessageSendUrl( + final String webhooksOnMessageSendUrl + ) { + return setWebhooksOnMessageSendUrl( + Promoter.uriFromString(webhooksOnMessageSendUrl) + ); } - public ServiceUpdater setWebhooksOnMessageSendMethod(final HttpMethod webhooksOnMessageSendMethod){ + + public ServiceUpdater setWebhooksOnMessageSendMethod( + final HttpMethod webhooksOnMessageSendMethod + ) { this.webhooksOnMessageSendMethod = webhooksOnMessageSendMethod; return this; } - public ServiceUpdater setWebhooksOnMessageUpdateUrl(final URI webhooksOnMessageUpdateUrl){ + + public ServiceUpdater setWebhooksOnMessageUpdateUrl( + final URI webhooksOnMessageUpdateUrl + ) { this.webhooksOnMessageUpdateUrl = webhooksOnMessageUpdateUrl; return this; } - public ServiceUpdater setWebhooksOnMessageUpdateUrl(final String webhooksOnMessageUpdateUrl){ - return setWebhooksOnMessageUpdateUrl(Promoter.uriFromString(webhooksOnMessageUpdateUrl)); + public ServiceUpdater setWebhooksOnMessageUpdateUrl( + final String webhooksOnMessageUpdateUrl + ) { + return setWebhooksOnMessageUpdateUrl( + Promoter.uriFromString(webhooksOnMessageUpdateUrl) + ); } - public ServiceUpdater setWebhooksOnMessageUpdateMethod(final HttpMethod webhooksOnMessageUpdateMethod){ + + public ServiceUpdater setWebhooksOnMessageUpdateMethod( + final HttpMethod webhooksOnMessageUpdateMethod + ) { this.webhooksOnMessageUpdateMethod = webhooksOnMessageUpdateMethod; return this; } - public ServiceUpdater setWebhooksOnMessageRemoveUrl(final URI webhooksOnMessageRemoveUrl){ + + public ServiceUpdater setWebhooksOnMessageRemoveUrl( + final URI webhooksOnMessageRemoveUrl + ) { this.webhooksOnMessageRemoveUrl = webhooksOnMessageRemoveUrl; return this; } - public ServiceUpdater setWebhooksOnMessageRemoveUrl(final String webhooksOnMessageRemoveUrl){ - return setWebhooksOnMessageRemoveUrl(Promoter.uriFromString(webhooksOnMessageRemoveUrl)); + public ServiceUpdater setWebhooksOnMessageRemoveUrl( + final String webhooksOnMessageRemoveUrl + ) { + return setWebhooksOnMessageRemoveUrl( + Promoter.uriFromString(webhooksOnMessageRemoveUrl) + ); } - public ServiceUpdater setWebhooksOnMessageRemoveMethod(final HttpMethod webhooksOnMessageRemoveMethod){ + + public ServiceUpdater setWebhooksOnMessageRemoveMethod( + final HttpMethod webhooksOnMessageRemoveMethod + ) { this.webhooksOnMessageRemoveMethod = webhooksOnMessageRemoveMethod; return this; } - public ServiceUpdater setWebhooksOnChannelAddUrl(final URI webhooksOnChannelAddUrl){ + + public ServiceUpdater setWebhooksOnChannelAddUrl( + final URI webhooksOnChannelAddUrl + ) { this.webhooksOnChannelAddUrl = webhooksOnChannelAddUrl; return this; } - public ServiceUpdater setWebhooksOnChannelAddUrl(final String webhooksOnChannelAddUrl){ - return setWebhooksOnChannelAddUrl(Promoter.uriFromString(webhooksOnChannelAddUrl)); + public ServiceUpdater setWebhooksOnChannelAddUrl( + final String webhooksOnChannelAddUrl + ) { + return setWebhooksOnChannelAddUrl( + Promoter.uriFromString(webhooksOnChannelAddUrl) + ); } - public ServiceUpdater setWebhooksOnChannelAddMethod(final HttpMethod webhooksOnChannelAddMethod){ + + public ServiceUpdater setWebhooksOnChannelAddMethod( + final HttpMethod webhooksOnChannelAddMethod + ) { this.webhooksOnChannelAddMethod = webhooksOnChannelAddMethod; return this; } - public ServiceUpdater setWebhooksOnChannelDestroyUrl(final URI webhooksOnChannelDestroyUrl){ + + public ServiceUpdater setWebhooksOnChannelDestroyUrl( + final URI webhooksOnChannelDestroyUrl + ) { this.webhooksOnChannelDestroyUrl = webhooksOnChannelDestroyUrl; return this; } - public ServiceUpdater setWebhooksOnChannelDestroyUrl(final String webhooksOnChannelDestroyUrl){ - return setWebhooksOnChannelDestroyUrl(Promoter.uriFromString(webhooksOnChannelDestroyUrl)); + public ServiceUpdater setWebhooksOnChannelDestroyUrl( + final String webhooksOnChannelDestroyUrl + ) { + return setWebhooksOnChannelDestroyUrl( + Promoter.uriFromString(webhooksOnChannelDestroyUrl) + ); } - public ServiceUpdater setWebhooksOnChannelDestroyMethod(final HttpMethod webhooksOnChannelDestroyMethod){ + + public ServiceUpdater setWebhooksOnChannelDestroyMethod( + final HttpMethod webhooksOnChannelDestroyMethod + ) { this.webhooksOnChannelDestroyMethod = webhooksOnChannelDestroyMethod; return this; } - public ServiceUpdater setWebhooksOnChannelUpdateUrl(final URI webhooksOnChannelUpdateUrl){ + + public ServiceUpdater setWebhooksOnChannelUpdateUrl( + final URI webhooksOnChannelUpdateUrl + ) { this.webhooksOnChannelUpdateUrl = webhooksOnChannelUpdateUrl; return this; } - public ServiceUpdater setWebhooksOnChannelUpdateUrl(final String webhooksOnChannelUpdateUrl){ - return setWebhooksOnChannelUpdateUrl(Promoter.uriFromString(webhooksOnChannelUpdateUrl)); + public ServiceUpdater setWebhooksOnChannelUpdateUrl( + final String webhooksOnChannelUpdateUrl + ) { + return setWebhooksOnChannelUpdateUrl( + Promoter.uriFromString(webhooksOnChannelUpdateUrl) + ); } - public ServiceUpdater setWebhooksOnChannelUpdateMethod(final HttpMethod webhooksOnChannelUpdateMethod){ + + public ServiceUpdater setWebhooksOnChannelUpdateMethod( + final HttpMethod webhooksOnChannelUpdateMethod + ) { this.webhooksOnChannelUpdateMethod = webhooksOnChannelUpdateMethod; return this; } - public ServiceUpdater setWebhooksOnMemberAddUrl(final URI webhooksOnMemberAddUrl){ + + public ServiceUpdater setWebhooksOnMemberAddUrl( + final URI webhooksOnMemberAddUrl + ) { this.webhooksOnMemberAddUrl = webhooksOnMemberAddUrl; return this; } - public ServiceUpdater setWebhooksOnMemberAddUrl(final String webhooksOnMemberAddUrl){ - return setWebhooksOnMemberAddUrl(Promoter.uriFromString(webhooksOnMemberAddUrl)); + public ServiceUpdater setWebhooksOnMemberAddUrl( + final String webhooksOnMemberAddUrl + ) { + return setWebhooksOnMemberAddUrl( + Promoter.uriFromString(webhooksOnMemberAddUrl) + ); } - public ServiceUpdater setWebhooksOnMemberAddMethod(final HttpMethod webhooksOnMemberAddMethod){ + + public ServiceUpdater setWebhooksOnMemberAddMethod( + final HttpMethod webhooksOnMemberAddMethod + ) { this.webhooksOnMemberAddMethod = webhooksOnMemberAddMethod; return this; } - public ServiceUpdater setWebhooksOnMemberRemoveUrl(final URI webhooksOnMemberRemoveUrl){ + + public ServiceUpdater setWebhooksOnMemberRemoveUrl( + final URI webhooksOnMemberRemoveUrl + ) { this.webhooksOnMemberRemoveUrl = webhooksOnMemberRemoveUrl; return this; } - public ServiceUpdater setWebhooksOnMemberRemoveUrl(final String webhooksOnMemberRemoveUrl){ - return setWebhooksOnMemberRemoveUrl(Promoter.uriFromString(webhooksOnMemberRemoveUrl)); + public ServiceUpdater setWebhooksOnMemberRemoveUrl( + final String webhooksOnMemberRemoveUrl + ) { + return setWebhooksOnMemberRemoveUrl( + Promoter.uriFromString(webhooksOnMemberRemoveUrl) + ); } - public ServiceUpdater setWebhooksOnMemberRemoveMethod(final HttpMethod webhooksOnMemberRemoveMethod){ + + public ServiceUpdater setWebhooksOnMemberRemoveMethod( + final HttpMethod webhooksOnMemberRemoveMethod + ) { this.webhooksOnMemberRemoveMethod = webhooksOnMemberRemoveMethod; return this; } - public ServiceUpdater setWebhooksOnMessageSentUrl(final URI webhooksOnMessageSentUrl){ + + public ServiceUpdater setWebhooksOnMessageSentUrl( + final URI webhooksOnMessageSentUrl + ) { this.webhooksOnMessageSentUrl = webhooksOnMessageSentUrl; return this; } - public ServiceUpdater setWebhooksOnMessageSentUrl(final String webhooksOnMessageSentUrl){ - return setWebhooksOnMessageSentUrl(Promoter.uriFromString(webhooksOnMessageSentUrl)); + public ServiceUpdater setWebhooksOnMessageSentUrl( + final String webhooksOnMessageSentUrl + ) { + return setWebhooksOnMessageSentUrl( + Promoter.uriFromString(webhooksOnMessageSentUrl) + ); } - public ServiceUpdater setWebhooksOnMessageSentMethod(final HttpMethod webhooksOnMessageSentMethod){ + + public ServiceUpdater setWebhooksOnMessageSentMethod( + final HttpMethod webhooksOnMessageSentMethod + ) { this.webhooksOnMessageSentMethod = webhooksOnMessageSentMethod; return this; } - public ServiceUpdater setWebhooksOnMessageUpdatedUrl(final URI webhooksOnMessageUpdatedUrl){ + + public ServiceUpdater setWebhooksOnMessageUpdatedUrl( + final URI webhooksOnMessageUpdatedUrl + ) { this.webhooksOnMessageUpdatedUrl = webhooksOnMessageUpdatedUrl; return this; } - public ServiceUpdater setWebhooksOnMessageUpdatedUrl(final String webhooksOnMessageUpdatedUrl){ - return setWebhooksOnMessageUpdatedUrl(Promoter.uriFromString(webhooksOnMessageUpdatedUrl)); + public ServiceUpdater setWebhooksOnMessageUpdatedUrl( + final String webhooksOnMessageUpdatedUrl + ) { + return setWebhooksOnMessageUpdatedUrl( + Promoter.uriFromString(webhooksOnMessageUpdatedUrl) + ); } - public ServiceUpdater setWebhooksOnMessageUpdatedMethod(final HttpMethod webhooksOnMessageUpdatedMethod){ + + public ServiceUpdater setWebhooksOnMessageUpdatedMethod( + final HttpMethod webhooksOnMessageUpdatedMethod + ) { this.webhooksOnMessageUpdatedMethod = webhooksOnMessageUpdatedMethod; return this; } - public ServiceUpdater setWebhooksOnMessageRemovedUrl(final URI webhooksOnMessageRemovedUrl){ + + public ServiceUpdater setWebhooksOnMessageRemovedUrl( + final URI webhooksOnMessageRemovedUrl + ) { this.webhooksOnMessageRemovedUrl = webhooksOnMessageRemovedUrl; return this; } - public ServiceUpdater setWebhooksOnMessageRemovedUrl(final String webhooksOnMessageRemovedUrl){ - return setWebhooksOnMessageRemovedUrl(Promoter.uriFromString(webhooksOnMessageRemovedUrl)); + public ServiceUpdater setWebhooksOnMessageRemovedUrl( + final String webhooksOnMessageRemovedUrl + ) { + return setWebhooksOnMessageRemovedUrl( + Promoter.uriFromString(webhooksOnMessageRemovedUrl) + ); } - public ServiceUpdater setWebhooksOnMessageRemovedMethod(final HttpMethod webhooksOnMessageRemovedMethod){ + + public ServiceUpdater setWebhooksOnMessageRemovedMethod( + final HttpMethod webhooksOnMessageRemovedMethod + ) { this.webhooksOnMessageRemovedMethod = webhooksOnMessageRemovedMethod; return this; } - public ServiceUpdater setWebhooksOnChannelAddedUrl(final URI webhooksOnChannelAddedUrl){ + + public ServiceUpdater setWebhooksOnChannelAddedUrl( + final URI webhooksOnChannelAddedUrl + ) { this.webhooksOnChannelAddedUrl = webhooksOnChannelAddedUrl; return this; } - public ServiceUpdater setWebhooksOnChannelAddedUrl(final String webhooksOnChannelAddedUrl){ - return setWebhooksOnChannelAddedUrl(Promoter.uriFromString(webhooksOnChannelAddedUrl)); + public ServiceUpdater setWebhooksOnChannelAddedUrl( + final String webhooksOnChannelAddedUrl + ) { + return setWebhooksOnChannelAddedUrl( + Promoter.uriFromString(webhooksOnChannelAddedUrl) + ); } - public ServiceUpdater setWebhooksOnChannelAddedMethod(final HttpMethod webhooksOnChannelAddedMethod){ + + public ServiceUpdater setWebhooksOnChannelAddedMethod( + final HttpMethod webhooksOnChannelAddedMethod + ) { this.webhooksOnChannelAddedMethod = webhooksOnChannelAddedMethod; return this; } - public ServiceUpdater setWebhooksOnChannelDestroyedUrl(final URI webhooksOnChannelDestroyedUrl){ + + public ServiceUpdater setWebhooksOnChannelDestroyedUrl( + final URI webhooksOnChannelDestroyedUrl + ) { this.webhooksOnChannelDestroyedUrl = webhooksOnChannelDestroyedUrl; return this; } - public ServiceUpdater setWebhooksOnChannelDestroyedUrl(final String webhooksOnChannelDestroyedUrl){ - return setWebhooksOnChannelDestroyedUrl(Promoter.uriFromString(webhooksOnChannelDestroyedUrl)); + public ServiceUpdater setWebhooksOnChannelDestroyedUrl( + final String webhooksOnChannelDestroyedUrl + ) { + return setWebhooksOnChannelDestroyedUrl( + Promoter.uriFromString(webhooksOnChannelDestroyedUrl) + ); } - public ServiceUpdater setWebhooksOnChannelDestroyedMethod(final HttpMethod webhooksOnChannelDestroyedMethod){ - this.webhooksOnChannelDestroyedMethod = webhooksOnChannelDestroyedMethod; + + public ServiceUpdater setWebhooksOnChannelDestroyedMethod( + final HttpMethod webhooksOnChannelDestroyedMethod + ) { + this.webhooksOnChannelDestroyedMethod = + webhooksOnChannelDestroyedMethod; return this; } - public ServiceUpdater setWebhooksOnChannelUpdatedUrl(final URI webhooksOnChannelUpdatedUrl){ + + public ServiceUpdater setWebhooksOnChannelUpdatedUrl( + final URI webhooksOnChannelUpdatedUrl + ) { this.webhooksOnChannelUpdatedUrl = webhooksOnChannelUpdatedUrl; return this; } - public ServiceUpdater setWebhooksOnChannelUpdatedUrl(final String webhooksOnChannelUpdatedUrl){ - return setWebhooksOnChannelUpdatedUrl(Promoter.uriFromString(webhooksOnChannelUpdatedUrl)); + public ServiceUpdater setWebhooksOnChannelUpdatedUrl( + final String webhooksOnChannelUpdatedUrl + ) { + return setWebhooksOnChannelUpdatedUrl( + Promoter.uriFromString(webhooksOnChannelUpdatedUrl) + ); } - public ServiceUpdater setWebhooksOnChannelUpdatedMethod(final HttpMethod webhooksOnChannelUpdatedMethod){ + + public ServiceUpdater setWebhooksOnChannelUpdatedMethod( + final HttpMethod webhooksOnChannelUpdatedMethod + ) { this.webhooksOnChannelUpdatedMethod = webhooksOnChannelUpdatedMethod; return this; } - public ServiceUpdater setWebhooksOnMemberAddedUrl(final URI webhooksOnMemberAddedUrl){ + + public ServiceUpdater setWebhooksOnMemberAddedUrl( + final URI webhooksOnMemberAddedUrl + ) { this.webhooksOnMemberAddedUrl = webhooksOnMemberAddedUrl; return this; } - public ServiceUpdater setWebhooksOnMemberAddedUrl(final String webhooksOnMemberAddedUrl){ - return setWebhooksOnMemberAddedUrl(Promoter.uriFromString(webhooksOnMemberAddedUrl)); + public ServiceUpdater setWebhooksOnMemberAddedUrl( + final String webhooksOnMemberAddedUrl + ) { + return setWebhooksOnMemberAddedUrl( + Promoter.uriFromString(webhooksOnMemberAddedUrl) + ); } - public ServiceUpdater setWebhooksOnMemberAddedMethod(final HttpMethod webhooksOnMemberAddedMethod){ + + public ServiceUpdater setWebhooksOnMemberAddedMethod( + final HttpMethod webhooksOnMemberAddedMethod + ) { this.webhooksOnMemberAddedMethod = webhooksOnMemberAddedMethod; return this; } - public ServiceUpdater setWebhooksOnMemberRemovedUrl(final URI webhooksOnMemberRemovedUrl){ + + public ServiceUpdater setWebhooksOnMemberRemovedUrl( + final URI webhooksOnMemberRemovedUrl + ) { this.webhooksOnMemberRemovedUrl = webhooksOnMemberRemovedUrl; return this; } - public ServiceUpdater setWebhooksOnMemberRemovedUrl(final String webhooksOnMemberRemovedUrl){ - return setWebhooksOnMemberRemovedUrl(Promoter.uriFromString(webhooksOnMemberRemovedUrl)); + public ServiceUpdater setWebhooksOnMemberRemovedUrl( + final String webhooksOnMemberRemovedUrl + ) { + return setWebhooksOnMemberRemovedUrl( + Promoter.uriFromString(webhooksOnMemberRemovedUrl) + ); } - public ServiceUpdater setWebhooksOnMemberRemovedMethod(final HttpMethod webhooksOnMemberRemovedMethod){ + + public ServiceUpdater setWebhooksOnMemberRemovedMethod( + final HttpMethod webhooksOnMemberRemovedMethod + ) { this.webhooksOnMemberRemovedMethod = webhooksOnMemberRemovedMethod; return this; } - public ServiceUpdater setLimitsChannelMembers(final Integer limitsChannelMembers){ + + public ServiceUpdater setLimitsChannelMembers( + final Integer limitsChannelMembers + ) { this.limitsChannelMembers = limitsChannelMembers; return this; } - public ServiceUpdater setLimitsUserChannels(final Integer limitsUserChannels){ + + public ServiceUpdater setLimitsUserChannels( + final Integer limitsUserChannels + ) { this.limitsUserChannels = limitsUserChannels; return this; } @Override - public Service update(final TwilioRestClient client){ + public Service update(final TwilioRestClient client) { String path = "/v1/Services/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -408,224 +636,318 @@ public Service update(final TwilioRestClient client){ return Service.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (defaultServiceRoleSid != null) { - request.addPostParam("DefaultServiceRoleSid", defaultServiceRoleSid); - + request.addPostParam( + "DefaultServiceRoleSid", + defaultServiceRoleSid + ); } if (defaultChannelRoleSid != null) { - request.addPostParam("DefaultChannelRoleSid", defaultChannelRoleSid); - + request.addPostParam( + "DefaultChannelRoleSid", + defaultChannelRoleSid + ); } if (defaultChannelCreatorRoleSid != null) { - request.addPostParam("DefaultChannelCreatorRoleSid", defaultChannelCreatorRoleSid); - + request.addPostParam( + "DefaultChannelCreatorRoleSid", + defaultChannelCreatorRoleSid + ); } if (readStatusEnabled != null) { - request.addPostParam("ReadStatusEnabled", readStatusEnabled.toString()); - + request.addPostParam( + "ReadStatusEnabled", + readStatusEnabled.toString() + ); } if (reachabilityEnabled != null) { - request.addPostParam("ReachabilityEnabled", reachabilityEnabled.toString()); - + request.addPostParam( + "ReachabilityEnabled", + reachabilityEnabled.toString() + ); } if (typingIndicatorTimeout != null) { - request.addPostParam("TypingIndicatorTimeout", typingIndicatorTimeout.toString()); - + request.addPostParam( + "TypingIndicatorTimeout", + typingIndicatorTimeout.toString() + ); } if (consumptionReportInterval != null) { - request.addPostParam("ConsumptionReportInterval", consumptionReportInterval.toString()); - + request.addPostParam( + "ConsumptionReportInterval", + consumptionReportInterval.toString() + ); } if (notificationsNewMessageEnabled != null) { - request.addPostParam("Notifications.NewMessage.Enabled", notificationsNewMessageEnabled.toString()); - + request.addPostParam( + "Notifications.NewMessage.Enabled", + notificationsNewMessageEnabled.toString() + ); } if (notificationsNewMessageTemplate != null) { - request.addPostParam("Notifications.NewMessage.Template", notificationsNewMessageTemplate); - + request.addPostParam( + "Notifications.NewMessage.Template", + notificationsNewMessageTemplate + ); } if (notificationsAddedToChannelEnabled != null) { - request.addPostParam("Notifications.AddedToChannel.Enabled", notificationsAddedToChannelEnabled.toString()); - + request.addPostParam( + "Notifications.AddedToChannel.Enabled", + notificationsAddedToChannelEnabled.toString() + ); } if (notificationsAddedToChannelTemplate != null) { - request.addPostParam("Notifications.AddedToChannel.Template", notificationsAddedToChannelTemplate); - + request.addPostParam( + "Notifications.AddedToChannel.Template", + notificationsAddedToChannelTemplate + ); } if (notificationsRemovedFromChannelEnabled != null) { - request.addPostParam("Notifications.RemovedFromChannel.Enabled", notificationsRemovedFromChannelEnabled.toString()); - + request.addPostParam( + "Notifications.RemovedFromChannel.Enabled", + notificationsRemovedFromChannelEnabled.toString() + ); } if (notificationsRemovedFromChannelTemplate != null) { - request.addPostParam("Notifications.RemovedFromChannel.Template", notificationsRemovedFromChannelTemplate); - + request.addPostParam( + "Notifications.RemovedFromChannel.Template", + notificationsRemovedFromChannelTemplate + ); } if (notificationsInvitedToChannelEnabled != null) { - request.addPostParam("Notifications.InvitedToChannel.Enabled", notificationsInvitedToChannelEnabled.toString()); - + request.addPostParam( + "Notifications.InvitedToChannel.Enabled", + notificationsInvitedToChannelEnabled.toString() + ); } if (notificationsInvitedToChannelTemplate != null) { - request.addPostParam("Notifications.InvitedToChannel.Template", notificationsInvitedToChannelTemplate); - + request.addPostParam( + "Notifications.InvitedToChannel.Template", + notificationsInvitedToChannelTemplate + ); } if (preWebhookUrl != null) { request.addPostParam("PreWebhookUrl", preWebhookUrl.toString()); - } if (postWebhookUrl != null) { request.addPostParam("PostWebhookUrl", postWebhookUrl.toString()); - } if (webhookMethod != null) { request.addPostParam("WebhookMethod", webhookMethod.toString()); - } if (webhookFilters != null) { for (String prop : webhookFilters) { request.addPostParam("WebhookFilters", prop); } - } if (webhooksOnMessageSendUrl != null) { - request.addPostParam("Webhooks.OnMessageSend.Url", webhooksOnMessageSendUrl.toString()); - + request.addPostParam( + "Webhooks.OnMessageSend.Url", + webhooksOnMessageSendUrl.toString() + ); } if (webhooksOnMessageSendMethod != null) { - request.addPostParam("Webhooks.OnMessageSend.Method", webhooksOnMessageSendMethod.toString()); - + request.addPostParam( + "Webhooks.OnMessageSend.Method", + webhooksOnMessageSendMethod.toString() + ); } if (webhooksOnMessageUpdateUrl != null) { - request.addPostParam("Webhooks.OnMessageUpdate.Url", webhooksOnMessageUpdateUrl.toString()); - + request.addPostParam( + "Webhooks.OnMessageUpdate.Url", + webhooksOnMessageUpdateUrl.toString() + ); } if (webhooksOnMessageUpdateMethod != null) { - request.addPostParam("Webhooks.OnMessageUpdate.Method", webhooksOnMessageUpdateMethod.toString()); - + request.addPostParam( + "Webhooks.OnMessageUpdate.Method", + webhooksOnMessageUpdateMethod.toString() + ); } if (webhooksOnMessageRemoveUrl != null) { - request.addPostParam("Webhooks.OnMessageRemove.Url", webhooksOnMessageRemoveUrl.toString()); - + request.addPostParam( + "Webhooks.OnMessageRemove.Url", + webhooksOnMessageRemoveUrl.toString() + ); } if (webhooksOnMessageRemoveMethod != null) { - request.addPostParam("Webhooks.OnMessageRemove.Method", webhooksOnMessageRemoveMethod.toString()); - + request.addPostParam( + "Webhooks.OnMessageRemove.Method", + webhooksOnMessageRemoveMethod.toString() + ); } if (webhooksOnChannelAddUrl != null) { - request.addPostParam("Webhooks.OnChannelAdd.Url", webhooksOnChannelAddUrl.toString()); - + request.addPostParam( + "Webhooks.OnChannelAdd.Url", + webhooksOnChannelAddUrl.toString() + ); } if (webhooksOnChannelAddMethod != null) { - request.addPostParam("Webhooks.OnChannelAdd.Method", webhooksOnChannelAddMethod.toString()); - + request.addPostParam( + "Webhooks.OnChannelAdd.Method", + webhooksOnChannelAddMethod.toString() + ); } if (webhooksOnChannelDestroyUrl != null) { - request.addPostParam("Webhooks.OnChannelDestroy.Url", webhooksOnChannelDestroyUrl.toString()); - + request.addPostParam( + "Webhooks.OnChannelDestroy.Url", + webhooksOnChannelDestroyUrl.toString() + ); } if (webhooksOnChannelDestroyMethod != null) { - request.addPostParam("Webhooks.OnChannelDestroy.Method", webhooksOnChannelDestroyMethod.toString()); - + request.addPostParam( + "Webhooks.OnChannelDestroy.Method", + webhooksOnChannelDestroyMethod.toString() + ); } if (webhooksOnChannelUpdateUrl != null) { - request.addPostParam("Webhooks.OnChannelUpdate.Url", webhooksOnChannelUpdateUrl.toString()); - + request.addPostParam( + "Webhooks.OnChannelUpdate.Url", + webhooksOnChannelUpdateUrl.toString() + ); } if (webhooksOnChannelUpdateMethod != null) { - request.addPostParam("Webhooks.OnChannelUpdate.Method", webhooksOnChannelUpdateMethod.toString()); - + request.addPostParam( + "Webhooks.OnChannelUpdate.Method", + webhooksOnChannelUpdateMethod.toString() + ); } if (webhooksOnMemberAddUrl != null) { - request.addPostParam("Webhooks.OnMemberAdd.Url", webhooksOnMemberAddUrl.toString()); - + request.addPostParam( + "Webhooks.OnMemberAdd.Url", + webhooksOnMemberAddUrl.toString() + ); } if (webhooksOnMemberAddMethod != null) { - request.addPostParam("Webhooks.OnMemberAdd.Method", webhooksOnMemberAddMethod.toString()); - + request.addPostParam( + "Webhooks.OnMemberAdd.Method", + webhooksOnMemberAddMethod.toString() + ); } if (webhooksOnMemberRemoveUrl != null) { - request.addPostParam("Webhooks.OnMemberRemove.Url", webhooksOnMemberRemoveUrl.toString()); - + request.addPostParam( + "Webhooks.OnMemberRemove.Url", + webhooksOnMemberRemoveUrl.toString() + ); } if (webhooksOnMemberRemoveMethod != null) { - request.addPostParam("Webhooks.OnMemberRemove.Method", webhooksOnMemberRemoveMethod.toString()); - + request.addPostParam( + "Webhooks.OnMemberRemove.Method", + webhooksOnMemberRemoveMethod.toString() + ); } if (webhooksOnMessageSentUrl != null) { - request.addPostParam("Webhooks.OnMessageSent.Url", webhooksOnMessageSentUrl.toString()); - + request.addPostParam( + "Webhooks.OnMessageSent.Url", + webhooksOnMessageSentUrl.toString() + ); } if (webhooksOnMessageSentMethod != null) { - request.addPostParam("Webhooks.OnMessageSent.Method", webhooksOnMessageSentMethod.toString()); - + request.addPostParam( + "Webhooks.OnMessageSent.Method", + webhooksOnMessageSentMethod.toString() + ); } if (webhooksOnMessageUpdatedUrl != null) { - request.addPostParam("Webhooks.OnMessageUpdated.Url", webhooksOnMessageUpdatedUrl.toString()); - + request.addPostParam( + "Webhooks.OnMessageUpdated.Url", + webhooksOnMessageUpdatedUrl.toString() + ); } if (webhooksOnMessageUpdatedMethod != null) { - request.addPostParam("Webhooks.OnMessageUpdated.Method", webhooksOnMessageUpdatedMethod.toString()); - + request.addPostParam( + "Webhooks.OnMessageUpdated.Method", + webhooksOnMessageUpdatedMethod.toString() + ); } if (webhooksOnMessageRemovedUrl != null) { - request.addPostParam("Webhooks.OnMessageRemoved.Url", webhooksOnMessageRemovedUrl.toString()); - + request.addPostParam( + "Webhooks.OnMessageRemoved.Url", + webhooksOnMessageRemovedUrl.toString() + ); } if (webhooksOnMessageRemovedMethod != null) { - request.addPostParam("Webhooks.OnMessageRemoved.Method", webhooksOnMessageRemovedMethod.toString()); - + request.addPostParam( + "Webhooks.OnMessageRemoved.Method", + webhooksOnMessageRemovedMethod.toString() + ); } if (webhooksOnChannelAddedUrl != null) { - request.addPostParam("Webhooks.OnChannelAdded.Url", webhooksOnChannelAddedUrl.toString()); - + request.addPostParam( + "Webhooks.OnChannelAdded.Url", + webhooksOnChannelAddedUrl.toString() + ); } if (webhooksOnChannelAddedMethod != null) { - request.addPostParam("Webhooks.OnChannelAdded.Method", webhooksOnChannelAddedMethod.toString()); - + request.addPostParam( + "Webhooks.OnChannelAdded.Method", + webhooksOnChannelAddedMethod.toString() + ); } if (webhooksOnChannelDestroyedUrl != null) { - request.addPostParam("Webhooks.OnChannelDestroyed.Url", webhooksOnChannelDestroyedUrl.toString()); - + request.addPostParam( + "Webhooks.OnChannelDestroyed.Url", + webhooksOnChannelDestroyedUrl.toString() + ); } if (webhooksOnChannelDestroyedMethod != null) { - request.addPostParam("Webhooks.OnChannelDestroyed.Method", webhooksOnChannelDestroyedMethod.toString()); - + request.addPostParam( + "Webhooks.OnChannelDestroyed.Method", + webhooksOnChannelDestroyedMethod.toString() + ); } if (webhooksOnChannelUpdatedUrl != null) { - request.addPostParam("Webhooks.OnChannelUpdated.Url", webhooksOnChannelUpdatedUrl.toString()); - + request.addPostParam( + "Webhooks.OnChannelUpdated.Url", + webhooksOnChannelUpdatedUrl.toString() + ); } if (webhooksOnChannelUpdatedMethod != null) { - request.addPostParam("Webhooks.OnChannelUpdated.Method", webhooksOnChannelUpdatedMethod.toString()); - + request.addPostParam( + "Webhooks.OnChannelUpdated.Method", + webhooksOnChannelUpdatedMethod.toString() + ); } if (webhooksOnMemberAddedUrl != null) { - request.addPostParam("Webhooks.OnMemberAdded.Url", webhooksOnMemberAddedUrl.toString()); - + request.addPostParam( + "Webhooks.OnMemberAdded.Url", + webhooksOnMemberAddedUrl.toString() + ); } if (webhooksOnMemberAddedMethod != null) { - request.addPostParam("Webhooks.OnMemberAdded.Method", webhooksOnMemberAddedMethod.toString()); - + request.addPostParam( + "Webhooks.OnMemberAdded.Method", + webhooksOnMemberAddedMethod.toString() + ); } if (webhooksOnMemberRemovedUrl != null) { - request.addPostParam("Webhooks.OnMemberRemoved.Url", webhooksOnMemberRemovedUrl.toString()); - + request.addPostParam( + "Webhooks.OnMemberRemoved.Url", + webhooksOnMemberRemovedUrl.toString() + ); } if (webhooksOnMemberRemovedMethod != null) { - request.addPostParam("Webhooks.OnMemberRemoved.Method", webhooksOnMemberRemovedMethod.toString()); - + request.addPostParam( + "Webhooks.OnMemberRemoved.Method", + webhooksOnMemberRemovedMethod.toString() + ); } if (limitsChannelMembers != null) { - request.addPostParam("Limits.ChannelMembers", limitsChannelMembers.toString()); - + request.addPostParam( + "Limits.ChannelMembers", + limitsChannelMembers.toString() + ); } if (limitsUserChannels != null) { - request.addPostParam("Limits.UserChannels", limitsUserChannels.toString()); - + request.addPostParam( + "Limits.UserChannels", + limitsUserChannels.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/chat/v1/service/Channel.java b/src/main/java/com/twilio/rest/chat/v1/service/Channel.java index 41bc604e86..d8a1eb22e1 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/Channel.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/Channel.java @@ -24,55 +24,63 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Channel extends Resource { + private static final long serialVersionUID = 188288773259274L; - public static ChannelCreator creator(final String pathServiceSid){ + public static ChannelCreator creator(final String pathServiceSid) { return new ChannelCreator(pathServiceSid); } - public static ChannelDeleter deleter(final String pathServiceSid, final String pathSid){ + public static ChannelDeleter deleter( + final String pathServiceSid, + final String pathSid + ) { return new ChannelDeleter(pathServiceSid, pathSid); } - public static ChannelFetcher fetcher(final String pathServiceSid, final String pathSid){ + public static ChannelFetcher fetcher( + final String pathServiceSid, + final String pathSid + ) { return new ChannelFetcher(pathServiceSid, pathSid); } - public static ChannelReader reader(final String pathServiceSid){ + public static ChannelReader reader(final String pathServiceSid) { return new ChannelReader(pathServiceSid); } - public static ChannelUpdater updater(final String pathServiceSid, final String pathSid){ + public static ChannelUpdater updater( + final String pathServiceSid, + final String pathSid + ) { return new ChannelUpdater(pathServiceSid, pathSid); } /** - * Converts a JSON String into a Channel object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Channel object represented by the provided JSON - */ - public static Channel fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Channel object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Channel object represented by the provided JSON + */ + public static Channel fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Channel.class); @@ -84,14 +92,17 @@ public static Channel fromJson(final String json, final ObjectMapper objectMappe } /** - * Converts a JSON InputStream into a Channel object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Channel object represented by the provided JSON - */ - public static Channel fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Channel object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Channel object represented by the provided JSON + */ + public static Channel fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Channel.class); @@ -101,6 +112,7 @@ public static Channel fromJson(final InputStream json, final ObjectMapper object throw new ApiConnectionException(e.getMessage(), e); } } + public enum ChannelType { PUBLIC("public"), PRIVATE("private"); @@ -138,47 +150,20 @@ public static ChannelType forValue(final String value) { @JsonCreator private Channel( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("unique_name") - final String uniqueName, - - @JsonProperty("attributes") - final String attributes, - - @JsonProperty("type") - final Channel.ChannelType type, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("created_by") - final String createdBy, - - @JsonProperty("members_count") - final Integer membersCount, - - @JsonProperty("messages_count") - final Integer messagesCount, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("attributes") final String attributes, + @JsonProperty("type") final Channel.ChannelType type, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("created_by") final String createdBy, + @JsonProperty("members_count") final Integer membersCount, + @JsonProperty("messages_count") final Integer messagesCount, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.sid = sid; this.accountSid = accountSid; @@ -196,52 +181,65 @@ private Channel( this.links = links; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getUniqueName() { - return this.uniqueName; - } - public final String getAttributes() { - return this.attributes; - } - public final Channel.ChannelType getType() { - return this.type; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getCreatedBy() { - return this.createdBy; - } - public final Integer getMembersCount() { - return this.membersCount; - } - public final Integer getMessagesCount() { - return this.messagesCount; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getUniqueName() { + return this.uniqueName; + } + + public final String getAttributes() { + return this.attributes; + } + + public final Channel.ChannelType getType() { + return this.type; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getCreatedBy() { + return this.createdBy; + } + + public final Integer getMembersCount() { + return this.membersCount; + } + + public final Integer getMessagesCount() { + return this.messagesCount; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -251,13 +249,41 @@ public boolean equals(final Object o) { Channel other = (Channel) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(uniqueName, other.uniqueName) && Objects.equals(attributes, other.attributes) && Objects.equals(type, other.type) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(createdBy, other.createdBy) && Objects.equals(membersCount, other.membersCount) && Objects.equals(messagesCount, other.messagesCount) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(attributes, other.attributes) && + Objects.equals(type, other.type) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(createdBy, other.createdBy) && + Objects.equals(membersCount, other.membersCount) && + Objects.equals(messagesCount, other.messagesCount) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, serviceSid, friendlyName, uniqueName, attributes, type, dateCreated, dateUpdated, createdBy, membersCount, messagesCount, url, links); + return Objects.hash( + sid, + accountSid, + serviceSid, + friendlyName, + uniqueName, + attributes, + type, + dateCreated, + dateUpdated, + createdBy, + membersCount, + messagesCount, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/chat/v1/service/ChannelCreator.java b/src/main/java/com/twilio/rest/chat/v1/service/ChannelCreator.java index 088d1faab2..eeaa90e8de 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/ChannelCreator.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/ChannelCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.chat.v1.service; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class ChannelCreator extends Creator { - - -public class ChannelCreator extends Creator{ private String pathServiceSid; private String friendlyName; private String uniqueName; @@ -38,40 +37,53 @@ public ChannelCreator(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - public ChannelCreator setFriendlyName(final String friendlyName){ + public ChannelCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public ChannelCreator setUniqueName(final String uniqueName){ + + public ChannelCreator setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - public ChannelCreator setAttributes(final String attributes){ + + public ChannelCreator setAttributes(final String attributes) { this.attributes = attributes; return this; } - public ChannelCreator setType(final Channel.ChannelType type){ + + public ChannelCreator setType(final Channel.ChannelType type) { this.type = type; return this; } @Override - public Channel create(final TwilioRestClient client){ + public Channel create(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Channels"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Channel creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Channel creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -80,22 +92,19 @@ public Channel create(final TwilioRestClient client){ return Channel.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (uniqueName != null) { request.addPostParam("UniqueName", uniqueName); - } if (attributes != null) { request.addPostParam("Attributes", attributes); - } if (type != null) { request.addPostParam("Type", type.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/chat/v1/service/ChannelDeleter.java b/src/main/java/com/twilio/rest/chat/v1/service/ChannelDeleter.java index 595513add3..da81b19e35 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/ChannelDeleter.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/ChannelDeleter.java @@ -24,24 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class ChannelDeleter extends Deleter { + private String pathServiceSid; private String pathSid; - public ChannelDeleter(final String pathServiceSid, final String pathSid){ + public ChannelDeleter(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Channels/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +53,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Channel delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Channel delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/chat/v1/service/ChannelFetcher.java b/src/main/java/com/twilio/rest/chat/v1/service/ChannelFetcher.java index e7ecf2f93c..469c177c22 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/ChannelFetcher.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/ChannelFetcher.java @@ -24,25 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class ChannelFetcher extends Fetcher { + private String pathServiceSid; private String pathSid; - public ChannelFetcher(final String pathServiceSid, final String pathSid){ + public ChannelFetcher(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - @Override public Channel fetch(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Channels/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,9 +53,14 @@ public Channel fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Channel fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Channel fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/chat/v1/service/ChannelReader.java b/src/main/java/com/twilio/rest/chat/v1/service/ChannelReader.java index 9204144eec..bed0640c65 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/ChannelReader.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/ChannelReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.chat.v1.service; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.converter.Promoter; @@ -25,28 +26,28 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - import java.util.List; - public class ChannelReader extends Reader { + private String pathServiceSid; private List type; private Integer pageSize; - public ChannelReader(final String pathServiceSid){ + public ChannelReader(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - public ChannelReader setType(final List type){ + public ChannelReader setType(final List type) { this.type = type; return this; } - public ChannelReader setType(final Channel.ChannelType type){ + + public ChannelReader setType(final Channel.ChannelType type) { return setType(Promoter.listOfOne(type)); } - public ChannelReader setPageSize(final Integer pageSize){ + + public ChannelReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -58,7 +59,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Channels"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -70,13 +75,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Channel read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Channel read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -92,7 +105,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reques } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.CHAT.toString()) @@ -100,9 +116,11 @@ public Page previousPage(final Page page, final TwilioRestClie return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.CHAT.toString()) @@ -111,14 +129,15 @@ public Page nextPage(final Page page, final TwilioRestClient c } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (type != null) { for (Channel.ChannelType prop : type) { @@ -126,11 +145,10 @@ private void addQueryParams(final Request request) { } } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/chat/v1/service/ChannelUpdater.java b/src/main/java/com/twilio/rest/chat/v1/service/ChannelUpdater.java index e005b16196..aa70f14878 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/ChannelUpdater.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/ChannelUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.chat.v1.service; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,52 +25,62 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class ChannelUpdater extends Updater { - - -public class ChannelUpdater extends Updater{ private String pathServiceSid; private String pathSid; private String friendlyName; private String uniqueName; private String attributes; - public ChannelUpdater(final String pathServiceSid, final String pathSid){ + public ChannelUpdater(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - public ChannelUpdater setFriendlyName(final String friendlyName){ + public ChannelUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public ChannelUpdater setUniqueName(final String uniqueName){ + + public ChannelUpdater setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - public ChannelUpdater setAttributes(final String attributes){ + + public ChannelUpdater setAttributes(final String attributes) { this.attributes = attributes; return this; } @Override - public Channel update(final TwilioRestClient client){ + public Channel update(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Channels/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Channel update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Channel update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -78,18 +89,16 @@ public Channel update(final TwilioRestClient client){ return Channel.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (uniqueName != null) { request.addPostParam("UniqueName", uniqueName); - } if (attributes != null) { request.addPostParam("Attributes", attributes); - } } } diff --git a/src/main/java/com/twilio/rest/chat/v1/service/Role.java b/src/main/java/com/twilio/rest/chat/v1/service/Role.java index e747de8fab..ace117b337 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/Role.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/Role.java @@ -24,54 +24,68 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.List; import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Role extends Resource { + private static final long serialVersionUID = 252065084446046L; - public static RoleCreator creator(final String pathServiceSid, final String friendlyName, final Role.RoleType type, final List permission){ + public static RoleCreator creator( + final String pathServiceSid, + final String friendlyName, + final Role.RoleType type, + final List permission + ) { return new RoleCreator(pathServiceSid, friendlyName, type, permission); } - public static RoleDeleter deleter(final String pathServiceSid, final String pathSid){ + public static RoleDeleter deleter( + final String pathServiceSid, + final String pathSid + ) { return new RoleDeleter(pathServiceSid, pathSid); } - public static RoleFetcher fetcher(final String pathServiceSid, final String pathSid){ + public static RoleFetcher fetcher( + final String pathServiceSid, + final String pathSid + ) { return new RoleFetcher(pathServiceSid, pathSid); } - public static RoleReader reader(final String pathServiceSid){ + public static RoleReader reader(final String pathServiceSid) { return new RoleReader(pathServiceSid); } - public static RoleUpdater updater(final String pathServiceSid, final String pathSid, final List permission){ + public static RoleUpdater updater( + final String pathServiceSid, + final String pathSid, + final List permission + ) { return new RoleUpdater(pathServiceSid, pathSid, permission); } /** - * Converts a JSON String into a Role object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Role object represented by the provided JSON - */ - public static Role fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Role object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Role object represented by the provided JSON + */ + public static Role fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Role.class); @@ -83,14 +97,17 @@ public static Role fromJson(final String json, final ObjectMapper objectMapper) } /** - * Converts a JSON InputStream into a Role object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Role object represented by the provided JSON - */ - public static Role fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Role object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Role object represented by the provided JSON + */ + public static Role fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Role.class); @@ -100,6 +117,7 @@ public static Role fromJson(final InputStream json, final ObjectMapper objectMap throw new ApiConnectionException(e.getMessage(), e); } } + public enum RoleType { CHANNEL("channel"), DEPLOYMENT("deployment"); @@ -132,32 +150,15 @@ public static RoleType forValue(final String value) { @JsonCreator private Role( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("type") - final Role.RoleType type, - - @JsonProperty("permissions") - final List permissions, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("type") final Role.RoleType type, + @JsonProperty("permissions") final List permissions, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url ) { this.sid = sid; this.accountSid = accountSid; @@ -170,37 +171,45 @@ private Role( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final Role.RoleType getType() { - return this.type; - } - public final List getPermissions() { - return this.permissions; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final Role.RoleType getType() { + return this.type; + } + + public final List getPermissions() { + return this.permissions; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -210,13 +219,31 @@ public boolean equals(final Object o) { Role other = (Role) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(type, other.type) && Objects.equals(permissions, other.permissions) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(type, other.type) && + Objects.equals(permissions, other.permissions) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, serviceSid, friendlyName, type, permissions, dateCreated, dateUpdated, url); + return Objects.hash( + sid, + accountSid, + serviceSid, + friendlyName, + type, + permissions, + dateCreated, + dateUpdated, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/chat/v1/service/RoleCreator.java b/src/main/java/com/twilio/rest/chat/v1/service/RoleCreator.java index 259e7a01fe..d73449dcbf 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/RoleCreator.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/RoleCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.chat.v1.service; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -25,60 +26,81 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.util.List; - import java.util.List; +public class RoleCreator extends Creator { - -public class RoleCreator extends Creator{ private String pathServiceSid; private String friendlyName; private Role.RoleType type; private List permission; - public RoleCreator(final String pathServiceSid, final String friendlyName, final Role.RoleType type, final List permission) { + public RoleCreator( + final String pathServiceSid, + final String friendlyName, + final Role.RoleType type, + final List permission + ) { this.pathServiceSid = pathServiceSid; this.friendlyName = friendlyName; this.type = type; this.permission = permission; } - public RoleCreator setFriendlyName(final String friendlyName){ + public RoleCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public RoleCreator setType(final Role.RoleType type){ + + public RoleCreator setType(final Role.RoleType type) { this.type = type; return this; } - public RoleCreator setPermission(final List permission){ + + public RoleCreator setPermission(final List permission) { this.permission = permission; return this; } - public RoleCreator setPermission(final String permission){ + + public RoleCreator setPermission(final String permission) { return setPermission(Promoter.listOfOne(permission)); } @Override - public Role create(final TwilioRestClient client){ + public Role create(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Roles"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"FriendlyName"+"}", this.friendlyName.toString()); - path = path.replace("{"+"Type"+"}", this.type.toString()); - path = path.replace("{"+"Permission"+"}", this.permission.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "FriendlyName" + "}", + this.friendlyName.toString() + ); + path = path.replace("{" + "Type" + "}", this.type.toString()); + path = + path.replace("{" + "Permission" + "}", this.permission.toString()); Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Role creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Role creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -87,20 +109,18 @@ public Role create(final TwilioRestClient client){ return Role.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (type != null) { request.addPostParam("Type", type.toString()); - } if (permission != null) { for (String prop : permission) { request.addPostParam("Permission", prop); } - } } } diff --git a/src/main/java/com/twilio/rest/chat/v1/service/RoleDeleter.java b/src/main/java/com/twilio/rest/chat/v1/service/RoleDeleter.java index 0329a02572..5ba9457c08 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/RoleDeleter.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/RoleDeleter.java @@ -24,24 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class RoleDeleter extends Deleter { + private String pathServiceSid; private String pathSid; - public RoleDeleter(final String pathServiceSid, final String pathSid){ + public RoleDeleter(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Roles/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +53,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Role delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Role delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/chat/v1/service/RoleFetcher.java b/src/main/java/com/twilio/rest/chat/v1/service/RoleFetcher.java index 79c9cba4b9..62e87d717d 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/RoleFetcher.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/RoleFetcher.java @@ -24,25 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class RoleFetcher extends Fetcher { + private String pathServiceSid; private String pathSid; - public RoleFetcher(final String pathServiceSid, final String pathSid){ + public RoleFetcher(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - @Override public Role fetch(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Roles/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,9 +53,14 @@ public Role fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Role fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Role fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/chat/v1/service/RoleReader.java b/src/main/java/com/twilio/rest/chat/v1/service/RoleReader.java index bf23ed7bff..fd2fd58a8e 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/RoleReader.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/RoleReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.chat.v1.service; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,19 +25,17 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class RoleReader extends Reader { + private String pathServiceSid; private Integer pageSize; - public RoleReader(final String pathServiceSid){ + public RoleReader(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - public RoleReader setPageSize(final Integer pageSize){ + public RoleReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -48,7 +47,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Roles"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -60,13 +63,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Role read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Role read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +93,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request r } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.CHAT.toString()) @@ -90,9 +104,11 @@ public Page previousPage(final Page page, final TwilioRestClient cli return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.CHAT.toString()) @@ -101,21 +117,21 @@ public Page nextPage(final Page page, final TwilioRestClient client) } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/chat/v1/service/RoleUpdater.java b/src/main/java/com/twilio/rest/chat/v1/service/RoleUpdater.java index c470fa874f..c5b82a472f 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/RoleUpdater.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/RoleUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.chat.v1.service; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -24,49 +25,63 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - import java.util.List; +public class RoleUpdater extends Updater { -public class RoleUpdater extends Updater{ private String pathServiceSid; private String pathSid; private List permission; - public RoleUpdater(final String pathServiceSid, final String pathSid, final List permission){ + public RoleUpdater( + final String pathServiceSid, + final String pathSid, + final List permission + ) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; this.permission = permission; } - public RoleUpdater setPermission(final List permission){ + public RoleUpdater setPermission(final List permission) { this.permission = permission; return this; } - public RoleUpdater setPermission(final String permission){ + + public RoleUpdater setPermission(final String permission) { return setPermission(Promoter.listOfOne(permission)); } @Override - public Role update(final TwilioRestClient client){ + public Role update(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Roles/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); - path = path.replace("{"+"Permission"+"}", this.permission.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + path = + path.replace("{" + "Permission" + "}", this.permission.toString()); Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Role update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Role update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -75,12 +90,12 @@ public Role update(final TwilioRestClient client){ return Role.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (permission != null) { for (String prop : permission) { request.addPostParam("Permission", prop); } - } } } diff --git a/src/main/java/com/twilio/rest/chat/v1/service/User.java b/src/main/java/com/twilio/rest/chat/v1/service/User.java index a3cd0fa267..f0c59969fc 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/User.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/User.java @@ -23,55 +23,66 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class User extends Resource { + private static final long serialVersionUID = 136391609300437L; - public static UserCreator creator(final String pathServiceSid, final String identity){ + public static UserCreator creator( + final String pathServiceSid, + final String identity + ) { return new UserCreator(pathServiceSid, identity); } - public static UserDeleter deleter(final String pathServiceSid, final String pathSid){ + public static UserDeleter deleter( + final String pathServiceSid, + final String pathSid + ) { return new UserDeleter(pathServiceSid, pathSid); } - public static UserFetcher fetcher(final String pathServiceSid, final String pathSid){ + public static UserFetcher fetcher( + final String pathServiceSid, + final String pathSid + ) { return new UserFetcher(pathServiceSid, pathSid); } - public static UserReader reader(final String pathServiceSid){ + public static UserReader reader(final String pathServiceSid) { return new UserReader(pathServiceSid); } - public static UserUpdater updater(final String pathServiceSid, final String pathSid){ + public static UserUpdater updater( + final String pathServiceSid, + final String pathSid + ) { return new UserUpdater(pathServiceSid, pathSid); } /** - * Converts a JSON String into a User object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return User object represented by the provided JSON - */ - public static User fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a User object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return User object represented by the provided JSON + */ + public static User fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, User.class); @@ -83,14 +94,17 @@ public static User fromJson(final String json, final ObjectMapper objectMapper) } /** - * Converts a JSON InputStream into a User object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return User object represented by the provided JSON - */ - public static User fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a User object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return User object represented by the provided JSON + */ + public static User fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, User.class); @@ -118,47 +132,22 @@ public static User fromJson(final InputStream json, final ObjectMapper objectMap @JsonCreator private User( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("attributes") - final String attributes, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("role_sid") - final String roleSid, - - @JsonProperty("identity") - final String identity, - - @JsonProperty("is_online") - final Boolean isOnline, - - @JsonProperty("is_notifiable") - final Boolean isNotifiable, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("joined_channels_count") - final Integer joinedChannelsCount, - - @JsonProperty("links") - final Map links, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("attributes") final String attributes, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("role_sid") final String roleSid, + @JsonProperty("identity") final String identity, + @JsonProperty("is_online") final Boolean isOnline, + @JsonProperty("is_notifiable") final Boolean isNotifiable, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty( + "joined_channels_count" + ) final Integer joinedChannelsCount, + @JsonProperty("links") final Map links, + @JsonProperty("url") final URI url ) { this.sid = sid; this.accountSid = accountSid; @@ -176,52 +165,65 @@ private User( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final String getAttributes() { - return this.attributes; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getRoleSid() { - return this.roleSid; - } - public final String getIdentity() { - return this.identity; - } - public final Boolean getIsOnline() { - return this.isOnline; - } - public final Boolean getIsNotifiable() { - return this.isNotifiable; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final Integer getJoinedChannelsCount() { - return this.joinedChannelsCount; - } - public final Map getLinks() { - return this.links; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final String getAttributes() { + return this.attributes; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getRoleSid() { + return this.roleSid; + } + + public final String getIdentity() { + return this.identity; + } + + public final Boolean getIsOnline() { + return this.isOnline; + } + + public final Boolean getIsNotifiable() { + return this.isNotifiable; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final Integer getJoinedChannelsCount() { + return this.joinedChannelsCount; + } + + public final Map getLinks() { + return this.links; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -231,13 +233,41 @@ public boolean equals(final Object o) { User other = (User) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(attributes, other.attributes) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(roleSid, other.roleSid) && Objects.equals(identity, other.identity) && Objects.equals(isOnline, other.isOnline) && Objects.equals(isNotifiable, other.isNotifiable) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(joinedChannelsCount, other.joinedChannelsCount) && Objects.equals(links, other.links) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(attributes, other.attributes) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(roleSid, other.roleSid) && + Objects.equals(identity, other.identity) && + Objects.equals(isOnline, other.isOnline) && + Objects.equals(isNotifiable, other.isNotifiable) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(joinedChannelsCount, other.joinedChannelsCount) && + Objects.equals(links, other.links) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, serviceSid, attributes, friendlyName, roleSid, identity, isOnline, isNotifiable, dateCreated, dateUpdated, joinedChannelsCount, links, url); + return Objects.hash( + sid, + accountSid, + serviceSid, + attributes, + friendlyName, + roleSid, + identity, + isOnline, + isNotifiable, + dateCreated, + dateUpdated, + joinedChannelsCount, + links, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/chat/v1/service/UserCreator.java b/src/main/java/com/twilio/rest/chat/v1/service/UserCreator.java index aac49c7935..eaf3c1683e 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/UserCreator.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/UserCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.chat.v1.service; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class UserCreator extends Creator { - - -public class UserCreator extends Creator{ private String pathServiceSid; private String identity; private String roleSid; @@ -39,41 +38,54 @@ public UserCreator(final String pathServiceSid, final String identity) { this.identity = identity; } - public UserCreator setIdentity(final String identity){ + public UserCreator setIdentity(final String identity) { this.identity = identity; return this; } - public UserCreator setRoleSid(final String roleSid){ + + public UserCreator setRoleSid(final String roleSid) { this.roleSid = roleSid; return this; } - public UserCreator setAttributes(final String attributes){ + + public UserCreator setAttributes(final String attributes) { this.attributes = attributes; return this; } - public UserCreator setFriendlyName(final String friendlyName){ + + public UserCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } @Override - public User create(final TwilioRestClient client){ + public User create(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Users"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Identity"+"}", this.identity.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Identity" + "}", this.identity.toString()); Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("User creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "User creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,22 +94,19 @@ public User create(final TwilioRestClient client){ return User.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (identity != null) { request.addPostParam("Identity", identity); - } if (roleSid != null) { request.addPostParam("RoleSid", roleSid); - } if (attributes != null) { request.addPostParam("Attributes", attributes); - } if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } } } diff --git a/src/main/java/com/twilio/rest/chat/v1/service/UserDeleter.java b/src/main/java/com/twilio/rest/chat/v1/service/UserDeleter.java index 06401b381a..45cdaaf0e7 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/UserDeleter.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/UserDeleter.java @@ -24,24 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class UserDeleter extends Deleter { + private String pathServiceSid; private String pathSid; - public UserDeleter(final String pathServiceSid, final String pathSid){ + public UserDeleter(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Users/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +53,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("User delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "User delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/chat/v1/service/UserFetcher.java b/src/main/java/com/twilio/rest/chat/v1/service/UserFetcher.java index ca735b092e..b72667599d 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/UserFetcher.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/UserFetcher.java @@ -24,25 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class UserFetcher extends Fetcher { + private String pathServiceSid; private String pathSid; - public UserFetcher(final String pathServiceSid, final String pathSid){ + public UserFetcher(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - @Override public User fetch(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Users/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,9 +53,14 @@ public User fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("User fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "User fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/chat/v1/service/UserReader.java b/src/main/java/com/twilio/rest/chat/v1/service/UserReader.java index 5b3f8a5f99..31d804462a 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/UserReader.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/UserReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.chat.v1.service; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,19 +25,17 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class UserReader extends Reader { + private String pathServiceSid; private Integer pageSize; - public UserReader(final String pathServiceSid){ + public UserReader(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - public UserReader setPageSize(final Integer pageSize){ + public UserReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -48,7 +47,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Users"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -60,13 +63,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("User read failed: Unable to connect to server"); + throw new ApiConnectionException( + "User read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +93,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request r } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.CHAT.toString()) @@ -90,9 +104,11 @@ public Page previousPage(final Page page, final TwilioRestClient cli return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.CHAT.toString()) @@ -101,21 +117,21 @@ public Page nextPage(final Page page, final TwilioRestClient client) } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/chat/v1/service/UserUpdater.java b/src/main/java/com/twilio/rest/chat/v1/service/UserUpdater.java index 9adeaec523..b722bf64cc 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/UserUpdater.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/UserUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.chat.v1.service; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,52 +25,62 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class UserUpdater extends Updater { - - -public class UserUpdater extends Updater{ private String pathServiceSid; private String pathSid; private String roleSid; private String attributes; private String friendlyName; - public UserUpdater(final String pathServiceSid, final String pathSid){ + public UserUpdater(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - public UserUpdater setRoleSid(final String roleSid){ + public UserUpdater setRoleSid(final String roleSid) { this.roleSid = roleSid; return this; } - public UserUpdater setAttributes(final String attributes){ + + public UserUpdater setAttributes(final String attributes) { this.attributes = attributes; return this; } - public UserUpdater setFriendlyName(final String friendlyName){ + + public UserUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } @Override - public User update(final TwilioRestClient client){ + public User update(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Users/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("User update failed: Unable to connect to server"); + throw new ApiConnectionException( + "User update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -78,18 +89,16 @@ public User update(final TwilioRestClient client){ return User.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (roleSid != null) { request.addPostParam("RoleSid", roleSid); - } if (attributes != null) { request.addPostParam("Attributes", attributes); - } if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } } } diff --git a/src/main/java/com/twilio/rest/chat/v1/service/channel/Invite.java b/src/main/java/com/twilio/rest/chat/v1/service/channel/Invite.java index 525352bbcf..daf4f4701f 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/channel/Invite.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/channel/Invite.java @@ -23,49 +23,63 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Invite extends Resource { + private static final long serialVersionUID = 148273166902210L; - public static InviteCreator creator(final String pathServiceSid, final String pathChannelSid, final String identity){ + public static InviteCreator creator( + final String pathServiceSid, + final String pathChannelSid, + final String identity + ) { return new InviteCreator(pathServiceSid, pathChannelSid, identity); } - public static InviteDeleter deleter(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public static InviteDeleter deleter( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { return new InviteDeleter(pathServiceSid, pathChannelSid, pathSid); } - public static InviteFetcher fetcher(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public static InviteFetcher fetcher( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { return new InviteFetcher(pathServiceSid, pathChannelSid, pathSid); } - public static InviteReader reader(final String pathServiceSid, final String pathChannelSid){ + public static InviteReader reader( + final String pathServiceSid, + final String pathChannelSid + ) { return new InviteReader(pathServiceSid, pathChannelSid); } /** - * Converts a JSON String into a Invite object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Invite object represented by the provided JSON - */ - public static Invite fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Invite object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Invite object represented by the provided JSON + */ + public static Invite fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Invite.class); @@ -77,14 +91,17 @@ public static Invite fromJson(final String json, final ObjectMapper objectMapper } /** - * Converts a JSON InputStream into a Invite object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Invite object represented by the provided JSON - */ - public static Invite fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Invite object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Invite object represented by the provided JSON + */ + public static Invite fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Invite.class); @@ -108,35 +125,16 @@ public static Invite fromJson(final InputStream json, final ObjectMapper objectM @JsonCreator private Invite( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("channel_sid") - final String channelSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("identity") - final String identity, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("role_sid") - final String roleSid, - - @JsonProperty("created_by") - final String createdBy, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("channel_sid") final String channelSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("identity") final String identity, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("role_sid") final String roleSid, + @JsonProperty("created_by") final String createdBy, + @JsonProperty("url") final URI url ) { this.sid = sid; this.accountSid = accountSid; @@ -150,40 +148,49 @@ private Invite( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getChannelSid() { - return this.channelSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final String getIdentity() { - return this.identity; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getRoleSid() { - return this.roleSid; - } - public final String getCreatedBy() { - return this.createdBy; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getChannelSid() { + return this.channelSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final String getIdentity() { + return this.identity; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getRoleSid() { + return this.roleSid; + } + + public final String getCreatedBy() { + return this.createdBy; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -193,13 +200,33 @@ public boolean equals(final Object o) { Invite other = (Invite) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(channelSid, other.channelSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(identity, other.identity) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(roleSid, other.roleSid) && Objects.equals(createdBy, other.createdBy) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(channelSid, other.channelSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(identity, other.identity) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(roleSid, other.roleSid) && + Objects.equals(createdBy, other.createdBy) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, channelSid, serviceSid, identity, dateCreated, dateUpdated, roleSid, createdBy, url); + return Objects.hash( + sid, + accountSid, + channelSid, + serviceSid, + identity, + dateCreated, + dateUpdated, + roleSid, + createdBy, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/chat/v1/service/channel/InviteCreator.java b/src/main/java/com/twilio/rest/chat/v1/service/channel/InviteCreator.java index 9727bd6fb8..bffd41e66b 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/channel/InviteCreator.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/channel/InviteCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.chat.v1.service.channel; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,49 +25,66 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class InviteCreator extends Creator { - - -public class InviteCreator extends Creator{ private String pathServiceSid; private String pathChannelSid; private String identity; private String roleSid; - public InviteCreator(final String pathServiceSid, final String pathChannelSid, final String identity) { + public InviteCreator( + final String pathServiceSid, + final String pathChannelSid, + final String identity + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.identity = identity; } - public InviteCreator setIdentity(final String identity){ + public InviteCreator setIdentity(final String identity) { this.identity = identity; return this; } - public InviteCreator setRoleSid(final String roleSid){ + + public InviteCreator setRoleSid(final String roleSid) { this.roleSid = roleSid; return this; } @Override - public Invite create(final TwilioRestClient client){ + public Invite create(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Invites"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); - path = path.replace("{"+"Identity"+"}", this.identity.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Identity" + "}", this.identity.toString()); Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Invite creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Invite creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -75,14 +93,13 @@ public Invite create(final TwilioRestClient client){ return Invite.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (identity != null) { request.addPostParam("Identity", identity); - } if (roleSid != null) { request.addPostParam("RoleSid", roleSid); - } } } diff --git a/src/main/java/com/twilio/rest/chat/v1/service/channel/InviteDeleter.java b/src/main/java/com/twilio/rest/chat/v1/service/channel/InviteDeleter.java index 65222d9d8a..fb3262493e 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/channel/InviteDeleter.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/channel/InviteDeleter.java @@ -24,27 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class InviteDeleter extends Deleter { + private String pathServiceSid; private String pathChannelSid; private String pathSid; - public InviteDeleter(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public InviteDeleter( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Invites/{Sid}"; + String path = + "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Invites/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -54,9 +65,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Invite delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Invite delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/chat/v1/service/channel/InviteFetcher.java b/src/main/java/com/twilio/rest/chat/v1/service/channel/InviteFetcher.java index 088c7d4d82..593d104a15 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/channel/InviteFetcher.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/channel/InviteFetcher.java @@ -24,28 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class InviteFetcher extends Fetcher { + private String pathServiceSid; private String pathChannelSid; private String pathSid; - public InviteFetcher(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public InviteFetcher( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - @Override public Invite fetch(final TwilioRestClient client) { - String path = "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Invites/{Sid}"; + String path = + "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Invites/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -55,9 +65,14 @@ public Invite fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Invite fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Invite fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/chat/v1/service/channel/InviteReader.java b/src/main/java/com/twilio/rest/chat/v1/service/channel/InviteReader.java index 98c105a184..37da693242 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/channel/InviteReader.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/channel/InviteReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.chat.v1.service.channel; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.converter.Promoter; @@ -25,30 +26,33 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - import java.util.List; - public class InviteReader extends Reader { + private String pathServiceSid; private String pathChannelSid; private List identity; private Integer pageSize; - public InviteReader(final String pathServiceSid, final String pathChannelSid){ + public InviteReader( + final String pathServiceSid, + final String pathChannelSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; } - public InviteReader setIdentity(final List identity){ + public InviteReader setIdentity(final List identity) { this.identity = identity; return this; } - public InviteReader setIdentity(final String identity){ + + public InviteReader setIdentity(final String identity) { return setIdentity(Promoter.listOfOne(identity)); } - public InviteReader setPageSize(final Integer pageSize){ + + public InviteReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -60,8 +64,16 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Invites"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -73,13 +85,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Invite read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Invite read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -95,7 +115,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.CHAT.toString()) @@ -103,9 +126,11 @@ public Page previousPage(final Page page, final TwilioRestClient return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.CHAT.toString()) @@ -114,14 +139,15 @@ public Page nextPage(final Page page, final TwilioRestClient cli } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (identity != null) { for (String prop : identity) { @@ -129,11 +155,10 @@ private void addQueryParams(final Request request) { } } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/chat/v1/service/channel/Member.java b/src/main/java/com/twilio/rest/chat/v1/service/channel/Member.java index 4ec990154b..166f46e1e2 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/channel/Member.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/channel/Member.java @@ -23,53 +23,71 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Member extends Resource { + private static final long serialVersionUID = 102757132179124L; - public static MemberCreator creator(final String pathServiceSid, final String pathChannelSid, final String identity){ + public static MemberCreator creator( + final String pathServiceSid, + final String pathChannelSid, + final String identity + ) { return new MemberCreator(pathServiceSid, pathChannelSid, identity); } - public static MemberDeleter deleter(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public static MemberDeleter deleter( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { return new MemberDeleter(pathServiceSid, pathChannelSid, pathSid); } - public static MemberFetcher fetcher(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public static MemberFetcher fetcher( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { return new MemberFetcher(pathServiceSid, pathChannelSid, pathSid); } - public static MemberReader reader(final String pathServiceSid, final String pathChannelSid){ + public static MemberReader reader( + final String pathServiceSid, + final String pathChannelSid + ) { return new MemberReader(pathServiceSid, pathChannelSid); } - public static MemberUpdater updater(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public static MemberUpdater updater( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { return new MemberUpdater(pathServiceSid, pathChannelSid, pathSid); } /** - * Converts a JSON String into a Member object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Member object represented by the provided JSON - */ - public static Member fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Member object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Member object represented by the provided JSON + */ + public static Member fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Member.class); @@ -81,14 +99,17 @@ public static Member fromJson(final String json, final ObjectMapper objectMapper } /** - * Converts a JSON InputStream into a Member object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Member object represented by the provided JSON - */ - public static Member fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Member object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Member object represented by the provided JSON + */ + public static Member fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Member.class); @@ -113,38 +134,21 @@ public static Member fromJson(final InputStream json, final ObjectMapper objectM @JsonCreator private Member( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("channel_sid") - final String channelSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("identity") - final String identity, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("role_sid") - final String roleSid, - - @JsonProperty("last_consumed_message_index") - final Integer lastConsumedMessageIndex, - - @JsonProperty("last_consumption_timestamp") - final String lastConsumptionTimestamp, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("channel_sid") final String channelSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("identity") final String identity, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("role_sid") final String roleSid, + @JsonProperty( + "last_consumed_message_index" + ) final Integer lastConsumedMessageIndex, + @JsonProperty( + "last_consumption_timestamp" + ) final String lastConsumptionTimestamp, + @JsonProperty("url") final URI url ) { this.sid = sid; this.accountSid = accountSid; @@ -155,47 +159,58 @@ private Member( this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); this.roleSid = roleSid; this.lastConsumedMessageIndex = lastConsumedMessageIndex; - this.lastConsumptionTimestamp = DateConverter.iso8601DateTimeFromString(lastConsumptionTimestamp); + this.lastConsumptionTimestamp = + DateConverter.iso8601DateTimeFromString(lastConsumptionTimestamp); this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getChannelSid() { - return this.channelSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final String getIdentity() { - return this.identity; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getRoleSid() { - return this.roleSid; - } - public final Integer getLastConsumedMessageIndex() { - return this.lastConsumedMessageIndex; - } - public final ZonedDateTime getLastConsumptionTimestamp() { - return this.lastConsumptionTimestamp; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getChannelSid() { + return this.channelSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final String getIdentity() { + return this.identity; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getRoleSid() { + return this.roleSid; + } + + public final Integer getLastConsumedMessageIndex() { + return this.lastConsumedMessageIndex; + } + + public final ZonedDateTime getLastConsumptionTimestamp() { + return this.lastConsumptionTimestamp; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -205,13 +220,41 @@ public boolean equals(final Object o) { Member other = (Member) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(channelSid, other.channelSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(identity, other.identity) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(roleSid, other.roleSid) && Objects.equals(lastConsumedMessageIndex, other.lastConsumedMessageIndex) && Objects.equals(lastConsumptionTimestamp, other.lastConsumptionTimestamp) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(channelSid, other.channelSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(identity, other.identity) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(roleSid, other.roleSid) && + Objects.equals( + lastConsumedMessageIndex, + other.lastConsumedMessageIndex + ) && + Objects.equals( + lastConsumptionTimestamp, + other.lastConsumptionTimestamp + ) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, channelSid, serviceSid, identity, dateCreated, dateUpdated, roleSid, lastConsumedMessageIndex, lastConsumptionTimestamp, url); + return Objects.hash( + sid, + accountSid, + channelSid, + serviceSid, + identity, + dateCreated, + dateUpdated, + roleSid, + lastConsumedMessageIndex, + lastConsumptionTimestamp, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/chat/v1/service/channel/MemberCreator.java b/src/main/java/com/twilio/rest/chat/v1/service/channel/MemberCreator.java index a6f5dbdc91..76a6740f50 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/channel/MemberCreator.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/channel/MemberCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.chat.v1.service.channel; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,49 +25,66 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class MemberCreator extends Creator { - - -public class MemberCreator extends Creator{ private String pathServiceSid; private String pathChannelSid; private String identity; private String roleSid; - public MemberCreator(final String pathServiceSid, final String pathChannelSid, final String identity) { + public MemberCreator( + final String pathServiceSid, + final String pathChannelSid, + final String identity + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.identity = identity; } - public MemberCreator setIdentity(final String identity){ + public MemberCreator setIdentity(final String identity) { this.identity = identity; return this; } - public MemberCreator setRoleSid(final String roleSid){ + + public MemberCreator setRoleSid(final String roleSid) { this.roleSid = roleSid; return this; } @Override - public Member create(final TwilioRestClient client){ + public Member create(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Members"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); - path = path.replace("{"+"Identity"+"}", this.identity.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Identity" + "}", this.identity.toString()); Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Member creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Member creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -75,14 +93,13 @@ public Member create(final TwilioRestClient client){ return Member.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (identity != null) { request.addPostParam("Identity", identity); - } if (roleSid != null) { request.addPostParam("RoleSid", roleSid); - } } } diff --git a/src/main/java/com/twilio/rest/chat/v1/service/channel/MemberDeleter.java b/src/main/java/com/twilio/rest/chat/v1/service/channel/MemberDeleter.java index 9f78939b2d..eecde4c927 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/channel/MemberDeleter.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/channel/MemberDeleter.java @@ -24,27 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class MemberDeleter extends Deleter { + private String pathServiceSid; private String pathChannelSid; private String pathSid; - public MemberDeleter(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public MemberDeleter( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Members/{Sid}"; + String path = + "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Members/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -54,9 +65,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Member delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Member delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/chat/v1/service/channel/MemberFetcher.java b/src/main/java/com/twilio/rest/chat/v1/service/channel/MemberFetcher.java index 61de3743b5..d7d561c8e4 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/channel/MemberFetcher.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/channel/MemberFetcher.java @@ -24,28 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class MemberFetcher extends Fetcher { + private String pathServiceSid; private String pathChannelSid; private String pathSid; - public MemberFetcher(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public MemberFetcher( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - @Override public Member fetch(final TwilioRestClient client) { - String path = "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Members/{Sid}"; + String path = + "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Members/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -55,9 +65,14 @@ public Member fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Member fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Member fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/chat/v1/service/channel/MemberReader.java b/src/main/java/com/twilio/rest/chat/v1/service/channel/MemberReader.java index 619a609c49..cd8976ab0a 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/channel/MemberReader.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/channel/MemberReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.chat.v1.service.channel; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.converter.Promoter; @@ -25,30 +26,33 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - import java.util.List; - public class MemberReader extends Reader { + private String pathServiceSid; private String pathChannelSid; private List identity; private Integer pageSize; - public MemberReader(final String pathServiceSid, final String pathChannelSid){ + public MemberReader( + final String pathServiceSid, + final String pathChannelSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; } - public MemberReader setIdentity(final List identity){ + public MemberReader setIdentity(final List identity) { this.identity = identity; return this; } - public MemberReader setIdentity(final String identity){ + + public MemberReader setIdentity(final String identity) { return setIdentity(Promoter.listOfOne(identity)); } - public MemberReader setPageSize(final Integer pageSize){ + + public MemberReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -60,8 +64,16 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Members"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -73,13 +85,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Member read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Member read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -95,7 +115,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.CHAT.toString()) @@ -103,9 +126,11 @@ public Page previousPage(final Page page, final TwilioRestClient return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.CHAT.toString()) @@ -114,14 +139,15 @@ public Page nextPage(final Page page, final TwilioRestClient cli } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (identity != null) { for (String prop : identity) { @@ -129,11 +155,10 @@ private void addQueryParams(final Request request) { } } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/chat/v1/service/channel/MemberUpdater.java b/src/main/java/com/twilio/rest/chat/v1/service/channel/MemberUpdater.java index 864d434d7f..d3bd6bf8d5 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/channel/MemberUpdater.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/channel/MemberUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.chat.v1.service.channel; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,50 +25,70 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class MemberUpdater extends Updater { - - -public class MemberUpdater extends Updater{ private String pathServiceSid; private String pathChannelSid; private String pathSid; private String roleSid; private Integer lastConsumedMessageIndex; - public MemberUpdater(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public MemberUpdater( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - public MemberUpdater setRoleSid(final String roleSid){ + public MemberUpdater setRoleSid(final String roleSid) { this.roleSid = roleSid; return this; } - public MemberUpdater setLastConsumedMessageIndex(final Integer lastConsumedMessageIndex){ + + public MemberUpdater setLastConsumedMessageIndex( + final Integer lastConsumedMessageIndex + ) { this.lastConsumedMessageIndex = lastConsumedMessageIndex; return this; } @Override - public Member update(final TwilioRestClient client){ - String path = "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Members/{Sid}"; + public Member update(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Members/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Member update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Member update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -76,14 +97,16 @@ public Member update(final TwilioRestClient client){ return Member.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (roleSid != null) { request.addPostParam("RoleSid", roleSid); - } if (lastConsumedMessageIndex != null) { - request.addPostParam("LastConsumedMessageIndex", lastConsumedMessageIndex.toString()); - + request.addPostParam( + "LastConsumedMessageIndex", + lastConsumedMessageIndex.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/chat/v1/service/channel/Message.java b/src/main/java/com/twilio/rest/chat/v1/service/channel/Message.java index b3e7991170..cbbcb4ec5e 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/channel/Message.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/channel/Message.java @@ -24,53 +24,71 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Message extends Resource { + private static final long serialVersionUID = 148235601690422L; - public static MessageCreator creator(final String pathServiceSid, final String pathChannelSid, final String body){ + public static MessageCreator creator( + final String pathServiceSid, + final String pathChannelSid, + final String body + ) { return new MessageCreator(pathServiceSid, pathChannelSid, body); } - public static MessageDeleter deleter(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public static MessageDeleter deleter( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { return new MessageDeleter(pathServiceSid, pathChannelSid, pathSid); } - public static MessageFetcher fetcher(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public static MessageFetcher fetcher( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { return new MessageFetcher(pathServiceSid, pathChannelSid, pathSid); } - public static MessageReader reader(final String pathServiceSid, final String pathChannelSid){ + public static MessageReader reader( + final String pathServiceSid, + final String pathChannelSid + ) { return new MessageReader(pathServiceSid, pathChannelSid); } - public static MessageUpdater updater(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public static MessageUpdater updater( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { return new MessageUpdater(pathServiceSid, pathChannelSid, pathSid); } /** - * Converts a JSON String into a Message object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Message object represented by the provided JSON - */ - public static Message fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Message object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Message object represented by the provided JSON + */ + public static Message fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Message.class); @@ -82,14 +100,17 @@ public static Message fromJson(final String json, final ObjectMapper objectMappe } /** - * Converts a JSON InputStream into a Message object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Message object represented by the provided JSON - */ - public static Message fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Message object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Message object represented by the provided JSON + */ + public static Message fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Message.class); @@ -99,6 +120,7 @@ public static Message fromJson(final InputStream json, final ObjectMapper object throw new ApiConnectionException(e.getMessage(), e); } } + public enum OrderType { ASC("asc"), DESC("desc"); @@ -135,44 +157,19 @@ public static OrderType forValue(final String value) { @JsonCreator private Message( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("attributes") - final String attributes, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("to") - final String to, - - @JsonProperty("channel_sid") - final String channelSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("was_edited") - final Boolean wasEdited, - - @JsonProperty("from") - final String from, - - @JsonProperty("body") - final String body, - - @JsonProperty("index") - final Integer index, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("attributes") final String attributes, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("to") final String to, + @JsonProperty("channel_sid") final String channelSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("was_edited") final Boolean wasEdited, + @JsonProperty("from") final String from, + @JsonProperty("body") final String body, + @JsonProperty("index") final Integer index, + @JsonProperty("url") final URI url ) { this.sid = sid; this.accountSid = accountSid; @@ -189,49 +186,61 @@ private Message( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getAttributes() { - return this.attributes; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final String getTo() { - return this.to; - } - public final String getChannelSid() { - return this.channelSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final Boolean getWasEdited() { - return this.wasEdited; - } - public final String getFrom() { - return this.from; - } - public final String getBody() { - return this.body; - } - public final Integer getIndex() { - return this.index; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getAttributes() { + return this.attributes; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final String getTo() { + return this.to; + } + + public final String getChannelSid() { + return this.channelSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final Boolean getWasEdited() { + return this.wasEdited; + } + + public final String getFrom() { + return this.from; + } + + public final String getBody() { + return this.body; + } + + public final Integer getIndex() { + return this.index; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -241,13 +250,39 @@ public boolean equals(final Object o) { Message other = (Message) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(attributes, other.attributes) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(to, other.to) && Objects.equals(channelSid, other.channelSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(wasEdited, other.wasEdited) && Objects.equals(from, other.from) && Objects.equals(body, other.body) && Objects.equals(index, other.index) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(attributes, other.attributes) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(to, other.to) && + Objects.equals(channelSid, other.channelSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(wasEdited, other.wasEdited) && + Objects.equals(from, other.from) && + Objects.equals(body, other.body) && + Objects.equals(index, other.index) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, attributes, serviceSid, to, channelSid, dateCreated, dateUpdated, wasEdited, from, body, index, url); + return Objects.hash( + sid, + accountSid, + attributes, + serviceSid, + to, + channelSid, + dateCreated, + dateUpdated, + wasEdited, + from, + body, + index, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/chat/v1/service/channel/MessageCreator.java b/src/main/java/com/twilio/rest/chat/v1/service/channel/MessageCreator.java index b308e5e7de..282735b658 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/channel/MessageCreator.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/channel/MessageCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.chat.v1.service.channel; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,54 +25,73 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class MessageCreator extends Creator { - - -public class MessageCreator extends Creator{ private String pathServiceSid; private String pathChannelSid; private String body; private String from; private String attributes; - public MessageCreator(final String pathServiceSid, final String pathChannelSid, final String body) { + public MessageCreator( + final String pathServiceSid, + final String pathChannelSid, + final String body + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.body = body; } - public MessageCreator setBody(final String body){ + public MessageCreator setBody(final String body) { this.body = body; return this; } - public MessageCreator setFrom(final String from){ + + public MessageCreator setFrom(final String from) { this.from = from; return this; } - public MessageCreator setAttributes(final String attributes){ + + public MessageCreator setAttributes(final String attributes) { this.attributes = attributes; return this; } @Override - public Message create(final TwilioRestClient client){ - String path = "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Messages"; + public Message create(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Messages"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); - path = path.replace("{"+"Body"+"}", this.body.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Body" + "}", this.body.toString()); Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Message creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Message creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -80,18 +100,16 @@ public Message create(final TwilioRestClient client){ return Message.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (body != null) { request.addPostParam("Body", body); - } if (from != null) { request.addPostParam("From", from); - } if (attributes != null) { request.addPostParam("Attributes", attributes); - } } } diff --git a/src/main/java/com/twilio/rest/chat/v1/service/channel/MessageDeleter.java b/src/main/java/com/twilio/rest/chat/v1/service/channel/MessageDeleter.java index 632ffb0fc7..fc4aebb601 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/channel/MessageDeleter.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/channel/MessageDeleter.java @@ -24,27 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class MessageDeleter extends Deleter { + private String pathServiceSid; private String pathChannelSid; private String pathSid; - public MessageDeleter(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public MessageDeleter( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Messages/{Sid}"; + String path = + "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Messages/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -54,9 +65,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Message delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Message delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/chat/v1/service/channel/MessageFetcher.java b/src/main/java/com/twilio/rest/chat/v1/service/channel/MessageFetcher.java index 5a11f6ce3c..5deeabe19d 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/channel/MessageFetcher.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/channel/MessageFetcher.java @@ -24,28 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class MessageFetcher extends Fetcher { + private String pathServiceSid; private String pathChannelSid; private String pathSid; - public MessageFetcher(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public MessageFetcher( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - @Override public Message fetch(final TwilioRestClient client) { - String path = "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Messages/{Sid}"; + String path = + "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Messages/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -55,9 +65,14 @@ public Message fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Message fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Message fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/chat/v1/service/channel/MessageReader.java b/src/main/java/com/twilio/rest/chat/v1/service/channel/MessageReader.java index f33666a886..588466c920 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/channel/MessageReader.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/channel/MessageReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.chat.v1.service.channel; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,26 +25,28 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class MessageReader extends Reader { + private String pathServiceSid; private String pathChannelSid; private Message.OrderType order; private Integer pageSize; - public MessageReader(final String pathServiceSid, final String pathChannelSid){ + public MessageReader( + final String pathServiceSid, + final String pathChannelSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; } - public MessageReader setOrder(final Message.OrderType order){ + public MessageReader setOrder(final Message.OrderType order) { this.order = order; return this; } - public MessageReader setPageSize(final Integer pageSize){ + + public MessageReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -54,9 +57,18 @@ public ResourceSet read(final TwilioRestClient client) { } public Page firstPage(final TwilioRestClient client) { - String path = "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Messages"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); + String path = + "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Messages"; + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -68,13 +80,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Message read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Message read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -90,7 +110,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reques } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.CHAT.toString()) @@ -98,9 +121,11 @@ public Page previousPage(final Page page, final TwilioRestClie return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.CHAT.toString()) @@ -109,25 +134,24 @@ public Page nextPage(final Page page, final TwilioRestClient c } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (order != null) { - request.addQueryParam("Order", order.toString()); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/chat/v1/service/channel/MessageUpdater.java b/src/main/java/com/twilio/rest/chat/v1/service/channel/MessageUpdater.java index 3243a24087..55c6d82c2c 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/channel/MessageUpdater.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/channel/MessageUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.chat.v1.service.channel; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,50 +25,68 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class MessageUpdater extends Updater { - - -public class MessageUpdater extends Updater{ private String pathServiceSid; private String pathChannelSid; private String pathSid; private String body; private String attributes; - public MessageUpdater(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public MessageUpdater( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - public MessageUpdater setBody(final String body){ + public MessageUpdater setBody(final String body) { this.body = body; return this; } - public MessageUpdater setAttributes(final String attributes){ + + public MessageUpdater setAttributes(final String attributes) { this.attributes = attributes; return this; } @Override - public Message update(final TwilioRestClient client){ - String path = "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Messages/{Sid}"; + public Message update(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Messages/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Message update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Message update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -76,14 +95,13 @@ public Message update(final TwilioRestClient client){ return Message.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (body != null) { request.addPostParam("Body", body); - } if (attributes != null) { request.addPostParam("Attributes", attributes); - } } } diff --git a/src/main/java/com/twilio/rest/chat/v1/service/user/UserChannel.java b/src/main/java/com/twilio/rest/chat/v1/service/user/UserChannel.java index 9f82a1ee8c..f76faee65b 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/user/UserChannel.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/user/UserChannel.java @@ -23,37 +23,39 @@ import com.twilio.base.Resource; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class UserChannel extends Resource { + private static final long serialVersionUID = 5311313114138L; - public static UserChannelReader reader(final String pathServiceSid, final String pathUserSid){ + public static UserChannelReader reader( + final String pathServiceSid, + final String pathUserSid + ) { return new UserChannelReader(pathServiceSid, pathUserSid); } /** - * Converts a JSON String into a UserChannel object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return UserChannel object represented by the provided JSON - */ - public static UserChannel fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a UserChannel object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return UserChannel object represented by the provided JSON + */ + public static UserChannel fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, UserChannel.class); @@ -65,14 +67,17 @@ public static UserChannel fromJson(final String json, final ObjectMapper objectM } /** - * Converts a JSON InputStream into a UserChannel object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return UserChannel object represented by the provided JSON - */ - public static UserChannel fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a UserChannel object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return UserChannel object represented by the provided JSON + */ + public static UserChannel fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, UserChannel.class); @@ -82,6 +87,7 @@ public static UserChannel fromJson(final InputStream json, final ObjectMapper ob throw new ApiConnectionException(e.getMessage(), e); } } + public enum ChannelStatus { JOINED("joined"), INVITED("invited"), @@ -114,29 +120,18 @@ public static ChannelStatus forValue(final String value) { @JsonCreator private UserChannel( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("channel_sid") - final String channelSid, - - @JsonProperty("member_sid") - final String memberSid, - - @JsonProperty("status") - final UserChannel.ChannelStatus status, - - @JsonProperty("last_consumed_message_index") - final Integer lastConsumedMessageIndex, - - @JsonProperty("unread_messages_count") - final Integer unreadMessagesCount, - - @JsonProperty("links") - final Map links + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("channel_sid") final String channelSid, + @JsonProperty("member_sid") final String memberSid, + @JsonProperty("status") final UserChannel.ChannelStatus status, + @JsonProperty( + "last_consumed_message_index" + ) final Integer lastConsumedMessageIndex, + @JsonProperty( + "unread_messages_count" + ) final Integer unreadMessagesCount, + @JsonProperty("links") final Map links ) { this.accountSid = accountSid; this.serviceSid = serviceSid; @@ -148,34 +143,41 @@ private UserChannel( this.links = links; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final String getChannelSid() { - return this.channelSid; - } - public final String getMemberSid() { - return this.memberSid; - } - public final UserChannel.ChannelStatus getStatus() { - return this.status; - } - public final Integer getLastConsumedMessageIndex() { - return this.lastConsumedMessageIndex; - } - public final Integer getUnreadMessagesCount() { - return this.unreadMessagesCount; - } - public final Map getLinks() { - return this.links; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final String getChannelSid() { + return this.channelSid; + } + + public final String getMemberSid() { + return this.memberSid; + } + + public final UserChannel.ChannelStatus getStatus() { + return this.status; + } + + public final Integer getLastConsumedMessageIndex() { + return this.lastConsumedMessageIndex; + } + + public final Integer getUnreadMessagesCount() { + return this.unreadMessagesCount; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -185,13 +187,32 @@ public boolean equals(final Object o) { UserChannel other = (UserChannel) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(channelSid, other.channelSid) && Objects.equals(memberSid, other.memberSid) && Objects.equals(status, other.status) && Objects.equals(lastConsumedMessageIndex, other.lastConsumedMessageIndex) && Objects.equals(unreadMessagesCount, other.unreadMessagesCount) && Objects.equals(links, other.links) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(channelSid, other.channelSid) && + Objects.equals(memberSid, other.memberSid) && + Objects.equals(status, other.status) && + Objects.equals( + lastConsumedMessageIndex, + other.lastConsumedMessageIndex + ) && + Objects.equals(unreadMessagesCount, other.unreadMessagesCount) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, serviceSid, channelSid, memberSid, status, lastConsumedMessageIndex, unreadMessagesCount, links); + return Objects.hash( + accountSid, + serviceSid, + channelSid, + memberSid, + status, + lastConsumedMessageIndex, + unreadMessagesCount, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/chat/v1/service/user/UserChannelReader.java b/src/main/java/com/twilio/rest/chat/v1/service/user/UserChannelReader.java index c703a32ab6..f2100ea80b 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/user/UserChannelReader.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/user/UserChannelReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.chat.v1.service.user; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,21 +25,22 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class UserChannelReader extends Reader { + private String pathServiceSid; private String pathUserSid; private Integer pageSize; - public UserChannelReader(final String pathServiceSid, final String pathUserSid){ + public UserChannelReader( + final String pathServiceSid, + final String pathUserSid + ) { this.pathServiceSid = pathServiceSid; this.pathUserSid = pathUserSid; } - public UserChannelReader setPageSize(final Integer pageSize){ + public UserChannelReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -50,8 +52,12 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Users/{UserSid}/Channels"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"UserSid"+"}", this.pathUserSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "UserSid" + "}", this.pathUserSid.toString()); Request request = new Request( HttpMethod.GET, @@ -63,13 +69,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("UserChannel read failed: Unable to connect to server"); + throw new ApiConnectionException( + "UserChannel read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -85,7 +99,10 @@ private Page pageForRequest(final TwilioRestClient client, final Re } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.CHAT.toString()) @@ -93,9 +110,11 @@ public Page previousPage(final Page page, final Twilio return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.CHAT.toString()) @@ -104,21 +123,21 @@ public Page nextPage(final Page page, final TwilioRest } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/chat/v2/Credential.java b/src/main/java/com/twilio/rest/chat/v2/Credential.java index 45839b9243..40574eff37 100644 --- a/src/main/java/com/twilio/rest/chat/v2/Credential.java +++ b/src/main/java/com/twilio/rest/chat/v2/Credential.java @@ -24,53 +24,52 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Credential extends Resource { + private static final long serialVersionUID = 161183169234848L; - public static CredentialCreator creator(final Credential.PushService type){ + public static CredentialCreator creator(final Credential.PushService type) { return new CredentialCreator(type); } - public static CredentialDeleter deleter(final String pathSid){ + public static CredentialDeleter deleter(final String pathSid) { return new CredentialDeleter(pathSid); } - public static CredentialFetcher fetcher(final String pathSid){ + public static CredentialFetcher fetcher(final String pathSid) { return new CredentialFetcher(pathSid); } - public static CredentialReader reader(){ + public static CredentialReader reader() { return new CredentialReader(); } - public static CredentialUpdater updater(final String pathSid){ + public static CredentialUpdater updater(final String pathSid) { return new CredentialUpdater(pathSid); } /** - * Converts a JSON String into a Credential object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Credential object represented by the provided JSON - */ - public static Credential fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Credential object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Credential object represented by the provided JSON + */ + public static Credential fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Credential.class); @@ -82,14 +81,17 @@ public static Credential fromJson(final String json, final ObjectMapper objectMa } /** - * Converts a JSON InputStream into a Credential object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Credential object represented by the provided JSON - */ - public static Credential fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Credential object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Credential object represented by the provided JSON + */ + public static Credential fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Credential.class); @@ -99,6 +101,7 @@ public static Credential fromJson(final InputStream json, final ObjectMapper obj throw new ApiConnectionException(e.getMessage(), e); } } + public enum PushService { GCM("gcm"), APN("apn"), @@ -131,29 +134,14 @@ public static PushService forValue(final String value) { @JsonCreator private Credential( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("type") - final Credential.PushService type, - - @JsonProperty("sandbox") - final String sandbox, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("type") final Credential.PushService type, + @JsonProperty("sandbox") final String sandbox, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url ) { this.sid = sid; this.accountSid = accountSid; @@ -165,34 +153,41 @@ private Credential( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final Credential.PushService getType() { - return this.type; - } - public final String getSandbox() { - return this.sandbox; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final Credential.PushService getType() { + return this.type; + } + + public final String getSandbox() { + return this.sandbox; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -202,13 +197,29 @@ public boolean equals(final Object o) { Credential other = (Credential) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(type, other.type) && Objects.equals(sandbox, other.sandbox) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(type, other.type) && + Objects.equals(sandbox, other.sandbox) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, friendlyName, type, sandbox, dateCreated, dateUpdated, url); + return Objects.hash( + sid, + accountSid, + friendlyName, + type, + sandbox, + dateCreated, + dateUpdated, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/chat/v2/CredentialCreator.java b/src/main/java/com/twilio/rest/chat/v2/CredentialCreator.java index 87d7f60d07..02e96d37a7 100644 --- a/src/main/java/com/twilio/rest/chat/v2/CredentialCreator.java +++ b/src/main/java/com/twilio/rest/chat/v2/CredentialCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.chat.v2; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class CredentialCreator extends Creator { - - -public class CredentialCreator extends Creator{ private Credential.PushService type; private String friendlyName; private String certificate; @@ -40,88 +39,97 @@ public CredentialCreator(final Credential.PushService type) { this.type = type; } - public CredentialCreator setType(final Credential.PushService type){ + public CredentialCreator setType(final Credential.PushService type) { this.type = type; return this; } - public CredentialCreator setFriendlyName(final String friendlyName){ + + public CredentialCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public CredentialCreator setCertificate(final String certificate){ + + public CredentialCreator setCertificate(final String certificate) { this.certificate = certificate; return this; } - public CredentialCreator setPrivateKey(final String privateKey){ + + public CredentialCreator setPrivateKey(final String privateKey) { this.privateKey = privateKey; return this; } - public CredentialCreator setSandbox(final Boolean sandbox){ + + public CredentialCreator setSandbox(final Boolean sandbox) { this.sandbox = sandbox; return this; } - public CredentialCreator setApiKey(final String apiKey){ + + public CredentialCreator setApiKey(final String apiKey) { this.apiKey = apiKey; return this; } - public CredentialCreator setSecret(final String secret){ + + public CredentialCreator setSecret(final String secret) { this.secret = secret; return this; } @Override - public Credential create(final TwilioRestClient client){ + public Credential create(final TwilioRestClient client) { String path = "/v2/Credentials"; - path = path.replace("{"+"Type"+"}", this.type.toString()); + path = path.replace("{" + "Type" + "}", this.type.toString()); Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Credential creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Credential creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Credential.fromJson(response.getStream(), client.getObjectMapper()); + return Credential.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (type != null) { request.addPostParam("Type", type.toString()); - } if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (certificate != null) { request.addPostParam("Certificate", certificate); - } if (privateKey != null) { request.addPostParam("PrivateKey", privateKey); - } if (sandbox != null) { request.addPostParam("Sandbox", sandbox.toString()); - } if (apiKey != null) { request.addPostParam("ApiKey", apiKey); - } if (secret != null) { request.addPostParam("Secret", secret); - } } } diff --git a/src/main/java/com/twilio/rest/chat/v2/CredentialDeleter.java b/src/main/java/com/twilio/rest/chat/v2/CredentialDeleter.java index 74c60e9845..6e3898f840 100644 --- a/src/main/java/com/twilio/rest/chat/v2/CredentialDeleter.java +++ b/src/main/java/com/twilio/rest/chat/v2/CredentialDeleter.java @@ -24,21 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class CredentialDeleter extends Deleter { + private String pathSid; - public CredentialDeleter(final String pathSid){ + public CredentialDeleter(final String pathSid) { this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v2/Credentials/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -48,9 +46,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Credential delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Credential delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/chat/v2/CredentialFetcher.java b/src/main/java/com/twilio/rest/chat/v2/CredentialFetcher.java index 59ff871879..149b6e77b2 100644 --- a/src/main/java/com/twilio/rest/chat/v2/CredentialFetcher.java +++ b/src/main/java/com/twilio/rest/chat/v2/CredentialFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class CredentialFetcher extends Fetcher { + private String pathSid; - public CredentialFetcher(final String pathSid){ + public CredentialFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public Credential fetch(final TwilioRestClient client) { String path = "/v2/Credentials/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,15 +46,23 @@ public Credential fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Credential fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Credential fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Credential.fromJson(response.getStream(), client.getObjectMapper()); + return Credential.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/chat/v2/CredentialReader.java b/src/main/java/com/twilio/rest/chat/v2/CredentialReader.java index 4a49bd1ac2..3b32eac98d 100644 --- a/src/main/java/com/twilio/rest/chat/v2/CredentialReader.java +++ b/src/main/java/com/twilio/rest/chat/v2/CredentialReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.chat.v2; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,17 +25,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class CredentialReader extends Reader { + private Integer pageSize; - public CredentialReader(){ - } + public CredentialReader() {} - public CredentialReader setPageSize(final Integer pageSize){ + public CredentialReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -57,13 +55,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Credential read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Credential read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -79,7 +85,10 @@ private Page pageForRequest(final TwilioRestClient client, final Req } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.CHAT.toString()) @@ -87,9 +96,11 @@ public Page previousPage(final Page page, final TwilioRe return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.CHAT.toString()) @@ -98,21 +109,21 @@ public Page nextPage(final Page page, final TwilioRestCl } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/chat/v2/CredentialUpdater.java b/src/main/java/com/twilio/rest/chat/v2/CredentialUpdater.java index 6e12187a5e..21fa8526fe 100644 --- a/src/main/java/com/twilio/rest/chat/v2/CredentialUpdater.java +++ b/src/main/java/com/twilio/rest/chat/v2/CredentialUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.chat.v2; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class CredentialUpdater extends Updater { - - -public class CredentialUpdater extends Updater{ private String pathSid; private String friendlyName; private String certificate; @@ -36,84 +35,93 @@ public class CredentialUpdater extends Updater{ private String apiKey; private String secret; - public CredentialUpdater(final String pathSid){ + public CredentialUpdater(final String pathSid) { this.pathSid = pathSid; } - public CredentialUpdater setFriendlyName(final String friendlyName){ + public CredentialUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public CredentialUpdater setCertificate(final String certificate){ + + public CredentialUpdater setCertificate(final String certificate) { this.certificate = certificate; return this; } - public CredentialUpdater setPrivateKey(final String privateKey){ + + public CredentialUpdater setPrivateKey(final String privateKey) { this.privateKey = privateKey; return this; } - public CredentialUpdater setSandbox(final Boolean sandbox){ + + public CredentialUpdater setSandbox(final Boolean sandbox) { this.sandbox = sandbox; return this; } - public CredentialUpdater setApiKey(final String apiKey){ + + public CredentialUpdater setApiKey(final String apiKey) { this.apiKey = apiKey; return this; } - public CredentialUpdater setSecret(final String secret){ + + public CredentialUpdater setSecret(final String secret) { this.secret = secret; return this; } @Override - public Credential update(final TwilioRestClient client){ + public Credential update(final TwilioRestClient client) { String path = "/v2/Credentials/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Credential update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Credential update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Credential.fromJson(response.getStream(), client.getObjectMapper()); + return Credential.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (certificate != null) { request.addPostParam("Certificate", certificate); - } if (privateKey != null) { request.addPostParam("PrivateKey", privateKey); - } if (sandbox != null) { request.addPostParam("Sandbox", sandbox.toString()); - } if (apiKey != null) { request.addPostParam("ApiKey", apiKey); - } if (secret != null) { request.addPostParam("Secret", secret); - } } } diff --git a/src/main/java/com/twilio/rest/chat/v2/Service.java b/src/main/java/com/twilio/rest/chat/v2/Service.java index 1e01a94615..f68a619f27 100644 --- a/src/main/java/com/twilio/rest/chat/v2/Service.java +++ b/src/main/java/com/twilio/rest/chat/v2/Service.java @@ -23,56 +23,55 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.List; import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Service extends Resource { + private static final long serialVersionUID = 187047184630676L; - public static ServiceCreator creator(final String friendlyName){ + public static ServiceCreator creator(final String friendlyName) { return new ServiceCreator(friendlyName); } - public static ServiceDeleter deleter(final String pathSid){ + public static ServiceDeleter deleter(final String pathSid) { return new ServiceDeleter(pathSid); } - public static ServiceFetcher fetcher(final String pathSid){ + public static ServiceFetcher fetcher(final String pathSid) { return new ServiceFetcher(pathSid); } - public static ServiceReader reader(){ + public static ServiceReader reader() { return new ServiceReader(); } - public static ServiceUpdater updater(final String pathSid){ + public static ServiceUpdater updater(final String pathSid) { return new ServiceUpdater(pathSid); } /** - * Converts a JSON String into a Service object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Service object represented by the provided JSON - */ - public static Service fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Service object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Service object represented by the provided JSON + */ + public static Service fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Service.class); @@ -84,14 +83,17 @@ public static Service fromJson(final String json, final ObjectMapper objectMappe } /** - * Converts a JSON InputStream into a Service object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Service object represented by the provided JSON - */ - public static Service fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Service object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Service object represented by the provided JSON + */ + public static Service fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Service.class); @@ -128,74 +130,43 @@ public static Service fromJson(final InputStream json, final ObjectMapper object @JsonCreator private Service( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("default_service_role_sid") - final String defaultServiceRoleSid, - - @JsonProperty("default_channel_role_sid") - final String defaultChannelRoleSid, - - @JsonProperty("default_channel_creator_role_sid") - final String defaultChannelCreatorRoleSid, - - @JsonProperty("read_status_enabled") - final Boolean readStatusEnabled, - - @JsonProperty("reachability_enabled") - final Boolean reachabilityEnabled, - - @JsonProperty("typing_indicator_timeout") - final Integer typingIndicatorTimeout, - - @JsonProperty("consumption_report_interval") - final Integer consumptionReportInterval, - - @JsonProperty("limits") - final Map limits, - - @JsonProperty("pre_webhook_url") - final String preWebhookUrl, - - @JsonProperty("post_webhook_url") - final String postWebhookUrl, - - @JsonProperty("webhook_method") - final String webhookMethod, - - @JsonProperty("webhook_filters") - final List webhookFilters, - - @JsonProperty("pre_webhook_retry_count") - final Integer preWebhookRetryCount, - - @JsonProperty("post_webhook_retry_count") - final Integer postWebhookRetryCount, - - @JsonProperty("notifications") - final Map notifications, - - @JsonProperty("media") - final Map media, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty( + "default_service_role_sid" + ) final String defaultServiceRoleSid, + @JsonProperty( + "default_channel_role_sid" + ) final String defaultChannelRoleSid, + @JsonProperty( + "default_channel_creator_role_sid" + ) final String defaultChannelCreatorRoleSid, + @JsonProperty("read_status_enabled") final Boolean readStatusEnabled, + @JsonProperty("reachability_enabled") final Boolean reachabilityEnabled, + @JsonProperty( + "typing_indicator_timeout" + ) final Integer typingIndicatorTimeout, + @JsonProperty( + "consumption_report_interval" + ) final Integer consumptionReportInterval, + @JsonProperty("limits") final Map limits, + @JsonProperty("pre_webhook_url") final String preWebhookUrl, + @JsonProperty("post_webhook_url") final String postWebhookUrl, + @JsonProperty("webhook_method") final String webhookMethod, + @JsonProperty("webhook_filters") final List webhookFilters, + @JsonProperty( + "pre_webhook_retry_count" + ) final Integer preWebhookRetryCount, + @JsonProperty( + "post_webhook_retry_count" + ) final Integer postWebhookRetryCount, + @JsonProperty("notifications") final Map notifications, + @JsonProperty("media") final Map media, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.sid = sid; this.accountSid = accountSid; @@ -222,79 +193,101 @@ private Service( this.links = links; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getDefaultServiceRoleSid() { - return this.defaultServiceRoleSid; - } - public final String getDefaultChannelRoleSid() { - return this.defaultChannelRoleSid; - } - public final String getDefaultChannelCreatorRoleSid() { - return this.defaultChannelCreatorRoleSid; - } - public final Boolean getReadStatusEnabled() { - return this.readStatusEnabled; - } - public final Boolean getReachabilityEnabled() { - return this.reachabilityEnabled; - } - public final Integer getTypingIndicatorTimeout() { - return this.typingIndicatorTimeout; - } - public final Integer getConsumptionReportInterval() { - return this.consumptionReportInterval; - } - public final Map getLimits() { - return this.limits; - } - public final String getPreWebhookUrl() { - return this.preWebhookUrl; - } - public final String getPostWebhookUrl() { - return this.postWebhookUrl; - } - public final String getWebhookMethod() { - return this.webhookMethod; - } - public final List getWebhookFilters() { - return this.webhookFilters; - } - public final Integer getPreWebhookRetryCount() { - return this.preWebhookRetryCount; - } - public final Integer getPostWebhookRetryCount() { - return this.postWebhookRetryCount; - } - public final Map getNotifications() { - return this.notifications; - } - public final Map getMedia() { - return this.media; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getDefaultServiceRoleSid() { + return this.defaultServiceRoleSid; + } + + public final String getDefaultChannelRoleSid() { + return this.defaultChannelRoleSid; + } + + public final String getDefaultChannelCreatorRoleSid() { + return this.defaultChannelCreatorRoleSid; + } + + public final Boolean getReadStatusEnabled() { + return this.readStatusEnabled; + } + + public final Boolean getReachabilityEnabled() { + return this.reachabilityEnabled; + } + + public final Integer getTypingIndicatorTimeout() { + return this.typingIndicatorTimeout; + } + + public final Integer getConsumptionReportInterval() { + return this.consumptionReportInterval; + } + + public final Map getLimits() { + return this.limits; + } + + public final String getPreWebhookUrl() { + return this.preWebhookUrl; + } + + public final String getPostWebhookUrl() { + return this.postWebhookUrl; + } + + public final String getWebhookMethod() { + return this.webhookMethod; + } + + public final List getWebhookFilters() { + return this.webhookFilters; + } + + public final Integer getPreWebhookRetryCount() { + return this.preWebhookRetryCount; + } + + public final Integer getPostWebhookRetryCount() { + return this.postWebhookRetryCount; + } + + public final Map getNotifications() { + return this.notifications; + } + + public final Map getMedia() { + return this.media; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -304,13 +297,77 @@ public boolean equals(final Object o) { Service other = (Service) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(defaultServiceRoleSid, other.defaultServiceRoleSid) && Objects.equals(defaultChannelRoleSid, other.defaultChannelRoleSid) && Objects.equals(defaultChannelCreatorRoleSid, other.defaultChannelCreatorRoleSid) && Objects.equals(readStatusEnabled, other.readStatusEnabled) && Objects.equals(reachabilityEnabled, other.reachabilityEnabled) && Objects.equals(typingIndicatorTimeout, other.typingIndicatorTimeout) && Objects.equals(consumptionReportInterval, other.consumptionReportInterval) && Objects.equals(limits, other.limits) && Objects.equals(preWebhookUrl, other.preWebhookUrl) && Objects.equals(postWebhookUrl, other.postWebhookUrl) && Objects.equals(webhookMethod, other.webhookMethod) && Objects.equals(webhookFilters, other.webhookFilters) && Objects.equals(preWebhookRetryCount, other.preWebhookRetryCount) && Objects.equals(postWebhookRetryCount, other.postWebhookRetryCount) && Objects.equals(notifications, other.notifications) && Objects.equals(media, other.media) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals( + defaultServiceRoleSid, + other.defaultServiceRoleSid + ) && + Objects.equals( + defaultChannelRoleSid, + other.defaultChannelRoleSid + ) && + Objects.equals( + defaultChannelCreatorRoleSid, + other.defaultChannelCreatorRoleSid + ) && + Objects.equals(readStatusEnabled, other.readStatusEnabled) && + Objects.equals(reachabilityEnabled, other.reachabilityEnabled) && + Objects.equals( + typingIndicatorTimeout, + other.typingIndicatorTimeout + ) && + Objects.equals( + consumptionReportInterval, + other.consumptionReportInterval + ) && + Objects.equals(limits, other.limits) && + Objects.equals(preWebhookUrl, other.preWebhookUrl) && + Objects.equals(postWebhookUrl, other.postWebhookUrl) && + Objects.equals(webhookMethod, other.webhookMethod) && + Objects.equals(webhookFilters, other.webhookFilters) && + Objects.equals(preWebhookRetryCount, other.preWebhookRetryCount) && + Objects.equals( + postWebhookRetryCount, + other.postWebhookRetryCount + ) && + Objects.equals(notifications, other.notifications) && + Objects.equals(media, other.media) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, friendlyName, dateCreated, dateUpdated, defaultServiceRoleSid, defaultChannelRoleSid, defaultChannelCreatorRoleSid, readStatusEnabled, reachabilityEnabled, typingIndicatorTimeout, consumptionReportInterval, limits, preWebhookUrl, postWebhookUrl, webhookMethod, webhookFilters, preWebhookRetryCount, postWebhookRetryCount, notifications, media, url, links); + return Objects.hash( + sid, + accountSid, + friendlyName, + dateCreated, + dateUpdated, + defaultServiceRoleSid, + defaultChannelRoleSid, + defaultChannelCreatorRoleSid, + readStatusEnabled, + reachabilityEnabled, + typingIndicatorTimeout, + consumptionReportInterval, + limits, + preWebhookUrl, + postWebhookUrl, + webhookMethod, + webhookFilters, + preWebhookRetryCount, + postWebhookRetryCount, + notifications, + media, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/chat/v2/ServiceCreator.java b/src/main/java/com/twilio/rest/chat/v2/ServiceCreator.java index 1ec08cb945..28213c05d1 100644 --- a/src/main/java/com/twilio/rest/chat/v2/ServiceCreator.java +++ b/src/main/java/com/twilio/rest/chat/v2/ServiceCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.chat.v2; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,38 +25,46 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class ServiceCreator extends Creator { - - -public class ServiceCreator extends Creator{ private String friendlyName; public ServiceCreator(final String friendlyName) { this.friendlyName = friendlyName; } - public ServiceCreator setFriendlyName(final String friendlyName){ + public ServiceCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } @Override - public Service create(final TwilioRestClient client){ + public Service create(final TwilioRestClient client) { String path = "/v2/Services"; - path = path.replace("{"+"FriendlyName"+"}", this.friendlyName.toString()); + path = + path.replace( + "{" + "FriendlyName" + "}", + this.friendlyName.toString() + ); Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -64,10 +73,10 @@ public Service create(final TwilioRestClient client){ return Service.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } } } diff --git a/src/main/java/com/twilio/rest/chat/v2/ServiceDeleter.java b/src/main/java/com/twilio/rest/chat/v2/ServiceDeleter.java index 7ba37ccb24..0f3d028c6c 100644 --- a/src/main/java/com/twilio/rest/chat/v2/ServiceDeleter.java +++ b/src/main/java/com/twilio/rest/chat/v2/ServiceDeleter.java @@ -24,21 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class ServiceDeleter extends Deleter { + private String pathSid; - public ServiceDeleter(final String pathSid){ + public ServiceDeleter(final String pathSid) { this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v2/Services/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -48,9 +46,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/chat/v2/ServiceFetcher.java b/src/main/java/com/twilio/rest/chat/v2/ServiceFetcher.java index f89603cd61..67e58a3b4d 100644 --- a/src/main/java/com/twilio/rest/chat/v2/ServiceFetcher.java +++ b/src/main/java/com/twilio/rest/chat/v2/ServiceFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class ServiceFetcher extends Fetcher { + private String pathSid; - public ServiceFetcher(final String pathSid){ + public ServiceFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public Service fetch(final TwilioRestClient client) { String path = "/v2/Services/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,9 +46,14 @@ public Service fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/chat/v2/ServiceReader.java b/src/main/java/com/twilio/rest/chat/v2/ServiceReader.java index 200b48baae..e4bd72687b 100644 --- a/src/main/java/com/twilio/rest/chat/v2/ServiceReader.java +++ b/src/main/java/com/twilio/rest/chat/v2/ServiceReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.chat.v2; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,17 +25,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class ServiceReader extends Reader { + private Integer pageSize; - public ServiceReader(){ - } + public ServiceReader() {} - public ServiceReader setPageSize(final Integer pageSize){ + public ServiceReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -57,13 +55,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -79,7 +85,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reques } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.CHAT.toString()) @@ -87,9 +96,11 @@ public Page previousPage(final Page page, final TwilioRestClie return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.CHAT.toString()) @@ -98,21 +109,21 @@ public Page nextPage(final Page page, final TwilioRestClient c } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/chat/v2/ServiceUpdater.java b/src/main/java/com/twilio/rest/chat/v2/ServiceUpdater.java index bc0d7dc1de..bc5f49c313 100644 --- a/src/main/java/com/twilio/rest/chat/v2/ServiceUpdater.java +++ b/src/main/java/com/twilio/rest/chat/v2/ServiceUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.chat.v2; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -24,13 +25,11 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.net.URI; - import java.util.List; +public class ServiceUpdater extends Updater { -public class ServiceUpdater extends Updater{ private String pathSid; private String friendlyName; private String defaultServiceRoleSid; @@ -64,163 +63,262 @@ public class ServiceUpdater extends Updater{ private Integer postWebhookRetryCount; private Boolean notificationsLogEnabled; - public ServiceUpdater(final String pathSid){ + public ServiceUpdater(final String pathSid) { this.pathSid = pathSid; } - public ServiceUpdater setFriendlyName(final String friendlyName){ + public ServiceUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public ServiceUpdater setDefaultServiceRoleSid(final String defaultServiceRoleSid){ + + public ServiceUpdater setDefaultServiceRoleSid( + final String defaultServiceRoleSid + ) { this.defaultServiceRoleSid = defaultServiceRoleSid; return this; } - public ServiceUpdater setDefaultChannelRoleSid(final String defaultChannelRoleSid){ + + public ServiceUpdater setDefaultChannelRoleSid( + final String defaultChannelRoleSid + ) { this.defaultChannelRoleSid = defaultChannelRoleSid; return this; } - public ServiceUpdater setDefaultChannelCreatorRoleSid(final String defaultChannelCreatorRoleSid){ + + public ServiceUpdater setDefaultChannelCreatorRoleSid( + final String defaultChannelCreatorRoleSid + ) { this.defaultChannelCreatorRoleSid = defaultChannelCreatorRoleSid; return this; } - public ServiceUpdater setReadStatusEnabled(final Boolean readStatusEnabled){ + + public ServiceUpdater setReadStatusEnabled( + final Boolean readStatusEnabled + ) { this.readStatusEnabled = readStatusEnabled; return this; } - public ServiceUpdater setReachabilityEnabled(final Boolean reachabilityEnabled){ + + public ServiceUpdater setReachabilityEnabled( + final Boolean reachabilityEnabled + ) { this.reachabilityEnabled = reachabilityEnabled; return this; } - public ServiceUpdater setTypingIndicatorTimeout(final Integer typingIndicatorTimeout){ + + public ServiceUpdater setTypingIndicatorTimeout( + final Integer typingIndicatorTimeout + ) { this.typingIndicatorTimeout = typingIndicatorTimeout; return this; } - public ServiceUpdater setConsumptionReportInterval(final Integer consumptionReportInterval){ + + public ServiceUpdater setConsumptionReportInterval( + final Integer consumptionReportInterval + ) { this.consumptionReportInterval = consumptionReportInterval; return this; } - public ServiceUpdater setNotificationsNewMessageEnabled(final Boolean notificationsNewMessageEnabled){ + + public ServiceUpdater setNotificationsNewMessageEnabled( + final Boolean notificationsNewMessageEnabled + ) { this.notificationsNewMessageEnabled = notificationsNewMessageEnabled; return this; } - public ServiceUpdater setNotificationsNewMessageTemplate(final String notificationsNewMessageTemplate){ + + public ServiceUpdater setNotificationsNewMessageTemplate( + final String notificationsNewMessageTemplate + ) { this.notificationsNewMessageTemplate = notificationsNewMessageTemplate; return this; } - public ServiceUpdater setNotificationsNewMessageSound(final String notificationsNewMessageSound){ + + public ServiceUpdater setNotificationsNewMessageSound( + final String notificationsNewMessageSound + ) { this.notificationsNewMessageSound = notificationsNewMessageSound; return this; } - public ServiceUpdater setNotificationsNewMessageBadgeCountEnabled(final Boolean notificationsNewMessageBadgeCountEnabled){ - this.notificationsNewMessageBadgeCountEnabled = notificationsNewMessageBadgeCountEnabled; + + public ServiceUpdater setNotificationsNewMessageBadgeCountEnabled( + final Boolean notificationsNewMessageBadgeCountEnabled + ) { + this.notificationsNewMessageBadgeCountEnabled = + notificationsNewMessageBadgeCountEnabled; return this; } - public ServiceUpdater setNotificationsAddedToChannelEnabled(final Boolean notificationsAddedToChannelEnabled){ - this.notificationsAddedToChannelEnabled = notificationsAddedToChannelEnabled; + + public ServiceUpdater setNotificationsAddedToChannelEnabled( + final Boolean notificationsAddedToChannelEnabled + ) { + this.notificationsAddedToChannelEnabled = + notificationsAddedToChannelEnabled; return this; } - public ServiceUpdater setNotificationsAddedToChannelTemplate(final String notificationsAddedToChannelTemplate){ - this.notificationsAddedToChannelTemplate = notificationsAddedToChannelTemplate; + + public ServiceUpdater setNotificationsAddedToChannelTemplate( + final String notificationsAddedToChannelTemplate + ) { + this.notificationsAddedToChannelTemplate = + notificationsAddedToChannelTemplate; return this; } - public ServiceUpdater setNotificationsAddedToChannelSound(final String notificationsAddedToChannelSound){ - this.notificationsAddedToChannelSound = notificationsAddedToChannelSound; + + public ServiceUpdater setNotificationsAddedToChannelSound( + final String notificationsAddedToChannelSound + ) { + this.notificationsAddedToChannelSound = + notificationsAddedToChannelSound; return this; } - public ServiceUpdater setNotificationsRemovedFromChannelEnabled(final Boolean notificationsRemovedFromChannelEnabled){ - this.notificationsRemovedFromChannelEnabled = notificationsRemovedFromChannelEnabled; + + public ServiceUpdater setNotificationsRemovedFromChannelEnabled( + final Boolean notificationsRemovedFromChannelEnabled + ) { + this.notificationsRemovedFromChannelEnabled = + notificationsRemovedFromChannelEnabled; return this; } - public ServiceUpdater setNotificationsRemovedFromChannelTemplate(final String notificationsRemovedFromChannelTemplate){ - this.notificationsRemovedFromChannelTemplate = notificationsRemovedFromChannelTemplate; + + public ServiceUpdater setNotificationsRemovedFromChannelTemplate( + final String notificationsRemovedFromChannelTemplate + ) { + this.notificationsRemovedFromChannelTemplate = + notificationsRemovedFromChannelTemplate; return this; } - public ServiceUpdater setNotificationsRemovedFromChannelSound(final String notificationsRemovedFromChannelSound){ - this.notificationsRemovedFromChannelSound = notificationsRemovedFromChannelSound; + + public ServiceUpdater setNotificationsRemovedFromChannelSound( + final String notificationsRemovedFromChannelSound + ) { + this.notificationsRemovedFromChannelSound = + notificationsRemovedFromChannelSound; return this; } - public ServiceUpdater setNotificationsInvitedToChannelEnabled(final Boolean notificationsInvitedToChannelEnabled){ - this.notificationsInvitedToChannelEnabled = notificationsInvitedToChannelEnabled; + + public ServiceUpdater setNotificationsInvitedToChannelEnabled( + final Boolean notificationsInvitedToChannelEnabled + ) { + this.notificationsInvitedToChannelEnabled = + notificationsInvitedToChannelEnabled; return this; } - public ServiceUpdater setNotificationsInvitedToChannelTemplate(final String notificationsInvitedToChannelTemplate){ - this.notificationsInvitedToChannelTemplate = notificationsInvitedToChannelTemplate; + + public ServiceUpdater setNotificationsInvitedToChannelTemplate( + final String notificationsInvitedToChannelTemplate + ) { + this.notificationsInvitedToChannelTemplate = + notificationsInvitedToChannelTemplate; return this; } - public ServiceUpdater setNotificationsInvitedToChannelSound(final String notificationsInvitedToChannelSound){ - this.notificationsInvitedToChannelSound = notificationsInvitedToChannelSound; + + public ServiceUpdater setNotificationsInvitedToChannelSound( + final String notificationsInvitedToChannelSound + ) { + this.notificationsInvitedToChannelSound = + notificationsInvitedToChannelSound; return this; } - public ServiceUpdater setPreWebhookUrl(final URI preWebhookUrl){ + + public ServiceUpdater setPreWebhookUrl(final URI preWebhookUrl) { this.preWebhookUrl = preWebhookUrl; return this; } - public ServiceUpdater setPreWebhookUrl(final String preWebhookUrl){ + public ServiceUpdater setPreWebhookUrl(final String preWebhookUrl) { return setPreWebhookUrl(Promoter.uriFromString(preWebhookUrl)); } - public ServiceUpdater setPostWebhookUrl(final URI postWebhookUrl){ + + public ServiceUpdater setPostWebhookUrl(final URI postWebhookUrl) { this.postWebhookUrl = postWebhookUrl; return this; } - public ServiceUpdater setPostWebhookUrl(final String postWebhookUrl){ + public ServiceUpdater setPostWebhookUrl(final String postWebhookUrl) { return setPostWebhookUrl(Promoter.uriFromString(postWebhookUrl)); } - public ServiceUpdater setWebhookMethod(final HttpMethod webhookMethod){ + + public ServiceUpdater setWebhookMethod(final HttpMethod webhookMethod) { this.webhookMethod = webhookMethod; return this; } - public ServiceUpdater setWebhookFilters(final List webhookFilters){ + + public ServiceUpdater setWebhookFilters(final List webhookFilters) { this.webhookFilters = webhookFilters; return this; } - public ServiceUpdater setWebhookFilters(final String webhookFilters){ + + public ServiceUpdater setWebhookFilters(final String webhookFilters) { return setWebhookFilters(Promoter.listOfOne(webhookFilters)); } - public ServiceUpdater setLimitsChannelMembers(final Integer limitsChannelMembers){ + + public ServiceUpdater setLimitsChannelMembers( + final Integer limitsChannelMembers + ) { this.limitsChannelMembers = limitsChannelMembers; return this; } - public ServiceUpdater setLimitsUserChannels(final Integer limitsUserChannels){ + + public ServiceUpdater setLimitsUserChannels( + final Integer limitsUserChannels + ) { this.limitsUserChannels = limitsUserChannels; return this; } - public ServiceUpdater setMediaCompatibilityMessage(final String mediaCompatibilityMessage){ + + public ServiceUpdater setMediaCompatibilityMessage( + final String mediaCompatibilityMessage + ) { this.mediaCompatibilityMessage = mediaCompatibilityMessage; return this; } - public ServiceUpdater setPreWebhookRetryCount(final Integer preWebhookRetryCount){ + + public ServiceUpdater setPreWebhookRetryCount( + final Integer preWebhookRetryCount + ) { this.preWebhookRetryCount = preWebhookRetryCount; return this; } - public ServiceUpdater setPostWebhookRetryCount(final Integer postWebhookRetryCount){ + + public ServiceUpdater setPostWebhookRetryCount( + final Integer postWebhookRetryCount + ) { this.postWebhookRetryCount = postWebhookRetryCount; return this; } - public ServiceUpdater setNotificationsLogEnabled(final Boolean notificationsLogEnabled){ + + public ServiceUpdater setNotificationsLogEnabled( + final Boolean notificationsLogEnabled + ) { this.notificationsLogEnabled = notificationsLogEnabled; return this; } @Override - public Service update(final TwilioRestClient client){ + public Service update(final TwilioRestClient client) { String path = "/v2/Services/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -229,132 +327,180 @@ public Service update(final TwilioRestClient client){ return Service.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (defaultServiceRoleSid != null) { - request.addPostParam("DefaultServiceRoleSid", defaultServiceRoleSid); - + request.addPostParam( + "DefaultServiceRoleSid", + defaultServiceRoleSid + ); } if (defaultChannelRoleSid != null) { - request.addPostParam("DefaultChannelRoleSid", defaultChannelRoleSid); - + request.addPostParam( + "DefaultChannelRoleSid", + defaultChannelRoleSid + ); } if (defaultChannelCreatorRoleSid != null) { - request.addPostParam("DefaultChannelCreatorRoleSid", defaultChannelCreatorRoleSid); - + request.addPostParam( + "DefaultChannelCreatorRoleSid", + defaultChannelCreatorRoleSid + ); } if (readStatusEnabled != null) { - request.addPostParam("ReadStatusEnabled", readStatusEnabled.toString()); - + request.addPostParam( + "ReadStatusEnabled", + readStatusEnabled.toString() + ); } if (reachabilityEnabled != null) { - request.addPostParam("ReachabilityEnabled", reachabilityEnabled.toString()); - + request.addPostParam( + "ReachabilityEnabled", + reachabilityEnabled.toString() + ); } if (typingIndicatorTimeout != null) { - request.addPostParam("TypingIndicatorTimeout", typingIndicatorTimeout.toString()); - + request.addPostParam( + "TypingIndicatorTimeout", + typingIndicatorTimeout.toString() + ); } if (consumptionReportInterval != null) { - request.addPostParam("ConsumptionReportInterval", consumptionReportInterval.toString()); - + request.addPostParam( + "ConsumptionReportInterval", + consumptionReportInterval.toString() + ); } if (notificationsNewMessageEnabled != null) { - request.addPostParam("Notifications.NewMessage.Enabled", notificationsNewMessageEnabled.toString()); - + request.addPostParam( + "Notifications.NewMessage.Enabled", + notificationsNewMessageEnabled.toString() + ); } if (notificationsNewMessageTemplate != null) { - request.addPostParam("Notifications.NewMessage.Template", notificationsNewMessageTemplate); - + request.addPostParam( + "Notifications.NewMessage.Template", + notificationsNewMessageTemplate + ); } if (notificationsNewMessageSound != null) { - request.addPostParam("Notifications.NewMessage.Sound", notificationsNewMessageSound); - + request.addPostParam( + "Notifications.NewMessage.Sound", + notificationsNewMessageSound + ); } if (notificationsNewMessageBadgeCountEnabled != null) { - request.addPostParam("Notifications.NewMessage.BadgeCountEnabled", notificationsNewMessageBadgeCountEnabled.toString()); - + request.addPostParam( + "Notifications.NewMessage.BadgeCountEnabled", + notificationsNewMessageBadgeCountEnabled.toString() + ); } if (notificationsAddedToChannelEnabled != null) { - request.addPostParam("Notifications.AddedToChannel.Enabled", notificationsAddedToChannelEnabled.toString()); - + request.addPostParam( + "Notifications.AddedToChannel.Enabled", + notificationsAddedToChannelEnabled.toString() + ); } if (notificationsAddedToChannelTemplate != null) { - request.addPostParam("Notifications.AddedToChannel.Template", notificationsAddedToChannelTemplate); - + request.addPostParam( + "Notifications.AddedToChannel.Template", + notificationsAddedToChannelTemplate + ); } if (notificationsAddedToChannelSound != null) { - request.addPostParam("Notifications.AddedToChannel.Sound", notificationsAddedToChannelSound); - + request.addPostParam( + "Notifications.AddedToChannel.Sound", + notificationsAddedToChannelSound + ); } if (notificationsRemovedFromChannelEnabled != null) { - request.addPostParam("Notifications.RemovedFromChannel.Enabled", notificationsRemovedFromChannelEnabled.toString()); - + request.addPostParam( + "Notifications.RemovedFromChannel.Enabled", + notificationsRemovedFromChannelEnabled.toString() + ); } if (notificationsRemovedFromChannelTemplate != null) { - request.addPostParam("Notifications.RemovedFromChannel.Template", notificationsRemovedFromChannelTemplate); - + request.addPostParam( + "Notifications.RemovedFromChannel.Template", + notificationsRemovedFromChannelTemplate + ); } if (notificationsRemovedFromChannelSound != null) { - request.addPostParam("Notifications.RemovedFromChannel.Sound", notificationsRemovedFromChannelSound); - + request.addPostParam( + "Notifications.RemovedFromChannel.Sound", + notificationsRemovedFromChannelSound + ); } if (notificationsInvitedToChannelEnabled != null) { - request.addPostParam("Notifications.InvitedToChannel.Enabled", notificationsInvitedToChannelEnabled.toString()); - + request.addPostParam( + "Notifications.InvitedToChannel.Enabled", + notificationsInvitedToChannelEnabled.toString() + ); } if (notificationsInvitedToChannelTemplate != null) { - request.addPostParam("Notifications.InvitedToChannel.Template", notificationsInvitedToChannelTemplate); - + request.addPostParam( + "Notifications.InvitedToChannel.Template", + notificationsInvitedToChannelTemplate + ); } if (notificationsInvitedToChannelSound != null) { - request.addPostParam("Notifications.InvitedToChannel.Sound", notificationsInvitedToChannelSound); - + request.addPostParam( + "Notifications.InvitedToChannel.Sound", + notificationsInvitedToChannelSound + ); } if (preWebhookUrl != null) { request.addPostParam("PreWebhookUrl", preWebhookUrl.toString()); - } if (postWebhookUrl != null) { request.addPostParam("PostWebhookUrl", postWebhookUrl.toString()); - } if (webhookMethod != null) { request.addPostParam("WebhookMethod", webhookMethod.toString()); - } if (webhookFilters != null) { for (String prop : webhookFilters) { request.addPostParam("WebhookFilters", prop); } - } if (limitsChannelMembers != null) { - request.addPostParam("Limits.ChannelMembers", limitsChannelMembers.toString()); - + request.addPostParam( + "Limits.ChannelMembers", + limitsChannelMembers.toString() + ); } if (limitsUserChannels != null) { - request.addPostParam("Limits.UserChannels", limitsUserChannels.toString()); - + request.addPostParam( + "Limits.UserChannels", + limitsUserChannels.toString() + ); } if (mediaCompatibilityMessage != null) { - request.addPostParam("Media.CompatibilityMessage", mediaCompatibilityMessage); - + request.addPostParam( + "Media.CompatibilityMessage", + mediaCompatibilityMessage + ); } if (preWebhookRetryCount != null) { - request.addPostParam("PreWebhookRetryCount", preWebhookRetryCount.toString()); - + request.addPostParam( + "PreWebhookRetryCount", + preWebhookRetryCount.toString() + ); } if (postWebhookRetryCount != null) { - request.addPostParam("PostWebhookRetryCount", postWebhookRetryCount.toString()); - + request.addPostParam( + "PostWebhookRetryCount", + postWebhookRetryCount.toString() + ); } if (notificationsLogEnabled != null) { - request.addPostParam("Notifications.LogEnabled", notificationsLogEnabled.toString()); - + request.addPostParam( + "Notifications.LogEnabled", + notificationsLogEnabled.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/chat/v2/service/Binding.java b/src/main/java/com/twilio/rest/chat/v2/service/Binding.java index f38fb6ebc4..49c6da9bb0 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/Binding.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/Binding.java @@ -24,48 +24,53 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.List; import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Binding extends Resource { + private static final long serialVersionUID = 223064407729885L; - public static BindingDeleter deleter(final String pathServiceSid, final String pathSid){ + public static BindingDeleter deleter( + final String pathServiceSid, + final String pathSid + ) { return new BindingDeleter(pathServiceSid, pathSid); } - public static BindingFetcher fetcher(final String pathServiceSid, final String pathSid){ + public static BindingFetcher fetcher( + final String pathServiceSid, + final String pathSid + ) { return new BindingFetcher(pathServiceSid, pathSid); } - public static BindingReader reader(final String pathServiceSid){ + public static BindingReader reader(final String pathServiceSid) { return new BindingReader(pathServiceSid); } /** - * Converts a JSON String into a Binding object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Binding object represented by the provided JSON - */ - public static Binding fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Binding object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Binding object represented by the provided JSON + */ + public static Binding fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Binding.class); @@ -77,14 +82,17 @@ public static Binding fromJson(final String json, final ObjectMapper objectMappe } /** - * Converts a JSON InputStream into a Binding object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Binding object represented by the provided JSON - */ - public static Binding fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Binding object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Binding object represented by the provided JSON + */ + public static Binding fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Binding.class); @@ -94,6 +102,7 @@ public static Binding fromJson(final InputStream json, final ObjectMapper object throw new ApiConnectionException(e.getMessage(), e); } } + public enum BindingType { GCM("gcm"), APN("apn"), @@ -130,41 +139,18 @@ public static BindingType forValue(final String value) { @JsonCreator private Binding( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("endpoint") - final String endpoint, - - @JsonProperty("identity") - final String identity, - - @JsonProperty("credential_sid") - final String credentialSid, - - @JsonProperty("binding_type") - final Binding.BindingType bindingType, - - @JsonProperty("message_types") - final List messageTypes, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("endpoint") final String endpoint, + @JsonProperty("identity") final String identity, + @JsonProperty("credential_sid") final String credentialSid, + @JsonProperty("binding_type") final Binding.BindingType bindingType, + @JsonProperty("message_types") final List messageTypes, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.sid = sid; this.accountSid = accountSid; @@ -180,46 +166,57 @@ private Binding( this.links = links; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getEndpoint() { - return this.endpoint; - } - public final String getIdentity() { - return this.identity; - } - public final String getCredentialSid() { - return this.credentialSid; - } - public final Binding.BindingType getBindingType() { - return this.bindingType; - } - public final List getMessageTypes() { - return this.messageTypes; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getEndpoint() { + return this.endpoint; + } + + public final String getIdentity() { + return this.identity; + } + + public final String getCredentialSid() { + return this.credentialSid; + } + + public final Binding.BindingType getBindingType() { + return this.bindingType; + } + + public final List getMessageTypes() { + return this.messageTypes; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -229,13 +226,37 @@ public boolean equals(final Object o) { Binding other = (Binding) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(endpoint, other.endpoint) && Objects.equals(identity, other.identity) && Objects.equals(credentialSid, other.credentialSid) && Objects.equals(bindingType, other.bindingType) && Objects.equals(messageTypes, other.messageTypes) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(endpoint, other.endpoint) && + Objects.equals(identity, other.identity) && + Objects.equals(credentialSid, other.credentialSid) && + Objects.equals(bindingType, other.bindingType) && + Objects.equals(messageTypes, other.messageTypes) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, serviceSid, dateCreated, dateUpdated, endpoint, identity, credentialSid, bindingType, messageTypes, url, links); + return Objects.hash( + sid, + accountSid, + serviceSid, + dateCreated, + dateUpdated, + endpoint, + identity, + credentialSid, + bindingType, + messageTypes, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/chat/v2/service/BindingDeleter.java b/src/main/java/com/twilio/rest/chat/v2/service/BindingDeleter.java index 47c8d138a7..8dd94bb63b 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/BindingDeleter.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/BindingDeleter.java @@ -24,24 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class BindingDeleter extends Deleter { + private String pathServiceSid; private String pathSid; - public BindingDeleter(final String pathServiceSid, final String pathSid){ + public BindingDeleter(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v2/Services/{ServiceSid}/Bindings/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +53,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Binding delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Binding delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/chat/v2/service/BindingFetcher.java b/src/main/java/com/twilio/rest/chat/v2/service/BindingFetcher.java index 85ff0d5f95..48e3710681 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/BindingFetcher.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/BindingFetcher.java @@ -24,25 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class BindingFetcher extends Fetcher { + private String pathServiceSid; private String pathSid; - public BindingFetcher(final String pathServiceSid, final String pathSid){ + public BindingFetcher(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - @Override public Binding fetch(final TwilioRestClient client) { String path = "/v2/Services/{ServiceSid}/Bindings/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,9 +53,14 @@ public Binding fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Binding fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Binding fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/chat/v2/service/BindingReader.java b/src/main/java/com/twilio/rest/chat/v2/service/BindingReader.java index a09ab3c2d9..2f5bcd4b07 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/BindingReader.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/BindingReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.chat.v2.service; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.converter.Promoter; @@ -25,36 +26,40 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - import java.util.List; - public class BindingReader extends Reader { + private String pathServiceSid; private List bindingType; private List identity; private Integer pageSize; - public BindingReader(final String pathServiceSid){ + public BindingReader(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - public BindingReader setBindingType(final List bindingType){ + public BindingReader setBindingType( + final List bindingType + ) { this.bindingType = bindingType; return this; } - public BindingReader setBindingType(final Binding.BindingType bindingType){ + + public BindingReader setBindingType(final Binding.BindingType bindingType) { return setBindingType(Promoter.listOfOne(bindingType)); } - public BindingReader setIdentity(final List identity){ + + public BindingReader setIdentity(final List identity) { this.identity = identity; return this; } - public BindingReader setIdentity(final String identity){ + + public BindingReader setIdentity(final String identity) { return setIdentity(Promoter.listOfOne(identity)); } - public BindingReader setPageSize(final Integer pageSize){ + + public BindingReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -66,7 +71,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v2/Services/{ServiceSid}/Bindings"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -78,13 +87,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Binding read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Binding read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -100,7 +117,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reques } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.CHAT.toString()) @@ -108,9 +128,11 @@ public Page previousPage(final Page page, final TwilioRestClie return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.CHAT.toString()) @@ -119,14 +141,15 @@ public Page nextPage(final Page page, final TwilioRestClient c } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (bindingType != null) { for (Binding.BindingType prop : bindingType) { @@ -139,11 +162,10 @@ private void addQueryParams(final Request request) { } } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/chat/v2/service/Channel.java b/src/main/java/com/twilio/rest/chat/v2/service/Channel.java index f236177016..b31509cba9 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/Channel.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/Channel.java @@ -24,55 +24,63 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Channel extends Resource { + private static final long serialVersionUID = 188288773259274L; - public static ChannelCreator creator(final String pathServiceSid){ + public static ChannelCreator creator(final String pathServiceSid) { return new ChannelCreator(pathServiceSid); } - public static ChannelDeleter deleter(final String pathServiceSid, final String pathSid){ + public static ChannelDeleter deleter( + final String pathServiceSid, + final String pathSid + ) { return new ChannelDeleter(pathServiceSid, pathSid); } - public static ChannelFetcher fetcher(final String pathServiceSid, final String pathSid){ + public static ChannelFetcher fetcher( + final String pathServiceSid, + final String pathSid + ) { return new ChannelFetcher(pathServiceSid, pathSid); } - public static ChannelReader reader(final String pathServiceSid){ + public static ChannelReader reader(final String pathServiceSid) { return new ChannelReader(pathServiceSid); } - public static ChannelUpdater updater(final String pathServiceSid, final String pathSid){ + public static ChannelUpdater updater( + final String pathServiceSid, + final String pathSid + ) { return new ChannelUpdater(pathServiceSid, pathSid); } /** - * Converts a JSON String into a Channel object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Channel object represented by the provided JSON - */ - public static Channel fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Channel object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Channel object represented by the provided JSON + */ + public static Channel fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Channel.class); @@ -84,14 +92,17 @@ public static Channel fromJson(final String json, final ObjectMapper objectMappe } /** - * Converts a JSON InputStream into a Channel object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Channel object represented by the provided JSON - */ - public static Channel fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Channel object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Channel object represented by the provided JSON + */ + public static Channel fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Channel.class); @@ -101,6 +112,7 @@ public static Channel fromJson(final InputStream json, final ObjectMapper object throw new ApiConnectionException(e.getMessage(), e); } } + public enum ChannelType { PUBLIC("public"), PRIVATE("private"); @@ -120,6 +132,7 @@ public static ChannelType forValue(final String value) { return Promoter.enumFromString(value, ChannelType.values()); } } + public enum WebhookEnabledType { TRUE("true"), FALSE("false"); @@ -157,47 +170,20 @@ public static WebhookEnabledType forValue(final String value) { @JsonCreator private Channel( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("unique_name") - final String uniqueName, - - @JsonProperty("attributes") - final String attributes, - - @JsonProperty("type") - final Channel.ChannelType type, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("created_by") - final String createdBy, - - @JsonProperty("members_count") - final Integer membersCount, - - @JsonProperty("messages_count") - final Integer messagesCount, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("attributes") final String attributes, + @JsonProperty("type") final Channel.ChannelType type, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("created_by") final String createdBy, + @JsonProperty("members_count") final Integer membersCount, + @JsonProperty("messages_count") final Integer messagesCount, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.sid = sid; this.accountSid = accountSid; @@ -215,52 +201,65 @@ private Channel( this.links = links; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getUniqueName() { - return this.uniqueName; - } - public final String getAttributes() { - return this.attributes; - } - public final Channel.ChannelType getType() { - return this.type; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getCreatedBy() { - return this.createdBy; - } - public final Integer getMembersCount() { - return this.membersCount; - } - public final Integer getMessagesCount() { - return this.messagesCount; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getUniqueName() { + return this.uniqueName; + } + + public final String getAttributes() { + return this.attributes; + } + + public final Channel.ChannelType getType() { + return this.type; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getCreatedBy() { + return this.createdBy; + } + + public final Integer getMembersCount() { + return this.membersCount; + } + + public final Integer getMessagesCount() { + return this.messagesCount; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -270,13 +269,41 @@ public boolean equals(final Object o) { Channel other = (Channel) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(uniqueName, other.uniqueName) && Objects.equals(attributes, other.attributes) && Objects.equals(type, other.type) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(createdBy, other.createdBy) && Objects.equals(membersCount, other.membersCount) && Objects.equals(messagesCount, other.messagesCount) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(attributes, other.attributes) && + Objects.equals(type, other.type) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(createdBy, other.createdBy) && + Objects.equals(membersCount, other.membersCount) && + Objects.equals(messagesCount, other.messagesCount) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, serviceSid, friendlyName, uniqueName, attributes, type, dateCreated, dateUpdated, createdBy, membersCount, messagesCount, url, links); + return Objects.hash( + sid, + accountSid, + serviceSid, + friendlyName, + uniqueName, + attributes, + type, + dateCreated, + dateUpdated, + createdBy, + membersCount, + messagesCount, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/chat/v2/service/ChannelCreator.java b/src/main/java/com/twilio/rest/chat/v2/service/ChannelCreator.java index 7f23f3c7af..ae43fd577a 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/ChannelCreator.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/ChannelCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.chat.v2.service; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -25,10 +26,8 @@ import com.twilio.rest.Domains; import java.time.ZonedDateTime; +public class ChannelCreator extends Creator { - - -public class ChannelCreator extends Creator{ private String pathServiceSid; private Channel.WebhookEnabledType xTwilioWebhookEnabled; private String friendlyName; @@ -43,57 +42,76 @@ public ChannelCreator(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - public ChannelCreator setXTwilioWebhookEnabled(final Channel.WebhookEnabledType xTwilioWebhookEnabled){ + public ChannelCreator setXTwilioWebhookEnabled( + final Channel.WebhookEnabledType xTwilioWebhookEnabled + ) { this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; return this; } - public ChannelCreator setFriendlyName(final String friendlyName){ + + public ChannelCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public ChannelCreator setUniqueName(final String uniqueName){ + + public ChannelCreator setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - public ChannelCreator setAttributes(final String attributes){ + + public ChannelCreator setAttributes(final String attributes) { this.attributes = attributes; return this; } - public ChannelCreator setType(final Channel.ChannelType type){ + + public ChannelCreator setType(final Channel.ChannelType type) { this.type = type; return this; } - public ChannelCreator setDateCreated(final ZonedDateTime dateCreated){ + + public ChannelCreator setDateCreated(final ZonedDateTime dateCreated) { this.dateCreated = dateCreated; return this; } - public ChannelCreator setDateUpdated(final ZonedDateTime dateUpdated){ + + public ChannelCreator setDateUpdated(final ZonedDateTime dateUpdated) { this.dateUpdated = dateUpdated; return this; } - public ChannelCreator setCreatedBy(final String createdBy){ + + public ChannelCreator setCreatedBy(final String createdBy) { this.createdBy = createdBy; return this; } @Override - public Channel create(final TwilioRestClient client){ + public Channel create(final TwilioRestClient client) { String path = "/v2/Services/{ServiceSid}/Channels"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); addHeaderParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Channel creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Channel creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -102,40 +120,43 @@ public Channel create(final TwilioRestClient client){ return Channel.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (uniqueName != null) { request.addPostParam("UniqueName", uniqueName); - } if (attributes != null) { request.addPostParam("Attributes", attributes); - } if (type != null) { request.addPostParam("Type", type.toString()); - } if (dateCreated != null) { - request.addPostParam("DateCreated", dateCreated.toInstant().toString()); - + request.addPostParam( + "DateCreated", + dateCreated.toInstant().toString() + ); } if (dateUpdated != null) { - request.addPostParam("DateUpdated", dateUpdated.toInstant().toString()); - + request.addPostParam( + "DateUpdated", + dateUpdated.toInstant().toString() + ); } if (createdBy != null) { request.addPostParam("CreatedBy", createdBy); - } } + private void addHeaderParams(final Request request) { if (xTwilioWebhookEnabled != null) { - request.addHeaderParam("X-Twilio-Webhook-Enabled", xTwilioWebhookEnabled.toString()); - + request.addHeaderParam( + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/chat/v2/service/ChannelDeleter.java b/src/main/java/com/twilio/rest/chat/v2/service/ChannelDeleter.java index bdd53aa719..28bf7cee90 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/ChannelDeleter.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/ChannelDeleter.java @@ -24,19 +24,20 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class ChannelDeleter extends Deleter { + private String pathServiceSid; private String pathSid; private Channel.WebhookEnabledType xTwilioWebhookEnabled; - public ChannelDeleter(final String pathServiceSid, final String pathSid){ + public ChannelDeleter(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - public ChannelDeleter setXTwilioWebhookEnabled(final Channel.WebhookEnabledType xTwilioWebhookEnabled){ + public ChannelDeleter setXTwilioWebhookEnabled( + final Channel.WebhookEnabledType xTwilioWebhookEnabled + ) { this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; return this; } @@ -45,8 +46,12 @@ public ChannelDeleter setXTwilioWebhookEnabled(final Channel.WebhookEnabledType public boolean delete(final TwilioRestClient client) { String path = "/v2/Services/{ServiceSid}/Channels/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -57,9 +62,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Channel delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Channel delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -67,10 +77,13 @@ public boolean delete(final TwilioRestClient client) { } return response.getStatusCode() == 204; } + private void addHeaderParams(final Request request) { if (xTwilioWebhookEnabled != null) { - request.addHeaderParam("X-Twilio-Webhook-Enabled", xTwilioWebhookEnabled.toString()); - + request.addHeaderParam( + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/chat/v2/service/ChannelFetcher.java b/src/main/java/com/twilio/rest/chat/v2/service/ChannelFetcher.java index 7da935c87e..725af2164d 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/ChannelFetcher.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/ChannelFetcher.java @@ -24,25 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class ChannelFetcher extends Fetcher { + private String pathServiceSid; private String pathSid; - public ChannelFetcher(final String pathServiceSid, final String pathSid){ + public ChannelFetcher(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - @Override public Channel fetch(final TwilioRestClient client) { String path = "/v2/Services/{ServiceSid}/Channels/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,9 +53,14 @@ public Channel fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Channel fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Channel fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/chat/v2/service/ChannelReader.java b/src/main/java/com/twilio/rest/chat/v2/service/ChannelReader.java index 43a4535326..ab333afd6e 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/ChannelReader.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/ChannelReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.chat.v2.service; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.converter.Promoter; @@ -25,28 +26,28 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - import java.util.List; - public class ChannelReader extends Reader { + private String pathServiceSid; private List type; private Integer pageSize; - public ChannelReader(final String pathServiceSid){ + public ChannelReader(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - public ChannelReader setType(final List type){ + public ChannelReader setType(final List type) { this.type = type; return this; } - public ChannelReader setType(final Channel.ChannelType type){ + + public ChannelReader setType(final Channel.ChannelType type) { return setType(Promoter.listOfOne(type)); } - public ChannelReader setPageSize(final Integer pageSize){ + + public ChannelReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -58,7 +59,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v2/Services/{ServiceSid}/Channels"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -70,13 +75,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Channel read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Channel read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -92,7 +105,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reques } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.CHAT.toString()) @@ -100,9 +116,11 @@ public Page previousPage(final Page page, final TwilioRestClie return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.CHAT.toString()) @@ -111,14 +129,15 @@ public Page nextPage(final Page page, final TwilioRestClient c } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (type != null) { for (Channel.ChannelType prop : type) { @@ -126,11 +145,10 @@ private void addQueryParams(final Request request) { } } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/chat/v2/service/ChannelUpdater.java b/src/main/java/com/twilio/rest/chat/v2/service/ChannelUpdater.java index aa9b8023aa..0caf1bb57c 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/ChannelUpdater.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/ChannelUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.chat.v2.service; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -23,12 +24,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.time.ZonedDateTime; +public class ChannelUpdater extends Updater { - -public class ChannelUpdater extends Updater{ private String pathServiceSid; private String pathSid; private Channel.WebhookEnabledType xTwilioWebhookEnabled; @@ -39,59 +38,77 @@ public class ChannelUpdater extends Updater{ private ZonedDateTime dateUpdated; private String createdBy; - public ChannelUpdater(final String pathServiceSid, final String pathSid){ + public ChannelUpdater(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - public ChannelUpdater setXTwilioWebhookEnabled(final Channel.WebhookEnabledType xTwilioWebhookEnabled){ + public ChannelUpdater setXTwilioWebhookEnabled( + final Channel.WebhookEnabledType xTwilioWebhookEnabled + ) { this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; return this; } - public ChannelUpdater setFriendlyName(final String friendlyName){ + + public ChannelUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public ChannelUpdater setUniqueName(final String uniqueName){ + + public ChannelUpdater setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - public ChannelUpdater setAttributes(final String attributes){ + + public ChannelUpdater setAttributes(final String attributes) { this.attributes = attributes; return this; } - public ChannelUpdater setDateCreated(final ZonedDateTime dateCreated){ + + public ChannelUpdater setDateCreated(final ZonedDateTime dateCreated) { this.dateCreated = dateCreated; return this; } - public ChannelUpdater setDateUpdated(final ZonedDateTime dateUpdated){ + + public ChannelUpdater setDateUpdated(final ZonedDateTime dateUpdated) { this.dateUpdated = dateUpdated; return this; } - public ChannelUpdater setCreatedBy(final String createdBy){ + + public ChannelUpdater setCreatedBy(final String createdBy) { this.createdBy = createdBy; return this; } @Override - public Channel update(final TwilioRestClient client){ + public Channel update(final TwilioRestClient client) { String path = "/v2/Services/{ServiceSid}/Channels/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); addHeaderParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Channel update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Channel update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -100,36 +117,40 @@ public Channel update(final TwilioRestClient client){ return Channel.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (uniqueName != null) { request.addPostParam("UniqueName", uniqueName); - } if (attributes != null) { request.addPostParam("Attributes", attributes); - } if (dateCreated != null) { - request.addPostParam("DateCreated", dateCreated.toInstant().toString()); - + request.addPostParam( + "DateCreated", + dateCreated.toInstant().toString() + ); } if (dateUpdated != null) { - request.addPostParam("DateUpdated", dateUpdated.toInstant().toString()); - + request.addPostParam( + "DateUpdated", + dateUpdated.toInstant().toString() + ); } if (createdBy != null) { request.addPostParam("CreatedBy", createdBy); - } } + private void addHeaderParams(final Request request) { if (xTwilioWebhookEnabled != null) { - request.addHeaderParam("X-Twilio-Webhook-Enabled", xTwilioWebhookEnabled.toString()); - + request.addHeaderParam( + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/chat/v2/service/Role.java b/src/main/java/com/twilio/rest/chat/v2/service/Role.java index 4b9d1470d6..52e7c0fccd 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/Role.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/Role.java @@ -24,54 +24,68 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.List; import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Role extends Resource { + private static final long serialVersionUID = 252065084446046L; - public static RoleCreator creator(final String pathServiceSid, final String friendlyName, final Role.RoleType type, final List permission){ + public static RoleCreator creator( + final String pathServiceSid, + final String friendlyName, + final Role.RoleType type, + final List permission + ) { return new RoleCreator(pathServiceSid, friendlyName, type, permission); } - public static RoleDeleter deleter(final String pathServiceSid, final String pathSid){ + public static RoleDeleter deleter( + final String pathServiceSid, + final String pathSid + ) { return new RoleDeleter(pathServiceSid, pathSid); } - public static RoleFetcher fetcher(final String pathServiceSid, final String pathSid){ + public static RoleFetcher fetcher( + final String pathServiceSid, + final String pathSid + ) { return new RoleFetcher(pathServiceSid, pathSid); } - public static RoleReader reader(final String pathServiceSid){ + public static RoleReader reader(final String pathServiceSid) { return new RoleReader(pathServiceSid); } - public static RoleUpdater updater(final String pathServiceSid, final String pathSid, final List permission){ + public static RoleUpdater updater( + final String pathServiceSid, + final String pathSid, + final List permission + ) { return new RoleUpdater(pathServiceSid, pathSid, permission); } /** - * Converts a JSON String into a Role object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Role object represented by the provided JSON - */ - public static Role fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Role object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Role object represented by the provided JSON + */ + public static Role fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Role.class); @@ -83,14 +97,17 @@ public static Role fromJson(final String json, final ObjectMapper objectMapper) } /** - * Converts a JSON InputStream into a Role object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Role object represented by the provided JSON - */ - public static Role fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Role object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Role object represented by the provided JSON + */ + public static Role fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Role.class); @@ -100,6 +117,7 @@ public static Role fromJson(final InputStream json, final ObjectMapper objectMap throw new ApiConnectionException(e.getMessage(), e); } } + public enum RoleType { CHANNEL("channel"), DEPLOYMENT("deployment"); @@ -132,32 +150,15 @@ public static RoleType forValue(final String value) { @JsonCreator private Role( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("type") - final Role.RoleType type, - - @JsonProperty("permissions") - final List permissions, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("type") final Role.RoleType type, + @JsonProperty("permissions") final List permissions, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url ) { this.sid = sid; this.accountSid = accountSid; @@ -170,37 +171,45 @@ private Role( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final Role.RoleType getType() { - return this.type; - } - public final List getPermissions() { - return this.permissions; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final Role.RoleType getType() { + return this.type; + } + + public final List getPermissions() { + return this.permissions; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -210,13 +219,31 @@ public boolean equals(final Object o) { Role other = (Role) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(type, other.type) && Objects.equals(permissions, other.permissions) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(type, other.type) && + Objects.equals(permissions, other.permissions) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, serviceSid, friendlyName, type, permissions, dateCreated, dateUpdated, url); + return Objects.hash( + sid, + accountSid, + serviceSid, + friendlyName, + type, + permissions, + dateCreated, + dateUpdated, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/chat/v2/service/RoleCreator.java b/src/main/java/com/twilio/rest/chat/v2/service/RoleCreator.java index 87b88396e6..190c42dd9f 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/RoleCreator.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/RoleCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.chat.v2.service; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -25,60 +26,81 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.util.List; - import java.util.List; +public class RoleCreator extends Creator { - -public class RoleCreator extends Creator{ private String pathServiceSid; private String friendlyName; private Role.RoleType type; private List permission; - public RoleCreator(final String pathServiceSid, final String friendlyName, final Role.RoleType type, final List permission) { + public RoleCreator( + final String pathServiceSid, + final String friendlyName, + final Role.RoleType type, + final List permission + ) { this.pathServiceSid = pathServiceSid; this.friendlyName = friendlyName; this.type = type; this.permission = permission; } - public RoleCreator setFriendlyName(final String friendlyName){ + public RoleCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public RoleCreator setType(final Role.RoleType type){ + + public RoleCreator setType(final Role.RoleType type) { this.type = type; return this; } - public RoleCreator setPermission(final List permission){ + + public RoleCreator setPermission(final List permission) { this.permission = permission; return this; } - public RoleCreator setPermission(final String permission){ + + public RoleCreator setPermission(final String permission) { return setPermission(Promoter.listOfOne(permission)); } @Override - public Role create(final TwilioRestClient client){ + public Role create(final TwilioRestClient client) { String path = "/v2/Services/{ServiceSid}/Roles"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"FriendlyName"+"}", this.friendlyName.toString()); - path = path.replace("{"+"Type"+"}", this.type.toString()); - path = path.replace("{"+"Permission"+"}", this.permission.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "FriendlyName" + "}", + this.friendlyName.toString() + ); + path = path.replace("{" + "Type" + "}", this.type.toString()); + path = + path.replace("{" + "Permission" + "}", this.permission.toString()); Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Role creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Role creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -87,20 +109,18 @@ public Role create(final TwilioRestClient client){ return Role.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (type != null) { request.addPostParam("Type", type.toString()); - } if (permission != null) { for (String prop : permission) { request.addPostParam("Permission", prop); } - } } } diff --git a/src/main/java/com/twilio/rest/chat/v2/service/RoleDeleter.java b/src/main/java/com/twilio/rest/chat/v2/service/RoleDeleter.java index e29e9ce11e..c2de53d7af 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/RoleDeleter.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/RoleDeleter.java @@ -24,24 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class RoleDeleter extends Deleter { + private String pathServiceSid; private String pathSid; - public RoleDeleter(final String pathServiceSid, final String pathSid){ + public RoleDeleter(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v2/Services/{ServiceSid}/Roles/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +53,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Role delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Role delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/chat/v2/service/RoleFetcher.java b/src/main/java/com/twilio/rest/chat/v2/service/RoleFetcher.java index c70e0ca3a2..46289b6beb 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/RoleFetcher.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/RoleFetcher.java @@ -24,25 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class RoleFetcher extends Fetcher { + private String pathServiceSid; private String pathSid; - public RoleFetcher(final String pathServiceSid, final String pathSid){ + public RoleFetcher(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - @Override public Role fetch(final TwilioRestClient client) { String path = "/v2/Services/{ServiceSid}/Roles/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,9 +53,14 @@ public Role fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Role fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Role fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/chat/v2/service/RoleReader.java b/src/main/java/com/twilio/rest/chat/v2/service/RoleReader.java index 573af635f4..81f1d0fba0 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/RoleReader.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/RoleReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.chat.v2.service; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,19 +25,17 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class RoleReader extends Reader { + private String pathServiceSid; private Integer pageSize; - public RoleReader(final String pathServiceSid){ + public RoleReader(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - public RoleReader setPageSize(final Integer pageSize){ + public RoleReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -48,7 +47,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v2/Services/{ServiceSid}/Roles"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -60,13 +63,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Role read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Role read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +93,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request r } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.CHAT.toString()) @@ -90,9 +104,11 @@ public Page previousPage(final Page page, final TwilioRestClient cli return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.CHAT.toString()) @@ -101,21 +117,21 @@ public Page nextPage(final Page page, final TwilioRestClient client) } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/chat/v2/service/RoleUpdater.java b/src/main/java/com/twilio/rest/chat/v2/service/RoleUpdater.java index 0652d9a179..c34fce808c 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/RoleUpdater.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/RoleUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.chat.v2.service; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -24,49 +25,63 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - import java.util.List; +public class RoleUpdater extends Updater { -public class RoleUpdater extends Updater{ private String pathServiceSid; private String pathSid; private List permission; - public RoleUpdater(final String pathServiceSid, final String pathSid, final List permission){ + public RoleUpdater( + final String pathServiceSid, + final String pathSid, + final List permission + ) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; this.permission = permission; } - public RoleUpdater setPermission(final List permission){ + public RoleUpdater setPermission(final List permission) { this.permission = permission; return this; } - public RoleUpdater setPermission(final String permission){ + + public RoleUpdater setPermission(final String permission) { return setPermission(Promoter.listOfOne(permission)); } @Override - public Role update(final TwilioRestClient client){ + public Role update(final TwilioRestClient client) { String path = "/v2/Services/{ServiceSid}/Roles/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); - path = path.replace("{"+"Permission"+"}", this.permission.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + path = + path.replace("{" + "Permission" + "}", this.permission.toString()); Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Role update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Role update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -75,12 +90,12 @@ public Role update(final TwilioRestClient client){ return Role.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (permission != null) { for (String prop : permission) { request.addPostParam("Permission", prop); } - } } } diff --git a/src/main/java/com/twilio/rest/chat/v2/service/User.java b/src/main/java/com/twilio/rest/chat/v2/service/User.java index 60321a0f56..3fb01d555f 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/User.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/User.java @@ -24,55 +24,66 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class User extends Resource { + private static final long serialVersionUID = 136391609300437L; - public static UserCreator creator(final String pathServiceSid, final String identity){ + public static UserCreator creator( + final String pathServiceSid, + final String identity + ) { return new UserCreator(pathServiceSid, identity); } - public static UserDeleter deleter(final String pathServiceSid, final String pathSid){ + public static UserDeleter deleter( + final String pathServiceSid, + final String pathSid + ) { return new UserDeleter(pathServiceSid, pathSid); } - public static UserFetcher fetcher(final String pathServiceSid, final String pathSid){ + public static UserFetcher fetcher( + final String pathServiceSid, + final String pathSid + ) { return new UserFetcher(pathServiceSid, pathSid); } - public static UserReader reader(final String pathServiceSid){ + public static UserReader reader(final String pathServiceSid) { return new UserReader(pathServiceSid); } - public static UserUpdater updater(final String pathServiceSid, final String pathSid){ + public static UserUpdater updater( + final String pathServiceSid, + final String pathSid + ) { return new UserUpdater(pathServiceSid, pathSid); } /** - * Converts a JSON String into a User object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return User object represented by the provided JSON - */ - public static User fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a User object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return User object represented by the provided JSON + */ + public static User fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, User.class); @@ -84,14 +95,17 @@ public static User fromJson(final String json, final ObjectMapper objectMapper) } /** - * Converts a JSON InputStream into a User object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return User object represented by the provided JSON - */ - public static User fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a User object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return User object represented by the provided JSON + */ + public static User fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, User.class); @@ -101,6 +115,7 @@ public static User fromJson(final InputStream json, final ObjectMapper objectMap throw new ApiConnectionException(e.getMessage(), e); } } + public enum WebhookEnabledType { TRUE("true"), FALSE("false"); @@ -138,47 +153,22 @@ public static WebhookEnabledType forValue(final String value) { @JsonCreator private User( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("attributes") - final String attributes, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("role_sid") - final String roleSid, - - @JsonProperty("identity") - final String identity, - - @JsonProperty("is_online") - final Boolean isOnline, - - @JsonProperty("is_notifiable") - final Boolean isNotifiable, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("joined_channels_count") - final Integer joinedChannelsCount, - - @JsonProperty("links") - final Map links, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("attributes") final String attributes, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("role_sid") final String roleSid, + @JsonProperty("identity") final String identity, + @JsonProperty("is_online") final Boolean isOnline, + @JsonProperty("is_notifiable") final Boolean isNotifiable, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty( + "joined_channels_count" + ) final Integer joinedChannelsCount, + @JsonProperty("links") final Map links, + @JsonProperty("url") final URI url ) { this.sid = sid; this.accountSid = accountSid; @@ -196,52 +186,65 @@ private User( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final String getAttributes() { - return this.attributes; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getRoleSid() { - return this.roleSid; - } - public final String getIdentity() { - return this.identity; - } - public final Boolean getIsOnline() { - return this.isOnline; - } - public final Boolean getIsNotifiable() { - return this.isNotifiable; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final Integer getJoinedChannelsCount() { - return this.joinedChannelsCount; - } - public final Map getLinks() { - return this.links; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final String getAttributes() { + return this.attributes; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getRoleSid() { + return this.roleSid; + } + + public final String getIdentity() { + return this.identity; + } + + public final Boolean getIsOnline() { + return this.isOnline; + } + + public final Boolean getIsNotifiable() { + return this.isNotifiable; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final Integer getJoinedChannelsCount() { + return this.joinedChannelsCount; + } + + public final Map getLinks() { + return this.links; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -251,13 +254,41 @@ public boolean equals(final Object o) { User other = (User) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(attributes, other.attributes) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(roleSid, other.roleSid) && Objects.equals(identity, other.identity) && Objects.equals(isOnline, other.isOnline) && Objects.equals(isNotifiable, other.isNotifiable) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(joinedChannelsCount, other.joinedChannelsCount) && Objects.equals(links, other.links) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(attributes, other.attributes) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(roleSid, other.roleSid) && + Objects.equals(identity, other.identity) && + Objects.equals(isOnline, other.isOnline) && + Objects.equals(isNotifiable, other.isNotifiable) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(joinedChannelsCount, other.joinedChannelsCount) && + Objects.equals(links, other.links) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, serviceSid, attributes, friendlyName, roleSid, identity, isOnline, isNotifiable, dateCreated, dateUpdated, joinedChannelsCount, links, url); + return Objects.hash( + sid, + accountSid, + serviceSid, + attributes, + friendlyName, + roleSid, + identity, + isOnline, + isNotifiable, + dateCreated, + dateUpdated, + joinedChannelsCount, + links, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/chat/v2/service/UserCreator.java b/src/main/java/com/twilio/rest/chat/v2/service/UserCreator.java index ed699a6cb2..f46853fe19 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/UserCreator.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/UserCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.chat.v2.service; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class UserCreator extends Creator { - - -public class UserCreator extends Creator{ private String pathServiceSid; private String identity; private User.WebhookEnabledType xTwilioWebhookEnabled; @@ -40,46 +39,62 @@ public UserCreator(final String pathServiceSid, final String identity) { this.identity = identity; } - public UserCreator setIdentity(final String identity){ + public UserCreator setIdentity(final String identity) { this.identity = identity; return this; } - public UserCreator setXTwilioWebhookEnabled(final User.WebhookEnabledType xTwilioWebhookEnabled){ + + public UserCreator setXTwilioWebhookEnabled( + final User.WebhookEnabledType xTwilioWebhookEnabled + ) { this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; return this; } - public UserCreator setRoleSid(final String roleSid){ + + public UserCreator setRoleSid(final String roleSid) { this.roleSid = roleSid; return this; } - public UserCreator setAttributes(final String attributes){ + + public UserCreator setAttributes(final String attributes) { this.attributes = attributes; return this; } - public UserCreator setFriendlyName(final String friendlyName){ + + public UserCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } @Override - public User create(final TwilioRestClient client){ + public User create(final TwilioRestClient client) { String path = "/v2/Services/{ServiceSid}/Users"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Identity"+"}", this.identity.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Identity" + "}", this.identity.toString()); Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); addHeaderParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("User creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "User creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -88,28 +103,28 @@ public User create(final TwilioRestClient client){ return User.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (identity != null) { request.addPostParam("Identity", identity); - } if (roleSid != null) { request.addPostParam("RoleSid", roleSid); - } if (attributes != null) { request.addPostParam("Attributes", attributes); - } if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } } + private void addHeaderParams(final Request request) { if (xTwilioWebhookEnabled != null) { - request.addHeaderParam("X-Twilio-Webhook-Enabled", xTwilioWebhookEnabled.toString()); - + request.addHeaderParam( + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/chat/v2/service/UserDeleter.java b/src/main/java/com/twilio/rest/chat/v2/service/UserDeleter.java index 9e6b07d979..85ad998016 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/UserDeleter.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/UserDeleter.java @@ -24,24 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class UserDeleter extends Deleter { + private String pathServiceSid; private String pathSid; - public UserDeleter(final String pathServiceSid, final String pathSid){ + public UserDeleter(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v2/Services/{ServiceSid}/Users/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +53,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("User delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "User delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/chat/v2/service/UserFetcher.java b/src/main/java/com/twilio/rest/chat/v2/service/UserFetcher.java index 0a2dcd6e8b..3add33c920 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/UserFetcher.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/UserFetcher.java @@ -24,25 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class UserFetcher extends Fetcher { + private String pathServiceSid; private String pathSid; - public UserFetcher(final String pathServiceSid, final String pathSid){ + public UserFetcher(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - @Override public User fetch(final TwilioRestClient client) { String path = "/v2/Services/{ServiceSid}/Users/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,9 +53,14 @@ public User fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("User fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "User fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/chat/v2/service/UserReader.java b/src/main/java/com/twilio/rest/chat/v2/service/UserReader.java index 511b7a39cf..5efb84e411 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/UserReader.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/UserReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.chat.v2.service; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,19 +25,17 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class UserReader extends Reader { + private String pathServiceSid; private Integer pageSize; - public UserReader(final String pathServiceSid){ + public UserReader(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - public UserReader setPageSize(final Integer pageSize){ + public UserReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -48,7 +47,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v2/Services/{ServiceSid}/Users"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -60,13 +63,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("User read failed: Unable to connect to server"); + throw new ApiConnectionException( + "User read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +93,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request r } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.CHAT.toString()) @@ -90,9 +104,11 @@ public Page previousPage(final Page page, final TwilioRestClient cli return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.CHAT.toString()) @@ -101,21 +117,21 @@ public Page nextPage(final Page page, final TwilioRestClient client) } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/chat/v2/service/UserUpdater.java b/src/main/java/com/twilio/rest/chat/v2/service/UserUpdater.java index ec5f7e206a..ea2d6a2bcd 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/UserUpdater.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/UserUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.chat.v2.service; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class UserUpdater extends Updater { - - -public class UserUpdater extends Updater{ private String pathServiceSid; private String pathSid; private User.WebhookEnabledType xTwilioWebhookEnabled; @@ -35,47 +34,62 @@ public class UserUpdater extends Updater{ private String attributes; private String friendlyName; - public UserUpdater(final String pathServiceSid, final String pathSid){ + public UserUpdater(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - public UserUpdater setXTwilioWebhookEnabled(final User.WebhookEnabledType xTwilioWebhookEnabled){ + public UserUpdater setXTwilioWebhookEnabled( + final User.WebhookEnabledType xTwilioWebhookEnabled + ) { this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; return this; } - public UserUpdater setRoleSid(final String roleSid){ + + public UserUpdater setRoleSid(final String roleSid) { this.roleSid = roleSid; return this; } - public UserUpdater setAttributes(final String attributes){ + + public UserUpdater setAttributes(final String attributes) { this.attributes = attributes; return this; } - public UserUpdater setFriendlyName(final String friendlyName){ + + public UserUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } @Override - public User update(final TwilioRestClient client){ + public User update(final TwilioRestClient client) { String path = "/v2/Services/{ServiceSid}/Users/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); addHeaderParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("User update failed: Unable to connect to server"); + throw new ApiConnectionException( + "User update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -84,24 +98,25 @@ public User update(final TwilioRestClient client){ return User.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (roleSid != null) { request.addPostParam("RoleSid", roleSid); - } if (attributes != null) { request.addPostParam("Attributes", attributes); - } if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } } + private void addHeaderParams(final Request request) { if (xTwilioWebhookEnabled != null) { - request.addHeaderParam("X-Twilio-Webhook-Enabled", xTwilioWebhookEnabled.toString()); - + request.addHeaderParam( + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/chat/v2/service/channel/Invite.java b/src/main/java/com/twilio/rest/chat/v2/service/channel/Invite.java index 92a29026a1..4c079f24d8 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/channel/Invite.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/channel/Invite.java @@ -23,49 +23,63 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Invite extends Resource { + private static final long serialVersionUID = 148273166902210L; - public static InviteCreator creator(final String pathServiceSid, final String pathChannelSid, final String identity){ + public static InviteCreator creator( + final String pathServiceSid, + final String pathChannelSid, + final String identity + ) { return new InviteCreator(pathServiceSid, pathChannelSid, identity); } - public static InviteDeleter deleter(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public static InviteDeleter deleter( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { return new InviteDeleter(pathServiceSid, pathChannelSid, pathSid); } - public static InviteFetcher fetcher(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public static InviteFetcher fetcher( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { return new InviteFetcher(pathServiceSid, pathChannelSid, pathSid); } - public static InviteReader reader(final String pathServiceSid, final String pathChannelSid){ + public static InviteReader reader( + final String pathServiceSid, + final String pathChannelSid + ) { return new InviteReader(pathServiceSid, pathChannelSid); } /** - * Converts a JSON String into a Invite object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Invite object represented by the provided JSON - */ - public static Invite fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Invite object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Invite object represented by the provided JSON + */ + public static Invite fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Invite.class); @@ -77,14 +91,17 @@ public static Invite fromJson(final String json, final ObjectMapper objectMapper } /** - * Converts a JSON InputStream into a Invite object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Invite object represented by the provided JSON - */ - public static Invite fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Invite object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Invite object represented by the provided JSON + */ + public static Invite fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Invite.class); @@ -108,35 +125,16 @@ public static Invite fromJson(final InputStream json, final ObjectMapper objectM @JsonCreator private Invite( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("channel_sid") - final String channelSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("identity") - final String identity, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("role_sid") - final String roleSid, - - @JsonProperty("created_by") - final String createdBy, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("channel_sid") final String channelSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("identity") final String identity, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("role_sid") final String roleSid, + @JsonProperty("created_by") final String createdBy, + @JsonProperty("url") final URI url ) { this.sid = sid; this.accountSid = accountSid; @@ -150,40 +148,49 @@ private Invite( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getChannelSid() { - return this.channelSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final String getIdentity() { - return this.identity; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getRoleSid() { - return this.roleSid; - } - public final String getCreatedBy() { - return this.createdBy; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getChannelSid() { + return this.channelSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final String getIdentity() { + return this.identity; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getRoleSid() { + return this.roleSid; + } + + public final String getCreatedBy() { + return this.createdBy; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -193,13 +200,33 @@ public boolean equals(final Object o) { Invite other = (Invite) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(channelSid, other.channelSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(identity, other.identity) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(roleSid, other.roleSid) && Objects.equals(createdBy, other.createdBy) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(channelSid, other.channelSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(identity, other.identity) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(roleSid, other.roleSid) && + Objects.equals(createdBy, other.createdBy) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, channelSid, serviceSid, identity, dateCreated, dateUpdated, roleSid, createdBy, url); + return Objects.hash( + sid, + accountSid, + channelSid, + serviceSid, + identity, + dateCreated, + dateUpdated, + roleSid, + createdBy, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/chat/v2/service/channel/InviteCreator.java b/src/main/java/com/twilio/rest/chat/v2/service/channel/InviteCreator.java index 8f9d558aeb..2570136953 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/channel/InviteCreator.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/channel/InviteCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.chat.v2.service.channel; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,49 +25,66 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class InviteCreator extends Creator { - - -public class InviteCreator extends Creator{ private String pathServiceSid; private String pathChannelSid; private String identity; private String roleSid; - public InviteCreator(final String pathServiceSid, final String pathChannelSid, final String identity) { + public InviteCreator( + final String pathServiceSid, + final String pathChannelSid, + final String identity + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.identity = identity; } - public InviteCreator setIdentity(final String identity){ + public InviteCreator setIdentity(final String identity) { this.identity = identity; return this; } - public InviteCreator setRoleSid(final String roleSid){ + + public InviteCreator setRoleSid(final String roleSid) { this.roleSid = roleSid; return this; } @Override - public Invite create(final TwilioRestClient client){ + public Invite create(final TwilioRestClient client) { String path = "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Invites"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); - path = path.replace("{"+"Identity"+"}", this.identity.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Identity" + "}", this.identity.toString()); Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Invite creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Invite creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -75,14 +93,13 @@ public Invite create(final TwilioRestClient client){ return Invite.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (identity != null) { request.addPostParam("Identity", identity); - } if (roleSid != null) { request.addPostParam("RoleSid", roleSid); - } } } diff --git a/src/main/java/com/twilio/rest/chat/v2/service/channel/InviteDeleter.java b/src/main/java/com/twilio/rest/chat/v2/service/channel/InviteDeleter.java index fbf31c521d..96ad4d096b 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/channel/InviteDeleter.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/channel/InviteDeleter.java @@ -24,27 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class InviteDeleter extends Deleter { + private String pathServiceSid; private String pathChannelSid; private String pathSid; - public InviteDeleter(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public InviteDeleter( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Invites/{Sid}"; + String path = + "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Invites/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -54,9 +65,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Invite delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Invite delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/chat/v2/service/channel/InviteFetcher.java b/src/main/java/com/twilio/rest/chat/v2/service/channel/InviteFetcher.java index 608ee9d803..383543fb80 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/channel/InviteFetcher.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/channel/InviteFetcher.java @@ -24,28 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class InviteFetcher extends Fetcher { + private String pathServiceSid; private String pathChannelSid; private String pathSid; - public InviteFetcher(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public InviteFetcher( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - @Override public Invite fetch(final TwilioRestClient client) { - String path = "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Invites/{Sid}"; + String path = + "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Invites/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -55,9 +65,14 @@ public Invite fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Invite fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Invite fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/chat/v2/service/channel/InviteReader.java b/src/main/java/com/twilio/rest/chat/v2/service/channel/InviteReader.java index 866bd335f1..cc97a7a4de 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/channel/InviteReader.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/channel/InviteReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.chat.v2.service.channel; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.converter.Promoter; @@ -25,30 +26,33 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - import java.util.List; - public class InviteReader extends Reader { + private String pathServiceSid; private String pathChannelSid; private List identity; private Integer pageSize; - public InviteReader(final String pathServiceSid, final String pathChannelSid){ + public InviteReader( + final String pathServiceSid, + final String pathChannelSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; } - public InviteReader setIdentity(final List identity){ + public InviteReader setIdentity(final List identity) { this.identity = identity; return this; } - public InviteReader setIdentity(final String identity){ + + public InviteReader setIdentity(final String identity) { return setIdentity(Promoter.listOfOne(identity)); } - public InviteReader setPageSize(final Integer pageSize){ + + public InviteReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -60,8 +64,16 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Invites"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -73,13 +85,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Invite read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Invite read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -95,7 +115,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.CHAT.toString()) @@ -103,9 +126,11 @@ public Page previousPage(final Page page, final TwilioRestClient return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.CHAT.toString()) @@ -114,14 +139,15 @@ public Page nextPage(final Page page, final TwilioRestClient cli } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (identity != null) { for (String prop : identity) { @@ -129,11 +155,10 @@ private void addQueryParams(final Request request) { } } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/chat/v2/service/channel/Member.java b/src/main/java/com/twilio/rest/chat/v2/service/channel/Member.java index d542667b15..f7fbd181fb 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/channel/Member.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/channel/Member.java @@ -24,53 +24,71 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Member extends Resource { + private static final long serialVersionUID = 220317594144302L; - public static MemberCreator creator(final String pathServiceSid, final String pathChannelSid, final String identity){ + public static MemberCreator creator( + final String pathServiceSid, + final String pathChannelSid, + final String identity + ) { return new MemberCreator(pathServiceSid, pathChannelSid, identity); } - public static MemberDeleter deleter(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public static MemberDeleter deleter( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { return new MemberDeleter(pathServiceSid, pathChannelSid, pathSid); } - public static MemberFetcher fetcher(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public static MemberFetcher fetcher( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { return new MemberFetcher(pathServiceSid, pathChannelSid, pathSid); } - public static MemberReader reader(final String pathServiceSid, final String pathChannelSid){ + public static MemberReader reader( + final String pathServiceSid, + final String pathChannelSid + ) { return new MemberReader(pathServiceSid, pathChannelSid); } - public static MemberUpdater updater(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public static MemberUpdater updater( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { return new MemberUpdater(pathServiceSid, pathChannelSid, pathSid); } /** - * Converts a JSON String into a Member object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Member object represented by the provided JSON - */ - public static Member fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Member object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Member object represented by the provided JSON + */ + public static Member fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Member.class); @@ -82,14 +100,17 @@ public static Member fromJson(final String json, final ObjectMapper objectMapper } /** - * Converts a JSON InputStream into a Member object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Member object represented by the provided JSON - */ - public static Member fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Member object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Member object represented by the provided JSON + */ + public static Member fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Member.class); @@ -99,6 +120,7 @@ public static Member fromJson(final InputStream json, final ObjectMapper objectM throw new ApiConnectionException(e.getMessage(), e); } } + public enum WebhookEnabledType { TRUE("true"), FALSE("false"); @@ -134,41 +156,22 @@ public static WebhookEnabledType forValue(final String value) { @JsonCreator private Member( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("channel_sid") - final String channelSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("identity") - final String identity, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("role_sid") - final String roleSid, - - @JsonProperty("last_consumed_message_index") - final Integer lastConsumedMessageIndex, - - @JsonProperty("last_consumption_timestamp") - final String lastConsumptionTimestamp, - - @JsonProperty("url") - final URI url, - - @JsonProperty("attributes") - final String attributes + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("channel_sid") final String channelSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("identity") final String identity, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("role_sid") final String roleSid, + @JsonProperty( + "last_consumed_message_index" + ) final Integer lastConsumedMessageIndex, + @JsonProperty( + "last_consumption_timestamp" + ) final String lastConsumptionTimestamp, + @JsonProperty("url") final URI url, + @JsonProperty("attributes") final String attributes ) { this.sid = sid; this.accountSid = accountSid; @@ -179,51 +182,63 @@ private Member( this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); this.roleSid = roleSid; this.lastConsumedMessageIndex = lastConsumedMessageIndex; - this.lastConsumptionTimestamp = DateConverter.iso8601DateTimeFromString(lastConsumptionTimestamp); + this.lastConsumptionTimestamp = + DateConverter.iso8601DateTimeFromString(lastConsumptionTimestamp); this.url = url; this.attributes = attributes; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getChannelSid() { - return this.channelSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final String getIdentity() { - return this.identity; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getRoleSid() { - return this.roleSid; - } - public final Integer getLastConsumedMessageIndex() { - return this.lastConsumedMessageIndex; - } - public final ZonedDateTime getLastConsumptionTimestamp() { - return this.lastConsumptionTimestamp; - } - public final URI getUrl() { - return this.url; - } - public final String getAttributes() { - return this.attributes; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getChannelSid() { + return this.channelSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final String getIdentity() { + return this.identity; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getRoleSid() { + return this.roleSid; + } + + public final Integer getLastConsumedMessageIndex() { + return this.lastConsumedMessageIndex; + } + + public final ZonedDateTime getLastConsumptionTimestamp() { + return this.lastConsumptionTimestamp; + } + + public final URI getUrl() { + return this.url; + } + + public final String getAttributes() { + return this.attributes; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -233,13 +248,43 @@ public boolean equals(final Object o) { Member other = (Member) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(channelSid, other.channelSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(identity, other.identity) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(roleSid, other.roleSid) && Objects.equals(lastConsumedMessageIndex, other.lastConsumedMessageIndex) && Objects.equals(lastConsumptionTimestamp, other.lastConsumptionTimestamp) && Objects.equals(url, other.url) && Objects.equals(attributes, other.attributes) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(channelSid, other.channelSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(identity, other.identity) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(roleSid, other.roleSid) && + Objects.equals( + lastConsumedMessageIndex, + other.lastConsumedMessageIndex + ) && + Objects.equals( + lastConsumptionTimestamp, + other.lastConsumptionTimestamp + ) && + Objects.equals(url, other.url) && + Objects.equals(attributes, other.attributes) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, channelSid, serviceSid, identity, dateCreated, dateUpdated, roleSid, lastConsumedMessageIndex, lastConsumptionTimestamp, url, attributes); + return Objects.hash( + sid, + accountSid, + channelSid, + serviceSid, + identity, + dateCreated, + dateUpdated, + roleSid, + lastConsumedMessageIndex, + lastConsumptionTimestamp, + url, + attributes + ); } - } - diff --git a/src/main/java/com/twilio/rest/chat/v2/service/channel/MemberCreator.java b/src/main/java/com/twilio/rest/chat/v2/service/channel/MemberCreator.java index e617a628b4..7fd176f40c 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/channel/MemberCreator.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/channel/MemberCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.chat.v2.service.channel; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -25,10 +26,8 @@ import com.twilio.rest.Domains; import java.time.ZonedDateTime; +public class MemberCreator extends Creator { - - -public class MemberCreator extends Creator{ private String pathServiceSid; private String pathChannelSid; private String identity; @@ -40,65 +39,96 @@ public class MemberCreator extends Creator{ private ZonedDateTime dateUpdated; private String attributes; - public MemberCreator(final String pathServiceSid, final String pathChannelSid, final String identity) { + public MemberCreator( + final String pathServiceSid, + final String pathChannelSid, + final String identity + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.identity = identity; } - public MemberCreator setIdentity(final String identity){ + public MemberCreator setIdentity(final String identity) { this.identity = identity; return this; } - public MemberCreator setXTwilioWebhookEnabled(final Member.WebhookEnabledType xTwilioWebhookEnabled){ + + public MemberCreator setXTwilioWebhookEnabled( + final Member.WebhookEnabledType xTwilioWebhookEnabled + ) { this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; return this; } - public MemberCreator setRoleSid(final String roleSid){ + + public MemberCreator setRoleSid(final String roleSid) { this.roleSid = roleSid; return this; } - public MemberCreator setLastConsumedMessageIndex(final Integer lastConsumedMessageIndex){ + + public MemberCreator setLastConsumedMessageIndex( + final Integer lastConsumedMessageIndex + ) { this.lastConsumedMessageIndex = lastConsumedMessageIndex; return this; } - public MemberCreator setLastConsumptionTimestamp(final ZonedDateTime lastConsumptionTimestamp){ + + public MemberCreator setLastConsumptionTimestamp( + final ZonedDateTime lastConsumptionTimestamp + ) { this.lastConsumptionTimestamp = lastConsumptionTimestamp; return this; } - public MemberCreator setDateCreated(final ZonedDateTime dateCreated){ + + public MemberCreator setDateCreated(final ZonedDateTime dateCreated) { this.dateCreated = dateCreated; return this; } - public MemberCreator setDateUpdated(final ZonedDateTime dateUpdated){ + + public MemberCreator setDateUpdated(final ZonedDateTime dateUpdated) { this.dateUpdated = dateUpdated; return this; } - public MemberCreator setAttributes(final String attributes){ + + public MemberCreator setAttributes(final String attributes) { this.attributes = attributes; return this; } @Override - public Member create(final TwilioRestClient client){ + public Member create(final TwilioRestClient client) { String path = "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Members"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); - path = path.replace("{"+"Identity"+"}", this.identity.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Identity" + "}", this.identity.toString()); Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); addHeaderParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Member creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Member creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -107,40 +137,49 @@ public Member create(final TwilioRestClient client){ return Member.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (identity != null) { request.addPostParam("Identity", identity); - } if (roleSid != null) { request.addPostParam("RoleSid", roleSid); - } if (lastConsumedMessageIndex != null) { - request.addPostParam("LastConsumedMessageIndex", lastConsumedMessageIndex.toString()); - + request.addPostParam( + "LastConsumedMessageIndex", + lastConsumedMessageIndex.toString() + ); } if (lastConsumptionTimestamp != null) { - request.addPostParam("LastConsumptionTimestamp", lastConsumptionTimestamp.toInstant().toString()); - + request.addPostParam( + "LastConsumptionTimestamp", + lastConsumptionTimestamp.toInstant().toString() + ); } if (dateCreated != null) { - request.addPostParam("DateCreated", dateCreated.toInstant().toString()); - + request.addPostParam( + "DateCreated", + dateCreated.toInstant().toString() + ); } if (dateUpdated != null) { - request.addPostParam("DateUpdated", dateUpdated.toInstant().toString()); - + request.addPostParam( + "DateUpdated", + dateUpdated.toInstant().toString() + ); } if (attributes != null) { request.addPostParam("Attributes", attributes); - } } + private void addHeaderParams(final Request request) { if (xTwilioWebhookEnabled != null) { - request.addHeaderParam("X-Twilio-Webhook-Enabled", xTwilioWebhookEnabled.toString()); - + request.addHeaderParam( + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/chat/v2/service/channel/MemberDeleter.java b/src/main/java/com/twilio/rest/chat/v2/service/channel/MemberDeleter.java index a96bad2567..0e62a5a6f3 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/channel/MemberDeleter.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/channel/MemberDeleter.java @@ -24,32 +24,46 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class MemberDeleter extends Deleter { + private String pathServiceSid; private String pathChannelSid; private String pathSid; private Member.WebhookEnabledType xTwilioWebhookEnabled; - public MemberDeleter(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public MemberDeleter( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - public MemberDeleter setXTwilioWebhookEnabled(final Member.WebhookEnabledType xTwilioWebhookEnabled){ + public MemberDeleter setXTwilioWebhookEnabled( + final Member.WebhookEnabledType xTwilioWebhookEnabled + ) { this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; return this; } @Override public boolean delete(final TwilioRestClient client) { - String path = "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Members/{Sid}"; + String path = + "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Members/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -60,9 +74,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Member delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Member delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -70,10 +89,13 @@ public boolean delete(final TwilioRestClient client) { } return response.getStatusCode() == 204; } + private void addHeaderParams(final Request request) { if (xTwilioWebhookEnabled != null) { - request.addHeaderParam("X-Twilio-Webhook-Enabled", xTwilioWebhookEnabled.toString()); - + request.addHeaderParam( + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/chat/v2/service/channel/MemberFetcher.java b/src/main/java/com/twilio/rest/chat/v2/service/channel/MemberFetcher.java index bdc5767b62..c7f045a66e 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/channel/MemberFetcher.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/channel/MemberFetcher.java @@ -24,28 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class MemberFetcher extends Fetcher { + private String pathServiceSid; private String pathChannelSid; private String pathSid; - public MemberFetcher(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public MemberFetcher( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - @Override public Member fetch(final TwilioRestClient client) { - String path = "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Members/{Sid}"; + String path = + "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Members/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -55,9 +65,14 @@ public Member fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Member fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Member fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/chat/v2/service/channel/MemberReader.java b/src/main/java/com/twilio/rest/chat/v2/service/channel/MemberReader.java index 8c9b3c806a..623951a7c0 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/channel/MemberReader.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/channel/MemberReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.chat.v2.service.channel; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.converter.Promoter; @@ -25,30 +26,33 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - import java.util.List; - public class MemberReader extends Reader { + private String pathServiceSid; private String pathChannelSid; private List identity; private Integer pageSize; - public MemberReader(final String pathServiceSid, final String pathChannelSid){ + public MemberReader( + final String pathServiceSid, + final String pathChannelSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; } - public MemberReader setIdentity(final List identity){ + public MemberReader setIdentity(final List identity) { this.identity = identity; return this; } - public MemberReader setIdentity(final String identity){ + + public MemberReader setIdentity(final String identity) { return setIdentity(Promoter.listOfOne(identity)); } - public MemberReader setPageSize(final Integer pageSize){ + + public MemberReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -60,8 +64,16 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Members"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -73,13 +85,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Member read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Member read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -95,7 +115,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.CHAT.toString()) @@ -103,9 +126,11 @@ public Page previousPage(final Page page, final TwilioRestClient return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.CHAT.toString()) @@ -114,14 +139,15 @@ public Page nextPage(final Page page, final TwilioRestClient cli } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (identity != null) { for (String prop : identity) { @@ -129,11 +155,10 @@ private void addQueryParams(final Request request) { } } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/chat/v2/service/channel/MemberUpdater.java b/src/main/java/com/twilio/rest/chat/v2/service/channel/MemberUpdater.java index 4348cff3c9..479c187bac 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/channel/MemberUpdater.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/channel/MemberUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.chat.v2.service.channel; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -23,12 +24,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.time.ZonedDateTime; +public class MemberUpdater extends Updater { - -public class MemberUpdater extends Updater{ private String pathServiceSid; private String pathChannelSid; private String pathSid; @@ -40,61 +39,92 @@ public class MemberUpdater extends Updater{ private ZonedDateTime dateUpdated; private String attributes; - public MemberUpdater(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public MemberUpdater( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - public MemberUpdater setXTwilioWebhookEnabled(final Member.WebhookEnabledType xTwilioWebhookEnabled){ + public MemberUpdater setXTwilioWebhookEnabled( + final Member.WebhookEnabledType xTwilioWebhookEnabled + ) { this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; return this; } - public MemberUpdater setRoleSid(final String roleSid){ + + public MemberUpdater setRoleSid(final String roleSid) { this.roleSid = roleSid; return this; } - public MemberUpdater setLastConsumedMessageIndex(final Integer lastConsumedMessageIndex){ + + public MemberUpdater setLastConsumedMessageIndex( + final Integer lastConsumedMessageIndex + ) { this.lastConsumedMessageIndex = lastConsumedMessageIndex; return this; } - public MemberUpdater setLastConsumptionTimestamp(final ZonedDateTime lastConsumptionTimestamp){ + + public MemberUpdater setLastConsumptionTimestamp( + final ZonedDateTime lastConsumptionTimestamp + ) { this.lastConsumptionTimestamp = lastConsumptionTimestamp; return this; } - public MemberUpdater setDateCreated(final ZonedDateTime dateCreated){ + + public MemberUpdater setDateCreated(final ZonedDateTime dateCreated) { this.dateCreated = dateCreated; return this; } - public MemberUpdater setDateUpdated(final ZonedDateTime dateUpdated){ + + public MemberUpdater setDateUpdated(final ZonedDateTime dateUpdated) { this.dateUpdated = dateUpdated; return this; } - public MemberUpdater setAttributes(final String attributes){ + + public MemberUpdater setAttributes(final String attributes) { this.attributes = attributes; return this; } @Override - public Member update(final TwilioRestClient client){ - String path = "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Members/{Sid}"; - - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + public Member update(final TwilioRestClient client) { + String path = + "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Members/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); addHeaderParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Member update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Member update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -103,36 +133,46 @@ public Member update(final TwilioRestClient client){ return Member.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (roleSid != null) { request.addPostParam("RoleSid", roleSid); - } if (lastConsumedMessageIndex != null) { - request.addPostParam("LastConsumedMessageIndex", lastConsumedMessageIndex.toString()); - + request.addPostParam( + "LastConsumedMessageIndex", + lastConsumedMessageIndex.toString() + ); } if (lastConsumptionTimestamp != null) { - request.addPostParam("LastConsumptionTimestamp", lastConsumptionTimestamp.toInstant().toString()); - + request.addPostParam( + "LastConsumptionTimestamp", + lastConsumptionTimestamp.toInstant().toString() + ); } if (dateCreated != null) { - request.addPostParam("DateCreated", dateCreated.toInstant().toString()); - + request.addPostParam( + "DateCreated", + dateCreated.toInstant().toString() + ); } if (dateUpdated != null) { - request.addPostParam("DateUpdated", dateUpdated.toInstant().toString()); - + request.addPostParam( + "DateUpdated", + dateUpdated.toInstant().toString() + ); } if (attributes != null) { request.addPostParam("Attributes", attributes); - } } + private void addHeaderParams(final Request request) { if (xTwilioWebhookEnabled != null) { - request.addHeaderParam("X-Twilio-Webhook-Enabled", xTwilioWebhookEnabled.toString()); - + request.addHeaderParam( + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/chat/v2/service/channel/Message.java b/src/main/java/com/twilio/rest/chat/v2/service/channel/Message.java index 462044bf9d..645c812e00 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/channel/Message.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/channel/Message.java @@ -24,55 +24,72 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Message extends Resource { + private static final long serialVersionUID = 210901647084119L; - public static MessageCreator creator(final String pathServiceSid, final String pathChannelSid){ + public static MessageCreator creator( + final String pathServiceSid, + final String pathChannelSid + ) { return new MessageCreator(pathServiceSid, pathChannelSid); } - public static MessageDeleter deleter(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public static MessageDeleter deleter( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { return new MessageDeleter(pathServiceSid, pathChannelSid, pathSid); } - public static MessageFetcher fetcher(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public static MessageFetcher fetcher( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { return new MessageFetcher(pathServiceSid, pathChannelSid, pathSid); } - public static MessageReader reader(final String pathServiceSid, final String pathChannelSid){ + public static MessageReader reader( + final String pathServiceSid, + final String pathChannelSid + ) { return new MessageReader(pathServiceSid, pathChannelSid); } - public static MessageUpdater updater(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public static MessageUpdater updater( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { return new MessageUpdater(pathServiceSid, pathChannelSid, pathSid); } /** - * Converts a JSON String into a Message object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Message object represented by the provided JSON - */ - public static Message fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Message object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Message object represented by the provided JSON + */ + public static Message fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Message.class); @@ -84,14 +101,17 @@ public static Message fromJson(final String json, final ObjectMapper objectMappe } /** - * Converts a JSON InputStream into a Message object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Message object represented by the provided JSON - */ - public static Message fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Message object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Message object represented by the provided JSON + */ + public static Message fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Message.class); @@ -101,6 +121,7 @@ public static Message fromJson(final InputStream json, final ObjectMapper object throw new ApiConnectionException(e.getMessage(), e); } } + public enum OrderType { ASC("asc"), DESC("desc"); @@ -120,6 +141,7 @@ public static OrderType forValue(final String value) { return Promoter.enumFromString(value, OrderType.values()); } } + public enum WebhookEnabledType { TRUE("true"), FALSE("false"); @@ -159,53 +181,22 @@ public static WebhookEnabledType forValue(final String value) { @JsonCreator private Message( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("attributes") - final String attributes, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("to") - final String to, - - @JsonProperty("channel_sid") - final String channelSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("last_updated_by") - final String lastUpdatedBy, - - @JsonProperty("was_edited") - final Boolean wasEdited, - - @JsonProperty("from") - final String from, - - @JsonProperty("body") - final String body, - - @JsonProperty("index") - final Integer index, - - @JsonProperty("type") - final String type, - - @JsonProperty("media") - final Map media, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("attributes") final String attributes, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("to") final String to, + @JsonProperty("channel_sid") final String channelSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("last_updated_by") final String lastUpdatedBy, + @JsonProperty("was_edited") final Boolean wasEdited, + @JsonProperty("from") final String from, + @JsonProperty("body") final String body, + @JsonProperty("index") final Integer index, + @JsonProperty("type") final String type, + @JsonProperty("media") final Map media, + @JsonProperty("url") final URI url ) { this.sid = sid; this.accountSid = accountSid; @@ -225,58 +216,73 @@ private Message( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getAttributes() { - return this.attributes; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final String getTo() { - return this.to; - } - public final String getChannelSid() { - return this.channelSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getLastUpdatedBy() { - return this.lastUpdatedBy; - } - public final Boolean getWasEdited() { - return this.wasEdited; - } - public final String getFrom() { - return this.from; - } - public final String getBody() { - return this.body; - } - public final Integer getIndex() { - return this.index; - } - public final String getType() { - return this.type; - } - public final Map getMedia() { - return this.media; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getAttributes() { + return this.attributes; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final String getTo() { + return this.to; + } + + public final String getChannelSid() { + return this.channelSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getLastUpdatedBy() { + return this.lastUpdatedBy; + } + + public final Boolean getWasEdited() { + return this.wasEdited; + } + + public final String getFrom() { + return this.from; + } + + public final String getBody() { + return this.body; + } + + public final Integer getIndex() { + return this.index; + } + + public final String getType() { + return this.type; + } + + public final Map getMedia() { + return this.media; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -286,13 +292,45 @@ public boolean equals(final Object o) { Message other = (Message) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(attributes, other.attributes) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(to, other.to) && Objects.equals(channelSid, other.channelSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(lastUpdatedBy, other.lastUpdatedBy) && Objects.equals(wasEdited, other.wasEdited) && Objects.equals(from, other.from) && Objects.equals(body, other.body) && Objects.equals(index, other.index) && Objects.equals(type, other.type) && Objects.equals(media, other.media) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(attributes, other.attributes) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(to, other.to) && + Objects.equals(channelSid, other.channelSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(lastUpdatedBy, other.lastUpdatedBy) && + Objects.equals(wasEdited, other.wasEdited) && + Objects.equals(from, other.from) && + Objects.equals(body, other.body) && + Objects.equals(index, other.index) && + Objects.equals(type, other.type) && + Objects.equals(media, other.media) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, attributes, serviceSid, to, channelSid, dateCreated, dateUpdated, lastUpdatedBy, wasEdited, from, body, index, type, media, url); + return Objects.hash( + sid, + accountSid, + attributes, + serviceSid, + to, + channelSid, + dateCreated, + dateUpdated, + lastUpdatedBy, + wasEdited, + from, + body, + index, + type, + media, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/chat/v2/service/channel/MessageCreator.java b/src/main/java/com/twilio/rest/chat/v2/service/channel/MessageCreator.java index 8cf1f3b811..67b6fce6d4 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/channel/MessageCreator.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/channel/MessageCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.chat.v2.service.channel; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -25,10 +26,8 @@ import com.twilio.rest.Domains; import java.time.ZonedDateTime; +public class MessageCreator extends Creator { - - -public class MessageCreator extends Creator{ private String pathServiceSid; private String pathChannelSid; private Message.WebhookEnabledType xTwilioWebhookEnabled; @@ -40,63 +39,90 @@ public class MessageCreator extends Creator{ private String body; private String mediaSid; - public MessageCreator(final String pathServiceSid, final String pathChannelSid) { + public MessageCreator( + final String pathServiceSid, + final String pathChannelSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; } - public MessageCreator setXTwilioWebhookEnabled(final Message.WebhookEnabledType xTwilioWebhookEnabled){ + public MessageCreator setXTwilioWebhookEnabled( + final Message.WebhookEnabledType xTwilioWebhookEnabled + ) { this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; return this; } - public MessageCreator setFrom(final String from){ + + public MessageCreator setFrom(final String from) { this.from = from; return this; } - public MessageCreator setAttributes(final String attributes){ + + public MessageCreator setAttributes(final String attributes) { this.attributes = attributes; return this; } - public MessageCreator setDateCreated(final ZonedDateTime dateCreated){ + + public MessageCreator setDateCreated(final ZonedDateTime dateCreated) { this.dateCreated = dateCreated; return this; } - public MessageCreator setDateUpdated(final ZonedDateTime dateUpdated){ + + public MessageCreator setDateUpdated(final ZonedDateTime dateUpdated) { this.dateUpdated = dateUpdated; return this; } - public MessageCreator setLastUpdatedBy(final String lastUpdatedBy){ + + public MessageCreator setLastUpdatedBy(final String lastUpdatedBy) { this.lastUpdatedBy = lastUpdatedBy; return this; } - public MessageCreator setBody(final String body){ + + public MessageCreator setBody(final String body) { this.body = body; return this; } - public MessageCreator setMediaSid(final String mediaSid){ + + public MessageCreator setMediaSid(final String mediaSid) { this.mediaSid = mediaSid; return this; } @Override - public Message create(final TwilioRestClient client){ - String path = "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Messages"; + public Message create(final TwilioRestClient client) { + String path = + "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Messages"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); addHeaderParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Message creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Message creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -105,40 +131,43 @@ public Message create(final TwilioRestClient client){ return Message.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (from != null) { request.addPostParam("From", from); - } if (attributes != null) { request.addPostParam("Attributes", attributes); - } if (dateCreated != null) { - request.addPostParam("DateCreated", dateCreated.toInstant().toString()); - + request.addPostParam( + "DateCreated", + dateCreated.toInstant().toString() + ); } if (dateUpdated != null) { - request.addPostParam("DateUpdated", dateUpdated.toInstant().toString()); - + request.addPostParam( + "DateUpdated", + dateUpdated.toInstant().toString() + ); } if (lastUpdatedBy != null) { request.addPostParam("LastUpdatedBy", lastUpdatedBy); - } if (body != null) { request.addPostParam("Body", body); - } if (mediaSid != null) { request.addPostParam("MediaSid", mediaSid); - } } + private void addHeaderParams(final Request request) { if (xTwilioWebhookEnabled != null) { - request.addHeaderParam("X-Twilio-Webhook-Enabled", xTwilioWebhookEnabled.toString()); - + request.addHeaderParam( + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/chat/v2/service/channel/MessageDeleter.java b/src/main/java/com/twilio/rest/chat/v2/service/channel/MessageDeleter.java index 4ce090e0ae..a34a28be86 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/channel/MessageDeleter.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/channel/MessageDeleter.java @@ -24,32 +24,46 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class MessageDeleter extends Deleter { + private String pathServiceSid; private String pathChannelSid; private String pathSid; private Message.WebhookEnabledType xTwilioWebhookEnabled; - public MessageDeleter(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public MessageDeleter( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - public MessageDeleter setXTwilioWebhookEnabled(final Message.WebhookEnabledType xTwilioWebhookEnabled){ + public MessageDeleter setXTwilioWebhookEnabled( + final Message.WebhookEnabledType xTwilioWebhookEnabled + ) { this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; return this; } @Override public boolean delete(final TwilioRestClient client) { - String path = "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Messages/{Sid}"; + String path = + "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Messages/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -60,9 +74,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Message delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Message delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -70,10 +89,13 @@ public boolean delete(final TwilioRestClient client) { } return response.getStatusCode() == 204; } + private void addHeaderParams(final Request request) { if (xTwilioWebhookEnabled != null) { - request.addHeaderParam("X-Twilio-Webhook-Enabled", xTwilioWebhookEnabled.toString()); - + request.addHeaderParam( + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/chat/v2/service/channel/MessageFetcher.java b/src/main/java/com/twilio/rest/chat/v2/service/channel/MessageFetcher.java index 7f483d8756..66736d384b 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/channel/MessageFetcher.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/channel/MessageFetcher.java @@ -24,28 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class MessageFetcher extends Fetcher { + private String pathServiceSid; private String pathChannelSid; private String pathSid; - public MessageFetcher(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public MessageFetcher( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - @Override public Message fetch(final TwilioRestClient client) { - String path = "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Messages/{Sid}"; + String path = + "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Messages/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -55,9 +65,14 @@ public Message fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Message fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Message fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/chat/v2/service/channel/MessageReader.java b/src/main/java/com/twilio/rest/chat/v2/service/channel/MessageReader.java index 752d3eee11..41caab550a 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/channel/MessageReader.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/channel/MessageReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.chat.v2.service.channel; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,26 +25,28 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class MessageReader extends Reader { + private String pathServiceSid; private String pathChannelSid; private Message.OrderType order; private Integer pageSize; - public MessageReader(final String pathServiceSid, final String pathChannelSid){ + public MessageReader( + final String pathServiceSid, + final String pathChannelSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; } - public MessageReader setOrder(final Message.OrderType order){ + public MessageReader setOrder(final Message.OrderType order) { this.order = order; return this; } - public MessageReader setPageSize(final Integer pageSize){ + + public MessageReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -54,9 +57,18 @@ public ResourceSet read(final TwilioRestClient client) { } public Page firstPage(final TwilioRestClient client) { - String path = "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Messages"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); + String path = + "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Messages"; + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -68,13 +80,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Message read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Message read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -90,7 +110,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reques } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.CHAT.toString()) @@ -98,9 +121,11 @@ public Page previousPage(final Page page, final TwilioRestClie return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.CHAT.toString()) @@ -109,25 +134,24 @@ public Page nextPage(final Page page, final TwilioRestClient c } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (order != null) { - request.addQueryParam("Order", order.toString()); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/chat/v2/service/channel/MessageUpdater.java b/src/main/java/com/twilio/rest/chat/v2/service/channel/MessageUpdater.java index 79d29d9f27..ad6c4422ca 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/channel/MessageUpdater.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/channel/MessageUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.chat.v2.service.channel; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -23,12 +24,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.time.ZonedDateTime; +public class MessageUpdater extends Updater { - -public class MessageUpdater extends Updater{ private String pathServiceSid; private String pathChannelSid; private String pathSid; @@ -40,61 +39,88 @@ public class MessageUpdater extends Updater{ private String lastUpdatedBy; private String from; - public MessageUpdater(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public MessageUpdater( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - public MessageUpdater setXTwilioWebhookEnabled(final Message.WebhookEnabledType xTwilioWebhookEnabled){ + public MessageUpdater setXTwilioWebhookEnabled( + final Message.WebhookEnabledType xTwilioWebhookEnabled + ) { this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; return this; } - public MessageUpdater setBody(final String body){ + + public MessageUpdater setBody(final String body) { this.body = body; return this; } - public MessageUpdater setAttributes(final String attributes){ + + public MessageUpdater setAttributes(final String attributes) { this.attributes = attributes; return this; } - public MessageUpdater setDateCreated(final ZonedDateTime dateCreated){ + + public MessageUpdater setDateCreated(final ZonedDateTime dateCreated) { this.dateCreated = dateCreated; return this; } - public MessageUpdater setDateUpdated(final ZonedDateTime dateUpdated){ + + public MessageUpdater setDateUpdated(final ZonedDateTime dateUpdated) { this.dateUpdated = dateUpdated; return this; } - public MessageUpdater setLastUpdatedBy(final String lastUpdatedBy){ + + public MessageUpdater setLastUpdatedBy(final String lastUpdatedBy) { this.lastUpdatedBy = lastUpdatedBy; return this; } - public MessageUpdater setFrom(final String from){ + + public MessageUpdater setFrom(final String from) { this.from = from; return this; } @Override - public Message update(final TwilioRestClient client){ - String path = "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Messages/{Sid}"; + public Message update(final TwilioRestClient client) { + String path = + "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Messages/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); addHeaderParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Message update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Message update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -103,36 +129,40 @@ public Message update(final TwilioRestClient client){ return Message.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (body != null) { request.addPostParam("Body", body); - } if (attributes != null) { request.addPostParam("Attributes", attributes); - } if (dateCreated != null) { - request.addPostParam("DateCreated", dateCreated.toInstant().toString()); - + request.addPostParam( + "DateCreated", + dateCreated.toInstant().toString() + ); } if (dateUpdated != null) { - request.addPostParam("DateUpdated", dateUpdated.toInstant().toString()); - + request.addPostParam( + "DateUpdated", + dateUpdated.toInstant().toString() + ); } if (lastUpdatedBy != null) { request.addPostParam("LastUpdatedBy", lastUpdatedBy); - } if (from != null) { request.addPostParam("From", from); - } } + private void addHeaderParams(final Request request) { if (xTwilioWebhookEnabled != null) { - request.addHeaderParam("X-Twilio-Webhook-Enabled", xTwilioWebhookEnabled.toString()); - + request.addHeaderParam( + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/chat/v2/service/channel/Webhook.java b/src/main/java/com/twilio/rest/chat/v2/service/channel/Webhook.java index 47e7cfeb96..6d9c660820 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/channel/Webhook.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/channel/Webhook.java @@ -24,55 +24,73 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Webhook extends Resource { + private static final long serialVersionUID = 201752828404640L; - public static WebhookCreator creator(final String pathServiceSid, final String pathChannelSid, final Webhook.Type type){ + public static WebhookCreator creator( + final String pathServiceSid, + final String pathChannelSid, + final Webhook.Type type + ) { return new WebhookCreator(pathServiceSid, pathChannelSid, type); } - public static WebhookDeleter deleter(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public static WebhookDeleter deleter( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { return new WebhookDeleter(pathServiceSid, pathChannelSid, pathSid); } - public static WebhookFetcher fetcher(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public static WebhookFetcher fetcher( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { return new WebhookFetcher(pathServiceSid, pathChannelSid, pathSid); } - public static WebhookReader reader(final String pathServiceSid, final String pathChannelSid){ + public static WebhookReader reader( + final String pathServiceSid, + final String pathChannelSid + ) { return new WebhookReader(pathServiceSid, pathChannelSid); } - public static WebhookUpdater updater(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public static WebhookUpdater updater( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { return new WebhookUpdater(pathServiceSid, pathChannelSid, pathSid); } /** - * Converts a JSON String into a Webhook object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Webhook object represented by the provided JSON - */ - public static Webhook fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Webhook object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Webhook object represented by the provided JSON + */ + public static Webhook fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Webhook.class); @@ -84,14 +102,17 @@ public static Webhook fromJson(final String json, final ObjectMapper objectMappe } /** - * Converts a JSON InputStream into a Webhook object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Webhook object represented by the provided JSON - */ - public static Webhook fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Webhook object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Webhook object represented by the provided JSON + */ + public static Webhook fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Webhook.class); @@ -101,6 +122,7 @@ public static Webhook fromJson(final InputStream json, final ObjectMapper object throw new ApiConnectionException(e.getMessage(), e); } } + public enum Method { GET("GET"), POST("POST"); @@ -120,6 +142,7 @@ public static Method forValue(final String value) { return Promoter.enumFromString(value, Method.values()); } } + public enum Type { WEBHOOK("webhook"), TRIGGER("trigger"), @@ -153,32 +176,15 @@ public static Type forValue(final String value) { @JsonCreator private Webhook( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("channel_sid") - final String channelSid, - - @JsonProperty("type") - final String type, - - @JsonProperty("url") - final URI url, - - @JsonProperty("configuration") - final Map configuration, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("channel_sid") final String channelSid, + @JsonProperty("type") final String type, + @JsonProperty("url") final URI url, + @JsonProperty("configuration") final Map configuration, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated ) { this.sid = sid; this.accountSid = accountSid; @@ -191,37 +197,45 @@ private Webhook( this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final String getChannelSid() { - return this.channelSid; - } - public final String getType() { - return this.type; - } - public final URI getUrl() { - return this.url; - } - public final Map getConfiguration() { - return this.configuration; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final String getChannelSid() { + return this.channelSid; + } + + public final String getType() { + return this.type; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getConfiguration() { + return this.configuration; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -231,13 +245,31 @@ public boolean equals(final Object o) { Webhook other = (Webhook) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(channelSid, other.channelSid) && Objects.equals(type, other.type) && Objects.equals(url, other.url) && Objects.equals(configuration, other.configuration) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(channelSid, other.channelSid) && + Objects.equals(type, other.type) && + Objects.equals(url, other.url) && + Objects.equals(configuration, other.configuration) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, serviceSid, channelSid, type, url, configuration, dateCreated, dateUpdated); + return Objects.hash( + sid, + accountSid, + serviceSid, + channelSid, + type, + url, + configuration, + dateCreated, + dateUpdated + ); } - } - diff --git a/src/main/java/com/twilio/rest/chat/v2/service/channel/WebhookCreator.java b/src/main/java/com/twilio/rest/chat/v2/service/channel/WebhookCreator.java index f5809281ee..e3f01b1408 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/channel/WebhookCreator.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/channel/WebhookCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.chat.v2.service.channel; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -25,12 +26,10 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.util.List; - import java.util.List; +public class WebhookCreator extends Creator { - -public class WebhookCreator extends Creator{ private String pathServiceSid; private String pathChannelSid; private Webhook.Type type; @@ -41,66 +40,111 @@ public class WebhookCreator extends Creator{ private String configurationFlowSid; private Integer configurationRetryCount; - public WebhookCreator(final String pathServiceSid, final String pathChannelSid, final Webhook.Type type) { + public WebhookCreator( + final String pathServiceSid, + final String pathChannelSid, + final Webhook.Type type + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.type = type; } - public WebhookCreator setType(final Webhook.Type type){ + public WebhookCreator setType(final Webhook.Type type) { this.type = type; return this; } - public WebhookCreator setConfigurationUrl(final String configurationUrl){ + + public WebhookCreator setConfigurationUrl(final String configurationUrl) { this.configurationUrl = configurationUrl; return this; } - public WebhookCreator setConfigurationMethod(final Webhook.Method configurationMethod){ + + public WebhookCreator setConfigurationMethod( + final Webhook.Method configurationMethod + ) { this.configurationMethod = configurationMethod; return this; } - public WebhookCreator setConfigurationFilters(final List configurationFilters){ + + public WebhookCreator setConfigurationFilters( + final List configurationFilters + ) { this.configurationFilters = configurationFilters; return this; } - public WebhookCreator setConfigurationFilters(final String configurationFilters){ - return setConfigurationFilters(Promoter.listOfOne(configurationFilters)); + + public WebhookCreator setConfigurationFilters( + final String configurationFilters + ) { + return setConfigurationFilters( + Promoter.listOfOne(configurationFilters) + ); } - public WebhookCreator setConfigurationTriggers(final List configurationTriggers){ + + public WebhookCreator setConfigurationTriggers( + final List configurationTriggers + ) { this.configurationTriggers = configurationTriggers; return this; } - public WebhookCreator setConfigurationTriggers(final String configurationTriggers){ - return setConfigurationTriggers(Promoter.listOfOne(configurationTriggers)); + + public WebhookCreator setConfigurationTriggers( + final String configurationTriggers + ) { + return setConfigurationTriggers( + Promoter.listOfOne(configurationTriggers) + ); } - public WebhookCreator setConfigurationFlowSid(final String configurationFlowSid){ + + public WebhookCreator setConfigurationFlowSid( + final String configurationFlowSid + ) { this.configurationFlowSid = configurationFlowSid; return this; } - public WebhookCreator setConfigurationRetryCount(final Integer configurationRetryCount){ + + public WebhookCreator setConfigurationRetryCount( + final Integer configurationRetryCount + ) { this.configurationRetryCount = configurationRetryCount; return this; } @Override - public Webhook create(final TwilioRestClient client){ - String path = "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Webhooks"; + public Webhook create(final TwilioRestClient client) { + String path = + "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Webhooks"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); - path = path.replace("{"+"Type"+"}", this.type.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Type" + "}", this.type.toString()); Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Webhook creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Webhook creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -109,38 +153,38 @@ public Webhook create(final TwilioRestClient client){ return Webhook.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (type != null) { request.addPostParam("Type", type.toString()); - } if (configurationUrl != null) { request.addPostParam("Configuration.Url", configurationUrl); - } if (configurationMethod != null) { - request.addPostParam("Configuration.Method", configurationMethod.toString()); - + request.addPostParam( + "Configuration.Method", + configurationMethod.toString() + ); } if (configurationFilters != null) { for (String prop : configurationFilters) { request.addPostParam("Configuration.Filters", prop); } - } if (configurationTriggers != null) { for (String prop : configurationTriggers) { request.addPostParam("Configuration.Triggers", prop); } - } if (configurationFlowSid != null) { request.addPostParam("Configuration.FlowSid", configurationFlowSid); - } if (configurationRetryCount != null) { - request.addPostParam("Configuration.RetryCount", configurationRetryCount.toString()); - + request.addPostParam( + "Configuration.RetryCount", + configurationRetryCount.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/chat/v2/service/channel/WebhookDeleter.java b/src/main/java/com/twilio/rest/chat/v2/service/channel/WebhookDeleter.java index 88c6d5e9a9..195c452acb 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/channel/WebhookDeleter.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/channel/WebhookDeleter.java @@ -24,27 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class WebhookDeleter extends Deleter { + private String pathServiceSid; private String pathChannelSid; private String pathSid; - public WebhookDeleter(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public WebhookDeleter( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Webhooks/{Sid}"; + String path = + "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Webhooks/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -54,9 +65,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Webhook delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Webhook delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/chat/v2/service/channel/WebhookFetcher.java b/src/main/java/com/twilio/rest/chat/v2/service/channel/WebhookFetcher.java index 760b0445bc..acb3e63a45 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/channel/WebhookFetcher.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/channel/WebhookFetcher.java @@ -24,28 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class WebhookFetcher extends Fetcher { + private String pathServiceSid; private String pathChannelSid; private String pathSid; - public WebhookFetcher(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public WebhookFetcher( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - @Override public Webhook fetch(final TwilioRestClient client) { - String path = "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Webhooks/{Sid}"; + String path = + "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Webhooks/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -55,9 +65,14 @@ public Webhook fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Webhook fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Webhook fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/chat/v2/service/channel/WebhookReader.java b/src/main/java/com/twilio/rest/chat/v2/service/channel/WebhookReader.java index ee5f5c88e3..01856f45b5 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/channel/WebhookReader.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/channel/WebhookReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.chat.v2.service.channel; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,21 +25,22 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class WebhookReader extends Reader { + private String pathServiceSid; private String pathChannelSid; private Integer pageSize; - public WebhookReader(final String pathServiceSid, final String pathChannelSid){ + public WebhookReader( + final String pathServiceSid, + final String pathChannelSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; } - public WebhookReader setPageSize(final Integer pageSize){ + public WebhookReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -49,9 +51,18 @@ public ResourceSet read(final TwilioRestClient client) { } public Page firstPage(final TwilioRestClient client) { - String path = "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Webhooks"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); + String path = + "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Webhooks"; + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -63,13 +74,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Webhook read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Webhook read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -85,7 +104,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reques } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.CHAT.toString()) @@ -93,9 +115,11 @@ public Page previousPage(final Page page, final TwilioRestClie return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.CHAT.toString()) @@ -104,21 +128,21 @@ public Page nextPage(final Page page, final TwilioRestClient c } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/chat/v2/service/channel/WebhookUpdater.java b/src/main/java/com/twilio/rest/chat/v2/service/channel/WebhookUpdater.java index 67a270811f..1f3356d21f 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/channel/WebhookUpdater.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/channel/WebhookUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.chat.v2.service.channel; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -24,12 +25,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - import java.util.List; +public class WebhookUpdater extends Updater { -public class WebhookUpdater extends Updater{ private String pathServiceSid; private String pathChannelSid; private String pathSid; @@ -40,62 +39,106 @@ public class WebhookUpdater extends Updater{ private String configurationFlowSid; private Integer configurationRetryCount; - public WebhookUpdater(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public WebhookUpdater( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - public WebhookUpdater setConfigurationUrl(final String configurationUrl){ + public WebhookUpdater setConfigurationUrl(final String configurationUrl) { this.configurationUrl = configurationUrl; return this; } - public WebhookUpdater setConfigurationMethod(final Webhook.Method configurationMethod){ + + public WebhookUpdater setConfigurationMethod( + final Webhook.Method configurationMethod + ) { this.configurationMethod = configurationMethod; return this; } - public WebhookUpdater setConfigurationFilters(final List configurationFilters){ + + public WebhookUpdater setConfigurationFilters( + final List configurationFilters + ) { this.configurationFilters = configurationFilters; return this; } - public WebhookUpdater setConfigurationFilters(final String configurationFilters){ - return setConfigurationFilters(Promoter.listOfOne(configurationFilters)); + + public WebhookUpdater setConfigurationFilters( + final String configurationFilters + ) { + return setConfigurationFilters( + Promoter.listOfOne(configurationFilters) + ); } - public WebhookUpdater setConfigurationTriggers(final List configurationTriggers){ + + public WebhookUpdater setConfigurationTriggers( + final List configurationTriggers + ) { this.configurationTriggers = configurationTriggers; return this; } - public WebhookUpdater setConfigurationTriggers(final String configurationTriggers){ - return setConfigurationTriggers(Promoter.listOfOne(configurationTriggers)); + + public WebhookUpdater setConfigurationTriggers( + final String configurationTriggers + ) { + return setConfigurationTriggers( + Promoter.listOfOne(configurationTriggers) + ); } - public WebhookUpdater setConfigurationFlowSid(final String configurationFlowSid){ + + public WebhookUpdater setConfigurationFlowSid( + final String configurationFlowSid + ) { this.configurationFlowSid = configurationFlowSid; return this; } - public WebhookUpdater setConfigurationRetryCount(final Integer configurationRetryCount){ + + public WebhookUpdater setConfigurationRetryCount( + final Integer configurationRetryCount + ) { this.configurationRetryCount = configurationRetryCount; return this; } @Override - public Webhook update(final TwilioRestClient client){ - String path = "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Webhooks/{Sid}"; + public Webhook update(final TwilioRestClient client) { + String path = + "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Webhooks/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Webhook update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Webhook update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -104,34 +147,35 @@ public Webhook update(final TwilioRestClient client){ return Webhook.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (configurationUrl != null) { request.addPostParam("Configuration.Url", configurationUrl); - } if (configurationMethod != null) { - request.addPostParam("Configuration.Method", configurationMethod.toString()); - + request.addPostParam( + "Configuration.Method", + configurationMethod.toString() + ); } if (configurationFilters != null) { for (String prop : configurationFilters) { request.addPostParam("Configuration.Filters", prop); } - } if (configurationTriggers != null) { for (String prop : configurationTriggers) { request.addPostParam("Configuration.Triggers", prop); } - } if (configurationFlowSid != null) { request.addPostParam("Configuration.FlowSid", configurationFlowSid); - } if (configurationRetryCount != null) { - request.addPostParam("Configuration.RetryCount", configurationRetryCount.toString()); - + request.addPostParam( + "Configuration.RetryCount", + configurationRetryCount.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/chat/v2/service/user/UserBinding.java b/src/main/java/com/twilio/rest/chat/v2/service/user/UserBinding.java index f7c8eeaa7a..0b494caeb0 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/user/UserBinding.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/user/UserBinding.java @@ -24,46 +24,56 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.List; import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class UserBinding extends Resource { + private static final long serialVersionUID = 252068300768529L; - public static UserBindingDeleter deleter(final String pathServiceSid, final String pathUserSid, final String pathSid){ + public static UserBindingDeleter deleter( + final String pathServiceSid, + final String pathUserSid, + final String pathSid + ) { return new UserBindingDeleter(pathServiceSid, pathUserSid, pathSid); } - public static UserBindingFetcher fetcher(final String pathServiceSid, final String pathUserSid, final String pathSid){ + public static UserBindingFetcher fetcher( + final String pathServiceSid, + final String pathUserSid, + final String pathSid + ) { return new UserBindingFetcher(pathServiceSid, pathUserSid, pathSid); } - public static UserBindingReader reader(final String pathServiceSid, final String pathUserSid){ + public static UserBindingReader reader( + final String pathServiceSid, + final String pathUserSid + ) { return new UserBindingReader(pathServiceSid, pathUserSid); } /** - * Converts a JSON String into a UserBinding object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return UserBinding object represented by the provided JSON - */ - public static UserBinding fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a UserBinding object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return UserBinding object represented by the provided JSON + */ + public static UserBinding fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, UserBinding.class); @@ -75,14 +85,17 @@ public static UserBinding fromJson(final String json, final ObjectMapper objectM } /** - * Converts a JSON InputStream into a UserBinding object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return UserBinding object represented by the provided JSON - */ - public static UserBinding fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a UserBinding object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return UserBinding object represented by the provided JSON + */ + public static UserBinding fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, UserBinding.class); @@ -92,6 +105,7 @@ public static UserBinding fromJson(final InputStream json, final ObjectMapper ob throw new ApiConnectionException(e.getMessage(), e); } } + public enum BindingType { GCM("gcm"), APN("apn"), @@ -128,41 +142,18 @@ public static BindingType forValue(final String value) { @JsonCreator private UserBinding( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("endpoint") - final String endpoint, - - @JsonProperty("identity") - final String identity, - - @JsonProperty("user_sid") - final String userSid, - - @JsonProperty("credential_sid") - final String credentialSid, - - @JsonProperty("binding_type") - final UserBinding.BindingType bindingType, - - @JsonProperty("message_types") - final List messageTypes, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("endpoint") final String endpoint, + @JsonProperty("identity") final String identity, + @JsonProperty("user_sid") final String userSid, + @JsonProperty("credential_sid") final String credentialSid, + @JsonProperty("binding_type") final UserBinding.BindingType bindingType, + @JsonProperty("message_types") final List messageTypes, + @JsonProperty("url") final URI url ) { this.sid = sid; this.accountSid = accountSid; @@ -178,46 +169,57 @@ private UserBinding( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getEndpoint() { - return this.endpoint; - } - public final String getIdentity() { - return this.identity; - } - public final String getUserSid() { - return this.userSid; - } - public final String getCredentialSid() { - return this.credentialSid; - } - public final UserBinding.BindingType getBindingType() { - return this.bindingType; - } - public final List getMessageTypes() { - return this.messageTypes; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getEndpoint() { + return this.endpoint; + } + + public final String getIdentity() { + return this.identity; + } + + public final String getUserSid() { + return this.userSid; + } + + public final String getCredentialSid() { + return this.credentialSid; + } + + public final UserBinding.BindingType getBindingType() { + return this.bindingType; + } + + public final List getMessageTypes() { + return this.messageTypes; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -227,13 +229,37 @@ public boolean equals(final Object o) { UserBinding other = (UserBinding) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(endpoint, other.endpoint) && Objects.equals(identity, other.identity) && Objects.equals(userSid, other.userSid) && Objects.equals(credentialSid, other.credentialSid) && Objects.equals(bindingType, other.bindingType) && Objects.equals(messageTypes, other.messageTypes) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(endpoint, other.endpoint) && + Objects.equals(identity, other.identity) && + Objects.equals(userSid, other.userSid) && + Objects.equals(credentialSid, other.credentialSid) && + Objects.equals(bindingType, other.bindingType) && + Objects.equals(messageTypes, other.messageTypes) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, serviceSid, dateCreated, dateUpdated, endpoint, identity, userSid, credentialSid, bindingType, messageTypes, url); + return Objects.hash( + sid, + accountSid, + serviceSid, + dateCreated, + dateUpdated, + endpoint, + identity, + userSid, + credentialSid, + bindingType, + messageTypes, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/chat/v2/service/user/UserBindingDeleter.java b/src/main/java/com/twilio/rest/chat/v2/service/user/UserBindingDeleter.java index 84409c0ba2..8503ca09f6 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/user/UserBindingDeleter.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/user/UserBindingDeleter.java @@ -24,27 +24,34 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class UserBindingDeleter extends Deleter { + private String pathServiceSid; private String pathUserSid; private String pathSid; - public UserBindingDeleter(final String pathServiceSid, final String pathUserSid, final String pathSid){ + public UserBindingDeleter( + final String pathServiceSid, + final String pathUserSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathUserSid = pathUserSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/v2/Services/{ServiceSid}/Users/{UserSid}/Bindings/{Sid}"; + String path = + "/v2/Services/{ServiceSid}/Users/{UserSid}/Bindings/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"UserSid"+"}", this.pathUserSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "UserSid" + "}", this.pathUserSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -54,9 +61,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("UserBinding delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "UserBinding delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/chat/v2/service/user/UserBindingFetcher.java b/src/main/java/com/twilio/rest/chat/v2/service/user/UserBindingFetcher.java index 65bb080094..8954903c0e 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/user/UserBindingFetcher.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/user/UserBindingFetcher.java @@ -24,28 +24,34 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class UserBindingFetcher extends Fetcher { + private String pathServiceSid; private String pathUserSid; private String pathSid; - public UserBindingFetcher(final String pathServiceSid, final String pathUserSid, final String pathSid){ + public UserBindingFetcher( + final String pathServiceSid, + final String pathUserSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathUserSid = pathUserSid; this.pathSid = pathSid; } - @Override public UserBinding fetch(final TwilioRestClient client) { - String path = "/v2/Services/{ServiceSid}/Users/{UserSid}/Bindings/{Sid}"; + String path = + "/v2/Services/{ServiceSid}/Users/{UserSid}/Bindings/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"UserSid"+"}", this.pathUserSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "UserSid" + "}", this.pathUserSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -55,15 +61,23 @@ public UserBinding fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("UserBinding fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "UserBinding fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return UserBinding.fromJson(response.getStream(), client.getObjectMapper()); + return UserBinding.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/chat/v2/service/user/UserBindingReader.java b/src/main/java/com/twilio/rest/chat/v2/service/user/UserBindingReader.java index ed7ed00dbc..7963ae3f14 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/user/UserBindingReader.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/user/UserBindingReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.chat.v2.service.user; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.converter.Promoter; @@ -25,30 +26,37 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - import java.util.List; - public class UserBindingReader extends Reader { + private String pathServiceSid; private String pathUserSid; private List bindingType; private Integer pageSize; - public UserBindingReader(final String pathServiceSid, final String pathUserSid){ + public UserBindingReader( + final String pathServiceSid, + final String pathUserSid + ) { this.pathServiceSid = pathServiceSid; this.pathUserSid = pathUserSid; } - public UserBindingReader setBindingType(final List bindingType){ + public UserBindingReader setBindingType( + final List bindingType + ) { this.bindingType = bindingType; return this; } - public UserBindingReader setBindingType(final UserBinding.BindingType bindingType){ + + public UserBindingReader setBindingType( + final UserBinding.BindingType bindingType + ) { return setBindingType(Promoter.listOfOne(bindingType)); } - public UserBindingReader setPageSize(final Integer pageSize){ + + public UserBindingReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -60,8 +68,12 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v2/Services/{ServiceSid}/Users/{UserSid}/Bindings"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"UserSid"+"}", this.pathUserSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "UserSid" + "}", this.pathUserSid.toString()); Request request = new Request( HttpMethod.GET, @@ -73,13 +85,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("UserBinding read failed: Unable to connect to server"); + throw new ApiConnectionException( + "UserBinding read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -95,7 +115,10 @@ private Page pageForRequest(final TwilioRestClient client, final Re } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.CHAT.toString()) @@ -103,9 +126,11 @@ public Page previousPage(final Page page, final Twilio return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.CHAT.toString()) @@ -114,14 +139,15 @@ public Page nextPage(final Page page, final TwilioRest } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (bindingType != null) { for (UserBinding.BindingType prop : bindingType) { @@ -129,11 +155,10 @@ private void addQueryParams(final Request request) { } } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/chat/v2/service/user/UserChannel.java b/src/main/java/com/twilio/rest/chat/v2/service/user/UserChannel.java index 96928d3dac..11195b322b 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/user/UserChannel.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/user/UserChannel.java @@ -23,50 +23,76 @@ import com.twilio.base.Resource; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class UserChannel extends Resource { + private static final long serialVersionUID = 104594062960806L; - public static UserChannelDeleter deleter(final String pathServiceSid, final String pathUserSid, final String pathChannelSid){ - return new UserChannelDeleter(pathServiceSid, pathUserSid, pathChannelSid); + public static UserChannelDeleter deleter( + final String pathServiceSid, + final String pathUserSid, + final String pathChannelSid + ) { + return new UserChannelDeleter( + pathServiceSid, + pathUserSid, + pathChannelSid + ); } - public static UserChannelFetcher fetcher(final String pathServiceSid, final String pathUserSid, final String pathChannelSid){ - return new UserChannelFetcher(pathServiceSid, pathUserSid, pathChannelSid); + public static UserChannelFetcher fetcher( + final String pathServiceSid, + final String pathUserSid, + final String pathChannelSid + ) { + return new UserChannelFetcher( + pathServiceSid, + pathUserSid, + pathChannelSid + ); } - public static UserChannelReader reader(final String pathServiceSid, final String pathUserSid){ + public static UserChannelReader reader( + final String pathServiceSid, + final String pathUserSid + ) { return new UserChannelReader(pathServiceSid, pathUserSid); } - public static UserChannelUpdater updater(final String pathServiceSid, final String pathUserSid, final String pathChannelSid){ - return new UserChannelUpdater(pathServiceSid, pathUserSid, pathChannelSid); + public static UserChannelUpdater updater( + final String pathServiceSid, + final String pathUserSid, + final String pathChannelSid + ) { + return new UserChannelUpdater( + pathServiceSid, + pathUserSid, + pathChannelSid + ); } /** - * Converts a JSON String into a UserChannel object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return UserChannel object represented by the provided JSON - */ - public static UserChannel fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a UserChannel object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return UserChannel object represented by the provided JSON + */ + public static UserChannel fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, UserChannel.class); @@ -78,14 +104,17 @@ public static UserChannel fromJson(final String json, final ObjectMapper objectM } /** - * Converts a JSON InputStream into a UserChannel object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return UserChannel object represented by the provided JSON - */ - public static UserChannel fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a UserChannel object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return UserChannel object represented by the provided JSON + */ + public static UserChannel fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, UserChannel.class); @@ -95,6 +124,7 @@ public static UserChannel fromJson(final InputStream json, final ObjectMapper ob throw new ApiConnectionException(e.getMessage(), e); } } + public enum ChannelStatus { JOINED("joined"), INVITED("invited"), @@ -115,6 +145,7 @@ public static ChannelStatus forValue(final String value) { return Promoter.enumFromString(value, ChannelStatus.values()); } } + public enum NotificationLevel { DEFAULT("default"), MUTED("muted"); @@ -134,6 +165,7 @@ public static NotificationLevel forValue(final String value) { return Promoter.enumFromString(value, NotificationLevel.values()); } } + public enum WebhookEnabledType { TRUE("true"), FALSE("false"); @@ -168,38 +200,23 @@ public static WebhookEnabledType forValue(final String value) { @JsonCreator private UserChannel( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("channel_sid") - final String channelSid, - - @JsonProperty("user_sid") - final String userSid, - - @JsonProperty("member_sid") - final String memberSid, - - @JsonProperty("status") - final UserChannel.ChannelStatus status, - - @JsonProperty("last_consumed_message_index") - final Integer lastConsumedMessageIndex, - - @JsonProperty("unread_messages_count") - final Integer unreadMessagesCount, - - @JsonProperty("links") - final Map links, - - @JsonProperty("url") - final URI url, - - @JsonProperty("notification_level") - final UserChannel.NotificationLevel notificationLevel + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("channel_sid") final String channelSid, + @JsonProperty("user_sid") final String userSid, + @JsonProperty("member_sid") final String memberSid, + @JsonProperty("status") final UserChannel.ChannelStatus status, + @JsonProperty( + "last_consumed_message_index" + ) final Integer lastConsumedMessageIndex, + @JsonProperty( + "unread_messages_count" + ) final Integer unreadMessagesCount, + @JsonProperty("links") final Map links, + @JsonProperty("url") final URI url, + @JsonProperty( + "notification_level" + ) final UserChannel.NotificationLevel notificationLevel ) { this.accountSid = accountSid; this.serviceSid = serviceSid; @@ -214,43 +231,53 @@ private UserChannel( this.notificationLevel = notificationLevel; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final String getChannelSid() { - return this.channelSid; - } - public final String getUserSid() { - return this.userSid; - } - public final String getMemberSid() { - return this.memberSid; - } - public final UserChannel.ChannelStatus getStatus() { - return this.status; - } - public final Integer getLastConsumedMessageIndex() { - return this.lastConsumedMessageIndex; - } - public final Integer getUnreadMessagesCount() { - return this.unreadMessagesCount; - } - public final Map getLinks() { - return this.links; - } - public final URI getUrl() { - return this.url; - } - public final UserChannel.NotificationLevel getNotificationLevel() { - return this.notificationLevel; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final String getChannelSid() { + return this.channelSid; + } + + public final String getUserSid() { + return this.userSid; + } + + public final String getMemberSid() { + return this.memberSid; + } + + public final UserChannel.ChannelStatus getStatus() { + return this.status; + } + + public final Integer getLastConsumedMessageIndex() { + return this.lastConsumedMessageIndex; + } + + public final Integer getUnreadMessagesCount() { + return this.unreadMessagesCount; + } + + public final Map getLinks() { + return this.links; + } + + public final URI getUrl() { + return this.url; + } + + public final UserChannel.NotificationLevel getNotificationLevel() { + return this.notificationLevel; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -260,13 +287,38 @@ public boolean equals(final Object o) { UserChannel other = (UserChannel) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(channelSid, other.channelSid) && Objects.equals(userSid, other.userSid) && Objects.equals(memberSid, other.memberSid) && Objects.equals(status, other.status) && Objects.equals(lastConsumedMessageIndex, other.lastConsumedMessageIndex) && Objects.equals(unreadMessagesCount, other.unreadMessagesCount) && Objects.equals(links, other.links) && Objects.equals(url, other.url) && Objects.equals(notificationLevel, other.notificationLevel) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(channelSid, other.channelSid) && + Objects.equals(userSid, other.userSid) && + Objects.equals(memberSid, other.memberSid) && + Objects.equals(status, other.status) && + Objects.equals( + lastConsumedMessageIndex, + other.lastConsumedMessageIndex + ) && + Objects.equals(unreadMessagesCount, other.unreadMessagesCount) && + Objects.equals(links, other.links) && + Objects.equals(url, other.url) && + Objects.equals(notificationLevel, other.notificationLevel) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, serviceSid, channelSid, userSid, memberSid, status, lastConsumedMessageIndex, unreadMessagesCount, links, url, notificationLevel); + return Objects.hash( + accountSid, + serviceSid, + channelSid, + userSid, + memberSid, + status, + lastConsumedMessageIndex, + unreadMessagesCount, + links, + url, + notificationLevel + ); } - } - diff --git a/src/main/java/com/twilio/rest/chat/v2/service/user/UserChannelDeleter.java b/src/main/java/com/twilio/rest/chat/v2/service/user/UserChannelDeleter.java index 9f0391a164..d30a5ed2e0 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/user/UserChannelDeleter.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/user/UserChannelDeleter.java @@ -24,32 +24,46 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class UserChannelDeleter extends Deleter { + private String pathServiceSid; private String pathUserSid; private String pathChannelSid; private UserChannel.WebhookEnabledType xTwilioWebhookEnabled; - public UserChannelDeleter(final String pathServiceSid, final String pathUserSid, final String pathChannelSid){ + public UserChannelDeleter( + final String pathServiceSid, + final String pathUserSid, + final String pathChannelSid + ) { this.pathServiceSid = pathServiceSid; this.pathUserSid = pathUserSid; this.pathChannelSid = pathChannelSid; } - public UserChannelDeleter setXTwilioWebhookEnabled(final UserChannel.WebhookEnabledType xTwilioWebhookEnabled){ + public UserChannelDeleter setXTwilioWebhookEnabled( + final UserChannel.WebhookEnabledType xTwilioWebhookEnabled + ) { this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; return this; } @Override public boolean delete(final TwilioRestClient client) { - String path = "/v2/Services/{ServiceSid}/Users/{UserSid}/Channels/{ChannelSid}"; + String path = + "/v2/Services/{ServiceSid}/Users/{UserSid}/Channels/{ChannelSid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"UserSid"+"}", this.pathUserSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "UserSid" + "}", this.pathUserSid.toString()); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); Request request = new Request( HttpMethod.DELETE, @@ -60,9 +74,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("UserChannel delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "UserChannel delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -70,10 +89,13 @@ public boolean delete(final TwilioRestClient client) { } return response.getStatusCode() == 204; } + private void addHeaderParams(final Request request) { if (xTwilioWebhookEnabled != null) { - request.addHeaderParam("X-Twilio-Webhook-Enabled", xTwilioWebhookEnabled.toString()); - + request.addHeaderParam( + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/chat/v2/service/user/UserChannelFetcher.java b/src/main/java/com/twilio/rest/chat/v2/service/user/UserChannelFetcher.java index 08c240b149..328709d60d 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/user/UserChannelFetcher.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/user/UserChannelFetcher.java @@ -24,28 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class UserChannelFetcher extends Fetcher { + private String pathServiceSid; private String pathUserSid; private String pathChannelSid; - public UserChannelFetcher(final String pathServiceSid, final String pathUserSid, final String pathChannelSid){ + public UserChannelFetcher( + final String pathServiceSid, + final String pathUserSid, + final String pathChannelSid + ) { this.pathServiceSid = pathServiceSid; this.pathUserSid = pathUserSid; this.pathChannelSid = pathChannelSid; } - @Override public UserChannel fetch(final TwilioRestClient client) { - String path = "/v2/Services/{ServiceSid}/Users/{UserSid}/Channels/{ChannelSid}"; + String path = + "/v2/Services/{ServiceSid}/Users/{UserSid}/Channels/{ChannelSid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"UserSid"+"}", this.pathUserSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "UserSid" + "}", this.pathUserSid.toString()); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -55,15 +65,23 @@ public UserChannel fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("UserChannel fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "UserChannel fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return UserChannel.fromJson(response.getStream(), client.getObjectMapper()); + return UserChannel.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/chat/v2/service/user/UserChannelReader.java b/src/main/java/com/twilio/rest/chat/v2/service/user/UserChannelReader.java index 7d36c9b314..6cb69cc4f1 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/user/UserChannelReader.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/user/UserChannelReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.chat.v2.service.user; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,21 +25,22 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class UserChannelReader extends Reader { + private String pathServiceSid; private String pathUserSid; private Integer pageSize; - public UserChannelReader(final String pathServiceSid, final String pathUserSid){ + public UserChannelReader( + final String pathServiceSid, + final String pathUserSid + ) { this.pathServiceSid = pathServiceSid; this.pathUserSid = pathUserSid; } - public UserChannelReader setPageSize(final Integer pageSize){ + public UserChannelReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -50,8 +52,12 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v2/Services/{ServiceSid}/Users/{UserSid}/Channels"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"UserSid"+"}", this.pathUserSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "UserSid" + "}", this.pathUserSid.toString()); Request request = new Request( HttpMethod.GET, @@ -63,13 +69,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("UserChannel read failed: Unable to connect to server"); + throw new ApiConnectionException( + "UserChannel read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -85,7 +99,10 @@ private Page pageForRequest(final TwilioRestClient client, final Re } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.CHAT.toString()) @@ -93,9 +110,11 @@ public Page previousPage(final Page page, final Twilio return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.CHAT.toString()) @@ -104,21 +123,21 @@ public Page nextPage(final Page page, final TwilioRest } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/chat/v2/service/user/UserChannelUpdater.java b/src/main/java/com/twilio/rest/chat/v2/service/user/UserChannelUpdater.java index d147bafc09..f0800b59d5 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/user/UserChannelUpdater.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/user/UserChannelUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.chat.v2.service.user; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -23,12 +24,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.time.ZonedDateTime; +public class UserChannelUpdater extends Updater { - -public class UserChannelUpdater extends Updater{ private String pathServiceSid; private String pathUserSid; private String pathChannelSid; @@ -36,64 +35,101 @@ public class UserChannelUpdater extends Updater{ private Integer lastConsumedMessageIndex; private ZonedDateTime lastConsumptionTimestamp; - public UserChannelUpdater(final String pathServiceSid, final String pathUserSid, final String pathChannelSid){ + public UserChannelUpdater( + final String pathServiceSid, + final String pathUserSid, + final String pathChannelSid + ) { this.pathServiceSid = pathServiceSid; this.pathUserSid = pathUserSid; this.pathChannelSid = pathChannelSid; } - public UserChannelUpdater setNotificationLevel(final UserChannel.NotificationLevel notificationLevel){ + public UserChannelUpdater setNotificationLevel( + final UserChannel.NotificationLevel notificationLevel + ) { this.notificationLevel = notificationLevel; return this; } - public UserChannelUpdater setLastConsumedMessageIndex(final Integer lastConsumedMessageIndex){ + + public UserChannelUpdater setLastConsumedMessageIndex( + final Integer lastConsumedMessageIndex + ) { this.lastConsumedMessageIndex = lastConsumedMessageIndex; return this; } - public UserChannelUpdater setLastConsumptionTimestamp(final ZonedDateTime lastConsumptionTimestamp){ + + public UserChannelUpdater setLastConsumptionTimestamp( + final ZonedDateTime lastConsumptionTimestamp + ) { this.lastConsumptionTimestamp = lastConsumptionTimestamp; return this; } @Override - public UserChannel update(final TwilioRestClient client){ - String path = "/v2/Services/{ServiceSid}/Users/{UserSid}/Channels/{ChannelSid}"; + public UserChannel update(final TwilioRestClient client) { + String path = + "/v2/Services/{ServiceSid}/Users/{UserSid}/Channels/{ChannelSid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"UserSid"+"}", this.pathUserSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "UserSid" + "}", this.pathUserSid.toString()); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("UserChannel update failed: Unable to connect to server"); + throw new ApiConnectionException( + "UserChannel update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return UserChannel.fromJson(response.getStream(), client.getObjectMapper()); + return UserChannel.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (notificationLevel != null) { - request.addPostParam("NotificationLevel", notificationLevel.toString()); - + request.addPostParam( + "NotificationLevel", + notificationLevel.toString() + ); } if (lastConsumedMessageIndex != null) { - request.addPostParam("LastConsumedMessageIndex", lastConsumedMessageIndex.toString()); - + request.addPostParam( + "LastConsumedMessageIndex", + lastConsumedMessageIndex.toString() + ); } if (lastConsumptionTimestamp != null) { - request.addPostParam("LastConsumptionTimestamp", lastConsumptionTimestamp.toInstant().toString()); - + request.addPostParam( + "LastConsumptionTimestamp", + lastConsumptionTimestamp.toInstant().toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/chat/v3/Channel.java b/src/main/java/com/twilio/rest/chat/v3/Channel.java index d7d1b039f9..7b89f59d42 100644 --- a/src/main/java/com/twilio/rest/chat/v3/Channel.java +++ b/src/main/java/com/twilio/rest/chat/v3/Channel.java @@ -24,37 +24,39 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Channel extends Resource { + private static final long serialVersionUID = 62753936180140L; - public static ChannelUpdater updater(final String pathServiceSid, final String pathSid){ + public static ChannelUpdater updater( + final String pathServiceSid, + final String pathSid + ) { return new ChannelUpdater(pathServiceSid, pathSid); } /** - * Converts a JSON String into a Channel object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Channel object represented by the provided JSON - */ - public static Channel fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Channel object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Channel object represented by the provided JSON + */ + public static Channel fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Channel.class); @@ -66,14 +68,17 @@ public static Channel fromJson(final String json, final ObjectMapper objectMappe } /** - * Converts a JSON InputStream into a Channel object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Channel object represented by the provided JSON - */ - public static Channel fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Channel object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Channel object represented by the provided JSON + */ + public static Channel fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Channel.class); @@ -83,6 +88,7 @@ public static Channel fromJson(final InputStream json, final ObjectMapper object throw new ApiConnectionException(e.getMessage(), e); } } + public enum ChannelType { PUBLIC("public"), PRIVATE("private"); @@ -102,6 +108,7 @@ public static ChannelType forValue(final String value) { return Promoter.enumFromString(value, ChannelType.values()); } } + public enum WebhookEnabledType { TRUE("true"), FALSE("false"); @@ -139,47 +146,20 @@ public static WebhookEnabledType forValue(final String value) { @JsonCreator private Channel( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("unique_name") - final String uniqueName, - - @JsonProperty("attributes") - final String attributes, - - @JsonProperty("type") - final Channel.ChannelType type, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("created_by") - final String createdBy, - - @JsonProperty("members_count") - final Integer membersCount, - - @JsonProperty("messages_count") - final Integer messagesCount, - - @JsonProperty("messaging_service_sid") - final String messagingServiceSid, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("attributes") final String attributes, + @JsonProperty("type") final Channel.ChannelType type, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("created_by") final String createdBy, + @JsonProperty("members_count") final Integer membersCount, + @JsonProperty("messages_count") final Integer messagesCount, + @JsonProperty("messaging_service_sid") final String messagingServiceSid, + @JsonProperty("url") final URI url ) { this.sid = sid; this.accountSid = accountSid; @@ -197,52 +177,65 @@ private Channel( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getUniqueName() { - return this.uniqueName; - } - public final String getAttributes() { - return this.attributes; - } - public final Channel.ChannelType getType() { - return this.type; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getCreatedBy() { - return this.createdBy; - } - public final Integer getMembersCount() { - return this.membersCount; - } - public final Integer getMessagesCount() { - return this.messagesCount; - } - public final String getMessagingServiceSid() { - return this.messagingServiceSid; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getUniqueName() { + return this.uniqueName; + } + + public final String getAttributes() { + return this.attributes; + } + + public final Channel.ChannelType getType() { + return this.type; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getCreatedBy() { + return this.createdBy; + } + + public final Integer getMembersCount() { + return this.membersCount; + } + + public final Integer getMessagesCount() { + return this.messagesCount; + } + + public final String getMessagingServiceSid() { + return this.messagingServiceSid; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -252,13 +245,41 @@ public boolean equals(final Object o) { Channel other = (Channel) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(uniqueName, other.uniqueName) && Objects.equals(attributes, other.attributes) && Objects.equals(type, other.type) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(createdBy, other.createdBy) && Objects.equals(membersCount, other.membersCount) && Objects.equals(messagesCount, other.messagesCount) && Objects.equals(messagingServiceSid, other.messagingServiceSid) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(attributes, other.attributes) && + Objects.equals(type, other.type) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(createdBy, other.createdBy) && + Objects.equals(membersCount, other.membersCount) && + Objects.equals(messagesCount, other.messagesCount) && + Objects.equals(messagingServiceSid, other.messagingServiceSid) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, serviceSid, friendlyName, uniqueName, attributes, type, dateCreated, dateUpdated, createdBy, membersCount, messagesCount, messagingServiceSid, url); + return Objects.hash( + sid, + accountSid, + serviceSid, + friendlyName, + uniqueName, + attributes, + type, + dateCreated, + dateUpdated, + createdBy, + membersCount, + messagesCount, + messagingServiceSid, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/chat/v3/ChannelUpdater.java b/src/main/java/com/twilio/rest/chat/v3/ChannelUpdater.java index a0df97ad16..2400e23910 100644 --- a/src/main/java/com/twilio/rest/chat/v3/ChannelUpdater.java +++ b/src/main/java/com/twilio/rest/chat/v3/ChannelUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.chat.v3; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,53 +25,67 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class ChannelUpdater extends Updater { - - -public class ChannelUpdater extends Updater{ private String pathServiceSid; private String pathSid; private Channel.WebhookEnabledType xTwilioWebhookEnabled; private Channel.ChannelType type; private String messagingServiceSid; - public ChannelUpdater(final String pathServiceSid, final String pathSid){ + public ChannelUpdater(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - public ChannelUpdater setXTwilioWebhookEnabled(final Channel.WebhookEnabledType xTwilioWebhookEnabled){ + public ChannelUpdater setXTwilioWebhookEnabled( + final Channel.WebhookEnabledType xTwilioWebhookEnabled + ) { this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; return this; } - public ChannelUpdater setType(final Channel.ChannelType type){ + + public ChannelUpdater setType(final Channel.ChannelType type) { this.type = type; return this; } - public ChannelUpdater setMessagingServiceSid(final String messagingServiceSid){ + + public ChannelUpdater setMessagingServiceSid( + final String messagingServiceSid + ) { this.messagingServiceSid = messagingServiceSid; return this; } @Override - public Channel update(final TwilioRestClient client){ + public Channel update(final TwilioRestClient client) { String path = "/v3/Services/{ServiceSid}/Channels/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); addHeaderParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Channel update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Channel update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -79,20 +94,22 @@ public Channel update(final TwilioRestClient client){ return Channel.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (type != null) { request.addPostParam("Type", type.toString()); - } if (messagingServiceSid != null) { request.addPostParam("MessagingServiceSid", messagingServiceSid); - } } + private void addHeaderParams(final Request request) { if (xTwilioWebhookEnabled != null) { - request.addHeaderParam("X-Twilio-Webhook-Enabled", xTwilioWebhookEnabled.toString()); - + request.addHeaderParam( + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/content/v1/Content.java b/src/main/java/com/twilio/rest/content/v1/Content.java index 7c857803ea..7fea420e96 100644 --- a/src/main/java/com/twilio/rest/content/v1/Content.java +++ b/src/main/java/com/twilio/rest/content/v1/Content.java @@ -23,47 +23,46 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Content extends Resource { + private static final long serialVersionUID = 58899890984300L; - public static ContentDeleter deleter(final String pathSid){ + public static ContentDeleter deleter(final String pathSid) { return new ContentDeleter(pathSid); } - public static ContentFetcher fetcher(final String pathSid){ + public static ContentFetcher fetcher(final String pathSid) { return new ContentFetcher(pathSid); } - public static ContentReader reader(){ + public static ContentReader reader() { return new ContentReader(); } /** - * Converts a JSON String into a Content object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Content object represented by the provided JSON - */ - public static Content fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Content object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Content object represented by the provided JSON + */ + public static Content fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Content.class); @@ -75,14 +74,17 @@ public static Content fromJson(final String json, final ObjectMapper objectMappe } /** - * Converts a JSON InputStream into a Content object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Content object represented by the provided JSON - */ - public static Content fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Content object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Content object represented by the provided JSON + */ + public static Content fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Content.class); @@ -106,35 +108,16 @@ public static Content fromJson(final InputStream json, final ObjectMapper object @JsonCreator private Content( - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("language") - final String language, - - @JsonProperty("variables") - final Map variables, - - @JsonProperty("types") - final Map types, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("language") final String language, + @JsonProperty("variables") final Map variables, + @JsonProperty("types") final Map types, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); @@ -148,40 +131,49 @@ private Content( this.links = links; } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getLanguage() { - return this.language; - } - public final Map getVariables() { - return this.variables; - } - public final Map getTypes() { - return this.types; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getLanguage() { + return this.language; + } + + public final Map getVariables() { + return this.variables; + } + + public final Map getTypes() { + return this.types; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -191,13 +183,33 @@ public boolean equals(final Object o) { Content other = (Content) o; - return Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(language, other.language) && Objects.equals(variables, other.variables) && Objects.equals(types, other.types) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(language, other.language) && + Objects.equals(variables, other.variables) && + Objects.equals(types, other.types) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(dateCreated, dateUpdated, sid, accountSid, friendlyName, language, variables, types, url, links); + return Objects.hash( + dateCreated, + dateUpdated, + sid, + accountSid, + friendlyName, + language, + variables, + types, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/content/v1/ContentAndApprovals.java b/src/main/java/com/twilio/rest/content/v1/ContentAndApprovals.java index 76048535b2..c8ee10317d 100644 --- a/src/main/java/com/twilio/rest/content/v1/ContentAndApprovals.java +++ b/src/main/java/com/twilio/rest/content/v1/ContentAndApprovals.java @@ -23,38 +23,37 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class ContentAndApprovals extends Resource { + private static final long serialVersionUID = 67575038421166L; - public static ContentAndApprovalsReader reader(){ + public static ContentAndApprovalsReader reader() { return new ContentAndApprovalsReader(); } /** - * Converts a JSON String into a ContentAndApprovals object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return ContentAndApprovals object represented by the provided JSON - */ - public static ContentAndApprovals fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a ContentAndApprovals object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return ContentAndApprovals object represented by the provided JSON + */ + public static ContentAndApprovals fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, ContentAndApprovals.class); @@ -66,14 +65,17 @@ public static ContentAndApprovals fromJson(final String json, final ObjectMapper } /** - * Converts a JSON InputStream into a ContentAndApprovals object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return ContentAndApprovals object represented by the provided JSON - */ - public static ContentAndApprovals fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a ContentAndApprovals object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return ContentAndApprovals object represented by the provided JSON + */ + public static ContentAndApprovals fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, ContentAndApprovals.class); @@ -96,32 +98,17 @@ public static ContentAndApprovals fromJson(final InputStream json, final ObjectM @JsonCreator private ContentAndApprovals( - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("language") - final String language, - - @JsonProperty("variables") - final Map variables, - - @JsonProperty("types") - final Map types, - - @JsonProperty("approval_requests") - final Map approvalRequests + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("language") final String language, + @JsonProperty("variables") final Map variables, + @JsonProperty("types") final Map types, + @JsonProperty( + "approval_requests" + ) final Map approvalRequests ) { this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); @@ -134,37 +121,45 @@ private ContentAndApprovals( this.approvalRequests = approvalRequests; } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getLanguage() { - return this.language; - } - public final Map getVariables() { - return this.variables; - } - public final Map getTypes() { - return this.types; - } - public final Map getApprovalRequests() { - return this.approvalRequests; - } + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getLanguage() { + return this.language; + } + + public final Map getVariables() { + return this.variables; + } + + public final Map getTypes() { + return this.types; + } + + public final Map getApprovalRequests() { + return this.approvalRequests; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -174,13 +169,31 @@ public boolean equals(final Object o) { ContentAndApprovals other = (ContentAndApprovals) o; - return Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(language, other.language) && Objects.equals(variables, other.variables) && Objects.equals(types, other.types) && Objects.equals(approvalRequests, other.approvalRequests) ; + return ( + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(language, other.language) && + Objects.equals(variables, other.variables) && + Objects.equals(types, other.types) && + Objects.equals(approvalRequests, other.approvalRequests) + ); } @Override public int hashCode() { - return Objects.hash(dateCreated, dateUpdated, sid, accountSid, friendlyName, language, variables, types, approvalRequests); + return Objects.hash( + dateCreated, + dateUpdated, + sid, + accountSid, + friendlyName, + language, + variables, + types, + approvalRequests + ); } - } - diff --git a/src/main/java/com/twilio/rest/content/v1/ContentAndApprovalsReader.java b/src/main/java/com/twilio/rest/content/v1/ContentAndApprovalsReader.java index 3c1727d762..949867ce28 100644 --- a/src/main/java/com/twilio/rest/content/v1/ContentAndApprovalsReader.java +++ b/src/main/java/com/twilio/rest/content/v1/ContentAndApprovalsReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.content.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,23 +25,22 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class ContentAndApprovalsReader extends Reader { + private Integer pageSize; - public ContentAndApprovalsReader(){ - } + public ContentAndApprovalsReader() {} - public ContentAndApprovalsReader setPageSize(final Integer pageSize){ + public ContentAndApprovalsReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @Override - public ResourceSet read(final TwilioRestClient client) { + public ResourceSet read( + final TwilioRestClient client + ) { return new ResourceSet<>(this, client, firstPage(client)); } @@ -57,13 +57,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("ContentAndApprovals read failed: Unable to connect to server"); + throw new ApiConnectionException( + "ContentAndApprovals read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -79,7 +87,10 @@ private Page pageForRequest(final TwilioRestClient client, } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.CONTENT.toString()) @@ -87,9 +98,11 @@ public Page previousPage(final Page pa return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.CONTENT.toString()) @@ -98,21 +111,21 @@ public Page nextPage(final Page page, } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/content/v1/ContentDeleter.java b/src/main/java/com/twilio/rest/content/v1/ContentDeleter.java index b55120cd4c..671f4f133c 100644 --- a/src/main/java/com/twilio/rest/content/v1/ContentDeleter.java +++ b/src/main/java/com/twilio/rest/content/v1/ContentDeleter.java @@ -24,21 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class ContentDeleter extends Deleter { + private String pathSid; - public ContentDeleter(final String pathSid){ + public ContentDeleter(final String pathSid) { this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Content/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -48,9 +46,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Content delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Content delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/content/v1/ContentFetcher.java b/src/main/java/com/twilio/rest/content/v1/ContentFetcher.java index bafda58a57..34b143c9b4 100644 --- a/src/main/java/com/twilio/rest/content/v1/ContentFetcher.java +++ b/src/main/java/com/twilio/rest/content/v1/ContentFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class ContentFetcher extends Fetcher { + private String pathSid; - public ContentFetcher(final String pathSid){ + public ContentFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public Content fetch(final TwilioRestClient client) { String path = "/v1/Content/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,9 +46,14 @@ public Content fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Content fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Content fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/content/v1/ContentReader.java b/src/main/java/com/twilio/rest/content/v1/ContentReader.java index b1386b00b4..680dbfb7a7 100644 --- a/src/main/java/com/twilio/rest/content/v1/ContentReader.java +++ b/src/main/java/com/twilio/rest/content/v1/ContentReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.content.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,17 +25,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class ContentReader extends Reader { + private Integer pageSize; - public ContentReader(){ - } + public ContentReader() {} - public ContentReader setPageSize(final Integer pageSize){ + public ContentReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -57,13 +55,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Content read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Content read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -79,7 +85,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reques } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.CONTENT.toString()) @@ -87,9 +96,11 @@ public Page previousPage(final Page page, final TwilioRestClie return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.CONTENT.toString()) @@ -98,21 +109,21 @@ public Page nextPage(final Page page, final TwilioRestClient c } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/content/v1/LegacyContent.java b/src/main/java/com/twilio/rest/content/v1/LegacyContent.java index 0da190cd2b..131390a1b8 100644 --- a/src/main/java/com/twilio/rest/content/v1/LegacyContent.java +++ b/src/main/java/com/twilio/rest/content/v1/LegacyContent.java @@ -23,39 +23,38 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class LegacyContent extends Resource { + private static final long serialVersionUID = 57833124155343L; - public static LegacyContentReader reader(){ + public static LegacyContentReader reader() { return new LegacyContentReader(); } /** - * Converts a JSON String into a LegacyContent object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return LegacyContent object represented by the provided JSON - */ - public static LegacyContent fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a LegacyContent object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return LegacyContent object represented by the provided JSON + */ + public static LegacyContent fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, LegacyContent.class); @@ -67,14 +66,17 @@ public static LegacyContent fromJson(final String json, final ObjectMapper objec } /** - * Converts a JSON InputStream into a LegacyContent object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return LegacyContent object represented by the provided JSON - */ - public static LegacyContent fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a LegacyContent object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return LegacyContent object represented by the provided JSON + */ + public static LegacyContent fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, LegacyContent.class); @@ -99,38 +101,17 @@ public static LegacyContent fromJson(final InputStream json, final ObjectMapper @JsonCreator private LegacyContent( - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("language") - final String language, - - @JsonProperty("variables") - final Map variables, - - @JsonProperty("types") - final Map types, - - @JsonProperty("legacy_template_name") - final String legacyTemplateName, - - @JsonProperty("legacy_body") - final String legacyBody, - - @JsonProperty("url") - final URI url + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("language") final String language, + @JsonProperty("variables") final Map variables, + @JsonProperty("types") final Map types, + @JsonProperty("legacy_template_name") final String legacyTemplateName, + @JsonProperty("legacy_body") final String legacyBody, + @JsonProperty("url") final URI url ) { this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); @@ -145,43 +126,53 @@ private LegacyContent( this.url = url; } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getLanguage() { - return this.language; - } - public final Map getVariables() { - return this.variables; - } - public final Map getTypes() { - return this.types; - } - public final String getLegacyTemplateName() { - return this.legacyTemplateName; - } - public final String getLegacyBody() { - return this.legacyBody; - } - public final URI getUrl() { - return this.url; - } + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getLanguage() { + return this.language; + } + + public final Map getVariables() { + return this.variables; + } + + public final Map getTypes() { + return this.types; + } + + public final String getLegacyTemplateName() { + return this.legacyTemplateName; + } + + public final String getLegacyBody() { + return this.legacyBody; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -191,13 +182,35 @@ public boolean equals(final Object o) { LegacyContent other = (LegacyContent) o; - return Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(language, other.language) && Objects.equals(variables, other.variables) && Objects.equals(types, other.types) && Objects.equals(legacyTemplateName, other.legacyTemplateName) && Objects.equals(legacyBody, other.legacyBody) && Objects.equals(url, other.url) ; + return ( + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(language, other.language) && + Objects.equals(variables, other.variables) && + Objects.equals(types, other.types) && + Objects.equals(legacyTemplateName, other.legacyTemplateName) && + Objects.equals(legacyBody, other.legacyBody) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(dateCreated, dateUpdated, sid, accountSid, friendlyName, language, variables, types, legacyTemplateName, legacyBody, url); + return Objects.hash( + dateCreated, + dateUpdated, + sid, + accountSid, + friendlyName, + language, + variables, + types, + legacyTemplateName, + legacyBody, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/content/v1/LegacyContentReader.java b/src/main/java/com/twilio/rest/content/v1/LegacyContentReader.java index 91f2985145..27e5242eb8 100644 --- a/src/main/java/com/twilio/rest/content/v1/LegacyContentReader.java +++ b/src/main/java/com/twilio/rest/content/v1/LegacyContentReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.content.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,17 +25,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class LegacyContentReader extends Reader { + private Integer pageSize; - public LegacyContentReader(){ - } + public LegacyContentReader() {} - public LegacyContentReader setPageSize(final Integer pageSize){ + public LegacyContentReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -57,13 +55,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("LegacyContent read failed: Unable to connect to server"); + throw new ApiConnectionException( + "LegacyContent read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -79,7 +85,10 @@ private Page pageForRequest(final TwilioRestClient client, final } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.CONTENT.toString()) @@ -87,9 +96,11 @@ public Page previousPage(final Page page, final Tw return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.CONTENT.toString()) @@ -98,21 +109,21 @@ public Page nextPage(final Page page, final Twilio } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/content/v1/content/ApprovalFetch.java b/src/main/java/com/twilio/rest/content/v1/content/ApprovalFetch.java index 6bad16d863..6893d223b7 100644 --- a/src/main/java/com/twilio/rest/content/v1/content/ApprovalFetch.java +++ b/src/main/java/com/twilio/rest/content/v1/content/ApprovalFetch.java @@ -22,38 +22,37 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class ApprovalFetch extends Resource { + private static final long serialVersionUID = 266557741388539L; - public static ApprovalFetchFetcher fetcher(final String pathSid){ + public static ApprovalFetchFetcher fetcher(final String pathSid) { return new ApprovalFetchFetcher(pathSid); } /** - * Converts a JSON String into a ApprovalFetch object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return ApprovalFetch object represented by the provided JSON - */ - public static ApprovalFetch fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a ApprovalFetch object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return ApprovalFetch object represented by the provided JSON + */ + public static ApprovalFetch fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, ApprovalFetch.class); @@ -65,14 +64,17 @@ public static ApprovalFetch fromJson(final String json, final ObjectMapper objec } /** - * Converts a JSON InputStream into a ApprovalFetch object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return ApprovalFetch object represented by the provided JSON - */ - public static ApprovalFetch fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a ApprovalFetch object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return ApprovalFetch object represented by the provided JSON + */ + public static ApprovalFetch fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, ApprovalFetch.class); @@ -90,17 +92,10 @@ public static ApprovalFetch fromJson(final InputStream json, final ObjectMapper @JsonCreator private ApprovalFetch( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("whatsapp") - final Map whatsapp, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("whatsapp") final Map whatsapp, + @JsonProperty("url") final URI url ) { this.sid = sid; this.accountSid = accountSid; @@ -108,22 +103,25 @@ private ApprovalFetch( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final Map getWhatsapp() { - return this.whatsapp; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final Map getWhatsapp() { + return this.whatsapp; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -133,13 +131,16 @@ public boolean equals(final Object o) { ApprovalFetch other = (ApprovalFetch) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(whatsapp, other.whatsapp) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(whatsapp, other.whatsapp) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { return Objects.hash(sid, accountSid, whatsapp, url); } - } - diff --git a/src/main/java/com/twilio/rest/content/v1/content/ApprovalFetchFetcher.java b/src/main/java/com/twilio/rest/content/v1/content/ApprovalFetchFetcher.java index cf7d3b7090..a136cd189b 100644 --- a/src/main/java/com/twilio/rest/content/v1/content/ApprovalFetchFetcher.java +++ b/src/main/java/com/twilio/rest/content/v1/content/ApprovalFetchFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class ApprovalFetchFetcher extends Fetcher { + private String pathSid; - public ApprovalFetchFetcher(final String pathSid){ + public ApprovalFetchFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public ApprovalFetch fetch(final TwilioRestClient client) { String path = "/v1/Content/{Sid}/ApprovalRequests"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,15 +46,23 @@ public ApprovalFetch fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("ApprovalFetch fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "ApprovalFetch fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return ApprovalFetch.fromJson(response.getStream(), client.getObjectMapper()); + return ApprovalFetch.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/AddressConfiguration.java b/src/main/java/com/twilio/rest/conversations/v1/AddressConfiguration.java index f03ce4ead8..3ae2da631b 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/AddressConfiguration.java +++ b/src/main/java/com/twilio/rest/conversations/v1/AddressConfiguration.java @@ -24,55 +24,57 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class AddressConfiguration extends Resource { + private static final long serialVersionUID = 162346024858734L; - public static AddressConfigurationCreator creator(final AddressConfiguration.Type type, final String address){ + public static AddressConfigurationCreator creator( + final AddressConfiguration.Type type, + final String address + ) { return new AddressConfigurationCreator(type, address); } - public static AddressConfigurationDeleter deleter(final String pathSid){ + public static AddressConfigurationDeleter deleter(final String pathSid) { return new AddressConfigurationDeleter(pathSid); } - public static AddressConfigurationFetcher fetcher(final String pathSid){ + public static AddressConfigurationFetcher fetcher(final String pathSid) { return new AddressConfigurationFetcher(pathSid); } - public static AddressConfigurationReader reader(){ + public static AddressConfigurationReader reader() { return new AddressConfigurationReader(); } - public static AddressConfigurationUpdater updater(final String pathSid){ + public static AddressConfigurationUpdater updater(final String pathSid) { return new AddressConfigurationUpdater(pathSid); } /** - * Converts a JSON String into a AddressConfiguration object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return AddressConfiguration object represented by the provided JSON - */ - public static AddressConfiguration fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a AddressConfiguration object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return AddressConfiguration object represented by the provided JSON + */ + public static AddressConfiguration fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, AddressConfiguration.class); @@ -84,14 +86,17 @@ public static AddressConfiguration fromJson(final String json, final ObjectMappe } /** - * Converts a JSON InputStream into a AddressConfiguration object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return AddressConfiguration object represented by the provided JSON - */ - public static AddressConfiguration fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a AddressConfiguration object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return AddressConfiguration object represented by the provided JSON + */ + public static AddressConfiguration fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, AddressConfiguration.class); @@ -101,6 +106,7 @@ public static AddressConfiguration fromJson(final InputStream json, final Object throw new ApiConnectionException(e.getMessage(), e); } } + public enum AutoCreationType { WEBHOOK("webhook"), STUDIO("studio"), @@ -121,6 +127,7 @@ public static AutoCreationType forValue(final String value) { return Promoter.enumFromString(value, AutoCreationType.values()); } } + public enum Method { GET("GET"), POST("POST"); @@ -140,6 +147,7 @@ public static Method forValue(final String value) { return Promoter.enumFromString(value, Method.values()); } } + public enum Type { SMS("sms"), WHATSAPP("whatsapp"), @@ -175,35 +183,16 @@ public static Type forValue(final String value) { @JsonCreator private AddressConfiguration( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("type") - final String type, - - @JsonProperty("address") - final String address, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("auto_creation") - final Map autoCreation, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url, - - @JsonProperty("address_country") - final String addressCountry + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("type") final String type, + @JsonProperty("address") final String address, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("auto_creation") final Map autoCreation, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url, + @JsonProperty("address_country") final String addressCountry ) { this.sid = sid; this.accountSid = accountSid; @@ -217,40 +206,49 @@ private AddressConfiguration( this.addressCountry = addressCountry; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getType() { - return this.type; - } - public final String getAddress() { - return this.address; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final Map getAutoCreation() { - return this.autoCreation; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } - public final String getAddressCountry() { - return this.addressCountry; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getType() { + return this.type; + } + + public final String getAddress() { + return this.address; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final Map getAutoCreation() { + return this.autoCreation; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } + + public final String getAddressCountry() { + return this.addressCountry; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -260,13 +258,33 @@ public boolean equals(final Object o) { AddressConfiguration other = (AddressConfiguration) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(type, other.type) && Objects.equals(address, other.address) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(autoCreation, other.autoCreation) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) && Objects.equals(addressCountry, other.addressCountry) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(type, other.type) && + Objects.equals(address, other.address) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(autoCreation, other.autoCreation) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) && + Objects.equals(addressCountry, other.addressCountry) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, type, address, friendlyName, autoCreation, dateCreated, dateUpdated, url, addressCountry); + return Objects.hash( + sid, + accountSid, + type, + address, + friendlyName, + autoCreation, + dateCreated, + dateUpdated, + url, + addressCountry + ); } - } - diff --git a/src/main/java/com/twilio/rest/conversations/v1/AddressConfigurationCreator.java b/src/main/java/com/twilio/rest/conversations/v1/AddressConfigurationCreator.java index b7da8c890d..3e10ce5977 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/AddressConfigurationCreator.java +++ b/src/main/java/com/twilio/rest/conversations/v1/AddressConfigurationCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.conversations.v1; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -25,12 +26,10 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.util.List; - import java.util.List; +public class AddressConfigurationCreator extends Creator { - -public class AddressConfigurationCreator extends Creator{ private AddressConfiguration.Type type; private String address; private String friendlyName; @@ -44,139 +43,200 @@ public class AddressConfigurationCreator extends Creator{ private Integer autoCreationStudioRetryCount; private String addressCountry; - public AddressConfigurationCreator(final AddressConfiguration.Type type, final String address) { + public AddressConfigurationCreator( + final AddressConfiguration.Type type, + final String address + ) { this.type = type; this.address = address; } - public AddressConfigurationCreator setType(final AddressConfiguration.Type type){ + public AddressConfigurationCreator setType( + final AddressConfiguration.Type type + ) { this.type = type; return this; } - public AddressConfigurationCreator setAddress(final String address){ + + public AddressConfigurationCreator setAddress(final String address) { this.address = address; return this; } - public AddressConfigurationCreator setFriendlyName(final String friendlyName){ + + public AddressConfigurationCreator setFriendlyName( + final String friendlyName + ) { this.friendlyName = friendlyName; return this; } - public AddressConfigurationCreator setAutoCreationEnabled(final Boolean autoCreationEnabled){ + + public AddressConfigurationCreator setAutoCreationEnabled( + final Boolean autoCreationEnabled + ) { this.autoCreationEnabled = autoCreationEnabled; return this; } - public AddressConfigurationCreator setAutoCreationType(final AddressConfiguration.AutoCreationType autoCreationType){ + + public AddressConfigurationCreator setAutoCreationType( + final AddressConfiguration.AutoCreationType autoCreationType + ) { this.autoCreationType = autoCreationType; return this; } - public AddressConfigurationCreator setAutoCreationConversationServiceSid(final String autoCreationConversationServiceSid){ - this.autoCreationConversationServiceSid = autoCreationConversationServiceSid; + + public AddressConfigurationCreator setAutoCreationConversationServiceSid( + final String autoCreationConversationServiceSid + ) { + this.autoCreationConversationServiceSid = + autoCreationConversationServiceSid; return this; } - public AddressConfigurationCreator setAutoCreationWebhookUrl(final String autoCreationWebhookUrl){ + + public AddressConfigurationCreator setAutoCreationWebhookUrl( + final String autoCreationWebhookUrl + ) { this.autoCreationWebhookUrl = autoCreationWebhookUrl; return this; } - public AddressConfigurationCreator setAutoCreationWebhookMethod(final AddressConfiguration.Method autoCreationWebhookMethod){ + + public AddressConfigurationCreator setAutoCreationWebhookMethod( + final AddressConfiguration.Method autoCreationWebhookMethod + ) { this.autoCreationWebhookMethod = autoCreationWebhookMethod; return this; } - public AddressConfigurationCreator setAutoCreationWebhookFilters(final List autoCreationWebhookFilters){ + + public AddressConfigurationCreator setAutoCreationWebhookFilters( + final List autoCreationWebhookFilters + ) { this.autoCreationWebhookFilters = autoCreationWebhookFilters; return this; } - public AddressConfigurationCreator setAutoCreationWebhookFilters(final String autoCreationWebhookFilters){ - return setAutoCreationWebhookFilters(Promoter.listOfOne(autoCreationWebhookFilters)); + + public AddressConfigurationCreator setAutoCreationWebhookFilters( + final String autoCreationWebhookFilters + ) { + return setAutoCreationWebhookFilters( + Promoter.listOfOne(autoCreationWebhookFilters) + ); } - public AddressConfigurationCreator setAutoCreationStudioFlowSid(final String autoCreationStudioFlowSid){ + + public AddressConfigurationCreator setAutoCreationStudioFlowSid( + final String autoCreationStudioFlowSid + ) { this.autoCreationStudioFlowSid = autoCreationStudioFlowSid; return this; } - public AddressConfigurationCreator setAutoCreationStudioRetryCount(final Integer autoCreationStudioRetryCount){ + + public AddressConfigurationCreator setAutoCreationStudioRetryCount( + final Integer autoCreationStudioRetryCount + ) { this.autoCreationStudioRetryCount = autoCreationStudioRetryCount; return this; } - public AddressConfigurationCreator setAddressCountry(final String addressCountry){ + + public AddressConfigurationCreator setAddressCountry( + final String addressCountry + ) { this.addressCountry = addressCountry; return this; } @Override - public AddressConfiguration create(final TwilioRestClient client){ + public AddressConfiguration create(final TwilioRestClient client) { String path = "/v1/Configuration/Addresses"; - path = path.replace("{"+"Type"+"}", this.type.toString()); - path = path.replace("{"+"Address"+"}", this.address.toString()); + path = path.replace("{" + "Type" + "}", this.type.toString()); + path = path.replace("{" + "Address" + "}", this.address.toString()); Request request = new Request( HttpMethod.POST, Domains.CONVERSATIONS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AddressConfiguration creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "AddressConfiguration creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return AddressConfiguration.fromJson(response.getStream(), client.getObjectMapper()); + return AddressConfiguration.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (type != null) { request.addPostParam("Type", type.toString()); - } if (address != null) { request.addPostParam("Address", address); - } if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (autoCreationEnabled != null) { - request.addPostParam("AutoCreation.Enabled", autoCreationEnabled.toString()); - + request.addPostParam( + "AutoCreation.Enabled", + autoCreationEnabled.toString() + ); } if (autoCreationType != null) { - request.addPostParam("AutoCreation.Type", autoCreationType.toString()); - + request.addPostParam( + "AutoCreation.Type", + autoCreationType.toString() + ); } if (autoCreationConversationServiceSid != null) { - request.addPostParam("AutoCreation.ConversationServiceSid", autoCreationConversationServiceSid); - + request.addPostParam( + "AutoCreation.ConversationServiceSid", + autoCreationConversationServiceSid + ); } if (autoCreationWebhookUrl != null) { - request.addPostParam("AutoCreation.WebhookUrl", autoCreationWebhookUrl); - + request.addPostParam( + "AutoCreation.WebhookUrl", + autoCreationWebhookUrl + ); } if (autoCreationWebhookMethod != null) { - request.addPostParam("AutoCreation.WebhookMethod", autoCreationWebhookMethod.toString()); - + request.addPostParam( + "AutoCreation.WebhookMethod", + autoCreationWebhookMethod.toString() + ); } if (autoCreationWebhookFilters != null) { for (String prop : autoCreationWebhookFilters) { request.addPostParam("AutoCreation.WebhookFilters", prop); } - } if (autoCreationStudioFlowSid != null) { - request.addPostParam("AutoCreation.StudioFlowSid", autoCreationStudioFlowSid); - + request.addPostParam( + "AutoCreation.StudioFlowSid", + autoCreationStudioFlowSid + ); } if (autoCreationStudioRetryCount != null) { - request.addPostParam("AutoCreation.StudioRetryCount", autoCreationStudioRetryCount.toString()); - + request.addPostParam( + "AutoCreation.StudioRetryCount", + autoCreationStudioRetryCount.toString() + ); } if (addressCountry != null) { request.addPostParam("AddressCountry", addressCountry); - } } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/AddressConfigurationDeleter.java b/src/main/java/com/twilio/rest/conversations/v1/AddressConfigurationDeleter.java index 8d84fa55af..0a2e569d35 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/AddressConfigurationDeleter.java +++ b/src/main/java/com/twilio/rest/conversations/v1/AddressConfigurationDeleter.java @@ -24,21 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class AddressConfigurationDeleter extends Deleter { + private String pathSid; - public AddressConfigurationDeleter(final String pathSid){ + public AddressConfigurationDeleter(final String pathSid) { this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Configuration/Addresses/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -48,9 +46,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AddressConfiguration delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "AddressConfiguration delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/conversations/v1/AddressConfigurationFetcher.java b/src/main/java/com/twilio/rest/conversations/v1/AddressConfigurationFetcher.java index a5279d45d6..97ebb07d7c 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/AddressConfigurationFetcher.java +++ b/src/main/java/com/twilio/rest/conversations/v1/AddressConfigurationFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class AddressConfigurationFetcher extends Fetcher { + private String pathSid; - public AddressConfigurationFetcher(final String pathSid){ + public AddressConfigurationFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public AddressConfiguration fetch(final TwilioRestClient client) { String path = "/v1/Configuration/Addresses/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,15 +46,23 @@ public AddressConfiguration fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AddressConfiguration fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "AddressConfiguration fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return AddressConfiguration.fromJson(response.getStream(), client.getObjectMapper()); + return AddressConfiguration.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/AddressConfigurationReader.java b/src/main/java/com/twilio/rest/conversations/v1/AddressConfigurationReader.java index c94546fb19..7f1c417516 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/AddressConfigurationReader.java +++ b/src/main/java/com/twilio/rest/conversations/v1/AddressConfigurationReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.conversations.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,28 +25,28 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class AddressConfigurationReader extends Reader { + private String type; private Integer pageSize; - public AddressConfigurationReader(){ - } + public AddressConfigurationReader() {} - public AddressConfigurationReader setType(final String type){ + public AddressConfigurationReader setType(final String type) { this.type = type; return this; } - public AddressConfigurationReader setPageSize(final Integer pageSize){ + + public AddressConfigurationReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @Override - public ResourceSet read(final TwilioRestClient client) { + public ResourceSet read( + final TwilioRestClient client + ) { return new ResourceSet<>(this, client, firstPage(client)); } @@ -62,13 +63,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AddressConfiguration read failed: Unable to connect to server"); + throw new ApiConnectionException( + "AddressConfiguration read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -84,7 +93,10 @@ private Page pageForRequest(final TwilioRestClient client, } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.CONVERSATIONS.toString()) @@ -92,9 +104,11 @@ public Page previousPage(final Page return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.CONVERSATIONS.toString()) @@ -103,25 +117,24 @@ public Page nextPage(final Page page } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (type != null) { - request.addQueryParam("Type", type); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/AddressConfigurationUpdater.java b/src/main/java/com/twilio/rest/conversations/v1/AddressConfigurationUpdater.java index 1dc2f9f4a7..306c12e7c4 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/AddressConfigurationUpdater.java +++ b/src/main/java/com/twilio/rest/conversations/v1/AddressConfigurationUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.conversations.v1; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -24,12 +25,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - import java.util.List; +public class AddressConfigurationUpdater extends Updater { -public class AddressConfigurationUpdater extends Updater{ private String pathSid; private String friendlyName; private Boolean autoCreationEnabled; @@ -41,113 +40,167 @@ public class AddressConfigurationUpdater extends Updater{ private String autoCreationStudioFlowSid; private Integer autoCreationStudioRetryCount; - public AddressConfigurationUpdater(final String pathSid){ + public AddressConfigurationUpdater(final String pathSid) { this.pathSid = pathSid; } - public AddressConfigurationUpdater setFriendlyName(final String friendlyName){ + public AddressConfigurationUpdater setFriendlyName( + final String friendlyName + ) { this.friendlyName = friendlyName; return this; } - public AddressConfigurationUpdater setAutoCreationEnabled(final Boolean autoCreationEnabled){ + + public AddressConfigurationUpdater setAutoCreationEnabled( + final Boolean autoCreationEnabled + ) { this.autoCreationEnabled = autoCreationEnabled; return this; } - public AddressConfigurationUpdater setAutoCreationType(final AddressConfiguration.AutoCreationType autoCreationType){ + + public AddressConfigurationUpdater setAutoCreationType( + final AddressConfiguration.AutoCreationType autoCreationType + ) { this.autoCreationType = autoCreationType; return this; } - public AddressConfigurationUpdater setAutoCreationConversationServiceSid(final String autoCreationConversationServiceSid){ - this.autoCreationConversationServiceSid = autoCreationConversationServiceSid; + + public AddressConfigurationUpdater setAutoCreationConversationServiceSid( + final String autoCreationConversationServiceSid + ) { + this.autoCreationConversationServiceSid = + autoCreationConversationServiceSid; return this; } - public AddressConfigurationUpdater setAutoCreationWebhookUrl(final String autoCreationWebhookUrl){ + + public AddressConfigurationUpdater setAutoCreationWebhookUrl( + final String autoCreationWebhookUrl + ) { this.autoCreationWebhookUrl = autoCreationWebhookUrl; return this; } - public AddressConfigurationUpdater setAutoCreationWebhookMethod(final AddressConfiguration.Method autoCreationWebhookMethod){ + + public AddressConfigurationUpdater setAutoCreationWebhookMethod( + final AddressConfiguration.Method autoCreationWebhookMethod + ) { this.autoCreationWebhookMethod = autoCreationWebhookMethod; return this; } - public AddressConfigurationUpdater setAutoCreationWebhookFilters(final List autoCreationWebhookFilters){ + + public AddressConfigurationUpdater setAutoCreationWebhookFilters( + final List autoCreationWebhookFilters + ) { this.autoCreationWebhookFilters = autoCreationWebhookFilters; return this; } - public AddressConfigurationUpdater setAutoCreationWebhookFilters(final String autoCreationWebhookFilters){ - return setAutoCreationWebhookFilters(Promoter.listOfOne(autoCreationWebhookFilters)); + + public AddressConfigurationUpdater setAutoCreationWebhookFilters( + final String autoCreationWebhookFilters + ) { + return setAutoCreationWebhookFilters( + Promoter.listOfOne(autoCreationWebhookFilters) + ); } - public AddressConfigurationUpdater setAutoCreationStudioFlowSid(final String autoCreationStudioFlowSid){ + + public AddressConfigurationUpdater setAutoCreationStudioFlowSid( + final String autoCreationStudioFlowSid + ) { this.autoCreationStudioFlowSid = autoCreationStudioFlowSid; return this; } - public AddressConfigurationUpdater setAutoCreationStudioRetryCount(final Integer autoCreationStudioRetryCount){ + + public AddressConfigurationUpdater setAutoCreationStudioRetryCount( + final Integer autoCreationStudioRetryCount + ) { this.autoCreationStudioRetryCount = autoCreationStudioRetryCount; return this; } @Override - public AddressConfiguration update(final TwilioRestClient client){ + public AddressConfiguration update(final TwilioRestClient client) { String path = "/v1/Configuration/Addresses/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.CONVERSATIONS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AddressConfiguration update failed: Unable to connect to server"); + throw new ApiConnectionException( + "AddressConfiguration update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return AddressConfiguration.fromJson(response.getStream(), client.getObjectMapper()); + return AddressConfiguration.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (autoCreationEnabled != null) { - request.addPostParam("AutoCreation.Enabled", autoCreationEnabled.toString()); - + request.addPostParam( + "AutoCreation.Enabled", + autoCreationEnabled.toString() + ); } if (autoCreationType != null) { - request.addPostParam("AutoCreation.Type", autoCreationType.toString()); - + request.addPostParam( + "AutoCreation.Type", + autoCreationType.toString() + ); } if (autoCreationConversationServiceSid != null) { - request.addPostParam("AutoCreation.ConversationServiceSid", autoCreationConversationServiceSid); - + request.addPostParam( + "AutoCreation.ConversationServiceSid", + autoCreationConversationServiceSid + ); } if (autoCreationWebhookUrl != null) { - request.addPostParam("AutoCreation.WebhookUrl", autoCreationWebhookUrl); - + request.addPostParam( + "AutoCreation.WebhookUrl", + autoCreationWebhookUrl + ); } if (autoCreationWebhookMethod != null) { - request.addPostParam("AutoCreation.WebhookMethod", autoCreationWebhookMethod.toString()); - + request.addPostParam( + "AutoCreation.WebhookMethod", + autoCreationWebhookMethod.toString() + ); } if (autoCreationWebhookFilters != null) { for (String prop : autoCreationWebhookFilters) { request.addPostParam("AutoCreation.WebhookFilters", prop); } - } if (autoCreationStudioFlowSid != null) { - request.addPostParam("AutoCreation.StudioFlowSid", autoCreationStudioFlowSid); - + request.addPostParam( + "AutoCreation.StudioFlowSid", + autoCreationStudioFlowSid + ); } if (autoCreationStudioRetryCount != null) { - request.addPostParam("AutoCreation.StudioRetryCount", autoCreationStudioRetryCount.toString()); - + request.addPostParam( + "AutoCreation.StudioRetryCount", + autoCreationStudioRetryCount.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/Configuration.java b/src/main/java/com/twilio/rest/conversations/v1/Configuration.java index 05c210a8bf..e426d2f468 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/Configuration.java +++ b/src/main/java/com/twilio/rest/conversations/v1/Configuration.java @@ -22,42 +22,41 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Configuration extends Resource { + private static final long serialVersionUID = 31286932068884L; - public static ConfigurationFetcher fetcher(){ + public static ConfigurationFetcher fetcher() { return new ConfigurationFetcher(); } - public static ConfigurationUpdater updater(){ + public static ConfigurationUpdater updater() { return new ConfigurationUpdater(); } /** - * Converts a JSON String into a Configuration object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Configuration object represented by the provided JSON - */ - public static Configuration fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Configuration object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Configuration object represented by the provided JSON + */ + public static Configuration fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Configuration.class); @@ -69,14 +68,17 @@ public static Configuration fromJson(final String json, final ObjectMapper objec } /** - * Converts a JSON InputStream into a Configuration object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Configuration object represented by the provided JSON - */ - public static Configuration fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Configuration object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Configuration object represented by the provided JSON + */ + public static Configuration fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Configuration.class); @@ -97,26 +99,19 @@ public static Configuration fromJson(final InputStream json, final ObjectMapper @JsonCreator private Configuration( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("default_chat_service_sid") - final String defaultChatServiceSid, - - @JsonProperty("default_messaging_service_sid") - final String defaultMessagingServiceSid, - - @JsonProperty("default_inactive_timer") - final String defaultInactiveTimer, - - @JsonProperty("default_closed_timer") - final String defaultClosedTimer, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("account_sid") final String accountSid, + @JsonProperty( + "default_chat_service_sid" + ) final String defaultChatServiceSid, + @JsonProperty( + "default_messaging_service_sid" + ) final String defaultMessagingServiceSid, + @JsonProperty( + "default_inactive_timer" + ) final String defaultInactiveTimer, + @JsonProperty("default_closed_timer") final String defaultClosedTimer, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.accountSid = accountSid; this.defaultChatServiceSid = defaultChatServiceSid; @@ -127,31 +122,37 @@ private Configuration( this.links = links; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getDefaultChatServiceSid() { - return this.defaultChatServiceSid; - } - public final String getDefaultMessagingServiceSid() { - return this.defaultMessagingServiceSid; - } - public final String getDefaultInactiveTimer() { - return this.defaultInactiveTimer; - } - public final String getDefaultClosedTimer() { - return this.defaultClosedTimer; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getDefaultChatServiceSid() { + return this.defaultChatServiceSid; + } + + public final String getDefaultMessagingServiceSid() { + return this.defaultMessagingServiceSid; + } + + public final String getDefaultInactiveTimer() { + return this.defaultInactiveTimer; + } + + public final String getDefaultClosedTimer() { + return this.defaultClosedTimer; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -161,13 +162,33 @@ public boolean equals(final Object o) { Configuration other = (Configuration) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(defaultChatServiceSid, other.defaultChatServiceSid) && Objects.equals(defaultMessagingServiceSid, other.defaultMessagingServiceSid) && Objects.equals(defaultInactiveTimer, other.defaultInactiveTimer) && Objects.equals(defaultClosedTimer, other.defaultClosedTimer) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals( + defaultChatServiceSid, + other.defaultChatServiceSid + ) && + Objects.equals( + defaultMessagingServiceSid, + other.defaultMessagingServiceSid + ) && + Objects.equals(defaultInactiveTimer, other.defaultInactiveTimer) && + Objects.equals(defaultClosedTimer, other.defaultClosedTimer) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, defaultChatServiceSid, defaultMessagingServiceSid, defaultInactiveTimer, defaultClosedTimer, url, links); + return Objects.hash( + accountSid, + defaultChatServiceSid, + defaultMessagingServiceSid, + defaultInactiveTimer, + defaultClosedTimer, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/conversations/v1/ConfigurationFetcher.java b/src/main/java/com/twilio/rest/conversations/v1/ConfigurationFetcher.java index a0c4c8e718..52ce05982b 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/ConfigurationFetcher.java +++ b/src/main/java/com/twilio/rest/conversations/v1/ConfigurationFetcher.java @@ -24,20 +24,14 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class ConfigurationFetcher extends Fetcher { - public ConfigurationFetcher(){ - } - + public ConfigurationFetcher() {} @Override public Configuration fetch(final TwilioRestClient client) { String path = "/v1/Configuration"; - Request request = new Request( HttpMethod.GET, Domains.CONVERSATIONS.toString(), @@ -46,15 +40,23 @@ public Configuration fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Configuration fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Configuration fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Configuration.fromJson(response.getStream(), client.getObjectMapper()); + return Configuration.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/ConfigurationUpdater.java b/src/main/java/com/twilio/rest/conversations/v1/ConfigurationUpdater.java index 13ba6b33f5..a822840863 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/ConfigurationUpdater.java +++ b/src/main/java/com/twilio/rest/conversations/v1/ConfigurationUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.conversations.v1; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,75 +25,94 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class ConfigurationUpdater extends Updater { - - -public class ConfigurationUpdater extends Updater{ private String defaultChatServiceSid; private String defaultMessagingServiceSid; private String defaultInactiveTimer; private String defaultClosedTimer; - public ConfigurationUpdater(){ - } + public ConfigurationUpdater() {} - public ConfigurationUpdater setDefaultChatServiceSid(final String defaultChatServiceSid){ + public ConfigurationUpdater setDefaultChatServiceSid( + final String defaultChatServiceSid + ) { this.defaultChatServiceSid = defaultChatServiceSid; return this; } - public ConfigurationUpdater setDefaultMessagingServiceSid(final String defaultMessagingServiceSid){ + + public ConfigurationUpdater setDefaultMessagingServiceSid( + final String defaultMessagingServiceSid + ) { this.defaultMessagingServiceSid = defaultMessagingServiceSid; return this; } - public ConfigurationUpdater setDefaultInactiveTimer(final String defaultInactiveTimer){ + + public ConfigurationUpdater setDefaultInactiveTimer( + final String defaultInactiveTimer + ) { this.defaultInactiveTimer = defaultInactiveTimer; return this; } - public ConfigurationUpdater setDefaultClosedTimer(final String defaultClosedTimer){ + + public ConfigurationUpdater setDefaultClosedTimer( + final String defaultClosedTimer + ) { this.defaultClosedTimer = defaultClosedTimer; return this; } @Override - public Configuration update(final TwilioRestClient client){ + public Configuration update(final TwilioRestClient client) { String path = "/v1/Configuration"; - Request request = new Request( HttpMethod.POST, Domains.CONVERSATIONS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Configuration update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Configuration update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Configuration.fromJson(response.getStream(), client.getObjectMapper()); + return Configuration.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (defaultChatServiceSid != null) { - request.addPostParam("DefaultChatServiceSid", defaultChatServiceSid); - + request.addPostParam( + "DefaultChatServiceSid", + defaultChatServiceSid + ); } if (defaultMessagingServiceSid != null) { - request.addPostParam("DefaultMessagingServiceSid", defaultMessagingServiceSid); - + request.addPostParam( + "DefaultMessagingServiceSid", + defaultMessagingServiceSid + ); } if (defaultInactiveTimer != null) { request.addPostParam("DefaultInactiveTimer", defaultInactiveTimer); - } if (defaultClosedTimer != null) { request.addPostParam("DefaultClosedTimer", defaultClosedTimer); - } } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/Conversation.java b/src/main/java/com/twilio/rest/conversations/v1/Conversation.java index c25ea523bd..35e700447f 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/Conversation.java +++ b/src/main/java/com/twilio/rest/conversations/v1/Conversation.java @@ -24,55 +24,54 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Conversation extends Resource { + private static final long serialVersionUID = 208929192266810L; - public static ConversationCreator creator(){ + public static ConversationCreator creator() { return new ConversationCreator(); } - public static ConversationDeleter deleter(final String pathSid){ + public static ConversationDeleter deleter(final String pathSid) { return new ConversationDeleter(pathSid); } - public static ConversationFetcher fetcher(final String pathSid){ + public static ConversationFetcher fetcher(final String pathSid) { return new ConversationFetcher(pathSid); } - public static ConversationReader reader(){ + public static ConversationReader reader() { return new ConversationReader(); } - public static ConversationUpdater updater(final String pathSid){ + public static ConversationUpdater updater(final String pathSid) { return new ConversationUpdater(pathSid); } /** - * Converts a JSON String into a Conversation object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Conversation object represented by the provided JSON - */ - public static Conversation fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Conversation object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Conversation object represented by the provided JSON + */ + public static Conversation fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Conversation.class); @@ -84,14 +83,17 @@ public static Conversation fromJson(final String json, final ObjectMapper object } /** - * Converts a JSON InputStream into a Conversation object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Conversation object represented by the provided JSON - */ - public static Conversation fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Conversation object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Conversation object represented by the provided JSON + */ + public static Conversation fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Conversation.class); @@ -101,6 +103,7 @@ public static Conversation fromJson(final InputStream json, final ObjectMapper o throw new ApiConnectionException(e.getMessage(), e); } } + public enum State { INACTIVE("inactive"), ACTIVE("active"), @@ -121,6 +124,7 @@ public static State forValue(final String value) { return Promoter.enumFromString(value, State.values()); } } + public enum WebhookEnabledType { TRUE("true"), FALSE("false"); @@ -158,47 +162,20 @@ public static WebhookEnabledType forValue(final String value) { @JsonCreator private Conversation( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("chat_service_sid") - final String chatServiceSid, - - @JsonProperty("messaging_service_sid") - final String messagingServiceSid, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("unique_name") - final String uniqueName, - - @JsonProperty("attributes") - final String attributes, - - @JsonProperty("state") - final Conversation.State state, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("timers") - final Map timers, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links, - - @JsonProperty("bindings") - final Map bindings + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("chat_service_sid") final String chatServiceSid, + @JsonProperty("messaging_service_sid") final String messagingServiceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("attributes") final String attributes, + @JsonProperty("state") final Conversation.State state, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("timers") final Map timers, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links, + @JsonProperty("bindings") final Map bindings ) { this.accountSid = accountSid; this.chatServiceSid = chatServiceSid; @@ -216,52 +193,65 @@ private Conversation( this.bindings = bindings; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getChatServiceSid() { - return this.chatServiceSid; - } - public final String getMessagingServiceSid() { - return this.messagingServiceSid; - } - public final String getSid() { - return this.sid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getUniqueName() { - return this.uniqueName; - } - public final String getAttributes() { - return this.attributes; - } - public final Conversation.State getState() { - return this.state; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final Map getTimers() { - return this.timers; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } - public final Map getBindings() { - return this.bindings; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getChatServiceSid() { + return this.chatServiceSid; + } + + public final String getMessagingServiceSid() { + return this.messagingServiceSid; + } + + public final String getSid() { + return this.sid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getUniqueName() { + return this.uniqueName; + } + + public final String getAttributes() { + return this.attributes; + } + + public final Conversation.State getState() { + return this.state; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final Map getTimers() { + return this.timers; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } + + public final Map getBindings() { + return this.bindings; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -271,13 +261,41 @@ public boolean equals(final Object o) { Conversation other = (Conversation) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(chatServiceSid, other.chatServiceSid) && Objects.equals(messagingServiceSid, other.messagingServiceSid) && Objects.equals(sid, other.sid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(uniqueName, other.uniqueName) && Objects.equals(attributes, other.attributes) && Objects.equals(state, other.state) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(timers, other.timers) && Objects.equals(url, other.url) && Objects.equals(links, other.links) && Objects.equals(bindings, other.bindings) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(chatServiceSid, other.chatServiceSid) && + Objects.equals(messagingServiceSid, other.messagingServiceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(attributes, other.attributes) && + Objects.equals(state, other.state) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(timers, other.timers) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) && + Objects.equals(bindings, other.bindings) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, chatServiceSid, messagingServiceSid, sid, friendlyName, uniqueName, attributes, state, dateCreated, dateUpdated, timers, url, links, bindings); + return Objects.hash( + accountSid, + chatServiceSid, + messagingServiceSid, + sid, + friendlyName, + uniqueName, + attributes, + state, + dateCreated, + dateUpdated, + timers, + url, + links, + bindings + ); } - } - diff --git a/src/main/java/com/twilio/rest/conversations/v1/ConversationCreator.java b/src/main/java/com/twilio/rest/conversations/v1/ConversationCreator.java index ba44b488ca..eba926d2c0 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/ConversationCreator.java +++ b/src/main/java/com/twilio/rest/conversations/v1/ConversationCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.conversations.v1; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -25,10 +26,8 @@ import com.twilio.rest.Domains; import java.time.ZonedDateTime; +public class ConversationCreator extends Creator { - - -public class ConversationCreator extends Creator{ private Conversation.WebhookEnabledType xTwilioWebhookEnabled; private String friendlyName; private String uniqueName; @@ -40,117 +39,138 @@ public class ConversationCreator extends Creator{ private String timersInactive; private String timersClosed; - public ConversationCreator() { - } + public ConversationCreator() {} - public ConversationCreator setXTwilioWebhookEnabled(final Conversation.WebhookEnabledType xTwilioWebhookEnabled){ + public ConversationCreator setXTwilioWebhookEnabled( + final Conversation.WebhookEnabledType xTwilioWebhookEnabled + ) { this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; return this; } - public ConversationCreator setFriendlyName(final String friendlyName){ + + public ConversationCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public ConversationCreator setUniqueName(final String uniqueName){ + + public ConversationCreator setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - public ConversationCreator setDateCreated(final ZonedDateTime dateCreated){ + + public ConversationCreator setDateCreated(final ZonedDateTime dateCreated) { this.dateCreated = dateCreated; return this; } - public ConversationCreator setDateUpdated(final ZonedDateTime dateUpdated){ + + public ConversationCreator setDateUpdated(final ZonedDateTime dateUpdated) { this.dateUpdated = dateUpdated; return this; } - public ConversationCreator setMessagingServiceSid(final String messagingServiceSid){ + + public ConversationCreator setMessagingServiceSid( + final String messagingServiceSid + ) { this.messagingServiceSid = messagingServiceSid; return this; } - public ConversationCreator setAttributes(final String attributes){ + + public ConversationCreator setAttributes(final String attributes) { this.attributes = attributes; return this; } - public ConversationCreator setState(final Conversation.State state){ + + public ConversationCreator setState(final Conversation.State state) { this.state = state; return this; } - public ConversationCreator setTimersInactive(final String timersInactive){ + + public ConversationCreator setTimersInactive(final String timersInactive) { this.timersInactive = timersInactive; return this; } - public ConversationCreator setTimersClosed(final String timersClosed){ + + public ConversationCreator setTimersClosed(final String timersClosed) { this.timersClosed = timersClosed; return this; } @Override - public Conversation create(final TwilioRestClient client){ + public Conversation create(final TwilioRestClient client) { String path = "/v1/Conversations"; - Request request = new Request( HttpMethod.POST, Domains.CONVERSATIONS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); addHeaderParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Conversation creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Conversation creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Conversation.fromJson(response.getStream(), client.getObjectMapper()); + return Conversation.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (uniqueName != null) { request.addPostParam("UniqueName", uniqueName); - } if (dateCreated != null) { - request.addPostParam("DateCreated", dateCreated.toInstant().toString()); - + request.addPostParam( + "DateCreated", + dateCreated.toInstant().toString() + ); } if (dateUpdated != null) { - request.addPostParam("DateUpdated", dateUpdated.toInstant().toString()); - + request.addPostParam( + "DateUpdated", + dateUpdated.toInstant().toString() + ); } if (messagingServiceSid != null) { request.addPostParam("MessagingServiceSid", messagingServiceSid); - } if (attributes != null) { request.addPostParam("Attributes", attributes); - } if (state != null) { request.addPostParam("State", state.toString()); - } if (timersInactive != null) { request.addPostParam("Timers.Inactive", timersInactive); - } if (timersClosed != null) { request.addPostParam("Timers.Closed", timersClosed); - } } + private void addHeaderParams(final Request request) { if (xTwilioWebhookEnabled != null) { - request.addHeaderParam("X-Twilio-Webhook-Enabled", xTwilioWebhookEnabled.toString()); - + request.addHeaderParam( + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/ConversationDeleter.java b/src/main/java/com/twilio/rest/conversations/v1/ConversationDeleter.java index 70c8b0c18b..ede58e2527 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/ConversationDeleter.java +++ b/src/main/java/com/twilio/rest/conversations/v1/ConversationDeleter.java @@ -24,17 +24,18 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class ConversationDeleter extends Deleter { + private String pathSid; private Conversation.WebhookEnabledType xTwilioWebhookEnabled; - public ConversationDeleter(final String pathSid){ + public ConversationDeleter(final String pathSid) { this.pathSid = pathSid; } - public ConversationDeleter setXTwilioWebhookEnabled(final Conversation.WebhookEnabledType xTwilioWebhookEnabled){ + public ConversationDeleter setXTwilioWebhookEnabled( + final Conversation.WebhookEnabledType xTwilioWebhookEnabled + ) { this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; return this; } @@ -43,7 +44,7 @@ public ConversationDeleter setXTwilioWebhookEnabled(final Conversation.WebhookEn public boolean delete(final TwilioRestClient client) { String path = "/v1/Conversations/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -54,9 +55,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Conversation delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Conversation delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -64,10 +70,13 @@ public boolean delete(final TwilioRestClient client) { } return response.getStatusCode() == 204; } + private void addHeaderParams(final Request request) { if (xTwilioWebhookEnabled != null) { - request.addHeaderParam("X-Twilio-Webhook-Enabled", xTwilioWebhookEnabled.toString()); - + request.addHeaderParam( + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/ConversationFetcher.java b/src/main/java/com/twilio/rest/conversations/v1/ConversationFetcher.java index db75c650f0..d6b973e1e7 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/ConversationFetcher.java +++ b/src/main/java/com/twilio/rest/conversations/v1/ConversationFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class ConversationFetcher extends Fetcher { + private String pathSid; - public ConversationFetcher(final String pathSid){ + public ConversationFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public Conversation fetch(final TwilioRestClient client) { String path = "/v1/Conversations/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,15 +46,23 @@ public Conversation fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Conversation fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Conversation fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Conversation.fromJson(response.getStream(), client.getObjectMapper()); + return Conversation.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/ConversationReader.java b/src/main/java/com/twilio/rest/conversations/v1/ConversationReader.java index 2f85e33fc3..038210b73e 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/ConversationReader.java +++ b/src/main/java/com/twilio/rest/conversations/v1/ConversationReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.conversations.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,32 +25,32 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class ConversationReader extends Reader { + private String startDate; private String endDate; private Conversation.State state; private Integer pageSize; - public ConversationReader(){ - } + public ConversationReader() {} - public ConversationReader setStartDate(final String startDate){ + public ConversationReader setStartDate(final String startDate) { this.startDate = startDate; return this; } - public ConversationReader setEndDate(final String endDate){ + + public ConversationReader setEndDate(final String endDate) { this.endDate = endDate; return this; } - public ConversationReader setState(final Conversation.State state){ + + public ConversationReader setState(final Conversation.State state) { this.state = state; return this; } - public ConversationReader setPageSize(final Integer pageSize){ + + public ConversationReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -72,13 +73,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Conversation read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Conversation read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -94,7 +103,10 @@ private Page pageForRequest(final TwilioRestClient client, final R } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.CONVERSATIONS.toString()) @@ -102,9 +114,11 @@ public Page previousPage(final Page page, final Twil return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.CONVERSATIONS.toString()) @@ -113,33 +127,30 @@ public Page nextPage(final Page page, final TwilioRe } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (startDate != null) { - request.addQueryParam("StartDate", startDate); } if (endDate != null) { - request.addQueryParam("EndDate", endDate); } if (state != null) { - request.addQueryParam("State", state.toString()); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/ConversationUpdater.java b/src/main/java/com/twilio/rest/conversations/v1/ConversationUpdater.java index 55de1e0e02..14693bef09 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/ConversationUpdater.java +++ b/src/main/java/com/twilio/rest/conversations/v1/ConversationUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.conversations.v1; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -23,12 +24,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.time.ZonedDateTime; +public class ConversationUpdater extends Updater { - -public class ConversationUpdater extends Updater{ private String pathSid; private Conversation.WebhookEnabledType xTwilioWebhookEnabled; private String friendlyName; @@ -41,119 +40,142 @@ public class ConversationUpdater extends Updater{ private String timersClosed; private String uniqueName; - public ConversationUpdater(final String pathSid){ + public ConversationUpdater(final String pathSid) { this.pathSid = pathSid; } - public ConversationUpdater setXTwilioWebhookEnabled(final Conversation.WebhookEnabledType xTwilioWebhookEnabled){ + public ConversationUpdater setXTwilioWebhookEnabled( + final Conversation.WebhookEnabledType xTwilioWebhookEnabled + ) { this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; return this; } - public ConversationUpdater setFriendlyName(final String friendlyName){ + + public ConversationUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public ConversationUpdater setDateCreated(final ZonedDateTime dateCreated){ + + public ConversationUpdater setDateCreated(final ZonedDateTime dateCreated) { this.dateCreated = dateCreated; return this; } - public ConversationUpdater setDateUpdated(final ZonedDateTime dateUpdated){ + + public ConversationUpdater setDateUpdated(final ZonedDateTime dateUpdated) { this.dateUpdated = dateUpdated; return this; } - public ConversationUpdater setAttributes(final String attributes){ + + public ConversationUpdater setAttributes(final String attributes) { this.attributes = attributes; return this; } - public ConversationUpdater setMessagingServiceSid(final String messagingServiceSid){ + + public ConversationUpdater setMessagingServiceSid( + final String messagingServiceSid + ) { this.messagingServiceSid = messagingServiceSid; return this; } - public ConversationUpdater setState(final Conversation.State state){ + + public ConversationUpdater setState(final Conversation.State state) { this.state = state; return this; } - public ConversationUpdater setTimersInactive(final String timersInactive){ + + public ConversationUpdater setTimersInactive(final String timersInactive) { this.timersInactive = timersInactive; return this; } - public ConversationUpdater setTimersClosed(final String timersClosed){ + + public ConversationUpdater setTimersClosed(final String timersClosed) { this.timersClosed = timersClosed; return this; } - public ConversationUpdater setUniqueName(final String uniqueName){ + + public ConversationUpdater setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } @Override - public Conversation update(final TwilioRestClient client){ + public Conversation update(final TwilioRestClient client) { String path = "/v1/Conversations/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.CONVERSATIONS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); addHeaderParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Conversation update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Conversation update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Conversation.fromJson(response.getStream(), client.getObjectMapper()); + return Conversation.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (dateCreated != null) { - request.addPostParam("DateCreated", dateCreated.toInstant().toString()); - + request.addPostParam( + "DateCreated", + dateCreated.toInstant().toString() + ); } if (dateUpdated != null) { - request.addPostParam("DateUpdated", dateUpdated.toInstant().toString()); - + request.addPostParam( + "DateUpdated", + dateUpdated.toInstant().toString() + ); } if (attributes != null) { request.addPostParam("Attributes", attributes); - } if (messagingServiceSid != null) { request.addPostParam("MessagingServiceSid", messagingServiceSid); - } if (state != null) { request.addPostParam("State", state.toString()); - } if (timersInactive != null) { request.addPostParam("Timers.Inactive", timersInactive); - } if (timersClosed != null) { request.addPostParam("Timers.Closed", timersClosed); - } if (uniqueName != null) { request.addPostParam("UniqueName", uniqueName); - } } + private void addHeaderParams(final Request request) { if (xTwilioWebhookEnabled != null) { - request.addHeaderParam("X-Twilio-Webhook-Enabled", xTwilioWebhookEnabled.toString()); - + request.addHeaderParam( + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/Credential.java b/src/main/java/com/twilio/rest/conversations/v1/Credential.java index e075159503..149daf3491 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/Credential.java +++ b/src/main/java/com/twilio/rest/conversations/v1/Credential.java @@ -24,53 +24,52 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Credential extends Resource { + private static final long serialVersionUID = 265726674321801L; - public static CredentialCreator creator(final Credential.PushType type){ + public static CredentialCreator creator(final Credential.PushType type) { return new CredentialCreator(type); } - public static CredentialDeleter deleter(final String pathSid){ + public static CredentialDeleter deleter(final String pathSid) { return new CredentialDeleter(pathSid); } - public static CredentialFetcher fetcher(final String pathSid){ + public static CredentialFetcher fetcher(final String pathSid) { return new CredentialFetcher(pathSid); } - public static CredentialReader reader(){ + public static CredentialReader reader() { return new CredentialReader(); } - public static CredentialUpdater updater(final String pathSid){ + public static CredentialUpdater updater(final String pathSid) { return new CredentialUpdater(pathSid); } /** - * Converts a JSON String into a Credential object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Credential object represented by the provided JSON - */ - public static Credential fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Credential object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Credential object represented by the provided JSON + */ + public static Credential fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Credential.class); @@ -82,14 +81,17 @@ public static Credential fromJson(final String json, final ObjectMapper objectMa } /** - * Converts a JSON InputStream into a Credential object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Credential object represented by the provided JSON - */ - public static Credential fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Credential object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Credential object represented by the provided JSON + */ + public static Credential fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Credential.class); @@ -99,6 +101,7 @@ public static Credential fromJson(final InputStream json, final ObjectMapper obj throw new ApiConnectionException(e.getMessage(), e); } } + public enum PushType { APN("apn"), GCM("gcm"), @@ -131,29 +134,14 @@ public static PushType forValue(final String value) { @JsonCreator private Credential( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("type") - final Credential.PushType type, - - @JsonProperty("sandbox") - final String sandbox, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("type") final Credential.PushType type, + @JsonProperty("sandbox") final String sandbox, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url ) { this.sid = sid; this.accountSid = accountSid; @@ -165,34 +153,41 @@ private Credential( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final Credential.PushType getType() { - return this.type; - } - public final String getSandbox() { - return this.sandbox; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final Credential.PushType getType() { + return this.type; + } + + public final String getSandbox() { + return this.sandbox; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -202,13 +197,29 @@ public boolean equals(final Object o) { Credential other = (Credential) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(type, other.type) && Objects.equals(sandbox, other.sandbox) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(type, other.type) && + Objects.equals(sandbox, other.sandbox) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, friendlyName, type, sandbox, dateCreated, dateUpdated, url); + return Objects.hash( + sid, + accountSid, + friendlyName, + type, + sandbox, + dateCreated, + dateUpdated, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/conversations/v1/CredentialCreator.java b/src/main/java/com/twilio/rest/conversations/v1/CredentialCreator.java index c342164d41..9f0a2eec6a 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/CredentialCreator.java +++ b/src/main/java/com/twilio/rest/conversations/v1/CredentialCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.conversations.v1; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class CredentialCreator extends Creator { - - -public class CredentialCreator extends Creator{ private Credential.PushType type; private String friendlyName; private String certificate; @@ -40,88 +39,97 @@ public CredentialCreator(final Credential.PushType type) { this.type = type; } - public CredentialCreator setType(final Credential.PushType type){ + public CredentialCreator setType(final Credential.PushType type) { this.type = type; return this; } - public CredentialCreator setFriendlyName(final String friendlyName){ + + public CredentialCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public CredentialCreator setCertificate(final String certificate){ + + public CredentialCreator setCertificate(final String certificate) { this.certificate = certificate; return this; } - public CredentialCreator setPrivateKey(final String privateKey){ + + public CredentialCreator setPrivateKey(final String privateKey) { this.privateKey = privateKey; return this; } - public CredentialCreator setSandbox(final Boolean sandbox){ + + public CredentialCreator setSandbox(final Boolean sandbox) { this.sandbox = sandbox; return this; } - public CredentialCreator setApiKey(final String apiKey){ + + public CredentialCreator setApiKey(final String apiKey) { this.apiKey = apiKey; return this; } - public CredentialCreator setSecret(final String secret){ + + public CredentialCreator setSecret(final String secret) { this.secret = secret; return this; } @Override - public Credential create(final TwilioRestClient client){ + public Credential create(final TwilioRestClient client) { String path = "/v1/Credentials"; - path = path.replace("{"+"Type"+"}", this.type.toString()); + path = path.replace("{" + "Type" + "}", this.type.toString()); Request request = new Request( HttpMethod.POST, Domains.CONVERSATIONS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Credential creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Credential creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Credential.fromJson(response.getStream(), client.getObjectMapper()); + return Credential.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (type != null) { request.addPostParam("Type", type.toString()); - } if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (certificate != null) { request.addPostParam("Certificate", certificate); - } if (privateKey != null) { request.addPostParam("PrivateKey", privateKey); - } if (sandbox != null) { request.addPostParam("Sandbox", sandbox.toString()); - } if (apiKey != null) { request.addPostParam("ApiKey", apiKey); - } if (secret != null) { request.addPostParam("Secret", secret); - } } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/CredentialDeleter.java b/src/main/java/com/twilio/rest/conversations/v1/CredentialDeleter.java index 8c64a4653d..838370cd72 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/CredentialDeleter.java +++ b/src/main/java/com/twilio/rest/conversations/v1/CredentialDeleter.java @@ -24,21 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class CredentialDeleter extends Deleter { + private String pathSid; - public CredentialDeleter(final String pathSid){ + public CredentialDeleter(final String pathSid) { this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Credentials/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -48,9 +46,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Credential delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Credential delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/conversations/v1/CredentialFetcher.java b/src/main/java/com/twilio/rest/conversations/v1/CredentialFetcher.java index 4201fbef0b..c9a9ecd9ba 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/CredentialFetcher.java +++ b/src/main/java/com/twilio/rest/conversations/v1/CredentialFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class CredentialFetcher extends Fetcher { + private String pathSid; - public CredentialFetcher(final String pathSid){ + public CredentialFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public Credential fetch(final TwilioRestClient client) { String path = "/v1/Credentials/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,15 +46,23 @@ public Credential fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Credential fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Credential fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Credential.fromJson(response.getStream(), client.getObjectMapper()); + return Credential.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/CredentialReader.java b/src/main/java/com/twilio/rest/conversations/v1/CredentialReader.java index 5be84db304..6178afff5e 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/CredentialReader.java +++ b/src/main/java/com/twilio/rest/conversations/v1/CredentialReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.conversations.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,17 +25,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class CredentialReader extends Reader { + private Integer pageSize; - public CredentialReader(){ - } + public CredentialReader() {} - public CredentialReader setPageSize(final Integer pageSize){ + public CredentialReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -57,13 +55,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Credential read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Credential read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -79,7 +85,10 @@ private Page pageForRequest(final TwilioRestClient client, final Req } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.CONVERSATIONS.toString()) @@ -87,9 +96,11 @@ public Page previousPage(final Page page, final TwilioRe return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.CONVERSATIONS.toString()) @@ -98,21 +109,21 @@ public Page nextPage(final Page page, final TwilioRestCl } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/CredentialUpdater.java b/src/main/java/com/twilio/rest/conversations/v1/CredentialUpdater.java index a7b341ac97..9f0fad0360 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/CredentialUpdater.java +++ b/src/main/java/com/twilio/rest/conversations/v1/CredentialUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.conversations.v1; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class CredentialUpdater extends Updater { - - -public class CredentialUpdater extends Updater{ private String pathSid; private Credential.PushType type; private String friendlyName; @@ -37,92 +36,101 @@ public class CredentialUpdater extends Updater{ private String apiKey; private String secret; - public CredentialUpdater(final String pathSid){ + public CredentialUpdater(final String pathSid) { this.pathSid = pathSid; } - public CredentialUpdater setType(final Credential.PushType type){ + public CredentialUpdater setType(final Credential.PushType type) { this.type = type; return this; } - public CredentialUpdater setFriendlyName(final String friendlyName){ + + public CredentialUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public CredentialUpdater setCertificate(final String certificate){ + + public CredentialUpdater setCertificate(final String certificate) { this.certificate = certificate; return this; } - public CredentialUpdater setPrivateKey(final String privateKey){ + + public CredentialUpdater setPrivateKey(final String privateKey) { this.privateKey = privateKey; return this; } - public CredentialUpdater setSandbox(final Boolean sandbox){ + + public CredentialUpdater setSandbox(final Boolean sandbox) { this.sandbox = sandbox; return this; } - public CredentialUpdater setApiKey(final String apiKey){ + + public CredentialUpdater setApiKey(final String apiKey) { this.apiKey = apiKey; return this; } - public CredentialUpdater setSecret(final String secret){ + + public CredentialUpdater setSecret(final String secret) { this.secret = secret; return this; } @Override - public Credential update(final TwilioRestClient client){ + public Credential update(final TwilioRestClient client) { String path = "/v1/Credentials/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.CONVERSATIONS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Credential update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Credential update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Credential.fromJson(response.getStream(), client.getObjectMapper()); + return Credential.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (type != null) { request.addPostParam("Type", type.toString()); - } if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (certificate != null) { request.addPostParam("Certificate", certificate); - } if (privateKey != null) { request.addPostParam("PrivateKey", privateKey); - } if (sandbox != null) { request.addPostParam("Sandbox", sandbox.toString()); - } if (apiKey != null) { request.addPostParam("ApiKey", apiKey); - } if (secret != null) { request.addPostParam("Secret", secret); - } } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/ParticipantConversation.java b/src/main/java/com/twilio/rest/conversations/v1/ParticipantConversation.java index 07e91cb9f1..a4f4b68f95 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/ParticipantConversation.java +++ b/src/main/java/com/twilio/rest/conversations/v1/ParticipantConversation.java @@ -24,38 +24,37 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class ParticipantConversation extends Resource { + private static final long serialVersionUID = 210706261724884L; - public static ParticipantConversationReader reader(){ + public static ParticipantConversationReader reader() { return new ParticipantConversationReader(); } /** - * Converts a JSON String into a ParticipantConversation object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return ParticipantConversation object represented by the provided JSON - */ - public static ParticipantConversation fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a ParticipantConversation object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return ParticipantConversation object represented by the provided JSON + */ + public static ParticipantConversation fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, ParticipantConversation.class); @@ -67,14 +66,17 @@ public static ParticipantConversation fromJson(final String json, final ObjectMa } /** - * Converts a JSON InputStream into a ParticipantConversation object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return ParticipantConversation object represented by the provided JSON - */ - public static ParticipantConversation fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a ParticipantConversation object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return ParticipantConversation object represented by the provided JSON + */ + public static ParticipantConversation fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, ParticipantConversation.class); @@ -84,6 +86,7 @@ public static ParticipantConversation fromJson(final InputStream json, final Obj throw new ApiConnectionException(e.getMessage(), e); } } + public enum State { INACTIVE("inactive"), ACTIVE("active"), @@ -124,53 +127,40 @@ public static State forValue(final String value) { @JsonCreator private ParticipantConversation( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("chat_service_sid") - final String chatServiceSid, - - @JsonProperty("participant_sid") - final String participantSid, - - @JsonProperty("participant_user_sid") - final String participantUserSid, - - @JsonProperty("participant_identity") - final String participantIdentity, - - @JsonProperty("participant_messaging_binding") - final Map participantMessagingBinding, - - @JsonProperty("conversation_sid") - final String conversationSid, - - @JsonProperty("conversation_unique_name") - final String conversationUniqueName, - - @JsonProperty("conversation_friendly_name") - final String conversationFriendlyName, - - @JsonProperty("conversation_attributes") - final String conversationAttributes, - - @JsonProperty("conversation_date_created") - final String conversationDateCreated, - - @JsonProperty("conversation_date_updated") - final String conversationDateUpdated, - - @JsonProperty("conversation_created_by") - final String conversationCreatedBy, - - @JsonProperty("conversation_state") - final ParticipantConversation.State conversationState, - - @JsonProperty("conversation_timers") - final Map conversationTimers, - - @JsonProperty("links") - final Map links + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("chat_service_sid") final String chatServiceSid, + @JsonProperty("participant_sid") final String participantSid, + @JsonProperty("participant_user_sid") final String participantUserSid, + @JsonProperty("participant_identity") final String participantIdentity, + @JsonProperty( + "participant_messaging_binding" + ) final Map participantMessagingBinding, + @JsonProperty("conversation_sid") final String conversationSid, + @JsonProperty( + "conversation_unique_name" + ) final String conversationUniqueName, + @JsonProperty( + "conversation_friendly_name" + ) final String conversationFriendlyName, + @JsonProperty( + "conversation_attributes" + ) final String conversationAttributes, + @JsonProperty( + "conversation_date_created" + ) final String conversationDateCreated, + @JsonProperty( + "conversation_date_updated" + ) final String conversationDateUpdated, + @JsonProperty( + "conversation_created_by" + ) final String conversationCreatedBy, + @JsonProperty( + "conversation_state" + ) final ParticipantConversation.State conversationState, + @JsonProperty( + "conversation_timers" + ) final Map conversationTimers, + @JsonProperty("links") final Map links ) { this.accountSid = accountSid; this.chatServiceSid = chatServiceSid; @@ -182,66 +172,83 @@ private ParticipantConversation( this.conversationUniqueName = conversationUniqueName; this.conversationFriendlyName = conversationFriendlyName; this.conversationAttributes = conversationAttributes; - this.conversationDateCreated = DateConverter.iso8601DateTimeFromString(conversationDateCreated); - this.conversationDateUpdated = DateConverter.iso8601DateTimeFromString(conversationDateUpdated); + this.conversationDateCreated = + DateConverter.iso8601DateTimeFromString(conversationDateCreated); + this.conversationDateUpdated = + DateConverter.iso8601DateTimeFromString(conversationDateUpdated); this.conversationCreatedBy = conversationCreatedBy; this.conversationState = conversationState; this.conversationTimers = conversationTimers; this.links = links; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getChatServiceSid() { - return this.chatServiceSid; - } - public final String getParticipantSid() { - return this.participantSid; - } - public final String getParticipantUserSid() { - return this.participantUserSid; - } - public final String getParticipantIdentity() { - return this.participantIdentity; - } - public final Map getParticipantMessagingBinding() { - return this.participantMessagingBinding; - } - public final String getConversationSid() { - return this.conversationSid; - } - public final String getConversationUniqueName() { - return this.conversationUniqueName; - } - public final String getConversationFriendlyName() { - return this.conversationFriendlyName; - } - public final String getConversationAttributes() { - return this.conversationAttributes; - } - public final ZonedDateTime getConversationDateCreated() { - return this.conversationDateCreated; - } - public final ZonedDateTime getConversationDateUpdated() { - return this.conversationDateUpdated; - } - public final String getConversationCreatedBy() { - return this.conversationCreatedBy; - } - public final ParticipantConversation.State getConversationState() { - return this.conversationState; - } - public final Map getConversationTimers() { - return this.conversationTimers; - } - public final Map getLinks() { - return this.links; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getChatServiceSid() { + return this.chatServiceSid; + } + + public final String getParticipantSid() { + return this.participantSid; + } + + public final String getParticipantUserSid() { + return this.participantUserSid; + } + + public final String getParticipantIdentity() { + return this.participantIdentity; + } + + public final Map getParticipantMessagingBinding() { + return this.participantMessagingBinding; + } + + public final String getConversationSid() { + return this.conversationSid; + } + + public final String getConversationUniqueName() { + return this.conversationUniqueName; + } + + public final String getConversationFriendlyName() { + return this.conversationFriendlyName; + } + + public final String getConversationAttributes() { + return this.conversationAttributes; + } + + public final ZonedDateTime getConversationDateCreated() { + return this.conversationDateCreated; + } + + public final ZonedDateTime getConversationDateUpdated() { + return this.conversationDateUpdated; + } + + public final String getConversationCreatedBy() { + return this.conversationCreatedBy; + } + + public final ParticipantConversation.State getConversationState() { + return this.conversationState; + } + + public final Map getConversationTimers() { + return this.conversationTimers; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -251,13 +258,66 @@ public boolean equals(final Object o) { ParticipantConversation other = (ParticipantConversation) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(chatServiceSid, other.chatServiceSid) && Objects.equals(participantSid, other.participantSid) && Objects.equals(participantUserSid, other.participantUserSid) && Objects.equals(participantIdentity, other.participantIdentity) && Objects.equals(participantMessagingBinding, other.participantMessagingBinding) && Objects.equals(conversationSid, other.conversationSid) && Objects.equals(conversationUniqueName, other.conversationUniqueName) && Objects.equals(conversationFriendlyName, other.conversationFriendlyName) && Objects.equals(conversationAttributes, other.conversationAttributes) && Objects.equals(conversationDateCreated, other.conversationDateCreated) && Objects.equals(conversationDateUpdated, other.conversationDateUpdated) && Objects.equals(conversationCreatedBy, other.conversationCreatedBy) && Objects.equals(conversationState, other.conversationState) && Objects.equals(conversationTimers, other.conversationTimers) && Objects.equals(links, other.links) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(chatServiceSid, other.chatServiceSid) && + Objects.equals(participantSid, other.participantSid) && + Objects.equals(participantUserSid, other.participantUserSid) && + Objects.equals(participantIdentity, other.participantIdentity) && + Objects.equals( + participantMessagingBinding, + other.participantMessagingBinding + ) && + Objects.equals(conversationSid, other.conversationSid) && + Objects.equals( + conversationUniqueName, + other.conversationUniqueName + ) && + Objects.equals( + conversationFriendlyName, + other.conversationFriendlyName + ) && + Objects.equals( + conversationAttributes, + other.conversationAttributes + ) && + Objects.equals( + conversationDateCreated, + other.conversationDateCreated + ) && + Objects.equals( + conversationDateUpdated, + other.conversationDateUpdated + ) && + Objects.equals( + conversationCreatedBy, + other.conversationCreatedBy + ) && + Objects.equals(conversationState, other.conversationState) && + Objects.equals(conversationTimers, other.conversationTimers) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, chatServiceSid, participantSid, participantUserSid, participantIdentity, participantMessagingBinding, conversationSid, conversationUniqueName, conversationFriendlyName, conversationAttributes, conversationDateCreated, conversationDateUpdated, conversationCreatedBy, conversationState, conversationTimers, links); + return Objects.hash( + accountSid, + chatServiceSid, + participantSid, + participantUserSid, + participantIdentity, + participantMessagingBinding, + conversationSid, + conversationUniqueName, + conversationFriendlyName, + conversationAttributes, + conversationDateCreated, + conversationDateUpdated, + conversationCreatedBy, + conversationState, + conversationTimers, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/conversations/v1/ParticipantConversationReader.java b/src/main/java/com/twilio/rest/conversations/v1/ParticipantConversationReader.java index 49c62b306a..07754e6b8e 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/ParticipantConversationReader.java +++ b/src/main/java/com/twilio/rest/conversations/v1/ParticipantConversationReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.conversations.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,37 +25,41 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - +public class ParticipantConversationReader + extends Reader { -public class ParticipantConversationReader extends Reader { private String identity; private String address; private Integer pageSize; - public ParticipantConversationReader(){ - } + public ParticipantConversationReader() {} - public ParticipantConversationReader setIdentity(final String identity){ + public ParticipantConversationReader setIdentity(final String identity) { this.identity = identity; return this; } - public ParticipantConversationReader setAddress(final String address){ + + public ParticipantConversationReader setAddress(final String address) { this.address = address; return this; } - public ParticipantConversationReader setPageSize(final Integer pageSize){ + + public ParticipantConversationReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @Override - public ResourceSet read(final TwilioRestClient client) { + public ResourceSet read( + final TwilioRestClient client + ) { return new ResourceSet<>(this, client, firstPage(client)); } - public Page firstPage(final TwilioRestClient client) { + public Page firstPage( + final TwilioRestClient client + ) { String path = "/v1/ParticipantConversations"; Request request = new Request( @@ -67,13 +72,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("ParticipantConversation read failed: Unable to connect to server"); + throw new ApiConnectionException( + "ParticipantConversation read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -89,7 +102,10 @@ private Page pageForRequest(final TwilioRestClient clie } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.CONVERSATIONS.toString()) @@ -97,9 +113,11 @@ public Page previousPage(final Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.CONVERSATIONS.toString()) @@ -108,29 +126,27 @@ public Page nextPage(final Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (identity != null) { - request.addQueryParam("Identity", identity); } if (address != null) { - request.addQueryParam("Address", address); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/Role.java b/src/main/java/com/twilio/rest/conversations/v1/Role.java index ff3637adef..930bf7c004 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/Role.java +++ b/src/main/java/com/twilio/rest/conversations/v1/Role.java @@ -24,54 +24,60 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.List; import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Role extends Resource { + private static final long serialVersionUID = 223283830784079L; - public static RoleCreator creator(final String friendlyName, final Role.RoleType type, final List permission){ + public static RoleCreator creator( + final String friendlyName, + final Role.RoleType type, + final List permission + ) { return new RoleCreator(friendlyName, type, permission); } - public static RoleDeleter deleter(final String pathSid){ + public static RoleDeleter deleter(final String pathSid) { return new RoleDeleter(pathSid); } - public static RoleFetcher fetcher(final String pathSid){ + public static RoleFetcher fetcher(final String pathSid) { return new RoleFetcher(pathSid); } - public static RoleReader reader(){ + public static RoleReader reader() { return new RoleReader(); } - public static RoleUpdater updater(final String pathSid, final List permission){ + public static RoleUpdater updater( + final String pathSid, + final List permission + ) { return new RoleUpdater(pathSid, permission); } /** - * Converts a JSON String into a Role object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Role object represented by the provided JSON - */ - public static Role fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Role object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Role object represented by the provided JSON + */ + public static Role fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Role.class); @@ -83,14 +89,17 @@ public static Role fromJson(final String json, final ObjectMapper objectMapper) } /** - * Converts a JSON InputStream into a Role object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Role object represented by the provided JSON - */ - public static Role fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Role object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Role object represented by the provided JSON + */ + public static Role fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Role.class); @@ -100,6 +109,7 @@ public static Role fromJson(final InputStream json, final ObjectMapper objectMap throw new ApiConnectionException(e.getMessage(), e); } } + public enum RoleType { CONVERSATION("conversation"), SERVICE("service"); @@ -132,32 +142,15 @@ public static RoleType forValue(final String value) { @JsonCreator private Role( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("chat_service_sid") - final String chatServiceSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("type") - final Role.RoleType type, - - @JsonProperty("permissions") - final List permissions, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("chat_service_sid") final String chatServiceSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("type") final Role.RoleType type, + @JsonProperty("permissions") final List permissions, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url ) { this.sid = sid; this.accountSid = accountSid; @@ -170,37 +163,45 @@ private Role( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getChatServiceSid() { - return this.chatServiceSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final Role.RoleType getType() { - return this.type; - } - public final List getPermissions() { - return this.permissions; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getChatServiceSid() { + return this.chatServiceSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final Role.RoleType getType() { + return this.type; + } + + public final List getPermissions() { + return this.permissions; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -210,13 +211,31 @@ public boolean equals(final Object o) { Role other = (Role) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(chatServiceSid, other.chatServiceSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(type, other.type) && Objects.equals(permissions, other.permissions) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(chatServiceSid, other.chatServiceSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(type, other.type) && + Objects.equals(permissions, other.permissions) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, chatServiceSid, friendlyName, type, permissions, dateCreated, dateUpdated, url); + return Objects.hash( + sid, + accountSid, + chatServiceSid, + friendlyName, + type, + permissions, + dateCreated, + dateUpdated, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/conversations/v1/RoleCreator.java b/src/main/java/com/twilio/rest/conversations/v1/RoleCreator.java index 9636480f05..c639009d5b 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/RoleCreator.java +++ b/src/main/java/com/twilio/rest/conversations/v1/RoleCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.conversations.v1; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -25,57 +26,73 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.util.List; - import java.util.List; +public class RoleCreator extends Creator { - -public class RoleCreator extends Creator{ private String friendlyName; private Role.RoleType type; private List permission; - public RoleCreator(final String friendlyName, final Role.RoleType type, final List permission) { + public RoleCreator( + final String friendlyName, + final Role.RoleType type, + final List permission + ) { this.friendlyName = friendlyName; this.type = type; this.permission = permission; } - public RoleCreator setFriendlyName(final String friendlyName){ + public RoleCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public RoleCreator setType(final Role.RoleType type){ + + public RoleCreator setType(final Role.RoleType type) { this.type = type; return this; } - public RoleCreator setPermission(final List permission){ + + public RoleCreator setPermission(final List permission) { this.permission = permission; return this; } - public RoleCreator setPermission(final String permission){ + + public RoleCreator setPermission(final String permission) { return setPermission(Promoter.listOfOne(permission)); } @Override - public Role create(final TwilioRestClient client){ + public Role create(final TwilioRestClient client) { String path = "/v1/Roles"; - path = path.replace("{"+"FriendlyName"+"}", this.friendlyName.toString()); - path = path.replace("{"+"Type"+"}", this.type.toString()); - path = path.replace("{"+"Permission"+"}", this.permission.toString()); + path = + path.replace( + "{" + "FriendlyName" + "}", + this.friendlyName.toString() + ); + path = path.replace("{" + "Type" + "}", this.type.toString()); + path = + path.replace("{" + "Permission" + "}", this.permission.toString()); Request request = new Request( HttpMethod.POST, Domains.CONVERSATIONS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Role creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Role creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -84,20 +101,18 @@ public Role create(final TwilioRestClient client){ return Role.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (type != null) { request.addPostParam("Type", type.toString()); - } if (permission != null) { for (String prop : permission) { request.addPostParam("Permission", prop); } - } } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/RoleDeleter.java b/src/main/java/com/twilio/rest/conversations/v1/RoleDeleter.java index b31ab50dea..bbf6e13246 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/RoleDeleter.java +++ b/src/main/java/com/twilio/rest/conversations/v1/RoleDeleter.java @@ -24,21 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class RoleDeleter extends Deleter { + private String pathSid; - public RoleDeleter(final String pathSid){ + public RoleDeleter(final String pathSid) { this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Roles/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -48,9 +46,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Role delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Role delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/conversations/v1/RoleFetcher.java b/src/main/java/com/twilio/rest/conversations/v1/RoleFetcher.java index cd5266c5c2..0f89c2dec8 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/RoleFetcher.java +++ b/src/main/java/com/twilio/rest/conversations/v1/RoleFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class RoleFetcher extends Fetcher { + private String pathSid; - public RoleFetcher(final String pathSid){ + public RoleFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public Role fetch(final TwilioRestClient client) { String path = "/v1/Roles/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,9 +46,14 @@ public Role fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Role fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Role fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/conversations/v1/RoleReader.java b/src/main/java/com/twilio/rest/conversations/v1/RoleReader.java index 99205cb734..e6e855c12d 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/RoleReader.java +++ b/src/main/java/com/twilio/rest/conversations/v1/RoleReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.conversations.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,17 +25,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class RoleReader extends Reader { + private Integer pageSize; - public RoleReader(){ - } + public RoleReader() {} - public RoleReader setPageSize(final Integer pageSize){ + public RoleReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -57,13 +55,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Role read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Role read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -79,7 +85,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request r } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.CONVERSATIONS.toString()) @@ -87,9 +96,11 @@ public Page previousPage(final Page page, final TwilioRestClient cli return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.CONVERSATIONS.toString()) @@ -98,21 +109,21 @@ public Page nextPage(final Page page, final TwilioRestClient client) } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/RoleUpdater.java b/src/main/java/com/twilio/rest/conversations/v1/RoleUpdater.java index 934b87ca71..d35c2a2878 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/RoleUpdater.java +++ b/src/main/java/com/twilio/rest/conversations/v1/RoleUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.conversations.v1; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -24,46 +25,52 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - import java.util.List; +public class RoleUpdater extends Updater { -public class RoleUpdater extends Updater{ private String pathSid; private List permission; - public RoleUpdater(final String pathSid, final List permission){ + public RoleUpdater(final String pathSid, final List permission) { this.pathSid = pathSid; this.permission = permission; } - public RoleUpdater setPermission(final List permission){ + public RoleUpdater setPermission(final List permission) { this.permission = permission; return this; } - public RoleUpdater setPermission(final String permission){ + + public RoleUpdater setPermission(final String permission) { return setPermission(Promoter.listOfOne(permission)); } @Override - public Role update(final TwilioRestClient client){ + public Role update(final TwilioRestClient client) { String path = "/v1/Roles/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); - path = path.replace("{"+"Permission"+"}", this.permission.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + path = + path.replace("{" + "Permission" + "}", this.permission.toString()); Request request = new Request( HttpMethod.POST, Domains.CONVERSATIONS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Role update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Role update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -72,12 +79,12 @@ public Role update(final TwilioRestClient client){ return Role.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (permission != null) { for (String prop : permission) { request.addPostParam("Permission", prop); } - } } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/Service.java b/src/main/java/com/twilio/rest/conversations/v1/Service.java index 017764ce54..2f21845b3a 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/Service.java +++ b/src/main/java/com/twilio/rest/conversations/v1/Service.java @@ -23,51 +23,50 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Service extends Resource { + private static final long serialVersionUID = 264513185242441L; - public static ServiceCreator creator(final String friendlyName){ + public static ServiceCreator creator(final String friendlyName) { return new ServiceCreator(friendlyName); } - public static ServiceDeleter deleter(final String pathSid){ + public static ServiceDeleter deleter(final String pathSid) { return new ServiceDeleter(pathSid); } - public static ServiceFetcher fetcher(final String pathSid){ + public static ServiceFetcher fetcher(final String pathSid) { return new ServiceFetcher(pathSid); } - public static ServiceReader reader(){ + public static ServiceReader reader() { return new ServiceReader(); } /** - * Converts a JSON String into a Service object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Service object represented by the provided JSON - */ - public static Service fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Service object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Service object represented by the provided JSON + */ + public static Service fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Service.class); @@ -79,14 +78,17 @@ public static Service fromJson(final String json, final ObjectMapper objectMappe } /** - * Converts a JSON InputStream into a Service object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Service object represented by the provided JSON - */ - public static Service fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Service object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Service object represented by the provided JSON + */ + public static Service fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Service.class); @@ -107,26 +109,13 @@ public static Service fromJson(final InputStream json, final ObjectMapper object @JsonCreator private Service( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("sid") final String sid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.accountSid = accountSid; this.sid = sid; @@ -137,31 +126,37 @@ private Service( this.links = links; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getSid() { - return this.sid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getSid() { + return this.sid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -171,13 +166,27 @@ public boolean equals(final Object o) { Service other = (Service) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(sid, other.sid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(sid, other.sid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, sid, friendlyName, dateCreated, dateUpdated, url, links); + return Objects.hash( + accountSid, + sid, + friendlyName, + dateCreated, + dateUpdated, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/conversations/v1/ServiceCreator.java b/src/main/java/com/twilio/rest/conversations/v1/ServiceCreator.java index 604bdd4a43..ce78c00301 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/ServiceCreator.java +++ b/src/main/java/com/twilio/rest/conversations/v1/ServiceCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.conversations.v1; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,38 +25,46 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class ServiceCreator extends Creator { - - -public class ServiceCreator extends Creator{ private String friendlyName; public ServiceCreator(final String friendlyName) { this.friendlyName = friendlyName; } - public ServiceCreator setFriendlyName(final String friendlyName){ + public ServiceCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } @Override - public Service create(final TwilioRestClient client){ + public Service create(final TwilioRestClient client) { String path = "/v1/Services"; - path = path.replace("{"+"FriendlyName"+"}", this.friendlyName.toString()); + path = + path.replace( + "{" + "FriendlyName" + "}", + this.friendlyName.toString() + ); Request request = new Request( HttpMethod.POST, Domains.CONVERSATIONS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -64,10 +73,10 @@ public Service create(final TwilioRestClient client){ return Service.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/ServiceDeleter.java b/src/main/java/com/twilio/rest/conversations/v1/ServiceDeleter.java index b19c69eeff..1bcd411770 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/ServiceDeleter.java +++ b/src/main/java/com/twilio/rest/conversations/v1/ServiceDeleter.java @@ -24,21 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class ServiceDeleter extends Deleter { + private String pathSid; - public ServiceDeleter(final String pathSid){ + public ServiceDeleter(final String pathSid) { this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Services/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -48,9 +46,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/conversations/v1/ServiceFetcher.java b/src/main/java/com/twilio/rest/conversations/v1/ServiceFetcher.java index 459e954546..d043a68207 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/ServiceFetcher.java +++ b/src/main/java/com/twilio/rest/conversations/v1/ServiceFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class ServiceFetcher extends Fetcher { + private String pathSid; - public ServiceFetcher(final String pathSid){ + public ServiceFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public Service fetch(final TwilioRestClient client) { String path = "/v1/Services/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,9 +46,14 @@ public Service fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/conversations/v1/ServiceReader.java b/src/main/java/com/twilio/rest/conversations/v1/ServiceReader.java index c525725fd5..2deeebc86e 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/ServiceReader.java +++ b/src/main/java/com/twilio/rest/conversations/v1/ServiceReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.conversations.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,17 +25,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class ServiceReader extends Reader { + private Integer pageSize; - public ServiceReader(){ - } + public ServiceReader() {} - public ServiceReader setPageSize(final Integer pageSize){ + public ServiceReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -57,13 +55,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -79,7 +85,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reques } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.CONVERSATIONS.toString()) @@ -87,9 +96,11 @@ public Page previousPage(final Page page, final TwilioRestClie return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.CONVERSATIONS.toString()) @@ -98,21 +109,21 @@ public Page nextPage(final Page page, final TwilioRestClient c } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/User.java b/src/main/java/com/twilio/rest/conversations/v1/User.java index b15865d00b..266211932b 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/User.java +++ b/src/main/java/com/twilio/rest/conversations/v1/User.java @@ -24,55 +24,54 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class User extends Resource { + private static final long serialVersionUID = 270629422616663L; - public static UserCreator creator(final String identity){ + public static UserCreator creator(final String identity) { return new UserCreator(identity); } - public static UserDeleter deleter(final String pathSid){ + public static UserDeleter deleter(final String pathSid) { return new UserDeleter(pathSid); } - public static UserFetcher fetcher(final String pathSid){ + public static UserFetcher fetcher(final String pathSid) { return new UserFetcher(pathSid); } - public static UserReader reader(){ + public static UserReader reader() { return new UserReader(); } - public static UserUpdater updater(final String pathSid){ + public static UserUpdater updater(final String pathSid) { return new UserUpdater(pathSid); } /** - * Converts a JSON String into a User object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return User object represented by the provided JSON - */ - public static User fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a User object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return User object represented by the provided JSON + */ + public static User fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, User.class); @@ -84,14 +83,17 @@ public static User fromJson(final String json, final ObjectMapper objectMapper) } /** - * Converts a JSON InputStream into a User object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return User object represented by the provided JSON - */ - public static User fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a User object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return User object represented by the provided JSON + */ + public static User fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, User.class); @@ -101,6 +103,7 @@ public static User fromJson(final InputStream json, final ObjectMapper objectMap throw new ApiConnectionException(e.getMessage(), e); } } + public enum WebhookEnabledType { TRUE("true"), FALSE("false"); @@ -137,44 +140,19 @@ public static WebhookEnabledType forValue(final String value) { @JsonCreator private User( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("chat_service_sid") - final String chatServiceSid, - - @JsonProperty("role_sid") - final String roleSid, - - @JsonProperty("identity") - final String identity, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("attributes") - final String attributes, - - @JsonProperty("is_online") - final Boolean isOnline, - - @JsonProperty("is_notifiable") - final Boolean isNotifiable, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("chat_service_sid") final String chatServiceSid, + @JsonProperty("role_sid") final String roleSid, + @JsonProperty("identity") final String identity, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("attributes") final String attributes, + @JsonProperty("is_online") final Boolean isOnline, + @JsonProperty("is_notifiable") final Boolean isNotifiable, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.sid = sid; this.accountSid = accountSid; @@ -191,49 +169,61 @@ private User( this.links = links; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getChatServiceSid() { - return this.chatServiceSid; - } - public final String getRoleSid() { - return this.roleSid; - } - public final String getIdentity() { - return this.identity; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getAttributes() { - return this.attributes; - } - public final Boolean getIsOnline() { - return this.isOnline; - } - public final Boolean getIsNotifiable() { - return this.isNotifiable; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getChatServiceSid() { + return this.chatServiceSid; + } + + public final String getRoleSid() { + return this.roleSid; + } + + public final String getIdentity() { + return this.identity; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getAttributes() { + return this.attributes; + } + + public final Boolean getIsOnline() { + return this.isOnline; + } + + public final Boolean getIsNotifiable() { + return this.isNotifiable; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -243,13 +233,39 @@ public boolean equals(final Object o) { User other = (User) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(chatServiceSid, other.chatServiceSid) && Objects.equals(roleSid, other.roleSid) && Objects.equals(identity, other.identity) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(attributes, other.attributes) && Objects.equals(isOnline, other.isOnline) && Objects.equals(isNotifiable, other.isNotifiable) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(chatServiceSid, other.chatServiceSid) && + Objects.equals(roleSid, other.roleSid) && + Objects.equals(identity, other.identity) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(attributes, other.attributes) && + Objects.equals(isOnline, other.isOnline) && + Objects.equals(isNotifiable, other.isNotifiable) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, chatServiceSid, roleSid, identity, friendlyName, attributes, isOnline, isNotifiable, dateCreated, dateUpdated, url, links); + return Objects.hash( + sid, + accountSid, + chatServiceSid, + roleSid, + identity, + friendlyName, + attributes, + isOnline, + isNotifiable, + dateCreated, + dateUpdated, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/conversations/v1/UserCreator.java b/src/main/java/com/twilio/rest/conversations/v1/UserCreator.java index e636737b02..be09bb99aa 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/UserCreator.java +++ b/src/main/java/com/twilio/rest/conversations/v1/UserCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.conversations.v1; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class UserCreator extends Creator { - - -public class UserCreator extends Creator{ private String identity; private User.WebhookEnabledType xTwilioWebhookEnabled; private String friendlyName; @@ -38,45 +37,57 @@ public UserCreator(final String identity) { this.identity = identity; } - public UserCreator setIdentity(final String identity){ + public UserCreator setIdentity(final String identity) { this.identity = identity; return this; } - public UserCreator setXTwilioWebhookEnabled(final User.WebhookEnabledType xTwilioWebhookEnabled){ + + public UserCreator setXTwilioWebhookEnabled( + final User.WebhookEnabledType xTwilioWebhookEnabled + ) { this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; return this; } - public UserCreator setFriendlyName(final String friendlyName){ + + public UserCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public UserCreator setAttributes(final String attributes){ + + public UserCreator setAttributes(final String attributes) { this.attributes = attributes; return this; } - public UserCreator setRoleSid(final String roleSid){ + + public UserCreator setRoleSid(final String roleSid) { this.roleSid = roleSid; return this; } @Override - public User create(final TwilioRestClient client){ + public User create(final TwilioRestClient client) { String path = "/v1/Users"; - path = path.replace("{"+"Identity"+"}", this.identity.toString()); + path = path.replace("{" + "Identity" + "}", this.identity.toString()); Request request = new Request( HttpMethod.POST, Domains.CONVERSATIONS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); addHeaderParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("User creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "User creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -85,28 +96,28 @@ public User create(final TwilioRestClient client){ return User.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (identity != null) { request.addPostParam("Identity", identity); - } if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (attributes != null) { request.addPostParam("Attributes", attributes); - } if (roleSid != null) { request.addPostParam("RoleSid", roleSid); - } } + private void addHeaderParams(final Request request) { if (xTwilioWebhookEnabled != null) { - request.addHeaderParam("X-Twilio-Webhook-Enabled", xTwilioWebhookEnabled.toString()); - + request.addHeaderParam( + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/UserDeleter.java b/src/main/java/com/twilio/rest/conversations/v1/UserDeleter.java index 6352f39a7c..486986367d 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/UserDeleter.java +++ b/src/main/java/com/twilio/rest/conversations/v1/UserDeleter.java @@ -24,17 +24,18 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class UserDeleter extends Deleter { + private String pathSid; private User.WebhookEnabledType xTwilioWebhookEnabled; - public UserDeleter(final String pathSid){ + public UserDeleter(final String pathSid) { this.pathSid = pathSid; } - public UserDeleter setXTwilioWebhookEnabled(final User.WebhookEnabledType xTwilioWebhookEnabled){ + public UserDeleter setXTwilioWebhookEnabled( + final User.WebhookEnabledType xTwilioWebhookEnabled + ) { this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; return this; } @@ -43,7 +44,7 @@ public UserDeleter setXTwilioWebhookEnabled(final User.WebhookEnabledType xTwili public boolean delete(final TwilioRestClient client) { String path = "/v1/Users/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -54,9 +55,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("User delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "User delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -64,10 +70,13 @@ public boolean delete(final TwilioRestClient client) { } return response.getStatusCode() == 204; } + private void addHeaderParams(final Request request) { if (xTwilioWebhookEnabled != null) { - request.addHeaderParam("X-Twilio-Webhook-Enabled", xTwilioWebhookEnabled.toString()); - + request.addHeaderParam( + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/UserFetcher.java b/src/main/java/com/twilio/rest/conversations/v1/UserFetcher.java index 8c79747555..6a89b68074 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/UserFetcher.java +++ b/src/main/java/com/twilio/rest/conversations/v1/UserFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class UserFetcher extends Fetcher { + private String pathSid; - public UserFetcher(final String pathSid){ + public UserFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public User fetch(final TwilioRestClient client) { String path = "/v1/Users/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,9 +46,14 @@ public User fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("User fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "User fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/conversations/v1/UserReader.java b/src/main/java/com/twilio/rest/conversations/v1/UserReader.java index 9b1f8ea002..30047263dd 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/UserReader.java +++ b/src/main/java/com/twilio/rest/conversations/v1/UserReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.conversations.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,17 +25,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class UserReader extends Reader { + private Integer pageSize; - public UserReader(){ - } + public UserReader() {} - public UserReader setPageSize(final Integer pageSize){ + public UserReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -57,13 +55,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("User read failed: Unable to connect to server"); + throw new ApiConnectionException( + "User read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -79,7 +85,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request r } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.CONVERSATIONS.toString()) @@ -87,9 +96,11 @@ public Page previousPage(final Page page, final TwilioRestClient cli return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.CONVERSATIONS.toString()) @@ -98,21 +109,21 @@ public Page nextPage(final Page page, final TwilioRestClient client) } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/UserUpdater.java b/src/main/java/com/twilio/rest/conversations/v1/UserUpdater.java index 3170511dac..79dda750c3 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/UserUpdater.java +++ b/src/main/java/com/twilio/rest/conversations/v1/UserUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.conversations.v1; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,55 +25,64 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class UserUpdater extends Updater { - - -public class UserUpdater extends Updater{ private String pathSid; private User.WebhookEnabledType xTwilioWebhookEnabled; private String friendlyName; private String attributes; private String roleSid; - public UserUpdater(final String pathSid){ + public UserUpdater(final String pathSid) { this.pathSid = pathSid; } - public UserUpdater setXTwilioWebhookEnabled(final User.WebhookEnabledType xTwilioWebhookEnabled){ + public UserUpdater setXTwilioWebhookEnabled( + final User.WebhookEnabledType xTwilioWebhookEnabled + ) { this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; return this; } - public UserUpdater setFriendlyName(final String friendlyName){ + + public UserUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public UserUpdater setAttributes(final String attributes){ + + public UserUpdater setAttributes(final String attributes) { this.attributes = attributes; return this; } - public UserUpdater setRoleSid(final String roleSid){ + + public UserUpdater setRoleSid(final String roleSid) { this.roleSid = roleSid; return this; } @Override - public User update(final TwilioRestClient client){ + public User update(final TwilioRestClient client) { String path = "/v1/Users/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.CONVERSATIONS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); addHeaderParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("User update failed: Unable to connect to server"); + throw new ApiConnectionException( + "User update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -81,24 +91,25 @@ public User update(final TwilioRestClient client){ return User.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (attributes != null) { request.addPostParam("Attributes", attributes); - } if (roleSid != null) { request.addPostParam("RoleSid", roleSid); - } } + private void addHeaderParams(final Request request) { if (xTwilioWebhookEnabled != null) { - request.addHeaderParam("X-Twilio-Webhook-Enabled", xTwilioWebhookEnabled.toString()); - + request.addHeaderParam( + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/configuration/Webhook.java b/src/main/java/com/twilio/rest/conversations/v1/configuration/Webhook.java index 19ee1d1bc4..91059a28d0 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/configuration/Webhook.java +++ b/src/main/java/com/twilio/rest/conversations/v1/configuration/Webhook.java @@ -23,41 +23,40 @@ import com.twilio.base.Resource; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.List; import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Webhook extends Resource { + private static final long serialVersionUID = 64791700237770L; - public static WebhookFetcher fetcher(){ + public static WebhookFetcher fetcher() { return new WebhookFetcher(); } - public static WebhookUpdater updater(){ + public static WebhookUpdater updater() { return new WebhookUpdater(); } /** - * Converts a JSON String into a Webhook object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Webhook object represented by the provided JSON - */ - public static Webhook fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Webhook object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Webhook object represented by the provided JSON + */ + public static Webhook fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Webhook.class); @@ -69,14 +68,17 @@ public static Webhook fromJson(final String json, final ObjectMapper objectMappe } /** - * Converts a JSON InputStream into a Webhook object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Webhook object represented by the provided JSON - */ - public static Webhook fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Webhook object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Webhook object represented by the provided JSON + */ + public static Webhook fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Webhook.class); @@ -86,6 +88,7 @@ public static Webhook fromJson(final InputStream json, final ObjectMapper object throw new ApiConnectionException(e.getMessage(), e); } } + public enum Method { GET("GET"), POST("POST"); @@ -105,6 +108,7 @@ public static Method forValue(final String value) { return Promoter.enumFromString(value, Method.values()); } } + public enum Target { WEBHOOK("webhook"), FLEX("flex"); @@ -135,26 +139,13 @@ public static Target forValue(final String value) { @JsonCreator private Webhook( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("method") - final Webhook.Method method, - - @JsonProperty("filters") - final List filters, - - @JsonProperty("pre_webhook_url") - final String preWebhookUrl, - - @JsonProperty("post_webhook_url") - final String postWebhookUrl, - - @JsonProperty("target") - final Webhook.Target target, - - @JsonProperty("url") - final URI url + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("method") final Webhook.Method method, + @JsonProperty("filters") final List filters, + @JsonProperty("pre_webhook_url") final String preWebhookUrl, + @JsonProperty("post_webhook_url") final String postWebhookUrl, + @JsonProperty("target") final Webhook.Target target, + @JsonProperty("url") final URI url ) { this.accountSid = accountSid; this.method = method; @@ -165,31 +156,37 @@ private Webhook( this.url = url; } - public final String getAccountSid() { - return this.accountSid; - } - public final Webhook.Method getMethod() { - return this.method; - } - public final List getFilters() { - return this.filters; - } - public final String getPreWebhookUrl() { - return this.preWebhookUrl; - } - public final String getPostWebhookUrl() { - return this.postWebhookUrl; - } - public final Webhook.Target getTarget() { - return this.target; - } - public final URI getUrl() { - return this.url; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final Webhook.Method getMethod() { + return this.method; + } + + public final List getFilters() { + return this.filters; + } + + public final String getPreWebhookUrl() { + return this.preWebhookUrl; + } + + public final String getPostWebhookUrl() { + return this.postWebhookUrl; + } + + public final Webhook.Target getTarget() { + return this.target; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -199,13 +196,27 @@ public boolean equals(final Object o) { Webhook other = (Webhook) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(method, other.method) && Objects.equals(filters, other.filters) && Objects.equals(preWebhookUrl, other.preWebhookUrl) && Objects.equals(postWebhookUrl, other.postWebhookUrl) && Objects.equals(target, other.target) && Objects.equals(url, other.url) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(method, other.method) && + Objects.equals(filters, other.filters) && + Objects.equals(preWebhookUrl, other.preWebhookUrl) && + Objects.equals(postWebhookUrl, other.postWebhookUrl) && + Objects.equals(target, other.target) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, method, filters, preWebhookUrl, postWebhookUrl, target, url); + return Objects.hash( + accountSid, + method, + filters, + preWebhookUrl, + postWebhookUrl, + target, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/conversations/v1/configuration/WebhookFetcher.java b/src/main/java/com/twilio/rest/conversations/v1/configuration/WebhookFetcher.java index d27c05ee0e..5af669234b 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/configuration/WebhookFetcher.java +++ b/src/main/java/com/twilio/rest/conversations/v1/configuration/WebhookFetcher.java @@ -24,20 +24,14 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class WebhookFetcher extends Fetcher { - public WebhookFetcher(){ - } - + public WebhookFetcher() {} @Override public Webhook fetch(final TwilioRestClient client) { String path = "/v1/Configuration/Webhooks"; - Request request = new Request( HttpMethod.GET, Domains.CONVERSATIONS.toString(), @@ -46,9 +40,14 @@ public Webhook fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Webhook fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Webhook fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/conversations/v1/configuration/WebhookUpdater.java b/src/main/java/com/twilio/rest/conversations/v1/configuration/WebhookUpdater.java index e53246640d..60dac1f328 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/configuration/WebhookUpdater.java +++ b/src/main/java/com/twilio/rest/conversations/v1/configuration/WebhookUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.conversations.v1.configuration; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -24,61 +25,68 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - import java.util.List; +public class WebhookUpdater extends Updater { -public class WebhookUpdater extends Updater{ private String method; private List filters; private String preWebhookUrl; private String postWebhookUrl; private Webhook.Target target; - public WebhookUpdater(){ - } + public WebhookUpdater() {} - public WebhookUpdater setMethod(final String method){ + public WebhookUpdater setMethod(final String method) { this.method = method; return this; } - public WebhookUpdater setFilters(final List filters){ + + public WebhookUpdater setFilters(final List filters) { this.filters = filters; return this; } - public WebhookUpdater setFilters(final String filters){ + + public WebhookUpdater setFilters(final String filters) { return setFilters(Promoter.listOfOne(filters)); } - public WebhookUpdater setPreWebhookUrl(final String preWebhookUrl){ + + public WebhookUpdater setPreWebhookUrl(final String preWebhookUrl) { this.preWebhookUrl = preWebhookUrl; return this; } - public WebhookUpdater setPostWebhookUrl(final String postWebhookUrl){ + + public WebhookUpdater setPostWebhookUrl(final String postWebhookUrl) { this.postWebhookUrl = postWebhookUrl; return this; } - public WebhookUpdater setTarget(final Webhook.Target target){ + + public WebhookUpdater setTarget(final Webhook.Target target) { this.target = target; return this; } @Override - public Webhook update(final TwilioRestClient client){ + public Webhook update(final TwilioRestClient client) { String path = "/v1/Configuration/Webhooks"; - Request request = new Request( HttpMethod.POST, Domains.CONVERSATIONS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Webhook update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Webhook update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -87,28 +95,24 @@ public Webhook update(final TwilioRestClient client){ return Webhook.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (method != null) { request.addPostParam("Method", method); - } if (filters != null) { for (String prop : filters) { request.addPostParam("Filters", prop); } - } if (preWebhookUrl != null) { request.addPostParam("PreWebhookUrl", preWebhookUrl); - } if (postWebhookUrl != null) { request.addPostParam("PostWebhookUrl", postWebhookUrl); - } if (target != null) { request.addPostParam("Target", target.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/conversation/Message.java b/src/main/java/com/twilio/rest/conversations/v1/conversation/Message.java index e06117acf1..ecf70f767b 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/conversation/Message.java +++ b/src/main/java/com/twilio/rest/conversations/v1/conversation/Message.java @@ -24,56 +24,64 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.List; import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Message extends Resource { + private static final long serialVersionUID = 43250311135417L; - public static MessageCreator creator(final String pathConversationSid){ + public static MessageCreator creator(final String pathConversationSid) { return new MessageCreator(pathConversationSid); } - public static MessageDeleter deleter(final String pathConversationSid, final String pathSid){ + public static MessageDeleter deleter( + final String pathConversationSid, + final String pathSid + ) { return new MessageDeleter(pathConversationSid, pathSid); } - public static MessageFetcher fetcher(final String pathConversationSid, final String pathSid){ + public static MessageFetcher fetcher( + final String pathConversationSid, + final String pathSid + ) { return new MessageFetcher(pathConversationSid, pathSid); } - public static MessageReader reader(final String pathConversationSid){ + public static MessageReader reader(final String pathConversationSid) { return new MessageReader(pathConversationSid); } - public static MessageUpdater updater(final String pathConversationSid, final String pathSid){ + public static MessageUpdater updater( + final String pathConversationSid, + final String pathSid + ) { return new MessageUpdater(pathConversationSid, pathSid); } /** - * Converts a JSON String into a Message object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Message object represented by the provided JSON - */ - public static Message fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Message object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Message object represented by the provided JSON + */ + public static Message fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Message.class); @@ -85,14 +93,17 @@ public static Message fromJson(final String json, final ObjectMapper objectMappe } /** - * Converts a JSON InputStream into a Message object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Message object represented by the provided JSON - */ - public static Message fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Message object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Message object represented by the provided JSON + */ + public static Message fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Message.class); @@ -102,6 +113,7 @@ public static Message fromJson(final InputStream json, final ObjectMapper object throw new ApiConnectionException(e.getMessage(), e); } } + public enum OrderType { ASC("asc"), DESC("desc"); @@ -121,6 +133,7 @@ public static OrderType forValue(final String value) { return Promoter.enumFromString(value, OrderType.values()); } } + public enum WebhookEnabledType { TRUE("true"), FALSE("false"); @@ -159,50 +172,21 @@ public static WebhookEnabledType forValue(final String value) { @JsonCreator private Message( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("conversation_sid") - final String conversationSid, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("index") - final Integer index, - - @JsonProperty("author") - final String author, - - @JsonProperty("body") - final String body, - - @JsonProperty("media") - final List> media, - - @JsonProperty("attributes") - final String attributes, - - @JsonProperty("participant_sid") - final String participantSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url, - - @JsonProperty("delivery") - final Map delivery, - - @JsonProperty("links") - final Map links, - - @JsonProperty("content_sid") - final String contentSid + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("conversation_sid") final String conversationSid, + @JsonProperty("sid") final String sid, + @JsonProperty("index") final Integer index, + @JsonProperty("author") final String author, + @JsonProperty("body") final String body, + @JsonProperty("media") final List> media, + @JsonProperty("attributes") final String attributes, + @JsonProperty("participant_sid") final String participantSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url, + @JsonProperty("delivery") final Map delivery, + @JsonProperty("links") final Map links, + @JsonProperty("content_sid") final String contentSid ) { this.accountSid = accountSid; this.conversationSid = conversationSid; @@ -221,55 +205,69 @@ private Message( this.contentSid = contentSid; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getConversationSid() { - return this.conversationSid; - } - public final String getSid() { - return this.sid; - } - public final Integer getIndex() { - return this.index; - } - public final String getAuthor() { - return this.author; - } - public final String getBody() { - return this.body; - } - public final List> getMedia() { - return this.media; - } - public final String getAttributes() { - return this.attributes; - } - public final String getParticipantSid() { - return this.participantSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } - public final Map getDelivery() { - return this.delivery; - } - public final Map getLinks() { - return this.links; - } - public final String getContentSid() { - return this.contentSid; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getConversationSid() { + return this.conversationSid; + } + + public final String getSid() { + return this.sid; + } + + public final Integer getIndex() { + return this.index; + } + + public final String getAuthor() { + return this.author; + } + + public final String getBody() { + return this.body; + } + + public final List> getMedia() { + return this.media; + } + + public final String getAttributes() { + return this.attributes; + } + + public final String getParticipantSid() { + return this.participantSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getDelivery() { + return this.delivery; + } + + public final Map getLinks() { + return this.links; + } + + public final String getContentSid() { + return this.contentSid; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -279,13 +277,43 @@ public boolean equals(final Object o) { Message other = (Message) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(conversationSid, other.conversationSid) && Objects.equals(sid, other.sid) && Objects.equals(index, other.index) && Objects.equals(author, other.author) && Objects.equals(body, other.body) && Objects.equals(media, other.media) && Objects.equals(attributes, other.attributes) && Objects.equals(participantSid, other.participantSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) && Objects.equals(delivery, other.delivery) && Objects.equals(links, other.links) && Objects.equals(contentSid, other.contentSid) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(conversationSid, other.conversationSid) && + Objects.equals(sid, other.sid) && + Objects.equals(index, other.index) && + Objects.equals(author, other.author) && + Objects.equals(body, other.body) && + Objects.equals(media, other.media) && + Objects.equals(attributes, other.attributes) && + Objects.equals(participantSid, other.participantSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) && + Objects.equals(delivery, other.delivery) && + Objects.equals(links, other.links) && + Objects.equals(contentSid, other.contentSid) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, conversationSid, sid, index, author, body, media, attributes, participantSid, dateCreated, dateUpdated, url, delivery, links, contentSid); + return Objects.hash( + accountSid, + conversationSid, + sid, + index, + author, + body, + media, + attributes, + participantSid, + dateCreated, + dateUpdated, + url, + delivery, + links, + contentSid + ); } - } - diff --git a/src/main/java/com/twilio/rest/conversations/v1/conversation/MessageCreator.java b/src/main/java/com/twilio/rest/conversations/v1/conversation/MessageCreator.java index e78ebc859d..e87a066c14 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/conversation/MessageCreator.java +++ b/src/main/java/com/twilio/rest/conversations/v1/conversation/MessageCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.conversations.v1.conversation; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -25,10 +26,8 @@ import com.twilio.rest.Domains; import java.time.ZonedDateTime; +public class MessageCreator extends Creator { - - -public class MessageCreator extends Creator{ private String pathConversationSid; private Message.WebhookEnabledType xTwilioWebhookEnabled; private String author; @@ -44,61 +43,81 @@ public MessageCreator(final String pathConversationSid) { this.pathConversationSid = pathConversationSid; } - public MessageCreator setXTwilioWebhookEnabled(final Message.WebhookEnabledType xTwilioWebhookEnabled){ + public MessageCreator setXTwilioWebhookEnabled( + final Message.WebhookEnabledType xTwilioWebhookEnabled + ) { this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; return this; } - public MessageCreator setAuthor(final String author){ + + public MessageCreator setAuthor(final String author) { this.author = author; return this; } - public MessageCreator setBody(final String body){ + + public MessageCreator setBody(final String body) { this.body = body; return this; } - public MessageCreator setDateCreated(final ZonedDateTime dateCreated){ + + public MessageCreator setDateCreated(final ZonedDateTime dateCreated) { this.dateCreated = dateCreated; return this; } - public MessageCreator setDateUpdated(final ZonedDateTime dateUpdated){ + + public MessageCreator setDateUpdated(final ZonedDateTime dateUpdated) { this.dateUpdated = dateUpdated; return this; } - public MessageCreator setAttributes(final String attributes){ + + public MessageCreator setAttributes(final String attributes) { this.attributes = attributes; return this; } - public MessageCreator setMediaSid(final String mediaSid){ + + public MessageCreator setMediaSid(final String mediaSid) { this.mediaSid = mediaSid; return this; } - public MessageCreator setContentSid(final String contentSid){ + + public MessageCreator setContentSid(final String contentSid) { this.contentSid = contentSid; return this; } - public MessageCreator setContentVariables(final String contentVariables){ + + public MessageCreator setContentVariables(final String contentVariables) { this.contentVariables = contentVariables; return this; } @Override - public Message create(final TwilioRestClient client){ + public Message create(final TwilioRestClient client) { String path = "/v1/Conversations/{ConversationSid}/Messages"; - path = path.replace("{"+"ConversationSid"+"}", this.pathConversationSid.toString()); + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.CONVERSATIONS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); addHeaderParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Message creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Message creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -107,44 +126,46 @@ public Message create(final TwilioRestClient client){ return Message.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (author != null) { request.addPostParam("Author", author); - } if (body != null) { request.addPostParam("Body", body); - } if (dateCreated != null) { - request.addPostParam("DateCreated", dateCreated.toInstant().toString()); - + request.addPostParam( + "DateCreated", + dateCreated.toInstant().toString() + ); } if (dateUpdated != null) { - request.addPostParam("DateUpdated", dateUpdated.toInstant().toString()); - + request.addPostParam( + "DateUpdated", + dateUpdated.toInstant().toString() + ); } if (attributes != null) { request.addPostParam("Attributes", attributes); - } if (mediaSid != null) { request.addPostParam("MediaSid", mediaSid); - } if (contentSid != null) { request.addPostParam("ContentSid", contentSid); - } if (contentVariables != null) { request.addPostParam("ContentVariables", contentVariables); - } } + private void addHeaderParams(final Request request) { if (xTwilioWebhookEnabled != null) { - request.addHeaderParam("X-Twilio-Webhook-Enabled", xTwilioWebhookEnabled.toString()); - + request.addHeaderParam( + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/conversation/MessageDeleter.java b/src/main/java/com/twilio/rest/conversations/v1/conversation/MessageDeleter.java index 6bea02e0d3..c1f7af4f2c 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/conversation/MessageDeleter.java +++ b/src/main/java/com/twilio/rest/conversations/v1/conversation/MessageDeleter.java @@ -24,19 +24,23 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class MessageDeleter extends Deleter { + private String pathConversationSid; private String pathSid; private Message.WebhookEnabledType xTwilioWebhookEnabled; - public MessageDeleter(final String pathConversationSid, final String pathSid){ + public MessageDeleter( + final String pathConversationSid, + final String pathSid + ) { this.pathConversationSid = pathConversationSid; this.pathSid = pathSid; } - public MessageDeleter setXTwilioWebhookEnabled(final Message.WebhookEnabledType xTwilioWebhookEnabled){ + public MessageDeleter setXTwilioWebhookEnabled( + final Message.WebhookEnabledType xTwilioWebhookEnabled + ) { this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; return this; } @@ -45,8 +49,12 @@ public MessageDeleter setXTwilioWebhookEnabled(final Message.WebhookEnabledType public boolean delete(final TwilioRestClient client) { String path = "/v1/Conversations/{ConversationSid}/Messages/{Sid}"; - path = path.replace("{"+"ConversationSid"+"}", this.pathConversationSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -57,9 +65,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Message delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Message delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -67,10 +80,13 @@ public boolean delete(final TwilioRestClient client) { } return response.getStatusCode() == 204; } + private void addHeaderParams(final Request request) { if (xTwilioWebhookEnabled != null) { - request.addHeaderParam("X-Twilio-Webhook-Enabled", xTwilioWebhookEnabled.toString()); - + request.addHeaderParam( + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/conversation/MessageFetcher.java b/src/main/java/com/twilio/rest/conversations/v1/conversation/MessageFetcher.java index c445dbc628..ea67b13659 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/conversation/MessageFetcher.java +++ b/src/main/java/com/twilio/rest/conversations/v1/conversation/MessageFetcher.java @@ -24,25 +24,29 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class MessageFetcher extends Fetcher { + private String pathConversationSid; private String pathSid; - public MessageFetcher(final String pathConversationSid, final String pathSid){ + public MessageFetcher( + final String pathConversationSid, + final String pathSid + ) { this.pathConversationSid = pathConversationSid; this.pathSid = pathSid; } - @Override public Message fetch(final TwilioRestClient client) { String path = "/v1/Conversations/{ConversationSid}/Messages/{Sid}"; - path = path.replace("{"+"ConversationSid"+"}", this.pathConversationSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,9 +56,14 @@ public Message fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Message fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Message fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/conversations/v1/conversation/MessageReader.java b/src/main/java/com/twilio/rest/conversations/v1/conversation/MessageReader.java index ce2515541e..1c8443dc94 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/conversation/MessageReader.java +++ b/src/main/java/com/twilio/rest/conversations/v1/conversation/MessageReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.conversations.v1.conversation; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,24 +25,23 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class MessageReader extends Reader { + private String pathConversationSid; private Message.OrderType order; private Integer pageSize; - public MessageReader(final String pathConversationSid){ + public MessageReader(final String pathConversationSid) { this.pathConversationSid = pathConversationSid; } - public MessageReader setOrder(final Message.OrderType order){ + public MessageReader setOrder(final Message.OrderType order) { this.order = order; return this; } - public MessageReader setPageSize(final Integer pageSize){ + + public MessageReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -53,7 +53,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Conversations/{ConversationSid}/Messages"; - path = path.replace("{"+"ConversationSid"+"}", this.pathConversationSid.toString()); + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -65,13 +69,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Message read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Message read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -87,7 +99,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reques } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.CONVERSATIONS.toString()) @@ -95,9 +110,11 @@ public Page previousPage(final Page page, final TwilioRestClie return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.CONVERSATIONS.toString()) @@ -106,25 +123,24 @@ public Page nextPage(final Page page, final TwilioRestClient c } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (order != null) { - request.addQueryParam("Order", order.toString()); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/conversation/MessageUpdater.java b/src/main/java/com/twilio/rest/conversations/v1/conversation/MessageUpdater.java index 116ca0b9f4..9f4f75761b 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/conversation/MessageUpdater.java +++ b/src/main/java/com/twilio/rest/conversations/v1/conversation/MessageUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.conversations.v1.conversation; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -23,12 +24,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.time.ZonedDateTime; +public class MessageUpdater extends Updater { - -public class MessageUpdater extends Updater{ private String pathConversationSid; private String pathSid; private Message.WebhookEnabledType xTwilioWebhookEnabled; @@ -38,55 +37,75 @@ public class MessageUpdater extends Updater{ private ZonedDateTime dateUpdated; private String attributes; - public MessageUpdater(final String pathConversationSid, final String pathSid){ + public MessageUpdater( + final String pathConversationSid, + final String pathSid + ) { this.pathConversationSid = pathConversationSid; this.pathSid = pathSid; } - public MessageUpdater setXTwilioWebhookEnabled(final Message.WebhookEnabledType xTwilioWebhookEnabled){ + public MessageUpdater setXTwilioWebhookEnabled( + final Message.WebhookEnabledType xTwilioWebhookEnabled + ) { this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; return this; } - public MessageUpdater setAuthor(final String author){ + + public MessageUpdater setAuthor(final String author) { this.author = author; return this; } - public MessageUpdater setBody(final String body){ + + public MessageUpdater setBody(final String body) { this.body = body; return this; } - public MessageUpdater setDateCreated(final ZonedDateTime dateCreated){ + + public MessageUpdater setDateCreated(final ZonedDateTime dateCreated) { this.dateCreated = dateCreated; return this; } - public MessageUpdater setDateUpdated(final ZonedDateTime dateUpdated){ + + public MessageUpdater setDateUpdated(final ZonedDateTime dateUpdated) { this.dateUpdated = dateUpdated; return this; } - public MessageUpdater setAttributes(final String attributes){ + + public MessageUpdater setAttributes(final String attributes) { this.attributes = attributes; return this; } @Override - public Message update(final TwilioRestClient client){ + public Message update(final TwilioRestClient client) { String path = "/v1/Conversations/{ConversationSid}/Messages/{Sid}"; - path = path.replace("{"+"ConversationSid"+"}", this.pathConversationSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.CONVERSATIONS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); addHeaderParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Message update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Message update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -95,32 +114,37 @@ public Message update(final TwilioRestClient client){ return Message.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (author != null) { request.addPostParam("Author", author); - } if (body != null) { request.addPostParam("Body", body); - } if (dateCreated != null) { - request.addPostParam("DateCreated", dateCreated.toInstant().toString()); - + request.addPostParam( + "DateCreated", + dateCreated.toInstant().toString() + ); } if (dateUpdated != null) { - request.addPostParam("DateUpdated", dateUpdated.toInstant().toString()); - + request.addPostParam( + "DateUpdated", + dateUpdated.toInstant().toString() + ); } if (attributes != null) { request.addPostParam("Attributes", attributes); - } } + private void addHeaderParams(final Request request) { if (xTwilioWebhookEnabled != null) { - request.addHeaderParam("X-Twilio-Webhook-Enabled", xTwilioWebhookEnabled.toString()); - + request.addHeaderParam( + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/conversation/Participant.java b/src/main/java/com/twilio/rest/conversations/v1/conversation/Participant.java index 2cb0e61517..13a74fccf5 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/conversation/Participant.java +++ b/src/main/java/com/twilio/rest/conversations/v1/conversation/Participant.java @@ -24,55 +24,63 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Participant extends Resource { + private static final long serialVersionUID = 164096252184722L; - public static ParticipantCreator creator(final String pathConversationSid){ + public static ParticipantCreator creator(final String pathConversationSid) { return new ParticipantCreator(pathConversationSid); } - public static ParticipantDeleter deleter(final String pathConversationSid, final String pathSid){ + public static ParticipantDeleter deleter( + final String pathConversationSid, + final String pathSid + ) { return new ParticipantDeleter(pathConversationSid, pathSid); } - public static ParticipantFetcher fetcher(final String pathConversationSid, final String pathSid){ + public static ParticipantFetcher fetcher( + final String pathConversationSid, + final String pathSid + ) { return new ParticipantFetcher(pathConversationSid, pathSid); } - public static ParticipantReader reader(final String pathConversationSid){ + public static ParticipantReader reader(final String pathConversationSid) { return new ParticipantReader(pathConversationSid); } - public static ParticipantUpdater updater(final String pathConversationSid, final String pathSid){ + public static ParticipantUpdater updater( + final String pathConversationSid, + final String pathSid + ) { return new ParticipantUpdater(pathConversationSid, pathSid); } /** - * Converts a JSON String into a Participant object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Participant object represented by the provided JSON - */ - public static Participant fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Participant object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Participant object represented by the provided JSON + */ + public static Participant fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Participant.class); @@ -84,14 +92,17 @@ public static Participant fromJson(final String json, final ObjectMapper objectM } /** - * Converts a JSON InputStream into a Participant object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Participant object represented by the provided JSON - */ - public static Participant fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Participant object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Participant object represented by the provided JSON + */ + public static Participant fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Participant.class); @@ -101,6 +112,7 @@ public static Participant fromJson(final InputStream json, final ObjectMapper ob throw new ApiConnectionException(e.getMessage(), e); } } + public enum WebhookEnabledType { TRUE("true"), FALSE("false"); @@ -136,41 +148,22 @@ public static WebhookEnabledType forValue(final String value) { @JsonCreator private Participant( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("conversation_sid") - final String conversationSid, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("identity") - final String identity, - - @JsonProperty("attributes") - final String attributes, - - @JsonProperty("messaging_binding") - final Map messagingBinding, - - @JsonProperty("role_sid") - final String roleSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url, - - @JsonProperty("last_read_message_index") - final Integer lastReadMessageIndex, - - @JsonProperty("last_read_timestamp") - final String lastReadTimestamp + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("conversation_sid") final String conversationSid, + @JsonProperty("sid") final String sid, + @JsonProperty("identity") final String identity, + @JsonProperty("attributes") final String attributes, + @JsonProperty( + "messaging_binding" + ) final Map messagingBinding, + @JsonProperty("role_sid") final String roleSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url, + @JsonProperty( + "last_read_message_index" + ) final Integer lastReadMessageIndex, + @JsonProperty("last_read_timestamp") final String lastReadTimestamp ) { this.accountSid = accountSid; this.conversationSid = conversationSid; @@ -186,46 +179,57 @@ private Participant( this.lastReadTimestamp = lastReadTimestamp; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getConversationSid() { - return this.conversationSid; - } - public final String getSid() { - return this.sid; - } - public final String getIdentity() { - return this.identity; - } - public final String getAttributes() { - return this.attributes; - } - public final Map getMessagingBinding() { - return this.messagingBinding; - } - public final String getRoleSid() { - return this.roleSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } - public final Integer getLastReadMessageIndex() { - return this.lastReadMessageIndex; - } - public final String getLastReadTimestamp() { - return this.lastReadTimestamp; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getConversationSid() { + return this.conversationSid; + } + + public final String getSid() { + return this.sid; + } + + public final String getIdentity() { + return this.identity; + } + + public final String getAttributes() { + return this.attributes; + } + + public final Map getMessagingBinding() { + return this.messagingBinding; + } + + public final String getRoleSid() { + return this.roleSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } + + public final Integer getLastReadMessageIndex() { + return this.lastReadMessageIndex; + } + + public final String getLastReadTimestamp() { + return this.lastReadTimestamp; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -235,13 +239,37 @@ public boolean equals(final Object o) { Participant other = (Participant) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(conversationSid, other.conversationSid) && Objects.equals(sid, other.sid) && Objects.equals(identity, other.identity) && Objects.equals(attributes, other.attributes) && Objects.equals(messagingBinding, other.messagingBinding) && Objects.equals(roleSid, other.roleSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) && Objects.equals(lastReadMessageIndex, other.lastReadMessageIndex) && Objects.equals(lastReadTimestamp, other.lastReadTimestamp) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(conversationSid, other.conversationSid) && + Objects.equals(sid, other.sid) && + Objects.equals(identity, other.identity) && + Objects.equals(attributes, other.attributes) && + Objects.equals(messagingBinding, other.messagingBinding) && + Objects.equals(roleSid, other.roleSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) && + Objects.equals(lastReadMessageIndex, other.lastReadMessageIndex) && + Objects.equals(lastReadTimestamp, other.lastReadTimestamp) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, conversationSid, sid, identity, attributes, messagingBinding, roleSid, dateCreated, dateUpdated, url, lastReadMessageIndex, lastReadTimestamp); + return Objects.hash( + accountSid, + conversationSid, + sid, + identity, + attributes, + messagingBinding, + roleSid, + dateCreated, + dateUpdated, + url, + lastReadMessageIndex, + lastReadTimestamp + ); } - } - diff --git a/src/main/java/com/twilio/rest/conversations/v1/conversation/ParticipantCreator.java b/src/main/java/com/twilio/rest/conversations/v1/conversation/ParticipantCreator.java index 729f9c2735..b0b2a26a3a 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/conversation/ParticipantCreator.java +++ b/src/main/java/com/twilio/rest/conversations/v1/conversation/ParticipantCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.conversations.v1.conversation; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -25,10 +26,8 @@ import com.twilio.rest.Domains; import java.time.ZonedDateTime; +public class ParticipantCreator extends Creator { - - -public class ParticipantCreator extends Creator{ private String pathConversationSid; private Participant.WebhookEnabledType xTwilioWebhookEnabled; private String identity; @@ -44,107 +43,148 @@ public ParticipantCreator(final String pathConversationSid) { this.pathConversationSid = pathConversationSid; } - public ParticipantCreator setXTwilioWebhookEnabled(final Participant.WebhookEnabledType xTwilioWebhookEnabled){ + public ParticipantCreator setXTwilioWebhookEnabled( + final Participant.WebhookEnabledType xTwilioWebhookEnabled + ) { this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; return this; } - public ParticipantCreator setIdentity(final String identity){ + + public ParticipantCreator setIdentity(final String identity) { this.identity = identity; return this; } - public ParticipantCreator setMessagingBindingAddress(final String messagingBindingAddress){ + + public ParticipantCreator setMessagingBindingAddress( + final String messagingBindingAddress + ) { this.messagingBindingAddress = messagingBindingAddress; return this; } - public ParticipantCreator setMessagingBindingProxyAddress(final String messagingBindingProxyAddress){ + + public ParticipantCreator setMessagingBindingProxyAddress( + final String messagingBindingProxyAddress + ) { this.messagingBindingProxyAddress = messagingBindingProxyAddress; return this; } - public ParticipantCreator setDateCreated(final ZonedDateTime dateCreated){ + + public ParticipantCreator setDateCreated(final ZonedDateTime dateCreated) { this.dateCreated = dateCreated; return this; } - public ParticipantCreator setDateUpdated(final ZonedDateTime dateUpdated){ + + public ParticipantCreator setDateUpdated(final ZonedDateTime dateUpdated) { this.dateUpdated = dateUpdated; return this; } - public ParticipantCreator setAttributes(final String attributes){ + + public ParticipantCreator setAttributes(final String attributes) { this.attributes = attributes; return this; } - public ParticipantCreator setMessagingBindingProjectedAddress(final String messagingBindingProjectedAddress){ - this.messagingBindingProjectedAddress = messagingBindingProjectedAddress; + + public ParticipantCreator setMessagingBindingProjectedAddress( + final String messagingBindingProjectedAddress + ) { + this.messagingBindingProjectedAddress = + messagingBindingProjectedAddress; return this; } - public ParticipantCreator setRoleSid(final String roleSid){ + + public ParticipantCreator setRoleSid(final String roleSid) { this.roleSid = roleSid; return this; } @Override - public Participant create(final TwilioRestClient client){ + public Participant create(final TwilioRestClient client) { String path = "/v1/Conversations/{ConversationSid}/Participants"; - path = path.replace("{"+"ConversationSid"+"}", this.pathConversationSid.toString()); + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.CONVERSATIONS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); addHeaderParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Participant creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Participant creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Participant.fromJson(response.getStream(), client.getObjectMapper()); + return Participant.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (identity != null) { request.addPostParam("Identity", identity); - } if (messagingBindingAddress != null) { - request.addPostParam("MessagingBinding.Address", messagingBindingAddress); - + request.addPostParam( + "MessagingBinding.Address", + messagingBindingAddress + ); } if (messagingBindingProxyAddress != null) { - request.addPostParam("MessagingBinding.ProxyAddress", messagingBindingProxyAddress); - + request.addPostParam( + "MessagingBinding.ProxyAddress", + messagingBindingProxyAddress + ); } if (dateCreated != null) { - request.addPostParam("DateCreated", dateCreated.toInstant().toString()); - + request.addPostParam( + "DateCreated", + dateCreated.toInstant().toString() + ); } if (dateUpdated != null) { - request.addPostParam("DateUpdated", dateUpdated.toInstant().toString()); - + request.addPostParam( + "DateUpdated", + dateUpdated.toInstant().toString() + ); } if (attributes != null) { request.addPostParam("Attributes", attributes); - } if (messagingBindingProjectedAddress != null) { - request.addPostParam("MessagingBinding.ProjectedAddress", messagingBindingProjectedAddress); - + request.addPostParam( + "MessagingBinding.ProjectedAddress", + messagingBindingProjectedAddress + ); } if (roleSid != null) { request.addPostParam("RoleSid", roleSid); - } } + private void addHeaderParams(final Request request) { if (xTwilioWebhookEnabled != null) { - request.addHeaderParam("X-Twilio-Webhook-Enabled", xTwilioWebhookEnabled.toString()); - + request.addHeaderParam( + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/conversation/ParticipantDeleter.java b/src/main/java/com/twilio/rest/conversations/v1/conversation/ParticipantDeleter.java index 6db914cb3d..7c5bec22e3 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/conversation/ParticipantDeleter.java +++ b/src/main/java/com/twilio/rest/conversations/v1/conversation/ParticipantDeleter.java @@ -24,19 +24,23 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class ParticipantDeleter extends Deleter { + private String pathConversationSid; private String pathSid; private Participant.WebhookEnabledType xTwilioWebhookEnabled; - public ParticipantDeleter(final String pathConversationSid, final String pathSid){ + public ParticipantDeleter( + final String pathConversationSid, + final String pathSid + ) { this.pathConversationSid = pathConversationSid; this.pathSid = pathSid; } - public ParticipantDeleter setXTwilioWebhookEnabled(final Participant.WebhookEnabledType xTwilioWebhookEnabled){ + public ParticipantDeleter setXTwilioWebhookEnabled( + final Participant.WebhookEnabledType xTwilioWebhookEnabled + ) { this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; return this; } @@ -45,8 +49,12 @@ public ParticipantDeleter setXTwilioWebhookEnabled(final Participant.WebhookEnab public boolean delete(final TwilioRestClient client) { String path = "/v1/Conversations/{ConversationSid}/Participants/{Sid}"; - path = path.replace("{"+"ConversationSid"+"}", this.pathConversationSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -57,9 +65,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Participant delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Participant delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -67,10 +80,13 @@ public boolean delete(final TwilioRestClient client) { } return response.getStatusCode() == 204; } + private void addHeaderParams(final Request request) { if (xTwilioWebhookEnabled != null) { - request.addHeaderParam("X-Twilio-Webhook-Enabled", xTwilioWebhookEnabled.toString()); - + request.addHeaderParam( + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/conversation/ParticipantFetcher.java b/src/main/java/com/twilio/rest/conversations/v1/conversation/ParticipantFetcher.java index eb6c465878..06e1fd6a67 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/conversation/ParticipantFetcher.java +++ b/src/main/java/com/twilio/rest/conversations/v1/conversation/ParticipantFetcher.java @@ -24,25 +24,29 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class ParticipantFetcher extends Fetcher { + private String pathConversationSid; private String pathSid; - public ParticipantFetcher(final String pathConversationSid, final String pathSid){ + public ParticipantFetcher( + final String pathConversationSid, + final String pathSid + ) { this.pathConversationSid = pathConversationSid; this.pathSid = pathSid; } - @Override public Participant fetch(final TwilioRestClient client) { String path = "/v1/Conversations/{ConversationSid}/Participants/{Sid}"; - path = path.replace("{"+"ConversationSid"+"}", this.pathConversationSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,15 +56,23 @@ public Participant fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Participant fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Participant fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Participant.fromJson(response.getStream(), client.getObjectMapper()); + return Participant.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/conversation/ParticipantReader.java b/src/main/java/com/twilio/rest/conversations/v1/conversation/ParticipantReader.java index 80a91a155c..91c1df1b81 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/conversation/ParticipantReader.java +++ b/src/main/java/com/twilio/rest/conversations/v1/conversation/ParticipantReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.conversations.v1.conversation; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,19 +25,17 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class ParticipantReader extends Reader { + private String pathConversationSid; private Integer pageSize; - public ParticipantReader(final String pathConversationSid){ + public ParticipantReader(final String pathConversationSid) { this.pathConversationSid = pathConversationSid; } - public ParticipantReader setPageSize(final Integer pageSize){ + public ParticipantReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -48,7 +47,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Conversations/{ConversationSid}/Participants"; - path = path.replace("{"+"ConversationSid"+"}", this.pathConversationSid.toString()); + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -60,13 +63,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Participant read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Participant read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +93,10 @@ private Page pageForRequest(final TwilioRestClient client, final Re } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.CONVERSATIONS.toString()) @@ -90,9 +104,11 @@ public Page previousPage(final Page page, final Twilio return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.CONVERSATIONS.toString()) @@ -101,21 +117,21 @@ public Page nextPage(final Page page, final TwilioRest } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/conversation/ParticipantUpdater.java b/src/main/java/com/twilio/rest/conversations/v1/conversation/ParticipantUpdater.java index 5b691afff7..56281949b3 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/conversation/ParticipantUpdater.java +++ b/src/main/java/com/twilio/rest/conversations/v1/conversation/ParticipantUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.conversations.v1.conversation; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -23,12 +24,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.time.ZonedDateTime; +public class ParticipantUpdater extends Updater { - -public class ParticipantUpdater extends Updater{ private String pathConversationSid; private String pathSid; private Participant.WebhookEnabledType xTwilioWebhookEnabled; @@ -42,121 +41,167 @@ public class ParticipantUpdater extends Updater{ private Integer lastReadMessageIndex; private String lastReadTimestamp; - public ParticipantUpdater(final String pathConversationSid, final String pathSid){ + public ParticipantUpdater( + final String pathConversationSid, + final String pathSid + ) { this.pathConversationSid = pathConversationSid; this.pathSid = pathSid; } - public ParticipantUpdater setXTwilioWebhookEnabled(final Participant.WebhookEnabledType xTwilioWebhookEnabled){ + public ParticipantUpdater setXTwilioWebhookEnabled( + final Participant.WebhookEnabledType xTwilioWebhookEnabled + ) { this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; return this; } - public ParticipantUpdater setDateCreated(final ZonedDateTime dateCreated){ + + public ParticipantUpdater setDateCreated(final ZonedDateTime dateCreated) { this.dateCreated = dateCreated; return this; } - public ParticipantUpdater setDateUpdated(final ZonedDateTime dateUpdated){ + + public ParticipantUpdater setDateUpdated(final ZonedDateTime dateUpdated) { this.dateUpdated = dateUpdated; return this; } - public ParticipantUpdater setAttributes(final String attributes){ + + public ParticipantUpdater setAttributes(final String attributes) { this.attributes = attributes; return this; } - public ParticipantUpdater setRoleSid(final String roleSid){ + + public ParticipantUpdater setRoleSid(final String roleSid) { this.roleSid = roleSid; return this; } - public ParticipantUpdater setMessagingBindingProxyAddress(final String messagingBindingProxyAddress){ + + public ParticipantUpdater setMessagingBindingProxyAddress( + final String messagingBindingProxyAddress + ) { this.messagingBindingProxyAddress = messagingBindingProxyAddress; return this; } - public ParticipantUpdater setMessagingBindingProjectedAddress(final String messagingBindingProjectedAddress){ - this.messagingBindingProjectedAddress = messagingBindingProjectedAddress; + + public ParticipantUpdater setMessagingBindingProjectedAddress( + final String messagingBindingProjectedAddress + ) { + this.messagingBindingProjectedAddress = + messagingBindingProjectedAddress; return this; } - public ParticipantUpdater setIdentity(final String identity){ + + public ParticipantUpdater setIdentity(final String identity) { this.identity = identity; return this; } - public ParticipantUpdater setLastReadMessageIndex(final Integer lastReadMessageIndex){ + + public ParticipantUpdater setLastReadMessageIndex( + final Integer lastReadMessageIndex + ) { this.lastReadMessageIndex = lastReadMessageIndex; return this; } - public ParticipantUpdater setLastReadTimestamp(final String lastReadTimestamp){ + + public ParticipantUpdater setLastReadTimestamp( + final String lastReadTimestamp + ) { this.lastReadTimestamp = lastReadTimestamp; return this; } @Override - public Participant update(final TwilioRestClient client){ + public Participant update(final TwilioRestClient client) { String path = "/v1/Conversations/{ConversationSid}/Participants/{Sid}"; - path = path.replace("{"+"ConversationSid"+"}", this.pathConversationSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.CONVERSATIONS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); addHeaderParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Participant update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Participant update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Participant.fromJson(response.getStream(), client.getObjectMapper()); + return Participant.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (dateCreated != null) { - request.addPostParam("DateCreated", dateCreated.toInstant().toString()); - + request.addPostParam( + "DateCreated", + dateCreated.toInstant().toString() + ); } if (dateUpdated != null) { - request.addPostParam("DateUpdated", dateUpdated.toInstant().toString()); - + request.addPostParam( + "DateUpdated", + dateUpdated.toInstant().toString() + ); } if (attributes != null) { request.addPostParam("Attributes", attributes); - } if (roleSid != null) { request.addPostParam("RoleSid", roleSid); - } if (messagingBindingProxyAddress != null) { - request.addPostParam("MessagingBinding.ProxyAddress", messagingBindingProxyAddress); - + request.addPostParam( + "MessagingBinding.ProxyAddress", + messagingBindingProxyAddress + ); } if (messagingBindingProjectedAddress != null) { - request.addPostParam("MessagingBinding.ProjectedAddress", messagingBindingProjectedAddress); - + request.addPostParam( + "MessagingBinding.ProjectedAddress", + messagingBindingProjectedAddress + ); } if (identity != null) { request.addPostParam("Identity", identity); - } if (lastReadMessageIndex != null) { - request.addPostParam("LastReadMessageIndex", lastReadMessageIndex.toString()); - + request.addPostParam( + "LastReadMessageIndex", + lastReadMessageIndex.toString() + ); } if (lastReadTimestamp != null) { request.addPostParam("LastReadTimestamp", lastReadTimestamp); - } } + private void addHeaderParams(final Request request) { if (xTwilioWebhookEnabled != null) { - request.addHeaderParam("X-Twilio-Webhook-Enabled", xTwilioWebhookEnabled.toString()); - + request.addHeaderParam( + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/conversation/Webhook.java b/src/main/java/com/twilio/rest/conversations/v1/conversation/Webhook.java index c8e9ef2dc9..2b01b65a9c 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/conversation/Webhook.java +++ b/src/main/java/com/twilio/rest/conversations/v1/conversation/Webhook.java @@ -24,55 +24,66 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Webhook extends Resource { + private static final long serialVersionUID = 253771507397775L; - public static WebhookCreator creator(final String pathConversationSid, final Webhook.Target target){ + public static WebhookCreator creator( + final String pathConversationSid, + final Webhook.Target target + ) { return new WebhookCreator(pathConversationSid, target); } - public static WebhookDeleter deleter(final String pathConversationSid, final String pathSid){ + public static WebhookDeleter deleter( + final String pathConversationSid, + final String pathSid + ) { return new WebhookDeleter(pathConversationSid, pathSid); } - public static WebhookFetcher fetcher(final String pathConversationSid, final String pathSid){ + public static WebhookFetcher fetcher( + final String pathConversationSid, + final String pathSid + ) { return new WebhookFetcher(pathConversationSid, pathSid); } - public static WebhookReader reader(final String pathConversationSid){ + public static WebhookReader reader(final String pathConversationSid) { return new WebhookReader(pathConversationSid); } - public static WebhookUpdater updater(final String pathConversationSid, final String pathSid){ + public static WebhookUpdater updater( + final String pathConversationSid, + final String pathSid + ) { return new WebhookUpdater(pathConversationSid, pathSid); } /** - * Converts a JSON String into a Webhook object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Webhook object represented by the provided JSON - */ - public static Webhook fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Webhook object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Webhook object represented by the provided JSON + */ + public static Webhook fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Webhook.class); @@ -84,14 +95,17 @@ public static Webhook fromJson(final String json, final ObjectMapper objectMappe } /** - * Converts a JSON InputStream into a Webhook object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Webhook object represented by the provided JSON - */ - public static Webhook fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Webhook object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Webhook object represented by the provided JSON + */ + public static Webhook fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Webhook.class); @@ -101,6 +115,7 @@ public static Webhook fromJson(final InputStream json, final ObjectMapper object throw new ApiConnectionException(e.getMessage(), e); } } + public enum Method { GET("GET"), POST("POST"); @@ -120,6 +135,7 @@ public static Method forValue(final String value) { return Promoter.enumFromString(value, Method.values()); } } + public enum Target { WEBHOOK("webhook"), TRIGGER("trigger"), @@ -152,29 +168,14 @@ public static Target forValue(final String value) { @JsonCreator private Webhook( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("conversation_sid") - final String conversationSid, - - @JsonProperty("target") - final String target, - - @JsonProperty("url") - final URI url, - - @JsonProperty("configuration") - final Map configuration, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("conversation_sid") final String conversationSid, + @JsonProperty("target") final String target, + @JsonProperty("url") final URI url, + @JsonProperty("configuration") final Map configuration, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated ) { this.sid = sid; this.accountSid = accountSid; @@ -186,34 +187,41 @@ private Webhook( this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getConversationSid() { - return this.conversationSid; - } - public final String getTarget() { - return this.target; - } - public final URI getUrl() { - return this.url; - } - public final Map getConfiguration() { - return this.configuration; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getConversationSid() { + return this.conversationSid; + } + + public final String getTarget() { + return this.target; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getConfiguration() { + return this.configuration; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -223,13 +231,29 @@ public boolean equals(final Object o) { Webhook other = (Webhook) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(conversationSid, other.conversationSid) && Objects.equals(target, other.target) && Objects.equals(url, other.url) && Objects.equals(configuration, other.configuration) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(conversationSid, other.conversationSid) && + Objects.equals(target, other.target) && + Objects.equals(url, other.url) && + Objects.equals(configuration, other.configuration) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, conversationSid, target, url, configuration, dateCreated, dateUpdated); + return Objects.hash( + sid, + accountSid, + conversationSid, + target, + url, + configuration, + dateCreated, + dateUpdated + ); } - } - diff --git a/src/main/java/com/twilio/rest/conversations/v1/conversation/WebhookCreator.java b/src/main/java/com/twilio/rest/conversations/v1/conversation/WebhookCreator.java index 98fdf03c65..5b09147eb6 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/conversation/WebhookCreator.java +++ b/src/main/java/com/twilio/rest/conversations/v1/conversation/WebhookCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.conversations.v1.conversation; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -25,12 +26,10 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.util.List; - import java.util.List; +public class WebhookCreator extends Creator { - -public class WebhookCreator extends Creator{ private String pathConversationSid; private Webhook.Target target; private String configurationUrl; @@ -40,64 +39,103 @@ public class WebhookCreator extends Creator{ private String configurationFlowSid; private Integer configurationReplayAfter; - public WebhookCreator(final String pathConversationSid, final Webhook.Target target) { + public WebhookCreator( + final String pathConversationSid, + final Webhook.Target target + ) { this.pathConversationSid = pathConversationSid; this.target = target; } - public WebhookCreator setTarget(final Webhook.Target target){ + public WebhookCreator setTarget(final Webhook.Target target) { this.target = target; return this; } - public WebhookCreator setConfigurationUrl(final String configurationUrl){ + + public WebhookCreator setConfigurationUrl(final String configurationUrl) { this.configurationUrl = configurationUrl; return this; } - public WebhookCreator setConfigurationMethod(final Webhook.Method configurationMethod){ + + public WebhookCreator setConfigurationMethod( + final Webhook.Method configurationMethod + ) { this.configurationMethod = configurationMethod; return this; } - public WebhookCreator setConfigurationFilters(final List configurationFilters){ + + public WebhookCreator setConfigurationFilters( + final List configurationFilters + ) { this.configurationFilters = configurationFilters; return this; } - public WebhookCreator setConfigurationFilters(final String configurationFilters){ - return setConfigurationFilters(Promoter.listOfOne(configurationFilters)); + + public WebhookCreator setConfigurationFilters( + final String configurationFilters + ) { + return setConfigurationFilters( + Promoter.listOfOne(configurationFilters) + ); } - public WebhookCreator setConfigurationTriggers(final List configurationTriggers){ + + public WebhookCreator setConfigurationTriggers( + final List configurationTriggers + ) { this.configurationTriggers = configurationTriggers; return this; } - public WebhookCreator setConfigurationTriggers(final String configurationTriggers){ - return setConfigurationTriggers(Promoter.listOfOne(configurationTriggers)); + + public WebhookCreator setConfigurationTriggers( + final String configurationTriggers + ) { + return setConfigurationTriggers( + Promoter.listOfOne(configurationTriggers) + ); } - public WebhookCreator setConfigurationFlowSid(final String configurationFlowSid){ + + public WebhookCreator setConfigurationFlowSid( + final String configurationFlowSid + ) { this.configurationFlowSid = configurationFlowSid; return this; } - public WebhookCreator setConfigurationReplayAfter(final Integer configurationReplayAfter){ + + public WebhookCreator setConfigurationReplayAfter( + final Integer configurationReplayAfter + ) { this.configurationReplayAfter = configurationReplayAfter; return this; } @Override - public Webhook create(final TwilioRestClient client){ + public Webhook create(final TwilioRestClient client) { String path = "/v1/Conversations/{ConversationSid}/Webhooks"; - path = path.replace("{"+"ConversationSid"+"}", this.pathConversationSid.toString()); - path = path.replace("{"+"Target"+"}", this.target.toString()); + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + path = path.replace("{" + "Target" + "}", this.target.toString()); Request request = new Request( HttpMethod.POST, Domains.CONVERSATIONS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Webhook creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Webhook creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -106,38 +144,38 @@ public Webhook create(final TwilioRestClient client){ return Webhook.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (target != null) { request.addPostParam("Target", target.toString()); - } if (configurationUrl != null) { request.addPostParam("Configuration.Url", configurationUrl); - } if (configurationMethod != null) { - request.addPostParam("Configuration.Method", configurationMethod.toString()); - + request.addPostParam( + "Configuration.Method", + configurationMethod.toString() + ); } if (configurationFilters != null) { for (String prop : configurationFilters) { request.addPostParam("Configuration.Filters", prop); } - } if (configurationTriggers != null) { for (String prop : configurationTriggers) { request.addPostParam("Configuration.Triggers", prop); } - } if (configurationFlowSid != null) { request.addPostParam("Configuration.FlowSid", configurationFlowSid); - } if (configurationReplayAfter != null) { - request.addPostParam("Configuration.ReplayAfter", configurationReplayAfter.toString()); - + request.addPostParam( + "Configuration.ReplayAfter", + configurationReplayAfter.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/conversation/WebhookDeleter.java b/src/main/java/com/twilio/rest/conversations/v1/conversation/WebhookDeleter.java index d478cbb289..bb11e502bf 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/conversation/WebhookDeleter.java +++ b/src/main/java/com/twilio/rest/conversations/v1/conversation/WebhookDeleter.java @@ -24,24 +24,29 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class WebhookDeleter extends Deleter { + private String pathConversationSid; private String pathSid; - public WebhookDeleter(final String pathConversationSid, final String pathSid){ + public WebhookDeleter( + final String pathConversationSid, + final String pathSid + ) { this.pathConversationSid = pathConversationSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Conversations/{ConversationSid}/Webhooks/{Sid}"; - path = path.replace("{"+"ConversationSid"+"}", this.pathConversationSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +56,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Webhook delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Webhook delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/conversations/v1/conversation/WebhookFetcher.java b/src/main/java/com/twilio/rest/conversations/v1/conversation/WebhookFetcher.java index 4e13eb99d3..de692ee6e4 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/conversation/WebhookFetcher.java +++ b/src/main/java/com/twilio/rest/conversations/v1/conversation/WebhookFetcher.java @@ -24,25 +24,29 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class WebhookFetcher extends Fetcher { + private String pathConversationSid; private String pathSid; - public WebhookFetcher(final String pathConversationSid, final String pathSid){ + public WebhookFetcher( + final String pathConversationSid, + final String pathSid + ) { this.pathConversationSid = pathConversationSid; this.pathSid = pathSid; } - @Override public Webhook fetch(final TwilioRestClient client) { String path = "/v1/Conversations/{ConversationSid}/Webhooks/{Sid}"; - path = path.replace("{"+"ConversationSid"+"}", this.pathConversationSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,9 +56,14 @@ public Webhook fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Webhook fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Webhook fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/conversations/v1/conversation/WebhookReader.java b/src/main/java/com/twilio/rest/conversations/v1/conversation/WebhookReader.java index 03af0a5c5f..7ecf978a7a 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/conversation/WebhookReader.java +++ b/src/main/java/com/twilio/rest/conversations/v1/conversation/WebhookReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.conversations.v1.conversation; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,19 +25,17 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class WebhookReader extends Reader { + private String pathConversationSid; private Integer pageSize; - public WebhookReader(final String pathConversationSid){ + public WebhookReader(final String pathConversationSid) { this.pathConversationSid = pathConversationSid; } - public WebhookReader setPageSize(final Integer pageSize){ + public WebhookReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -48,7 +47,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Conversations/{ConversationSid}/Webhooks"; - path = path.replace("{"+"ConversationSid"+"}", this.pathConversationSid.toString()); + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -60,13 +63,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Webhook read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Webhook read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +93,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reques } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.CONVERSATIONS.toString()) @@ -90,9 +104,11 @@ public Page previousPage(final Page page, final TwilioRestClie return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.CONVERSATIONS.toString()) @@ -101,21 +117,21 @@ public Page nextPage(final Page page, final TwilioRestClient c } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/conversation/WebhookUpdater.java b/src/main/java/com/twilio/rest/conversations/v1/conversation/WebhookUpdater.java index d8e7bc29cc..e7cfb07714 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/conversation/WebhookUpdater.java +++ b/src/main/java/com/twilio/rest/conversations/v1/conversation/WebhookUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.conversations.v1.conversation; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -24,12 +25,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - import java.util.List; +public class WebhookUpdater extends Updater { -public class WebhookUpdater extends Updater{ private String pathConversationSid; private String pathSid; private String configurationUrl; @@ -38,56 +37,91 @@ public class WebhookUpdater extends Updater{ private List configurationTriggers; private String configurationFlowSid; - public WebhookUpdater(final String pathConversationSid, final String pathSid){ + public WebhookUpdater( + final String pathConversationSid, + final String pathSid + ) { this.pathConversationSid = pathConversationSid; this.pathSid = pathSid; } - public WebhookUpdater setConfigurationUrl(final String configurationUrl){ + public WebhookUpdater setConfigurationUrl(final String configurationUrl) { this.configurationUrl = configurationUrl; return this; } - public WebhookUpdater setConfigurationMethod(final Webhook.Method configurationMethod){ + + public WebhookUpdater setConfigurationMethod( + final Webhook.Method configurationMethod + ) { this.configurationMethod = configurationMethod; return this; } - public WebhookUpdater setConfigurationFilters(final List configurationFilters){ + + public WebhookUpdater setConfigurationFilters( + final List configurationFilters + ) { this.configurationFilters = configurationFilters; return this; } - public WebhookUpdater setConfigurationFilters(final String configurationFilters){ - return setConfigurationFilters(Promoter.listOfOne(configurationFilters)); + + public WebhookUpdater setConfigurationFilters( + final String configurationFilters + ) { + return setConfigurationFilters( + Promoter.listOfOne(configurationFilters) + ); } - public WebhookUpdater setConfigurationTriggers(final List configurationTriggers){ + + public WebhookUpdater setConfigurationTriggers( + final List configurationTriggers + ) { this.configurationTriggers = configurationTriggers; return this; } - public WebhookUpdater setConfigurationTriggers(final String configurationTriggers){ - return setConfigurationTriggers(Promoter.listOfOne(configurationTriggers)); + + public WebhookUpdater setConfigurationTriggers( + final String configurationTriggers + ) { + return setConfigurationTriggers( + Promoter.listOfOne(configurationTriggers) + ); } - public WebhookUpdater setConfigurationFlowSid(final String configurationFlowSid){ + + public WebhookUpdater setConfigurationFlowSid( + final String configurationFlowSid + ) { this.configurationFlowSid = configurationFlowSid; return this; } @Override - public Webhook update(final TwilioRestClient client){ + public Webhook update(final TwilioRestClient client) { String path = "/v1/Conversations/{ConversationSid}/Webhooks/{Sid}"; - path = path.replace("{"+"ConversationSid"+"}", this.pathConversationSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.CONVERSATIONS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Webhook update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Webhook update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -96,30 +130,29 @@ public Webhook update(final TwilioRestClient client){ return Webhook.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (configurationUrl != null) { request.addPostParam("Configuration.Url", configurationUrl); - } if (configurationMethod != null) { - request.addPostParam("Configuration.Method", configurationMethod.toString()); - + request.addPostParam( + "Configuration.Method", + configurationMethod.toString() + ); } if (configurationFilters != null) { for (String prop : configurationFilters) { request.addPostParam("Configuration.Filters", prop); } - } if (configurationTriggers != null) { for (String prop : configurationTriggers) { request.addPostParam("Configuration.Triggers", prop); } - } if (configurationFlowSid != null) { request.addPostParam("Configuration.FlowSid", configurationFlowSid); - } } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/conversation/message/DeliveryReceipt.java b/src/main/java/com/twilio/rest/conversations/v1/conversation/message/DeliveryReceipt.java index 26db80d4ed..0bbf9d25ce 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/conversation/message/DeliveryReceipt.java +++ b/src/main/java/com/twilio/rest/conversations/v1/conversation/message/DeliveryReceipt.java @@ -24,41 +24,51 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class DeliveryReceipt extends Resource { + private static final long serialVersionUID = 126608153820635L; - public static DeliveryReceiptFetcher fetcher(final String pathConversationSid, final String pathMessageSid, final String pathSid){ - return new DeliveryReceiptFetcher(pathConversationSid, pathMessageSid, pathSid); + public static DeliveryReceiptFetcher fetcher( + final String pathConversationSid, + final String pathMessageSid, + final String pathSid + ) { + return new DeliveryReceiptFetcher( + pathConversationSid, + pathMessageSid, + pathSid + ); } - public static DeliveryReceiptReader reader(final String pathConversationSid, final String pathMessageSid){ + public static DeliveryReceiptReader reader( + final String pathConversationSid, + final String pathMessageSid + ) { return new DeliveryReceiptReader(pathConversationSid, pathMessageSid); } /** - * Converts a JSON String into a DeliveryReceipt object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return DeliveryReceipt object represented by the provided JSON - */ - public static DeliveryReceipt fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a DeliveryReceipt object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return DeliveryReceipt object represented by the provided JSON + */ + public static DeliveryReceipt fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, DeliveryReceipt.class); @@ -70,14 +80,17 @@ public static DeliveryReceipt fromJson(final String json, final ObjectMapper obj } /** - * Converts a JSON InputStream into a DeliveryReceipt object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return DeliveryReceipt object represented by the provided JSON - */ - public static DeliveryReceipt fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a DeliveryReceipt object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return DeliveryReceipt object represented by the provided JSON + */ + public static DeliveryReceipt fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, DeliveryReceipt.class); @@ -87,6 +100,7 @@ public static DeliveryReceipt fromJson(final InputStream json, final ObjectMappe throw new ApiConnectionException(e.getMessage(), e); } } + public enum DeliveryStatus { READ("read"), FAILED("failed"), @@ -124,38 +138,17 @@ public static DeliveryStatus forValue(final String value) { @JsonCreator private DeliveryReceipt( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("conversation_sid") - final String conversationSid, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("message_sid") - final String messageSid, - - @JsonProperty("channel_message_sid") - final String channelMessageSid, - - @JsonProperty("participant_sid") - final String participantSid, - - @JsonProperty("status") - final DeliveryReceipt.DeliveryStatus status, - - @JsonProperty("error_code") - final Integer errorCode, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("conversation_sid") final String conversationSid, + @JsonProperty("sid") final String sid, + @JsonProperty("message_sid") final String messageSid, + @JsonProperty("channel_message_sid") final String channelMessageSid, + @JsonProperty("participant_sid") final String participantSid, + @JsonProperty("status") final DeliveryReceipt.DeliveryStatus status, + @JsonProperty("error_code") final Integer errorCode, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url ) { this.accountSid = accountSid; this.conversationSid = conversationSid; @@ -170,43 +163,53 @@ private DeliveryReceipt( this.url = url; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getConversationSid() { - return this.conversationSid; - } - public final String getSid() { - return this.sid; - } - public final String getMessageSid() { - return this.messageSid; - } - public final String getChannelMessageSid() { - return this.channelMessageSid; - } - public final String getParticipantSid() { - return this.participantSid; - } - public final DeliveryReceipt.DeliveryStatus getStatus() { - return this.status; - } - public final Integer getErrorCode() { - return this.errorCode; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getConversationSid() { + return this.conversationSid; + } + + public final String getSid() { + return this.sid; + } + + public final String getMessageSid() { + return this.messageSid; + } + + public final String getChannelMessageSid() { + return this.channelMessageSid; + } + + public final String getParticipantSid() { + return this.participantSid; + } + + public final DeliveryReceipt.DeliveryStatus getStatus() { + return this.status; + } + + public final Integer getErrorCode() { + return this.errorCode; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -216,13 +219,35 @@ public boolean equals(final Object o) { DeliveryReceipt other = (DeliveryReceipt) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(conversationSid, other.conversationSid) && Objects.equals(sid, other.sid) && Objects.equals(messageSid, other.messageSid) && Objects.equals(channelMessageSid, other.channelMessageSid) && Objects.equals(participantSid, other.participantSid) && Objects.equals(status, other.status) && Objects.equals(errorCode, other.errorCode) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(conversationSid, other.conversationSid) && + Objects.equals(sid, other.sid) && + Objects.equals(messageSid, other.messageSid) && + Objects.equals(channelMessageSid, other.channelMessageSid) && + Objects.equals(participantSid, other.participantSid) && + Objects.equals(status, other.status) && + Objects.equals(errorCode, other.errorCode) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, conversationSid, sid, messageSid, channelMessageSid, participantSid, status, errorCode, dateCreated, dateUpdated, url); + return Objects.hash( + accountSid, + conversationSid, + sid, + messageSid, + channelMessageSid, + participantSid, + status, + errorCode, + dateCreated, + dateUpdated, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/conversations/v1/conversation/message/DeliveryReceiptFetcher.java b/src/main/java/com/twilio/rest/conversations/v1/conversation/message/DeliveryReceiptFetcher.java index 05036b5281..021f725d2e 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/conversation/message/DeliveryReceiptFetcher.java +++ b/src/main/java/com/twilio/rest/conversations/v1/conversation/message/DeliveryReceiptFetcher.java @@ -24,28 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class DeliveryReceiptFetcher extends Fetcher { + private String pathConversationSid; private String pathMessageSid; private String pathSid; - public DeliveryReceiptFetcher(final String pathConversationSid, final String pathMessageSid, final String pathSid){ + public DeliveryReceiptFetcher( + final String pathConversationSid, + final String pathMessageSid, + final String pathSid + ) { this.pathConversationSid = pathConversationSid; this.pathMessageSid = pathMessageSid; this.pathSid = pathSid; } - @Override public DeliveryReceipt fetch(final TwilioRestClient client) { - String path = "/v1/Conversations/{ConversationSid}/Messages/{MessageSid}/Receipts/{Sid}"; + String path = + "/v1/Conversations/{ConversationSid}/Messages/{MessageSid}/Receipts/{Sid}"; - path = path.replace("{"+"ConversationSid"+"}", this.pathConversationSid.toString()); - path = path.replace("{"+"MessageSid"+"}", this.pathMessageSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + path = + path.replace( + "{" + "MessageSid" + "}", + this.pathMessageSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -55,15 +65,23 @@ public DeliveryReceipt fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("DeliveryReceipt fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "DeliveryReceipt fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return DeliveryReceipt.fromJson(response.getStream(), client.getObjectMapper()); + return DeliveryReceipt.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/conversation/message/DeliveryReceiptReader.java b/src/main/java/com/twilio/rest/conversations/v1/conversation/message/DeliveryReceiptReader.java index c237497a9e..e18a75dbfd 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/conversation/message/DeliveryReceiptReader.java +++ b/src/main/java/com/twilio/rest/conversations/v1/conversation/message/DeliveryReceiptReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.conversations.v1.conversation.message; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,21 +25,22 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class DeliveryReceiptReader extends Reader { + private String pathConversationSid; private String pathMessageSid; private Integer pageSize; - public DeliveryReceiptReader(final String pathConversationSid, final String pathMessageSid){ + public DeliveryReceiptReader( + final String pathConversationSid, + final String pathMessageSid + ) { this.pathConversationSid = pathConversationSid; this.pathMessageSid = pathMessageSid; } - public DeliveryReceiptReader setPageSize(final Integer pageSize){ + public DeliveryReceiptReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -49,9 +51,18 @@ public ResourceSet read(final TwilioRestClient client) { } public Page firstPage(final TwilioRestClient client) { - String path = "/v1/Conversations/{ConversationSid}/Messages/{MessageSid}/Receipts"; - path = path.replace("{"+"ConversationSid"+"}", this.pathConversationSid.toString()); - path = path.replace("{"+"MessageSid"+"}", this.pathMessageSid.toString()); + String path = + "/v1/Conversations/{ConversationSid}/Messages/{MessageSid}/Receipts"; + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + path = + path.replace( + "{" + "MessageSid" + "}", + this.pathMessageSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -63,13 +74,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("DeliveryReceipt read failed: Unable to connect to server"); + throw new ApiConnectionException( + "DeliveryReceipt read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -85,7 +104,10 @@ private Page pageForRequest(final TwilioRestClient client, fina } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.CONVERSATIONS.toString()) @@ -93,9 +115,11 @@ public Page previousPage(final Page page, fina return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.CONVERSATIONS.toString()) @@ -104,21 +128,21 @@ public Page nextPage(final Page page, final Tw } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/Binding.java b/src/main/java/com/twilio/rest/conversations/v1/service/Binding.java index 03c4df4db0..4e66e21f87 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/service/Binding.java +++ b/src/main/java/com/twilio/rest/conversations/v1/service/Binding.java @@ -24,46 +24,51 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.List; import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Binding extends Resource { + private static final long serialVersionUID = 124400281339927L; - public static BindingDeleter deleter(final String pathChatServiceSid, final String pathSid){ + public static BindingDeleter deleter( + final String pathChatServiceSid, + final String pathSid + ) { return new BindingDeleter(pathChatServiceSid, pathSid); } - public static BindingFetcher fetcher(final String pathChatServiceSid, final String pathSid){ + public static BindingFetcher fetcher( + final String pathChatServiceSid, + final String pathSid + ) { return new BindingFetcher(pathChatServiceSid, pathSid); } - public static BindingReader reader(final String pathChatServiceSid){ + public static BindingReader reader(final String pathChatServiceSid) { return new BindingReader(pathChatServiceSid); } /** - * Converts a JSON String into a Binding object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Binding object represented by the provided JSON - */ - public static Binding fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Binding object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Binding object represented by the provided JSON + */ + public static Binding fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Binding.class); @@ -75,14 +80,17 @@ public static Binding fromJson(final String json, final ObjectMapper objectMappe } /** - * Converts a JSON InputStream into a Binding object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Binding object represented by the provided JSON - */ - public static Binding fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Binding object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Binding object represented by the provided JSON + */ + public static Binding fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Binding.class); @@ -92,6 +100,7 @@ public static Binding fromJson(final InputStream json, final ObjectMapper object throw new ApiConnectionException(e.getMessage(), e); } } + public enum BindingType { APN("apn"), GCM("gcm"), @@ -127,38 +136,17 @@ public static BindingType forValue(final String value) { @JsonCreator private Binding( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("chat_service_sid") - final String chatServiceSid, - - @JsonProperty("credential_sid") - final String credentialSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("endpoint") - final String endpoint, - - @JsonProperty("identity") - final String identity, - - @JsonProperty("binding_type") - final Binding.BindingType bindingType, - - @JsonProperty("message_types") - final List messageTypes, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("chat_service_sid") final String chatServiceSid, + @JsonProperty("credential_sid") final String credentialSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("endpoint") final String endpoint, + @JsonProperty("identity") final String identity, + @JsonProperty("binding_type") final Binding.BindingType bindingType, + @JsonProperty("message_types") final List messageTypes, + @JsonProperty("url") final URI url ) { this.sid = sid; this.accountSid = accountSid; @@ -173,43 +161,53 @@ private Binding( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getChatServiceSid() { - return this.chatServiceSid; - } - public final String getCredentialSid() { - return this.credentialSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getEndpoint() { - return this.endpoint; - } - public final String getIdentity() { - return this.identity; - } - public final Binding.BindingType getBindingType() { - return this.bindingType; - } - public final List getMessageTypes() { - return this.messageTypes; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getChatServiceSid() { + return this.chatServiceSid; + } + + public final String getCredentialSid() { + return this.credentialSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getEndpoint() { + return this.endpoint; + } + + public final String getIdentity() { + return this.identity; + } + + public final Binding.BindingType getBindingType() { + return this.bindingType; + } + + public final List getMessageTypes() { + return this.messageTypes; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -219,13 +217,35 @@ public boolean equals(final Object o) { Binding other = (Binding) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(chatServiceSid, other.chatServiceSid) && Objects.equals(credentialSid, other.credentialSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(endpoint, other.endpoint) && Objects.equals(identity, other.identity) && Objects.equals(bindingType, other.bindingType) && Objects.equals(messageTypes, other.messageTypes) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(chatServiceSid, other.chatServiceSid) && + Objects.equals(credentialSid, other.credentialSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(endpoint, other.endpoint) && + Objects.equals(identity, other.identity) && + Objects.equals(bindingType, other.bindingType) && + Objects.equals(messageTypes, other.messageTypes) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, chatServiceSid, credentialSid, dateCreated, dateUpdated, endpoint, identity, bindingType, messageTypes, url); + return Objects.hash( + sid, + accountSid, + chatServiceSid, + credentialSid, + dateCreated, + dateUpdated, + endpoint, + identity, + bindingType, + messageTypes, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/BindingDeleter.java b/src/main/java/com/twilio/rest/conversations/v1/service/BindingDeleter.java index e279ce223b..ade3100414 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/service/BindingDeleter.java +++ b/src/main/java/com/twilio/rest/conversations/v1/service/BindingDeleter.java @@ -24,24 +24,29 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class BindingDeleter extends Deleter { + private String pathChatServiceSid; private String pathSid; - public BindingDeleter(final String pathChatServiceSid, final String pathSid){ + public BindingDeleter( + final String pathChatServiceSid, + final String pathSid + ) { this.pathChatServiceSid = pathChatServiceSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Services/{ChatServiceSid}/Bindings/{Sid}"; - path = path.replace("{"+"ChatServiceSid"+"}", this.pathChatServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +56,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Binding delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Binding delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/BindingFetcher.java b/src/main/java/com/twilio/rest/conversations/v1/service/BindingFetcher.java index 06161b2794..a3a19226a9 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/service/BindingFetcher.java +++ b/src/main/java/com/twilio/rest/conversations/v1/service/BindingFetcher.java @@ -24,25 +24,29 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class BindingFetcher extends Fetcher { + private String pathChatServiceSid; private String pathSid; - public BindingFetcher(final String pathChatServiceSid, final String pathSid){ + public BindingFetcher( + final String pathChatServiceSid, + final String pathSid + ) { this.pathChatServiceSid = pathChatServiceSid; this.pathSid = pathSid; } - @Override public Binding fetch(final TwilioRestClient client) { String path = "/v1/Services/{ChatServiceSid}/Bindings/{Sid}"; - path = path.replace("{"+"ChatServiceSid"+"}", this.pathChatServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,9 +56,14 @@ public Binding fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Binding fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Binding fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/BindingReader.java b/src/main/java/com/twilio/rest/conversations/v1/service/BindingReader.java index 7d85df2117..02ff867fa6 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/service/BindingReader.java +++ b/src/main/java/com/twilio/rest/conversations/v1/service/BindingReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.conversations.v1.service; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.converter.Promoter; @@ -25,36 +26,40 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - import java.util.List; - public class BindingReader extends Reader { + private String pathChatServiceSid; private List bindingType; private List identity; private Integer pageSize; - public BindingReader(final String pathChatServiceSid){ + public BindingReader(final String pathChatServiceSid) { this.pathChatServiceSid = pathChatServiceSid; } - public BindingReader setBindingType(final List bindingType){ + public BindingReader setBindingType( + final List bindingType + ) { this.bindingType = bindingType; return this; } - public BindingReader setBindingType(final Binding.BindingType bindingType){ + + public BindingReader setBindingType(final Binding.BindingType bindingType) { return setBindingType(Promoter.listOfOne(bindingType)); } - public BindingReader setIdentity(final List identity){ + + public BindingReader setIdentity(final List identity) { this.identity = identity; return this; } - public BindingReader setIdentity(final String identity){ + + public BindingReader setIdentity(final String identity) { return setIdentity(Promoter.listOfOne(identity)); } - public BindingReader setPageSize(final Integer pageSize){ + + public BindingReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -66,7 +71,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Services/{ChatServiceSid}/Bindings"; - path = path.replace("{"+"ChatServiceSid"+"}", this.pathChatServiceSid.toString()); + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -78,13 +87,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Binding read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Binding read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -100,7 +117,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reques } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.CONVERSATIONS.toString()) @@ -108,9 +128,11 @@ public Page previousPage(final Page page, final TwilioRestClie return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.CONVERSATIONS.toString()) @@ -119,14 +141,15 @@ public Page nextPage(final Page page, final TwilioRestClient c } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (bindingType != null) { for (Binding.BindingType prop : bindingType) { @@ -139,11 +162,10 @@ private void addQueryParams(final Request request) { } } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/Configuration.java b/src/main/java/com/twilio/rest/conversations/v1/service/Configuration.java index 7813a51151..9e686dae32 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/service/Configuration.java +++ b/src/main/java/com/twilio/rest/conversations/v1/service/Configuration.java @@ -22,42 +22,45 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Configuration extends Resource { + private static final long serialVersionUID = 35465460450497L; - public static ConfigurationFetcher fetcher(final String pathChatServiceSid){ + public static ConfigurationFetcher fetcher( + final String pathChatServiceSid + ) { return new ConfigurationFetcher(pathChatServiceSid); } - public static ConfigurationUpdater updater(final String pathChatServiceSid){ + public static ConfigurationUpdater updater( + final String pathChatServiceSid + ) { return new ConfigurationUpdater(pathChatServiceSid); } /** - * Converts a JSON String into a Configuration object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Configuration object represented by the provided JSON - */ - public static Configuration fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Configuration object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Configuration object represented by the provided JSON + */ + public static Configuration fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Configuration.class); @@ -69,14 +72,17 @@ public static Configuration fromJson(final String json, final ObjectMapper objec } /** - * Converts a JSON InputStream into a Configuration object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Configuration object represented by the provided JSON - */ - public static Configuration fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Configuration object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Configuration object represented by the provided JSON + */ + public static Configuration fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Configuration.class); @@ -97,29 +103,23 @@ public static Configuration fromJson(final InputStream json, final ObjectMapper @JsonCreator private Configuration( - @JsonProperty("chat_service_sid") - final String chatServiceSid, - - @JsonProperty("default_conversation_creator_role_sid") - final String defaultConversationCreatorRoleSid, - - @JsonProperty("default_conversation_role_sid") - final String defaultConversationRoleSid, - - @JsonProperty("default_chat_service_role_sid") - final String defaultChatServiceRoleSid, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links, - - @JsonProperty("reachability_enabled") - final Boolean reachabilityEnabled + @JsonProperty("chat_service_sid") final String chatServiceSid, + @JsonProperty( + "default_conversation_creator_role_sid" + ) final String defaultConversationCreatorRoleSid, + @JsonProperty( + "default_conversation_role_sid" + ) final String defaultConversationRoleSid, + @JsonProperty( + "default_chat_service_role_sid" + ) final String defaultChatServiceRoleSid, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links, + @JsonProperty("reachability_enabled") final Boolean reachabilityEnabled ) { this.chatServiceSid = chatServiceSid; - this.defaultConversationCreatorRoleSid = defaultConversationCreatorRoleSid; + this.defaultConversationCreatorRoleSid = + defaultConversationCreatorRoleSid; this.defaultConversationRoleSid = defaultConversationRoleSid; this.defaultChatServiceRoleSid = defaultChatServiceRoleSid; this.url = url; @@ -127,31 +127,37 @@ private Configuration( this.reachabilityEnabled = reachabilityEnabled; } - public final String getChatServiceSid() { - return this.chatServiceSid; - } - public final String getDefaultConversationCreatorRoleSid() { - return this.defaultConversationCreatorRoleSid; - } - public final String getDefaultConversationRoleSid() { - return this.defaultConversationRoleSid; - } - public final String getDefaultChatServiceRoleSid() { - return this.defaultChatServiceRoleSid; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } - public final Boolean getReachabilityEnabled() { - return this.reachabilityEnabled; - } + public final String getChatServiceSid() { + return this.chatServiceSid; + } + + public final String getDefaultConversationCreatorRoleSid() { + return this.defaultConversationCreatorRoleSid; + } + + public final String getDefaultConversationRoleSid() { + return this.defaultConversationRoleSid; + } + + public final String getDefaultChatServiceRoleSid() { + return this.defaultChatServiceRoleSid; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } + + public final Boolean getReachabilityEnabled() { + return this.reachabilityEnabled; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -161,13 +167,36 @@ public boolean equals(final Object o) { Configuration other = (Configuration) o; - return Objects.equals(chatServiceSid, other.chatServiceSid) && Objects.equals(defaultConversationCreatorRoleSid, other.defaultConversationCreatorRoleSid) && Objects.equals(defaultConversationRoleSid, other.defaultConversationRoleSid) && Objects.equals(defaultChatServiceRoleSid, other.defaultChatServiceRoleSid) && Objects.equals(url, other.url) && Objects.equals(links, other.links) && Objects.equals(reachabilityEnabled, other.reachabilityEnabled) ; + return ( + Objects.equals(chatServiceSid, other.chatServiceSid) && + Objects.equals( + defaultConversationCreatorRoleSid, + other.defaultConversationCreatorRoleSid + ) && + Objects.equals( + defaultConversationRoleSid, + other.defaultConversationRoleSid + ) && + Objects.equals( + defaultChatServiceRoleSid, + other.defaultChatServiceRoleSid + ) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) && + Objects.equals(reachabilityEnabled, other.reachabilityEnabled) + ); } @Override public int hashCode() { - return Objects.hash(chatServiceSid, defaultConversationCreatorRoleSid, defaultConversationRoleSid, defaultChatServiceRoleSid, url, links, reachabilityEnabled); + return Objects.hash( + chatServiceSid, + defaultConversationCreatorRoleSid, + defaultConversationRoleSid, + defaultChatServiceRoleSid, + url, + links, + reachabilityEnabled + ); } - } - diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/ConfigurationFetcher.java b/src/main/java/com/twilio/rest/conversations/v1/service/ConfigurationFetcher.java index 31d476ea55..808d47f496 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/service/ConfigurationFetcher.java +++ b/src/main/java/com/twilio/rest/conversations/v1/service/ConfigurationFetcher.java @@ -24,22 +24,23 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class ConfigurationFetcher extends Fetcher { + private String pathChatServiceSid; - public ConfigurationFetcher(final String pathChatServiceSid){ + public ConfigurationFetcher(final String pathChatServiceSid) { this.pathChatServiceSid = pathChatServiceSid; } - @Override public Configuration fetch(final TwilioRestClient client) { String path = "/v1/Services/{ChatServiceSid}/Configuration"; - path = path.replace("{"+"ChatServiceSid"+"}", this.pathChatServiceSid.toString()); + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -49,15 +50,23 @@ public Configuration fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Configuration fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Configuration fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Configuration.fromJson(response.getStream(), client.getObjectMapper()); + return Configuration.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/ConfigurationUpdater.java b/src/main/java/com/twilio/rest/conversations/v1/service/ConfigurationUpdater.java index 599830f0d2..243bdd03d2 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/service/ConfigurationUpdater.java +++ b/src/main/java/com/twilio/rest/conversations/v1/service/ConfigurationUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.conversations.v1.service; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,78 +25,110 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class ConfigurationUpdater extends Updater { - - -public class ConfigurationUpdater extends Updater{ private String pathChatServiceSid; private String defaultConversationCreatorRoleSid; private String defaultConversationRoleSid; private String defaultChatServiceRoleSid; private Boolean reachabilityEnabled; - public ConfigurationUpdater(final String pathChatServiceSid){ + public ConfigurationUpdater(final String pathChatServiceSid) { this.pathChatServiceSid = pathChatServiceSid; } - public ConfigurationUpdater setDefaultConversationCreatorRoleSid(final String defaultConversationCreatorRoleSid){ - this.defaultConversationCreatorRoleSid = defaultConversationCreatorRoleSid; + public ConfigurationUpdater setDefaultConversationCreatorRoleSid( + final String defaultConversationCreatorRoleSid + ) { + this.defaultConversationCreatorRoleSid = + defaultConversationCreatorRoleSid; return this; } - public ConfigurationUpdater setDefaultConversationRoleSid(final String defaultConversationRoleSid){ + + public ConfigurationUpdater setDefaultConversationRoleSid( + final String defaultConversationRoleSid + ) { this.defaultConversationRoleSid = defaultConversationRoleSid; return this; } - public ConfigurationUpdater setDefaultChatServiceRoleSid(final String defaultChatServiceRoleSid){ + + public ConfigurationUpdater setDefaultChatServiceRoleSid( + final String defaultChatServiceRoleSid + ) { this.defaultChatServiceRoleSid = defaultChatServiceRoleSid; return this; } - public ConfigurationUpdater setReachabilityEnabled(final Boolean reachabilityEnabled){ + + public ConfigurationUpdater setReachabilityEnabled( + final Boolean reachabilityEnabled + ) { this.reachabilityEnabled = reachabilityEnabled; return this; } @Override - public Configuration update(final TwilioRestClient client){ + public Configuration update(final TwilioRestClient client) { String path = "/v1/Services/{ChatServiceSid}/Configuration"; - path = path.replace("{"+"ChatServiceSid"+"}", this.pathChatServiceSid.toString()); + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.CONVERSATIONS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Configuration update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Configuration update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Configuration.fromJson(response.getStream(), client.getObjectMapper()); + return Configuration.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (defaultConversationCreatorRoleSid != null) { - request.addPostParam("DefaultConversationCreatorRoleSid", defaultConversationCreatorRoleSid); - + request.addPostParam( + "DefaultConversationCreatorRoleSid", + defaultConversationCreatorRoleSid + ); } if (defaultConversationRoleSid != null) { - request.addPostParam("DefaultConversationRoleSid", defaultConversationRoleSid); - + request.addPostParam( + "DefaultConversationRoleSid", + defaultConversationRoleSid + ); } if (defaultChatServiceRoleSid != null) { - request.addPostParam("DefaultChatServiceRoleSid", defaultChatServiceRoleSid); - + request.addPostParam( + "DefaultChatServiceRoleSid", + defaultChatServiceRoleSid + ); } if (reachabilityEnabled != null) { - request.addPostParam("ReachabilityEnabled", reachabilityEnabled.toString()); - + request.addPostParam( + "ReachabilityEnabled", + reachabilityEnabled.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/Conversation.java b/src/main/java/com/twilio/rest/conversations/v1/service/Conversation.java index d8c801621f..162e908f2c 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/service/Conversation.java +++ b/src/main/java/com/twilio/rest/conversations/v1/service/Conversation.java @@ -24,55 +24,63 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Conversation extends Resource { + private static final long serialVersionUID = 208929192266810L; - public static ConversationCreator creator(final String pathChatServiceSid){ + public static ConversationCreator creator(final String pathChatServiceSid) { return new ConversationCreator(pathChatServiceSid); } - public static ConversationDeleter deleter(final String pathChatServiceSid, final String pathSid){ + public static ConversationDeleter deleter( + final String pathChatServiceSid, + final String pathSid + ) { return new ConversationDeleter(pathChatServiceSid, pathSid); } - public static ConversationFetcher fetcher(final String pathChatServiceSid, final String pathSid){ + public static ConversationFetcher fetcher( + final String pathChatServiceSid, + final String pathSid + ) { return new ConversationFetcher(pathChatServiceSid, pathSid); } - public static ConversationReader reader(final String pathChatServiceSid){ + public static ConversationReader reader(final String pathChatServiceSid) { return new ConversationReader(pathChatServiceSid); } - public static ConversationUpdater updater(final String pathChatServiceSid, final String pathSid){ + public static ConversationUpdater updater( + final String pathChatServiceSid, + final String pathSid + ) { return new ConversationUpdater(pathChatServiceSid, pathSid); } /** - * Converts a JSON String into a Conversation object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Conversation object represented by the provided JSON - */ - public static Conversation fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Conversation object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Conversation object represented by the provided JSON + */ + public static Conversation fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Conversation.class); @@ -84,14 +92,17 @@ public static Conversation fromJson(final String json, final ObjectMapper object } /** - * Converts a JSON InputStream into a Conversation object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Conversation object represented by the provided JSON - */ - public static Conversation fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Conversation object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Conversation object represented by the provided JSON + */ + public static Conversation fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Conversation.class); @@ -101,6 +112,7 @@ public static Conversation fromJson(final InputStream json, final ObjectMapper o throw new ApiConnectionException(e.getMessage(), e); } } + public enum State { INACTIVE("inactive"), ACTIVE("active"), @@ -121,6 +133,7 @@ public static State forValue(final String value) { return Promoter.enumFromString(value, State.values()); } } + public enum WebhookEnabledType { TRUE("true"), FALSE("false"); @@ -158,47 +171,20 @@ public static WebhookEnabledType forValue(final String value) { @JsonCreator private Conversation( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("chat_service_sid") - final String chatServiceSid, - - @JsonProperty("messaging_service_sid") - final String messagingServiceSid, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("unique_name") - final String uniqueName, - - @JsonProperty("attributes") - final String attributes, - - @JsonProperty("state") - final Conversation.State state, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("timers") - final Map timers, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links, - - @JsonProperty("bindings") - final Map bindings + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("chat_service_sid") final String chatServiceSid, + @JsonProperty("messaging_service_sid") final String messagingServiceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("attributes") final String attributes, + @JsonProperty("state") final Conversation.State state, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("timers") final Map timers, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links, + @JsonProperty("bindings") final Map bindings ) { this.accountSid = accountSid; this.chatServiceSid = chatServiceSid; @@ -216,52 +202,65 @@ private Conversation( this.bindings = bindings; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getChatServiceSid() { - return this.chatServiceSid; - } - public final String getMessagingServiceSid() { - return this.messagingServiceSid; - } - public final String getSid() { - return this.sid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getUniqueName() { - return this.uniqueName; - } - public final String getAttributes() { - return this.attributes; - } - public final Conversation.State getState() { - return this.state; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final Map getTimers() { - return this.timers; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } - public final Map getBindings() { - return this.bindings; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getChatServiceSid() { + return this.chatServiceSid; + } + + public final String getMessagingServiceSid() { + return this.messagingServiceSid; + } + + public final String getSid() { + return this.sid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getUniqueName() { + return this.uniqueName; + } + + public final String getAttributes() { + return this.attributes; + } + + public final Conversation.State getState() { + return this.state; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final Map getTimers() { + return this.timers; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } + + public final Map getBindings() { + return this.bindings; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -271,13 +270,41 @@ public boolean equals(final Object o) { Conversation other = (Conversation) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(chatServiceSid, other.chatServiceSid) && Objects.equals(messagingServiceSid, other.messagingServiceSid) && Objects.equals(sid, other.sid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(uniqueName, other.uniqueName) && Objects.equals(attributes, other.attributes) && Objects.equals(state, other.state) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(timers, other.timers) && Objects.equals(url, other.url) && Objects.equals(links, other.links) && Objects.equals(bindings, other.bindings) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(chatServiceSid, other.chatServiceSid) && + Objects.equals(messagingServiceSid, other.messagingServiceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(attributes, other.attributes) && + Objects.equals(state, other.state) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(timers, other.timers) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) && + Objects.equals(bindings, other.bindings) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, chatServiceSid, messagingServiceSid, sid, friendlyName, uniqueName, attributes, state, dateCreated, dateUpdated, timers, url, links, bindings); + return Objects.hash( + accountSid, + chatServiceSid, + messagingServiceSid, + sid, + friendlyName, + uniqueName, + attributes, + state, + dateCreated, + dateUpdated, + timers, + url, + links, + bindings + ); } - } - diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/ConversationCreator.java b/src/main/java/com/twilio/rest/conversations/v1/service/ConversationCreator.java index 7ef62e7371..1a00cb63bb 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/service/ConversationCreator.java +++ b/src/main/java/com/twilio/rest/conversations/v1/service/ConversationCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.conversations.v1.service; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -25,10 +26,8 @@ import com.twilio.rest.Domains; import java.time.ZonedDateTime; +public class ConversationCreator extends Creator { - - -public class ConversationCreator extends Creator{ private String pathChatServiceSid; private Conversation.WebhookEnabledType xTwilioWebhookEnabled; private String friendlyName; @@ -45,115 +44,142 @@ public ConversationCreator(final String pathChatServiceSid) { this.pathChatServiceSid = pathChatServiceSid; } - public ConversationCreator setXTwilioWebhookEnabled(final Conversation.WebhookEnabledType xTwilioWebhookEnabled){ + public ConversationCreator setXTwilioWebhookEnabled( + final Conversation.WebhookEnabledType xTwilioWebhookEnabled + ) { this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; return this; } - public ConversationCreator setFriendlyName(final String friendlyName){ + + public ConversationCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public ConversationCreator setUniqueName(final String uniqueName){ + + public ConversationCreator setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - public ConversationCreator setAttributes(final String attributes){ + + public ConversationCreator setAttributes(final String attributes) { this.attributes = attributes; return this; } - public ConversationCreator setMessagingServiceSid(final String messagingServiceSid){ + + public ConversationCreator setMessagingServiceSid( + final String messagingServiceSid + ) { this.messagingServiceSid = messagingServiceSid; return this; } - public ConversationCreator setDateCreated(final ZonedDateTime dateCreated){ + + public ConversationCreator setDateCreated(final ZonedDateTime dateCreated) { this.dateCreated = dateCreated; return this; } - public ConversationCreator setDateUpdated(final ZonedDateTime dateUpdated){ + + public ConversationCreator setDateUpdated(final ZonedDateTime dateUpdated) { this.dateUpdated = dateUpdated; return this; } - public ConversationCreator setState(final Conversation.State state){ + + public ConversationCreator setState(final Conversation.State state) { this.state = state; return this; } - public ConversationCreator setTimersInactive(final String timersInactive){ + + public ConversationCreator setTimersInactive(final String timersInactive) { this.timersInactive = timersInactive; return this; } - public ConversationCreator setTimersClosed(final String timersClosed){ + + public ConversationCreator setTimersClosed(final String timersClosed) { this.timersClosed = timersClosed; return this; } @Override - public Conversation create(final TwilioRestClient client){ + public Conversation create(final TwilioRestClient client) { String path = "/v1/Services/{ChatServiceSid}/Conversations"; - path = path.replace("{"+"ChatServiceSid"+"}", this.pathChatServiceSid.toString()); + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.CONVERSATIONS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); addHeaderParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Conversation creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Conversation creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Conversation.fromJson(response.getStream(), client.getObjectMapper()); + return Conversation.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (uniqueName != null) { request.addPostParam("UniqueName", uniqueName); - } if (attributes != null) { request.addPostParam("Attributes", attributes); - } if (messagingServiceSid != null) { request.addPostParam("MessagingServiceSid", messagingServiceSid); - } if (dateCreated != null) { - request.addPostParam("DateCreated", dateCreated.toInstant().toString()); - + request.addPostParam( + "DateCreated", + dateCreated.toInstant().toString() + ); } if (dateUpdated != null) { - request.addPostParam("DateUpdated", dateUpdated.toInstant().toString()); - + request.addPostParam( + "DateUpdated", + dateUpdated.toInstant().toString() + ); } if (state != null) { request.addPostParam("State", state.toString()); - } if (timersInactive != null) { request.addPostParam("Timers.Inactive", timersInactive); - } if (timersClosed != null) { request.addPostParam("Timers.Closed", timersClosed); - } } + private void addHeaderParams(final Request request) { if (xTwilioWebhookEnabled != null) { - request.addHeaderParam("X-Twilio-Webhook-Enabled", xTwilioWebhookEnabled.toString()); - + request.addHeaderParam( + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/ConversationDeleter.java b/src/main/java/com/twilio/rest/conversations/v1/service/ConversationDeleter.java index 8ee6f46964..2e80104865 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/service/ConversationDeleter.java +++ b/src/main/java/com/twilio/rest/conversations/v1/service/ConversationDeleter.java @@ -24,19 +24,23 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class ConversationDeleter extends Deleter { + private String pathChatServiceSid; private String pathSid; private Conversation.WebhookEnabledType xTwilioWebhookEnabled; - public ConversationDeleter(final String pathChatServiceSid, final String pathSid){ + public ConversationDeleter( + final String pathChatServiceSid, + final String pathSid + ) { this.pathChatServiceSid = pathChatServiceSid; this.pathSid = pathSid; } - public ConversationDeleter setXTwilioWebhookEnabled(final Conversation.WebhookEnabledType xTwilioWebhookEnabled){ + public ConversationDeleter setXTwilioWebhookEnabled( + final Conversation.WebhookEnabledType xTwilioWebhookEnabled + ) { this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; return this; } @@ -45,8 +49,12 @@ public ConversationDeleter setXTwilioWebhookEnabled(final Conversation.WebhookEn public boolean delete(final TwilioRestClient client) { String path = "/v1/Services/{ChatServiceSid}/Conversations/{Sid}"; - path = path.replace("{"+"ChatServiceSid"+"}", this.pathChatServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -57,9 +65,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Conversation delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Conversation delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -67,10 +80,13 @@ public boolean delete(final TwilioRestClient client) { } return response.getStatusCode() == 204; } + private void addHeaderParams(final Request request) { if (xTwilioWebhookEnabled != null) { - request.addHeaderParam("X-Twilio-Webhook-Enabled", xTwilioWebhookEnabled.toString()); - + request.addHeaderParam( + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/ConversationFetcher.java b/src/main/java/com/twilio/rest/conversations/v1/service/ConversationFetcher.java index 7548a2798a..d731097a9a 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/service/ConversationFetcher.java +++ b/src/main/java/com/twilio/rest/conversations/v1/service/ConversationFetcher.java @@ -24,25 +24,29 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class ConversationFetcher extends Fetcher { + private String pathChatServiceSid; private String pathSid; - public ConversationFetcher(final String pathChatServiceSid, final String pathSid){ + public ConversationFetcher( + final String pathChatServiceSid, + final String pathSid + ) { this.pathChatServiceSid = pathChatServiceSid; this.pathSid = pathSid; } - @Override public Conversation fetch(final TwilioRestClient client) { String path = "/v1/Services/{ChatServiceSid}/Conversations/{Sid}"; - path = path.replace("{"+"ChatServiceSid"+"}", this.pathChatServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,15 +56,23 @@ public Conversation fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Conversation fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Conversation fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Conversation.fromJson(response.getStream(), client.getObjectMapper()); + return Conversation.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/ConversationReader.java b/src/main/java/com/twilio/rest/conversations/v1/service/ConversationReader.java index 6b2aa3b810..238f77a06a 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/service/ConversationReader.java +++ b/src/main/java/com/twilio/rest/conversations/v1/service/ConversationReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.conversations.v1.service; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,34 +25,35 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class ConversationReader extends Reader { + private String pathChatServiceSid; private String startDate; private String endDate; private Conversation.State state; private Integer pageSize; - public ConversationReader(final String pathChatServiceSid){ + public ConversationReader(final String pathChatServiceSid) { this.pathChatServiceSid = pathChatServiceSid; } - public ConversationReader setStartDate(final String startDate){ + public ConversationReader setStartDate(final String startDate) { this.startDate = startDate; return this; } - public ConversationReader setEndDate(final String endDate){ + + public ConversationReader setEndDate(final String endDate) { this.endDate = endDate; return this; } - public ConversationReader setState(final Conversation.State state){ + + public ConversationReader setState(final Conversation.State state) { this.state = state; return this; } - public ConversationReader setPageSize(final Integer pageSize){ + + public ConversationReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -63,7 +65,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Services/{ChatServiceSid}/Conversations"; - path = path.replace("{"+"ChatServiceSid"+"}", this.pathChatServiceSid.toString()); + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -75,13 +81,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Conversation read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Conversation read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -97,7 +111,10 @@ private Page pageForRequest(final TwilioRestClient client, final R } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.CONVERSATIONS.toString()) @@ -105,9 +122,11 @@ public Page previousPage(final Page page, final Twil return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.CONVERSATIONS.toString()) @@ -116,33 +135,30 @@ public Page nextPage(final Page page, final TwilioRe } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (startDate != null) { - request.addQueryParam("StartDate", startDate); } if (endDate != null) { - request.addQueryParam("EndDate", endDate); } if (state != null) { - request.addQueryParam("State", state.toString()); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/ConversationUpdater.java b/src/main/java/com/twilio/rest/conversations/v1/service/ConversationUpdater.java index 13a75e02b1..8c8b2cc64b 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/service/ConversationUpdater.java +++ b/src/main/java/com/twilio/rest/conversations/v1/service/ConversationUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.conversations.v1.service; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -23,12 +24,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.time.ZonedDateTime; +public class ConversationUpdater extends Updater { - -public class ConversationUpdater extends Updater{ private String pathChatServiceSid; private String pathSid; private Conversation.WebhookEnabledType xTwilioWebhookEnabled; @@ -42,121 +41,151 @@ public class ConversationUpdater extends Updater{ private String timersClosed; private String uniqueName; - public ConversationUpdater(final String pathChatServiceSid, final String pathSid){ + public ConversationUpdater( + final String pathChatServiceSid, + final String pathSid + ) { this.pathChatServiceSid = pathChatServiceSid; this.pathSid = pathSid; } - public ConversationUpdater setXTwilioWebhookEnabled(final Conversation.WebhookEnabledType xTwilioWebhookEnabled){ + public ConversationUpdater setXTwilioWebhookEnabled( + final Conversation.WebhookEnabledType xTwilioWebhookEnabled + ) { this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; return this; } - public ConversationUpdater setFriendlyName(final String friendlyName){ + + public ConversationUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public ConversationUpdater setDateCreated(final ZonedDateTime dateCreated){ + + public ConversationUpdater setDateCreated(final ZonedDateTime dateCreated) { this.dateCreated = dateCreated; return this; } - public ConversationUpdater setDateUpdated(final ZonedDateTime dateUpdated){ + + public ConversationUpdater setDateUpdated(final ZonedDateTime dateUpdated) { this.dateUpdated = dateUpdated; return this; } - public ConversationUpdater setAttributes(final String attributes){ + + public ConversationUpdater setAttributes(final String attributes) { this.attributes = attributes; return this; } - public ConversationUpdater setMessagingServiceSid(final String messagingServiceSid){ + + public ConversationUpdater setMessagingServiceSid( + final String messagingServiceSid + ) { this.messagingServiceSid = messagingServiceSid; return this; } - public ConversationUpdater setState(final Conversation.State state){ + + public ConversationUpdater setState(final Conversation.State state) { this.state = state; return this; } - public ConversationUpdater setTimersInactive(final String timersInactive){ + + public ConversationUpdater setTimersInactive(final String timersInactive) { this.timersInactive = timersInactive; return this; } - public ConversationUpdater setTimersClosed(final String timersClosed){ + + public ConversationUpdater setTimersClosed(final String timersClosed) { this.timersClosed = timersClosed; return this; } - public ConversationUpdater setUniqueName(final String uniqueName){ + + public ConversationUpdater setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } @Override - public Conversation update(final TwilioRestClient client){ + public Conversation update(final TwilioRestClient client) { String path = "/v1/Services/{ChatServiceSid}/Conversations/{Sid}"; - path = path.replace("{"+"ChatServiceSid"+"}", this.pathChatServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.CONVERSATIONS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); addHeaderParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Conversation update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Conversation update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Conversation.fromJson(response.getStream(), client.getObjectMapper()); + return Conversation.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (dateCreated != null) { - request.addPostParam("DateCreated", dateCreated.toInstant().toString()); - + request.addPostParam( + "DateCreated", + dateCreated.toInstant().toString() + ); } if (dateUpdated != null) { - request.addPostParam("DateUpdated", dateUpdated.toInstant().toString()); - + request.addPostParam( + "DateUpdated", + dateUpdated.toInstant().toString() + ); } if (attributes != null) { request.addPostParam("Attributes", attributes); - } if (messagingServiceSid != null) { request.addPostParam("MessagingServiceSid", messagingServiceSid); - } if (state != null) { request.addPostParam("State", state.toString()); - } if (timersInactive != null) { request.addPostParam("Timers.Inactive", timersInactive); - } if (timersClosed != null) { request.addPostParam("Timers.Closed", timersClosed); - } if (uniqueName != null) { request.addPostParam("UniqueName", uniqueName); - } } + private void addHeaderParams(final Request request) { if (xTwilioWebhookEnabled != null) { - request.addHeaderParam("X-Twilio-Webhook-Enabled", xTwilioWebhookEnabled.toString()); - + request.addHeaderParam( + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/ParticipantConversation.java b/src/main/java/com/twilio/rest/conversations/v1/service/ParticipantConversation.java index 1a7571df93..d8adde7061 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/service/ParticipantConversation.java +++ b/src/main/java/com/twilio/rest/conversations/v1/service/ParticipantConversation.java @@ -24,38 +24,39 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class ParticipantConversation extends Resource { + private static final long serialVersionUID = 210706261724884L; - public static ParticipantConversationReader reader(final String pathChatServiceSid){ + public static ParticipantConversationReader reader( + final String pathChatServiceSid + ) { return new ParticipantConversationReader(pathChatServiceSid); } /** - * Converts a JSON String into a ParticipantConversation object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return ParticipantConversation object represented by the provided JSON - */ - public static ParticipantConversation fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a ParticipantConversation object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return ParticipantConversation object represented by the provided JSON + */ + public static ParticipantConversation fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, ParticipantConversation.class); @@ -67,14 +68,17 @@ public static ParticipantConversation fromJson(final String json, final ObjectMa } /** - * Converts a JSON InputStream into a ParticipantConversation object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return ParticipantConversation object represented by the provided JSON - */ - public static ParticipantConversation fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a ParticipantConversation object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return ParticipantConversation object represented by the provided JSON + */ + public static ParticipantConversation fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, ParticipantConversation.class); @@ -84,6 +88,7 @@ public static ParticipantConversation fromJson(final InputStream json, final Obj throw new ApiConnectionException(e.getMessage(), e); } } + public enum State { INACTIVE("inactive"), ACTIVE("active"), @@ -124,53 +129,40 @@ public static State forValue(final String value) { @JsonCreator private ParticipantConversation( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("chat_service_sid") - final String chatServiceSid, - - @JsonProperty("participant_sid") - final String participantSid, - - @JsonProperty("participant_user_sid") - final String participantUserSid, - - @JsonProperty("participant_identity") - final String participantIdentity, - - @JsonProperty("participant_messaging_binding") - final Map participantMessagingBinding, - - @JsonProperty("conversation_sid") - final String conversationSid, - - @JsonProperty("conversation_unique_name") - final String conversationUniqueName, - - @JsonProperty("conversation_friendly_name") - final String conversationFriendlyName, - - @JsonProperty("conversation_attributes") - final String conversationAttributes, - - @JsonProperty("conversation_date_created") - final String conversationDateCreated, - - @JsonProperty("conversation_date_updated") - final String conversationDateUpdated, - - @JsonProperty("conversation_created_by") - final String conversationCreatedBy, - - @JsonProperty("conversation_state") - final ParticipantConversation.State conversationState, - - @JsonProperty("conversation_timers") - final Map conversationTimers, - - @JsonProperty("links") - final Map links + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("chat_service_sid") final String chatServiceSid, + @JsonProperty("participant_sid") final String participantSid, + @JsonProperty("participant_user_sid") final String participantUserSid, + @JsonProperty("participant_identity") final String participantIdentity, + @JsonProperty( + "participant_messaging_binding" + ) final Map participantMessagingBinding, + @JsonProperty("conversation_sid") final String conversationSid, + @JsonProperty( + "conversation_unique_name" + ) final String conversationUniqueName, + @JsonProperty( + "conversation_friendly_name" + ) final String conversationFriendlyName, + @JsonProperty( + "conversation_attributes" + ) final String conversationAttributes, + @JsonProperty( + "conversation_date_created" + ) final String conversationDateCreated, + @JsonProperty( + "conversation_date_updated" + ) final String conversationDateUpdated, + @JsonProperty( + "conversation_created_by" + ) final String conversationCreatedBy, + @JsonProperty( + "conversation_state" + ) final ParticipantConversation.State conversationState, + @JsonProperty( + "conversation_timers" + ) final Map conversationTimers, + @JsonProperty("links") final Map links ) { this.accountSid = accountSid; this.chatServiceSid = chatServiceSid; @@ -182,66 +174,83 @@ private ParticipantConversation( this.conversationUniqueName = conversationUniqueName; this.conversationFriendlyName = conversationFriendlyName; this.conversationAttributes = conversationAttributes; - this.conversationDateCreated = DateConverter.iso8601DateTimeFromString(conversationDateCreated); - this.conversationDateUpdated = DateConverter.iso8601DateTimeFromString(conversationDateUpdated); + this.conversationDateCreated = + DateConverter.iso8601DateTimeFromString(conversationDateCreated); + this.conversationDateUpdated = + DateConverter.iso8601DateTimeFromString(conversationDateUpdated); this.conversationCreatedBy = conversationCreatedBy; this.conversationState = conversationState; this.conversationTimers = conversationTimers; this.links = links; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getChatServiceSid() { - return this.chatServiceSid; - } - public final String getParticipantSid() { - return this.participantSid; - } - public final String getParticipantUserSid() { - return this.participantUserSid; - } - public final String getParticipantIdentity() { - return this.participantIdentity; - } - public final Map getParticipantMessagingBinding() { - return this.participantMessagingBinding; - } - public final String getConversationSid() { - return this.conversationSid; - } - public final String getConversationUniqueName() { - return this.conversationUniqueName; - } - public final String getConversationFriendlyName() { - return this.conversationFriendlyName; - } - public final String getConversationAttributes() { - return this.conversationAttributes; - } - public final ZonedDateTime getConversationDateCreated() { - return this.conversationDateCreated; - } - public final ZonedDateTime getConversationDateUpdated() { - return this.conversationDateUpdated; - } - public final String getConversationCreatedBy() { - return this.conversationCreatedBy; - } - public final ParticipantConversation.State getConversationState() { - return this.conversationState; - } - public final Map getConversationTimers() { - return this.conversationTimers; - } - public final Map getLinks() { - return this.links; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getChatServiceSid() { + return this.chatServiceSid; + } + + public final String getParticipantSid() { + return this.participantSid; + } + + public final String getParticipantUserSid() { + return this.participantUserSid; + } + + public final String getParticipantIdentity() { + return this.participantIdentity; + } + + public final Map getParticipantMessagingBinding() { + return this.participantMessagingBinding; + } + + public final String getConversationSid() { + return this.conversationSid; + } + + public final String getConversationUniqueName() { + return this.conversationUniqueName; + } + + public final String getConversationFriendlyName() { + return this.conversationFriendlyName; + } + + public final String getConversationAttributes() { + return this.conversationAttributes; + } + + public final ZonedDateTime getConversationDateCreated() { + return this.conversationDateCreated; + } + + public final ZonedDateTime getConversationDateUpdated() { + return this.conversationDateUpdated; + } + + public final String getConversationCreatedBy() { + return this.conversationCreatedBy; + } + + public final ParticipantConversation.State getConversationState() { + return this.conversationState; + } + + public final Map getConversationTimers() { + return this.conversationTimers; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -251,13 +260,66 @@ public boolean equals(final Object o) { ParticipantConversation other = (ParticipantConversation) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(chatServiceSid, other.chatServiceSid) && Objects.equals(participantSid, other.participantSid) && Objects.equals(participantUserSid, other.participantUserSid) && Objects.equals(participantIdentity, other.participantIdentity) && Objects.equals(participantMessagingBinding, other.participantMessagingBinding) && Objects.equals(conversationSid, other.conversationSid) && Objects.equals(conversationUniqueName, other.conversationUniqueName) && Objects.equals(conversationFriendlyName, other.conversationFriendlyName) && Objects.equals(conversationAttributes, other.conversationAttributes) && Objects.equals(conversationDateCreated, other.conversationDateCreated) && Objects.equals(conversationDateUpdated, other.conversationDateUpdated) && Objects.equals(conversationCreatedBy, other.conversationCreatedBy) && Objects.equals(conversationState, other.conversationState) && Objects.equals(conversationTimers, other.conversationTimers) && Objects.equals(links, other.links) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(chatServiceSid, other.chatServiceSid) && + Objects.equals(participantSid, other.participantSid) && + Objects.equals(participantUserSid, other.participantUserSid) && + Objects.equals(participantIdentity, other.participantIdentity) && + Objects.equals( + participantMessagingBinding, + other.participantMessagingBinding + ) && + Objects.equals(conversationSid, other.conversationSid) && + Objects.equals( + conversationUniqueName, + other.conversationUniqueName + ) && + Objects.equals( + conversationFriendlyName, + other.conversationFriendlyName + ) && + Objects.equals( + conversationAttributes, + other.conversationAttributes + ) && + Objects.equals( + conversationDateCreated, + other.conversationDateCreated + ) && + Objects.equals( + conversationDateUpdated, + other.conversationDateUpdated + ) && + Objects.equals( + conversationCreatedBy, + other.conversationCreatedBy + ) && + Objects.equals(conversationState, other.conversationState) && + Objects.equals(conversationTimers, other.conversationTimers) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, chatServiceSid, participantSid, participantUserSid, participantIdentity, participantMessagingBinding, conversationSid, conversationUniqueName, conversationFriendlyName, conversationAttributes, conversationDateCreated, conversationDateUpdated, conversationCreatedBy, conversationState, conversationTimers, links); + return Objects.hash( + accountSid, + chatServiceSid, + participantSid, + participantUserSid, + participantIdentity, + participantMessagingBinding, + conversationSid, + conversationUniqueName, + conversationFriendlyName, + conversationAttributes, + conversationDateCreated, + conversationDateUpdated, + conversationCreatedBy, + conversationState, + conversationTimers, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/ParticipantConversationReader.java b/src/main/java/com/twilio/rest/conversations/v1/service/ParticipantConversationReader.java index 3e00ae8e4a..6f64fca29a 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/service/ParticipantConversationReader.java +++ b/src/main/java/com/twilio/rest/conversations/v1/service/ParticipantConversationReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.conversations.v1.service; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,41 +25,50 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - +public class ParticipantConversationReader + extends Reader { -public class ParticipantConversationReader extends Reader { private String pathChatServiceSid; private String identity; private String address; private Integer pageSize; - public ParticipantConversationReader(final String pathChatServiceSid){ + public ParticipantConversationReader(final String pathChatServiceSid) { this.pathChatServiceSid = pathChatServiceSid; } - public ParticipantConversationReader setIdentity(final String identity){ + public ParticipantConversationReader setIdentity(final String identity) { this.identity = identity; return this; } - public ParticipantConversationReader setAddress(final String address){ + + public ParticipantConversationReader setAddress(final String address) { this.address = address; return this; } - public ParticipantConversationReader setPageSize(final Integer pageSize){ + + public ParticipantConversationReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @Override - public ResourceSet read(final TwilioRestClient client) { + public ResourceSet read( + final TwilioRestClient client + ) { return new ResourceSet<>(this, client, firstPage(client)); } - public Page firstPage(final TwilioRestClient client) { + public Page firstPage( + final TwilioRestClient client + ) { String path = "/v1/Services/{ChatServiceSid}/ParticipantConversations"; - path = path.replace("{"+"ChatServiceSid"+"}", this.pathChatServiceSid.toString()); + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -70,13 +80,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("ParticipantConversation read failed: Unable to connect to server"); + throw new ApiConnectionException( + "ParticipantConversation read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -92,7 +110,10 @@ private Page pageForRequest(final TwilioRestClient clie } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.CONVERSATIONS.toString()) @@ -100,9 +121,11 @@ public Page previousPage(final Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.CONVERSATIONS.toString()) @@ -111,29 +134,27 @@ public Page nextPage(final Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (identity != null) { - request.addQueryParam("Identity", identity); } if (address != null) { - request.addQueryParam("Address", address); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/Role.java b/src/main/java/com/twilio/rest/conversations/v1/service/Role.java index 01da2ba1a7..827ffe7bba 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/service/Role.java +++ b/src/main/java/com/twilio/rest/conversations/v1/service/Role.java @@ -24,54 +24,73 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.List; import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Role extends Resource { + private static final long serialVersionUID = 223283830784079L; - public static RoleCreator creator(final String pathChatServiceSid, final String friendlyName, final Role.RoleType type, final List permission){ - return new RoleCreator(pathChatServiceSid, friendlyName, type, permission); + public static RoleCreator creator( + final String pathChatServiceSid, + final String friendlyName, + final Role.RoleType type, + final List permission + ) { + return new RoleCreator( + pathChatServiceSid, + friendlyName, + type, + permission + ); } - public static RoleDeleter deleter(final String pathChatServiceSid, final String pathSid){ + public static RoleDeleter deleter( + final String pathChatServiceSid, + final String pathSid + ) { return new RoleDeleter(pathChatServiceSid, pathSid); } - public static RoleFetcher fetcher(final String pathChatServiceSid, final String pathSid){ + public static RoleFetcher fetcher( + final String pathChatServiceSid, + final String pathSid + ) { return new RoleFetcher(pathChatServiceSid, pathSid); } - public static RoleReader reader(final String pathChatServiceSid){ + public static RoleReader reader(final String pathChatServiceSid) { return new RoleReader(pathChatServiceSid); } - public static RoleUpdater updater(final String pathChatServiceSid, final String pathSid, final List permission){ + public static RoleUpdater updater( + final String pathChatServiceSid, + final String pathSid, + final List permission + ) { return new RoleUpdater(pathChatServiceSid, pathSid, permission); } /** - * Converts a JSON String into a Role object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Role object represented by the provided JSON - */ - public static Role fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Role object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Role object represented by the provided JSON + */ + public static Role fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Role.class); @@ -83,14 +102,17 @@ public static Role fromJson(final String json, final ObjectMapper objectMapper) } /** - * Converts a JSON InputStream into a Role object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Role object represented by the provided JSON - */ - public static Role fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Role object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Role object represented by the provided JSON + */ + public static Role fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Role.class); @@ -100,6 +122,7 @@ public static Role fromJson(final InputStream json, final ObjectMapper objectMap throw new ApiConnectionException(e.getMessage(), e); } } + public enum RoleType { CONVERSATION("conversation"), SERVICE("service"); @@ -132,32 +155,15 @@ public static RoleType forValue(final String value) { @JsonCreator private Role( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("chat_service_sid") - final String chatServiceSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("type") - final Role.RoleType type, - - @JsonProperty("permissions") - final List permissions, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("chat_service_sid") final String chatServiceSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("type") final Role.RoleType type, + @JsonProperty("permissions") final List permissions, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url ) { this.sid = sid; this.accountSid = accountSid; @@ -170,37 +176,45 @@ private Role( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getChatServiceSid() { - return this.chatServiceSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final Role.RoleType getType() { - return this.type; - } - public final List getPermissions() { - return this.permissions; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getChatServiceSid() { + return this.chatServiceSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final Role.RoleType getType() { + return this.type; + } + + public final List getPermissions() { + return this.permissions; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -210,13 +224,31 @@ public boolean equals(final Object o) { Role other = (Role) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(chatServiceSid, other.chatServiceSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(type, other.type) && Objects.equals(permissions, other.permissions) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(chatServiceSid, other.chatServiceSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(type, other.type) && + Objects.equals(permissions, other.permissions) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, chatServiceSid, friendlyName, type, permissions, dateCreated, dateUpdated, url); + return Objects.hash( + sid, + accountSid, + chatServiceSid, + friendlyName, + type, + permissions, + dateCreated, + dateUpdated, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/RoleCreator.java b/src/main/java/com/twilio/rest/conversations/v1/service/RoleCreator.java index b00533a224..ee13e20f54 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/service/RoleCreator.java +++ b/src/main/java/com/twilio/rest/conversations/v1/service/RoleCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.conversations.v1.service; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -25,60 +26,81 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.util.List; - import java.util.List; +public class RoleCreator extends Creator { - -public class RoleCreator extends Creator{ private String pathChatServiceSid; private String friendlyName; private Role.RoleType type; private List permission; - public RoleCreator(final String pathChatServiceSid, final String friendlyName, final Role.RoleType type, final List permission) { + public RoleCreator( + final String pathChatServiceSid, + final String friendlyName, + final Role.RoleType type, + final List permission + ) { this.pathChatServiceSid = pathChatServiceSid; this.friendlyName = friendlyName; this.type = type; this.permission = permission; } - public RoleCreator setFriendlyName(final String friendlyName){ + public RoleCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public RoleCreator setType(final Role.RoleType type){ + + public RoleCreator setType(final Role.RoleType type) { this.type = type; return this; } - public RoleCreator setPermission(final List permission){ + + public RoleCreator setPermission(final List permission) { this.permission = permission; return this; } - public RoleCreator setPermission(final String permission){ + + public RoleCreator setPermission(final String permission) { return setPermission(Promoter.listOfOne(permission)); } @Override - public Role create(final TwilioRestClient client){ + public Role create(final TwilioRestClient client) { String path = "/v1/Services/{ChatServiceSid}/Roles"; - path = path.replace("{"+"ChatServiceSid"+"}", this.pathChatServiceSid.toString()); - path = path.replace("{"+"FriendlyName"+"}", this.friendlyName.toString()); - path = path.replace("{"+"Type"+"}", this.type.toString()); - path = path.replace("{"+"Permission"+"}", this.permission.toString()); + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = + path.replace( + "{" + "FriendlyName" + "}", + this.friendlyName.toString() + ); + path = path.replace("{" + "Type" + "}", this.type.toString()); + path = + path.replace("{" + "Permission" + "}", this.permission.toString()); Request request = new Request( HttpMethod.POST, Domains.CONVERSATIONS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Role creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Role creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -87,20 +109,18 @@ public Role create(final TwilioRestClient client){ return Role.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (type != null) { request.addPostParam("Type", type.toString()); - } if (permission != null) { for (String prop : permission) { request.addPostParam("Permission", prop); } - } } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/RoleDeleter.java b/src/main/java/com/twilio/rest/conversations/v1/service/RoleDeleter.java index cf2e157816..509b784d3f 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/service/RoleDeleter.java +++ b/src/main/java/com/twilio/rest/conversations/v1/service/RoleDeleter.java @@ -24,24 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class RoleDeleter extends Deleter { + private String pathChatServiceSid; private String pathSid; - public RoleDeleter(final String pathChatServiceSid, final String pathSid){ + public RoleDeleter(final String pathChatServiceSid, final String pathSid) { this.pathChatServiceSid = pathChatServiceSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Services/{ChatServiceSid}/Roles/{Sid}"; - path = path.replace("{"+"ChatServiceSid"+"}", this.pathChatServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +53,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Role delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Role delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/RoleFetcher.java b/src/main/java/com/twilio/rest/conversations/v1/service/RoleFetcher.java index 6e1000a8af..887888e757 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/service/RoleFetcher.java +++ b/src/main/java/com/twilio/rest/conversations/v1/service/RoleFetcher.java @@ -24,25 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class RoleFetcher extends Fetcher { + private String pathChatServiceSid; private String pathSid; - public RoleFetcher(final String pathChatServiceSid, final String pathSid){ + public RoleFetcher(final String pathChatServiceSid, final String pathSid) { this.pathChatServiceSid = pathChatServiceSid; this.pathSid = pathSid; } - @Override public Role fetch(final TwilioRestClient client) { String path = "/v1/Services/{ChatServiceSid}/Roles/{Sid}"; - path = path.replace("{"+"ChatServiceSid"+"}", this.pathChatServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,9 +53,14 @@ public Role fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Role fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Role fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/RoleReader.java b/src/main/java/com/twilio/rest/conversations/v1/service/RoleReader.java index 7ff95cb91f..d50c2445f3 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/service/RoleReader.java +++ b/src/main/java/com/twilio/rest/conversations/v1/service/RoleReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.conversations.v1.service; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,19 +25,17 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class RoleReader extends Reader { + private String pathChatServiceSid; private Integer pageSize; - public RoleReader(final String pathChatServiceSid){ + public RoleReader(final String pathChatServiceSid) { this.pathChatServiceSid = pathChatServiceSid; } - public RoleReader setPageSize(final Integer pageSize){ + public RoleReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -48,7 +47,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Services/{ChatServiceSid}/Roles"; - path = path.replace("{"+"ChatServiceSid"+"}", this.pathChatServiceSid.toString()); + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -60,13 +63,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Role read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Role read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +93,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request r } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.CONVERSATIONS.toString()) @@ -90,9 +104,11 @@ public Page previousPage(final Page page, final TwilioRestClient cli return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.CONVERSATIONS.toString()) @@ -101,21 +117,21 @@ public Page nextPage(final Page page, final TwilioRestClient client) } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/RoleUpdater.java b/src/main/java/com/twilio/rest/conversations/v1/service/RoleUpdater.java index 657dc537dc..22002ecca5 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/service/RoleUpdater.java +++ b/src/main/java/com/twilio/rest/conversations/v1/service/RoleUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.conversations.v1.service; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -24,49 +25,63 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - import java.util.List; +public class RoleUpdater extends Updater { -public class RoleUpdater extends Updater{ private String pathChatServiceSid; private String pathSid; private List permission; - public RoleUpdater(final String pathChatServiceSid, final String pathSid, final List permission){ + public RoleUpdater( + final String pathChatServiceSid, + final String pathSid, + final List permission + ) { this.pathChatServiceSid = pathChatServiceSid; this.pathSid = pathSid; this.permission = permission; } - public RoleUpdater setPermission(final List permission){ + public RoleUpdater setPermission(final List permission) { this.permission = permission; return this; } - public RoleUpdater setPermission(final String permission){ + + public RoleUpdater setPermission(final String permission) { return setPermission(Promoter.listOfOne(permission)); } @Override - public Role update(final TwilioRestClient client){ + public Role update(final TwilioRestClient client) { String path = "/v1/Services/{ChatServiceSid}/Roles/{Sid}"; - path = path.replace("{"+"ChatServiceSid"+"}", this.pathChatServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); - path = path.replace("{"+"Permission"+"}", this.permission.toString()); + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + path = + path.replace("{" + "Permission" + "}", this.permission.toString()); Request request = new Request( HttpMethod.POST, Domains.CONVERSATIONS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Role update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Role update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -75,12 +90,12 @@ public Role update(final TwilioRestClient client){ return Role.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (permission != null) { for (String prop : permission) { request.addPostParam("Permission", prop); } - } } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/User.java b/src/main/java/com/twilio/rest/conversations/v1/service/User.java index aca0361f46..99ba37edd0 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/service/User.java +++ b/src/main/java/com/twilio/rest/conversations/v1/service/User.java @@ -24,55 +24,66 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class User extends Resource { + private static final long serialVersionUID = 270629422616663L; - public static UserCreator creator(final String pathChatServiceSid, final String identity){ + public static UserCreator creator( + final String pathChatServiceSid, + final String identity + ) { return new UserCreator(pathChatServiceSid, identity); } - public static UserDeleter deleter(final String pathChatServiceSid, final String pathSid){ + public static UserDeleter deleter( + final String pathChatServiceSid, + final String pathSid + ) { return new UserDeleter(pathChatServiceSid, pathSid); } - public static UserFetcher fetcher(final String pathChatServiceSid, final String pathSid){ + public static UserFetcher fetcher( + final String pathChatServiceSid, + final String pathSid + ) { return new UserFetcher(pathChatServiceSid, pathSid); } - public static UserReader reader(final String pathChatServiceSid){ + public static UserReader reader(final String pathChatServiceSid) { return new UserReader(pathChatServiceSid); } - public static UserUpdater updater(final String pathChatServiceSid, final String pathSid){ + public static UserUpdater updater( + final String pathChatServiceSid, + final String pathSid + ) { return new UserUpdater(pathChatServiceSid, pathSid); } /** - * Converts a JSON String into a User object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return User object represented by the provided JSON - */ - public static User fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a User object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return User object represented by the provided JSON + */ + public static User fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, User.class); @@ -84,14 +95,17 @@ public static User fromJson(final String json, final ObjectMapper objectMapper) } /** - * Converts a JSON InputStream into a User object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return User object represented by the provided JSON - */ - public static User fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a User object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return User object represented by the provided JSON + */ + public static User fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, User.class); @@ -101,6 +115,7 @@ public static User fromJson(final InputStream json, final ObjectMapper objectMap throw new ApiConnectionException(e.getMessage(), e); } } + public enum WebhookEnabledType { TRUE("true"), FALSE("false"); @@ -137,44 +152,19 @@ public static WebhookEnabledType forValue(final String value) { @JsonCreator private User( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("chat_service_sid") - final String chatServiceSid, - - @JsonProperty("role_sid") - final String roleSid, - - @JsonProperty("identity") - final String identity, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("attributes") - final String attributes, - - @JsonProperty("is_online") - final Boolean isOnline, - - @JsonProperty("is_notifiable") - final Boolean isNotifiable, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("chat_service_sid") final String chatServiceSid, + @JsonProperty("role_sid") final String roleSid, + @JsonProperty("identity") final String identity, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("attributes") final String attributes, + @JsonProperty("is_online") final Boolean isOnline, + @JsonProperty("is_notifiable") final Boolean isNotifiable, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.sid = sid; this.accountSid = accountSid; @@ -191,49 +181,61 @@ private User( this.links = links; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getChatServiceSid() { - return this.chatServiceSid; - } - public final String getRoleSid() { - return this.roleSid; - } - public final String getIdentity() { - return this.identity; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getAttributes() { - return this.attributes; - } - public final Boolean getIsOnline() { - return this.isOnline; - } - public final Boolean getIsNotifiable() { - return this.isNotifiable; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getChatServiceSid() { + return this.chatServiceSid; + } + + public final String getRoleSid() { + return this.roleSid; + } + + public final String getIdentity() { + return this.identity; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getAttributes() { + return this.attributes; + } + + public final Boolean getIsOnline() { + return this.isOnline; + } + + public final Boolean getIsNotifiable() { + return this.isNotifiable; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -243,13 +245,39 @@ public boolean equals(final Object o) { User other = (User) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(chatServiceSid, other.chatServiceSid) && Objects.equals(roleSid, other.roleSid) && Objects.equals(identity, other.identity) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(attributes, other.attributes) && Objects.equals(isOnline, other.isOnline) && Objects.equals(isNotifiable, other.isNotifiable) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(chatServiceSid, other.chatServiceSid) && + Objects.equals(roleSid, other.roleSid) && + Objects.equals(identity, other.identity) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(attributes, other.attributes) && + Objects.equals(isOnline, other.isOnline) && + Objects.equals(isNotifiable, other.isNotifiable) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, chatServiceSid, roleSid, identity, friendlyName, attributes, isOnline, isNotifiable, dateCreated, dateUpdated, url, links); + return Objects.hash( + sid, + accountSid, + chatServiceSid, + roleSid, + identity, + friendlyName, + attributes, + isOnline, + isNotifiable, + dateCreated, + dateUpdated, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/UserCreator.java b/src/main/java/com/twilio/rest/conversations/v1/service/UserCreator.java index 8ed1ef6e26..bd6a5b6a15 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/service/UserCreator.java +++ b/src/main/java/com/twilio/rest/conversations/v1/service/UserCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.conversations.v1.service; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class UserCreator extends Creator { - - -public class UserCreator extends Creator{ private String pathChatServiceSid; private String identity; private User.WebhookEnabledType xTwilioWebhookEnabled; @@ -40,46 +39,62 @@ public UserCreator(final String pathChatServiceSid, final String identity) { this.identity = identity; } - public UserCreator setIdentity(final String identity){ + public UserCreator setIdentity(final String identity) { this.identity = identity; return this; } - public UserCreator setXTwilioWebhookEnabled(final User.WebhookEnabledType xTwilioWebhookEnabled){ + + public UserCreator setXTwilioWebhookEnabled( + final User.WebhookEnabledType xTwilioWebhookEnabled + ) { this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; return this; } - public UserCreator setFriendlyName(final String friendlyName){ + + public UserCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public UserCreator setAttributes(final String attributes){ + + public UserCreator setAttributes(final String attributes) { this.attributes = attributes; return this; } - public UserCreator setRoleSid(final String roleSid){ + + public UserCreator setRoleSid(final String roleSid) { this.roleSid = roleSid; return this; } @Override - public User create(final TwilioRestClient client){ + public User create(final TwilioRestClient client) { String path = "/v1/Services/{ChatServiceSid}/Users"; - path = path.replace("{"+"ChatServiceSid"+"}", this.pathChatServiceSid.toString()); - path = path.replace("{"+"Identity"+"}", this.identity.toString()); + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = path.replace("{" + "Identity" + "}", this.identity.toString()); Request request = new Request( HttpMethod.POST, Domains.CONVERSATIONS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); addHeaderParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("User creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "User creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -88,28 +103,28 @@ public User create(final TwilioRestClient client){ return User.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (identity != null) { request.addPostParam("Identity", identity); - } if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (attributes != null) { request.addPostParam("Attributes", attributes); - } if (roleSid != null) { request.addPostParam("RoleSid", roleSid); - } } + private void addHeaderParams(final Request request) { if (xTwilioWebhookEnabled != null) { - request.addHeaderParam("X-Twilio-Webhook-Enabled", xTwilioWebhookEnabled.toString()); - + request.addHeaderParam( + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/UserDeleter.java b/src/main/java/com/twilio/rest/conversations/v1/service/UserDeleter.java index fe7240c5e0..eac8d0f868 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/service/UserDeleter.java +++ b/src/main/java/com/twilio/rest/conversations/v1/service/UserDeleter.java @@ -24,19 +24,20 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class UserDeleter extends Deleter { + private String pathChatServiceSid; private String pathSid; private User.WebhookEnabledType xTwilioWebhookEnabled; - public UserDeleter(final String pathChatServiceSid, final String pathSid){ + public UserDeleter(final String pathChatServiceSid, final String pathSid) { this.pathChatServiceSid = pathChatServiceSid; this.pathSid = pathSid; } - public UserDeleter setXTwilioWebhookEnabled(final User.WebhookEnabledType xTwilioWebhookEnabled){ + public UserDeleter setXTwilioWebhookEnabled( + final User.WebhookEnabledType xTwilioWebhookEnabled + ) { this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; return this; } @@ -45,8 +46,12 @@ public UserDeleter setXTwilioWebhookEnabled(final User.WebhookEnabledType xTwili public boolean delete(final TwilioRestClient client) { String path = "/v1/Services/{ChatServiceSid}/Users/{Sid}"; - path = path.replace("{"+"ChatServiceSid"+"}", this.pathChatServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -57,9 +62,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("User delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "User delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -67,10 +77,13 @@ public boolean delete(final TwilioRestClient client) { } return response.getStatusCode() == 204; } + private void addHeaderParams(final Request request) { if (xTwilioWebhookEnabled != null) { - request.addHeaderParam("X-Twilio-Webhook-Enabled", xTwilioWebhookEnabled.toString()); - + request.addHeaderParam( + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/UserFetcher.java b/src/main/java/com/twilio/rest/conversations/v1/service/UserFetcher.java index 78e6783ccb..0fc2e6322e 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/service/UserFetcher.java +++ b/src/main/java/com/twilio/rest/conversations/v1/service/UserFetcher.java @@ -24,25 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class UserFetcher extends Fetcher { + private String pathChatServiceSid; private String pathSid; - public UserFetcher(final String pathChatServiceSid, final String pathSid){ + public UserFetcher(final String pathChatServiceSid, final String pathSid) { this.pathChatServiceSid = pathChatServiceSid; this.pathSid = pathSid; } - @Override public User fetch(final TwilioRestClient client) { String path = "/v1/Services/{ChatServiceSid}/Users/{Sid}"; - path = path.replace("{"+"ChatServiceSid"+"}", this.pathChatServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,9 +53,14 @@ public User fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("User fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "User fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/UserReader.java b/src/main/java/com/twilio/rest/conversations/v1/service/UserReader.java index 5bdbf0fe6d..2cef552a46 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/service/UserReader.java +++ b/src/main/java/com/twilio/rest/conversations/v1/service/UserReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.conversations.v1.service; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,19 +25,17 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class UserReader extends Reader { + private String pathChatServiceSid; private Integer pageSize; - public UserReader(final String pathChatServiceSid){ + public UserReader(final String pathChatServiceSid) { this.pathChatServiceSid = pathChatServiceSid; } - public UserReader setPageSize(final Integer pageSize){ + public UserReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -48,7 +47,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Services/{ChatServiceSid}/Users"; - path = path.replace("{"+"ChatServiceSid"+"}", this.pathChatServiceSid.toString()); + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -60,13 +63,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("User read failed: Unable to connect to server"); + throw new ApiConnectionException( + "User read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +93,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request r } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.CONVERSATIONS.toString()) @@ -90,9 +104,11 @@ public Page previousPage(final Page page, final TwilioRestClient cli return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.CONVERSATIONS.toString()) @@ -101,21 +117,21 @@ public Page nextPage(final Page page, final TwilioRestClient client) } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/UserUpdater.java b/src/main/java/com/twilio/rest/conversations/v1/service/UserUpdater.java index fddb7a0a53..02ff056246 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/service/UserUpdater.java +++ b/src/main/java/com/twilio/rest/conversations/v1/service/UserUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.conversations.v1.service; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class UserUpdater extends Updater { - - -public class UserUpdater extends Updater{ private String pathChatServiceSid; private String pathSid; private User.WebhookEnabledType xTwilioWebhookEnabled; @@ -35,47 +34,62 @@ public class UserUpdater extends Updater{ private String attributes; private String roleSid; - public UserUpdater(final String pathChatServiceSid, final String pathSid){ + public UserUpdater(final String pathChatServiceSid, final String pathSid) { this.pathChatServiceSid = pathChatServiceSid; this.pathSid = pathSid; } - public UserUpdater setXTwilioWebhookEnabled(final User.WebhookEnabledType xTwilioWebhookEnabled){ + public UserUpdater setXTwilioWebhookEnabled( + final User.WebhookEnabledType xTwilioWebhookEnabled + ) { this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; return this; } - public UserUpdater setFriendlyName(final String friendlyName){ + + public UserUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public UserUpdater setAttributes(final String attributes){ + + public UserUpdater setAttributes(final String attributes) { this.attributes = attributes; return this; } - public UserUpdater setRoleSid(final String roleSid){ + + public UserUpdater setRoleSid(final String roleSid) { this.roleSid = roleSid; return this; } @Override - public User update(final TwilioRestClient client){ + public User update(final TwilioRestClient client) { String path = "/v1/Services/{ChatServiceSid}/Users/{Sid}"; - path = path.replace("{"+"ChatServiceSid"+"}", this.pathChatServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.CONVERSATIONS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); addHeaderParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("User update failed: Unable to connect to server"); + throw new ApiConnectionException( + "User update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -84,24 +98,25 @@ public User update(final TwilioRestClient client){ return User.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (attributes != null) { request.addPostParam("Attributes", attributes); - } if (roleSid != null) { request.addPostParam("RoleSid", roleSid); - } } + private void addHeaderParams(final Request request) { if (xTwilioWebhookEnabled != null) { - request.addHeaderParam("X-Twilio-Webhook-Enabled", xTwilioWebhookEnabled.toString()); - + request.addHeaderParam( + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/configuration/Notification.java b/src/main/java/com/twilio/rest/conversations/v1/service/configuration/Notification.java index 99340dd45e..a66f8eda3b 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/service/configuration/Notification.java +++ b/src/main/java/com/twilio/rest/conversations/v1/service/configuration/Notification.java @@ -22,42 +22,41 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Notification extends Resource { + private static final long serialVersionUID = 46010876689651L; - public static NotificationFetcher fetcher(final String pathChatServiceSid){ + public static NotificationFetcher fetcher(final String pathChatServiceSid) { return new NotificationFetcher(pathChatServiceSid); } - public static NotificationUpdater updater(final String pathChatServiceSid){ + public static NotificationUpdater updater(final String pathChatServiceSid) { return new NotificationUpdater(pathChatServiceSid); } /** - * Converts a JSON String into a Notification object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Notification object represented by the provided JSON - */ - public static Notification fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Notification object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Notification object represented by the provided JSON + */ + public static Notification fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Notification.class); @@ -69,14 +68,17 @@ public static Notification fromJson(final String json, final ObjectMapper object } /** - * Converts a JSON InputStream into a Notification object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Notification object represented by the provided JSON - */ - public static Notification fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Notification object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Notification object represented by the provided JSON + */ + public static Notification fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Notification.class); @@ -97,26 +99,17 @@ public static Notification fromJson(final InputStream json, final ObjectMapper o @JsonCreator private Notification( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("chat_service_sid") - final String chatServiceSid, - - @JsonProperty("new_message") - final Map newMessage, - - @JsonProperty("added_to_conversation") - final Map addedToConversation, - - @JsonProperty("removed_from_conversation") - final Map removedFromConversation, - - @JsonProperty("log_enabled") - final Boolean logEnabled, - - @JsonProperty("url") - final URI url + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("chat_service_sid") final String chatServiceSid, + @JsonProperty("new_message") final Map newMessage, + @JsonProperty( + "added_to_conversation" + ) final Map addedToConversation, + @JsonProperty( + "removed_from_conversation" + ) final Map removedFromConversation, + @JsonProperty("log_enabled") final Boolean logEnabled, + @JsonProperty("url") final URI url ) { this.accountSid = accountSid; this.chatServiceSid = chatServiceSid; @@ -127,31 +120,37 @@ private Notification( this.url = url; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getChatServiceSid() { - return this.chatServiceSid; - } - public final Map getNewMessage() { - return this.newMessage; - } - public final Map getAddedToConversation() { - return this.addedToConversation; - } - public final Map getRemovedFromConversation() { - return this.removedFromConversation; - } - public final Boolean getLogEnabled() { - return this.logEnabled; - } - public final URI getUrl() { - return this.url; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getChatServiceSid() { + return this.chatServiceSid; + } + + public final Map getNewMessage() { + return this.newMessage; + } + + public final Map getAddedToConversation() { + return this.addedToConversation; + } + + public final Map getRemovedFromConversation() { + return this.removedFromConversation; + } + + public final Boolean getLogEnabled() { + return this.logEnabled; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -161,13 +160,30 @@ public boolean equals(final Object o) { Notification other = (Notification) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(chatServiceSid, other.chatServiceSid) && Objects.equals(newMessage, other.newMessage) && Objects.equals(addedToConversation, other.addedToConversation) && Objects.equals(removedFromConversation, other.removedFromConversation) && Objects.equals(logEnabled, other.logEnabled) && Objects.equals(url, other.url) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(chatServiceSid, other.chatServiceSid) && + Objects.equals(newMessage, other.newMessage) && + Objects.equals(addedToConversation, other.addedToConversation) && + Objects.equals( + removedFromConversation, + other.removedFromConversation + ) && + Objects.equals(logEnabled, other.logEnabled) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, chatServiceSid, newMessage, addedToConversation, removedFromConversation, logEnabled, url); + return Objects.hash( + accountSid, + chatServiceSid, + newMessage, + addedToConversation, + removedFromConversation, + logEnabled, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/configuration/NotificationFetcher.java b/src/main/java/com/twilio/rest/conversations/v1/service/configuration/NotificationFetcher.java index f52af9557c..e329fad4c4 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/service/configuration/NotificationFetcher.java +++ b/src/main/java/com/twilio/rest/conversations/v1/service/configuration/NotificationFetcher.java @@ -24,22 +24,24 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class NotificationFetcher extends Fetcher { + private String pathChatServiceSid; - public NotificationFetcher(final String pathChatServiceSid){ + public NotificationFetcher(final String pathChatServiceSid) { this.pathChatServiceSid = pathChatServiceSid; } - @Override public Notification fetch(final TwilioRestClient client) { - String path = "/v1/Services/{ChatServiceSid}/Configuration/Notifications"; + String path = + "/v1/Services/{ChatServiceSid}/Configuration/Notifications"; - path = path.replace("{"+"ChatServiceSid"+"}", this.pathChatServiceSid.toString()); + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -49,15 +51,23 @@ public Notification fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Notification fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Notification fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Notification.fromJson(response.getStream(), client.getObjectMapper()); + return Notification.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/configuration/NotificationUpdater.java b/src/main/java/com/twilio/rest/conversations/v1/service/configuration/NotificationUpdater.java index c6e2ad4c64..deaedec0f1 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/service/configuration/NotificationUpdater.java +++ b/src/main/java/com/twilio/rest/conversations/v1/service/configuration/NotificationUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.conversations.v1.service.configuration; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class NotificationUpdater extends Updater { - - -public class NotificationUpdater extends Updater{ private String pathChatServiceSid; private Boolean logEnabled; private Boolean newMessageEnabled; @@ -43,140 +42,208 @@ public class NotificationUpdater extends Updater{ private Boolean newMessageWithMediaEnabled; private String newMessageWithMediaTemplate; - public NotificationUpdater(final String pathChatServiceSid){ + public NotificationUpdater(final String pathChatServiceSid) { this.pathChatServiceSid = pathChatServiceSid; } - public NotificationUpdater setLogEnabled(final Boolean logEnabled){ + public NotificationUpdater setLogEnabled(final Boolean logEnabled) { this.logEnabled = logEnabled; return this; } - public NotificationUpdater setNewMessageEnabled(final Boolean newMessageEnabled){ + + public NotificationUpdater setNewMessageEnabled( + final Boolean newMessageEnabled + ) { this.newMessageEnabled = newMessageEnabled; return this; } - public NotificationUpdater setNewMessageTemplate(final String newMessageTemplate){ + + public NotificationUpdater setNewMessageTemplate( + final String newMessageTemplate + ) { this.newMessageTemplate = newMessageTemplate; return this; } - public NotificationUpdater setNewMessageSound(final String newMessageSound){ + + public NotificationUpdater setNewMessageSound( + final String newMessageSound + ) { this.newMessageSound = newMessageSound; return this; } - public NotificationUpdater setNewMessageBadgeCountEnabled(final Boolean newMessageBadgeCountEnabled){ + + public NotificationUpdater setNewMessageBadgeCountEnabled( + final Boolean newMessageBadgeCountEnabled + ) { this.newMessageBadgeCountEnabled = newMessageBadgeCountEnabled; return this; } - public NotificationUpdater setAddedToConversationEnabled(final Boolean addedToConversationEnabled){ + + public NotificationUpdater setAddedToConversationEnabled( + final Boolean addedToConversationEnabled + ) { this.addedToConversationEnabled = addedToConversationEnabled; return this; } - public NotificationUpdater setAddedToConversationTemplate(final String addedToConversationTemplate){ + + public NotificationUpdater setAddedToConversationTemplate( + final String addedToConversationTemplate + ) { this.addedToConversationTemplate = addedToConversationTemplate; return this; } - public NotificationUpdater setAddedToConversationSound(final String addedToConversationSound){ + + public NotificationUpdater setAddedToConversationSound( + final String addedToConversationSound + ) { this.addedToConversationSound = addedToConversationSound; return this; } - public NotificationUpdater setRemovedFromConversationEnabled(final Boolean removedFromConversationEnabled){ + + public NotificationUpdater setRemovedFromConversationEnabled( + final Boolean removedFromConversationEnabled + ) { this.removedFromConversationEnabled = removedFromConversationEnabled; return this; } - public NotificationUpdater setRemovedFromConversationTemplate(final String removedFromConversationTemplate){ + + public NotificationUpdater setRemovedFromConversationTemplate( + final String removedFromConversationTemplate + ) { this.removedFromConversationTemplate = removedFromConversationTemplate; return this; } - public NotificationUpdater setRemovedFromConversationSound(final String removedFromConversationSound){ + + public NotificationUpdater setRemovedFromConversationSound( + final String removedFromConversationSound + ) { this.removedFromConversationSound = removedFromConversationSound; return this; } - public NotificationUpdater setNewMessageWithMediaEnabled(final Boolean newMessageWithMediaEnabled){ + + public NotificationUpdater setNewMessageWithMediaEnabled( + final Boolean newMessageWithMediaEnabled + ) { this.newMessageWithMediaEnabled = newMessageWithMediaEnabled; return this; } - public NotificationUpdater setNewMessageWithMediaTemplate(final String newMessageWithMediaTemplate){ + + public NotificationUpdater setNewMessageWithMediaTemplate( + final String newMessageWithMediaTemplate + ) { this.newMessageWithMediaTemplate = newMessageWithMediaTemplate; return this; } @Override - public Notification update(final TwilioRestClient client){ - String path = "/v1/Services/{ChatServiceSid}/Configuration/Notifications"; + public Notification update(final TwilioRestClient client) { + String path = + "/v1/Services/{ChatServiceSid}/Configuration/Notifications"; - path = path.replace("{"+"ChatServiceSid"+"}", this.pathChatServiceSid.toString()); + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.CONVERSATIONS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Notification update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Notification update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Notification.fromJson(response.getStream(), client.getObjectMapper()); + return Notification.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (logEnabled != null) { request.addPostParam("LogEnabled", logEnabled.toString()); - } if (newMessageEnabled != null) { - request.addPostParam("NewMessage.Enabled", newMessageEnabled.toString()); - + request.addPostParam( + "NewMessage.Enabled", + newMessageEnabled.toString() + ); } if (newMessageTemplate != null) { request.addPostParam("NewMessage.Template", newMessageTemplate); - } if (newMessageSound != null) { request.addPostParam("NewMessage.Sound", newMessageSound); - } if (newMessageBadgeCountEnabled != null) { - request.addPostParam("NewMessage.BadgeCountEnabled", newMessageBadgeCountEnabled.toString()); - + request.addPostParam( + "NewMessage.BadgeCountEnabled", + newMessageBadgeCountEnabled.toString() + ); } if (addedToConversationEnabled != null) { - request.addPostParam("AddedToConversation.Enabled", addedToConversationEnabled.toString()); - + request.addPostParam( + "AddedToConversation.Enabled", + addedToConversationEnabled.toString() + ); } if (addedToConversationTemplate != null) { - request.addPostParam("AddedToConversation.Template", addedToConversationTemplate); - + request.addPostParam( + "AddedToConversation.Template", + addedToConversationTemplate + ); } if (addedToConversationSound != null) { - request.addPostParam("AddedToConversation.Sound", addedToConversationSound); - + request.addPostParam( + "AddedToConversation.Sound", + addedToConversationSound + ); } if (removedFromConversationEnabled != null) { - request.addPostParam("RemovedFromConversation.Enabled", removedFromConversationEnabled.toString()); - + request.addPostParam( + "RemovedFromConversation.Enabled", + removedFromConversationEnabled.toString() + ); } if (removedFromConversationTemplate != null) { - request.addPostParam("RemovedFromConversation.Template", removedFromConversationTemplate); - + request.addPostParam( + "RemovedFromConversation.Template", + removedFromConversationTemplate + ); } if (removedFromConversationSound != null) { - request.addPostParam("RemovedFromConversation.Sound", removedFromConversationSound); - + request.addPostParam( + "RemovedFromConversation.Sound", + removedFromConversationSound + ); } if (newMessageWithMediaEnabled != null) { - request.addPostParam("NewMessage.WithMedia.Enabled", newMessageWithMediaEnabled.toString()); - + request.addPostParam( + "NewMessage.WithMedia.Enabled", + newMessageWithMediaEnabled.toString() + ); } if (newMessageWithMediaTemplate != null) { - request.addPostParam("NewMessage.WithMedia.Template", newMessageWithMediaTemplate); - + request.addPostParam( + "NewMessage.WithMedia.Template", + newMessageWithMediaTemplate + ); } } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/configuration/Webhook.java b/src/main/java/com/twilio/rest/conversations/v1/service/configuration/Webhook.java index c0bc387d04..f86e5088c3 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/service/configuration/Webhook.java +++ b/src/main/java/com/twilio/rest/conversations/v1/service/configuration/Webhook.java @@ -23,41 +23,40 @@ import com.twilio.base.Resource; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.List; import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Webhook extends Resource { + private static final long serialVersionUID = 148454673918473L; - public static WebhookFetcher fetcher(final String pathChatServiceSid){ + public static WebhookFetcher fetcher(final String pathChatServiceSid) { return new WebhookFetcher(pathChatServiceSid); } - public static WebhookUpdater updater(final String pathChatServiceSid){ + public static WebhookUpdater updater(final String pathChatServiceSid) { return new WebhookUpdater(pathChatServiceSid); } /** - * Converts a JSON String into a Webhook object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Webhook object represented by the provided JSON - */ - public static Webhook fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Webhook object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Webhook object represented by the provided JSON + */ + public static Webhook fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Webhook.class); @@ -69,14 +68,17 @@ public static Webhook fromJson(final String json, final ObjectMapper objectMappe } /** - * Converts a JSON InputStream into a Webhook object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Webhook object represented by the provided JSON - */ - public static Webhook fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Webhook object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Webhook object represented by the provided JSON + */ + public static Webhook fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Webhook.class); @@ -86,6 +88,7 @@ public static Webhook fromJson(final InputStream json, final ObjectMapper object throw new ApiConnectionException(e.getMessage(), e); } } + public enum Method { GET("GET"), POST("POST"); @@ -116,26 +119,13 @@ public static Method forValue(final String value) { @JsonCreator private Webhook( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("chat_service_sid") - final String chatServiceSid, - - @JsonProperty("pre_webhook_url") - final URI preWebhookUrl, - - @JsonProperty("post_webhook_url") - final URI postWebhookUrl, - - @JsonProperty("filters") - final List filters, - - @JsonProperty("method") - final Webhook.Method method, - - @JsonProperty("url") - final URI url + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("chat_service_sid") final String chatServiceSid, + @JsonProperty("pre_webhook_url") final URI preWebhookUrl, + @JsonProperty("post_webhook_url") final URI postWebhookUrl, + @JsonProperty("filters") final List filters, + @JsonProperty("method") final Webhook.Method method, + @JsonProperty("url") final URI url ) { this.accountSid = accountSid; this.chatServiceSid = chatServiceSid; @@ -146,31 +136,37 @@ private Webhook( this.url = url; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getChatServiceSid() { - return this.chatServiceSid; - } - public final URI getPreWebhookUrl() { - return this.preWebhookUrl; - } - public final URI getPostWebhookUrl() { - return this.postWebhookUrl; - } - public final List getFilters() { - return this.filters; - } - public final Webhook.Method getMethod() { - return this.method; - } - public final URI getUrl() { - return this.url; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getChatServiceSid() { + return this.chatServiceSid; + } + + public final URI getPreWebhookUrl() { + return this.preWebhookUrl; + } + + public final URI getPostWebhookUrl() { + return this.postWebhookUrl; + } + + public final List getFilters() { + return this.filters; + } + + public final Webhook.Method getMethod() { + return this.method; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -180,13 +176,27 @@ public boolean equals(final Object o) { Webhook other = (Webhook) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(chatServiceSid, other.chatServiceSid) && Objects.equals(preWebhookUrl, other.preWebhookUrl) && Objects.equals(postWebhookUrl, other.postWebhookUrl) && Objects.equals(filters, other.filters) && Objects.equals(method, other.method) && Objects.equals(url, other.url) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(chatServiceSid, other.chatServiceSid) && + Objects.equals(preWebhookUrl, other.preWebhookUrl) && + Objects.equals(postWebhookUrl, other.postWebhookUrl) && + Objects.equals(filters, other.filters) && + Objects.equals(method, other.method) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, chatServiceSid, preWebhookUrl, postWebhookUrl, filters, method, url); + return Objects.hash( + accountSid, + chatServiceSid, + preWebhookUrl, + postWebhookUrl, + filters, + method, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/configuration/WebhookFetcher.java b/src/main/java/com/twilio/rest/conversations/v1/service/configuration/WebhookFetcher.java index 68c741a9ad..c000114b3e 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/service/configuration/WebhookFetcher.java +++ b/src/main/java/com/twilio/rest/conversations/v1/service/configuration/WebhookFetcher.java @@ -24,22 +24,23 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class WebhookFetcher extends Fetcher { + private String pathChatServiceSid; - public WebhookFetcher(final String pathChatServiceSid){ + public WebhookFetcher(final String pathChatServiceSid) { this.pathChatServiceSid = pathChatServiceSid; } - @Override public Webhook fetch(final TwilioRestClient client) { String path = "/v1/Services/{ChatServiceSid}/Configuration/Webhooks"; - path = path.replace("{"+"ChatServiceSid"+"}", this.pathChatServiceSid.toString()); + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -49,9 +50,14 @@ public Webhook fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Webhook fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Webhook fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/configuration/WebhookUpdater.java b/src/main/java/com/twilio/rest/conversations/v1/service/configuration/WebhookUpdater.java index 2094761be4..fe4f84218e 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/service/configuration/WebhookUpdater.java +++ b/src/main/java/com/twilio/rest/conversations/v1/service/configuration/WebhookUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.conversations.v1.service.configuration; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -24,68 +25,80 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.net.URI; - import java.util.List; +public class WebhookUpdater extends Updater { -public class WebhookUpdater extends Updater{ private String pathChatServiceSid; private URI preWebhookUrl; private URI postWebhookUrl; private List filters; private String method; - public WebhookUpdater(final String pathChatServiceSid){ + public WebhookUpdater(final String pathChatServiceSid) { this.pathChatServiceSid = pathChatServiceSid; } - public WebhookUpdater setPreWebhookUrl(final URI preWebhookUrl){ + public WebhookUpdater setPreWebhookUrl(final URI preWebhookUrl) { this.preWebhookUrl = preWebhookUrl; return this; } - public WebhookUpdater setPreWebhookUrl(final String preWebhookUrl){ + public WebhookUpdater setPreWebhookUrl(final String preWebhookUrl) { return setPreWebhookUrl(Promoter.uriFromString(preWebhookUrl)); } - public WebhookUpdater setPostWebhookUrl(final URI postWebhookUrl){ + + public WebhookUpdater setPostWebhookUrl(final URI postWebhookUrl) { this.postWebhookUrl = postWebhookUrl; return this; } - public WebhookUpdater setPostWebhookUrl(final String postWebhookUrl){ + public WebhookUpdater setPostWebhookUrl(final String postWebhookUrl) { return setPostWebhookUrl(Promoter.uriFromString(postWebhookUrl)); } - public WebhookUpdater setFilters(final List filters){ + + public WebhookUpdater setFilters(final List filters) { this.filters = filters; return this; } - public WebhookUpdater setFilters(final String filters){ + + public WebhookUpdater setFilters(final String filters) { return setFilters(Promoter.listOfOne(filters)); } - public WebhookUpdater setMethod(final String method){ + + public WebhookUpdater setMethod(final String method) { this.method = method; return this; } @Override - public Webhook update(final TwilioRestClient client){ + public Webhook update(final TwilioRestClient client) { String path = "/v1/Services/{ChatServiceSid}/Configuration/Webhooks"; - path = path.replace("{"+"ChatServiceSid"+"}", this.pathChatServiceSid.toString()); + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.CONVERSATIONS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Webhook update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Webhook update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -94,24 +107,21 @@ public Webhook update(final TwilioRestClient client){ return Webhook.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (preWebhookUrl != null) { request.addPostParam("PreWebhookUrl", preWebhookUrl.toString()); - } if (postWebhookUrl != null) { request.addPostParam("PostWebhookUrl", postWebhookUrl.toString()); - } if (filters != null) { for (String prop : filters) { request.addPostParam("Filters", prop); } - } if (method != null) { request.addPostParam("Method", method); - } } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/conversation/Message.java b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/Message.java index 7a472b9796..a685164d7a 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/service/conversation/Message.java +++ b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/Message.java @@ -24,56 +24,85 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.List; import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Message extends Resource { + private static final long serialVersionUID = 273348594526439L; - public static MessageCreator creator(final String pathChatServiceSid, final String pathConversationSid){ + public static MessageCreator creator( + final String pathChatServiceSid, + final String pathConversationSid + ) { return new MessageCreator(pathChatServiceSid, pathConversationSid); } - public static MessageDeleter deleter(final String pathChatServiceSid, final String pathConversationSid, final String pathSid){ - return new MessageDeleter(pathChatServiceSid, pathConversationSid, pathSid); + public static MessageDeleter deleter( + final String pathChatServiceSid, + final String pathConversationSid, + final String pathSid + ) { + return new MessageDeleter( + pathChatServiceSid, + pathConversationSid, + pathSid + ); } - public static MessageFetcher fetcher(final String pathChatServiceSid, final String pathConversationSid, final String pathSid){ - return new MessageFetcher(pathChatServiceSid, pathConversationSid, pathSid); + public static MessageFetcher fetcher( + final String pathChatServiceSid, + final String pathConversationSid, + final String pathSid + ) { + return new MessageFetcher( + pathChatServiceSid, + pathConversationSid, + pathSid + ); } - public static MessageReader reader(final String pathChatServiceSid, final String pathConversationSid){ + public static MessageReader reader( + final String pathChatServiceSid, + final String pathConversationSid + ) { return new MessageReader(pathChatServiceSid, pathConversationSid); } - public static MessageUpdater updater(final String pathChatServiceSid, final String pathConversationSid, final String pathSid){ - return new MessageUpdater(pathChatServiceSid, pathConversationSid, pathSid); + public static MessageUpdater updater( + final String pathChatServiceSid, + final String pathConversationSid, + final String pathSid + ) { + return new MessageUpdater( + pathChatServiceSid, + pathConversationSid, + pathSid + ); } /** - * Converts a JSON String into a Message object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Message object represented by the provided JSON - */ - public static Message fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Message object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Message object represented by the provided JSON + */ + public static Message fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Message.class); @@ -85,14 +114,17 @@ public static Message fromJson(final String json, final ObjectMapper objectMappe } /** - * Converts a JSON InputStream into a Message object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Message object represented by the provided JSON - */ - public static Message fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Message object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Message object represented by the provided JSON + */ + public static Message fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Message.class); @@ -102,6 +134,7 @@ public static Message fromJson(final InputStream json, final ObjectMapper object throw new ApiConnectionException(e.getMessage(), e); } } + public enum OrderType { ASC("asc"), DESC("desc"); @@ -121,6 +154,7 @@ public static OrderType forValue(final String value) { return Promoter.enumFromString(value, OrderType.values()); } } + public enum WebhookEnabledType { TRUE("true"), FALSE("false"); @@ -160,53 +194,22 @@ public static WebhookEnabledType forValue(final String value) { @JsonCreator private Message( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("chat_service_sid") - final String chatServiceSid, - - @JsonProperty("conversation_sid") - final String conversationSid, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("index") - final Integer index, - - @JsonProperty("author") - final String author, - - @JsonProperty("body") - final String body, - - @JsonProperty("media") - final List> media, - - @JsonProperty("attributes") - final String attributes, - - @JsonProperty("participant_sid") - final String participantSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("delivery") - final Map delivery, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links, - - @JsonProperty("content_sid") - final String contentSid + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("chat_service_sid") final String chatServiceSid, + @JsonProperty("conversation_sid") final String conversationSid, + @JsonProperty("sid") final String sid, + @JsonProperty("index") final Integer index, + @JsonProperty("author") final String author, + @JsonProperty("body") final String body, + @JsonProperty("media") final List> media, + @JsonProperty("attributes") final String attributes, + @JsonProperty("participant_sid") final String participantSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("delivery") final Map delivery, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links, + @JsonProperty("content_sid") final String contentSid ) { this.accountSid = accountSid; this.chatServiceSid = chatServiceSid; @@ -226,58 +229,73 @@ private Message( this.contentSid = contentSid; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getChatServiceSid() { - return this.chatServiceSid; - } - public final String getConversationSid() { - return this.conversationSid; - } - public final String getSid() { - return this.sid; - } - public final Integer getIndex() { - return this.index; - } - public final String getAuthor() { - return this.author; - } - public final String getBody() { - return this.body; - } - public final List> getMedia() { - return this.media; - } - public final String getAttributes() { - return this.attributes; - } - public final String getParticipantSid() { - return this.participantSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final Map getDelivery() { - return this.delivery; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } - public final String getContentSid() { - return this.contentSid; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getChatServiceSid() { + return this.chatServiceSid; + } + + public final String getConversationSid() { + return this.conversationSid; + } + + public final String getSid() { + return this.sid; + } + + public final Integer getIndex() { + return this.index; + } + + public final String getAuthor() { + return this.author; + } + + public final String getBody() { + return this.body; + } + + public final List> getMedia() { + return this.media; + } + + public final String getAttributes() { + return this.attributes; + } + + public final String getParticipantSid() { + return this.participantSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final Map getDelivery() { + return this.delivery; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } + + public final String getContentSid() { + return this.contentSid; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -287,13 +305,45 @@ public boolean equals(final Object o) { Message other = (Message) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(chatServiceSid, other.chatServiceSid) && Objects.equals(conversationSid, other.conversationSid) && Objects.equals(sid, other.sid) && Objects.equals(index, other.index) && Objects.equals(author, other.author) && Objects.equals(body, other.body) && Objects.equals(media, other.media) && Objects.equals(attributes, other.attributes) && Objects.equals(participantSid, other.participantSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(delivery, other.delivery) && Objects.equals(url, other.url) && Objects.equals(links, other.links) && Objects.equals(contentSid, other.contentSid) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(chatServiceSid, other.chatServiceSid) && + Objects.equals(conversationSid, other.conversationSid) && + Objects.equals(sid, other.sid) && + Objects.equals(index, other.index) && + Objects.equals(author, other.author) && + Objects.equals(body, other.body) && + Objects.equals(media, other.media) && + Objects.equals(attributes, other.attributes) && + Objects.equals(participantSid, other.participantSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(delivery, other.delivery) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) && + Objects.equals(contentSid, other.contentSid) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, chatServiceSid, conversationSid, sid, index, author, body, media, attributes, participantSid, dateCreated, dateUpdated, delivery, url, links, contentSid); + return Objects.hash( + accountSid, + chatServiceSid, + conversationSid, + sid, + index, + author, + body, + media, + attributes, + participantSid, + dateCreated, + dateUpdated, + delivery, + url, + links, + contentSid + ); } - } - diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/conversation/MessageCreator.java b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/MessageCreator.java index e47ce15857..b1b0a6596d 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/service/conversation/MessageCreator.java +++ b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/MessageCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.conversations.v1.service.conversation; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -25,10 +26,8 @@ import com.twilio.rest.Domains; import java.time.ZonedDateTime; +public class MessageCreator extends Creator { - - -public class MessageCreator extends Creator{ private String pathChatServiceSid; private String pathConversationSid; private Message.WebhookEnabledType xTwilioWebhookEnabled; @@ -41,67 +40,95 @@ public class MessageCreator extends Creator{ private String contentSid; private String contentVariables; - public MessageCreator(final String pathChatServiceSid, final String pathConversationSid) { + public MessageCreator( + final String pathChatServiceSid, + final String pathConversationSid + ) { this.pathChatServiceSid = pathChatServiceSid; this.pathConversationSid = pathConversationSid; } - public MessageCreator setXTwilioWebhookEnabled(final Message.WebhookEnabledType xTwilioWebhookEnabled){ + public MessageCreator setXTwilioWebhookEnabled( + final Message.WebhookEnabledType xTwilioWebhookEnabled + ) { this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; return this; } - public MessageCreator setAuthor(final String author){ + + public MessageCreator setAuthor(final String author) { this.author = author; return this; } - public MessageCreator setBody(final String body){ + + public MessageCreator setBody(final String body) { this.body = body; return this; } - public MessageCreator setDateCreated(final ZonedDateTime dateCreated){ + + public MessageCreator setDateCreated(final ZonedDateTime dateCreated) { this.dateCreated = dateCreated; return this; } - public MessageCreator setDateUpdated(final ZonedDateTime dateUpdated){ + + public MessageCreator setDateUpdated(final ZonedDateTime dateUpdated) { this.dateUpdated = dateUpdated; return this; } - public MessageCreator setAttributes(final String attributes){ + + public MessageCreator setAttributes(final String attributes) { this.attributes = attributes; return this; } - public MessageCreator setMediaSid(final String mediaSid){ + + public MessageCreator setMediaSid(final String mediaSid) { this.mediaSid = mediaSid; return this; } - public MessageCreator setContentSid(final String contentSid){ + + public MessageCreator setContentSid(final String contentSid) { this.contentSid = contentSid; return this; } - public MessageCreator setContentVariables(final String contentVariables){ + + public MessageCreator setContentVariables(final String contentVariables) { this.contentVariables = contentVariables; return this; } @Override - public Message create(final TwilioRestClient client){ - String path = "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Messages"; + public Message create(final TwilioRestClient client) { + String path = + "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Messages"; - path = path.replace("{"+"ChatServiceSid"+"}", this.pathChatServiceSid.toString()); - path = path.replace("{"+"ConversationSid"+"}", this.pathConversationSid.toString()); + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.CONVERSATIONS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); addHeaderParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Message creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Message creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -110,44 +137,46 @@ public Message create(final TwilioRestClient client){ return Message.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (author != null) { request.addPostParam("Author", author); - } if (body != null) { request.addPostParam("Body", body); - } if (dateCreated != null) { - request.addPostParam("DateCreated", dateCreated.toInstant().toString()); - + request.addPostParam( + "DateCreated", + dateCreated.toInstant().toString() + ); } if (dateUpdated != null) { - request.addPostParam("DateUpdated", dateUpdated.toInstant().toString()); - + request.addPostParam( + "DateUpdated", + dateUpdated.toInstant().toString() + ); } if (attributes != null) { request.addPostParam("Attributes", attributes); - } if (mediaSid != null) { request.addPostParam("MediaSid", mediaSid); - } if (contentSid != null) { request.addPostParam("ContentSid", contentSid); - } if (contentVariables != null) { request.addPostParam("ContentVariables", contentVariables); - } } + private void addHeaderParams(final Request request) { if (xTwilioWebhookEnabled != null) { - request.addHeaderParam("X-Twilio-Webhook-Enabled", xTwilioWebhookEnabled.toString()); - + request.addHeaderParam( + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/conversation/MessageDeleter.java b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/MessageDeleter.java index b2bac3975a..8a30c673d9 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/service/conversation/MessageDeleter.java +++ b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/MessageDeleter.java @@ -24,32 +24,46 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class MessageDeleter extends Deleter { + private String pathChatServiceSid; private String pathConversationSid; private String pathSid; private Message.WebhookEnabledType xTwilioWebhookEnabled; - public MessageDeleter(final String pathChatServiceSid, final String pathConversationSid, final String pathSid){ + public MessageDeleter( + final String pathChatServiceSid, + final String pathConversationSid, + final String pathSid + ) { this.pathChatServiceSid = pathChatServiceSid; this.pathConversationSid = pathConversationSid; this.pathSid = pathSid; } - public MessageDeleter setXTwilioWebhookEnabled(final Message.WebhookEnabledType xTwilioWebhookEnabled){ + public MessageDeleter setXTwilioWebhookEnabled( + final Message.WebhookEnabledType xTwilioWebhookEnabled + ) { this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; return this; } @Override public boolean delete(final TwilioRestClient client) { - String path = "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Messages/{Sid}"; + String path = + "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Messages/{Sid}"; - path = path.replace("{"+"ChatServiceSid"+"}", this.pathChatServiceSid.toString()); - path = path.replace("{"+"ConversationSid"+"}", this.pathConversationSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -60,9 +74,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Message delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Message delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -70,10 +89,13 @@ public boolean delete(final TwilioRestClient client) { } return response.getStatusCode() == 204; } + private void addHeaderParams(final Request request) { if (xTwilioWebhookEnabled != null) { - request.addHeaderParam("X-Twilio-Webhook-Enabled", xTwilioWebhookEnabled.toString()); - + request.addHeaderParam( + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/conversation/MessageFetcher.java b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/MessageFetcher.java index f22b174a34..745d14c67d 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/service/conversation/MessageFetcher.java +++ b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/MessageFetcher.java @@ -24,28 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class MessageFetcher extends Fetcher { + private String pathChatServiceSid; private String pathConversationSid; private String pathSid; - public MessageFetcher(final String pathChatServiceSid, final String pathConversationSid, final String pathSid){ + public MessageFetcher( + final String pathChatServiceSid, + final String pathConversationSid, + final String pathSid + ) { this.pathChatServiceSid = pathChatServiceSid; this.pathConversationSid = pathConversationSid; this.pathSid = pathSid; } - @Override public Message fetch(final TwilioRestClient client) { - String path = "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Messages/{Sid}"; + String path = + "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Messages/{Sid}"; - path = path.replace("{"+"ChatServiceSid"+"}", this.pathChatServiceSid.toString()); - path = path.replace("{"+"ConversationSid"+"}", this.pathConversationSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -55,9 +65,14 @@ public Message fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Message fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Message fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/conversation/MessageReader.java b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/MessageReader.java index 6b979e4320..656be8ff75 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/service/conversation/MessageReader.java +++ b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/MessageReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.conversations.v1.service.conversation; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,26 +25,28 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class MessageReader extends Reader { + private String pathChatServiceSid; private String pathConversationSid; private Message.OrderType order; private Integer pageSize; - public MessageReader(final String pathChatServiceSid, final String pathConversationSid){ + public MessageReader( + final String pathChatServiceSid, + final String pathConversationSid + ) { this.pathChatServiceSid = pathChatServiceSid; this.pathConversationSid = pathConversationSid; } - public MessageReader setOrder(final Message.OrderType order){ + public MessageReader setOrder(final Message.OrderType order) { this.order = order; return this; } - public MessageReader setPageSize(final Integer pageSize){ + + public MessageReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -54,9 +57,18 @@ public ResourceSet read(final TwilioRestClient client) { } public Page firstPage(final TwilioRestClient client) { - String path = "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Messages"; - path = path.replace("{"+"ChatServiceSid"+"}", this.pathChatServiceSid.toString()); - path = path.replace("{"+"ConversationSid"+"}", this.pathConversationSid.toString()); + String path = + "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Messages"; + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -68,13 +80,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Message read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Message read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -90,7 +110,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reques } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.CONVERSATIONS.toString()) @@ -98,9 +121,11 @@ public Page previousPage(final Page page, final TwilioRestClie return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.CONVERSATIONS.toString()) @@ -109,25 +134,24 @@ public Page nextPage(final Page page, final TwilioRestClient c } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (order != null) { - request.addQueryParam("Order", order.toString()); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/conversation/MessageUpdater.java b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/MessageUpdater.java index 871c8778b8..3fb04f77b4 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/service/conversation/MessageUpdater.java +++ b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/MessageUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.conversations.v1.service.conversation; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -23,12 +24,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.time.ZonedDateTime; +public class MessageUpdater extends Updater { - -public class MessageUpdater extends Updater{ private String pathChatServiceSid; private String pathConversationSid; private String pathSid; @@ -39,57 +38,83 @@ public class MessageUpdater extends Updater{ private ZonedDateTime dateUpdated; private String attributes; - public MessageUpdater(final String pathChatServiceSid, final String pathConversationSid, final String pathSid){ + public MessageUpdater( + final String pathChatServiceSid, + final String pathConversationSid, + final String pathSid + ) { this.pathChatServiceSid = pathChatServiceSid; this.pathConversationSid = pathConversationSid; this.pathSid = pathSid; } - public MessageUpdater setXTwilioWebhookEnabled(final Message.WebhookEnabledType xTwilioWebhookEnabled){ + public MessageUpdater setXTwilioWebhookEnabled( + final Message.WebhookEnabledType xTwilioWebhookEnabled + ) { this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; return this; } - public MessageUpdater setAuthor(final String author){ + + public MessageUpdater setAuthor(final String author) { this.author = author; return this; } - public MessageUpdater setBody(final String body){ + + public MessageUpdater setBody(final String body) { this.body = body; return this; } - public MessageUpdater setDateCreated(final ZonedDateTime dateCreated){ + + public MessageUpdater setDateCreated(final ZonedDateTime dateCreated) { this.dateCreated = dateCreated; return this; } - public MessageUpdater setDateUpdated(final ZonedDateTime dateUpdated){ + + public MessageUpdater setDateUpdated(final ZonedDateTime dateUpdated) { this.dateUpdated = dateUpdated; return this; } - public MessageUpdater setAttributes(final String attributes){ + + public MessageUpdater setAttributes(final String attributes) { this.attributes = attributes; return this; } @Override - public Message update(final TwilioRestClient client){ - String path = "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Messages/{Sid}"; + public Message update(final TwilioRestClient client) { + String path = + "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Messages/{Sid}"; - path = path.replace("{"+"ChatServiceSid"+"}", this.pathChatServiceSid.toString()); - path = path.replace("{"+"ConversationSid"+"}", this.pathConversationSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.CONVERSATIONS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); addHeaderParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Message update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Message update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -98,32 +123,37 @@ public Message update(final TwilioRestClient client){ return Message.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (author != null) { request.addPostParam("Author", author); - } if (body != null) { request.addPostParam("Body", body); - } if (dateCreated != null) { - request.addPostParam("DateCreated", dateCreated.toInstant().toString()); - + request.addPostParam( + "DateCreated", + dateCreated.toInstant().toString() + ); } if (dateUpdated != null) { - request.addPostParam("DateUpdated", dateUpdated.toInstant().toString()); - + request.addPostParam( + "DateUpdated", + dateUpdated.toInstant().toString() + ); } if (attributes != null) { request.addPostParam("Attributes", attributes); - } } + private void addHeaderParams(final Request request) { if (xTwilioWebhookEnabled != null) { - request.addHeaderParam("X-Twilio-Webhook-Enabled", xTwilioWebhookEnabled.toString()); - + request.addHeaderParam( + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/conversation/Participant.java b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/Participant.java index 3b7b690839..05bc5369a4 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/service/conversation/Participant.java +++ b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/Participant.java @@ -24,55 +24,84 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Participant extends Resource { + private static final long serialVersionUID = 110295013528965L; - public static ParticipantCreator creator(final String pathChatServiceSid, final String pathConversationSid){ + public static ParticipantCreator creator( + final String pathChatServiceSid, + final String pathConversationSid + ) { return new ParticipantCreator(pathChatServiceSid, pathConversationSid); } - public static ParticipantDeleter deleter(final String pathChatServiceSid, final String pathConversationSid, final String pathSid){ - return new ParticipantDeleter(pathChatServiceSid, pathConversationSid, pathSid); + public static ParticipantDeleter deleter( + final String pathChatServiceSid, + final String pathConversationSid, + final String pathSid + ) { + return new ParticipantDeleter( + pathChatServiceSid, + pathConversationSid, + pathSid + ); } - public static ParticipantFetcher fetcher(final String pathChatServiceSid, final String pathConversationSid, final String pathSid){ - return new ParticipantFetcher(pathChatServiceSid, pathConversationSid, pathSid); + public static ParticipantFetcher fetcher( + final String pathChatServiceSid, + final String pathConversationSid, + final String pathSid + ) { + return new ParticipantFetcher( + pathChatServiceSid, + pathConversationSid, + pathSid + ); } - public static ParticipantReader reader(final String pathChatServiceSid, final String pathConversationSid){ + public static ParticipantReader reader( + final String pathChatServiceSid, + final String pathConversationSid + ) { return new ParticipantReader(pathChatServiceSid, pathConversationSid); } - public static ParticipantUpdater updater(final String pathChatServiceSid, final String pathConversationSid, final String pathSid){ - return new ParticipantUpdater(pathChatServiceSid, pathConversationSid, pathSid); + public static ParticipantUpdater updater( + final String pathChatServiceSid, + final String pathConversationSid, + final String pathSid + ) { + return new ParticipantUpdater( + pathChatServiceSid, + pathConversationSid, + pathSid + ); } /** - * Converts a JSON String into a Participant object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Participant object represented by the provided JSON - */ - public static Participant fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Participant object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Participant object represented by the provided JSON + */ + public static Participant fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Participant.class); @@ -84,14 +113,17 @@ public static Participant fromJson(final String json, final ObjectMapper objectM } /** - * Converts a JSON InputStream into a Participant object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Participant object represented by the provided JSON - */ - public static Participant fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Participant object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Participant object represented by the provided JSON + */ + public static Participant fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Participant.class); @@ -101,6 +133,7 @@ public static Participant fromJson(final InputStream json, final ObjectMapper ob throw new ApiConnectionException(e.getMessage(), e); } } + public enum WebhookEnabledType { TRUE("true"), FALSE("false"); @@ -137,44 +170,23 @@ public static WebhookEnabledType forValue(final String value) { @JsonCreator private Participant( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("chat_service_sid") - final String chatServiceSid, - - @JsonProperty("conversation_sid") - final String conversationSid, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("identity") - final String identity, - - @JsonProperty("attributes") - final String attributes, - - @JsonProperty("messaging_binding") - final Map messagingBinding, - - @JsonProperty("role_sid") - final String roleSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url, - - @JsonProperty("last_read_message_index") - final Integer lastReadMessageIndex, - - @JsonProperty("last_read_timestamp") - final String lastReadTimestamp + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("chat_service_sid") final String chatServiceSid, + @JsonProperty("conversation_sid") final String conversationSid, + @JsonProperty("sid") final String sid, + @JsonProperty("identity") final String identity, + @JsonProperty("attributes") final String attributes, + @JsonProperty( + "messaging_binding" + ) final Map messagingBinding, + @JsonProperty("role_sid") final String roleSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url, + @JsonProperty( + "last_read_message_index" + ) final Integer lastReadMessageIndex, + @JsonProperty("last_read_timestamp") final String lastReadTimestamp ) { this.accountSid = accountSid; this.chatServiceSid = chatServiceSid; @@ -191,49 +203,61 @@ private Participant( this.lastReadTimestamp = lastReadTimestamp; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getChatServiceSid() { - return this.chatServiceSid; - } - public final String getConversationSid() { - return this.conversationSid; - } - public final String getSid() { - return this.sid; - } - public final String getIdentity() { - return this.identity; - } - public final String getAttributes() { - return this.attributes; - } - public final Map getMessagingBinding() { - return this.messagingBinding; - } - public final String getRoleSid() { - return this.roleSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } - public final Integer getLastReadMessageIndex() { - return this.lastReadMessageIndex; - } - public final String getLastReadTimestamp() { - return this.lastReadTimestamp; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getChatServiceSid() { + return this.chatServiceSid; + } + + public final String getConversationSid() { + return this.conversationSid; + } + + public final String getSid() { + return this.sid; + } + + public final String getIdentity() { + return this.identity; + } + + public final String getAttributes() { + return this.attributes; + } + + public final Map getMessagingBinding() { + return this.messagingBinding; + } + + public final String getRoleSid() { + return this.roleSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } + + public final Integer getLastReadMessageIndex() { + return this.lastReadMessageIndex; + } + + public final String getLastReadTimestamp() { + return this.lastReadTimestamp; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -243,13 +267,39 @@ public boolean equals(final Object o) { Participant other = (Participant) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(chatServiceSid, other.chatServiceSid) && Objects.equals(conversationSid, other.conversationSid) && Objects.equals(sid, other.sid) && Objects.equals(identity, other.identity) && Objects.equals(attributes, other.attributes) && Objects.equals(messagingBinding, other.messagingBinding) && Objects.equals(roleSid, other.roleSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) && Objects.equals(lastReadMessageIndex, other.lastReadMessageIndex) && Objects.equals(lastReadTimestamp, other.lastReadTimestamp) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(chatServiceSid, other.chatServiceSid) && + Objects.equals(conversationSid, other.conversationSid) && + Objects.equals(sid, other.sid) && + Objects.equals(identity, other.identity) && + Objects.equals(attributes, other.attributes) && + Objects.equals(messagingBinding, other.messagingBinding) && + Objects.equals(roleSid, other.roleSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) && + Objects.equals(lastReadMessageIndex, other.lastReadMessageIndex) && + Objects.equals(lastReadTimestamp, other.lastReadTimestamp) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, chatServiceSid, conversationSid, sid, identity, attributes, messagingBinding, roleSid, dateCreated, dateUpdated, url, lastReadMessageIndex, lastReadTimestamp); + return Objects.hash( + accountSid, + chatServiceSid, + conversationSid, + sid, + identity, + attributes, + messagingBinding, + roleSid, + dateCreated, + dateUpdated, + url, + lastReadMessageIndex, + lastReadTimestamp + ); } - } - diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/conversation/ParticipantCreator.java b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/ParticipantCreator.java index 535cf5999b..681d3c292d 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/service/conversation/ParticipantCreator.java +++ b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/ParticipantCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.conversations.v1.service.conversation; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -25,10 +26,8 @@ import com.twilio.rest.Domains; import java.time.ZonedDateTime; +public class ParticipantCreator extends Creator { - - -public class ParticipantCreator extends Creator{ private String pathChatServiceSid; private String pathConversationSid; private Participant.WebhookEnabledType xTwilioWebhookEnabled; @@ -41,113 +40,162 @@ public class ParticipantCreator extends Creator{ private String messagingBindingProjectedAddress; private String roleSid; - public ParticipantCreator(final String pathChatServiceSid, final String pathConversationSid) { + public ParticipantCreator( + final String pathChatServiceSid, + final String pathConversationSid + ) { this.pathChatServiceSid = pathChatServiceSid; this.pathConversationSid = pathConversationSid; } - public ParticipantCreator setXTwilioWebhookEnabled(final Participant.WebhookEnabledType xTwilioWebhookEnabled){ + public ParticipantCreator setXTwilioWebhookEnabled( + final Participant.WebhookEnabledType xTwilioWebhookEnabled + ) { this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; return this; } - public ParticipantCreator setIdentity(final String identity){ + + public ParticipantCreator setIdentity(final String identity) { this.identity = identity; return this; } - public ParticipantCreator setMessagingBindingAddress(final String messagingBindingAddress){ + + public ParticipantCreator setMessagingBindingAddress( + final String messagingBindingAddress + ) { this.messagingBindingAddress = messagingBindingAddress; return this; } - public ParticipantCreator setMessagingBindingProxyAddress(final String messagingBindingProxyAddress){ + + public ParticipantCreator setMessagingBindingProxyAddress( + final String messagingBindingProxyAddress + ) { this.messagingBindingProxyAddress = messagingBindingProxyAddress; return this; } - public ParticipantCreator setDateCreated(final ZonedDateTime dateCreated){ + + public ParticipantCreator setDateCreated(final ZonedDateTime dateCreated) { this.dateCreated = dateCreated; return this; } - public ParticipantCreator setDateUpdated(final ZonedDateTime dateUpdated){ + + public ParticipantCreator setDateUpdated(final ZonedDateTime dateUpdated) { this.dateUpdated = dateUpdated; return this; } - public ParticipantCreator setAttributes(final String attributes){ + + public ParticipantCreator setAttributes(final String attributes) { this.attributes = attributes; return this; } - public ParticipantCreator setMessagingBindingProjectedAddress(final String messagingBindingProjectedAddress){ - this.messagingBindingProjectedAddress = messagingBindingProjectedAddress; + + public ParticipantCreator setMessagingBindingProjectedAddress( + final String messagingBindingProjectedAddress + ) { + this.messagingBindingProjectedAddress = + messagingBindingProjectedAddress; return this; } - public ParticipantCreator setRoleSid(final String roleSid){ + + public ParticipantCreator setRoleSid(final String roleSid) { this.roleSid = roleSid; return this; } @Override - public Participant create(final TwilioRestClient client){ - String path = "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Participants"; + public Participant create(final TwilioRestClient client) { + String path = + "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Participants"; - path = path.replace("{"+"ChatServiceSid"+"}", this.pathChatServiceSid.toString()); - path = path.replace("{"+"ConversationSid"+"}", this.pathConversationSid.toString()); + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.CONVERSATIONS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); addHeaderParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Participant creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Participant creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Participant.fromJson(response.getStream(), client.getObjectMapper()); + return Participant.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (identity != null) { request.addPostParam("Identity", identity); - } if (messagingBindingAddress != null) { - request.addPostParam("MessagingBinding.Address", messagingBindingAddress); - + request.addPostParam( + "MessagingBinding.Address", + messagingBindingAddress + ); } if (messagingBindingProxyAddress != null) { - request.addPostParam("MessagingBinding.ProxyAddress", messagingBindingProxyAddress); - + request.addPostParam( + "MessagingBinding.ProxyAddress", + messagingBindingProxyAddress + ); } if (dateCreated != null) { - request.addPostParam("DateCreated", dateCreated.toInstant().toString()); - + request.addPostParam( + "DateCreated", + dateCreated.toInstant().toString() + ); } if (dateUpdated != null) { - request.addPostParam("DateUpdated", dateUpdated.toInstant().toString()); - + request.addPostParam( + "DateUpdated", + dateUpdated.toInstant().toString() + ); } if (attributes != null) { request.addPostParam("Attributes", attributes); - } if (messagingBindingProjectedAddress != null) { - request.addPostParam("MessagingBinding.ProjectedAddress", messagingBindingProjectedAddress); - + request.addPostParam( + "MessagingBinding.ProjectedAddress", + messagingBindingProjectedAddress + ); } if (roleSid != null) { request.addPostParam("RoleSid", roleSid); - } } + private void addHeaderParams(final Request request) { if (xTwilioWebhookEnabled != null) { - request.addHeaderParam("X-Twilio-Webhook-Enabled", xTwilioWebhookEnabled.toString()); - + request.addHeaderParam( + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/conversation/ParticipantDeleter.java b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/ParticipantDeleter.java index 80add62eed..74de5e39df 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/service/conversation/ParticipantDeleter.java +++ b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/ParticipantDeleter.java @@ -24,32 +24,46 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class ParticipantDeleter extends Deleter { + private String pathChatServiceSid; private String pathConversationSid; private String pathSid; private Participant.WebhookEnabledType xTwilioWebhookEnabled; - public ParticipantDeleter(final String pathChatServiceSid, final String pathConversationSid, final String pathSid){ + public ParticipantDeleter( + final String pathChatServiceSid, + final String pathConversationSid, + final String pathSid + ) { this.pathChatServiceSid = pathChatServiceSid; this.pathConversationSid = pathConversationSid; this.pathSid = pathSid; } - public ParticipantDeleter setXTwilioWebhookEnabled(final Participant.WebhookEnabledType xTwilioWebhookEnabled){ + public ParticipantDeleter setXTwilioWebhookEnabled( + final Participant.WebhookEnabledType xTwilioWebhookEnabled + ) { this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; return this; } @Override public boolean delete(final TwilioRestClient client) { - String path = "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Participants/{Sid}"; + String path = + "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Participants/{Sid}"; - path = path.replace("{"+"ChatServiceSid"+"}", this.pathChatServiceSid.toString()); - path = path.replace("{"+"ConversationSid"+"}", this.pathConversationSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -60,9 +74,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Participant delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Participant delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -70,10 +89,13 @@ public boolean delete(final TwilioRestClient client) { } return response.getStatusCode() == 204; } + private void addHeaderParams(final Request request) { if (xTwilioWebhookEnabled != null) { - request.addHeaderParam("X-Twilio-Webhook-Enabled", xTwilioWebhookEnabled.toString()); - + request.addHeaderParam( + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/conversation/ParticipantFetcher.java b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/ParticipantFetcher.java index cae2dc97b5..3f13da59b6 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/service/conversation/ParticipantFetcher.java +++ b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/ParticipantFetcher.java @@ -24,28 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class ParticipantFetcher extends Fetcher { + private String pathChatServiceSid; private String pathConversationSid; private String pathSid; - public ParticipantFetcher(final String pathChatServiceSid, final String pathConversationSid, final String pathSid){ + public ParticipantFetcher( + final String pathChatServiceSid, + final String pathConversationSid, + final String pathSid + ) { this.pathChatServiceSid = pathChatServiceSid; this.pathConversationSid = pathConversationSid; this.pathSid = pathSid; } - @Override public Participant fetch(final TwilioRestClient client) { - String path = "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Participants/{Sid}"; + String path = + "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Participants/{Sid}"; - path = path.replace("{"+"ChatServiceSid"+"}", this.pathChatServiceSid.toString()); - path = path.replace("{"+"ConversationSid"+"}", this.pathConversationSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -55,15 +65,23 @@ public Participant fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Participant fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Participant fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Participant.fromJson(response.getStream(), client.getObjectMapper()); + return Participant.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/conversation/ParticipantReader.java b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/ParticipantReader.java index 21127ef0dc..54e3abc006 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/service/conversation/ParticipantReader.java +++ b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/ParticipantReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.conversations.v1.service.conversation; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,21 +25,22 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class ParticipantReader extends Reader { + private String pathChatServiceSid; private String pathConversationSid; private Integer pageSize; - public ParticipantReader(final String pathChatServiceSid, final String pathConversationSid){ + public ParticipantReader( + final String pathChatServiceSid, + final String pathConversationSid + ) { this.pathChatServiceSid = pathChatServiceSid; this.pathConversationSid = pathConversationSid; } - public ParticipantReader setPageSize(final Integer pageSize){ + public ParticipantReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -49,9 +51,18 @@ public ResourceSet read(final TwilioRestClient client) { } public Page firstPage(final TwilioRestClient client) { - String path = "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Participants"; - path = path.replace("{"+"ChatServiceSid"+"}", this.pathChatServiceSid.toString()); - path = path.replace("{"+"ConversationSid"+"}", this.pathConversationSid.toString()); + String path = + "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Participants"; + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -63,13 +74,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Participant read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Participant read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -85,7 +104,10 @@ private Page pageForRequest(final TwilioRestClient client, final Re } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.CONVERSATIONS.toString()) @@ -93,9 +115,11 @@ public Page previousPage(final Page page, final Twilio return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.CONVERSATIONS.toString()) @@ -104,21 +128,21 @@ public Page nextPage(final Page page, final TwilioRest } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/conversation/ParticipantUpdater.java b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/ParticipantUpdater.java index 07cc480eb1..ddb87605b6 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/service/conversation/ParticipantUpdater.java +++ b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/ParticipantUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.conversations.v1.service.conversation; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -23,12 +24,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.time.ZonedDateTime; +public class ParticipantUpdater extends Updater { - -public class ParticipantUpdater extends Updater{ private String pathChatServiceSid; private String pathConversationSid; private String pathSid; @@ -43,123 +42,175 @@ public class ParticipantUpdater extends Updater{ private Integer lastReadMessageIndex; private String lastReadTimestamp; - public ParticipantUpdater(final String pathChatServiceSid, final String pathConversationSid, final String pathSid){ + public ParticipantUpdater( + final String pathChatServiceSid, + final String pathConversationSid, + final String pathSid + ) { this.pathChatServiceSid = pathChatServiceSid; this.pathConversationSid = pathConversationSid; this.pathSid = pathSid; } - public ParticipantUpdater setXTwilioWebhookEnabled(final Participant.WebhookEnabledType xTwilioWebhookEnabled){ + public ParticipantUpdater setXTwilioWebhookEnabled( + final Participant.WebhookEnabledType xTwilioWebhookEnabled + ) { this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; return this; } - public ParticipantUpdater setDateCreated(final ZonedDateTime dateCreated){ + + public ParticipantUpdater setDateCreated(final ZonedDateTime dateCreated) { this.dateCreated = dateCreated; return this; } - public ParticipantUpdater setDateUpdated(final ZonedDateTime dateUpdated){ + + public ParticipantUpdater setDateUpdated(final ZonedDateTime dateUpdated) { this.dateUpdated = dateUpdated; return this; } - public ParticipantUpdater setIdentity(final String identity){ + + public ParticipantUpdater setIdentity(final String identity) { this.identity = identity; return this; } - public ParticipantUpdater setAttributes(final String attributes){ + + public ParticipantUpdater setAttributes(final String attributes) { this.attributes = attributes; return this; } - public ParticipantUpdater setRoleSid(final String roleSid){ + + public ParticipantUpdater setRoleSid(final String roleSid) { this.roleSid = roleSid; return this; } - public ParticipantUpdater setMessagingBindingProxyAddress(final String messagingBindingProxyAddress){ + + public ParticipantUpdater setMessagingBindingProxyAddress( + final String messagingBindingProxyAddress + ) { this.messagingBindingProxyAddress = messagingBindingProxyAddress; return this; } - public ParticipantUpdater setMessagingBindingProjectedAddress(final String messagingBindingProjectedAddress){ - this.messagingBindingProjectedAddress = messagingBindingProjectedAddress; + + public ParticipantUpdater setMessagingBindingProjectedAddress( + final String messagingBindingProjectedAddress + ) { + this.messagingBindingProjectedAddress = + messagingBindingProjectedAddress; return this; } - public ParticipantUpdater setLastReadMessageIndex(final Integer lastReadMessageIndex){ + + public ParticipantUpdater setLastReadMessageIndex( + final Integer lastReadMessageIndex + ) { this.lastReadMessageIndex = lastReadMessageIndex; return this; } - public ParticipantUpdater setLastReadTimestamp(final String lastReadTimestamp){ + + public ParticipantUpdater setLastReadTimestamp( + final String lastReadTimestamp + ) { this.lastReadTimestamp = lastReadTimestamp; return this; } @Override - public Participant update(final TwilioRestClient client){ - String path = "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Participants/{Sid}"; + public Participant update(final TwilioRestClient client) { + String path = + "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Participants/{Sid}"; - path = path.replace("{"+"ChatServiceSid"+"}", this.pathChatServiceSid.toString()); - path = path.replace("{"+"ConversationSid"+"}", this.pathConversationSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.CONVERSATIONS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); addHeaderParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Participant update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Participant update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Participant.fromJson(response.getStream(), client.getObjectMapper()); + return Participant.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (dateCreated != null) { - request.addPostParam("DateCreated", dateCreated.toInstant().toString()); - + request.addPostParam( + "DateCreated", + dateCreated.toInstant().toString() + ); } if (dateUpdated != null) { - request.addPostParam("DateUpdated", dateUpdated.toInstant().toString()); - + request.addPostParam( + "DateUpdated", + dateUpdated.toInstant().toString() + ); } if (identity != null) { request.addPostParam("Identity", identity); - } if (attributes != null) { request.addPostParam("Attributes", attributes); - } if (roleSid != null) { request.addPostParam("RoleSid", roleSid); - } if (messagingBindingProxyAddress != null) { - request.addPostParam("MessagingBinding.ProxyAddress", messagingBindingProxyAddress); - + request.addPostParam( + "MessagingBinding.ProxyAddress", + messagingBindingProxyAddress + ); } if (messagingBindingProjectedAddress != null) { - request.addPostParam("MessagingBinding.ProjectedAddress", messagingBindingProjectedAddress); - + request.addPostParam( + "MessagingBinding.ProjectedAddress", + messagingBindingProjectedAddress + ); } if (lastReadMessageIndex != null) { - request.addPostParam("LastReadMessageIndex", lastReadMessageIndex.toString()); - + request.addPostParam( + "LastReadMessageIndex", + lastReadMessageIndex.toString() + ); } if (lastReadTimestamp != null) { request.addPostParam("LastReadTimestamp", lastReadTimestamp); - } } + private void addHeaderParams(final Request request) { if (xTwilioWebhookEnabled != null) { - request.addHeaderParam("X-Twilio-Webhook-Enabled", xTwilioWebhookEnabled.toString()); - + request.addHeaderParam( + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/conversation/Webhook.java b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/Webhook.java index 1dcc842f33..0984e2e4c6 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/service/conversation/Webhook.java +++ b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/Webhook.java @@ -24,55 +24,89 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Webhook extends Resource { + private static final long serialVersionUID = 228548505277204L; - public static WebhookCreator creator(final String pathChatServiceSid, final String pathConversationSid, final Webhook.Target target){ - return new WebhookCreator(pathChatServiceSid, pathConversationSid, target); + public static WebhookCreator creator( + final String pathChatServiceSid, + final String pathConversationSid, + final Webhook.Target target + ) { + return new WebhookCreator( + pathChatServiceSid, + pathConversationSid, + target + ); } - public static WebhookDeleter deleter(final String pathChatServiceSid, final String pathConversationSid, final String pathSid){ - return new WebhookDeleter(pathChatServiceSid, pathConversationSid, pathSid); + public static WebhookDeleter deleter( + final String pathChatServiceSid, + final String pathConversationSid, + final String pathSid + ) { + return new WebhookDeleter( + pathChatServiceSid, + pathConversationSid, + pathSid + ); } - public static WebhookFetcher fetcher(final String pathChatServiceSid, final String pathConversationSid, final String pathSid){ - return new WebhookFetcher(pathChatServiceSid, pathConversationSid, pathSid); + public static WebhookFetcher fetcher( + final String pathChatServiceSid, + final String pathConversationSid, + final String pathSid + ) { + return new WebhookFetcher( + pathChatServiceSid, + pathConversationSid, + pathSid + ); } - public static WebhookReader reader(final String pathChatServiceSid, final String pathConversationSid){ + public static WebhookReader reader( + final String pathChatServiceSid, + final String pathConversationSid + ) { return new WebhookReader(pathChatServiceSid, pathConversationSid); } - public static WebhookUpdater updater(final String pathChatServiceSid, final String pathConversationSid, final String pathSid){ - return new WebhookUpdater(pathChatServiceSid, pathConversationSid, pathSid); + public static WebhookUpdater updater( + final String pathChatServiceSid, + final String pathConversationSid, + final String pathSid + ) { + return new WebhookUpdater( + pathChatServiceSid, + pathConversationSid, + pathSid + ); } /** - * Converts a JSON String into a Webhook object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Webhook object represented by the provided JSON - */ - public static Webhook fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Webhook object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Webhook object represented by the provided JSON + */ + public static Webhook fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Webhook.class); @@ -84,14 +118,17 @@ public static Webhook fromJson(final String json, final ObjectMapper objectMappe } /** - * Converts a JSON InputStream into a Webhook object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Webhook object represented by the provided JSON - */ - public static Webhook fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Webhook object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Webhook object represented by the provided JSON + */ + public static Webhook fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Webhook.class); @@ -101,6 +138,7 @@ public static Webhook fromJson(final InputStream json, final ObjectMapper object throw new ApiConnectionException(e.getMessage(), e); } } + public enum Method { GET("GET"), POST("POST"); @@ -120,6 +158,7 @@ public static Method forValue(final String value) { return Promoter.enumFromString(value, Method.values()); } } + public enum Target { WEBHOOK("webhook"), TRIGGER("trigger"), @@ -153,32 +192,15 @@ public static Target forValue(final String value) { @JsonCreator private Webhook( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("chat_service_sid") - final String chatServiceSid, - - @JsonProperty("conversation_sid") - final String conversationSid, - - @JsonProperty("target") - final String target, - - @JsonProperty("url") - final URI url, - - @JsonProperty("configuration") - final Map configuration, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("chat_service_sid") final String chatServiceSid, + @JsonProperty("conversation_sid") final String conversationSid, + @JsonProperty("target") final String target, + @JsonProperty("url") final URI url, + @JsonProperty("configuration") final Map configuration, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated ) { this.sid = sid; this.accountSid = accountSid; @@ -191,37 +213,45 @@ private Webhook( this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getChatServiceSid() { - return this.chatServiceSid; - } - public final String getConversationSid() { - return this.conversationSid; - } - public final String getTarget() { - return this.target; - } - public final URI getUrl() { - return this.url; - } - public final Map getConfiguration() { - return this.configuration; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getChatServiceSid() { + return this.chatServiceSid; + } + + public final String getConversationSid() { + return this.conversationSid; + } + + public final String getTarget() { + return this.target; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getConfiguration() { + return this.configuration; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -231,13 +261,31 @@ public boolean equals(final Object o) { Webhook other = (Webhook) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(chatServiceSid, other.chatServiceSid) && Objects.equals(conversationSid, other.conversationSid) && Objects.equals(target, other.target) && Objects.equals(url, other.url) && Objects.equals(configuration, other.configuration) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(chatServiceSid, other.chatServiceSid) && + Objects.equals(conversationSid, other.conversationSid) && + Objects.equals(target, other.target) && + Objects.equals(url, other.url) && + Objects.equals(configuration, other.configuration) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, chatServiceSid, conversationSid, target, url, configuration, dateCreated, dateUpdated); + return Objects.hash( + sid, + accountSid, + chatServiceSid, + conversationSid, + target, + url, + configuration, + dateCreated, + dateUpdated + ); } - } - diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/conversation/WebhookCreator.java b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/WebhookCreator.java index e3d757fe08..5f8254ef53 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/service/conversation/WebhookCreator.java +++ b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/WebhookCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.conversations.v1.service.conversation; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -25,12 +26,10 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.util.List; - import java.util.List; +public class WebhookCreator extends Creator { - -public class WebhookCreator extends Creator{ private String pathChatServiceSid; private String pathConversationSid; private Webhook.Target target; @@ -41,66 +40,111 @@ public class WebhookCreator extends Creator{ private String configurationFlowSid; private Integer configurationReplayAfter; - public WebhookCreator(final String pathChatServiceSid, final String pathConversationSid, final Webhook.Target target) { + public WebhookCreator( + final String pathChatServiceSid, + final String pathConversationSid, + final Webhook.Target target + ) { this.pathChatServiceSid = pathChatServiceSid; this.pathConversationSid = pathConversationSid; this.target = target; } - public WebhookCreator setTarget(final Webhook.Target target){ + public WebhookCreator setTarget(final Webhook.Target target) { this.target = target; return this; } - public WebhookCreator setConfigurationUrl(final String configurationUrl){ + + public WebhookCreator setConfigurationUrl(final String configurationUrl) { this.configurationUrl = configurationUrl; return this; } - public WebhookCreator setConfigurationMethod(final Webhook.Method configurationMethod){ + + public WebhookCreator setConfigurationMethod( + final Webhook.Method configurationMethod + ) { this.configurationMethod = configurationMethod; return this; } - public WebhookCreator setConfigurationFilters(final List configurationFilters){ + + public WebhookCreator setConfigurationFilters( + final List configurationFilters + ) { this.configurationFilters = configurationFilters; return this; } - public WebhookCreator setConfigurationFilters(final String configurationFilters){ - return setConfigurationFilters(Promoter.listOfOne(configurationFilters)); + + public WebhookCreator setConfigurationFilters( + final String configurationFilters + ) { + return setConfigurationFilters( + Promoter.listOfOne(configurationFilters) + ); } - public WebhookCreator setConfigurationTriggers(final List configurationTriggers){ + + public WebhookCreator setConfigurationTriggers( + final List configurationTriggers + ) { this.configurationTriggers = configurationTriggers; return this; } - public WebhookCreator setConfigurationTriggers(final String configurationTriggers){ - return setConfigurationTriggers(Promoter.listOfOne(configurationTriggers)); + + public WebhookCreator setConfigurationTriggers( + final String configurationTriggers + ) { + return setConfigurationTriggers( + Promoter.listOfOne(configurationTriggers) + ); } - public WebhookCreator setConfigurationFlowSid(final String configurationFlowSid){ + + public WebhookCreator setConfigurationFlowSid( + final String configurationFlowSid + ) { this.configurationFlowSid = configurationFlowSid; return this; } - public WebhookCreator setConfigurationReplayAfter(final Integer configurationReplayAfter){ + + public WebhookCreator setConfigurationReplayAfter( + final Integer configurationReplayAfter + ) { this.configurationReplayAfter = configurationReplayAfter; return this; } @Override - public Webhook create(final TwilioRestClient client){ - String path = "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Webhooks"; + public Webhook create(final TwilioRestClient client) { + String path = + "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Webhooks"; - path = path.replace("{"+"ChatServiceSid"+"}", this.pathChatServiceSid.toString()); - path = path.replace("{"+"ConversationSid"+"}", this.pathConversationSid.toString()); - path = path.replace("{"+"Target"+"}", this.target.toString()); + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + path = path.replace("{" + "Target" + "}", this.target.toString()); Request request = new Request( HttpMethod.POST, Domains.CONVERSATIONS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Webhook creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Webhook creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -109,38 +153,38 @@ public Webhook create(final TwilioRestClient client){ return Webhook.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (target != null) { request.addPostParam("Target", target.toString()); - } if (configurationUrl != null) { request.addPostParam("Configuration.Url", configurationUrl); - } if (configurationMethod != null) { - request.addPostParam("Configuration.Method", configurationMethod.toString()); - + request.addPostParam( + "Configuration.Method", + configurationMethod.toString() + ); } if (configurationFilters != null) { for (String prop : configurationFilters) { request.addPostParam("Configuration.Filters", prop); } - } if (configurationTriggers != null) { for (String prop : configurationTriggers) { request.addPostParam("Configuration.Triggers", prop); } - } if (configurationFlowSid != null) { request.addPostParam("Configuration.FlowSid", configurationFlowSid); - } if (configurationReplayAfter != null) { - request.addPostParam("Configuration.ReplayAfter", configurationReplayAfter.toString()); - + request.addPostParam( + "Configuration.ReplayAfter", + configurationReplayAfter.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/conversation/WebhookDeleter.java b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/WebhookDeleter.java index 909b29956c..2f1ed556bc 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/service/conversation/WebhookDeleter.java +++ b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/WebhookDeleter.java @@ -24,27 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class WebhookDeleter extends Deleter { + private String pathChatServiceSid; private String pathConversationSid; private String pathSid; - public WebhookDeleter(final String pathChatServiceSid, final String pathConversationSid, final String pathSid){ + public WebhookDeleter( + final String pathChatServiceSid, + final String pathConversationSid, + final String pathSid + ) { this.pathChatServiceSid = pathChatServiceSid; this.pathConversationSid = pathConversationSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Webhooks/{Sid}"; + String path = + "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Webhooks/{Sid}"; - path = path.replace("{"+"ChatServiceSid"+"}", this.pathChatServiceSid.toString()); - path = path.replace("{"+"ConversationSid"+"}", this.pathConversationSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -54,9 +65,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Webhook delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Webhook delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/conversation/WebhookFetcher.java b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/WebhookFetcher.java index 2286c7857c..8a9b510957 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/service/conversation/WebhookFetcher.java +++ b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/WebhookFetcher.java @@ -24,28 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class WebhookFetcher extends Fetcher { + private String pathChatServiceSid; private String pathConversationSid; private String pathSid; - public WebhookFetcher(final String pathChatServiceSid, final String pathConversationSid, final String pathSid){ + public WebhookFetcher( + final String pathChatServiceSid, + final String pathConversationSid, + final String pathSid + ) { this.pathChatServiceSid = pathChatServiceSid; this.pathConversationSid = pathConversationSid; this.pathSid = pathSid; } - @Override public Webhook fetch(final TwilioRestClient client) { - String path = "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Webhooks/{Sid}"; + String path = + "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Webhooks/{Sid}"; - path = path.replace("{"+"ChatServiceSid"+"}", this.pathChatServiceSid.toString()); - path = path.replace("{"+"ConversationSid"+"}", this.pathConversationSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -55,9 +65,14 @@ public Webhook fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Webhook fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Webhook fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/conversation/WebhookReader.java b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/WebhookReader.java index 469c7b4269..8b66a53600 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/service/conversation/WebhookReader.java +++ b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/WebhookReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.conversations.v1.service.conversation; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,21 +25,22 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class WebhookReader extends Reader { + private String pathChatServiceSid; private String pathConversationSid; private Integer pageSize; - public WebhookReader(final String pathChatServiceSid, final String pathConversationSid){ + public WebhookReader( + final String pathChatServiceSid, + final String pathConversationSid + ) { this.pathChatServiceSid = pathChatServiceSid; this.pathConversationSid = pathConversationSid; } - public WebhookReader setPageSize(final Integer pageSize){ + public WebhookReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -49,9 +51,18 @@ public ResourceSet read(final TwilioRestClient client) { } public Page firstPage(final TwilioRestClient client) { - String path = "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Webhooks"; - path = path.replace("{"+"ChatServiceSid"+"}", this.pathChatServiceSid.toString()); - path = path.replace("{"+"ConversationSid"+"}", this.pathConversationSid.toString()); + String path = + "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Webhooks"; + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -63,13 +74,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Webhook read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Webhook read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -85,7 +104,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reques } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.CONVERSATIONS.toString()) @@ -93,9 +115,11 @@ public Page previousPage(final Page page, final TwilioRestClie return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.CONVERSATIONS.toString()) @@ -104,21 +128,21 @@ public Page nextPage(final Page page, final TwilioRestClient c } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/conversation/WebhookUpdater.java b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/WebhookUpdater.java index 8f8b97b256..ba99211c66 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/service/conversation/WebhookUpdater.java +++ b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/WebhookUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.conversations.v1.service.conversation; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -24,12 +25,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - import java.util.List; +public class WebhookUpdater extends Updater { -public class WebhookUpdater extends Updater{ private String pathChatServiceSid; private String pathConversationSid; private String pathSid; @@ -39,58 +38,99 @@ public class WebhookUpdater extends Updater{ private List configurationTriggers; private String configurationFlowSid; - public WebhookUpdater(final String pathChatServiceSid, final String pathConversationSid, final String pathSid){ + public WebhookUpdater( + final String pathChatServiceSid, + final String pathConversationSid, + final String pathSid + ) { this.pathChatServiceSid = pathChatServiceSid; this.pathConversationSid = pathConversationSid; this.pathSid = pathSid; } - public WebhookUpdater setConfigurationUrl(final String configurationUrl){ + public WebhookUpdater setConfigurationUrl(final String configurationUrl) { this.configurationUrl = configurationUrl; return this; } - public WebhookUpdater setConfigurationMethod(final Webhook.Method configurationMethod){ + + public WebhookUpdater setConfigurationMethod( + final Webhook.Method configurationMethod + ) { this.configurationMethod = configurationMethod; return this; } - public WebhookUpdater setConfigurationFilters(final List configurationFilters){ + + public WebhookUpdater setConfigurationFilters( + final List configurationFilters + ) { this.configurationFilters = configurationFilters; return this; } - public WebhookUpdater setConfigurationFilters(final String configurationFilters){ - return setConfigurationFilters(Promoter.listOfOne(configurationFilters)); + + public WebhookUpdater setConfigurationFilters( + final String configurationFilters + ) { + return setConfigurationFilters( + Promoter.listOfOne(configurationFilters) + ); } - public WebhookUpdater setConfigurationTriggers(final List configurationTriggers){ + + public WebhookUpdater setConfigurationTriggers( + final List configurationTriggers + ) { this.configurationTriggers = configurationTriggers; return this; } - public WebhookUpdater setConfigurationTriggers(final String configurationTriggers){ - return setConfigurationTriggers(Promoter.listOfOne(configurationTriggers)); + + public WebhookUpdater setConfigurationTriggers( + final String configurationTriggers + ) { + return setConfigurationTriggers( + Promoter.listOfOne(configurationTriggers) + ); } - public WebhookUpdater setConfigurationFlowSid(final String configurationFlowSid){ + + public WebhookUpdater setConfigurationFlowSid( + final String configurationFlowSid + ) { this.configurationFlowSid = configurationFlowSid; return this; } @Override - public Webhook update(final TwilioRestClient client){ - String path = "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Webhooks/{Sid}"; + public Webhook update(final TwilioRestClient client) { + String path = + "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Webhooks/{Sid}"; - path = path.replace("{"+"ChatServiceSid"+"}", this.pathChatServiceSid.toString()); - path = path.replace("{"+"ConversationSid"+"}", this.pathConversationSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.CONVERSATIONS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Webhook update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Webhook update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -99,30 +139,29 @@ public Webhook update(final TwilioRestClient client){ return Webhook.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (configurationUrl != null) { request.addPostParam("Configuration.Url", configurationUrl); - } if (configurationMethod != null) { - request.addPostParam("Configuration.Method", configurationMethod.toString()); - + request.addPostParam( + "Configuration.Method", + configurationMethod.toString() + ); } if (configurationFilters != null) { for (String prop : configurationFilters) { request.addPostParam("Configuration.Filters", prop); } - } if (configurationTriggers != null) { for (String prop : configurationTriggers) { request.addPostParam("Configuration.Triggers", prop); } - } if (configurationFlowSid != null) { request.addPostParam("Configuration.FlowSid", configurationFlowSid); - } } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/conversation/message/DeliveryReceipt.java b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/message/DeliveryReceipt.java index 440f8b0827..890677bc98 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/service/conversation/message/DeliveryReceipt.java +++ b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/message/DeliveryReceipt.java @@ -24,41 +24,58 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class DeliveryReceipt extends Resource { + private static final long serialVersionUID = 201260516970011L; - public static DeliveryReceiptFetcher fetcher(final String pathChatServiceSid, final String pathConversationSid, final String pathMessageSid, final String pathSid){ - return new DeliveryReceiptFetcher(pathChatServiceSid, pathConversationSid, pathMessageSid, pathSid); + public static DeliveryReceiptFetcher fetcher( + final String pathChatServiceSid, + final String pathConversationSid, + final String pathMessageSid, + final String pathSid + ) { + return new DeliveryReceiptFetcher( + pathChatServiceSid, + pathConversationSid, + pathMessageSid, + pathSid + ); } - public static DeliveryReceiptReader reader(final String pathChatServiceSid, final String pathConversationSid, final String pathMessageSid){ - return new DeliveryReceiptReader(pathChatServiceSid, pathConversationSid, pathMessageSid); + public static DeliveryReceiptReader reader( + final String pathChatServiceSid, + final String pathConversationSid, + final String pathMessageSid + ) { + return new DeliveryReceiptReader( + pathChatServiceSid, + pathConversationSid, + pathMessageSid + ); } /** - * Converts a JSON String into a DeliveryReceipt object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return DeliveryReceipt object represented by the provided JSON - */ - public static DeliveryReceipt fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a DeliveryReceipt object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return DeliveryReceipt object represented by the provided JSON + */ + public static DeliveryReceipt fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, DeliveryReceipt.class); @@ -70,14 +87,17 @@ public static DeliveryReceipt fromJson(final String json, final ObjectMapper obj } /** - * Converts a JSON InputStream into a DeliveryReceipt object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return DeliveryReceipt object represented by the provided JSON - */ - public static DeliveryReceipt fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a DeliveryReceipt object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return DeliveryReceipt object represented by the provided JSON + */ + public static DeliveryReceipt fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, DeliveryReceipt.class); @@ -87,6 +107,7 @@ public static DeliveryReceipt fromJson(final InputStream json, final ObjectMappe throw new ApiConnectionException(e.getMessage(), e); } } + public enum DeliveryStatus { READ("read"), FAILED("failed"), @@ -125,41 +146,18 @@ public static DeliveryStatus forValue(final String value) { @JsonCreator private DeliveryReceipt( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("chat_service_sid") - final String chatServiceSid, - - @JsonProperty("conversation_sid") - final String conversationSid, - - @JsonProperty("message_sid") - final String messageSid, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("channel_message_sid") - final String channelMessageSid, - - @JsonProperty("participant_sid") - final String participantSid, - - @JsonProperty("status") - final DeliveryReceipt.DeliveryStatus status, - - @JsonProperty("error_code") - final Integer errorCode, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("chat_service_sid") final String chatServiceSid, + @JsonProperty("conversation_sid") final String conversationSid, + @JsonProperty("message_sid") final String messageSid, + @JsonProperty("sid") final String sid, + @JsonProperty("channel_message_sid") final String channelMessageSid, + @JsonProperty("participant_sid") final String participantSid, + @JsonProperty("status") final DeliveryReceipt.DeliveryStatus status, + @JsonProperty("error_code") final Integer errorCode, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url ) { this.accountSid = accountSid; this.chatServiceSid = chatServiceSid; @@ -175,46 +173,57 @@ private DeliveryReceipt( this.url = url; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getChatServiceSid() { - return this.chatServiceSid; - } - public final String getConversationSid() { - return this.conversationSid; - } - public final String getMessageSid() { - return this.messageSid; - } - public final String getSid() { - return this.sid; - } - public final String getChannelMessageSid() { - return this.channelMessageSid; - } - public final String getParticipantSid() { - return this.participantSid; - } - public final DeliveryReceipt.DeliveryStatus getStatus() { - return this.status; - } - public final Integer getErrorCode() { - return this.errorCode; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getChatServiceSid() { + return this.chatServiceSid; + } + + public final String getConversationSid() { + return this.conversationSid; + } + + public final String getMessageSid() { + return this.messageSid; + } + + public final String getSid() { + return this.sid; + } + + public final String getChannelMessageSid() { + return this.channelMessageSid; + } + + public final String getParticipantSid() { + return this.participantSid; + } + + public final DeliveryReceipt.DeliveryStatus getStatus() { + return this.status; + } + + public final Integer getErrorCode() { + return this.errorCode; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -224,13 +233,37 @@ public boolean equals(final Object o) { DeliveryReceipt other = (DeliveryReceipt) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(chatServiceSid, other.chatServiceSid) && Objects.equals(conversationSid, other.conversationSid) && Objects.equals(messageSid, other.messageSid) && Objects.equals(sid, other.sid) && Objects.equals(channelMessageSid, other.channelMessageSid) && Objects.equals(participantSid, other.participantSid) && Objects.equals(status, other.status) && Objects.equals(errorCode, other.errorCode) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(chatServiceSid, other.chatServiceSid) && + Objects.equals(conversationSid, other.conversationSid) && + Objects.equals(messageSid, other.messageSid) && + Objects.equals(sid, other.sid) && + Objects.equals(channelMessageSid, other.channelMessageSid) && + Objects.equals(participantSid, other.participantSid) && + Objects.equals(status, other.status) && + Objects.equals(errorCode, other.errorCode) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, chatServiceSid, conversationSid, messageSid, sid, channelMessageSid, participantSid, status, errorCode, dateCreated, dateUpdated, url); + return Objects.hash( + accountSid, + chatServiceSid, + conversationSid, + messageSid, + sid, + channelMessageSid, + participantSid, + status, + errorCode, + dateCreated, + dateUpdated, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/conversation/message/DeliveryReceiptFetcher.java b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/message/DeliveryReceiptFetcher.java index 7b49e98391..413377a8b0 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/service/conversation/message/DeliveryReceiptFetcher.java +++ b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/message/DeliveryReceiptFetcher.java @@ -24,31 +24,46 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class DeliveryReceiptFetcher extends Fetcher { + private String pathChatServiceSid; private String pathConversationSid; private String pathMessageSid; private String pathSid; - public DeliveryReceiptFetcher(final String pathChatServiceSid, final String pathConversationSid, final String pathMessageSid, final String pathSid){ + public DeliveryReceiptFetcher( + final String pathChatServiceSid, + final String pathConversationSid, + final String pathMessageSid, + final String pathSid + ) { this.pathChatServiceSid = pathChatServiceSid; this.pathConversationSid = pathConversationSid; this.pathMessageSid = pathMessageSid; this.pathSid = pathSid; } - @Override public DeliveryReceipt fetch(final TwilioRestClient client) { - String path = "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Messages/{MessageSid}/Receipts/{Sid}"; + String path = + "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Messages/{MessageSid}/Receipts/{Sid}"; - path = path.replace("{"+"ChatServiceSid"+"}", this.pathChatServiceSid.toString()); - path = path.replace("{"+"ConversationSid"+"}", this.pathConversationSid.toString()); - path = path.replace("{"+"MessageSid"+"}", this.pathMessageSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + path = + path.replace( + "{" + "MessageSid" + "}", + this.pathMessageSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -58,15 +73,23 @@ public DeliveryReceipt fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("DeliveryReceipt fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "DeliveryReceipt fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return DeliveryReceipt.fromJson(response.getStream(), client.getObjectMapper()); + return DeliveryReceipt.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/conversation/message/DeliveryReceiptReader.java b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/message/DeliveryReceiptReader.java index 289e6aa1a3..d3ad2caab0 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/service/conversation/message/DeliveryReceiptReader.java +++ b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/message/DeliveryReceiptReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.conversations.v1.service.conversation.message; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,23 +25,25 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class DeliveryReceiptReader extends Reader { + private String pathChatServiceSid; private String pathConversationSid; private String pathMessageSid; private Integer pageSize; - public DeliveryReceiptReader(final String pathChatServiceSid, final String pathConversationSid, final String pathMessageSid){ + public DeliveryReceiptReader( + final String pathChatServiceSid, + final String pathConversationSid, + final String pathMessageSid + ) { this.pathChatServiceSid = pathChatServiceSid; this.pathConversationSid = pathConversationSid; this.pathMessageSid = pathMessageSid; } - public DeliveryReceiptReader setPageSize(final Integer pageSize){ + public DeliveryReceiptReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -51,10 +54,23 @@ public ResourceSet read(final TwilioRestClient client) { } public Page firstPage(final TwilioRestClient client) { - String path = "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Messages/{MessageSid}/Receipts"; - path = path.replace("{"+"ChatServiceSid"+"}", this.pathChatServiceSid.toString()); - path = path.replace("{"+"ConversationSid"+"}", this.pathConversationSid.toString()); - path = path.replace("{"+"MessageSid"+"}", this.pathMessageSid.toString()); + String path = + "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Messages/{MessageSid}/Receipts"; + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + path = + path.replace( + "{" + "MessageSid" + "}", + this.pathMessageSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -66,13 +82,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("DeliveryReceipt read failed: Unable to connect to server"); + throw new ApiConnectionException( + "DeliveryReceipt read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -88,7 +112,10 @@ private Page pageForRequest(final TwilioRestClient client, fina } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.CONVERSATIONS.toString()) @@ -96,9 +123,11 @@ public Page previousPage(final Page page, fina return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.CONVERSATIONS.toString()) @@ -107,21 +136,21 @@ public Page nextPage(final Page page, final Tw } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/user/UserConversation.java b/src/main/java/com/twilio/rest/conversations/v1/service/user/UserConversation.java index 68de7643af..4e71c2947d 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/service/user/UserConversation.java +++ b/src/main/java/com/twilio/rest/conversations/v1/service/user/UserConversation.java @@ -24,51 +24,77 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class UserConversation extends Resource { + private static final long serialVersionUID = 269317644556189L; - public static UserConversationDeleter deleter(final String pathChatServiceSid, final String pathUserSid, final String pathConversationSid){ - return new UserConversationDeleter(pathChatServiceSid, pathUserSid, pathConversationSid); + public static UserConversationDeleter deleter( + final String pathChatServiceSid, + final String pathUserSid, + final String pathConversationSid + ) { + return new UserConversationDeleter( + pathChatServiceSid, + pathUserSid, + pathConversationSid + ); } - public static UserConversationFetcher fetcher(final String pathChatServiceSid, final String pathUserSid, final String pathConversationSid){ - return new UserConversationFetcher(pathChatServiceSid, pathUserSid, pathConversationSid); + public static UserConversationFetcher fetcher( + final String pathChatServiceSid, + final String pathUserSid, + final String pathConversationSid + ) { + return new UserConversationFetcher( + pathChatServiceSid, + pathUserSid, + pathConversationSid + ); } - public static UserConversationReader reader(final String pathChatServiceSid, final String pathUserSid){ + public static UserConversationReader reader( + final String pathChatServiceSid, + final String pathUserSid + ) { return new UserConversationReader(pathChatServiceSid, pathUserSid); } - public static UserConversationUpdater updater(final String pathChatServiceSid, final String pathUserSid, final String pathConversationSid){ - return new UserConversationUpdater(pathChatServiceSid, pathUserSid, pathConversationSid); + public static UserConversationUpdater updater( + final String pathChatServiceSid, + final String pathUserSid, + final String pathConversationSid + ) { + return new UserConversationUpdater( + pathChatServiceSid, + pathUserSid, + pathConversationSid + ); } /** - * Converts a JSON String into a UserConversation object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return UserConversation object represented by the provided JSON - */ - public static UserConversation fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a UserConversation object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return UserConversation object represented by the provided JSON + */ + public static UserConversation fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, UserConversation.class); @@ -80,14 +106,17 @@ public static UserConversation fromJson(final String json, final ObjectMapper ob } /** - * Converts a JSON InputStream into a UserConversation object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return UserConversation object represented by the provided JSON - */ - public static UserConversation fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a UserConversation object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return UserConversation object represented by the provided JSON + */ + public static UserConversation fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, UserConversation.class); @@ -97,6 +126,7 @@ public static UserConversation fromJson(final InputStream json, final ObjectMapp throw new ApiConnectionException(e.getMessage(), e); } } + public enum NotificationLevel { DEFAULT("default"), MUTED("muted"); @@ -116,6 +146,7 @@ public static NotificationLevel forValue(final String value) { return Promoter.enumFromString(value, NotificationLevel.values()); } } + public enum State { INACTIVE("inactive"), ACTIVE("active"), @@ -158,59 +189,32 @@ public static State forValue(final String value) { @JsonCreator private UserConversation( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("chat_service_sid") - final String chatServiceSid, - - @JsonProperty("conversation_sid") - final String conversationSid, - - @JsonProperty("unread_messages_count") - final Integer unreadMessagesCount, - - @JsonProperty("last_read_message_index") - final Integer lastReadMessageIndex, - - @JsonProperty("participant_sid") - final String participantSid, - - @JsonProperty("user_sid") - final String userSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("conversation_state") - final UserConversation.State conversationState, - - @JsonProperty("timers") - final Map timers, - - @JsonProperty("attributes") - final String attributes, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("created_by") - final String createdBy, - - @JsonProperty("notification_level") - final UserConversation.NotificationLevel notificationLevel, - - @JsonProperty("unique_name") - final String uniqueName, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("chat_service_sid") final String chatServiceSid, + @JsonProperty("conversation_sid") final String conversationSid, + @JsonProperty( + "unread_messages_count" + ) final Integer unreadMessagesCount, + @JsonProperty( + "last_read_message_index" + ) final Integer lastReadMessageIndex, + @JsonProperty("participant_sid") final String participantSid, + @JsonProperty("user_sid") final String userSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty( + "conversation_state" + ) final UserConversation.State conversationState, + @JsonProperty("timers") final Map timers, + @JsonProperty("attributes") final String attributes, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("created_by") final String createdBy, + @JsonProperty( + "notification_level" + ) final UserConversation.NotificationLevel notificationLevel, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.accountSid = accountSid; this.chatServiceSid = chatServiceSid; @@ -232,64 +236,81 @@ private UserConversation( this.links = links; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getChatServiceSid() { - return this.chatServiceSid; - } - public final String getConversationSid() { - return this.conversationSid; - } - public final Integer getUnreadMessagesCount() { - return this.unreadMessagesCount; - } - public final Integer getLastReadMessageIndex() { - return this.lastReadMessageIndex; - } - public final String getParticipantSid() { - return this.participantSid; - } - public final String getUserSid() { - return this.userSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final UserConversation.State getConversationState() { - return this.conversationState; - } - public final Map getTimers() { - return this.timers; - } - public final String getAttributes() { - return this.attributes; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getCreatedBy() { - return this.createdBy; - } - public final UserConversation.NotificationLevel getNotificationLevel() { - return this.notificationLevel; - } - public final String getUniqueName() { - return this.uniqueName; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getChatServiceSid() { + return this.chatServiceSid; + } + + public final String getConversationSid() { + return this.conversationSid; + } + + public final Integer getUnreadMessagesCount() { + return this.unreadMessagesCount; + } + + public final Integer getLastReadMessageIndex() { + return this.lastReadMessageIndex; + } + + public final String getParticipantSid() { + return this.participantSid; + } + + public final String getUserSid() { + return this.userSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final UserConversation.State getConversationState() { + return this.conversationState; + } + + public final Map getTimers() { + return this.timers; + } + + public final String getAttributes() { + return this.attributes; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getCreatedBy() { + return this.createdBy; + } + + public final UserConversation.NotificationLevel getNotificationLevel() { + return this.notificationLevel; + } + + public final String getUniqueName() { + return this.uniqueName; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -299,13 +320,49 @@ public boolean equals(final Object o) { UserConversation other = (UserConversation) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(chatServiceSid, other.chatServiceSid) && Objects.equals(conversationSid, other.conversationSid) && Objects.equals(unreadMessagesCount, other.unreadMessagesCount) && Objects.equals(lastReadMessageIndex, other.lastReadMessageIndex) && Objects.equals(participantSid, other.participantSid) && Objects.equals(userSid, other.userSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(conversationState, other.conversationState) && Objects.equals(timers, other.timers) && Objects.equals(attributes, other.attributes) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(createdBy, other.createdBy) && Objects.equals(notificationLevel, other.notificationLevel) && Objects.equals(uniqueName, other.uniqueName) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(chatServiceSid, other.chatServiceSid) && + Objects.equals(conversationSid, other.conversationSid) && + Objects.equals(unreadMessagesCount, other.unreadMessagesCount) && + Objects.equals(lastReadMessageIndex, other.lastReadMessageIndex) && + Objects.equals(participantSid, other.participantSid) && + Objects.equals(userSid, other.userSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(conversationState, other.conversationState) && + Objects.equals(timers, other.timers) && + Objects.equals(attributes, other.attributes) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(createdBy, other.createdBy) && + Objects.equals(notificationLevel, other.notificationLevel) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, chatServiceSid, conversationSid, unreadMessagesCount, lastReadMessageIndex, participantSid, userSid, friendlyName, conversationState, timers, attributes, dateCreated, dateUpdated, createdBy, notificationLevel, uniqueName, url, links); + return Objects.hash( + accountSid, + chatServiceSid, + conversationSid, + unreadMessagesCount, + lastReadMessageIndex, + participantSid, + userSid, + friendlyName, + conversationState, + timers, + attributes, + dateCreated, + dateUpdated, + createdBy, + notificationLevel, + uniqueName, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/user/UserConversationDeleter.java b/src/main/java/com/twilio/rest/conversations/v1/service/user/UserConversationDeleter.java index e36daad949..3a2831d35a 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/service/user/UserConversationDeleter.java +++ b/src/main/java/com/twilio/rest/conversations/v1/service/user/UserConversationDeleter.java @@ -24,27 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class UserConversationDeleter extends Deleter { + private String pathChatServiceSid; private String pathUserSid; private String pathConversationSid; - public UserConversationDeleter(final String pathChatServiceSid, final String pathUserSid, final String pathConversationSid){ + public UserConversationDeleter( + final String pathChatServiceSid, + final String pathUserSid, + final String pathConversationSid + ) { this.pathChatServiceSid = pathChatServiceSid; this.pathUserSid = pathUserSid; this.pathConversationSid = pathConversationSid; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/v1/Services/{ChatServiceSid}/Users/{UserSid}/Conversations/{ConversationSid}"; + String path = + "/v1/Services/{ChatServiceSid}/Users/{UserSid}/Conversations/{ConversationSid}"; - path = path.replace("{"+"ChatServiceSid"+"}", this.pathChatServiceSid.toString()); - path = path.replace("{"+"UserSid"+"}", this.pathUserSid.toString()); - path = path.replace("{"+"ConversationSid"+"}", this.pathConversationSid.toString()); + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = path.replace("{" + "UserSid" + "}", this.pathUserSid.toString()); + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); Request request = new Request( HttpMethod.DELETE, @@ -54,9 +65,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("UserConversation delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "UserConversation delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/user/UserConversationFetcher.java b/src/main/java/com/twilio/rest/conversations/v1/service/user/UserConversationFetcher.java index c41210f309..12974ea025 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/service/user/UserConversationFetcher.java +++ b/src/main/java/com/twilio/rest/conversations/v1/service/user/UserConversationFetcher.java @@ -24,28 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class UserConversationFetcher extends Fetcher { + private String pathChatServiceSid; private String pathUserSid; private String pathConversationSid; - public UserConversationFetcher(final String pathChatServiceSid, final String pathUserSid, final String pathConversationSid){ + public UserConversationFetcher( + final String pathChatServiceSid, + final String pathUserSid, + final String pathConversationSid + ) { this.pathChatServiceSid = pathChatServiceSid; this.pathUserSid = pathUserSid; this.pathConversationSid = pathConversationSid; } - @Override public UserConversation fetch(final TwilioRestClient client) { - String path = "/v1/Services/{ChatServiceSid}/Users/{UserSid}/Conversations/{ConversationSid}"; + String path = + "/v1/Services/{ChatServiceSid}/Users/{UserSid}/Conversations/{ConversationSid}"; - path = path.replace("{"+"ChatServiceSid"+"}", this.pathChatServiceSid.toString()); - path = path.replace("{"+"UserSid"+"}", this.pathUserSid.toString()); - path = path.replace("{"+"ConversationSid"+"}", this.pathConversationSid.toString()); + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = path.replace("{" + "UserSid" + "}", this.pathUserSid.toString()); + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -55,15 +65,23 @@ public UserConversation fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("UserConversation fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "UserConversation fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return UserConversation.fromJson(response.getStream(), client.getObjectMapper()); + return UserConversation.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/user/UserConversationReader.java b/src/main/java/com/twilio/rest/conversations/v1/service/user/UserConversationReader.java index 4acb904ccd..008efffc4a 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/service/user/UserConversationReader.java +++ b/src/main/java/com/twilio/rest/conversations/v1/service/user/UserConversationReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.conversations.v1.service.user; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,21 +25,22 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class UserConversationReader extends Reader { + private String pathChatServiceSid; private String pathUserSid; private Integer pageSize; - public UserConversationReader(final String pathChatServiceSid, final String pathUserSid){ + public UserConversationReader( + final String pathChatServiceSid, + final String pathUserSid + ) { this.pathChatServiceSid = pathChatServiceSid; this.pathUserSid = pathUserSid; } - public UserConversationReader setPageSize(final Integer pageSize){ + public UserConversationReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -49,9 +51,14 @@ public ResourceSet read(final TwilioRestClient client) { } public Page firstPage(final TwilioRestClient client) { - String path = "/v1/Services/{ChatServiceSid}/Users/{UserSid}/Conversations"; - path = path.replace("{"+"ChatServiceSid"+"}", this.pathChatServiceSid.toString()); - path = path.replace("{"+"UserSid"+"}", this.pathUserSid.toString()); + String path = + "/v1/Services/{ChatServiceSid}/Users/{UserSid}/Conversations"; + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = path.replace("{" + "UserSid" + "}", this.pathUserSid.toString()); Request request = new Request( HttpMethod.GET, @@ -63,13 +70,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("UserConversation read failed: Unable to connect to server"); + throw new ApiConnectionException( + "UserConversation read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -85,7 +100,10 @@ private Page pageForRequest(final TwilioRestClient client, fin } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.CONVERSATIONS.toString()) @@ -93,9 +111,11 @@ public Page previousPage(final Page page, fi return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.CONVERSATIONS.toString()) @@ -104,21 +124,21 @@ public Page nextPage(final Page page, final } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/user/UserConversationUpdater.java b/src/main/java/com/twilio/rest/conversations/v1/service/user/UserConversationUpdater.java index accc0cee81..9a1b85cd87 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/service/user/UserConversationUpdater.java +++ b/src/main/java/com/twilio/rest/conversations/v1/service/user/UserConversationUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.conversations.v1.service.user; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -23,12 +24,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.time.ZonedDateTime; +public class UserConversationUpdater extends Updater { - -public class UserConversationUpdater extends Updater{ private String pathChatServiceSid; private String pathUserSid; private String pathConversationSid; @@ -36,64 +35,101 @@ public class UserConversationUpdater extends Updater{ private ZonedDateTime lastReadTimestamp; private Integer lastReadMessageIndex; - public UserConversationUpdater(final String pathChatServiceSid, final String pathUserSid, final String pathConversationSid){ + public UserConversationUpdater( + final String pathChatServiceSid, + final String pathUserSid, + final String pathConversationSid + ) { this.pathChatServiceSid = pathChatServiceSid; this.pathUserSid = pathUserSid; this.pathConversationSid = pathConversationSid; } - public UserConversationUpdater setNotificationLevel(final UserConversation.NotificationLevel notificationLevel){ + public UserConversationUpdater setNotificationLevel( + final UserConversation.NotificationLevel notificationLevel + ) { this.notificationLevel = notificationLevel; return this; } - public UserConversationUpdater setLastReadTimestamp(final ZonedDateTime lastReadTimestamp){ + + public UserConversationUpdater setLastReadTimestamp( + final ZonedDateTime lastReadTimestamp + ) { this.lastReadTimestamp = lastReadTimestamp; return this; } - public UserConversationUpdater setLastReadMessageIndex(final Integer lastReadMessageIndex){ + + public UserConversationUpdater setLastReadMessageIndex( + final Integer lastReadMessageIndex + ) { this.lastReadMessageIndex = lastReadMessageIndex; return this; } @Override - public UserConversation update(final TwilioRestClient client){ - String path = "/v1/Services/{ChatServiceSid}/Users/{UserSid}/Conversations/{ConversationSid}"; + public UserConversation update(final TwilioRestClient client) { + String path = + "/v1/Services/{ChatServiceSid}/Users/{UserSid}/Conversations/{ConversationSid}"; - path = path.replace("{"+"ChatServiceSid"+"}", this.pathChatServiceSid.toString()); - path = path.replace("{"+"UserSid"+"}", this.pathUserSid.toString()); - path = path.replace("{"+"ConversationSid"+"}", this.pathConversationSid.toString()); + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = path.replace("{" + "UserSid" + "}", this.pathUserSid.toString()); + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.CONVERSATIONS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("UserConversation update failed: Unable to connect to server"); + throw new ApiConnectionException( + "UserConversation update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return UserConversation.fromJson(response.getStream(), client.getObjectMapper()); + return UserConversation.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (notificationLevel != null) { - request.addPostParam("NotificationLevel", notificationLevel.toString()); - + request.addPostParam( + "NotificationLevel", + notificationLevel.toString() + ); } if (lastReadTimestamp != null) { - request.addPostParam("LastReadTimestamp", lastReadTimestamp.toInstant().toString()); - + request.addPostParam( + "LastReadTimestamp", + lastReadTimestamp.toInstant().toString() + ); } if (lastReadMessageIndex != null) { - request.addPostParam("LastReadMessageIndex", lastReadMessageIndex.toString()); - + request.addPostParam( + "LastReadMessageIndex", + lastReadMessageIndex.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/user/UserConversation.java b/src/main/java/com/twilio/rest/conversations/v1/user/UserConversation.java index 744cadbe34..5b3e13292c 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/user/UserConversation.java +++ b/src/main/java/com/twilio/rest/conversations/v1/user/UserConversation.java @@ -24,51 +24,59 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class UserConversation extends Resource { + private static final long serialVersionUID = 269317644556189L; - public static UserConversationDeleter deleter(final String pathUserSid, final String pathConversationSid){ + public static UserConversationDeleter deleter( + final String pathUserSid, + final String pathConversationSid + ) { return new UserConversationDeleter(pathUserSid, pathConversationSid); } - public static UserConversationFetcher fetcher(final String pathUserSid, final String pathConversationSid){ + public static UserConversationFetcher fetcher( + final String pathUserSid, + final String pathConversationSid + ) { return new UserConversationFetcher(pathUserSid, pathConversationSid); } - public static UserConversationReader reader(final String pathUserSid){ + public static UserConversationReader reader(final String pathUserSid) { return new UserConversationReader(pathUserSid); } - public static UserConversationUpdater updater(final String pathUserSid, final String pathConversationSid){ + public static UserConversationUpdater updater( + final String pathUserSid, + final String pathConversationSid + ) { return new UserConversationUpdater(pathUserSid, pathConversationSid); } /** - * Converts a JSON String into a UserConversation object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return UserConversation object represented by the provided JSON - */ - public static UserConversation fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a UserConversation object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return UserConversation object represented by the provided JSON + */ + public static UserConversation fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, UserConversation.class); @@ -80,14 +88,17 @@ public static UserConversation fromJson(final String json, final ObjectMapper ob } /** - * Converts a JSON InputStream into a UserConversation object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return UserConversation object represented by the provided JSON - */ - public static UserConversation fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a UserConversation object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return UserConversation object represented by the provided JSON + */ + public static UserConversation fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, UserConversation.class); @@ -97,6 +108,7 @@ public static UserConversation fromJson(final InputStream json, final ObjectMapp throw new ApiConnectionException(e.getMessage(), e); } } + public enum NotificationLevel { DEFAULT("default"), MUTED("muted"); @@ -116,6 +128,7 @@ public static NotificationLevel forValue(final String value) { return Promoter.enumFromString(value, NotificationLevel.values()); } } + public enum State { INACTIVE("inactive"), ACTIVE("active"), @@ -158,59 +171,32 @@ public static State forValue(final String value) { @JsonCreator private UserConversation( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("chat_service_sid") - final String chatServiceSid, - - @JsonProperty("conversation_sid") - final String conversationSid, - - @JsonProperty("unread_messages_count") - final Integer unreadMessagesCount, - - @JsonProperty("last_read_message_index") - final Integer lastReadMessageIndex, - - @JsonProperty("participant_sid") - final String participantSid, - - @JsonProperty("user_sid") - final String userSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("conversation_state") - final UserConversation.State conversationState, - - @JsonProperty("timers") - final Map timers, - - @JsonProperty("attributes") - final String attributes, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("created_by") - final String createdBy, - - @JsonProperty("notification_level") - final UserConversation.NotificationLevel notificationLevel, - - @JsonProperty("unique_name") - final String uniqueName, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("chat_service_sid") final String chatServiceSid, + @JsonProperty("conversation_sid") final String conversationSid, + @JsonProperty( + "unread_messages_count" + ) final Integer unreadMessagesCount, + @JsonProperty( + "last_read_message_index" + ) final Integer lastReadMessageIndex, + @JsonProperty("participant_sid") final String participantSid, + @JsonProperty("user_sid") final String userSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty( + "conversation_state" + ) final UserConversation.State conversationState, + @JsonProperty("timers") final Map timers, + @JsonProperty("attributes") final String attributes, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("created_by") final String createdBy, + @JsonProperty( + "notification_level" + ) final UserConversation.NotificationLevel notificationLevel, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.accountSid = accountSid; this.chatServiceSid = chatServiceSid; @@ -232,64 +218,81 @@ private UserConversation( this.links = links; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getChatServiceSid() { - return this.chatServiceSid; - } - public final String getConversationSid() { - return this.conversationSid; - } - public final Integer getUnreadMessagesCount() { - return this.unreadMessagesCount; - } - public final Integer getLastReadMessageIndex() { - return this.lastReadMessageIndex; - } - public final String getParticipantSid() { - return this.participantSid; - } - public final String getUserSid() { - return this.userSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final UserConversation.State getConversationState() { - return this.conversationState; - } - public final Map getTimers() { - return this.timers; - } - public final String getAttributes() { - return this.attributes; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getCreatedBy() { - return this.createdBy; - } - public final UserConversation.NotificationLevel getNotificationLevel() { - return this.notificationLevel; - } - public final String getUniqueName() { - return this.uniqueName; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getChatServiceSid() { + return this.chatServiceSid; + } + + public final String getConversationSid() { + return this.conversationSid; + } + + public final Integer getUnreadMessagesCount() { + return this.unreadMessagesCount; + } + + public final Integer getLastReadMessageIndex() { + return this.lastReadMessageIndex; + } + + public final String getParticipantSid() { + return this.participantSid; + } + + public final String getUserSid() { + return this.userSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final UserConversation.State getConversationState() { + return this.conversationState; + } + + public final Map getTimers() { + return this.timers; + } + + public final String getAttributes() { + return this.attributes; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getCreatedBy() { + return this.createdBy; + } + + public final UserConversation.NotificationLevel getNotificationLevel() { + return this.notificationLevel; + } + + public final String getUniqueName() { + return this.uniqueName; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -299,13 +302,49 @@ public boolean equals(final Object o) { UserConversation other = (UserConversation) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(chatServiceSid, other.chatServiceSid) && Objects.equals(conversationSid, other.conversationSid) && Objects.equals(unreadMessagesCount, other.unreadMessagesCount) && Objects.equals(lastReadMessageIndex, other.lastReadMessageIndex) && Objects.equals(participantSid, other.participantSid) && Objects.equals(userSid, other.userSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(conversationState, other.conversationState) && Objects.equals(timers, other.timers) && Objects.equals(attributes, other.attributes) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(createdBy, other.createdBy) && Objects.equals(notificationLevel, other.notificationLevel) && Objects.equals(uniqueName, other.uniqueName) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(chatServiceSid, other.chatServiceSid) && + Objects.equals(conversationSid, other.conversationSid) && + Objects.equals(unreadMessagesCount, other.unreadMessagesCount) && + Objects.equals(lastReadMessageIndex, other.lastReadMessageIndex) && + Objects.equals(participantSid, other.participantSid) && + Objects.equals(userSid, other.userSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(conversationState, other.conversationState) && + Objects.equals(timers, other.timers) && + Objects.equals(attributes, other.attributes) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(createdBy, other.createdBy) && + Objects.equals(notificationLevel, other.notificationLevel) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, chatServiceSid, conversationSid, unreadMessagesCount, lastReadMessageIndex, participantSid, userSid, friendlyName, conversationState, timers, attributes, dateCreated, dateUpdated, createdBy, notificationLevel, uniqueName, url, links); + return Objects.hash( + accountSid, + chatServiceSid, + conversationSid, + unreadMessagesCount, + lastReadMessageIndex, + participantSid, + userSid, + friendlyName, + conversationState, + timers, + attributes, + dateCreated, + dateUpdated, + createdBy, + notificationLevel, + uniqueName, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/conversations/v1/user/UserConversationDeleter.java b/src/main/java/com/twilio/rest/conversations/v1/user/UserConversationDeleter.java index ab40efa476..e40400c015 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/user/UserConversationDeleter.java +++ b/src/main/java/com/twilio/rest/conversations/v1/user/UserConversationDeleter.java @@ -24,24 +24,29 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class UserConversationDeleter extends Deleter { + private String pathUserSid; private String pathConversationSid; - public UserConversationDeleter(final String pathUserSid, final String pathConversationSid){ + public UserConversationDeleter( + final String pathUserSid, + final String pathConversationSid + ) { this.pathUserSid = pathUserSid; this.pathConversationSid = pathConversationSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Users/{UserSid}/Conversations/{ConversationSid}"; - path = path.replace("{"+"UserSid"+"}", this.pathUserSid.toString()); - path = path.replace("{"+"ConversationSid"+"}", this.pathConversationSid.toString()); + path = path.replace("{" + "UserSid" + "}", this.pathUserSid.toString()); + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +56,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("UserConversation delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "UserConversation delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/conversations/v1/user/UserConversationFetcher.java b/src/main/java/com/twilio/rest/conversations/v1/user/UserConversationFetcher.java index 2edcaa8519..d5d32d83e0 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/user/UserConversationFetcher.java +++ b/src/main/java/com/twilio/rest/conversations/v1/user/UserConversationFetcher.java @@ -24,25 +24,29 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class UserConversationFetcher extends Fetcher { + private String pathUserSid; private String pathConversationSid; - public UserConversationFetcher(final String pathUserSid, final String pathConversationSid){ + public UserConversationFetcher( + final String pathUserSid, + final String pathConversationSid + ) { this.pathUserSid = pathUserSid; this.pathConversationSid = pathConversationSid; } - @Override public UserConversation fetch(final TwilioRestClient client) { String path = "/v1/Users/{UserSid}/Conversations/{ConversationSid}"; - path = path.replace("{"+"UserSid"+"}", this.pathUserSid.toString()); - path = path.replace("{"+"ConversationSid"+"}", this.pathConversationSid.toString()); + path = path.replace("{" + "UserSid" + "}", this.pathUserSid.toString()); + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -52,15 +56,23 @@ public UserConversation fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("UserConversation fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "UserConversation fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return UserConversation.fromJson(response.getStream(), client.getObjectMapper()); + return UserConversation.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/user/UserConversationReader.java b/src/main/java/com/twilio/rest/conversations/v1/user/UserConversationReader.java index 542e6595ca..e0ceb6a548 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/user/UserConversationReader.java +++ b/src/main/java/com/twilio/rest/conversations/v1/user/UserConversationReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.conversations.v1.user; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,19 +25,17 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class UserConversationReader extends Reader { + private String pathUserSid; private Integer pageSize; - public UserConversationReader(final String pathUserSid){ + public UserConversationReader(final String pathUserSid) { this.pathUserSid = pathUserSid; } - public UserConversationReader setPageSize(final Integer pageSize){ + public UserConversationReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -48,7 +47,7 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Users/{UserSid}/Conversations"; - path = path.replace("{"+"UserSid"+"}", this.pathUserSid.toString()); + path = path.replace("{" + "UserSid" + "}", this.pathUserSid.toString()); Request request = new Request( HttpMethod.GET, @@ -60,13 +59,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("UserConversation read failed: Unable to connect to server"); + throw new ApiConnectionException( + "UserConversation read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +89,10 @@ private Page pageForRequest(final TwilioRestClient client, fin } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.CONVERSATIONS.toString()) @@ -90,9 +100,11 @@ public Page previousPage(final Page page, fi return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.CONVERSATIONS.toString()) @@ -101,21 +113,21 @@ public Page nextPage(final Page page, final } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/conversations/v1/user/UserConversationUpdater.java b/src/main/java/com/twilio/rest/conversations/v1/user/UserConversationUpdater.java index cc63432802..8c32bfcf58 100644 --- a/src/main/java/com/twilio/rest/conversations/v1/user/UserConversationUpdater.java +++ b/src/main/java/com/twilio/rest/conversations/v1/user/UserConversationUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.conversations.v1.user; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -23,74 +24,103 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.time.ZonedDateTime; +public class UserConversationUpdater extends Updater { - -public class UserConversationUpdater extends Updater{ private String pathUserSid; private String pathConversationSid; private UserConversation.NotificationLevel notificationLevel; private ZonedDateTime lastReadTimestamp; private Integer lastReadMessageIndex; - public UserConversationUpdater(final String pathUserSid, final String pathConversationSid){ + public UserConversationUpdater( + final String pathUserSid, + final String pathConversationSid + ) { this.pathUserSid = pathUserSid; this.pathConversationSid = pathConversationSid; } - public UserConversationUpdater setNotificationLevel(final UserConversation.NotificationLevel notificationLevel){ + public UserConversationUpdater setNotificationLevel( + final UserConversation.NotificationLevel notificationLevel + ) { this.notificationLevel = notificationLevel; return this; } - public UserConversationUpdater setLastReadTimestamp(final ZonedDateTime lastReadTimestamp){ + + public UserConversationUpdater setLastReadTimestamp( + final ZonedDateTime lastReadTimestamp + ) { this.lastReadTimestamp = lastReadTimestamp; return this; } - public UserConversationUpdater setLastReadMessageIndex(final Integer lastReadMessageIndex){ + + public UserConversationUpdater setLastReadMessageIndex( + final Integer lastReadMessageIndex + ) { this.lastReadMessageIndex = lastReadMessageIndex; return this; } @Override - public UserConversation update(final TwilioRestClient client){ + public UserConversation update(final TwilioRestClient client) { String path = "/v1/Users/{UserSid}/Conversations/{ConversationSid}"; - path = path.replace("{"+"UserSid"+"}", this.pathUserSid.toString()); - path = path.replace("{"+"ConversationSid"+"}", this.pathConversationSid.toString()); + path = path.replace("{" + "UserSid" + "}", this.pathUserSid.toString()); + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.CONVERSATIONS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("UserConversation update failed: Unable to connect to server"); + throw new ApiConnectionException( + "UserConversation update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return UserConversation.fromJson(response.getStream(), client.getObjectMapper()); + return UserConversation.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (notificationLevel != null) { - request.addPostParam("NotificationLevel", notificationLevel.toString()); - + request.addPostParam( + "NotificationLevel", + notificationLevel.toString() + ); } if (lastReadTimestamp != null) { - request.addPostParam("LastReadTimestamp", lastReadTimestamp.toInstant().toString()); - + request.addPostParam( + "LastReadTimestamp", + lastReadTimestamp.toInstant().toString() + ); } if (lastReadMessageIndex != null) { - request.addPostParam("LastReadMessageIndex", lastReadMessageIndex.toString()); - + request.addPostParam( + "LastReadMessageIndex", + lastReadMessageIndex.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/events/v1/EventType.java b/src/main/java/com/twilio/rest/events/v1/EventType.java index e0b802340a..f96618de87 100644 --- a/src/main/java/com/twilio/rest/events/v1/EventType.java +++ b/src/main/java/com/twilio/rest/events/v1/EventType.java @@ -23,43 +23,42 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class EventType extends Resource { + private static final long serialVersionUID = 236822326358907L; - public static EventTypeFetcher fetcher(final String pathType){ + public static EventTypeFetcher fetcher(final String pathType) { return new EventTypeFetcher(pathType); } - public static EventTypeReader reader(){ + public static EventTypeReader reader() { return new EventTypeReader(); } /** - * Converts a JSON String into a EventType object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return EventType object represented by the provided JSON - */ - public static EventType fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a EventType object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return EventType object represented by the provided JSON + */ + public static EventType fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, EventType.class); @@ -71,14 +70,17 @@ public static EventType fromJson(final String json, final ObjectMapper objectMap } /** - * Converts a JSON InputStream into a EventType object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return EventType object represented by the provided JSON - */ - public static EventType fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a EventType object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return EventType object represented by the provided JSON + */ + public static EventType fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, EventType.class); @@ -99,26 +101,13 @@ public static EventType fromJson(final InputStream json, final ObjectMapper obje @JsonCreator private EventType( - @JsonProperty("type") - final String type, - - @JsonProperty("schema_id") - final String schemaId, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("description") - final String description, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("type") final String type, + @JsonProperty("schema_id") final String schemaId, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("description") final String description, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.type = type; this.schemaId = schemaId; @@ -129,31 +118,37 @@ private EventType( this.links = links; } - public final String getType() { - return this.type; - } - public final String getSchemaId() { - return this.schemaId; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getDescription() { - return this.description; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getType() { + return this.type; + } + + public final String getSchemaId() { + return this.schemaId; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getDescription() { + return this.description; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -163,13 +158,27 @@ public boolean equals(final Object o) { EventType other = (EventType) o; - return Objects.equals(type, other.type) && Objects.equals(schemaId, other.schemaId) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(description, other.description) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(type, other.type) && + Objects.equals(schemaId, other.schemaId) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(description, other.description) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(type, schemaId, dateCreated, dateUpdated, description, url, links); + return Objects.hash( + type, + schemaId, + dateCreated, + dateUpdated, + description, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/events/v1/EventTypeFetcher.java b/src/main/java/com/twilio/rest/events/v1/EventTypeFetcher.java index 4633e42fb2..0b4416fb44 100644 --- a/src/main/java/com/twilio/rest/events/v1/EventTypeFetcher.java +++ b/src/main/java/com/twilio/rest/events/v1/EventTypeFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class EventTypeFetcher extends Fetcher { + private String pathType; - public EventTypeFetcher(final String pathType){ + public EventTypeFetcher(final String pathType) { this.pathType = pathType; } - @Override public EventType fetch(final TwilioRestClient client) { String path = "/v1/Types/{Type}"; - path = path.replace("{"+"Type"+"}", this.pathType.toString()); + path = path.replace("{" + "Type" + "}", this.pathType.toString()); Request request = new Request( HttpMethod.GET, @@ -49,15 +46,23 @@ public EventType fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("EventType fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "EventType fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return EventType.fromJson(response.getStream(), client.getObjectMapper()); + return EventType.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/events/v1/EventTypeReader.java b/src/main/java/com/twilio/rest/events/v1/EventTypeReader.java index 59c5863a79..14ca4efe48 100644 --- a/src/main/java/com/twilio/rest/events/v1/EventTypeReader.java +++ b/src/main/java/com/twilio/rest/events/v1/EventTypeReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.events.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,22 +25,20 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class EventTypeReader extends Reader { + private String schemaId; private Integer pageSize; - public EventTypeReader(){ - } + public EventTypeReader() {} - public EventTypeReader setSchemaId(final String schemaId){ + public EventTypeReader setSchemaId(final String schemaId) { this.schemaId = schemaId; return this; } - public EventTypeReader setPageSize(final Integer pageSize){ + + public EventTypeReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -62,13 +61,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("EventType read failed: Unable to connect to server"); + throw new ApiConnectionException( + "EventType read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -84,7 +91,10 @@ private Page pageForRequest(final TwilioRestClient client, final Requ } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.EVENTS.toString()) @@ -92,9 +102,11 @@ public Page previousPage(final Page page, final TwilioRest return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.EVENTS.toString()) @@ -103,25 +115,24 @@ public Page nextPage(final Page page, final TwilioRestClie } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (schemaId != null) { - request.addQueryParam("SchemaId", schemaId); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/events/v1/Schema.java b/src/main/java/com/twilio/rest/events/v1/Schema.java index 065fd0c078..09155b0f8c 100644 --- a/src/main/java/com/twilio/rest/events/v1/Schema.java +++ b/src/main/java/com/twilio/rest/events/v1/Schema.java @@ -23,39 +23,38 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Schema extends Resource { + private static final long serialVersionUID = 100183907119303L; - public static SchemaFetcher fetcher(final String pathId){ + public static SchemaFetcher fetcher(final String pathId) { return new SchemaFetcher(pathId); } /** - * Converts a JSON String into a Schema object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Schema object represented by the provided JSON - */ - public static Schema fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Schema object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Schema object represented by the provided JSON + */ + public static Schema fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Schema.class); @@ -67,14 +66,17 @@ public static Schema fromJson(final String json, final ObjectMapper objectMapper } /** - * Converts a JSON InputStream into a Schema object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Schema object represented by the provided JSON - */ - public static Schema fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Schema object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Schema object represented by the provided JSON + */ + public static Schema fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Schema.class); @@ -93,47 +95,45 @@ public static Schema fromJson(final InputStream json, final ObjectMapper objectM @JsonCreator private Schema( - @JsonProperty("id") - final String id, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links, - - @JsonProperty("latest_version_date_created") - final String latestVersionDateCreated, - - @JsonProperty("latest_version") - final Integer latestVersion + @JsonProperty("id") final String id, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links, + @JsonProperty( + "latest_version_date_created" + ) final String latestVersionDateCreated, + @JsonProperty("latest_version") final Integer latestVersion ) { this.id = id; this.url = url; this.links = links; - this.latestVersionDateCreated = DateConverter.iso8601DateTimeFromString(latestVersionDateCreated); + this.latestVersionDateCreated = + DateConverter.iso8601DateTimeFromString(latestVersionDateCreated); this.latestVersion = latestVersion; } - public final String getId() { - return this.id; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } - public final ZonedDateTime getLatestVersionDateCreated() { - return this.latestVersionDateCreated; - } - public final Integer getLatestVersion() { - return this.latestVersion; - } + public final String getId() { + return this.id; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } + + public final ZonedDateTime getLatestVersionDateCreated() { + return this.latestVersionDateCreated; + } + + public final Integer getLatestVersion() { + return this.latestVersion; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -143,13 +143,26 @@ public boolean equals(final Object o) { Schema other = (Schema) o; - return Objects.equals(id, other.id) && Objects.equals(url, other.url) && Objects.equals(links, other.links) && Objects.equals(latestVersionDateCreated, other.latestVersionDateCreated) && Objects.equals(latestVersion, other.latestVersion) ; + return ( + Objects.equals(id, other.id) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) && + Objects.equals( + latestVersionDateCreated, + other.latestVersionDateCreated + ) && + Objects.equals(latestVersion, other.latestVersion) + ); } @Override public int hashCode() { - return Objects.hash(id, url, links, latestVersionDateCreated, latestVersion); + return Objects.hash( + id, + url, + links, + latestVersionDateCreated, + latestVersion + ); } - } - diff --git a/src/main/java/com/twilio/rest/events/v1/SchemaFetcher.java b/src/main/java/com/twilio/rest/events/v1/SchemaFetcher.java index 606a906460..d8ab9da780 100644 --- a/src/main/java/com/twilio/rest/events/v1/SchemaFetcher.java +++ b/src/main/java/com/twilio/rest/events/v1/SchemaFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class SchemaFetcher extends Fetcher { + private String pathId; - public SchemaFetcher(final String pathId){ + public SchemaFetcher(final String pathId) { this.pathId = pathId; } - @Override public Schema fetch(final TwilioRestClient client) { String path = "/v1/Schemas/{Id}"; - path = path.replace("{"+"Id"+"}", this.pathId.toString()); + path = path.replace("{" + "Id" + "}", this.pathId.toString()); Request request = new Request( HttpMethod.GET, @@ -49,9 +46,14 @@ public Schema fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Schema fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Schema fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/events/v1/Sink.java b/src/main/java/com/twilio/rest/events/v1/Sink.java index 2e0b427ce1..4f7391b13f 100644 --- a/src/main/java/com/twilio/rest/events/v1/Sink.java +++ b/src/main/java/com/twilio/rest/events/v1/Sink.java @@ -24,55 +24,61 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Sink extends Resource { + private static final long serialVersionUID = 81524362005938L; - public static SinkCreator creator(final String description, final Map sinkConfiguration, final Sink.SinkType sinkType){ + public static SinkCreator creator( + final String description, + final Map sinkConfiguration, + final Sink.SinkType sinkType + ) { return new SinkCreator(description, sinkConfiguration, sinkType); } - public static SinkDeleter deleter(final String pathSid){ + public static SinkDeleter deleter(final String pathSid) { return new SinkDeleter(pathSid); } - public static SinkFetcher fetcher(final String pathSid){ + public static SinkFetcher fetcher(final String pathSid) { return new SinkFetcher(pathSid); } - public static SinkReader reader(){ + public static SinkReader reader() { return new SinkReader(); } - public static SinkUpdater updater(final String pathSid, final String description){ + public static SinkUpdater updater( + final String pathSid, + final String description + ) { return new SinkUpdater(pathSid, description); } /** - * Converts a JSON String into a Sink object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Sink object represented by the provided JSON - */ - public static Sink fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Sink object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Sink object represented by the provided JSON + */ + public static Sink fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Sink.class); @@ -84,14 +90,17 @@ public static Sink fromJson(final String json, final ObjectMapper objectMapper) } /** - * Converts a JSON InputStream into a Sink object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Sink object represented by the provided JSON - */ - public static Sink fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Sink object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Sink object represented by the provided JSON + */ + public static Sink fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Sink.class); @@ -101,6 +110,7 @@ public static Sink fromJson(final InputStream json, final ObjectMapper objectMap throw new ApiConnectionException(e.getMessage(), e); } } + public enum SinkType { KINESIS("kinesis"), WEBHOOK("webhook"), @@ -121,6 +131,7 @@ public static SinkType forValue(final String value) { return Promoter.enumFromString(value, SinkType.values()); } } + public enum Status { INITIALIZED("initialized"), VALIDATING("validating"), @@ -155,32 +166,17 @@ public static Status forValue(final String value) { @JsonCreator private Sink( - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("description") - final String description, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("sink_configuration") - final Map sinkConfiguration, - - @JsonProperty("sink_type") - final Sink.SinkType sinkType, - - @JsonProperty("status") - final Sink.Status status, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("description") final String description, + @JsonProperty("sid") final String sid, + @JsonProperty( + "sink_configuration" + ) final Map sinkConfiguration, + @JsonProperty("sink_type") final Sink.SinkType sinkType, + @JsonProperty("status") final Sink.Status status, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); @@ -193,37 +189,45 @@ private Sink( this.links = links; } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getDescription() { - return this.description; - } - public final String getSid() { - return this.sid; - } - public final Map getSinkConfiguration() { - return this.sinkConfiguration; - } - public final Sink.SinkType getSinkType() { - return this.sinkType; - } - public final Sink.Status getStatus() { - return this.status; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getDescription() { + return this.description; + } + + public final String getSid() { + return this.sid; + } + + public final Map getSinkConfiguration() { + return this.sinkConfiguration; + } + + public final Sink.SinkType getSinkType() { + return this.sinkType; + } + + public final Sink.Status getStatus() { + return this.status; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -233,13 +237,31 @@ public boolean equals(final Object o) { Sink other = (Sink) o; - return Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(description, other.description) && Objects.equals(sid, other.sid) && Objects.equals(sinkConfiguration, other.sinkConfiguration) && Objects.equals(sinkType, other.sinkType) && Objects.equals(status, other.status) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(description, other.description) && + Objects.equals(sid, other.sid) && + Objects.equals(sinkConfiguration, other.sinkConfiguration) && + Objects.equals(sinkType, other.sinkType) && + Objects.equals(status, other.status) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(dateCreated, dateUpdated, description, sid, sinkConfiguration, sinkType, status, url, links); + return Objects.hash( + dateCreated, + dateUpdated, + description, + sid, + sinkConfiguration, + sinkType, + status, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/events/v1/SinkCreator.java b/src/main/java/com/twilio/rest/events/v1/SinkCreator.java index 5047ea0cdb..ef65ba5bf3 100644 --- a/src/main/java/com/twilio/rest/events/v1/SinkCreator.java +++ b/src/main/java/com/twilio/rest/events/v1/SinkCreator.java @@ -15,8 +15,10 @@ package com.twilio.rest.events.v1; import com.twilio.base.Creator; -import com.twilio.exception.ApiConnectionException; +import com.twilio.constant.EnumConstants; +import com.twilio.converter.Converter; import com.twilio.converter.Converter; +import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; @@ -25,55 +27,74 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.util.Map; -import com.twilio.converter.Converter; - import java.util.Map; +public class SinkCreator extends Creator { - -public class SinkCreator extends Creator{ private String description; private Map sinkConfiguration; private Sink.SinkType sinkType; - public SinkCreator(final String description, final Map sinkConfiguration, final Sink.SinkType sinkType) { + public SinkCreator( + final String description, + final Map sinkConfiguration, + final Sink.SinkType sinkType + ) { this.description = description; this.sinkConfiguration = sinkConfiguration; this.sinkType = sinkType; } - public SinkCreator setDescription(final String description){ + public SinkCreator setDescription(final String description) { this.description = description; return this; } - public SinkCreator setSinkConfiguration(final Map sinkConfiguration){ + + public SinkCreator setSinkConfiguration( + final Map sinkConfiguration + ) { this.sinkConfiguration = sinkConfiguration; return this; } - public SinkCreator setSinkType(final Sink.SinkType sinkType){ + + public SinkCreator setSinkType(final Sink.SinkType sinkType) { this.sinkType = sinkType; return this; } @Override - public Sink create(final TwilioRestClient client){ + public Sink create(final TwilioRestClient client) { String path = "/v1/Sinks"; - path = path.replace("{"+"Description"+"}", this.description.toString()); - path = path.replace("{"+"SinkConfiguration"+"}", this.sinkConfiguration.toString()); - path = path.replace("{"+"SinkType"+"}", this.sinkType.toString()); + path = + path.replace( + "{" + "Description" + "}", + this.description.toString() + ); + path = + path.replace( + "{" + "SinkConfiguration" + "}", + this.sinkConfiguration.toString() + ); + path = path.replace("{" + "SinkType" + "}", this.sinkType.toString()); Request request = new Request( HttpMethod.POST, Domains.EVENTS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Sink creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Sink creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,18 +103,19 @@ public Sink create(final TwilioRestClient client){ return Sink.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (description != null) { request.addPostParam("Description", description); - } if (sinkConfiguration != null) { - request.addPostParam("SinkConfiguration", Converter.mapToJson(sinkConfiguration)); - + request.addPostParam( + "SinkConfiguration", + Converter.mapToJson(sinkConfiguration) + ); } if (sinkType != null) { request.addPostParam("SinkType", sinkType.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/events/v1/SinkDeleter.java b/src/main/java/com/twilio/rest/events/v1/SinkDeleter.java index 8e21d5c83c..884ab0e50f 100644 --- a/src/main/java/com/twilio/rest/events/v1/SinkDeleter.java +++ b/src/main/java/com/twilio/rest/events/v1/SinkDeleter.java @@ -24,21 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class SinkDeleter extends Deleter { + private String pathSid; - public SinkDeleter(final String pathSid){ + public SinkDeleter(final String pathSid) { this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Sinks/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -48,9 +46,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Sink delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Sink delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/events/v1/SinkFetcher.java b/src/main/java/com/twilio/rest/events/v1/SinkFetcher.java index b35ff9f24c..f215900c30 100644 --- a/src/main/java/com/twilio/rest/events/v1/SinkFetcher.java +++ b/src/main/java/com/twilio/rest/events/v1/SinkFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class SinkFetcher extends Fetcher { + private String pathSid; - public SinkFetcher(final String pathSid){ + public SinkFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public Sink fetch(final TwilioRestClient client) { String path = "/v1/Sinks/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,9 +46,14 @@ public Sink fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Sink fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Sink fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/events/v1/SinkReader.java b/src/main/java/com/twilio/rest/events/v1/SinkReader.java index 5f135ac909..a56c62510e 100644 --- a/src/main/java/com/twilio/rest/events/v1/SinkReader.java +++ b/src/main/java/com/twilio/rest/events/v1/SinkReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.events.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,27 +25,26 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class SinkReader extends Reader { + private Boolean inUse; private String status; private Integer pageSize; - public SinkReader(){ - } + public SinkReader() {} - public SinkReader setInUse(final Boolean inUse){ + public SinkReader setInUse(final Boolean inUse) { this.inUse = inUse; return this; } - public SinkReader setStatus(final String status){ + + public SinkReader setStatus(final String status) { this.status = status; return this; } - public SinkReader setPageSize(final Integer pageSize){ + + public SinkReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -67,13 +67,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Sink read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Sink read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -89,7 +97,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request r } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.EVENTS.toString()) @@ -97,9 +108,11 @@ public Page previousPage(final Page page, final TwilioRestClient cli return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.EVENTS.toString()) @@ -108,29 +121,27 @@ public Page nextPage(final Page page, final TwilioRestClient client) } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (inUse != null) { - request.addQueryParam("InUse", inUse.toString()); } if (status != null) { - request.addQueryParam("Status", status); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/events/v1/SinkUpdater.java b/src/main/java/com/twilio/rest/events/v1/SinkUpdater.java index 786c1c5634..c802e55955 100644 --- a/src/main/java/com/twilio/rest/events/v1/SinkUpdater.java +++ b/src/main/java/com/twilio/rest/events/v1/SinkUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.events.v1; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,41 +25,49 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class SinkUpdater extends Updater { - - -public class SinkUpdater extends Updater{ private String pathSid; private String description; - public SinkUpdater(final String pathSid, final String description){ + public SinkUpdater(final String pathSid, final String description) { this.pathSid = pathSid; this.description = description; } - public SinkUpdater setDescription(final String description){ + public SinkUpdater setDescription(final String description) { this.description = description; return this; } @Override - public Sink update(final TwilioRestClient client){ + public Sink update(final TwilioRestClient client) { String path = "/v1/Sinks/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); - path = path.replace("{"+"Description"+"}", this.description.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + path = + path.replace( + "{" + "Description" + "}", + this.description.toString() + ); Request request = new Request( HttpMethod.POST, Domains.EVENTS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Sink update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Sink update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -67,10 +76,10 @@ public Sink update(final TwilioRestClient client){ return Sink.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (description != null) { request.addPostParam("Description", description); - } } } diff --git a/src/main/java/com/twilio/rest/events/v1/Subscription.java b/src/main/java/com/twilio/rest/events/v1/Subscription.java index ba44aa4be2..0a37de2b4a 100644 --- a/src/main/java/com/twilio/rest/events/v1/Subscription.java +++ b/src/main/java/com/twilio/rest/events/v1/Subscription.java @@ -23,56 +23,59 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.List; import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Subscription extends Resource { + private static final long serialVersionUID = 198248500185102L; - public static SubscriptionCreator creator(final String description, final String sinkSid, final List> types){ + public static SubscriptionCreator creator( + final String description, + final String sinkSid, + final List> types + ) { return new SubscriptionCreator(description, sinkSid, types); } - public static SubscriptionDeleter deleter(final String pathSid){ + public static SubscriptionDeleter deleter(final String pathSid) { return new SubscriptionDeleter(pathSid); } - public static SubscriptionFetcher fetcher(final String pathSid){ + public static SubscriptionFetcher fetcher(final String pathSid) { return new SubscriptionFetcher(pathSid); } - public static SubscriptionReader reader(){ + public static SubscriptionReader reader() { return new SubscriptionReader(); } - public static SubscriptionUpdater updater(final String pathSid){ + public static SubscriptionUpdater updater(final String pathSid) { return new SubscriptionUpdater(pathSid); } /** - * Converts a JSON String into a Subscription object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Subscription object represented by the provided JSON - */ - public static Subscription fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Subscription object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Subscription object represented by the provided JSON + */ + public static Subscription fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Subscription.class); @@ -84,14 +87,17 @@ public static Subscription fromJson(final String json, final ObjectMapper object } /** - * Converts a JSON InputStream into a Subscription object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Subscription object represented by the provided JSON - */ - public static Subscription fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Subscription object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Subscription object represented by the provided JSON + */ + public static Subscription fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Subscription.class); @@ -113,29 +119,14 @@ public static Subscription fromJson(final InputStream json, final ObjectMapper o @JsonCreator private Subscription( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("description") - final String description, - - @JsonProperty("sink_sid") - final String sinkSid, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("sid") final String sid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("description") final String description, + @JsonProperty("sink_sid") final String sinkSid, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.accountSid = accountSid; this.sid = sid; @@ -147,34 +138,41 @@ private Subscription( this.links = links; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getSid() { - return this.sid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getDescription() { - return this.description; - } - public final String getSinkSid() { - return this.sinkSid; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getSid() { + return this.sid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getDescription() { + return this.description; + } + + public final String getSinkSid() { + return this.sinkSid; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -184,13 +182,29 @@ public boolean equals(final Object o) { Subscription other = (Subscription) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(sid, other.sid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(description, other.description) && Objects.equals(sinkSid, other.sinkSid) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(sid, other.sid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(description, other.description) && + Objects.equals(sinkSid, other.sinkSid) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, sid, dateCreated, dateUpdated, description, sinkSid, url, links); + return Objects.hash( + accountSid, + sid, + dateCreated, + dateUpdated, + description, + sinkSid, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/events/v1/SubscriptionCreator.java b/src/main/java/com/twilio/rest/events/v1/SubscriptionCreator.java index 3c6707c965..43cdb44d2e 100644 --- a/src/main/java/com/twilio/rest/events/v1/SubscriptionCreator.java +++ b/src/main/java/com/twilio/rest/events/v1/SubscriptionCreator.java @@ -15,9 +15,11 @@ package com.twilio.rest.events.v1; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; +import com.twilio.converter.Converter; +import com.twilio.converter.Converter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; -import com.twilio.converter.Converter; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; @@ -26,82 +28,97 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.util.List; -import java.util.Map; -import com.twilio.converter.Converter; - import java.util.List; import java.util.Map; +import java.util.Map; +public class SubscriptionCreator extends Creator { - -public class SubscriptionCreator extends Creator{ private String description; private String sinkSid; private List> types; - public SubscriptionCreator(final String description, final String sinkSid, final List> types) { + public SubscriptionCreator( + final String description, + final String sinkSid, + final List> types + ) { this.description = description; this.sinkSid = sinkSid; this.types = types; } - public SubscriptionCreator setDescription(final String description){ + public SubscriptionCreator setDescription(final String description) { this.description = description; return this; } - public SubscriptionCreator setSinkSid(final String sinkSid){ + + public SubscriptionCreator setSinkSid(final String sinkSid) { this.sinkSid = sinkSid; return this; } - public SubscriptionCreator setTypes(final List> types){ + + public SubscriptionCreator setTypes(final List> types) { this.types = types; return this; } - public SubscriptionCreator setTypes(final Map types){ + + public SubscriptionCreator setTypes(final Map types) { return setTypes(Promoter.listOfOne(types)); } @Override - public Subscription create(final TwilioRestClient client){ + public Subscription create(final TwilioRestClient client) { String path = "/v1/Subscriptions"; - path = path.replace("{"+"Description"+"}", this.description.toString()); - path = path.replace("{"+"SinkSid"+"}", this.sinkSid.toString()); - path = path.replace("{"+"Types"+"}", this.types.toString()); + path = + path.replace( + "{" + "Description" + "}", + this.description.toString() + ); + path = path.replace("{" + "SinkSid" + "}", this.sinkSid.toString()); + path = path.replace("{" + "Types" + "}", this.types.toString()); Request request = new Request( HttpMethod.POST, Domains.EVENTS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Subscription creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Subscription creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Subscription.fromJson(response.getStream(), client.getObjectMapper()); + return Subscription.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (description != null) { request.addPostParam("Description", description); - } if (sinkSid != null) { request.addPostParam("SinkSid", sinkSid); - } if (types != null) { for (Map prop : types) { request.addPostParam("Types", Converter.mapToJson(prop)); } - } } } diff --git a/src/main/java/com/twilio/rest/events/v1/SubscriptionDeleter.java b/src/main/java/com/twilio/rest/events/v1/SubscriptionDeleter.java index bf9c887928..b1e6eab7c5 100644 --- a/src/main/java/com/twilio/rest/events/v1/SubscriptionDeleter.java +++ b/src/main/java/com/twilio/rest/events/v1/SubscriptionDeleter.java @@ -24,21 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class SubscriptionDeleter extends Deleter { + private String pathSid; - public SubscriptionDeleter(final String pathSid){ + public SubscriptionDeleter(final String pathSid) { this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Subscriptions/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -48,9 +46,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Subscription delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Subscription delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/events/v1/SubscriptionFetcher.java b/src/main/java/com/twilio/rest/events/v1/SubscriptionFetcher.java index 1b0ade3d28..2298cfaea4 100644 --- a/src/main/java/com/twilio/rest/events/v1/SubscriptionFetcher.java +++ b/src/main/java/com/twilio/rest/events/v1/SubscriptionFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class SubscriptionFetcher extends Fetcher { + private String pathSid; - public SubscriptionFetcher(final String pathSid){ + public SubscriptionFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public Subscription fetch(final TwilioRestClient client) { String path = "/v1/Subscriptions/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,15 +46,23 @@ public Subscription fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Subscription fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Subscription fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Subscription.fromJson(response.getStream(), client.getObjectMapper()); + return Subscription.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/events/v1/SubscriptionReader.java b/src/main/java/com/twilio/rest/events/v1/SubscriptionReader.java index d786fb5967..65511f040b 100644 --- a/src/main/java/com/twilio/rest/events/v1/SubscriptionReader.java +++ b/src/main/java/com/twilio/rest/events/v1/SubscriptionReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.events.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,22 +25,20 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class SubscriptionReader extends Reader { + private String sinkSid; private Integer pageSize; - public SubscriptionReader(){ - } + public SubscriptionReader() {} - public SubscriptionReader setSinkSid(final String sinkSid){ + public SubscriptionReader setSinkSid(final String sinkSid) { this.sinkSid = sinkSid; return this; } - public SubscriptionReader setPageSize(final Integer pageSize){ + + public SubscriptionReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -62,13 +61,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Subscription read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Subscription read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -84,7 +91,10 @@ private Page pageForRequest(final TwilioRestClient client, final R } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.EVENTS.toString()) @@ -92,9 +102,11 @@ public Page previousPage(final Page page, final Twil return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.EVENTS.toString()) @@ -103,25 +115,24 @@ public Page nextPage(final Page page, final TwilioRe } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (sinkSid != null) { - request.addQueryParam("SinkSid", sinkSid); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/events/v1/SubscriptionUpdater.java b/src/main/java/com/twilio/rest/events/v1/SubscriptionUpdater.java index a38571ae36..dc2bc40cbe 100644 --- a/src/main/java/com/twilio/rest/events/v1/SubscriptionUpdater.java +++ b/src/main/java/com/twilio/rest/events/v1/SubscriptionUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.events.v1; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,60 +25,67 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class SubscriptionUpdater extends Updater { - - -public class SubscriptionUpdater extends Updater{ private String pathSid; private String description; private String sinkSid; - public SubscriptionUpdater(final String pathSid){ + public SubscriptionUpdater(final String pathSid) { this.pathSid = pathSid; } - public SubscriptionUpdater setDescription(final String description){ + public SubscriptionUpdater setDescription(final String description) { this.description = description; return this; } - public SubscriptionUpdater setSinkSid(final String sinkSid){ + + public SubscriptionUpdater setSinkSid(final String sinkSid) { this.sinkSid = sinkSid; return this; } @Override - public Subscription update(final TwilioRestClient client){ + public Subscription update(final TwilioRestClient client) { String path = "/v1/Subscriptions/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.EVENTS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Subscription update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Subscription update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Subscription.fromJson(response.getStream(), client.getObjectMapper()); + return Subscription.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (description != null) { request.addPostParam("Description", description); - } if (sinkSid != null) { request.addPostParam("SinkSid", sinkSid); - } } } diff --git a/src/main/java/com/twilio/rest/events/v1/schema/SchemaVersion.java b/src/main/java/com/twilio/rest/events/v1/schema/SchemaVersion.java index 742e8222f9..1e30a12e12 100644 --- a/src/main/java/com/twilio/rest/events/v1/schema/SchemaVersion.java +++ b/src/main/java/com/twilio/rest/events/v1/schema/SchemaVersion.java @@ -23,41 +23,43 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class SchemaVersion extends Resource { + private static final long serialVersionUID = 232564429627083L; - public static SchemaVersionFetcher fetcher(final String pathId, final Integer pathSchemaVersion){ + public static SchemaVersionFetcher fetcher( + final String pathId, + final Integer pathSchemaVersion + ) { return new SchemaVersionFetcher(pathId, pathSchemaVersion); } - public static SchemaVersionReader reader(final String pathId){ + public static SchemaVersionReader reader(final String pathId) { return new SchemaVersionReader(pathId); } /** - * Converts a JSON String into a SchemaVersion object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return SchemaVersion object represented by the provided JSON - */ - public static SchemaVersion fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a SchemaVersion object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return SchemaVersion object represented by the provided JSON + */ + public static SchemaVersion fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SchemaVersion.class); @@ -69,14 +71,17 @@ public static SchemaVersion fromJson(final String json, final ObjectMapper objec } /** - * Converts a JSON InputStream into a SchemaVersion object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return SchemaVersion object represented by the provided JSON - */ - public static SchemaVersion fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a SchemaVersion object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return SchemaVersion object represented by the provided JSON + */ + public static SchemaVersion fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SchemaVersion.class); @@ -95,20 +100,11 @@ public static SchemaVersion fromJson(final InputStream json, final ObjectMapper @JsonCreator private SchemaVersion( - @JsonProperty("id") - final String id, - - @JsonProperty("schema_version") - final Integer schemaVersion, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("url") - final URI url, - - @JsonProperty("raw") - final URI raw + @JsonProperty("id") final String id, + @JsonProperty("schema_version") final Integer schemaVersion, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("url") final URI url, + @JsonProperty("raw") final URI raw ) { this.id = id; this.schemaVersion = schemaVersion; @@ -117,25 +113,29 @@ private SchemaVersion( this.raw = raw; } - public final String getId() { - return this.id; - } - public final Integer getSchemaVersion() { - return this.schemaVersion; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final URI getUrl() { - return this.url; - } - public final URI getRaw() { - return this.raw; - } + public final String getId() { + return this.id; + } + + public final Integer getSchemaVersion() { + return this.schemaVersion; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final URI getUrl() { + return this.url; + } + + public final URI getRaw() { + return this.raw; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -145,13 +145,17 @@ public boolean equals(final Object o) { SchemaVersion other = (SchemaVersion) o; - return Objects.equals(id, other.id) && Objects.equals(schemaVersion, other.schemaVersion) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(url, other.url) && Objects.equals(raw, other.raw) ; + return ( + Objects.equals(id, other.id) && + Objects.equals(schemaVersion, other.schemaVersion) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(url, other.url) && + Objects.equals(raw, other.raw) + ); } @Override public int hashCode() { return Objects.hash(id, schemaVersion, dateCreated, url, raw); } - } - diff --git a/src/main/java/com/twilio/rest/events/v1/schema/SchemaVersionFetcher.java b/src/main/java/com/twilio/rest/events/v1/schema/SchemaVersionFetcher.java index 2527a3338f..9fe71219eb 100644 --- a/src/main/java/com/twilio/rest/events/v1/schema/SchemaVersionFetcher.java +++ b/src/main/java/com/twilio/rest/events/v1/schema/SchemaVersionFetcher.java @@ -24,25 +24,29 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class SchemaVersionFetcher extends Fetcher { + private String pathId; private Integer pathSchemaVersion; - public SchemaVersionFetcher(final String pathId, final Integer pathSchemaVersion){ + public SchemaVersionFetcher( + final String pathId, + final Integer pathSchemaVersion + ) { this.pathId = pathId; this.pathSchemaVersion = pathSchemaVersion; } - @Override public SchemaVersion fetch(final TwilioRestClient client) { String path = "/v1/Schemas/{Id}/Versions/{SchemaVersion}"; - path = path.replace("{"+"Id"+"}", this.pathId.toString()); - path = path.replace("{"+"SchemaVersion"+"}", this.pathSchemaVersion.toString()); + path = path.replace("{" + "Id" + "}", this.pathId.toString()); + path = + path.replace( + "{" + "SchemaVersion" + "}", + this.pathSchemaVersion.toString() + ); Request request = new Request( HttpMethod.GET, @@ -52,15 +56,23 @@ public SchemaVersion fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SchemaVersion fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "SchemaVersion fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return SchemaVersion.fromJson(response.getStream(), client.getObjectMapper()); + return SchemaVersion.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/events/v1/schema/SchemaVersionReader.java b/src/main/java/com/twilio/rest/events/v1/schema/SchemaVersionReader.java index f6089c26ee..eb1ba9eeeb 100644 --- a/src/main/java/com/twilio/rest/events/v1/schema/SchemaVersionReader.java +++ b/src/main/java/com/twilio/rest/events/v1/schema/SchemaVersionReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.events.v1.schema; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,19 +25,17 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class SchemaVersionReader extends Reader { + private String pathId; private Integer pageSize; - public SchemaVersionReader(final String pathId){ + public SchemaVersionReader(final String pathId) { this.pathId = pathId; } - public SchemaVersionReader setPageSize(final Integer pageSize){ + public SchemaVersionReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -48,7 +47,7 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Schemas/{Id}/Versions"; - path = path.replace("{"+"Id"+"}", this.pathId.toString()); + path = path.replace("{" + "Id" + "}", this.pathId.toString()); Request request = new Request( HttpMethod.GET, @@ -60,13 +59,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SchemaVersion read failed: Unable to connect to server"); + throw new ApiConnectionException( + "SchemaVersion read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +89,10 @@ private Page pageForRequest(final TwilioRestClient client, final } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.EVENTS.toString()) @@ -90,9 +100,11 @@ public Page previousPage(final Page page, final Tw return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.EVENTS.toString()) @@ -101,21 +113,21 @@ public Page nextPage(final Page page, final Twilio } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/events/v1/sink/SinkTest.java b/src/main/java/com/twilio/rest/events/v1/sink/SinkTest.java index 5746ce07b2..c3bd4ae6a7 100644 --- a/src/main/java/com/twilio/rest/events/v1/sink/SinkTest.java +++ b/src/main/java/com/twilio/rest/events/v1/sink/SinkTest.java @@ -22,35 +22,34 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class SinkTest extends Resource { + private static final long serialVersionUID = 233814002700195L; - public static SinkTestCreator creator(final String pathSid){ + public static SinkTestCreator creator(final String pathSid) { return new SinkTestCreator(pathSid); } /** - * Converts a JSON String into a SinkTest object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return SinkTest object represented by the provided JSON - */ - public static SinkTest fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a SinkTest object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return SinkTest object represented by the provided JSON + */ + public static SinkTest fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SinkTest.class); @@ -62,14 +61,17 @@ public static SinkTest fromJson(final String json, final ObjectMapper objectMapp } /** - * Converts a JSON InputStream into a SinkTest object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return SinkTest object represented by the provided JSON - */ - public static SinkTest fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a SinkTest object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return SinkTest object represented by the provided JSON + */ + public static SinkTest fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SinkTest.class); @@ -83,20 +85,17 @@ public static SinkTest fromJson(final InputStream json, final ObjectMapper objec private final String result; @JsonCreator - private SinkTest( - @JsonProperty("result") - final String result - ) { + private SinkTest(@JsonProperty("result") final String result) { this.result = result; } - public final String getResult() { - return this.result; - } + public final String getResult() { + return this.result; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -106,13 +105,11 @@ public boolean equals(final Object o) { SinkTest other = (SinkTest) o; - return Objects.equals(result, other.result) ; + return Objects.equals(result, other.result); } @Override public int hashCode() { return Objects.hash(result); } - } - diff --git a/src/main/java/com/twilio/rest/events/v1/sink/SinkTestCreator.java b/src/main/java/com/twilio/rest/events/v1/sink/SinkTestCreator.java index 9ec640ae49..b01f7d1db6 100644 --- a/src/main/java/com/twilio/rest/events/v1/sink/SinkTestCreator.java +++ b/src/main/java/com/twilio/rest/events/v1/sink/SinkTestCreator.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class SinkTestCreator extends Creator { - - -public class SinkTestCreator extends Creator{ private String pathSid; public SinkTestCreator(final String pathSid) { this.pathSid = pathSid; } - @Override - public SinkTest create(final TwilioRestClient client){ + public SinkTest create(final TwilioRestClient client) { String path = "/v1/Sinks/{Sid}/Test"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, @@ -48,15 +45,23 @@ public SinkTest create(final TwilioRestClient client){ ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SinkTest creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "SinkTest creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return SinkTest.fromJson(response.getStream(), client.getObjectMapper()); + return SinkTest.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/events/v1/sink/SinkValidate.java b/src/main/java/com/twilio/rest/events/v1/sink/SinkValidate.java index 90710ebda8..ebca5d979c 100644 --- a/src/main/java/com/twilio/rest/events/v1/sink/SinkValidate.java +++ b/src/main/java/com/twilio/rest/events/v1/sink/SinkValidate.java @@ -22,35 +22,37 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class SinkValidate extends Resource { + private static final long serialVersionUID = 233814002700195L; - public static SinkValidateCreator creator(final String pathSid, final String testId){ + public static SinkValidateCreator creator( + final String pathSid, + final String testId + ) { return new SinkValidateCreator(pathSid, testId); } /** - * Converts a JSON String into a SinkValidate object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return SinkValidate object represented by the provided JSON - */ - public static SinkValidate fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a SinkValidate object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return SinkValidate object represented by the provided JSON + */ + public static SinkValidate fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SinkValidate.class); @@ -62,14 +64,17 @@ public static SinkValidate fromJson(final String json, final ObjectMapper object } /** - * Converts a JSON InputStream into a SinkValidate object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return SinkValidate object represented by the provided JSON - */ - public static SinkValidate fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a SinkValidate object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return SinkValidate object represented by the provided JSON + */ + public static SinkValidate fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SinkValidate.class); @@ -83,20 +88,17 @@ public static SinkValidate fromJson(final InputStream json, final ObjectMapper o private final String result; @JsonCreator - private SinkValidate( - @JsonProperty("result") - final String result - ) { + private SinkValidate(@JsonProperty("result") final String result) { this.result = result; } - public final String getResult() { - return this.result; - } + public final String getResult() { + return this.result; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -106,13 +108,11 @@ public boolean equals(final Object o) { SinkValidate other = (SinkValidate) o; - return Objects.equals(result, other.result) ; + return Objects.equals(result, other.result); } @Override public int hashCode() { return Objects.hash(result); } - } - diff --git a/src/main/java/com/twilio/rest/events/v1/sink/SinkValidateCreator.java b/src/main/java/com/twilio/rest/events/v1/sink/SinkValidateCreator.java index 796ee152bd..3f57a47499 100644 --- a/src/main/java/com/twilio/rest/events/v1/sink/SinkValidateCreator.java +++ b/src/main/java/com/twilio/rest/events/v1/sink/SinkValidateCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.events.v1.sink; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class SinkValidateCreator extends Creator { - - -public class SinkValidateCreator extends Creator{ private String pathSid; private String testId; @@ -36,41 +35,50 @@ public SinkValidateCreator(final String pathSid, final String testId) { this.testId = testId; } - public SinkValidateCreator setTestId(final String testId){ + public SinkValidateCreator setTestId(final String testId) { this.testId = testId; return this; } @Override - public SinkValidate create(final TwilioRestClient client){ + public SinkValidate create(final TwilioRestClient client) { String path = "/v1/Sinks/{Sid}/Validate"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); - path = path.replace("{"+"TestId"+"}", this.testId.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + path = path.replace("{" + "TestId" + "}", this.testId.toString()); Request request = new Request( HttpMethod.POST, Domains.EVENTS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SinkValidate creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "SinkValidate creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return SinkValidate.fromJson(response.getStream(), client.getObjectMapper()); + return SinkValidate.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (testId != null) { request.addPostParam("TestId", testId); - } } } diff --git a/src/main/java/com/twilio/rest/events/v1/subscription/SubscribedEvent.java b/src/main/java/com/twilio/rest/events/v1/subscription/SubscribedEvent.java index d7bf79c5c4..4affd70649 100644 --- a/src/main/java/com/twilio/rest/events/v1/subscription/SubscribedEvent.java +++ b/src/main/java/com/twilio/rest/events/v1/subscription/SubscribedEvent.java @@ -22,52 +22,65 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class SubscribedEvent extends Resource { + private static final long serialVersionUID = 216550539675838L; - public static SubscribedEventCreator creator(final String pathSubscriptionSid, final String type){ + public static SubscribedEventCreator creator( + final String pathSubscriptionSid, + final String type + ) { return new SubscribedEventCreator(pathSubscriptionSid, type); } - public static SubscribedEventDeleter deleter(final String pathSubscriptionSid, final String pathType){ + public static SubscribedEventDeleter deleter( + final String pathSubscriptionSid, + final String pathType + ) { return new SubscribedEventDeleter(pathSubscriptionSid, pathType); } - public static SubscribedEventFetcher fetcher(final String pathSubscriptionSid, final String pathType){ + public static SubscribedEventFetcher fetcher( + final String pathSubscriptionSid, + final String pathType + ) { return new SubscribedEventFetcher(pathSubscriptionSid, pathType); } - public static SubscribedEventReader reader(final String pathSubscriptionSid){ + public static SubscribedEventReader reader( + final String pathSubscriptionSid + ) { return new SubscribedEventReader(pathSubscriptionSid); } - public static SubscribedEventUpdater updater(final String pathSubscriptionSid, final String pathType){ + public static SubscribedEventUpdater updater( + final String pathSubscriptionSid, + final String pathType + ) { return new SubscribedEventUpdater(pathSubscriptionSid, pathType); } /** - * Converts a JSON String into a SubscribedEvent object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return SubscribedEvent object represented by the provided JSON - */ - public static SubscribedEvent fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a SubscribedEvent object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return SubscribedEvent object represented by the provided JSON + */ + public static SubscribedEvent fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SubscribedEvent.class); @@ -79,14 +92,17 @@ public static SubscribedEvent fromJson(final String json, final ObjectMapper obj } /** - * Converts a JSON InputStream into a SubscribedEvent object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return SubscribedEvent object represented by the provided JSON - */ - public static SubscribedEvent fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a SubscribedEvent object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return SubscribedEvent object represented by the provided JSON + */ + public static SubscribedEvent fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SubscribedEvent.class); @@ -105,20 +121,11 @@ public static SubscribedEvent fromJson(final InputStream json, final ObjectMappe @JsonCreator private SubscribedEvent( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("type") - final String type, - - @JsonProperty("schema_version") - final Integer schemaVersion, - - @JsonProperty("subscription_sid") - final String subscriptionSid, - - @JsonProperty("url") - final URI url + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("type") final String type, + @JsonProperty("schema_version") final Integer schemaVersion, + @JsonProperty("subscription_sid") final String subscriptionSid, + @JsonProperty("url") final URI url ) { this.accountSid = accountSid; this.type = type; @@ -127,25 +134,29 @@ private SubscribedEvent( this.url = url; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getType() { - return this.type; - } - public final Integer getSchemaVersion() { - return this.schemaVersion; - } - public final String getSubscriptionSid() { - return this.subscriptionSid; - } - public final URI getUrl() { - return this.url; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getType() { + return this.type; + } + + public final Integer getSchemaVersion() { + return this.schemaVersion; + } + + public final String getSubscriptionSid() { + return this.subscriptionSid; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -155,13 +166,23 @@ public boolean equals(final Object o) { SubscribedEvent other = (SubscribedEvent) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(type, other.type) && Objects.equals(schemaVersion, other.schemaVersion) && Objects.equals(subscriptionSid, other.subscriptionSid) && Objects.equals(url, other.url) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(type, other.type) && + Objects.equals(schemaVersion, other.schemaVersion) && + Objects.equals(subscriptionSid, other.subscriptionSid) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, type, schemaVersion, subscriptionSid, url); + return Objects.hash( + accountSid, + type, + schemaVersion, + subscriptionSid, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/events/v1/subscription/SubscribedEventCreator.java b/src/main/java/com/twilio/rest/events/v1/subscription/SubscribedEventCreator.java index 081ccc909d..9008c18bcd 100644 --- a/src/main/java/com/twilio/rest/events/v1/subscription/SubscribedEventCreator.java +++ b/src/main/java/com/twilio/rest/events/v1/subscription/SubscribedEventCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.events.v1.subscription; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,62 +25,78 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class SubscribedEventCreator extends Creator { - - -public class SubscribedEventCreator extends Creator{ private String pathSubscriptionSid; private String type; private Integer schemaVersion; - public SubscribedEventCreator(final String pathSubscriptionSid, final String type) { + public SubscribedEventCreator( + final String pathSubscriptionSid, + final String type + ) { this.pathSubscriptionSid = pathSubscriptionSid; this.type = type; } - public SubscribedEventCreator setType(final String type){ + public SubscribedEventCreator setType(final String type) { this.type = type; return this; } - public SubscribedEventCreator setSchemaVersion(final Integer schemaVersion){ + + public SubscribedEventCreator setSchemaVersion( + final Integer schemaVersion + ) { this.schemaVersion = schemaVersion; return this; } @Override - public SubscribedEvent create(final TwilioRestClient client){ + public SubscribedEvent create(final TwilioRestClient client) { String path = "/v1/Subscriptions/{SubscriptionSid}/SubscribedEvents"; - path = path.replace("{"+"SubscriptionSid"+"}", this.pathSubscriptionSid.toString()); - path = path.replace("{"+"Type"+"}", this.type.toString()); + path = + path.replace( + "{" + "SubscriptionSid" + "}", + this.pathSubscriptionSid.toString() + ); + path = path.replace("{" + "Type" + "}", this.type.toString()); Request request = new Request( HttpMethod.POST, Domains.EVENTS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SubscribedEvent creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "SubscribedEvent creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return SubscribedEvent.fromJson(response.getStream(), client.getObjectMapper()); + return SubscribedEvent.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (type != null) { request.addPostParam("Type", type); - } if (schemaVersion != null) { request.addPostParam("SchemaVersion", schemaVersion.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/events/v1/subscription/SubscribedEventDeleter.java b/src/main/java/com/twilio/rest/events/v1/subscription/SubscribedEventDeleter.java index 4449e49fd5..e683f0aee7 100644 --- a/src/main/java/com/twilio/rest/events/v1/subscription/SubscribedEventDeleter.java +++ b/src/main/java/com/twilio/rest/events/v1/subscription/SubscribedEventDeleter.java @@ -24,24 +24,30 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class SubscribedEventDeleter extends Deleter { + private String pathSubscriptionSid; private String pathType; - public SubscribedEventDeleter(final String pathSubscriptionSid, final String pathType){ + public SubscribedEventDeleter( + final String pathSubscriptionSid, + final String pathType + ) { this.pathSubscriptionSid = pathSubscriptionSid; this.pathType = pathType; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/v1/Subscriptions/{SubscriptionSid}/SubscribedEvents/{Type}"; + String path = + "/v1/Subscriptions/{SubscriptionSid}/SubscribedEvents/{Type}"; - path = path.replace("{"+"SubscriptionSid"+"}", this.pathSubscriptionSid.toString()); - path = path.replace("{"+"Type"+"}", this.pathType.toString()); + path = + path.replace( + "{" + "SubscriptionSid" + "}", + this.pathSubscriptionSid.toString() + ); + path = path.replace("{" + "Type" + "}", this.pathType.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +57,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SubscribedEvent delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "SubscribedEvent delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/events/v1/subscription/SubscribedEventFetcher.java b/src/main/java/com/twilio/rest/events/v1/subscription/SubscribedEventFetcher.java index 66719eeb20..4771da4ad4 100644 --- a/src/main/java/com/twilio/rest/events/v1/subscription/SubscribedEventFetcher.java +++ b/src/main/java/com/twilio/rest/events/v1/subscription/SubscribedEventFetcher.java @@ -24,25 +24,30 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class SubscribedEventFetcher extends Fetcher { + private String pathSubscriptionSid; private String pathType; - public SubscribedEventFetcher(final String pathSubscriptionSid, final String pathType){ + public SubscribedEventFetcher( + final String pathSubscriptionSid, + final String pathType + ) { this.pathSubscriptionSid = pathSubscriptionSid; this.pathType = pathType; } - @Override public SubscribedEvent fetch(final TwilioRestClient client) { - String path = "/v1/Subscriptions/{SubscriptionSid}/SubscribedEvents/{Type}"; + String path = + "/v1/Subscriptions/{SubscriptionSid}/SubscribedEvents/{Type}"; - path = path.replace("{"+"SubscriptionSid"+"}", this.pathSubscriptionSid.toString()); - path = path.replace("{"+"Type"+"}", this.pathType.toString()); + path = + path.replace( + "{" + "SubscriptionSid" + "}", + this.pathSubscriptionSid.toString() + ); + path = path.replace("{" + "Type" + "}", this.pathType.toString()); Request request = new Request( HttpMethod.GET, @@ -52,15 +57,23 @@ public SubscribedEvent fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SubscribedEvent fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "SubscribedEvent fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return SubscribedEvent.fromJson(response.getStream(), client.getObjectMapper()); + return SubscribedEvent.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/events/v1/subscription/SubscribedEventReader.java b/src/main/java/com/twilio/rest/events/v1/subscription/SubscribedEventReader.java index 08d5ac9630..3ab4eba087 100644 --- a/src/main/java/com/twilio/rest/events/v1/subscription/SubscribedEventReader.java +++ b/src/main/java/com/twilio/rest/events/v1/subscription/SubscribedEventReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.events.v1.subscription; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,19 +25,17 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class SubscribedEventReader extends Reader { + private String pathSubscriptionSid; private Integer pageSize; - public SubscribedEventReader(final String pathSubscriptionSid){ + public SubscribedEventReader(final String pathSubscriptionSid) { this.pathSubscriptionSid = pathSubscriptionSid; } - public SubscribedEventReader setPageSize(final Integer pageSize){ + public SubscribedEventReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -48,7 +47,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Subscriptions/{SubscriptionSid}/SubscribedEvents"; - path = path.replace("{"+"SubscriptionSid"+"}", this.pathSubscriptionSid.toString()); + path = + path.replace( + "{" + "SubscriptionSid" + "}", + this.pathSubscriptionSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -60,13 +63,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SubscribedEvent read failed: Unable to connect to server"); + throw new ApiConnectionException( + "SubscribedEvent read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +93,10 @@ private Page pageForRequest(final TwilioRestClient client, fina } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.EVENTS.toString()) @@ -90,9 +104,11 @@ public Page previousPage(final Page page, fina return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.EVENTS.toString()) @@ -101,21 +117,21 @@ public Page nextPage(final Page page, final Tw } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/events/v1/subscription/SubscribedEventUpdater.java b/src/main/java/com/twilio/rest/events/v1/subscription/SubscribedEventUpdater.java index 612ee79adf..626d5e4a34 100644 --- a/src/main/java/com/twilio/rest/events/v1/subscription/SubscribedEventUpdater.java +++ b/src/main/java/com/twilio/rest/events/v1/subscription/SubscribedEventUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.events.v1.subscription; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,54 +25,71 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class SubscribedEventUpdater extends Updater { - - -public class SubscribedEventUpdater extends Updater{ private String pathSubscriptionSid; private String pathType; private Integer schemaVersion; - public SubscribedEventUpdater(final String pathSubscriptionSid, final String pathType){ + public SubscribedEventUpdater( + final String pathSubscriptionSid, + final String pathType + ) { this.pathSubscriptionSid = pathSubscriptionSid; this.pathType = pathType; } - public SubscribedEventUpdater setSchemaVersion(final Integer schemaVersion){ + public SubscribedEventUpdater setSchemaVersion( + final Integer schemaVersion + ) { this.schemaVersion = schemaVersion; return this; } @Override - public SubscribedEvent update(final TwilioRestClient client){ - String path = "/v1/Subscriptions/{SubscriptionSid}/SubscribedEvents/{Type}"; + public SubscribedEvent update(final TwilioRestClient client) { + String path = + "/v1/Subscriptions/{SubscriptionSid}/SubscribedEvents/{Type}"; - path = path.replace("{"+"SubscriptionSid"+"}", this.pathSubscriptionSid.toString()); - path = path.replace("{"+"Type"+"}", this.pathType.toString()); + path = + path.replace( + "{" + "SubscriptionSid" + "}", + this.pathSubscriptionSid.toString() + ); + path = path.replace("{" + "Type" + "}", this.pathType.toString()); Request request = new Request( HttpMethod.POST, Domains.EVENTS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SubscribedEvent update failed: Unable to connect to server"); + throw new ApiConnectionException( + "SubscribedEvent update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return SubscribedEvent.fromJson(response.getStream(), client.getObjectMapper()); + return SubscribedEvent.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (schemaVersion != null) { request.addPostParam("SchemaVersion", schemaVersion.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/flexapi/v1/Assessments.java b/src/main/java/com/twilio/rest/flexapi/v1/Assessments.java index 39da462b7f..7bade94c98 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/Assessments.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/Assessments.java @@ -22,47 +22,78 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; +import java.math.BigDecimal; import java.net.URI; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; -import java.math.BigDecimal; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Assessments extends Resource { + private static final long serialVersionUID = 249351913918322L; - public static AssessmentsCreator creator(final String categorySid, final String categoryName, final String segmentId, final String agentId, final BigDecimal offset, final String metricId, final String metricName, final String answerText, final String answerId, final String questionnaireSid){ - return new AssessmentsCreator(categorySid, categoryName, segmentId, agentId, offset, metricId, metricName, answerText, answerId, questionnaireSid); + public static AssessmentsCreator creator( + final String categorySid, + final String categoryName, + final String segmentId, + final String agentId, + final BigDecimal offset, + final String metricId, + final String metricName, + final String answerText, + final String answerId, + final String questionnaireSid + ) { + return new AssessmentsCreator( + categorySid, + categoryName, + segmentId, + agentId, + offset, + metricId, + metricName, + answerText, + answerId, + questionnaireSid + ); } - public static AssessmentsReader reader(){ + public static AssessmentsReader reader() { return new AssessmentsReader(); } - public static AssessmentsUpdater updater(final String pathAssessmentSid, final BigDecimal offset, final String answerText, final String answerId){ - return new AssessmentsUpdater(pathAssessmentSid, offset, answerText, answerId); + public static AssessmentsUpdater updater( + final String pathAssessmentSid, + final BigDecimal offset, + final String answerText, + final String answerId + ) { + return new AssessmentsUpdater( + pathAssessmentSid, + offset, + answerText, + answerId + ); } /** - * Converts a JSON String into a Assessments object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Assessments object represented by the provided JSON - */ - public static Assessments fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Assessments object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Assessments object represented by the provided JSON + */ + public static Assessments fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Assessments.class); @@ -74,14 +105,17 @@ public static Assessments fromJson(final String json, final ObjectMapper objectM } /** - * Converts a JSON InputStream into a Assessments object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Assessments object represented by the provided JSON - */ - public static Assessments fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Assessments object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Assessments object represented by the provided JSON + */ + public static Assessments fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Assessments.class); @@ -109,47 +143,20 @@ public static Assessments fromJson(final InputStream json, final ObjectMapper ob @JsonCreator private Assessments( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("assessment_sid") - final String assessmentSid, - - @JsonProperty("offset") - final BigDecimal offset, - - @JsonProperty("report") - final Boolean report, - - @JsonProperty("weight") - final BigDecimal weight, - - @JsonProperty("agent_id") - final String agentId, - - @JsonProperty("segment_id") - final String segmentId, - - @JsonProperty("user_name") - final String userName, - - @JsonProperty("user_email") - final String userEmail, - - @JsonProperty("answer_text") - final String answerText, - - @JsonProperty("answer_id") - final String answerId, - - @JsonProperty("assessment") - final Map assessment, - - @JsonProperty("timestamp") - final BigDecimal timestamp, - - @JsonProperty("url") - final URI url + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("assessment_sid") final String assessmentSid, + @JsonProperty("offset") final BigDecimal offset, + @JsonProperty("report") final Boolean report, + @JsonProperty("weight") final BigDecimal weight, + @JsonProperty("agent_id") final String agentId, + @JsonProperty("segment_id") final String segmentId, + @JsonProperty("user_name") final String userName, + @JsonProperty("user_email") final String userEmail, + @JsonProperty("answer_text") final String answerText, + @JsonProperty("answer_id") final String answerId, + @JsonProperty("assessment") final Map assessment, + @JsonProperty("timestamp") final BigDecimal timestamp, + @JsonProperty("url") final URI url ) { this.accountSid = accountSid; this.assessmentSid = assessmentSid; @@ -167,52 +174,65 @@ private Assessments( this.url = url; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getAssessmentSid() { - return this.assessmentSid; - } - public final BigDecimal getOffset() { - return this.offset; - } - public final Boolean getReport() { - return this.report; - } - public final BigDecimal getWeight() { - return this.weight; - } - public final String getAgentId() { - return this.agentId; - } - public final String getSegmentId() { - return this.segmentId; - } - public final String getUserName() { - return this.userName; - } - public final String getUserEmail() { - return this.userEmail; - } - public final String getAnswerText() { - return this.answerText; - } - public final String getAnswerId() { - return this.answerId; - } - public final Map getAssessment() { - return this.assessment; - } - public final BigDecimal getTimestamp() { - return this.timestamp; - } - public final URI getUrl() { - return this.url; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getAssessmentSid() { + return this.assessmentSid; + } + + public final BigDecimal getOffset() { + return this.offset; + } + + public final Boolean getReport() { + return this.report; + } + + public final BigDecimal getWeight() { + return this.weight; + } + + public final String getAgentId() { + return this.agentId; + } + + public final String getSegmentId() { + return this.segmentId; + } + + public final String getUserName() { + return this.userName; + } + + public final String getUserEmail() { + return this.userEmail; + } + + public final String getAnswerText() { + return this.answerText; + } + + public final String getAnswerId() { + return this.answerId; + } + + public final Map getAssessment() { + return this.assessment; + } + + public final BigDecimal getTimestamp() { + return this.timestamp; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -222,13 +242,41 @@ public boolean equals(final Object o) { Assessments other = (Assessments) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(assessmentSid, other.assessmentSid) && Objects.equals(offset, other.offset) && Objects.equals(report, other.report) && Objects.equals(weight, other.weight) && Objects.equals(agentId, other.agentId) && Objects.equals(segmentId, other.segmentId) && Objects.equals(userName, other.userName) && Objects.equals(userEmail, other.userEmail) && Objects.equals(answerText, other.answerText) && Objects.equals(answerId, other.answerId) && Objects.equals(assessment, other.assessment) && Objects.equals(timestamp, other.timestamp) && Objects.equals(url, other.url) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(assessmentSid, other.assessmentSid) && + Objects.equals(offset, other.offset) && + Objects.equals(report, other.report) && + Objects.equals(weight, other.weight) && + Objects.equals(agentId, other.agentId) && + Objects.equals(segmentId, other.segmentId) && + Objects.equals(userName, other.userName) && + Objects.equals(userEmail, other.userEmail) && + Objects.equals(answerText, other.answerText) && + Objects.equals(answerId, other.answerId) && + Objects.equals(assessment, other.assessment) && + Objects.equals(timestamp, other.timestamp) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, assessmentSid, offset, report, weight, agentId, segmentId, userName, userEmail, answerText, answerId, assessment, timestamp, url); + return Objects.hash( + accountSid, + assessmentSid, + offset, + report, + weight, + agentId, + segmentId, + userName, + userEmail, + answerText, + answerId, + assessment, + timestamp, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/flexapi/v1/AssessmentsCreator.java b/src/main/java/com/twilio/rest/flexapi/v1/AssessmentsCreator.java index 42d9863ee6..cfa20c6071 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/AssessmentsCreator.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/AssessmentsCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.flexapi.v1; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -26,10 +27,8 @@ import java.math.BigDecimal; import java.math.BigDecimal; +public class AssessmentsCreator extends Creator { - - -public class AssessmentsCreator extends Creator{ private String categorySid; private String categoryName; private String segmentId; @@ -42,7 +41,18 @@ public class AssessmentsCreator extends Creator{ private String questionnaireSid; private String authorization; - public AssessmentsCreator(final String categorySid, final String categoryName, final String segmentId, final String agentId, final BigDecimal offset, final String metricId, final String metricName, final String answerText, final String answerId, final String questionnaireSid) { + public AssessmentsCreator( + final String categorySid, + final String categoryName, + final String segmentId, + final String agentId, + final BigDecimal offset, + final String metricId, + final String metricName, + final String answerText, + final String answerId, + final String questionnaireSid + ) { this.categorySid = categorySid; this.categoryName = categoryName; this.segmentId = segmentId; @@ -55,132 +65,158 @@ public AssessmentsCreator(final String categorySid, final String categoryName, f this.questionnaireSid = questionnaireSid; } - public AssessmentsCreator setCategorySid(final String categorySid){ + public AssessmentsCreator setCategorySid(final String categorySid) { this.categorySid = categorySid; return this; } - public AssessmentsCreator setCategoryName(final String categoryName){ + + public AssessmentsCreator setCategoryName(final String categoryName) { this.categoryName = categoryName; return this; } - public AssessmentsCreator setSegmentId(final String segmentId){ + + public AssessmentsCreator setSegmentId(final String segmentId) { this.segmentId = segmentId; return this; } - public AssessmentsCreator setAgentId(final String agentId){ + + public AssessmentsCreator setAgentId(final String agentId) { this.agentId = agentId; return this; } - public AssessmentsCreator setOffset(final BigDecimal offset){ + + public AssessmentsCreator setOffset(final BigDecimal offset) { this.offset = offset; return this; } - public AssessmentsCreator setMetricId(final String metricId){ + + public AssessmentsCreator setMetricId(final String metricId) { this.metricId = metricId; return this; } - public AssessmentsCreator setMetricName(final String metricName){ + + public AssessmentsCreator setMetricName(final String metricName) { this.metricName = metricName; return this; } - public AssessmentsCreator setAnswerText(final String answerText){ + + public AssessmentsCreator setAnswerText(final String answerText) { this.answerText = answerText; return this; } - public AssessmentsCreator setAnswerId(final String answerId){ + + public AssessmentsCreator setAnswerId(final String answerId) { this.answerId = answerId; return this; } - public AssessmentsCreator setQuestionnaireSid(final String questionnaireSid){ + + public AssessmentsCreator setQuestionnaireSid( + final String questionnaireSid + ) { this.questionnaireSid = questionnaireSid; return this; } - public AssessmentsCreator setAuthorization(final String authorization){ + + public AssessmentsCreator setAuthorization(final String authorization) { this.authorization = authorization; return this; } @Override - public Assessments create(final TwilioRestClient client){ + public Assessments create(final TwilioRestClient client) { String path = "/v1/Insights/QualityManagement/Assessments"; - path = path.replace("{"+"CategorySid"+"}", this.categorySid.toString()); - path = path.replace("{"+"CategoryName"+"}", this.categoryName.toString()); - path = path.replace("{"+"SegmentId"+"}", this.segmentId.toString()); - path = path.replace("{"+"AgentId"+"}", this.agentId.toString()); - path = path.replace("{"+"Offset"+"}", this.offset.toString()); - path = path.replace("{"+"MetricId"+"}", this.metricId.toString()); - path = path.replace("{"+"MetricName"+"}", this.metricName.toString()); - path = path.replace("{"+"AnswerText"+"}", this.answerText.toString()); - path = path.replace("{"+"AnswerId"+"}", this.answerId.toString()); - path = path.replace("{"+"QuestionnaireSid"+"}", this.questionnaireSid.toString()); + path = + path.replace( + "{" + "CategorySid" + "}", + this.categorySid.toString() + ); + path = + path.replace( + "{" + "CategoryName" + "}", + this.categoryName.toString() + ); + path = path.replace("{" + "SegmentId" + "}", this.segmentId.toString()); + path = path.replace("{" + "AgentId" + "}", this.agentId.toString()); + path = path.replace("{" + "Offset" + "}", this.offset.toString()); + path = path.replace("{" + "MetricId" + "}", this.metricId.toString()); + path = + path.replace("{" + "MetricName" + "}", this.metricName.toString()); + path = + path.replace("{" + "AnswerText" + "}", this.answerText.toString()); + path = path.replace("{" + "AnswerId" + "}", this.answerId.toString()); + path = + path.replace( + "{" + "QuestionnaireSid" + "}", + this.questionnaireSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.FLEXAPI.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); addHeaderParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Assessments creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Assessments creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Assessments.fromJson(response.getStream(), client.getObjectMapper()); + return Assessments.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (categorySid != null) { request.addPostParam("CategorySid", categorySid); - } if (categoryName != null) { request.addPostParam("CategoryName", categoryName); - } if (segmentId != null) { request.addPostParam("SegmentId", segmentId); - } if (agentId != null) { request.addPostParam("AgentId", agentId); - } if (offset != null) { request.addPostParam("Offset", offset.toString()); - } if (metricId != null) { request.addPostParam("MetricId", metricId); - } if (metricName != null) { request.addPostParam("MetricName", metricName); - } if (answerText != null) { request.addPostParam("AnswerText", answerText); - } if (answerId != null) { request.addPostParam("AnswerId", answerId); - } if (questionnaireSid != null) { request.addPostParam("QuestionnaireSid", questionnaireSid); - } } + private void addHeaderParams(final Request request) { if (authorization != null) { request.addHeaderParam("Authorization", authorization); - } } } diff --git a/src/main/java/com/twilio/rest/flexapi/v1/AssessmentsReader.java b/src/main/java/com/twilio/rest/flexapi/v1/AssessmentsReader.java index 766e1cdf21..ca340afdb5 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/AssessmentsReader.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/AssessmentsReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.flexapi.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,27 +25,26 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class AssessmentsReader extends Reader { + private String authorization; private String segmentId; private Integer pageSize; - public AssessmentsReader(){ - } + public AssessmentsReader() {} - public AssessmentsReader setAuthorization(final String authorization){ + public AssessmentsReader setAuthorization(final String authorization) { this.authorization = authorization; return this; } - public AssessmentsReader setSegmentId(final String segmentId){ + + public AssessmentsReader setSegmentId(final String segmentId) { this.segmentId = segmentId; return this; } - public AssessmentsReader setPageSize(final Integer pageSize){ + + public AssessmentsReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -68,13 +68,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Assessments read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Assessments read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -90,7 +98,10 @@ private Page pageForRequest(final TwilioRestClient client, final Re } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.FLEXAPI.toString()) @@ -98,9 +109,11 @@ public Page previousPage(final Page page, final Twilio return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.FLEXAPI.toString()) @@ -109,31 +122,30 @@ public Page nextPage(final Page page, final TwilioRest } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addHeaderParams(final Request request) { if (authorization != null) { request.addHeaderParam("Authorization", authorization); - } } + private void addQueryParams(final Request request) { if (segmentId != null) { - request.addQueryParam("SegmentId", segmentId); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/flexapi/v1/AssessmentsUpdater.java b/src/main/java/com/twilio/rest/flexapi/v1/AssessmentsUpdater.java index e2a07e1cb5..8d028146f3 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/AssessmentsUpdater.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/AssessmentsUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.flexapi.v1; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -23,89 +24,108 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.math.BigDecimal; +public class AssessmentsUpdater extends Updater { - -public class AssessmentsUpdater extends Updater{ private String pathAssessmentSid; private BigDecimal offset; private String answerText; private String answerId; private String authorization; - public AssessmentsUpdater(final String pathAssessmentSid, final BigDecimal offset, final String answerText, final String answerId){ + public AssessmentsUpdater( + final String pathAssessmentSid, + final BigDecimal offset, + final String answerText, + final String answerId + ) { this.pathAssessmentSid = pathAssessmentSid; this.offset = offset; this.answerText = answerText; this.answerId = answerId; } - public AssessmentsUpdater setOffset(final BigDecimal offset){ + public AssessmentsUpdater setOffset(final BigDecimal offset) { this.offset = offset; return this; } - public AssessmentsUpdater setAnswerText(final String answerText){ + + public AssessmentsUpdater setAnswerText(final String answerText) { this.answerText = answerText; return this; } - public AssessmentsUpdater setAnswerId(final String answerId){ + + public AssessmentsUpdater setAnswerId(final String answerId) { this.answerId = answerId; return this; } - public AssessmentsUpdater setAuthorization(final String authorization){ + + public AssessmentsUpdater setAuthorization(final String authorization) { this.authorization = authorization; return this; } @Override - public Assessments update(final TwilioRestClient client){ - String path = "/v1/Insights/QualityManagement/Assessments/{AssessmentSid}"; + public Assessments update(final TwilioRestClient client) { + String path = + "/v1/Insights/QualityManagement/Assessments/{AssessmentSid}"; - path = path.replace("{"+"AssessmentSid"+"}", this.pathAssessmentSid.toString()); - path = path.replace("{"+"Offset"+"}", this.offset.toString()); - path = path.replace("{"+"AnswerText"+"}", this.answerText.toString()); - path = path.replace("{"+"AnswerId"+"}", this.answerId.toString()); + path = + path.replace( + "{" + "AssessmentSid" + "}", + this.pathAssessmentSid.toString() + ); + path = path.replace("{" + "Offset" + "}", this.offset.toString()); + path = + path.replace("{" + "AnswerText" + "}", this.answerText.toString()); + path = path.replace("{" + "AnswerId" + "}", this.answerId.toString()); Request request = new Request( HttpMethod.POST, Domains.FLEXAPI.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); addHeaderParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Assessments update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Assessments update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Assessments.fromJson(response.getStream(), client.getObjectMapper()); + return Assessments.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (offset != null) { request.addPostParam("Offset", offset.toString()); - } if (answerText != null) { request.addPostParam("AnswerText", answerText); - } if (answerId != null) { request.addPostParam("AnswerId", answerId); - } } + private void addHeaderParams(final Request request) { if (authorization != null) { request.addHeaderParam("Authorization", authorization); - } } } diff --git a/src/main/java/com/twilio/rest/flexapi/v1/Channel.java b/src/main/java/com/twilio/rest/flexapi/v1/Channel.java index 1fbf57d1a0..bde09c99f7 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/Channel.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/Channel.java @@ -23,49 +23,58 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Channel extends Resource { + private static final long serialVersionUID = 86822994047371L; - public static ChannelCreator creator(final String flexFlowSid, final String identity, final String chatUserFriendlyName, final String chatFriendlyName){ - return new ChannelCreator(flexFlowSid, identity, chatUserFriendlyName, chatFriendlyName); + public static ChannelCreator creator( + final String flexFlowSid, + final String identity, + final String chatUserFriendlyName, + final String chatFriendlyName + ) { + return new ChannelCreator( + flexFlowSid, + identity, + chatUserFriendlyName, + chatFriendlyName + ); } - public static ChannelDeleter deleter(final String pathSid){ + public static ChannelDeleter deleter(final String pathSid) { return new ChannelDeleter(pathSid); } - public static ChannelFetcher fetcher(final String pathSid){ + public static ChannelFetcher fetcher(final String pathSid) { return new ChannelFetcher(pathSid); } - public static ChannelReader reader(){ + public static ChannelReader reader() { return new ChannelReader(); } /** - * Converts a JSON String into a Channel object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Channel object represented by the provided JSON - */ - public static Channel fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Channel object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Channel object represented by the provided JSON + */ + public static Channel fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Channel.class); @@ -77,14 +86,17 @@ public static Channel fromJson(final String json, final ObjectMapper objectMappe } /** - * Converts a JSON InputStream into a Channel object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Channel object represented by the provided JSON - */ - public static Channel fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Channel object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Channel object represented by the provided JSON + */ + public static Channel fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Channel.class); @@ -106,29 +118,14 @@ public static Channel fromJson(final InputStream json, final ObjectMapper object @JsonCreator private Channel( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("flex_flow_sid") - final String flexFlowSid, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("user_sid") - final String userSid, - - @JsonProperty("task_sid") - final String taskSid, - - @JsonProperty("url") - final URI url, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("flex_flow_sid") final String flexFlowSid, + @JsonProperty("sid") final String sid, + @JsonProperty("user_sid") final String userSid, + @JsonProperty("task_sid") final String taskSid, + @JsonProperty("url") final URI url, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated ) { this.accountSid = accountSid; this.flexFlowSid = flexFlowSid; @@ -140,34 +137,41 @@ private Channel( this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); } - public final String getAccountSid() { - return this.accountSid; - } - public final String getFlexFlowSid() { - return this.flexFlowSid; - } - public final String getSid() { - return this.sid; - } - public final String getUserSid() { - return this.userSid; - } - public final String getTaskSid() { - return this.taskSid; - } - public final URI getUrl() { - return this.url; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getFlexFlowSid() { + return this.flexFlowSid; + } + + public final String getSid() { + return this.sid; + } + + public final String getUserSid() { + return this.userSid; + } + + public final String getTaskSid() { + return this.taskSid; + } + + public final URI getUrl() { + return this.url; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -177,13 +181,29 @@ public boolean equals(final Object o) { Channel other = (Channel) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(flexFlowSid, other.flexFlowSid) && Objects.equals(sid, other.sid) && Objects.equals(userSid, other.userSid) && Objects.equals(taskSid, other.taskSid) && Objects.equals(url, other.url) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(flexFlowSid, other.flexFlowSid) && + Objects.equals(sid, other.sid) && + Objects.equals(userSid, other.userSid) && + Objects.equals(taskSid, other.taskSid) && + Objects.equals(url, other.url) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, flexFlowSid, sid, userSid, taskSid, url, dateCreated, dateUpdated); + return Objects.hash( + accountSid, + flexFlowSid, + sid, + userSid, + taskSid, + url, + dateCreated, + dateUpdated + ); } - } - diff --git a/src/main/java/com/twilio/rest/flexapi/v1/ChannelCreator.java b/src/main/java/com/twilio/rest/flexapi/v1/ChannelCreator.java index 81d11f4c47..d5b9ad3141 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/ChannelCreator.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/ChannelCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.flexapi.v1; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class ChannelCreator extends Creator { - - -public class ChannelCreator extends Creator{ private String flexFlowSid; private String identity; private String chatUserFriendlyName; @@ -39,74 +38,108 @@ public class ChannelCreator extends Creator{ private String taskAttributes; private Boolean longLived; - public ChannelCreator(final String flexFlowSid, final String identity, final String chatUserFriendlyName, final String chatFriendlyName) { + public ChannelCreator( + final String flexFlowSid, + final String identity, + final String chatUserFriendlyName, + final String chatFriendlyName + ) { this.flexFlowSid = flexFlowSid; this.identity = identity; this.chatUserFriendlyName = chatUserFriendlyName; this.chatFriendlyName = chatFriendlyName; } - public ChannelCreator setFlexFlowSid(final String flexFlowSid){ + public ChannelCreator setFlexFlowSid(final String flexFlowSid) { this.flexFlowSid = flexFlowSid; return this; } - public ChannelCreator setIdentity(final String identity){ + + public ChannelCreator setIdentity(final String identity) { this.identity = identity; return this; } - public ChannelCreator setChatUserFriendlyName(final String chatUserFriendlyName){ + + public ChannelCreator setChatUserFriendlyName( + final String chatUserFriendlyName + ) { this.chatUserFriendlyName = chatUserFriendlyName; return this; } - public ChannelCreator setChatFriendlyName(final String chatFriendlyName){ + + public ChannelCreator setChatFriendlyName(final String chatFriendlyName) { this.chatFriendlyName = chatFriendlyName; return this; } - public ChannelCreator setTarget(final String target){ + + public ChannelCreator setTarget(final String target) { this.target = target; return this; } - public ChannelCreator setChatUniqueName(final String chatUniqueName){ + + public ChannelCreator setChatUniqueName(final String chatUniqueName) { this.chatUniqueName = chatUniqueName; return this; } - public ChannelCreator setPreEngagementData(final String preEngagementData){ + + public ChannelCreator setPreEngagementData(final String preEngagementData) { this.preEngagementData = preEngagementData; return this; } - public ChannelCreator setTaskSid(final String taskSid){ + + public ChannelCreator setTaskSid(final String taskSid) { this.taskSid = taskSid; return this; } - public ChannelCreator setTaskAttributes(final String taskAttributes){ + + public ChannelCreator setTaskAttributes(final String taskAttributes) { this.taskAttributes = taskAttributes; return this; } - public ChannelCreator setLongLived(final Boolean longLived){ + + public ChannelCreator setLongLived(final Boolean longLived) { this.longLived = longLived; return this; } @Override - public Channel create(final TwilioRestClient client){ + public Channel create(final TwilioRestClient client) { String path = "/v1/Channels"; - path = path.replace("{"+"FlexFlowSid"+"}", this.flexFlowSid.toString()); - path = path.replace("{"+"Identity"+"}", this.identity.toString()); - path = path.replace("{"+"ChatUserFriendlyName"+"}", this.chatUserFriendlyName.toString()); - path = path.replace("{"+"ChatFriendlyName"+"}", this.chatFriendlyName.toString()); + path = + path.replace( + "{" + "FlexFlowSid" + "}", + this.flexFlowSid.toString() + ); + path = path.replace("{" + "Identity" + "}", this.identity.toString()); + path = + path.replace( + "{" + "ChatUserFriendlyName" + "}", + this.chatUserFriendlyName.toString() + ); + path = + path.replace( + "{" + "ChatFriendlyName" + "}", + this.chatFriendlyName.toString() + ); Request request = new Request( HttpMethod.POST, Domains.FLEXAPI.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Channel creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Channel creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -115,46 +148,37 @@ public Channel create(final TwilioRestClient client){ return Channel.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (flexFlowSid != null) { request.addPostParam("FlexFlowSid", flexFlowSid); - } if (identity != null) { request.addPostParam("Identity", identity); - } if (chatUserFriendlyName != null) { request.addPostParam("ChatUserFriendlyName", chatUserFriendlyName); - } if (chatFriendlyName != null) { request.addPostParam("ChatFriendlyName", chatFriendlyName); - } if (target != null) { request.addPostParam("Target", target); - } if (chatUniqueName != null) { request.addPostParam("ChatUniqueName", chatUniqueName); - } if (preEngagementData != null) { request.addPostParam("PreEngagementData", preEngagementData); - } if (taskSid != null) { request.addPostParam("TaskSid", taskSid); - } if (taskAttributes != null) { request.addPostParam("TaskAttributes", taskAttributes); - } if (longLived != null) { request.addPostParam("LongLived", longLived.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/flexapi/v1/ChannelDeleter.java b/src/main/java/com/twilio/rest/flexapi/v1/ChannelDeleter.java index 1e92acaf27..49510f0a31 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/ChannelDeleter.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/ChannelDeleter.java @@ -24,21 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class ChannelDeleter extends Deleter { + private String pathSid; - public ChannelDeleter(final String pathSid){ + public ChannelDeleter(final String pathSid) { this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Channels/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -48,9 +46,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Channel delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Channel delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/flexapi/v1/ChannelFetcher.java b/src/main/java/com/twilio/rest/flexapi/v1/ChannelFetcher.java index acd078c0fb..bdf3d84dae 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/ChannelFetcher.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/ChannelFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class ChannelFetcher extends Fetcher { + private String pathSid; - public ChannelFetcher(final String pathSid){ + public ChannelFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public Channel fetch(final TwilioRestClient client) { String path = "/v1/Channels/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,9 +46,14 @@ public Channel fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Channel fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Channel fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/flexapi/v1/ChannelReader.java b/src/main/java/com/twilio/rest/flexapi/v1/ChannelReader.java index 4832c11d8e..cf62b2674c 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/ChannelReader.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/ChannelReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.flexapi.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,17 +25,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class ChannelReader extends Reader { + private Integer pageSize; - public ChannelReader(){ - } + public ChannelReader() {} - public ChannelReader setPageSize(final Integer pageSize){ + public ChannelReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -57,13 +55,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Channel read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Channel read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -79,7 +85,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reques } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.FLEXAPI.toString()) @@ -87,9 +96,11 @@ public Page previousPage(final Page page, final TwilioRestClie return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.FLEXAPI.toString()) @@ -98,21 +109,21 @@ public Page nextPage(final Page page, final TwilioRestClient c } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/flexapi/v1/Configuration.java b/src/main/java/com/twilio/rest/flexapi/v1/Configuration.java index 2ab066e26b..0fbcfaa1dd 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/Configuration.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/Configuration.java @@ -24,40 +24,39 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.List; import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Configuration extends Resource { + private static final long serialVersionUID = 184471195219828L; - public static ConfigurationFetcher fetcher(){ + public static ConfigurationFetcher fetcher() { return new ConfigurationFetcher(); } /** - * Converts a JSON String into a Configuration object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Configuration object represented by the provided JSON - */ - public static Configuration fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Configuration object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Configuration object represented by the provided JSON + */ + public static Configuration fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Configuration.class); @@ -69,14 +68,17 @@ public static Configuration fromJson(final String json, final ObjectMapper objec } /** - * Converts a JSON InputStream into a Configuration object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Configuration object represented by the provided JSON - */ - public static Configuration fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Configuration object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Configuration object represented by the provided JSON + */ + public static Configuration fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Configuration.class); @@ -86,6 +88,7 @@ public static Configuration fromJson(final InputStream json, final ObjectMapper throw new ApiConnectionException(e.getMessage(), e); } } + public enum Status { OK("ok"), INPROGRESS("inprogress"), @@ -155,140 +158,103 @@ public static Status forValue(final String value) { @JsonCreator private Configuration( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("attributes") - final Map attributes, - - @JsonProperty("status") - final Configuration.Status status, - - @JsonProperty("taskrouter_workspace_sid") - final String taskrouterWorkspaceSid, - - @JsonProperty("taskrouter_target_workflow_sid") - final String taskrouterTargetWorkflowSid, - - @JsonProperty("taskrouter_target_taskqueue_sid") - final String taskrouterTargetTaskqueueSid, - - @JsonProperty("taskrouter_taskqueues") - final List> taskrouterTaskqueues, - - @JsonProperty("taskrouter_skills") - final List> taskrouterSkills, - - @JsonProperty("taskrouter_worker_channels") - final Map taskrouterWorkerChannels, - - @JsonProperty("taskrouter_worker_attributes") - final Map taskrouterWorkerAttributes, - - @JsonProperty("taskrouter_offline_activity_sid") - final String taskrouterOfflineActivitySid, - - @JsonProperty("runtime_domain") - final URI runtimeDomain, - - @JsonProperty("messaging_service_instance_sid") - final String messagingServiceInstanceSid, - - @JsonProperty("chat_service_instance_sid") - final String chatServiceInstanceSid, - - @JsonProperty("flex_service_instance_sid") - final String flexServiceInstanceSid, - - @JsonProperty("ui_language") - final String uiLanguage, - - @JsonProperty("ui_attributes") - final Map uiAttributes, - - @JsonProperty("ui_dependencies") - final Map uiDependencies, - - @JsonProperty("ui_version") - final String uiVersion, - - @JsonProperty("service_version") - final String serviceVersion, - - @JsonProperty("call_recording_enabled") - final Boolean callRecordingEnabled, - - @JsonProperty("call_recording_webhook_url") - final URI callRecordingWebhookUrl, - - @JsonProperty("crm_enabled") - final Boolean crmEnabled, - - @JsonProperty("crm_type") - final String crmType, - - @JsonProperty("crm_callback_url") - final URI crmCallbackUrl, - - @JsonProperty("crm_fallback_url") - final URI crmFallbackUrl, - - @JsonProperty("crm_attributes") - final Map crmAttributes, - - @JsonProperty("public_attributes") - final Map publicAttributes, - - @JsonProperty("plugin_service_enabled") - final Boolean pluginServiceEnabled, - - @JsonProperty("plugin_service_attributes") - final Map pluginServiceAttributes, - - @JsonProperty("integrations") - final List> integrations, - - @JsonProperty("outbound_call_flows") - final Map outboundCallFlows, - - @JsonProperty("serverless_service_sids") - final List serverlessServiceSids, - - @JsonProperty("queue_stats_configuration") - final Map queueStatsConfiguration, - - @JsonProperty("notifications") - final Map notifications, - - @JsonProperty("markdown") - final Map markdown, - - @JsonProperty("url") - final URI url, - - @JsonProperty("flex_insights_hr") - final Map flexInsightsHr, - - @JsonProperty("flex_insights_drilldown") - final Boolean flexInsightsDrilldown, - - @JsonProperty("flex_url") - final URI flexUrl, - - @JsonProperty("channel_configs") - final List> channelConfigs, - - @JsonProperty("debugger_integration") - final Map debuggerIntegration, - - @JsonProperty("flex_ui_status_report") - final Map flexUiStatusReport + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("attributes") final Map attributes, + @JsonProperty("status") final Configuration.Status status, + @JsonProperty( + "taskrouter_workspace_sid" + ) final String taskrouterWorkspaceSid, + @JsonProperty( + "taskrouter_target_workflow_sid" + ) final String taskrouterTargetWorkflowSid, + @JsonProperty( + "taskrouter_target_taskqueue_sid" + ) final String taskrouterTargetTaskqueueSid, + @JsonProperty( + "taskrouter_taskqueues" + ) final List> taskrouterTaskqueues, + @JsonProperty( + "taskrouter_skills" + ) final List> taskrouterSkills, + @JsonProperty( + "taskrouter_worker_channels" + ) final Map taskrouterWorkerChannels, + @JsonProperty( + "taskrouter_worker_attributes" + ) final Map taskrouterWorkerAttributes, + @JsonProperty( + "taskrouter_offline_activity_sid" + ) final String taskrouterOfflineActivitySid, + @JsonProperty("runtime_domain") final URI runtimeDomain, + @JsonProperty( + "messaging_service_instance_sid" + ) final String messagingServiceInstanceSid, + @JsonProperty( + "chat_service_instance_sid" + ) final String chatServiceInstanceSid, + @JsonProperty( + "flex_service_instance_sid" + ) final String flexServiceInstanceSid, + @JsonProperty("ui_language") final String uiLanguage, + @JsonProperty("ui_attributes") final Map uiAttributes, + @JsonProperty( + "ui_dependencies" + ) final Map uiDependencies, + @JsonProperty("ui_version") final String uiVersion, + @JsonProperty("service_version") final String serviceVersion, + @JsonProperty( + "call_recording_enabled" + ) final Boolean callRecordingEnabled, + @JsonProperty( + "call_recording_webhook_url" + ) final URI callRecordingWebhookUrl, + @JsonProperty("crm_enabled") final Boolean crmEnabled, + @JsonProperty("crm_type") final String crmType, + @JsonProperty("crm_callback_url") final URI crmCallbackUrl, + @JsonProperty("crm_fallback_url") final URI crmFallbackUrl, + @JsonProperty("crm_attributes") final Map crmAttributes, + @JsonProperty( + "public_attributes" + ) final Map publicAttributes, + @JsonProperty( + "plugin_service_enabled" + ) final Boolean pluginServiceEnabled, + @JsonProperty( + "plugin_service_attributes" + ) final Map pluginServiceAttributes, + @JsonProperty( + "integrations" + ) final List> integrations, + @JsonProperty( + "outbound_call_flows" + ) final Map outboundCallFlows, + @JsonProperty( + "serverless_service_sids" + ) final List serverlessServiceSids, + @JsonProperty( + "queue_stats_configuration" + ) final Map queueStatsConfiguration, + @JsonProperty("notifications") final Map notifications, + @JsonProperty("markdown") final Map markdown, + @JsonProperty("url") final URI url, + @JsonProperty( + "flex_insights_hr" + ) final Map flexInsightsHr, + @JsonProperty( + "flex_insights_drilldown" + ) final Boolean flexInsightsDrilldown, + @JsonProperty("flex_url") final URI flexUrl, + @JsonProperty( + "channel_configs" + ) final List> channelConfigs, + @JsonProperty( + "debugger_integration" + ) final Map debuggerIntegration, + @JsonProperty( + "flex_ui_status_report" + ) final Map flexUiStatusReport ) { this.accountSid = accountSid; this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); @@ -337,145 +303,189 @@ private Configuration( this.flexUiStatusReport = flexUiStatusReport; } - public final String getAccountSid() { - return this.accountSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final Map getAttributes() { - return this.attributes; - } - public final Configuration.Status getStatus() { - return this.status; - } - public final String getTaskrouterWorkspaceSid() { - return this.taskrouterWorkspaceSid; - } - public final String getTaskrouterTargetWorkflowSid() { - return this.taskrouterTargetWorkflowSid; - } - public final String getTaskrouterTargetTaskqueueSid() { - return this.taskrouterTargetTaskqueueSid; - } - public final List> getTaskrouterTaskqueues() { - return this.taskrouterTaskqueues; - } - public final List> getTaskrouterSkills() { - return this.taskrouterSkills; - } - public final Map getTaskrouterWorkerChannels() { - return this.taskrouterWorkerChannels; - } - public final Map getTaskrouterWorkerAttributes() { - return this.taskrouterWorkerAttributes; - } - public final String getTaskrouterOfflineActivitySid() { - return this.taskrouterOfflineActivitySid; - } - public final URI getRuntimeDomain() { - return this.runtimeDomain; - } - public final String getMessagingServiceInstanceSid() { - return this.messagingServiceInstanceSid; - } - public final String getChatServiceInstanceSid() { - return this.chatServiceInstanceSid; - } - public final String getFlexServiceInstanceSid() { - return this.flexServiceInstanceSid; - } - public final String getUiLanguage() { - return this.uiLanguage; - } - public final Map getUiAttributes() { - return this.uiAttributes; - } - public final Map getUiDependencies() { - return this.uiDependencies; - } - public final String getUiVersion() { - return this.uiVersion; - } - public final String getServiceVersion() { - return this.serviceVersion; - } - public final Boolean getCallRecordingEnabled() { - return this.callRecordingEnabled; - } - public final URI getCallRecordingWebhookUrl() { - return this.callRecordingWebhookUrl; - } - public final Boolean getCrmEnabled() { - return this.crmEnabled; - } - public final String getCrmType() { - return this.crmType; - } - public final URI getCrmCallbackUrl() { - return this.crmCallbackUrl; - } - public final URI getCrmFallbackUrl() { - return this.crmFallbackUrl; - } - public final Map getCrmAttributes() { - return this.crmAttributes; - } - public final Map getPublicAttributes() { - return this.publicAttributes; - } - public final Boolean getPluginServiceEnabled() { - return this.pluginServiceEnabled; - } - public final Map getPluginServiceAttributes() { - return this.pluginServiceAttributes; - } - public final List> getIntegrations() { - return this.integrations; - } - public final Map getOutboundCallFlows() { - return this.outboundCallFlows; - } - public final List getServerlessServiceSids() { - return this.serverlessServiceSids; - } - public final Map getQueueStatsConfiguration() { - return this.queueStatsConfiguration; - } - public final Map getNotifications() { - return this.notifications; - } - public final Map getMarkdown() { - return this.markdown; - } - public final URI getUrl() { - return this.url; - } - public final Map getFlexInsightsHr() { - return this.flexInsightsHr; - } - public final Boolean getFlexInsightsDrilldown() { - return this.flexInsightsDrilldown; - } - public final URI getFlexUrl() { - return this.flexUrl; - } - public final List> getChannelConfigs() { - return this.channelConfigs; - } - public final Map getDebuggerIntegration() { - return this.debuggerIntegration; - } - public final Map getFlexUiStatusReport() { - return this.flexUiStatusReport; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final Map getAttributes() { + return this.attributes; + } + + public final Configuration.Status getStatus() { + return this.status; + } + + public final String getTaskrouterWorkspaceSid() { + return this.taskrouterWorkspaceSid; + } + + public final String getTaskrouterTargetWorkflowSid() { + return this.taskrouterTargetWorkflowSid; + } + + public final String getTaskrouterTargetTaskqueueSid() { + return this.taskrouterTargetTaskqueueSid; + } + + public final List> getTaskrouterTaskqueues() { + return this.taskrouterTaskqueues; + } + + public final List> getTaskrouterSkills() { + return this.taskrouterSkills; + } + + public final Map getTaskrouterWorkerChannels() { + return this.taskrouterWorkerChannels; + } + + public final Map getTaskrouterWorkerAttributes() { + return this.taskrouterWorkerAttributes; + } + + public final String getTaskrouterOfflineActivitySid() { + return this.taskrouterOfflineActivitySid; + } + + public final URI getRuntimeDomain() { + return this.runtimeDomain; + } + + public final String getMessagingServiceInstanceSid() { + return this.messagingServiceInstanceSid; + } + + public final String getChatServiceInstanceSid() { + return this.chatServiceInstanceSid; + } + + public final String getFlexServiceInstanceSid() { + return this.flexServiceInstanceSid; + } + + public final String getUiLanguage() { + return this.uiLanguage; + } + + public final Map getUiAttributes() { + return this.uiAttributes; + } + + public final Map getUiDependencies() { + return this.uiDependencies; + } + + public final String getUiVersion() { + return this.uiVersion; + } + + public final String getServiceVersion() { + return this.serviceVersion; + } + + public final Boolean getCallRecordingEnabled() { + return this.callRecordingEnabled; + } + + public final URI getCallRecordingWebhookUrl() { + return this.callRecordingWebhookUrl; + } + + public final Boolean getCrmEnabled() { + return this.crmEnabled; + } + + public final String getCrmType() { + return this.crmType; + } + + public final URI getCrmCallbackUrl() { + return this.crmCallbackUrl; + } + + public final URI getCrmFallbackUrl() { + return this.crmFallbackUrl; + } + + public final Map getCrmAttributes() { + return this.crmAttributes; + } + + public final Map getPublicAttributes() { + return this.publicAttributes; + } + + public final Boolean getPluginServiceEnabled() { + return this.pluginServiceEnabled; + } + + public final Map getPluginServiceAttributes() { + return this.pluginServiceAttributes; + } + + public final List> getIntegrations() { + return this.integrations; + } + + public final Map getOutboundCallFlows() { + return this.outboundCallFlows; + } + + public final List getServerlessServiceSids() { + return this.serverlessServiceSids; + } + + public final Map getQueueStatsConfiguration() { + return this.queueStatsConfiguration; + } + + public final Map getNotifications() { + return this.notifications; + } + + public final Map getMarkdown() { + return this.markdown; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getFlexInsightsHr() { + return this.flexInsightsHr; + } + + public final Boolean getFlexInsightsDrilldown() { + return this.flexInsightsDrilldown; + } + + public final URI getFlexUrl() { + return this.flexUrl; + } + + public final List> getChannelConfigs() { + return this.channelConfigs; + } + + public final Map getDebuggerIntegration() { + return this.debuggerIntegration; + } + + public final Map getFlexUiStatusReport() { + return this.flexUiStatusReport; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -485,13 +495,145 @@ public boolean equals(final Object o) { Configuration other = (Configuration) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(attributes, other.attributes) && Objects.equals(status, other.status) && Objects.equals(taskrouterWorkspaceSid, other.taskrouterWorkspaceSid) && Objects.equals(taskrouterTargetWorkflowSid, other.taskrouterTargetWorkflowSid) && Objects.equals(taskrouterTargetTaskqueueSid, other.taskrouterTargetTaskqueueSid) && Objects.equals(taskrouterTaskqueues, other.taskrouterTaskqueues) && Objects.equals(taskrouterSkills, other.taskrouterSkills) && Objects.equals(taskrouterWorkerChannels, other.taskrouterWorkerChannels) && Objects.equals(taskrouterWorkerAttributes, other.taskrouterWorkerAttributes) && Objects.equals(taskrouterOfflineActivitySid, other.taskrouterOfflineActivitySid) && Objects.equals(runtimeDomain, other.runtimeDomain) && Objects.equals(messagingServiceInstanceSid, other.messagingServiceInstanceSid) && Objects.equals(chatServiceInstanceSid, other.chatServiceInstanceSid) && Objects.equals(flexServiceInstanceSid, other.flexServiceInstanceSid) && Objects.equals(uiLanguage, other.uiLanguage) && Objects.equals(uiAttributes, other.uiAttributes) && Objects.equals(uiDependencies, other.uiDependencies) && Objects.equals(uiVersion, other.uiVersion) && Objects.equals(serviceVersion, other.serviceVersion) && Objects.equals(callRecordingEnabled, other.callRecordingEnabled) && Objects.equals(callRecordingWebhookUrl, other.callRecordingWebhookUrl) && Objects.equals(crmEnabled, other.crmEnabled) && Objects.equals(crmType, other.crmType) && Objects.equals(crmCallbackUrl, other.crmCallbackUrl) && Objects.equals(crmFallbackUrl, other.crmFallbackUrl) && Objects.equals(crmAttributes, other.crmAttributes) && Objects.equals(publicAttributes, other.publicAttributes) && Objects.equals(pluginServiceEnabled, other.pluginServiceEnabled) && Objects.equals(pluginServiceAttributes, other.pluginServiceAttributes) && Objects.equals(integrations, other.integrations) && Objects.equals(outboundCallFlows, other.outboundCallFlows) && Objects.equals(serverlessServiceSids, other.serverlessServiceSids) && Objects.equals(queueStatsConfiguration, other.queueStatsConfiguration) && Objects.equals(notifications, other.notifications) && Objects.equals(markdown, other.markdown) && Objects.equals(url, other.url) && Objects.equals(flexInsightsHr, other.flexInsightsHr) && Objects.equals(flexInsightsDrilldown, other.flexInsightsDrilldown) && Objects.equals(flexUrl, other.flexUrl) && Objects.equals(channelConfigs, other.channelConfigs) && Objects.equals(debuggerIntegration, other.debuggerIntegration) && Objects.equals(flexUiStatusReport, other.flexUiStatusReport) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(attributes, other.attributes) && + Objects.equals(status, other.status) && + Objects.equals( + taskrouterWorkspaceSid, + other.taskrouterWorkspaceSid + ) && + Objects.equals( + taskrouterTargetWorkflowSid, + other.taskrouterTargetWorkflowSid + ) && + Objects.equals( + taskrouterTargetTaskqueueSid, + other.taskrouterTargetTaskqueueSid + ) && + Objects.equals(taskrouterTaskqueues, other.taskrouterTaskqueues) && + Objects.equals(taskrouterSkills, other.taskrouterSkills) && + Objects.equals( + taskrouterWorkerChannels, + other.taskrouterWorkerChannels + ) && + Objects.equals( + taskrouterWorkerAttributes, + other.taskrouterWorkerAttributes + ) && + Objects.equals( + taskrouterOfflineActivitySid, + other.taskrouterOfflineActivitySid + ) && + Objects.equals(runtimeDomain, other.runtimeDomain) && + Objects.equals( + messagingServiceInstanceSid, + other.messagingServiceInstanceSid + ) && + Objects.equals( + chatServiceInstanceSid, + other.chatServiceInstanceSid + ) && + Objects.equals( + flexServiceInstanceSid, + other.flexServiceInstanceSid + ) && + Objects.equals(uiLanguage, other.uiLanguage) && + Objects.equals(uiAttributes, other.uiAttributes) && + Objects.equals(uiDependencies, other.uiDependencies) && + Objects.equals(uiVersion, other.uiVersion) && + Objects.equals(serviceVersion, other.serviceVersion) && + Objects.equals(callRecordingEnabled, other.callRecordingEnabled) && + Objects.equals( + callRecordingWebhookUrl, + other.callRecordingWebhookUrl + ) && + Objects.equals(crmEnabled, other.crmEnabled) && + Objects.equals(crmType, other.crmType) && + Objects.equals(crmCallbackUrl, other.crmCallbackUrl) && + Objects.equals(crmFallbackUrl, other.crmFallbackUrl) && + Objects.equals(crmAttributes, other.crmAttributes) && + Objects.equals(publicAttributes, other.publicAttributes) && + Objects.equals(pluginServiceEnabled, other.pluginServiceEnabled) && + Objects.equals( + pluginServiceAttributes, + other.pluginServiceAttributes + ) && + Objects.equals(integrations, other.integrations) && + Objects.equals(outboundCallFlows, other.outboundCallFlows) && + Objects.equals( + serverlessServiceSids, + other.serverlessServiceSids + ) && + Objects.equals( + queueStatsConfiguration, + other.queueStatsConfiguration + ) && + Objects.equals(notifications, other.notifications) && + Objects.equals(markdown, other.markdown) && + Objects.equals(url, other.url) && + Objects.equals(flexInsightsHr, other.flexInsightsHr) && + Objects.equals( + flexInsightsDrilldown, + other.flexInsightsDrilldown + ) && + Objects.equals(flexUrl, other.flexUrl) && + Objects.equals(channelConfigs, other.channelConfigs) && + Objects.equals(debuggerIntegration, other.debuggerIntegration) && + Objects.equals(flexUiStatusReport, other.flexUiStatusReport) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, dateCreated, dateUpdated, attributes, status, taskrouterWorkspaceSid, taskrouterTargetWorkflowSid, taskrouterTargetTaskqueueSid, taskrouterTaskqueues, taskrouterSkills, taskrouterWorkerChannels, taskrouterWorkerAttributes, taskrouterOfflineActivitySid, runtimeDomain, messagingServiceInstanceSid, chatServiceInstanceSid, flexServiceInstanceSid, uiLanguage, uiAttributes, uiDependencies, uiVersion, serviceVersion, callRecordingEnabled, callRecordingWebhookUrl, crmEnabled, crmType, crmCallbackUrl, crmFallbackUrl, crmAttributes, publicAttributes, pluginServiceEnabled, pluginServiceAttributes, integrations, outboundCallFlows, serverlessServiceSids, queueStatsConfiguration, notifications, markdown, url, flexInsightsHr, flexInsightsDrilldown, flexUrl, channelConfigs, debuggerIntegration, flexUiStatusReport); + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + attributes, + status, + taskrouterWorkspaceSid, + taskrouterTargetWorkflowSid, + taskrouterTargetTaskqueueSid, + taskrouterTaskqueues, + taskrouterSkills, + taskrouterWorkerChannels, + taskrouterWorkerAttributes, + taskrouterOfflineActivitySid, + runtimeDomain, + messagingServiceInstanceSid, + chatServiceInstanceSid, + flexServiceInstanceSid, + uiLanguage, + uiAttributes, + uiDependencies, + uiVersion, + serviceVersion, + callRecordingEnabled, + callRecordingWebhookUrl, + crmEnabled, + crmType, + crmCallbackUrl, + crmFallbackUrl, + crmAttributes, + publicAttributes, + pluginServiceEnabled, + pluginServiceAttributes, + integrations, + outboundCallFlows, + serverlessServiceSids, + queueStatsConfiguration, + notifications, + markdown, + url, + flexInsightsHr, + flexInsightsDrilldown, + flexUrl, + channelConfigs, + debuggerIntegration, + flexUiStatusReport + ); } - } - diff --git a/src/main/java/com/twilio/rest/flexapi/v1/ConfigurationFetcher.java b/src/main/java/com/twilio/rest/flexapi/v1/ConfigurationFetcher.java index b8324068a6..4c9d0fec4a 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/ConfigurationFetcher.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/ConfigurationFetcher.java @@ -24,16 +24,13 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class ConfigurationFetcher extends Fetcher { + private String uiVersion; - public ConfigurationFetcher(){ - } + public ConfigurationFetcher() {} - public ConfigurationFetcher setUiVersion(final String uiVersion){ + public ConfigurationFetcher setUiVersion(final String uiVersion) { this.uiVersion = uiVersion; return this; } @@ -42,7 +39,6 @@ public ConfigurationFetcher setUiVersion(final String uiVersion){ public Configuration fetch(final TwilioRestClient client) { String path = "/v1/Configuration"; - Request request = new Request( HttpMethod.GET, Domains.FLEXAPI.toString(), @@ -52,20 +48,28 @@ public Configuration fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Configuration fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Configuration fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Configuration.fromJson(response.getStream(), client.getObjectMapper()); + return Configuration.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addQueryParams(final Request request) { if (uiVersion != null) { - request.addQueryParam("UiVersion", uiVersion); } } diff --git a/src/main/java/com/twilio/rest/flexapi/v1/FlexFlow.java b/src/main/java/com/twilio/rest/flexapi/v1/FlexFlow.java index 26a2144911..fca91d474c 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/FlexFlow.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/FlexFlow.java @@ -24,55 +24,58 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class FlexFlow extends Resource { + private static final long serialVersionUID = 232454907869065L; - public static FlexFlowCreator creator(final String friendlyName, final String chatServiceSid, final FlexFlow.ChannelType channelType){ + public static FlexFlowCreator creator( + final String friendlyName, + final String chatServiceSid, + final FlexFlow.ChannelType channelType + ) { return new FlexFlowCreator(friendlyName, chatServiceSid, channelType); } - public static FlexFlowDeleter deleter(final String pathSid){ + public static FlexFlowDeleter deleter(final String pathSid) { return new FlexFlowDeleter(pathSid); } - public static FlexFlowFetcher fetcher(final String pathSid){ + public static FlexFlowFetcher fetcher(final String pathSid) { return new FlexFlowFetcher(pathSid); } - public static FlexFlowReader reader(){ + public static FlexFlowReader reader() { return new FlexFlowReader(); } - public static FlexFlowUpdater updater(final String pathSid){ + public static FlexFlowUpdater updater(final String pathSid) { return new FlexFlowUpdater(pathSid); } /** - * Converts a JSON String into a FlexFlow object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return FlexFlow object represented by the provided JSON - */ - public static FlexFlow fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a FlexFlow object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return FlexFlow object represented by the provided JSON + */ + public static FlexFlow fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, FlexFlow.class); @@ -84,14 +87,17 @@ public static FlexFlow fromJson(final String json, final ObjectMapper objectMapp } /** - * Converts a JSON InputStream into a FlexFlow object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return FlexFlow object represented by the provided JSON - */ - public static FlexFlow fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a FlexFlow object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return FlexFlow object represented by the provided JSON + */ + public static FlexFlow fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, FlexFlow.class); @@ -101,6 +107,7 @@ public static FlexFlow fromJson(final InputStream json, final ObjectMapper objec throw new ApiConnectionException(e.getMessage(), e); } } + public enum ChannelType { WEB("web"), SMS("sms"), @@ -124,6 +131,7 @@ public static ChannelType forValue(final String value) { return Promoter.enumFromString(value, ChannelType.values()); } } + public enum IntegrationType { STUDIO("studio"), EXTERNAL("external"), @@ -162,47 +170,22 @@ public static IntegrationType forValue(final String value) { @JsonCreator private FlexFlow( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("chat_service_sid") - final String chatServiceSid, - - @JsonProperty("channel_type") - final FlexFlow.ChannelType channelType, - - @JsonProperty("contact_identity") - final String contactIdentity, - - @JsonProperty("enabled") - final Boolean enabled, - - @JsonProperty("integration_type") - final FlexFlow.IntegrationType integrationType, - - @JsonProperty("integration") - final Map integration, - - @JsonProperty("long_lived") - final Boolean longLived, - - @JsonProperty("janitor_enabled") - final Boolean janitorEnabled, - - @JsonProperty("url") - final URI url + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("sid") final String sid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("chat_service_sid") final String chatServiceSid, + @JsonProperty("channel_type") final FlexFlow.ChannelType channelType, + @JsonProperty("contact_identity") final String contactIdentity, + @JsonProperty("enabled") final Boolean enabled, + @JsonProperty( + "integration_type" + ) final FlexFlow.IntegrationType integrationType, + @JsonProperty("integration") final Map integration, + @JsonProperty("long_lived") final Boolean longLived, + @JsonProperty("janitor_enabled") final Boolean janitorEnabled, + @JsonProperty("url") final URI url ) { this.accountSid = accountSid; this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); @@ -220,52 +203,65 @@ private FlexFlow( this.url = url; } - public final String getAccountSid() { - return this.accountSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getSid() { - return this.sid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getChatServiceSid() { - return this.chatServiceSid; - } - public final FlexFlow.ChannelType getChannelType() { - return this.channelType; - } - public final String getContactIdentity() { - return this.contactIdentity; - } - public final Boolean getEnabled() { - return this.enabled; - } - public final FlexFlow.IntegrationType getIntegrationType() { - return this.integrationType; - } - public final Map getIntegration() { - return this.integration; - } - public final Boolean getLongLived() { - return this.longLived; - } - public final Boolean getJanitorEnabled() { - return this.janitorEnabled; - } - public final URI getUrl() { - return this.url; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getSid() { + return this.sid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getChatServiceSid() { + return this.chatServiceSid; + } + + public final FlexFlow.ChannelType getChannelType() { + return this.channelType; + } + + public final String getContactIdentity() { + return this.contactIdentity; + } + + public final Boolean getEnabled() { + return this.enabled; + } + + public final FlexFlow.IntegrationType getIntegrationType() { + return this.integrationType; + } + + public final Map getIntegration() { + return this.integration; + } + + public final Boolean getLongLived() { + return this.longLived; + } + + public final Boolean getJanitorEnabled() { + return this.janitorEnabled; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -275,13 +271,41 @@ public boolean equals(final Object o) { FlexFlow other = (FlexFlow) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(sid, other.sid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(chatServiceSid, other.chatServiceSid) && Objects.equals(channelType, other.channelType) && Objects.equals(contactIdentity, other.contactIdentity) && Objects.equals(enabled, other.enabled) && Objects.equals(integrationType, other.integrationType) && Objects.equals(integration, other.integration) && Objects.equals(longLived, other.longLived) && Objects.equals(janitorEnabled, other.janitorEnabled) && Objects.equals(url, other.url) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(sid, other.sid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(chatServiceSid, other.chatServiceSid) && + Objects.equals(channelType, other.channelType) && + Objects.equals(contactIdentity, other.contactIdentity) && + Objects.equals(enabled, other.enabled) && + Objects.equals(integrationType, other.integrationType) && + Objects.equals(integration, other.integration) && + Objects.equals(longLived, other.longLived) && + Objects.equals(janitorEnabled, other.janitorEnabled) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, dateCreated, dateUpdated, sid, friendlyName, chatServiceSid, channelType, contactIdentity, enabled, integrationType, integration, longLived, janitorEnabled, url); + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + sid, + friendlyName, + chatServiceSid, + channelType, + contactIdentity, + enabled, + integrationType, + integration, + longLived, + janitorEnabled, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/flexapi/v1/FlexFlowCreator.java b/src/main/java/com/twilio/rest/flexapi/v1/FlexFlowCreator.java index e7fdf32c1d..bc16f08763 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/FlexFlowCreator.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/FlexFlowCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.flexapi.v1; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -25,12 +26,10 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.net.URI; - - - import java.net.URI; -public class FlexFlowCreator extends Creator{ +public class FlexFlowCreator extends Creator { + private String friendlyName; private String chatServiceSid; private FlexFlow.ChannelType channelType; @@ -49,180 +48,243 @@ public class FlexFlowCreator extends Creator{ private Boolean janitorEnabled; private Integer integrationRetryCount; - public FlexFlowCreator(final String friendlyName, final String chatServiceSid, final FlexFlow.ChannelType channelType) { + public FlexFlowCreator( + final String friendlyName, + final String chatServiceSid, + final FlexFlow.ChannelType channelType + ) { this.friendlyName = friendlyName; this.chatServiceSid = chatServiceSid; this.channelType = channelType; } - public FlexFlowCreator setFriendlyName(final String friendlyName){ + public FlexFlowCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public FlexFlowCreator setChatServiceSid(final String chatServiceSid){ + + public FlexFlowCreator setChatServiceSid(final String chatServiceSid) { this.chatServiceSid = chatServiceSid; return this; } - public FlexFlowCreator setChannelType(final FlexFlow.ChannelType channelType){ + + public FlexFlowCreator setChannelType( + final FlexFlow.ChannelType channelType + ) { this.channelType = channelType; return this; } - public FlexFlowCreator setContactIdentity(final String contactIdentity){ + + public FlexFlowCreator setContactIdentity(final String contactIdentity) { this.contactIdentity = contactIdentity; return this; } - public FlexFlowCreator setEnabled(final Boolean enabled){ + + public FlexFlowCreator setEnabled(final Boolean enabled) { this.enabled = enabled; return this; } - public FlexFlowCreator setIntegrationType(final FlexFlow.IntegrationType integrationType){ + + public FlexFlowCreator setIntegrationType( + final FlexFlow.IntegrationType integrationType + ) { this.integrationType = integrationType; return this; } - public FlexFlowCreator setIntegrationFlowSid(final String integrationFlowSid){ + + public FlexFlowCreator setIntegrationFlowSid( + final String integrationFlowSid + ) { this.integrationFlowSid = integrationFlowSid; return this; } - public FlexFlowCreator setIntegrationUrl(final URI integrationUrl){ + + public FlexFlowCreator setIntegrationUrl(final URI integrationUrl) { this.integrationUrl = integrationUrl; return this; } - public FlexFlowCreator setIntegrationUrl(final String integrationUrl){ + public FlexFlowCreator setIntegrationUrl(final String integrationUrl) { return setIntegrationUrl(Promoter.uriFromString(integrationUrl)); } - public FlexFlowCreator setIntegrationWorkspaceSid(final String integrationWorkspaceSid){ + + public FlexFlowCreator setIntegrationWorkspaceSid( + final String integrationWorkspaceSid + ) { this.integrationWorkspaceSid = integrationWorkspaceSid; return this; } - public FlexFlowCreator setIntegrationWorkflowSid(final String integrationWorkflowSid){ + + public FlexFlowCreator setIntegrationWorkflowSid( + final String integrationWorkflowSid + ) { this.integrationWorkflowSid = integrationWorkflowSid; return this; } - public FlexFlowCreator setIntegrationChannel(final String integrationChannel){ + + public FlexFlowCreator setIntegrationChannel( + final String integrationChannel + ) { this.integrationChannel = integrationChannel; return this; } - public FlexFlowCreator setIntegrationTimeout(final Integer integrationTimeout){ + + public FlexFlowCreator setIntegrationTimeout( + final Integer integrationTimeout + ) { this.integrationTimeout = integrationTimeout; return this; } - public FlexFlowCreator setIntegrationPriority(final Integer integrationPriority){ + + public FlexFlowCreator setIntegrationPriority( + final Integer integrationPriority + ) { this.integrationPriority = integrationPriority; return this; } - public FlexFlowCreator setIntegrationCreationOnMessage(final Boolean integrationCreationOnMessage){ + + public FlexFlowCreator setIntegrationCreationOnMessage( + final Boolean integrationCreationOnMessage + ) { this.integrationCreationOnMessage = integrationCreationOnMessage; return this; } - public FlexFlowCreator setLongLived(final Boolean longLived){ + + public FlexFlowCreator setLongLived(final Boolean longLived) { this.longLived = longLived; return this; } - public FlexFlowCreator setJanitorEnabled(final Boolean janitorEnabled){ + + public FlexFlowCreator setJanitorEnabled(final Boolean janitorEnabled) { this.janitorEnabled = janitorEnabled; return this; } - public FlexFlowCreator setIntegrationRetryCount(final Integer integrationRetryCount){ + + public FlexFlowCreator setIntegrationRetryCount( + final Integer integrationRetryCount + ) { this.integrationRetryCount = integrationRetryCount; return this; } @Override - public FlexFlow create(final TwilioRestClient client){ + public FlexFlow create(final TwilioRestClient client) { String path = "/v1/FlexFlows"; - path = path.replace("{"+"FriendlyName"+"}", this.friendlyName.toString()); - path = path.replace("{"+"ChatServiceSid"+"}", this.chatServiceSid.toString()); - path = path.replace("{"+"ChannelType"+"}", this.channelType.toString()); + path = + path.replace( + "{" + "FriendlyName" + "}", + this.friendlyName.toString() + ); + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.chatServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelType" + "}", + this.channelType.toString() + ); Request request = new Request( HttpMethod.POST, Domains.FLEXAPI.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("FlexFlow creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "FlexFlow creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return FlexFlow.fromJson(response.getStream(), client.getObjectMapper()); + return FlexFlow.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (chatServiceSid != null) { request.addPostParam("ChatServiceSid", chatServiceSid); - } if (channelType != null) { request.addPostParam("ChannelType", channelType.toString()); - } if (contactIdentity != null) { request.addPostParam("ContactIdentity", contactIdentity); - } if (enabled != null) { request.addPostParam("Enabled", enabled.toString()); - } if (integrationType != null) { request.addPostParam("IntegrationType", integrationType.toString()); - } if (integrationFlowSid != null) { request.addPostParam("Integration.FlowSid", integrationFlowSid); - } if (integrationUrl != null) { request.addPostParam("Integration.Url", integrationUrl.toString()); - } if (integrationWorkspaceSid != null) { - request.addPostParam("Integration.WorkspaceSid", integrationWorkspaceSid); - + request.addPostParam( + "Integration.WorkspaceSid", + integrationWorkspaceSid + ); } if (integrationWorkflowSid != null) { - request.addPostParam("Integration.WorkflowSid", integrationWorkflowSid); - + request.addPostParam( + "Integration.WorkflowSid", + integrationWorkflowSid + ); } if (integrationChannel != null) { request.addPostParam("Integration.Channel", integrationChannel); - } if (integrationTimeout != null) { - request.addPostParam("Integration.Timeout", integrationTimeout.toString()); - + request.addPostParam( + "Integration.Timeout", + integrationTimeout.toString() + ); } if (integrationPriority != null) { - request.addPostParam("Integration.Priority", integrationPriority.toString()); - + request.addPostParam( + "Integration.Priority", + integrationPriority.toString() + ); } if (integrationCreationOnMessage != null) { - request.addPostParam("Integration.CreationOnMessage", integrationCreationOnMessage.toString()); - + request.addPostParam( + "Integration.CreationOnMessage", + integrationCreationOnMessage.toString() + ); } if (longLived != null) { request.addPostParam("LongLived", longLived.toString()); - } if (janitorEnabled != null) { request.addPostParam("JanitorEnabled", janitorEnabled.toString()); - } if (integrationRetryCount != null) { - request.addPostParam("Integration.RetryCount", integrationRetryCount.toString()); - + request.addPostParam( + "Integration.RetryCount", + integrationRetryCount.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/flexapi/v1/FlexFlowDeleter.java b/src/main/java/com/twilio/rest/flexapi/v1/FlexFlowDeleter.java index c1830df1bb..4fe3f2b547 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/FlexFlowDeleter.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/FlexFlowDeleter.java @@ -24,21 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class FlexFlowDeleter extends Deleter { + private String pathSid; - public FlexFlowDeleter(final String pathSid){ + public FlexFlowDeleter(final String pathSid) { this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/FlexFlows/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -48,9 +46,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("FlexFlow delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "FlexFlow delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/flexapi/v1/FlexFlowFetcher.java b/src/main/java/com/twilio/rest/flexapi/v1/FlexFlowFetcher.java index 4d16f2bb56..f463849c73 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/FlexFlowFetcher.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/FlexFlowFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class FlexFlowFetcher extends Fetcher { + private String pathSid; - public FlexFlowFetcher(final String pathSid){ + public FlexFlowFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public FlexFlow fetch(final TwilioRestClient client) { String path = "/v1/FlexFlows/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,15 +46,23 @@ public FlexFlow fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("FlexFlow fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "FlexFlow fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return FlexFlow.fromJson(response.getStream(), client.getObjectMapper()); + return FlexFlow.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/flexapi/v1/FlexFlowReader.java b/src/main/java/com/twilio/rest/flexapi/v1/FlexFlowReader.java index 73acf341e8..119926cc14 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/FlexFlowReader.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/FlexFlowReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.flexapi.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,22 +25,20 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class FlexFlowReader extends Reader { + private String friendlyName; private Integer pageSize; - public FlexFlowReader(){ - } + public FlexFlowReader() {} - public FlexFlowReader setFriendlyName(final String friendlyName){ + public FlexFlowReader setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public FlexFlowReader setPageSize(final Integer pageSize){ + + public FlexFlowReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -62,13 +61,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("FlexFlow read failed: Unable to connect to server"); + throw new ApiConnectionException( + "FlexFlow read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -84,7 +91,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reque } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.FLEXAPI.toString()) @@ -92,9 +102,11 @@ public Page previousPage(final Page page, final TwilioRestCl return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.FLEXAPI.toString()) @@ -103,25 +115,24 @@ public Page nextPage(final Page page, final TwilioRestClient } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (friendlyName != null) { - request.addQueryParam("FriendlyName", friendlyName); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/flexapi/v1/FlexFlowUpdater.java b/src/main/java/com/twilio/rest/flexapi/v1/FlexFlowUpdater.java index b52eeef1f8..5cdaddb729 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/FlexFlowUpdater.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/FlexFlowUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.flexapi.v1; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -24,12 +25,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.net.URI; +public class FlexFlowUpdater extends Updater { - -public class FlexFlowUpdater extends Updater{ private String pathSid; private String friendlyName; private String chatServiceSid; @@ -49,176 +48,223 @@ public class FlexFlowUpdater extends Updater{ private Boolean janitorEnabled; private Integer integrationRetryCount; - public FlexFlowUpdater(final String pathSid){ + public FlexFlowUpdater(final String pathSid) { this.pathSid = pathSid; } - public FlexFlowUpdater setFriendlyName(final String friendlyName){ + public FlexFlowUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public FlexFlowUpdater setChatServiceSid(final String chatServiceSid){ + + public FlexFlowUpdater setChatServiceSid(final String chatServiceSid) { this.chatServiceSid = chatServiceSid; return this; } - public FlexFlowUpdater setChannelType(final FlexFlow.ChannelType channelType){ + + public FlexFlowUpdater setChannelType( + final FlexFlow.ChannelType channelType + ) { this.channelType = channelType; return this; } - public FlexFlowUpdater setContactIdentity(final String contactIdentity){ + + public FlexFlowUpdater setContactIdentity(final String contactIdentity) { this.contactIdentity = contactIdentity; return this; } - public FlexFlowUpdater setEnabled(final Boolean enabled){ + + public FlexFlowUpdater setEnabled(final Boolean enabled) { this.enabled = enabled; return this; } - public FlexFlowUpdater setIntegrationType(final FlexFlow.IntegrationType integrationType){ + + public FlexFlowUpdater setIntegrationType( + final FlexFlow.IntegrationType integrationType + ) { this.integrationType = integrationType; return this; } - public FlexFlowUpdater setIntegrationFlowSid(final String integrationFlowSid){ + + public FlexFlowUpdater setIntegrationFlowSid( + final String integrationFlowSid + ) { this.integrationFlowSid = integrationFlowSid; return this; } - public FlexFlowUpdater setIntegrationUrl(final URI integrationUrl){ + + public FlexFlowUpdater setIntegrationUrl(final URI integrationUrl) { this.integrationUrl = integrationUrl; return this; } - public FlexFlowUpdater setIntegrationUrl(final String integrationUrl){ + public FlexFlowUpdater setIntegrationUrl(final String integrationUrl) { return setIntegrationUrl(Promoter.uriFromString(integrationUrl)); } - public FlexFlowUpdater setIntegrationWorkspaceSid(final String integrationWorkspaceSid){ + + public FlexFlowUpdater setIntegrationWorkspaceSid( + final String integrationWorkspaceSid + ) { this.integrationWorkspaceSid = integrationWorkspaceSid; return this; } - public FlexFlowUpdater setIntegrationWorkflowSid(final String integrationWorkflowSid){ + + public FlexFlowUpdater setIntegrationWorkflowSid( + final String integrationWorkflowSid + ) { this.integrationWorkflowSid = integrationWorkflowSid; return this; } - public FlexFlowUpdater setIntegrationChannel(final String integrationChannel){ + + public FlexFlowUpdater setIntegrationChannel( + final String integrationChannel + ) { this.integrationChannel = integrationChannel; return this; } - public FlexFlowUpdater setIntegrationTimeout(final Integer integrationTimeout){ + + public FlexFlowUpdater setIntegrationTimeout( + final Integer integrationTimeout + ) { this.integrationTimeout = integrationTimeout; return this; } - public FlexFlowUpdater setIntegrationPriority(final Integer integrationPriority){ + + public FlexFlowUpdater setIntegrationPriority( + final Integer integrationPriority + ) { this.integrationPriority = integrationPriority; return this; } - public FlexFlowUpdater setIntegrationCreationOnMessage(final Boolean integrationCreationOnMessage){ + + public FlexFlowUpdater setIntegrationCreationOnMessage( + final Boolean integrationCreationOnMessage + ) { this.integrationCreationOnMessage = integrationCreationOnMessage; return this; } - public FlexFlowUpdater setLongLived(final Boolean longLived){ + + public FlexFlowUpdater setLongLived(final Boolean longLived) { this.longLived = longLived; return this; } - public FlexFlowUpdater setJanitorEnabled(final Boolean janitorEnabled){ + + public FlexFlowUpdater setJanitorEnabled(final Boolean janitorEnabled) { this.janitorEnabled = janitorEnabled; return this; } - public FlexFlowUpdater setIntegrationRetryCount(final Integer integrationRetryCount){ + + public FlexFlowUpdater setIntegrationRetryCount( + final Integer integrationRetryCount + ) { this.integrationRetryCount = integrationRetryCount; return this; } @Override - public FlexFlow update(final TwilioRestClient client){ + public FlexFlow update(final TwilioRestClient client) { String path = "/v1/FlexFlows/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.FLEXAPI.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("FlexFlow update failed: Unable to connect to server"); + throw new ApiConnectionException( + "FlexFlow update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return FlexFlow.fromJson(response.getStream(), client.getObjectMapper()); + return FlexFlow.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (chatServiceSid != null) { request.addPostParam("ChatServiceSid", chatServiceSid); - } if (channelType != null) { request.addPostParam("ChannelType", channelType.toString()); - } if (contactIdentity != null) { request.addPostParam("ContactIdentity", contactIdentity); - } if (enabled != null) { request.addPostParam("Enabled", enabled.toString()); - } if (integrationType != null) { request.addPostParam("IntegrationType", integrationType.toString()); - } if (integrationFlowSid != null) { request.addPostParam("Integration.FlowSid", integrationFlowSid); - } if (integrationUrl != null) { request.addPostParam("Integration.Url", integrationUrl.toString()); - } if (integrationWorkspaceSid != null) { - request.addPostParam("Integration.WorkspaceSid", integrationWorkspaceSid); - + request.addPostParam( + "Integration.WorkspaceSid", + integrationWorkspaceSid + ); } if (integrationWorkflowSid != null) { - request.addPostParam("Integration.WorkflowSid", integrationWorkflowSid); - + request.addPostParam( + "Integration.WorkflowSid", + integrationWorkflowSid + ); } if (integrationChannel != null) { request.addPostParam("Integration.Channel", integrationChannel); - } if (integrationTimeout != null) { - request.addPostParam("Integration.Timeout", integrationTimeout.toString()); - + request.addPostParam( + "Integration.Timeout", + integrationTimeout.toString() + ); } if (integrationPriority != null) { - request.addPostParam("Integration.Priority", integrationPriority.toString()); - + request.addPostParam( + "Integration.Priority", + integrationPriority.toString() + ); } if (integrationCreationOnMessage != null) { - request.addPostParam("Integration.CreationOnMessage", integrationCreationOnMessage.toString()); - + request.addPostParam( + "Integration.CreationOnMessage", + integrationCreationOnMessage.toString() + ); } if (longLived != null) { request.addPostParam("LongLived", longLived.toString()); - } if (janitorEnabled != null) { request.addPostParam("JanitorEnabled", janitorEnabled.toString()); - } if (integrationRetryCount != null) { - request.addPostParam("Integration.RetryCount", integrationRetryCount.toString()); - + request.addPostParam( + "Integration.RetryCount", + integrationRetryCount.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InsightsAssessmentsComment.java b/src/main/java/com/twilio/rest/flexapi/v1/InsightsAssessmentsComment.java index fa3ab05a81..115b9e464b 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/InsightsAssessmentsComment.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/InsightsAssessmentsComment.java @@ -22,46 +22,62 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; +import java.math.BigDecimal; import java.net.URI; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; -import java.math.BigDecimal; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class InsightsAssessmentsComment extends Resource { + private static final long serialVersionUID = 175598645429423L; - public static InsightsAssessmentsCommentCreator creator(final String categoryId, final String categoryName, final String comment, final String segmentId, final String agentId, final BigDecimal offset){ - return new InsightsAssessmentsCommentCreator(categoryId, categoryName, comment, segmentId, agentId, offset); + public static InsightsAssessmentsCommentCreator creator( + final String categoryId, + final String categoryName, + final String comment, + final String segmentId, + final String agentId, + final BigDecimal offset + ) { + return new InsightsAssessmentsCommentCreator( + categoryId, + categoryName, + comment, + segmentId, + agentId, + offset + ); } - public static InsightsAssessmentsCommentReader reader(){ + public static InsightsAssessmentsCommentReader reader() { return new InsightsAssessmentsCommentReader(); } /** - * Converts a JSON String into a InsightsAssessmentsComment object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return InsightsAssessmentsComment object represented by the provided JSON - */ - public static InsightsAssessmentsComment fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a InsightsAssessmentsComment object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return InsightsAssessmentsComment object represented by the provided JSON + */ + public static InsightsAssessmentsComment fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, InsightsAssessmentsComment.class); + return objectMapper.readValue( + json, + InsightsAssessmentsComment.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -70,17 +86,23 @@ public static InsightsAssessmentsComment fromJson(final String json, final Objec } /** - * Converts a JSON InputStream into a InsightsAssessmentsComment object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return InsightsAssessmentsComment object represented by the provided JSON - */ - public static InsightsAssessmentsComment fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a InsightsAssessmentsComment object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return InsightsAssessmentsComment object represented by the provided JSON + */ + public static InsightsAssessmentsComment fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, InsightsAssessmentsComment.class); + return objectMapper.readValue( + json, + InsightsAssessmentsComment.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -103,41 +125,18 @@ public static InsightsAssessmentsComment fromJson(final InputStream json, final @JsonCreator private InsightsAssessmentsComment( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("assessment_sid") - final String assessmentSid, - - @JsonProperty("comment") - final Map comment, - - @JsonProperty("offset") - final BigDecimal offset, - - @JsonProperty("report") - final Boolean report, - - @JsonProperty("weight") - final BigDecimal weight, - - @JsonProperty("agent_id") - final String agentId, - - @JsonProperty("segment_id") - final String segmentId, - - @JsonProperty("user_name") - final String userName, - - @JsonProperty("user_email") - final String userEmail, - - @JsonProperty("timestamp") - final BigDecimal timestamp, - - @JsonProperty("url") - final URI url + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("assessment_sid") final String assessmentSid, + @JsonProperty("comment") final Map comment, + @JsonProperty("offset") final BigDecimal offset, + @JsonProperty("report") final Boolean report, + @JsonProperty("weight") final BigDecimal weight, + @JsonProperty("agent_id") final String agentId, + @JsonProperty("segment_id") final String segmentId, + @JsonProperty("user_name") final String userName, + @JsonProperty("user_email") final String userEmail, + @JsonProperty("timestamp") final BigDecimal timestamp, + @JsonProperty("url") final URI url ) { this.accountSid = accountSid; this.assessmentSid = assessmentSid; @@ -153,46 +152,57 @@ private InsightsAssessmentsComment( this.url = url; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getAssessmentSid() { - return this.assessmentSid; - } - public final Map getComment() { - return this.comment; - } - public final BigDecimal getOffset() { - return this.offset; - } - public final Boolean getReport() { - return this.report; - } - public final BigDecimal getWeight() { - return this.weight; - } - public final String getAgentId() { - return this.agentId; - } - public final String getSegmentId() { - return this.segmentId; - } - public final String getUserName() { - return this.userName; - } - public final String getUserEmail() { - return this.userEmail; - } - public final BigDecimal getTimestamp() { - return this.timestamp; - } - public final URI getUrl() { - return this.url; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getAssessmentSid() { + return this.assessmentSid; + } + + public final Map getComment() { + return this.comment; + } + + public final BigDecimal getOffset() { + return this.offset; + } + + public final Boolean getReport() { + return this.report; + } + + public final BigDecimal getWeight() { + return this.weight; + } + + public final String getAgentId() { + return this.agentId; + } + + public final String getSegmentId() { + return this.segmentId; + } + + public final String getUserName() { + return this.userName; + } + + public final String getUserEmail() { + return this.userEmail; + } + + public final BigDecimal getTimestamp() { + return this.timestamp; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -202,13 +212,37 @@ public boolean equals(final Object o) { InsightsAssessmentsComment other = (InsightsAssessmentsComment) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(assessmentSid, other.assessmentSid) && Objects.equals(comment, other.comment) && Objects.equals(offset, other.offset) && Objects.equals(report, other.report) && Objects.equals(weight, other.weight) && Objects.equals(agentId, other.agentId) && Objects.equals(segmentId, other.segmentId) && Objects.equals(userName, other.userName) && Objects.equals(userEmail, other.userEmail) && Objects.equals(timestamp, other.timestamp) && Objects.equals(url, other.url) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(assessmentSid, other.assessmentSid) && + Objects.equals(comment, other.comment) && + Objects.equals(offset, other.offset) && + Objects.equals(report, other.report) && + Objects.equals(weight, other.weight) && + Objects.equals(agentId, other.agentId) && + Objects.equals(segmentId, other.segmentId) && + Objects.equals(userName, other.userName) && + Objects.equals(userEmail, other.userEmail) && + Objects.equals(timestamp, other.timestamp) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, assessmentSid, comment, offset, report, weight, agentId, segmentId, userName, userEmail, timestamp, url); + return Objects.hash( + accountSid, + assessmentSid, + comment, + offset, + report, + weight, + agentId, + segmentId, + userName, + userEmail, + timestamp, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InsightsAssessmentsCommentCreator.java b/src/main/java/com/twilio/rest/flexapi/v1/InsightsAssessmentsCommentCreator.java index 76c25109c7..04d26997c9 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/InsightsAssessmentsCommentCreator.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/InsightsAssessmentsCommentCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.flexapi.v1; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -26,10 +27,9 @@ import java.math.BigDecimal; import java.math.BigDecimal; +public class InsightsAssessmentsCommentCreator + extends Creator { - - -public class InsightsAssessmentsCommentCreator extends Creator{ private String categoryId; private String categoryName; private String comment; @@ -38,7 +38,14 @@ public class InsightsAssessmentsCommentCreator extends Creator { - -public class InsightsAssessmentsCommentReader extends Reader { private String authorization; private String segmentId; private String agentId; private Integer pageSize; - public InsightsAssessmentsCommentReader(){ - } + public InsightsAssessmentsCommentReader() {} - public InsightsAssessmentsCommentReader setAuthorization(final String authorization){ + public InsightsAssessmentsCommentReader setAuthorization( + final String authorization + ) { this.authorization = authorization; return this; } - public InsightsAssessmentsCommentReader setSegmentId(final String segmentId){ + + public InsightsAssessmentsCommentReader setSegmentId( + final String segmentId + ) { this.segmentId = segmentId; return this; } - public InsightsAssessmentsCommentReader setAgentId(final String agentId){ + + public InsightsAssessmentsCommentReader setAgentId(final String agentId) { this.agentId = agentId; return this; } - public InsightsAssessmentsCommentReader setPageSize(final Integer pageSize){ + + public InsightsAssessmentsCommentReader setPageSize( + final Integer pageSize + ) { this.pageSize = pageSize; return this; } @Override - public ResourceSet read(final TwilioRestClient client) { + public ResourceSet read( + final TwilioRestClient client + ) { return new ResourceSet<>(this, client, firstPage(client)); } - public Page firstPage(final TwilioRestClient client) { + public Page firstPage( + final TwilioRestClient client + ) { String path = "/v1/Insights/QualityManagement/Assessments/Comments"; Request request = new Request( @@ -73,13 +85,21 @@ public Page firstPage(final TwilioRestClient client) return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("InsightsAssessmentsComment read failed: Unable to connect to server"); + throw new ApiConnectionException( + "InsightsAssessmentsComment read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -95,7 +115,10 @@ private Page pageForRequest(final TwilioRestClient c } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.FLEXAPI.toString()) @@ -103,9 +126,11 @@ public Page previousPage(final Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.FLEXAPI.toString()) @@ -114,35 +139,33 @@ public Page nextPage(final Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addHeaderParams(final Request request) { if (authorization != null) { request.addHeaderParam("Authorization", authorization); - } } + private void addQueryParams(final Request request) { if (segmentId != null) { - request.addQueryParam("SegmentId", segmentId); } if (agentId != null) { - request.addQueryParam("AgentId", agentId); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InsightsConversations.java b/src/main/java/com/twilio/rest/flexapi/v1/InsightsConversations.java index 31238a91b3..e458cfafe9 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/InsightsConversations.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/InsightsConversations.java @@ -22,38 +22,37 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; - import java.util.List; import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class InsightsConversations extends Resource { + private static final long serialVersionUID = 172863414006149L; - public static InsightsConversationsReader reader(){ + public static InsightsConversationsReader reader() { return new InsightsConversationsReader(); } /** - * Converts a JSON String into a InsightsConversations object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return InsightsConversations object represented by the provided JSON - */ - public static InsightsConversations fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a InsightsConversations object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return InsightsConversations object represented by the provided JSON + */ + public static InsightsConversations fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, InsightsConversations.class); @@ -65,14 +64,17 @@ public static InsightsConversations fromJson(final String json, final ObjectMapp } /** - * Converts a JSON InputStream into a InsightsConversations object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return InsightsConversations object represented by the provided JSON - */ - public static InsightsConversations fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a InsightsConversations object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return InsightsConversations object represented by the provided JSON + */ + public static InsightsConversations fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, InsightsConversations.class); @@ -90,17 +92,10 @@ public static InsightsConversations fromJson(final InputStream json, final Objec @JsonCreator private InsightsConversations( - @JsonProperty("account_id") - final String accountId, - - @JsonProperty("conversation_id") - final String conversationId, - - @JsonProperty("segment_count") - final Integer segmentCount, - - @JsonProperty("segments") - final List> segments + @JsonProperty("account_id") final String accountId, + @JsonProperty("conversation_id") final String conversationId, + @JsonProperty("segment_count") final Integer segmentCount, + @JsonProperty("segments") final List> segments ) { this.accountId = accountId; this.conversationId = conversationId; @@ -108,22 +103,25 @@ private InsightsConversations( this.segments = segments; } - public final String getAccountId() { - return this.accountId; - } - public final String getConversationId() { - return this.conversationId; - } - public final Integer getSegmentCount() { - return this.segmentCount; - } - public final List> getSegments() { - return this.segments; - } + public final String getAccountId() { + return this.accountId; + } + + public final String getConversationId() { + return this.conversationId; + } + + public final Integer getSegmentCount() { + return this.segmentCount; + } + + public final List> getSegments() { + return this.segments; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -133,13 +131,16 @@ public boolean equals(final Object o) { InsightsConversations other = (InsightsConversations) o; - return Objects.equals(accountId, other.accountId) && Objects.equals(conversationId, other.conversationId) && Objects.equals(segmentCount, other.segmentCount) && Objects.equals(segments, other.segments) ; + return ( + Objects.equals(accountId, other.accountId) && + Objects.equals(conversationId, other.conversationId) && + Objects.equals(segmentCount, other.segmentCount) && + Objects.equals(segments, other.segments) + ); } @Override public int hashCode() { return Objects.hash(accountId, conversationId, segmentCount, segments); } - } - diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InsightsConversationsReader.java b/src/main/java/com/twilio/rest/flexapi/v1/InsightsConversationsReader.java index a9c14ad3b9..27fbf69616 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/InsightsConversationsReader.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/InsightsConversationsReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.flexapi.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,37 +25,42 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class InsightsConversationsReader extends Reader { + private String authorization; private String segmentId; private Integer pageSize; - public InsightsConversationsReader(){ - } + public InsightsConversationsReader() {} - public InsightsConversationsReader setAuthorization(final String authorization){ + public InsightsConversationsReader setAuthorization( + final String authorization + ) { this.authorization = authorization; return this; } - public InsightsConversationsReader setSegmentId(final String segmentId){ + + public InsightsConversationsReader setSegmentId(final String segmentId) { this.segmentId = segmentId; return this; } - public InsightsConversationsReader setPageSize(final Integer pageSize){ + + public InsightsConversationsReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @Override - public ResourceSet read(final TwilioRestClient client) { + public ResourceSet read( + final TwilioRestClient client + ) { return new ResourceSet<>(this, client, firstPage(client)); } - public Page firstPage(final TwilioRestClient client) { + public Page firstPage( + final TwilioRestClient client + ) { String path = "/v1/Insights/Conversations"; Request request = new Request( @@ -68,13 +74,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("InsightsConversations read failed: Unable to connect to server"); + throw new ApiConnectionException( + "InsightsConversations read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -90,7 +104,10 @@ private Page pageForRequest(final TwilioRestClient client } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.FLEXAPI.toString()) @@ -98,9 +115,11 @@ public Page previousPage(final Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.FLEXAPI.toString()) @@ -109,31 +128,30 @@ public Page nextPage(final Page pa } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addHeaderParams(final Request request) { if (authorization != null) { request.addHeaderParam("Authorization", authorization); - } } + private void addQueryParams(final Request request) { if (segmentId != null) { - request.addQueryParam("SegmentId", segmentId); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnaires.java b/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnaires.java index 861b5b71c2..72266a5492 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnaires.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnaires.java @@ -22,55 +22,61 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.List; import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class InsightsQuestionnaires extends Resource { + private static final long serialVersionUID = 101221063563372L; - public static InsightsQuestionnairesCreator creator(final String name){ + public static InsightsQuestionnairesCreator creator(final String name) { return new InsightsQuestionnairesCreator(name); } - public static InsightsQuestionnairesDeleter deleter(final String pathQuestionnaireSid){ + public static InsightsQuestionnairesDeleter deleter( + final String pathQuestionnaireSid + ) { return new InsightsQuestionnairesDeleter(pathQuestionnaireSid); } - public static InsightsQuestionnairesFetcher fetcher(final String pathQuestionnaireSid){ + public static InsightsQuestionnairesFetcher fetcher( + final String pathQuestionnaireSid + ) { return new InsightsQuestionnairesFetcher(pathQuestionnaireSid); } - public static InsightsQuestionnairesReader reader(){ + public static InsightsQuestionnairesReader reader() { return new InsightsQuestionnairesReader(); } - public static InsightsQuestionnairesUpdater updater(final String pathQuestionnaireSid, final Boolean active){ + public static InsightsQuestionnairesUpdater updater( + final String pathQuestionnaireSid, + final Boolean active + ) { return new InsightsQuestionnairesUpdater(pathQuestionnaireSid, active); } /** - * Converts a JSON String into a InsightsQuestionnaires object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return InsightsQuestionnaires object represented by the provided JSON - */ - public static InsightsQuestionnaires fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a InsightsQuestionnaires object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return InsightsQuestionnaires object represented by the provided JSON + */ + public static InsightsQuestionnaires fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, InsightsQuestionnaires.class); @@ -82,14 +88,17 @@ public static InsightsQuestionnaires fromJson(final String json, final ObjectMap } /** - * Converts a JSON InputStream into a InsightsQuestionnaires object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return InsightsQuestionnaires object represented by the provided JSON - */ - public static InsightsQuestionnaires fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a InsightsQuestionnaires object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return InsightsQuestionnaires object represented by the provided JSON + */ + public static InsightsQuestionnaires fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, InsightsQuestionnaires.class); @@ -110,26 +119,13 @@ public static InsightsQuestionnaires fromJson(final InputStream json, final Obje @JsonCreator private InsightsQuestionnaires( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("questionnaire_sid") - final String questionnaireSid, - - @JsonProperty("name") - final String name, - - @JsonProperty("description") - final String description, - - @JsonProperty("active") - final Boolean active, - - @JsonProperty("questions") - final List> questions, - - @JsonProperty("url") - final URI url + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("questionnaire_sid") final String questionnaireSid, + @JsonProperty("name") final String name, + @JsonProperty("description") final String description, + @JsonProperty("active") final Boolean active, + @JsonProperty("questions") final List> questions, + @JsonProperty("url") final URI url ) { this.accountSid = accountSid; this.questionnaireSid = questionnaireSid; @@ -140,31 +136,37 @@ private InsightsQuestionnaires( this.url = url; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getQuestionnaireSid() { - return this.questionnaireSid; - } - public final String getName() { - return this.name; - } - public final String getDescription() { - return this.description; - } - public final Boolean getActive() { - return this.active; - } - public final List> getQuestions() { - return this.questions; - } - public final URI getUrl() { - return this.url; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getQuestionnaireSid() { + return this.questionnaireSid; + } + + public final String getName() { + return this.name; + } + + public final String getDescription() { + return this.description; + } + + public final Boolean getActive() { + return this.active; + } + + public final List> getQuestions() { + return this.questions; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -174,13 +176,27 @@ public boolean equals(final Object o) { InsightsQuestionnaires other = (InsightsQuestionnaires) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(questionnaireSid, other.questionnaireSid) && Objects.equals(name, other.name) && Objects.equals(description, other.description) && Objects.equals(active, other.active) && Objects.equals(questions, other.questions) && Objects.equals(url, other.url) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(questionnaireSid, other.questionnaireSid) && + Objects.equals(name, other.name) && + Objects.equals(description, other.description) && + Objects.equals(active, other.active) && + Objects.equals(questions, other.questions) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, questionnaireSid, name, description, active, questions, url); + return Objects.hash( + accountSid, + questionnaireSid, + name, + description, + active, + questions, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesCategory.java b/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesCategory.java index 85a7f85777..3682d38fcc 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesCategory.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesCategory.java @@ -22,51 +22,60 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class InsightsQuestionnairesCategory extends Resource { + private static final long serialVersionUID = 80122837059940L; - public static InsightsQuestionnairesCategoryCreator creator(final String name){ + public static InsightsQuestionnairesCategoryCreator creator( + final String name + ) { return new InsightsQuestionnairesCategoryCreator(name); } - public static InsightsQuestionnairesCategoryDeleter deleter(final String pathCategorySid){ + public static InsightsQuestionnairesCategoryDeleter deleter( + final String pathCategorySid + ) { return new InsightsQuestionnairesCategoryDeleter(pathCategorySid); } - public static InsightsQuestionnairesCategoryReader reader(){ + public static InsightsQuestionnairesCategoryReader reader() { return new InsightsQuestionnairesCategoryReader(); } - public static InsightsQuestionnairesCategoryUpdater updater(final String pathCategorySid, final String name){ + public static InsightsQuestionnairesCategoryUpdater updater( + final String pathCategorySid, + final String name + ) { return new InsightsQuestionnairesCategoryUpdater(pathCategorySid, name); } /** - * Converts a JSON String into a InsightsQuestionnairesCategory object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return InsightsQuestionnairesCategory object represented by the provided JSON - */ - public static InsightsQuestionnairesCategory fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a InsightsQuestionnairesCategory object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return InsightsQuestionnairesCategory object represented by the provided JSON + */ + public static InsightsQuestionnairesCategory fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, InsightsQuestionnairesCategory.class); + return objectMapper.readValue( + json, + InsightsQuestionnairesCategory.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -75,17 +84,23 @@ public static InsightsQuestionnairesCategory fromJson(final String json, final O } /** - * Converts a JSON InputStream into a InsightsQuestionnairesCategory object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return InsightsQuestionnairesCategory object represented by the provided JSON - */ - public static InsightsQuestionnairesCategory fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a InsightsQuestionnairesCategory object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return InsightsQuestionnairesCategory object represented by the provided JSON + */ + public static InsightsQuestionnairesCategory fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, InsightsQuestionnairesCategory.class); + return objectMapper.readValue( + json, + InsightsQuestionnairesCategory.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -100,17 +115,10 @@ public static InsightsQuestionnairesCategory fromJson(final InputStream json, fi @JsonCreator private InsightsQuestionnairesCategory( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("category_sid") - final String categorySid, - - @JsonProperty("name") - final String name, - - @JsonProperty("url") - final URI url + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("category_sid") final String categorySid, + @JsonProperty("name") final String name, + @JsonProperty("url") final URI url ) { this.accountSid = accountSid; this.categorySid = categorySid; @@ -118,22 +126,25 @@ private InsightsQuestionnairesCategory( this.url = url; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getCategorySid() { - return this.categorySid; - } - public final String getName() { - return this.name; - } - public final URI getUrl() { - return this.url; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getCategorySid() { + return this.categorySid; + } + + public final String getName() { + return this.name; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -141,15 +152,19 @@ public boolean equals(final Object o) { return false; } - InsightsQuestionnairesCategory other = (InsightsQuestionnairesCategory) o; + InsightsQuestionnairesCategory other = + (InsightsQuestionnairesCategory) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(categorySid, other.categorySid) && Objects.equals(name, other.name) && Objects.equals(url, other.url) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(categorySid, other.categorySid) && + Objects.equals(name, other.name) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { return Objects.hash(accountSid, categorySid, name, url); } - } - diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesCategoryCreator.java b/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesCategoryCreator.java index 500b668cd5..1ba3a544c0 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesCategoryCreator.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesCategoryCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.flexapi.v1; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,9 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class InsightsQuestionnairesCategoryCreator + extends Creator { - - -public class InsightsQuestionnairesCategoryCreator extends Creator{ private String name; private String authorization; @@ -35,51 +35,65 @@ public InsightsQuestionnairesCategoryCreator(final String name) { this.name = name; } - public InsightsQuestionnairesCategoryCreator setName(final String name){ + public InsightsQuestionnairesCategoryCreator setName(final String name) { this.name = name; return this; } - public InsightsQuestionnairesCategoryCreator setAuthorization(final String authorization){ + + public InsightsQuestionnairesCategoryCreator setAuthorization( + final String authorization + ) { this.authorization = authorization; return this; } @Override - public InsightsQuestionnairesCategory create(final TwilioRestClient client){ + public InsightsQuestionnairesCategory create( + final TwilioRestClient client + ) { String path = "/v1/Insights/QualityManagement/Categories"; - path = path.replace("{"+"Name"+"}", this.name.toString()); + path = path.replace("{" + "Name" + "}", this.name.toString()); Request request = new Request( HttpMethod.POST, Domains.FLEXAPI.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); addHeaderParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("InsightsQuestionnairesCategory creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "InsightsQuestionnairesCategory creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return InsightsQuestionnairesCategory.fromJson(response.getStream(), client.getObjectMapper()); + return InsightsQuestionnairesCategory.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (name != null) { request.addPostParam("Name", name); - } } + private void addHeaderParams(final Request request) { if (authorization != null) { request.addHeaderParam("Authorization", authorization); - } } } diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesCategoryDeleter.java b/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesCategoryDeleter.java index 11e5483480..fe23344ba2 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesCategoryDeleter.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesCategoryDeleter.java @@ -24,17 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class InsightsQuestionnairesCategoryDeleter + extends Deleter { - -public class InsightsQuestionnairesCategoryDeleter extends Deleter { private String pathCategorySid; private String authorization; - public InsightsQuestionnairesCategoryDeleter(final String pathCategorySid){ + public InsightsQuestionnairesCategoryDeleter(final String pathCategorySid) { this.pathCategorySid = pathCategorySid; } - public InsightsQuestionnairesCategoryDeleter setAuthorization(final String authorization){ + public InsightsQuestionnairesCategoryDeleter setAuthorization( + final String authorization + ) { this.authorization = authorization; return this; } @@ -43,7 +45,11 @@ public InsightsQuestionnairesCategoryDeleter setAuthorization(final String autho public boolean delete(final TwilioRestClient client) { String path = "/v1/Insights/QualityManagement/Categories/{CategorySid}"; - path = path.replace("{"+"CategorySid"+"}", this.pathCategorySid.toString()); + path = + path.replace( + "{" + "CategorySid" + "}", + this.pathCategorySid.toString() + ); Request request = new Request( HttpMethod.DELETE, @@ -54,9 +60,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("InsightsQuestionnairesCategory delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "InsightsQuestionnairesCategory delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -64,10 +75,10 @@ public boolean delete(final TwilioRestClient client) { } return response.getStatusCode() == 204; } + private void addHeaderParams(final Request request) { if (authorization != null) { request.addHeaderParam("Authorization", authorization); - } } } diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesCategoryReader.java b/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesCategoryReader.java index 2af503d702..0ebb7a1a3a 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesCategoryReader.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesCategoryReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.flexapi.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,32 +25,39 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - +public class InsightsQuestionnairesCategoryReader + extends Reader { -public class InsightsQuestionnairesCategoryReader extends Reader { private String authorization; private Integer pageSize; - public InsightsQuestionnairesCategoryReader(){ - } + public InsightsQuestionnairesCategoryReader() {} - public InsightsQuestionnairesCategoryReader setAuthorization(final String authorization){ + public InsightsQuestionnairesCategoryReader setAuthorization( + final String authorization + ) { this.authorization = authorization; return this; } - public InsightsQuestionnairesCategoryReader setPageSize(final Integer pageSize){ + + public InsightsQuestionnairesCategoryReader setPageSize( + final Integer pageSize + ) { this.pageSize = pageSize; return this; } @Override - public ResourceSet read(final TwilioRestClient client) { + public ResourceSet read( + final TwilioRestClient client + ) { return new ResourceSet<>(this, client, firstPage(client)); } - public Page firstPage(final TwilioRestClient client) { + public Page firstPage( + final TwilioRestClient client + ) { String path = "/v1/Insights/QualityManagement/Categories"; Request request = new Request( @@ -63,13 +71,21 @@ public Page firstPage(final TwilioRestClient cli return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("InsightsQuestionnairesCategory read failed: Unable to connect to server"); + throw new ApiConnectionException( + "InsightsQuestionnairesCategory read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -85,7 +101,10 @@ private Page pageForRequest(final TwilioRestClie } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.FLEXAPI.toString()) @@ -93,9 +112,11 @@ public Page previousPage(final Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.FLEXAPI.toString()) @@ -104,27 +125,27 @@ public Page nextPage(final Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addHeaderParams(final Request request) { if (authorization != null) { request.addHeaderParam("Authorization", authorization); - } } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesCategoryUpdater.java b/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesCategoryUpdater.java index 2a7584c2aa..d4c4555552 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesCategoryUpdater.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesCategoryUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.flexapi.v1; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,65 +25,85 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class InsightsQuestionnairesCategoryUpdater + extends Updater { - - -public class InsightsQuestionnairesCategoryUpdater extends Updater{ private String pathCategorySid; private String name; private String authorization; - public InsightsQuestionnairesCategoryUpdater(final String pathCategorySid, final String name){ + public InsightsQuestionnairesCategoryUpdater( + final String pathCategorySid, + final String name + ) { this.pathCategorySid = pathCategorySid; this.name = name; } - public InsightsQuestionnairesCategoryUpdater setName(final String name){ + public InsightsQuestionnairesCategoryUpdater setName(final String name) { this.name = name; return this; } - public InsightsQuestionnairesCategoryUpdater setAuthorization(final String authorization){ + + public InsightsQuestionnairesCategoryUpdater setAuthorization( + final String authorization + ) { this.authorization = authorization; return this; } @Override - public InsightsQuestionnairesCategory update(final TwilioRestClient client){ + public InsightsQuestionnairesCategory update( + final TwilioRestClient client + ) { String path = "/v1/Insights/QualityManagement/Categories/{CategorySid}"; - path = path.replace("{"+"CategorySid"+"}", this.pathCategorySid.toString()); - path = path.replace("{"+"Name"+"}", this.name.toString()); + path = + path.replace( + "{" + "CategorySid" + "}", + this.pathCategorySid.toString() + ); + path = path.replace("{" + "Name" + "}", this.name.toString()); Request request = new Request( HttpMethod.POST, Domains.FLEXAPI.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); addHeaderParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("InsightsQuestionnairesCategory update failed: Unable to connect to server"); + throw new ApiConnectionException( + "InsightsQuestionnairesCategory update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return InsightsQuestionnairesCategory.fromJson(response.getStream(), client.getObjectMapper()); + return InsightsQuestionnairesCategory.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (name != null) { request.addPostParam("Name", name); - } } + private void addHeaderParams(final Request request) { if (authorization != null) { request.addHeaderParam("Authorization", authorization); - } } } diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesCreator.java b/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesCreator.java index 57aa152d80..346067bfdf 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesCreator.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.flexapi.v1; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -25,12 +26,11 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.util.List; - import java.util.List; +public class InsightsQuestionnairesCreator + extends Creator { - -public class InsightsQuestionnairesCreator extends Creator{ private String name; private String authorization; private String description; @@ -41,80 +41,99 @@ public InsightsQuestionnairesCreator(final String name) { this.name = name; } - public InsightsQuestionnairesCreator setName(final String name){ + public InsightsQuestionnairesCreator setName(final String name) { this.name = name; return this; } - public InsightsQuestionnairesCreator setAuthorization(final String authorization){ + + public InsightsQuestionnairesCreator setAuthorization( + final String authorization + ) { this.authorization = authorization; return this; } - public InsightsQuestionnairesCreator setDescription(final String description){ + + public InsightsQuestionnairesCreator setDescription( + final String description + ) { this.description = description; return this; } - public InsightsQuestionnairesCreator setActive(final Boolean active){ + + public InsightsQuestionnairesCreator setActive(final Boolean active) { this.active = active; return this; } - public InsightsQuestionnairesCreator setQuestionSids(final List questionSids){ + + public InsightsQuestionnairesCreator setQuestionSids( + final List questionSids + ) { this.questionSids = questionSids; return this; } - public InsightsQuestionnairesCreator setQuestionSids(final String questionSids){ + + public InsightsQuestionnairesCreator setQuestionSids( + final String questionSids + ) { return setQuestionSids(Promoter.listOfOne(questionSids)); } @Override - public InsightsQuestionnaires create(final TwilioRestClient client){ + public InsightsQuestionnaires create(final TwilioRestClient client) { String path = "/v1/Insights/QualityManagement/Questionnaires"; - path = path.replace("{"+"Name"+"}", this.name.toString()); + path = path.replace("{" + "Name" + "}", this.name.toString()); Request request = new Request( HttpMethod.POST, Domains.FLEXAPI.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); addHeaderParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("InsightsQuestionnaires creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "InsightsQuestionnaires creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return InsightsQuestionnaires.fromJson(response.getStream(), client.getObjectMapper()); + return InsightsQuestionnaires.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (name != null) { request.addPostParam("Name", name); - } if (description != null) { request.addPostParam("Description", description); - } if (active != null) { request.addPostParam("Active", active.toString()); - } if (questionSids != null) { for (String prop : questionSids) { request.addPostParam("QuestionSids", prop); } - } } + private void addHeaderParams(final Request request) { if (authorization != null) { request.addHeaderParam("Authorization", authorization); - } } } diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesDeleter.java b/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesDeleter.java index 95ee60c276..41b8fda818 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesDeleter.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesDeleter.java @@ -24,26 +24,33 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class InsightsQuestionnairesDeleter + extends Deleter { - -public class InsightsQuestionnairesDeleter extends Deleter { private String pathQuestionnaireSid; private String authorization; - public InsightsQuestionnairesDeleter(final String pathQuestionnaireSid){ + public InsightsQuestionnairesDeleter(final String pathQuestionnaireSid) { this.pathQuestionnaireSid = pathQuestionnaireSid; } - public InsightsQuestionnairesDeleter setAuthorization(final String authorization){ + public InsightsQuestionnairesDeleter setAuthorization( + final String authorization + ) { this.authorization = authorization; return this; } @Override public boolean delete(final TwilioRestClient client) { - String path = "/v1/Insights/QualityManagement/Questionnaires/{QuestionnaireSid}"; + String path = + "/v1/Insights/QualityManagement/Questionnaires/{QuestionnaireSid}"; - path = path.replace("{"+"QuestionnaireSid"+"}", this.pathQuestionnaireSid.toString()); + path = + path.replace( + "{" + "QuestionnaireSid" + "}", + this.pathQuestionnaireSid.toString() + ); Request request = new Request( HttpMethod.DELETE, @@ -54,9 +61,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("InsightsQuestionnaires delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "InsightsQuestionnaires delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -64,10 +76,10 @@ public boolean delete(final TwilioRestClient client) { } return response.getStatusCode() == 204; } + private void addHeaderParams(final Request request) { if (authorization != null) { request.addHeaderParam("Authorization", authorization); - } } } diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesFetcher.java b/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesFetcher.java index 5468a154a0..196a61bb5c 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesFetcher.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesFetcher.java @@ -24,27 +24,33 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class InsightsQuestionnairesFetcher + extends Fetcher { - - -public class InsightsQuestionnairesFetcher extends Fetcher { private String pathQuestionnaireSid; private String authorization; - public InsightsQuestionnairesFetcher(final String pathQuestionnaireSid){ + public InsightsQuestionnairesFetcher(final String pathQuestionnaireSid) { this.pathQuestionnaireSid = pathQuestionnaireSid; } - public InsightsQuestionnairesFetcher setAuthorization(final String authorization){ + public InsightsQuestionnairesFetcher setAuthorization( + final String authorization + ) { this.authorization = authorization; return this; } @Override public InsightsQuestionnaires fetch(final TwilioRestClient client) { - String path = "/v1/Insights/QualityManagement/Questionnaires/{QuestionnaireSid}"; + String path = + "/v1/Insights/QualityManagement/Questionnaires/{QuestionnaireSid}"; - path = path.replace("{"+"QuestionnaireSid"+"}", this.pathQuestionnaireSid.toString()); + path = + path.replace( + "{" + "QuestionnaireSid" + "}", + this.pathQuestionnaireSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -55,21 +61,29 @@ public InsightsQuestionnaires fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("InsightsQuestionnaires fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "InsightsQuestionnaires fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return InsightsQuestionnaires.fromJson(response.getStream(), client.getObjectMapper()); + return InsightsQuestionnaires.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addHeaderParams(final Request request) { if (authorization != null) { request.addHeaderParam("Authorization", authorization); - } } } diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesQuestion.java b/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesQuestion.java index b1957f429c..b3f35448fa 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesQuestion.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesQuestion.java @@ -22,53 +22,73 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class InsightsQuestionnairesQuestion extends Resource { + private static final long serialVersionUID = 10229949486791L; - public static InsightsQuestionnairesQuestionCreator creator(final String categorySid, final String question, final String answerSetId, final Boolean allowNa){ - return new InsightsQuestionnairesQuestionCreator(categorySid, question, answerSetId, allowNa); + public static InsightsQuestionnairesQuestionCreator creator( + final String categorySid, + final String question, + final String answerSetId, + final Boolean allowNa + ) { + return new InsightsQuestionnairesQuestionCreator( + categorySid, + question, + answerSetId, + allowNa + ); } - public static InsightsQuestionnairesQuestionDeleter deleter(final String pathQuestionSid){ + public static InsightsQuestionnairesQuestionDeleter deleter( + final String pathQuestionSid + ) { return new InsightsQuestionnairesQuestionDeleter(pathQuestionSid); } - public static InsightsQuestionnairesQuestionReader reader(){ + public static InsightsQuestionnairesQuestionReader reader() { return new InsightsQuestionnairesQuestionReader(); } - public static InsightsQuestionnairesQuestionUpdater updater(final String pathQuestionSid, final Boolean allowNa){ - return new InsightsQuestionnairesQuestionUpdater(pathQuestionSid, allowNa); + public static InsightsQuestionnairesQuestionUpdater updater( + final String pathQuestionSid, + final Boolean allowNa + ) { + return new InsightsQuestionnairesQuestionUpdater( + pathQuestionSid, + allowNa + ); } /** - * Converts a JSON String into a InsightsQuestionnairesQuestion object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return InsightsQuestionnairesQuestion object represented by the provided JSON - */ - public static InsightsQuestionnairesQuestion fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a InsightsQuestionnairesQuestion object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return InsightsQuestionnairesQuestion object represented by the provided JSON + */ + public static InsightsQuestionnairesQuestion fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, InsightsQuestionnairesQuestion.class); + return objectMapper.readValue( + json, + InsightsQuestionnairesQuestion.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -77,17 +97,23 @@ public static InsightsQuestionnairesQuestion fromJson(final String json, final O } /** - * Converts a JSON InputStream into a InsightsQuestionnairesQuestion object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return InsightsQuestionnairesQuestion object represented by the provided JSON - */ - public static InsightsQuestionnairesQuestion fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a InsightsQuestionnairesQuestion object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return InsightsQuestionnairesQuestion object represented by the provided JSON + */ + public static InsightsQuestionnairesQuestion fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, InsightsQuestionnairesQuestion.class); + return objectMapper.readValue( + json, + InsightsQuestionnairesQuestion.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -108,35 +134,16 @@ public static InsightsQuestionnairesQuestion fromJson(final InputStream json, fi @JsonCreator private InsightsQuestionnairesQuestion( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("question_sid") - final String questionSid, - - @JsonProperty("question") - final String question, - - @JsonProperty("description") - final String description, - - @JsonProperty("category") - final Map category, - - @JsonProperty("answer_set_id") - final String answerSetId, - - @JsonProperty("allow_na") - final Boolean allowNa, - - @JsonProperty("usage") - final Integer usage, - - @JsonProperty("answer_set") - final Map answerSet, - - @JsonProperty("url") - final URI url + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("question_sid") final String questionSid, + @JsonProperty("question") final String question, + @JsonProperty("description") final String description, + @JsonProperty("category") final Map category, + @JsonProperty("answer_set_id") final String answerSetId, + @JsonProperty("allow_na") final Boolean allowNa, + @JsonProperty("usage") final Integer usage, + @JsonProperty("answer_set") final Map answerSet, + @JsonProperty("url") final URI url ) { this.accountSid = accountSid; this.questionSid = questionSid; @@ -150,40 +157,49 @@ private InsightsQuestionnairesQuestion( this.url = url; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getQuestionSid() { - return this.questionSid; - } - public final String getQuestion() { - return this.question; - } - public final String getDescription() { - return this.description; - } - public final Map getCategory() { - return this.category; - } - public final String getAnswerSetId() { - return this.answerSetId; - } - public final Boolean getAllowNa() { - return this.allowNa; - } - public final Integer getUsage() { - return this.usage; - } - public final Map getAnswerSet() { - return this.answerSet; - } - public final URI getUrl() { - return this.url; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getQuestionSid() { + return this.questionSid; + } + + public final String getQuestion() { + return this.question; + } + + public final String getDescription() { + return this.description; + } + + public final Map getCategory() { + return this.category; + } + + public final String getAnswerSetId() { + return this.answerSetId; + } + + public final Boolean getAllowNa() { + return this.allowNa; + } + + public final Integer getUsage() { + return this.usage; + } + + public final Map getAnswerSet() { + return this.answerSet; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -191,15 +207,36 @@ public boolean equals(final Object o) { return false; } - InsightsQuestionnairesQuestion other = (InsightsQuestionnairesQuestion) o; - - return Objects.equals(accountSid, other.accountSid) && Objects.equals(questionSid, other.questionSid) && Objects.equals(question, other.question) && Objects.equals(description, other.description) && Objects.equals(category, other.category) && Objects.equals(answerSetId, other.answerSetId) && Objects.equals(allowNa, other.allowNa) && Objects.equals(usage, other.usage) && Objects.equals(answerSet, other.answerSet) && Objects.equals(url, other.url) ; + InsightsQuestionnairesQuestion other = + (InsightsQuestionnairesQuestion) o; + + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(questionSid, other.questionSid) && + Objects.equals(question, other.question) && + Objects.equals(description, other.description) && + Objects.equals(category, other.category) && + Objects.equals(answerSetId, other.answerSetId) && + Objects.equals(allowNa, other.allowNa) && + Objects.equals(usage, other.usage) && + Objects.equals(answerSet, other.answerSet) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, questionSid, question, description, category, answerSetId, allowNa, usage, answerSet, url); + return Objects.hash( + accountSid, + questionSid, + question, + description, + category, + answerSetId, + allowNa, + usage, + answerSet, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesQuestionCreator.java b/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesQuestionCreator.java index b9c9bb826a..ef0218c91c 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesQuestionCreator.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesQuestionCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.flexapi.v1; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,9 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class InsightsQuestionnairesQuestionCreator + extends Creator { - - -public class InsightsQuestionnairesQuestionCreator extends Creator{ private String categorySid; private String question; private String answerSetId; @@ -35,93 +35,130 @@ public class InsightsQuestionnairesQuestionCreator extends Creator { - -public class InsightsQuestionnairesQuestionDeleter extends Deleter { private String pathQuestionSid; private String authorization; - public InsightsQuestionnairesQuestionDeleter(final String pathQuestionSid){ + public InsightsQuestionnairesQuestionDeleter(final String pathQuestionSid) { this.pathQuestionSid = pathQuestionSid; } - public InsightsQuestionnairesQuestionDeleter setAuthorization(final String authorization){ + public InsightsQuestionnairesQuestionDeleter setAuthorization( + final String authorization + ) { this.authorization = authorization; return this; } @@ -43,7 +45,11 @@ public InsightsQuestionnairesQuestionDeleter setAuthorization(final String autho public boolean delete(final TwilioRestClient client) { String path = "/v1/Insights/QualityManagement/Questions/{QuestionSid}"; - path = path.replace("{"+"QuestionSid"+"}", this.pathQuestionSid.toString()); + path = + path.replace( + "{" + "QuestionSid" + "}", + this.pathQuestionSid.toString() + ); Request request = new Request( HttpMethod.DELETE, @@ -54,9 +60,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("InsightsQuestionnairesQuestion delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "InsightsQuestionnairesQuestion delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -64,10 +75,10 @@ public boolean delete(final TwilioRestClient client) { } return response.getStatusCode() == 204; } + private void addHeaderParams(final Request request) { if (authorization != null) { request.addHeaderParam("Authorization", authorization); - } } } diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesQuestionReader.java b/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesQuestionReader.java index 3899a2f422..561484591b 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesQuestionReader.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesQuestionReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.flexapi.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.converter.Promoter; @@ -25,41 +26,54 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - import java.util.List; +public class InsightsQuestionnairesQuestionReader + extends Reader { -public class InsightsQuestionnairesQuestionReader extends Reader { private String authorization; private List categorySid; private Integer pageSize; - public InsightsQuestionnairesQuestionReader(){ - } + public InsightsQuestionnairesQuestionReader() {} - public InsightsQuestionnairesQuestionReader setAuthorization(final String authorization){ + public InsightsQuestionnairesQuestionReader setAuthorization( + final String authorization + ) { this.authorization = authorization; return this; } - public InsightsQuestionnairesQuestionReader setCategorySid(final List categorySid){ + + public InsightsQuestionnairesQuestionReader setCategorySid( + final List categorySid + ) { this.categorySid = categorySid; return this; } - public InsightsQuestionnairesQuestionReader setCategorySid(final String categorySid){ + + public InsightsQuestionnairesQuestionReader setCategorySid( + final String categorySid + ) { return setCategorySid(Promoter.listOfOne(categorySid)); } - public InsightsQuestionnairesQuestionReader setPageSize(final Integer pageSize){ + + public InsightsQuestionnairesQuestionReader setPageSize( + final Integer pageSize + ) { this.pageSize = pageSize; return this; } @Override - public ResourceSet read(final TwilioRestClient client) { + public ResourceSet read( + final TwilioRestClient client + ) { return new ResourceSet<>(this, client, firstPage(client)); } - public Page firstPage(final TwilioRestClient client) { + public Page firstPage( + final TwilioRestClient client + ) { String path = "/v1/Insights/QualityManagement/Questions"; Request request = new Request( @@ -73,13 +87,21 @@ public Page firstPage(final TwilioRestClient cli return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("InsightsQuestionnairesQuestion read failed: Unable to connect to server"); + throw new ApiConnectionException( + "InsightsQuestionnairesQuestion read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -95,7 +117,10 @@ private Page pageForRequest(final TwilioRestClie } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.FLEXAPI.toString()) @@ -103,9 +128,11 @@ public Page previousPage(final Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.FLEXAPI.toString()) @@ -114,20 +141,21 @@ public Page nextPage(final Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addHeaderParams(final Request request) { if (authorization != null) { request.addHeaderParam("Authorization", authorization); - } } + private void addQueryParams(final Request request) { if (categorySid != null) { for (String prop : categorySid) { @@ -135,11 +163,10 @@ private void addQueryParams(final Request request) { } } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesQuestionUpdater.java b/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesQuestionUpdater.java index af7e35146e..a91f6effa5 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesQuestionUpdater.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesQuestionUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.flexapi.v1; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,9 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class InsightsQuestionnairesQuestionUpdater + extends Updater { - - -public class InsightsQuestionnairesQuestionUpdater extends Updater{ private String pathQuestionSid; private Boolean allowNa; private String authorization; @@ -36,89 +36,120 @@ public class InsightsQuestionnairesQuestionUpdater extends Updater { - -public class InsightsQuestionnairesReader extends Reader { private String authorization; private Boolean includeInactive; private Integer pageSize; - public InsightsQuestionnairesReader(){ - } + public InsightsQuestionnairesReader() {} - public InsightsQuestionnairesReader setAuthorization(final String authorization){ + public InsightsQuestionnairesReader setAuthorization( + final String authorization + ) { this.authorization = authorization; return this; } - public InsightsQuestionnairesReader setIncludeInactive(final Boolean includeInactive){ + + public InsightsQuestionnairesReader setIncludeInactive( + final Boolean includeInactive + ) { this.includeInactive = includeInactive; return this; } - public InsightsQuestionnairesReader setPageSize(final Integer pageSize){ + + public InsightsQuestionnairesReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @Override - public ResourceSet read(final TwilioRestClient client) { + public ResourceSet read( + final TwilioRestClient client + ) { return new ResourceSet<>(this, client, firstPage(client)); } - public Page firstPage(final TwilioRestClient client) { + public Page firstPage( + final TwilioRestClient client + ) { String path = "/v1/Insights/QualityManagement/Questionnaires"; Request request = new Request( @@ -68,13 +77,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("InsightsQuestionnaires read failed: Unable to connect to server"); + throw new ApiConnectionException( + "InsightsQuestionnaires read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -90,7 +107,10 @@ private Page pageForRequest(final TwilioRestClient clien } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.FLEXAPI.toString()) @@ -98,9 +118,11 @@ public Page previousPage(final Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.FLEXAPI.toString()) @@ -109,31 +131,33 @@ public Page nextPage(final Page } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addHeaderParams(final Request request) { if (authorization != null) { request.addHeaderParam("Authorization", authorization); - } } + private void addQueryParams(final Request request) { if (includeInactive != null) { - - request.addQueryParam("IncludeInactive", includeInactive.toString()); + request.addQueryParam( + "IncludeInactive", + includeInactive.toString() + ); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesUpdater.java b/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesUpdater.java index a42fb3a395..5e416dc101 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesUpdater.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.flexapi.v1; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -24,12 +25,11 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - import java.util.List; +public class InsightsQuestionnairesUpdater + extends Updater { -public class InsightsQuestionnairesUpdater extends Updater{ private String pathQuestionnaireSid; private Boolean active; private String authorization; @@ -37,86 +37,113 @@ public class InsightsQuestionnairesUpdater extends Updater questionSids; - public InsightsQuestionnairesUpdater(final String pathQuestionnaireSid, final Boolean active){ + public InsightsQuestionnairesUpdater( + final String pathQuestionnaireSid, + final Boolean active + ) { this.pathQuestionnaireSid = pathQuestionnaireSid; this.active = active; } - public InsightsQuestionnairesUpdater setActive(final Boolean active){ + public InsightsQuestionnairesUpdater setActive(final Boolean active) { this.active = active; return this; } - public InsightsQuestionnairesUpdater setAuthorization(final String authorization){ + + public InsightsQuestionnairesUpdater setAuthorization( + final String authorization + ) { this.authorization = authorization; return this; } - public InsightsQuestionnairesUpdater setName(final String name){ + + public InsightsQuestionnairesUpdater setName(final String name) { this.name = name; return this; } - public InsightsQuestionnairesUpdater setDescription(final String description){ + + public InsightsQuestionnairesUpdater setDescription( + final String description + ) { this.description = description; return this; } - public InsightsQuestionnairesUpdater setQuestionSids(final List questionSids){ + + public InsightsQuestionnairesUpdater setQuestionSids( + final List questionSids + ) { this.questionSids = questionSids; return this; } - public InsightsQuestionnairesUpdater setQuestionSids(final String questionSids){ + + public InsightsQuestionnairesUpdater setQuestionSids( + final String questionSids + ) { return setQuestionSids(Promoter.listOfOne(questionSids)); } @Override - public InsightsQuestionnaires update(final TwilioRestClient client){ - String path = "/v1/Insights/QualityManagement/Questionnaires/{QuestionnaireSid}"; + public InsightsQuestionnaires update(final TwilioRestClient client) { + String path = + "/v1/Insights/QualityManagement/Questionnaires/{QuestionnaireSid}"; - path = path.replace("{"+"QuestionnaireSid"+"}", this.pathQuestionnaireSid.toString()); - path = path.replace("{"+"Active"+"}", this.active.toString()); + path = + path.replace( + "{" + "QuestionnaireSid" + "}", + this.pathQuestionnaireSid.toString() + ); + path = path.replace("{" + "Active" + "}", this.active.toString()); Request request = new Request( HttpMethod.POST, Domains.FLEXAPI.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); addHeaderParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("InsightsQuestionnaires update failed: Unable to connect to server"); + throw new ApiConnectionException( + "InsightsQuestionnaires update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return InsightsQuestionnaires.fromJson(response.getStream(), client.getObjectMapper()); + return InsightsQuestionnaires.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (active != null) { request.addPostParam("Active", active.toString()); - } if (name != null) { request.addPostParam("Name", name); - } if (description != null) { request.addPostParam("Description", description); - } if (questionSids != null) { for (String prop : questionSids) { request.addPostParam("QuestionSids", prop); } - } } + private void addHeaderParams(final Request request) { if (authorization != null) { request.addHeaderParam("Authorization", authorization); - } } } diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InsightsSegments.java b/src/main/java/com/twilio/rest/flexapi/v1/InsightsSegments.java index 27cc8bbff9..1d9cc8fe50 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/InsightsSegments.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/InsightsSegments.java @@ -22,38 +22,37 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class InsightsSegments extends Resource { + private static final long serialVersionUID = 85034429282364L; - public static InsightsSegmentsReader reader(){ + public static InsightsSegmentsReader reader() { return new InsightsSegmentsReader(); } /** - * Converts a JSON String into a InsightsSegments object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return InsightsSegments object represented by the provided JSON - */ - public static InsightsSegments fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a InsightsSegments object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return InsightsSegments object represented by the provided JSON + */ + public static InsightsSegments fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, InsightsSegments.class); @@ -65,14 +64,17 @@ public static InsightsSegments fromJson(final String json, final ObjectMapper ob } /** - * Converts a JSON InputStream into a InsightsSegments object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return InsightsSegments object represented by the provided JSON - */ - public static InsightsSegments fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a InsightsSegments object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return InsightsSegments object represented by the provided JSON + */ + public static InsightsSegments fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, InsightsSegments.class); @@ -108,71 +110,38 @@ public static InsightsSegments fromJson(final InputStream json, final ObjectMapp @JsonCreator private InsightsSegments( - @JsonProperty("segment_id") - final String segmentId, - - @JsonProperty("external_id") - final String externalId, - - @JsonProperty("queue") - final String queue, - - @JsonProperty("external_contact") - final String externalContact, - - @JsonProperty("external_segment_link_id") - final String externalSegmentLinkId, - - @JsonProperty("date") - final String date, - - @JsonProperty("account_id") - final String accountId, - - @JsonProperty("external_segment_link") - final String externalSegmentLink, - - @JsonProperty("agent_id") - final String agentId, - - @JsonProperty("agent_phone") - final String agentPhone, - - @JsonProperty("agent_name") - final String agentName, - - @JsonProperty("agent_team_name") - final String agentTeamName, - - @JsonProperty("agent_team_name_in_hierarchy") - final String agentTeamNameInHierarchy, - - @JsonProperty("agent_link") - final String agentLink, - - @JsonProperty("customer_phone") - final String customerPhone, - - @JsonProperty("customer_name") - final String customerName, - - @JsonProperty("customer_link") - final String customerLink, - - @JsonProperty("segment_recording_offset") - final String segmentRecordingOffset, - - @JsonProperty("media") - final Map media, - - @JsonProperty("assessment_type") - final Map assessmentType, - - @JsonProperty("assessment_percentage") - final Map assessmentPercentage, - - @JsonProperty("url") - final URI url + @JsonProperty("segment_id") final String segmentId, + @JsonProperty("external_id") final String externalId, + @JsonProperty("queue") final String queue, + @JsonProperty("external_contact") final String externalContact, + @JsonProperty( + "external_segment_link_id" + ) final String externalSegmentLinkId, + @JsonProperty("date") final String date, + @JsonProperty("account_id") final String accountId, + @JsonProperty("external_segment_link") final String externalSegmentLink, + @JsonProperty("agent_id") final String agentId, + @JsonProperty("agent_phone") final String agentPhone, + @JsonProperty("agent_name") final String agentName, + @JsonProperty("agent_team_name") final String agentTeamName, + @JsonProperty( + "agent_team_name_in_hierarchy" + ) final String agentTeamNameInHierarchy, + @JsonProperty("agent_link") final String agentLink, + @JsonProperty("customer_phone") final String customerPhone, + @JsonProperty("customer_name") final String customerName, + @JsonProperty("customer_link") final String customerLink, + @JsonProperty( + "segment_recording_offset" + ) final String segmentRecordingOffset, + @JsonProperty("media") final Map media, + @JsonProperty( + "assessment_type" + ) final Map assessmentType, + @JsonProperty( + "assessment_percentage" + ) final Map assessmentPercentage, + @JsonProperty("url") final URI url ) { this.segmentId = segmentId; this.externalId = externalId; @@ -198,76 +167,97 @@ private InsightsSegments( this.url = url; } - public final String getSegmentId() { - return this.segmentId; - } - public final String getExternalId() { - return this.externalId; - } - public final String getQueue() { - return this.queue; - } - public final String getExternalContact() { - return this.externalContact; - } - public final String getExternalSegmentLinkId() { - return this.externalSegmentLinkId; - } - public final String getDate() { - return this.date; - } - public final String getAccountId() { - return this.accountId; - } - public final String getExternalSegmentLink() { - return this.externalSegmentLink; - } - public final String getAgentId() { - return this.agentId; - } - public final String getAgentPhone() { - return this.agentPhone; - } - public final String getAgentName() { - return this.agentName; - } - public final String getAgentTeamName() { - return this.agentTeamName; - } - public final String getAgentTeamNameInHierarchy() { - return this.agentTeamNameInHierarchy; - } - public final String getAgentLink() { - return this.agentLink; - } - public final String getCustomerPhone() { - return this.customerPhone; - } - public final String getCustomerName() { - return this.customerName; - } - public final String getCustomerLink() { - return this.customerLink; - } - public final String getSegmentRecordingOffset() { - return this.segmentRecordingOffset; - } - public final Map getMedia() { - return this.media; - } - public final Map getAssessmentType() { - return this.assessmentType; - } - public final Map getAssessmentPercentage() { - return this.assessmentPercentage; - } - public final URI getUrl() { - return this.url; - } + public final String getSegmentId() { + return this.segmentId; + } + + public final String getExternalId() { + return this.externalId; + } + + public final String getQueue() { + return this.queue; + } + + public final String getExternalContact() { + return this.externalContact; + } + + public final String getExternalSegmentLinkId() { + return this.externalSegmentLinkId; + } + + public final String getDate() { + return this.date; + } + + public final String getAccountId() { + return this.accountId; + } + + public final String getExternalSegmentLink() { + return this.externalSegmentLink; + } + + public final String getAgentId() { + return this.agentId; + } + + public final String getAgentPhone() { + return this.agentPhone; + } + + public final String getAgentName() { + return this.agentName; + } + + public final String getAgentTeamName() { + return this.agentTeamName; + } + + public final String getAgentTeamNameInHierarchy() { + return this.agentTeamNameInHierarchy; + } + + public final String getAgentLink() { + return this.agentLink; + } + + public final String getCustomerPhone() { + return this.customerPhone; + } + + public final String getCustomerName() { + return this.customerName; + } + + public final String getCustomerLink() { + return this.customerLink; + } + + public final String getSegmentRecordingOffset() { + return this.segmentRecordingOffset; + } + + public final Map getMedia() { + return this.media; + } + + public final Map getAssessmentType() { + return this.assessmentType; + } + + public final Map getAssessmentPercentage() { + return this.assessmentPercentage; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -277,13 +267,66 @@ public boolean equals(final Object o) { InsightsSegments other = (InsightsSegments) o; - return Objects.equals(segmentId, other.segmentId) && Objects.equals(externalId, other.externalId) && Objects.equals(queue, other.queue) && Objects.equals(externalContact, other.externalContact) && Objects.equals(externalSegmentLinkId, other.externalSegmentLinkId) && Objects.equals(date, other.date) && Objects.equals(accountId, other.accountId) && Objects.equals(externalSegmentLink, other.externalSegmentLink) && Objects.equals(agentId, other.agentId) && Objects.equals(agentPhone, other.agentPhone) && Objects.equals(agentName, other.agentName) && Objects.equals(agentTeamName, other.agentTeamName) && Objects.equals(agentTeamNameInHierarchy, other.agentTeamNameInHierarchy) && Objects.equals(agentLink, other.agentLink) && Objects.equals(customerPhone, other.customerPhone) && Objects.equals(customerName, other.customerName) && Objects.equals(customerLink, other.customerLink) && Objects.equals(segmentRecordingOffset, other.segmentRecordingOffset) && Objects.equals(media, other.media) && Objects.equals(assessmentType, other.assessmentType) && Objects.equals(assessmentPercentage, other.assessmentPercentage) && Objects.equals(url, other.url) ; + return ( + Objects.equals(segmentId, other.segmentId) && + Objects.equals(externalId, other.externalId) && + Objects.equals(queue, other.queue) && + Objects.equals(externalContact, other.externalContact) && + Objects.equals( + externalSegmentLinkId, + other.externalSegmentLinkId + ) && + Objects.equals(date, other.date) && + Objects.equals(accountId, other.accountId) && + Objects.equals(externalSegmentLink, other.externalSegmentLink) && + Objects.equals(agentId, other.agentId) && + Objects.equals(agentPhone, other.agentPhone) && + Objects.equals(agentName, other.agentName) && + Objects.equals(agentTeamName, other.agentTeamName) && + Objects.equals( + agentTeamNameInHierarchy, + other.agentTeamNameInHierarchy + ) && + Objects.equals(agentLink, other.agentLink) && + Objects.equals(customerPhone, other.customerPhone) && + Objects.equals(customerName, other.customerName) && + Objects.equals(customerLink, other.customerLink) && + Objects.equals( + segmentRecordingOffset, + other.segmentRecordingOffset + ) && + Objects.equals(media, other.media) && + Objects.equals(assessmentType, other.assessmentType) && + Objects.equals(assessmentPercentage, other.assessmentPercentage) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(segmentId, externalId, queue, externalContact, externalSegmentLinkId, date, accountId, externalSegmentLink, agentId, agentPhone, agentName, agentTeamName, agentTeamNameInHierarchy, agentLink, customerPhone, customerName, customerLink, segmentRecordingOffset, media, assessmentType, assessmentPercentage, url); + return Objects.hash( + segmentId, + externalId, + queue, + externalContact, + externalSegmentLinkId, + date, + accountId, + externalSegmentLink, + agentId, + agentPhone, + agentName, + agentTeamName, + agentTeamNameInHierarchy, + agentLink, + customerPhone, + customerName, + customerLink, + segmentRecordingOffset, + media, + assessmentType, + assessmentPercentage, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InsightsSegmentsReader.java b/src/main/java/com/twilio/rest/flexapi/v1/InsightsSegmentsReader.java index 774f88bec3..571b9e6954 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/InsightsSegmentsReader.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/InsightsSegmentsReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.flexapi.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.converter.Promoter; @@ -25,36 +26,39 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - import java.util.List; - public class InsightsSegmentsReader extends Reader { + private String authorization; private String segmentId; private List reservationId; private Integer pageSize; - public InsightsSegmentsReader(){ - } + public InsightsSegmentsReader() {} - public InsightsSegmentsReader setAuthorization(final String authorization){ + public InsightsSegmentsReader setAuthorization(final String authorization) { this.authorization = authorization; return this; } - public InsightsSegmentsReader setSegmentId(final String segmentId){ + + public InsightsSegmentsReader setSegmentId(final String segmentId) { this.segmentId = segmentId; return this; } - public InsightsSegmentsReader setReservationId(final List reservationId){ + + public InsightsSegmentsReader setReservationId( + final List reservationId + ) { this.reservationId = reservationId; return this; } - public InsightsSegmentsReader setReservationId(final String reservationId){ + + public InsightsSegmentsReader setReservationId(final String reservationId) { return setReservationId(Promoter.listOfOne(reservationId)); } - public InsightsSegmentsReader setPageSize(final Integer pageSize){ + + public InsightsSegmentsReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -78,13 +82,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("InsightsSegments read failed: Unable to connect to server"); + throw new ApiConnectionException( + "InsightsSegments read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -100,7 +112,10 @@ private Page pageForRequest(final TwilioRestClient client, fin } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.FLEXAPI.toString()) @@ -108,9 +123,11 @@ public Page previousPage(final Page page, fi return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.FLEXAPI.toString()) @@ -119,23 +136,23 @@ public Page nextPage(final Page page, final } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addHeaderParams(final Request request) { if (authorization != null) { request.addHeaderParam("Authorization", authorization); - } } + private void addQueryParams(final Request request) { if (segmentId != null) { - request.addQueryParam("SegmentId", segmentId); } if (reservationId != null) { @@ -144,11 +161,10 @@ private void addQueryParams(final Request request) { } } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InsightsSession.java b/src/main/java/com/twilio/rest/flexapi/v1/InsightsSession.java index e46977df81..648283e6e7 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/InsightsSession.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/InsightsSession.java @@ -22,36 +22,35 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class InsightsSession extends Resource { + private static final long serialVersionUID = 184746612300929L; - public static InsightsSessionCreator creator(){ + public static InsightsSessionCreator creator() { return new InsightsSessionCreator(); } /** - * Converts a JSON String into a InsightsSession object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return InsightsSession object represented by the provided JSON - */ - public static InsightsSession fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a InsightsSession object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return InsightsSession object represented by the provided JSON + */ + public static InsightsSession fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, InsightsSession.class); @@ -63,14 +62,17 @@ public static InsightsSession fromJson(final String json, final ObjectMapper obj } /** - * Converts a JSON InputStream into a InsightsSession object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return InsightsSession object represented by the provided JSON - */ - public static InsightsSession fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a InsightsSession object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return InsightsSession object represented by the provided JSON + */ + public static InsightsSession fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, InsightsSession.class); @@ -89,20 +91,11 @@ public static InsightsSession fromJson(final InputStream json, final ObjectMappe @JsonCreator private InsightsSession( - @JsonProperty("workspace_id") - final String workspaceId, - - @JsonProperty("session_expiry") - final String sessionExpiry, - - @JsonProperty("session_id") - final String sessionId, - - @JsonProperty("base_url") - final String baseUrl, - - @JsonProperty("url") - final URI url + @JsonProperty("workspace_id") final String workspaceId, + @JsonProperty("session_expiry") final String sessionExpiry, + @JsonProperty("session_id") final String sessionId, + @JsonProperty("base_url") final String baseUrl, + @JsonProperty("url") final URI url ) { this.workspaceId = workspaceId; this.sessionExpiry = sessionExpiry; @@ -111,25 +104,29 @@ private InsightsSession( this.url = url; } - public final String getWorkspaceId() { - return this.workspaceId; - } - public final String getSessionExpiry() { - return this.sessionExpiry; - } - public final String getSessionId() { - return this.sessionId; - } - public final String getBaseUrl() { - return this.baseUrl; - } - public final URI getUrl() { - return this.url; - } + public final String getWorkspaceId() { + return this.workspaceId; + } + + public final String getSessionExpiry() { + return this.sessionExpiry; + } + + public final String getSessionId() { + return this.sessionId; + } + + public final String getBaseUrl() { + return this.baseUrl; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -139,13 +136,23 @@ public boolean equals(final Object o) { InsightsSession other = (InsightsSession) o; - return Objects.equals(workspaceId, other.workspaceId) && Objects.equals(sessionExpiry, other.sessionExpiry) && Objects.equals(sessionId, other.sessionId) && Objects.equals(baseUrl, other.baseUrl) && Objects.equals(url, other.url) ; + return ( + Objects.equals(workspaceId, other.workspaceId) && + Objects.equals(sessionExpiry, other.sessionExpiry) && + Objects.equals(sessionId, other.sessionId) && + Objects.equals(baseUrl, other.baseUrl) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(workspaceId, sessionExpiry, sessionId, baseUrl, url); + return Objects.hash( + workspaceId, + sessionExpiry, + sessionId, + baseUrl, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InsightsSessionCreator.java b/src/main/java/com/twilio/rest/flexapi/v1/InsightsSessionCreator.java index f1f2cc04df..c89b06e9ee 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/InsightsSessionCreator.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/InsightsSessionCreator.java @@ -24,25 +24,21 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class InsightsSessionCreator extends Creator { - - -public class InsightsSessionCreator extends Creator{ private String authorization; - public InsightsSessionCreator() { - } + public InsightsSessionCreator() {} - public InsightsSessionCreator setAuthorization(final String authorization){ + public InsightsSessionCreator setAuthorization(final String authorization) { this.authorization = authorization; return this; } @Override - public InsightsSession create(final TwilioRestClient client){ + public InsightsSession create(final TwilioRestClient client) { String path = "/v1/Insights/Session"; - Request request = new Request( HttpMethod.POST, Domains.FLEXAPI.toString(), @@ -51,21 +47,29 @@ public InsightsSession create(final TwilioRestClient client){ addHeaderParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("InsightsSession creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "InsightsSession creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return InsightsSession.fromJson(response.getStream(), client.getObjectMapper()); + return InsightsSession.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addHeaderParams(final Request request) { if (authorization != null) { request.addHeaderParam("Authorization", authorization); - } } } diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InsightsSettingsAnswerSets.java b/src/main/java/com/twilio/rest/flexapi/v1/InsightsSettingsAnswerSets.java index 705121b2c2..58634e177e 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/InsightsSettingsAnswerSets.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/InsightsSettingsAnswerSets.java @@ -22,41 +22,43 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class InsightsSettingsAnswerSets extends Resource { + private static final long serialVersionUID = 252326702169213L; - public static InsightsSettingsAnswerSetsFetcher fetcher(){ + public static InsightsSettingsAnswerSetsFetcher fetcher() { return new InsightsSettingsAnswerSetsFetcher(); } /** - * Converts a JSON String into a InsightsSettingsAnswerSets object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return InsightsSettingsAnswerSets object represented by the provided JSON - */ - public static InsightsSettingsAnswerSets fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a InsightsSettingsAnswerSets object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return InsightsSettingsAnswerSets object represented by the provided JSON + */ + public static InsightsSettingsAnswerSets fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, InsightsSettingsAnswerSets.class); + return objectMapper.readValue( + json, + InsightsSettingsAnswerSets.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -65,17 +67,23 @@ public static InsightsSettingsAnswerSets fromJson(final String json, final Objec } /** - * Converts a JSON InputStream into a InsightsSettingsAnswerSets object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return InsightsSettingsAnswerSets object represented by the provided JSON - */ - public static InsightsSettingsAnswerSets fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a InsightsSettingsAnswerSets object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return InsightsSettingsAnswerSets object represented by the provided JSON + */ + public static InsightsSettingsAnswerSets fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, InsightsSettingsAnswerSets.class); + return objectMapper.readValue( + json, + InsightsSettingsAnswerSets.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -91,20 +99,13 @@ public static InsightsSettingsAnswerSets fromJson(final InputStream json, final @JsonCreator private InsightsSettingsAnswerSets( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("answer_sets") - final Map answerSets, - - @JsonProperty("answer_set_categories") - final Map answerSetCategories, - - @JsonProperty("not_applicable") - final Map notApplicable, - - @JsonProperty("url") - final URI url + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("answer_sets") final Map answerSets, + @JsonProperty( + "answer_set_categories" + ) final Map answerSetCategories, + @JsonProperty("not_applicable") final Map notApplicable, + @JsonProperty("url") final URI url ) { this.accountSid = accountSid; this.answerSets = answerSets; @@ -113,25 +114,29 @@ private InsightsSettingsAnswerSets( this.url = url; } - public final String getAccountSid() { - return this.accountSid; - } - public final Map getAnswerSets() { - return this.answerSets; - } - public final Map getAnswerSetCategories() { - return this.answerSetCategories; - } - public final Map getNotApplicable() { - return this.notApplicable; - } - public final URI getUrl() { - return this.url; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final Map getAnswerSets() { + return this.answerSets; + } + + public final Map getAnswerSetCategories() { + return this.answerSetCategories; + } + + public final Map getNotApplicable() { + return this.notApplicable; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -141,13 +146,23 @@ public boolean equals(final Object o) { InsightsSettingsAnswerSets other = (InsightsSettingsAnswerSets) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(answerSets, other.answerSets) && Objects.equals(answerSetCategories, other.answerSetCategories) && Objects.equals(notApplicable, other.notApplicable) && Objects.equals(url, other.url) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(answerSets, other.answerSets) && + Objects.equals(answerSetCategories, other.answerSetCategories) && + Objects.equals(notApplicable, other.notApplicable) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, answerSets, answerSetCategories, notApplicable, url); + return Objects.hash( + accountSid, + answerSets, + answerSetCategories, + notApplicable, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InsightsSettingsAnswerSetsFetcher.java b/src/main/java/com/twilio/rest/flexapi/v1/InsightsSettingsAnswerSetsFetcher.java index b0f1d166f6..eea4d9bf98 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/InsightsSettingsAnswerSetsFetcher.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/InsightsSettingsAnswerSetsFetcher.java @@ -24,16 +24,16 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class InsightsSettingsAnswerSetsFetcher + extends Fetcher { - - -public class InsightsSettingsAnswerSetsFetcher extends Fetcher { private String authorization; - public InsightsSettingsAnswerSetsFetcher(){ - } + public InsightsSettingsAnswerSetsFetcher() {} - public InsightsSettingsAnswerSetsFetcher setAuthorization(final String authorization){ + public InsightsSettingsAnswerSetsFetcher setAuthorization( + final String authorization + ) { this.authorization = authorization; return this; } @@ -42,7 +42,6 @@ public InsightsSettingsAnswerSetsFetcher setAuthorization(final String authoriza public InsightsSettingsAnswerSets fetch(final TwilioRestClient client) { String path = "/v1/Insights/QualityManagement/Settings/AnswerSets"; - Request request = new Request( HttpMethod.GET, Domains.FLEXAPI.toString(), @@ -52,21 +51,29 @@ public InsightsSettingsAnswerSets fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("InsightsSettingsAnswerSets fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "InsightsSettingsAnswerSets fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return InsightsSettingsAnswerSets.fromJson(response.getStream(), client.getObjectMapper()); + return InsightsSettingsAnswerSets.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addHeaderParams(final Request request) { if (authorization != null) { request.addHeaderParam("Authorization", authorization); - } } } diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InsightsSettingsComment.java b/src/main/java/com/twilio/rest/flexapi/v1/InsightsSettingsComment.java index 7f2f25b326..90afe4c870 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/InsightsSettingsComment.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/InsightsSettingsComment.java @@ -22,38 +22,37 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class InsightsSettingsComment extends Resource { + private static final long serialVersionUID = 241533672645071L; - public static InsightsSettingsCommentFetcher fetcher(){ + public static InsightsSettingsCommentFetcher fetcher() { return new InsightsSettingsCommentFetcher(); } /** - * Converts a JSON String into a InsightsSettingsComment object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return InsightsSettingsComment object represented by the provided JSON - */ - public static InsightsSettingsComment fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a InsightsSettingsComment object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return InsightsSettingsComment object represented by the provided JSON + */ + public static InsightsSettingsComment fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, InsightsSettingsComment.class); @@ -65,14 +64,17 @@ public static InsightsSettingsComment fromJson(final String json, final ObjectMa } /** - * Converts a JSON InputStream into a InsightsSettingsComment object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return InsightsSettingsComment object represented by the provided JSON - */ - public static InsightsSettingsComment fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a InsightsSettingsComment object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return InsightsSettingsComment object represented by the provided JSON + */ + public static InsightsSettingsComment fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, InsightsSettingsComment.class); @@ -89,33 +91,30 @@ public static InsightsSettingsComment fromJson(final InputStream json, final Obj @JsonCreator private InsightsSettingsComment( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("comments") - final Map comments, - - @JsonProperty("url") - final URI url + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("comments") final Map comments, + @JsonProperty("url") final URI url ) { this.accountSid = accountSid; this.comments = comments; this.url = url; } - public final String getAccountSid() { - return this.accountSid; - } - public final Map getComments() { - return this.comments; - } - public final URI getUrl() { - return this.url; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final Map getComments() { + return this.comments; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -125,13 +124,15 @@ public boolean equals(final Object o) { InsightsSettingsComment other = (InsightsSettingsComment) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(comments, other.comments) && Objects.equals(url, other.url) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(comments, other.comments) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { return Objects.hash(accountSid, comments, url); } - } - diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InsightsSettingsCommentFetcher.java b/src/main/java/com/twilio/rest/flexapi/v1/InsightsSettingsCommentFetcher.java index 9376a4b577..4bb36308ea 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/InsightsSettingsCommentFetcher.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/InsightsSettingsCommentFetcher.java @@ -24,16 +24,16 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class InsightsSettingsCommentFetcher + extends Fetcher { - - -public class InsightsSettingsCommentFetcher extends Fetcher { private String authorization; - public InsightsSettingsCommentFetcher(){ - } + public InsightsSettingsCommentFetcher() {} - public InsightsSettingsCommentFetcher setAuthorization(final String authorization){ + public InsightsSettingsCommentFetcher setAuthorization( + final String authorization + ) { this.authorization = authorization; return this; } @@ -42,7 +42,6 @@ public InsightsSettingsCommentFetcher setAuthorization(final String authorizatio public InsightsSettingsComment fetch(final TwilioRestClient client) { String path = "/v1/Insights/QualityManagement/Settings/CommentTags"; - Request request = new Request( HttpMethod.GET, Domains.FLEXAPI.toString(), @@ -52,21 +51,29 @@ public InsightsSettingsComment fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("InsightsSettingsComment fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "InsightsSettingsComment fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return InsightsSettingsComment.fromJson(response.getStream(), client.getObjectMapper()); + return InsightsSettingsComment.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addHeaderParams(final Request request) { if (authorization != null) { request.addHeaderParam("Authorization", authorization); - } } } diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InsightsUserRoles.java b/src/main/java/com/twilio/rest/flexapi/v1/InsightsUserRoles.java index 1c76837916..f9a82520c0 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/InsightsUserRoles.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/InsightsUserRoles.java @@ -22,37 +22,36 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.List; import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class InsightsUserRoles extends Resource { + private static final long serialVersionUID = 154216272914379L; - public static InsightsUserRolesFetcher fetcher(){ + public static InsightsUserRolesFetcher fetcher() { return new InsightsUserRolesFetcher(); } /** - * Converts a JSON String into a InsightsUserRoles object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return InsightsUserRoles object represented by the provided JSON - */ - public static InsightsUserRoles fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a InsightsUserRoles object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return InsightsUserRoles object represented by the provided JSON + */ + public static InsightsUserRoles fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, InsightsUserRoles.class); @@ -64,14 +63,17 @@ public static InsightsUserRoles fromJson(final String json, final ObjectMapper o } /** - * Converts a JSON InputStream into a InsightsUserRoles object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return InsightsUserRoles object represented by the provided JSON - */ - public static InsightsUserRoles fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a InsightsUserRoles object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return InsightsUserRoles object represented by the provided JSON + */ + public static InsightsUserRoles fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, InsightsUserRoles.class); @@ -87,26 +89,24 @@ public static InsightsUserRoles fromJson(final InputStream json, final ObjectMap @JsonCreator private InsightsUserRoles( - @JsonProperty("roles") - final List roles, - - @JsonProperty("url") - final URI url + @JsonProperty("roles") final List roles, + @JsonProperty("url") final URI url ) { this.roles = roles; this.url = url; } - public final List getRoles() { - return this.roles; - } - public final URI getUrl() { - return this.url; - } + public final List getRoles() { + return this.roles; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -116,13 +116,13 @@ public boolean equals(final Object o) { InsightsUserRoles other = (InsightsUserRoles) o; - return Objects.equals(roles, other.roles) && Objects.equals(url, other.url) ; + return ( + Objects.equals(roles, other.roles) && Objects.equals(url, other.url) + ); } @Override public int hashCode() { return Objects.hash(roles, url); } - } - diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InsightsUserRolesFetcher.java b/src/main/java/com/twilio/rest/flexapi/v1/InsightsUserRolesFetcher.java index 7f99233939..9d3ec0992b 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/InsightsUserRolesFetcher.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/InsightsUserRolesFetcher.java @@ -24,16 +24,15 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class InsightsUserRolesFetcher extends Fetcher { + private String authorization; - public InsightsUserRolesFetcher(){ - } + public InsightsUserRolesFetcher() {} - public InsightsUserRolesFetcher setAuthorization(final String authorization){ + public InsightsUserRolesFetcher setAuthorization( + final String authorization + ) { this.authorization = authorization; return this; } @@ -42,7 +41,6 @@ public InsightsUserRolesFetcher setAuthorization(final String authorization){ public InsightsUserRoles fetch(final TwilioRestClient client) { String path = "/v1/Insights/UserRoles"; - Request request = new Request( HttpMethod.GET, Domains.FLEXAPI.toString(), @@ -52,21 +50,29 @@ public InsightsUserRoles fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("InsightsUserRoles fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "InsightsUserRoles fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return InsightsUserRoles.fromJson(response.getStream(), client.getObjectMapper()); + return InsightsUserRoles.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addHeaderParams(final Request request) { if (authorization != null) { request.addHeaderParam("Authorization", authorization); - } } } diff --git a/src/main/java/com/twilio/rest/flexapi/v1/Interaction.java b/src/main/java/com/twilio/rest/flexapi/v1/Interaction.java index e013e4737e..1af90ef336 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/Interaction.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/Interaction.java @@ -22,42 +22,44 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Interaction extends Resource { - private static final long serialVersionUID = 122002847153214L; - public static InteractionCreator creator(final Map channel, final Map routing){ + private static final long serialVersionUID = 1684368631913L; + + public static InteractionCreator creator( + final Map channel, + final Map routing + ) { return new InteractionCreator(channel, routing); } - public static InteractionFetcher fetcher(final String pathSid){ + public static InteractionFetcher fetcher(final String pathSid) { return new InteractionFetcher(pathSid); } /** - * Converts a JSON String into a Interaction object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Interaction object represented by the provided JSON - */ - public static Interaction fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Interaction object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Interaction object represented by the provided JSON + */ + public static Interaction fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Interaction.class); @@ -69,14 +71,17 @@ public static Interaction fromJson(final String json, final ObjectMapper objectM } /** - * Converts a JSON InputStream into a Interaction object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Interaction object represented by the provided JSON - */ - public static Interaction fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Interaction object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Interaction object represented by the provided JSON + */ + public static Interaction fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Interaction.class); @@ -92,50 +97,54 @@ public static Interaction fromJson(final InputStream json, final ObjectMapper ob private final Map routing; private final URI url; private final Map links; + private final String interactionContextSid; @JsonCreator private Interaction( - @JsonProperty("sid") - final String sid, - - @JsonProperty("channel") - final Map channel, - - @JsonProperty("routing") - final Map routing, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("sid") final String sid, + @JsonProperty("channel") final Map channel, + @JsonProperty("routing") final Map routing, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links, + @JsonProperty( + "interaction_context_sid" + ) final String interactionContextSid ) { this.sid = sid; this.channel = channel; this.routing = routing; this.url = url; this.links = links; + this.interactionContextSid = interactionContextSid; } - public final String getSid() { - return this.sid; - } - public final Map getChannel() { - return this.channel; - } - public final Map getRouting() { - return this.routing; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getSid() { + return this.sid; + } + + public final Map getChannel() { + return this.channel; + } + + public final Map getRouting() { + return this.routing; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } + + public final String getInteractionContextSid() { + return this.interactionContextSid; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -145,13 +154,25 @@ public boolean equals(final Object o) { Interaction other = (Interaction) o; - return Objects.equals(sid, other.sid) && Objects.equals(channel, other.channel) && Objects.equals(routing, other.routing) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(channel, other.channel) && + Objects.equals(routing, other.routing) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) && + Objects.equals(interactionContextSid, other.interactionContextSid) + ); } @Override public int hashCode() { - return Objects.hash(sid, channel, routing, url, links); + return Objects.hash( + sid, + channel, + routing, + url, + links, + interactionContextSid + ); } - } - diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InteractionCreator.java b/src/main/java/com/twilio/rest/flexapi/v1/InteractionCreator.java index df13c3f72a..298da0791b 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/InteractionCreator.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/InteractionCreator.java @@ -15,8 +15,10 @@ package com.twilio.rest.flexapi.v1; import com.twilio.base.Creator; -import com.twilio.exception.ApiConnectionException; +import com.twilio.constant.EnumConstants; +import com.twilio.converter.Converter; import com.twilio.converter.Converter; +import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; @@ -25,64 +27,87 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.util.Map; -import com.twilio.converter.Converter; - import java.util.Map; +public class InteractionCreator extends Creator { - -public class InteractionCreator extends Creator{ private Map channel; private Map routing; + private String interactionContextSid; - public InteractionCreator(final Map channel, final Map routing) { + public InteractionCreator( + final Map channel, + final Map routing + ) { this.channel = channel; this.routing = routing; } - public InteractionCreator setChannel(final Map channel){ + public InteractionCreator setChannel(final Map channel) { this.channel = channel; return this; } - public InteractionCreator setRouting(final Map routing){ + + public InteractionCreator setRouting(final Map routing) { this.routing = routing; return this; } + public InteractionCreator setInteractionContextSid( + final String interactionContextSid + ) { + this.interactionContextSid = interactionContextSid; + return this; + } + @Override - public Interaction create(final TwilioRestClient client){ + public Interaction create(final TwilioRestClient client) { String path = "/v1/Interactions"; - path = path.replace("{"+"Channel"+"}", this.channel.toString()); - path = path.replace("{"+"Routing"+"}", this.routing.toString()); + path = path.replace("{" + "Channel" + "}", this.channel.toString()); + path = path.replace("{" + "Routing" + "}", this.routing.toString()); Request request = new Request( HttpMethod.POST, Domains.FLEXAPI.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Interaction creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Interaction creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Interaction.fromJson(response.getStream(), client.getObjectMapper()); + return Interaction.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (channel != null) { - request.addPostParam("Channel", Converter.mapToJson(channel)); - + request.addPostParam("Channel", Converter.mapToJson(channel)); } if (routing != null) { - request.addPostParam("Routing", Converter.mapToJson(routing)); - + request.addPostParam("Routing", Converter.mapToJson(routing)); + } + if (interactionContextSid != null) { + request.addPostParam( + "InteractionContextSid", + interactionContextSid + ); } } } diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InteractionFetcher.java b/src/main/java/com/twilio/rest/flexapi/v1/InteractionFetcher.java index fa78f91e6f..a2f0a755d5 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/InteractionFetcher.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/InteractionFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class InteractionFetcher extends Fetcher { + private String pathSid; - public InteractionFetcher(final String pathSid){ + public InteractionFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public Interaction fetch(final TwilioRestClient client) { String path = "/v1/Interactions/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,15 +46,23 @@ public Interaction fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Interaction fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Interaction fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Interaction.fromJson(response.getStream(), client.getObjectMapper()); + return Interaction.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/flexapi/v1/WebChannel.java b/src/main/java/com/twilio/rest/flexapi/v1/WebChannel.java index 2e29a53dd1..f4f2c05134 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/WebChannel.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/WebChannel.java @@ -24,53 +24,62 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class WebChannel extends Resource { + private static final long serialVersionUID = 55535071818984L; - public static WebChannelCreator creator(final String flexFlowSid, final String identity, final String customerFriendlyName, final String chatFriendlyName){ - return new WebChannelCreator(flexFlowSid, identity, customerFriendlyName, chatFriendlyName); + public static WebChannelCreator creator( + final String flexFlowSid, + final String identity, + final String customerFriendlyName, + final String chatFriendlyName + ) { + return new WebChannelCreator( + flexFlowSid, + identity, + customerFriendlyName, + chatFriendlyName + ); } - public static WebChannelDeleter deleter(final String pathSid){ + public static WebChannelDeleter deleter(final String pathSid) { return new WebChannelDeleter(pathSid); } - public static WebChannelFetcher fetcher(final String pathSid){ + public static WebChannelFetcher fetcher(final String pathSid) { return new WebChannelFetcher(pathSid); } - public static WebChannelReader reader(){ + public static WebChannelReader reader() { return new WebChannelReader(); } - public static WebChannelUpdater updater(final String pathSid){ + public static WebChannelUpdater updater(final String pathSid) { return new WebChannelUpdater(pathSid); } /** - * Converts a JSON String into a WebChannel object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return WebChannel object represented by the provided JSON - */ - public static WebChannel fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a WebChannel object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return WebChannel object represented by the provided JSON + */ + public static WebChannel fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, WebChannel.class); @@ -82,14 +91,17 @@ public static WebChannel fromJson(final String json, final ObjectMapper objectMa } /** - * Converts a JSON InputStream into a WebChannel object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return WebChannel object represented by the provided JSON - */ - public static WebChannel fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a WebChannel object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return WebChannel object represented by the provided JSON + */ + public static WebChannel fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, WebChannel.class); @@ -99,6 +111,7 @@ public static WebChannel fromJson(final InputStream json, final ObjectMapper obj throw new ApiConnectionException(e.getMessage(), e); } } + public enum ChatStatus { INACTIVE("inactive"); @@ -127,23 +140,12 @@ public static ChatStatus forValue(final String value) { @JsonCreator private WebChannel( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("flex_flow_sid") - final String flexFlowSid, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("url") - final URI url, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("flex_flow_sid") final String flexFlowSid, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated ) { this.accountSid = accountSid; this.flexFlowSid = flexFlowSid; @@ -153,28 +155,33 @@ private WebChannel( this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); } - public final String getAccountSid() { - return this.accountSid; - } - public final String getFlexFlowSid() { - return this.flexFlowSid; - } - public final String getSid() { - return this.sid; - } - public final URI getUrl() { - return this.url; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getFlexFlowSid() { + return this.flexFlowSid; + } + + public final String getSid() { + return this.sid; + } + + public final URI getUrl() { + return this.url; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -184,13 +191,25 @@ public boolean equals(final Object o) { WebChannel other = (WebChannel) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(flexFlowSid, other.flexFlowSid) && Objects.equals(sid, other.sid) && Objects.equals(url, other.url) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(flexFlowSid, other.flexFlowSid) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, flexFlowSid, sid, url, dateCreated, dateUpdated); + return Objects.hash( + accountSid, + flexFlowSid, + sid, + url, + dateCreated, + dateUpdated + ); } - } - diff --git a/src/main/java/com/twilio/rest/flexapi/v1/WebChannelCreator.java b/src/main/java/com/twilio/rest/flexapi/v1/WebChannelCreator.java index 956c286967..50dd93cbd7 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/WebChannelCreator.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/WebChannelCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.flexapi.v1; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class WebChannelCreator extends Creator { - - -public class WebChannelCreator extends Creator{ private String flexFlowSid; private String identity; private String customerFriendlyName; @@ -35,90 +34,122 @@ public class WebChannelCreator extends Creator{ private String chatUniqueName; private String preEngagementData; - public WebChannelCreator(final String flexFlowSid, final String identity, final String customerFriendlyName, final String chatFriendlyName) { + public WebChannelCreator( + final String flexFlowSid, + final String identity, + final String customerFriendlyName, + final String chatFriendlyName + ) { this.flexFlowSid = flexFlowSid; this.identity = identity; this.customerFriendlyName = customerFriendlyName; this.chatFriendlyName = chatFriendlyName; } - public WebChannelCreator setFlexFlowSid(final String flexFlowSid){ + public WebChannelCreator setFlexFlowSid(final String flexFlowSid) { this.flexFlowSid = flexFlowSid; return this; } - public WebChannelCreator setIdentity(final String identity){ + + public WebChannelCreator setIdentity(final String identity) { this.identity = identity; return this; } - public WebChannelCreator setCustomerFriendlyName(final String customerFriendlyName){ + + public WebChannelCreator setCustomerFriendlyName( + final String customerFriendlyName + ) { this.customerFriendlyName = customerFriendlyName; return this; } - public WebChannelCreator setChatFriendlyName(final String chatFriendlyName){ + + public WebChannelCreator setChatFriendlyName( + final String chatFriendlyName + ) { this.chatFriendlyName = chatFriendlyName; return this; } - public WebChannelCreator setChatUniqueName(final String chatUniqueName){ + + public WebChannelCreator setChatUniqueName(final String chatUniqueName) { this.chatUniqueName = chatUniqueName; return this; } - public WebChannelCreator setPreEngagementData(final String preEngagementData){ + + public WebChannelCreator setPreEngagementData( + final String preEngagementData + ) { this.preEngagementData = preEngagementData; return this; } @Override - public WebChannel create(final TwilioRestClient client){ + public WebChannel create(final TwilioRestClient client) { String path = "/v1/WebChannels"; - path = path.replace("{"+"FlexFlowSid"+"}", this.flexFlowSid.toString()); - path = path.replace("{"+"Identity"+"}", this.identity.toString()); - path = path.replace("{"+"CustomerFriendlyName"+"}", this.customerFriendlyName.toString()); - path = path.replace("{"+"ChatFriendlyName"+"}", this.chatFriendlyName.toString()); + path = + path.replace( + "{" + "FlexFlowSid" + "}", + this.flexFlowSid.toString() + ); + path = path.replace("{" + "Identity" + "}", this.identity.toString()); + path = + path.replace( + "{" + "CustomerFriendlyName" + "}", + this.customerFriendlyName.toString() + ); + path = + path.replace( + "{" + "ChatFriendlyName" + "}", + this.chatFriendlyName.toString() + ); Request request = new Request( HttpMethod.POST, Domains.FLEXAPI.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("WebChannel creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "WebChannel creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return WebChannel.fromJson(response.getStream(), client.getObjectMapper()); + return WebChannel.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (flexFlowSid != null) { request.addPostParam("FlexFlowSid", flexFlowSid); - } if (identity != null) { request.addPostParam("Identity", identity); - } if (customerFriendlyName != null) { request.addPostParam("CustomerFriendlyName", customerFriendlyName); - } if (chatFriendlyName != null) { request.addPostParam("ChatFriendlyName", chatFriendlyName); - } if (chatUniqueName != null) { request.addPostParam("ChatUniqueName", chatUniqueName); - } if (preEngagementData != null) { request.addPostParam("PreEngagementData", preEngagementData); - } } } diff --git a/src/main/java/com/twilio/rest/flexapi/v1/WebChannelDeleter.java b/src/main/java/com/twilio/rest/flexapi/v1/WebChannelDeleter.java index 85dae379f5..31dc719721 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/WebChannelDeleter.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/WebChannelDeleter.java @@ -24,21 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class WebChannelDeleter extends Deleter { + private String pathSid; - public WebChannelDeleter(final String pathSid){ + public WebChannelDeleter(final String pathSid) { this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/WebChannels/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -48,9 +46,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("WebChannel delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "WebChannel delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/flexapi/v1/WebChannelFetcher.java b/src/main/java/com/twilio/rest/flexapi/v1/WebChannelFetcher.java index fd9220d51f..c16f519e9f 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/WebChannelFetcher.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/WebChannelFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class WebChannelFetcher extends Fetcher { + private String pathSid; - public WebChannelFetcher(final String pathSid){ + public WebChannelFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public WebChannel fetch(final TwilioRestClient client) { String path = "/v1/WebChannels/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,15 +46,23 @@ public WebChannel fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("WebChannel fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "WebChannel fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return WebChannel.fromJson(response.getStream(), client.getObjectMapper()); + return WebChannel.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/flexapi/v1/WebChannelReader.java b/src/main/java/com/twilio/rest/flexapi/v1/WebChannelReader.java index f55c73a050..4f35ff2e01 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/WebChannelReader.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/WebChannelReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.flexapi.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,17 +25,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class WebChannelReader extends Reader { + private Integer pageSize; - public WebChannelReader(){ - } + public WebChannelReader() {} - public WebChannelReader setPageSize(final Integer pageSize){ + public WebChannelReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -57,13 +55,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("WebChannel read failed: Unable to connect to server"); + throw new ApiConnectionException( + "WebChannel read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -79,7 +85,10 @@ private Page pageForRequest(final TwilioRestClient client, final Req } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.FLEXAPI.toString()) @@ -87,9 +96,11 @@ public Page previousPage(final Page page, final TwilioRe return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.FLEXAPI.toString()) @@ -98,21 +109,21 @@ public Page nextPage(final Page page, final TwilioRestCl } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/flexapi/v1/WebChannelUpdater.java b/src/main/java/com/twilio/rest/flexapi/v1/WebChannelUpdater.java index 18ee9c08c4..dfc4aebe9b 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/WebChannelUpdater.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/WebChannelUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.flexapi.v1; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,60 +25,71 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class WebChannelUpdater extends Updater { - - -public class WebChannelUpdater extends Updater{ private String pathSid; private WebChannel.ChatStatus chatStatus; private String postEngagementData; - public WebChannelUpdater(final String pathSid){ + public WebChannelUpdater(final String pathSid) { this.pathSid = pathSid; } - public WebChannelUpdater setChatStatus(final WebChannel.ChatStatus chatStatus){ + public WebChannelUpdater setChatStatus( + final WebChannel.ChatStatus chatStatus + ) { this.chatStatus = chatStatus; return this; } - public WebChannelUpdater setPostEngagementData(final String postEngagementData){ + + public WebChannelUpdater setPostEngagementData( + final String postEngagementData + ) { this.postEngagementData = postEngagementData; return this; } @Override - public WebChannel update(final TwilioRestClient client){ + public WebChannel update(final TwilioRestClient client) { String path = "/v1/WebChannels/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.FLEXAPI.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("WebChannel update failed: Unable to connect to server"); + throw new ApiConnectionException( + "WebChannel update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return WebChannel.fromJson(response.getStream(), client.getObjectMapper()); + return WebChannel.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (chatStatus != null) { request.addPostParam("ChatStatus", chatStatus.toString()); - } if (postEngagementData != null) { request.addPostParam("PostEngagementData", postEngagementData); - } } } diff --git a/src/main/java/com/twilio/rest/flexapi/v1/interaction/InteractionChannel.java b/src/main/java/com/twilio/rest/flexapi/v1/interaction/InteractionChannel.java index e2e7d4502c..a26c79682e 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/interaction/InteractionChannel.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/interaction/InteractionChannel.java @@ -23,46 +23,58 @@ import com.twilio.base.Resource; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class InteractionChannel extends Resource { + private static final long serialVersionUID = 96183028905472L; - public static InteractionChannelFetcher fetcher(final String pathInteractionSid, final String pathSid){ + public static InteractionChannelFetcher fetcher( + final String pathInteractionSid, + final String pathSid + ) { return new InteractionChannelFetcher(pathInteractionSid, pathSid); } - public static InteractionChannelReader reader(final String pathInteractionSid){ + public static InteractionChannelReader reader( + final String pathInteractionSid + ) { return new InteractionChannelReader(pathInteractionSid); } - public static InteractionChannelUpdater updater(final String pathInteractionSid, final String pathSid, final InteractionChannel.Status status){ - return new InteractionChannelUpdater(pathInteractionSid, pathSid, status); + public static InteractionChannelUpdater updater( + final String pathInteractionSid, + final String pathSid, + final InteractionChannel.Status status + ) { + return new InteractionChannelUpdater( + pathInteractionSid, + pathSid, + status + ); } /** - * Converts a JSON String into a InteractionChannel object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return InteractionChannel object represented by the provided JSON - */ - public static InteractionChannel fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a InteractionChannel object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return InteractionChannel object represented by the provided JSON + */ + public static InteractionChannel fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, InteractionChannel.class); @@ -74,14 +86,17 @@ public static InteractionChannel fromJson(final String json, final ObjectMapper } /** - * Converts a JSON InputStream into a InteractionChannel object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return InteractionChannel object represented by the provided JSON - */ - public static InteractionChannel fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a InteractionChannel object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return InteractionChannel object represented by the provided JSON + */ + public static InteractionChannel fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, InteractionChannel.class); @@ -91,6 +106,7 @@ public static InteractionChannel fromJson(final InputStream json, final ObjectMa throw new ApiConnectionException(e.getMessage(), e); } } + public enum ChannelStatus { SETUP("setup"), ACTIVE("active"), @@ -112,6 +128,7 @@ public static ChannelStatus forValue(final String value) { return Promoter.enumFromString(value, ChannelStatus.values()); } } + public enum Status { CLOSED("closed"), WRAPUP("wrapup"); @@ -131,6 +148,7 @@ public static Status forValue(final String value) { return Promoter.enumFromString(value, Status.values()); } } + public enum Type { VOICE("voice"), SMS("sms"), @@ -168,29 +186,14 @@ public static Type forValue(final String value) { @JsonCreator private InteractionChannel( - @JsonProperty("sid") - final String sid, - - @JsonProperty("interaction_sid") - final String interactionSid, - - @JsonProperty("type") - final InteractionChannel.Type type, - - @JsonProperty("status") - final InteractionChannel.ChannelStatus status, - - @JsonProperty("error_code") - final Integer errorCode, - - @JsonProperty("error_message") - final String errorMessage, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("sid") final String sid, + @JsonProperty("interaction_sid") final String interactionSid, + @JsonProperty("type") final InteractionChannel.Type type, + @JsonProperty("status") final InteractionChannel.ChannelStatus status, + @JsonProperty("error_code") final Integer errorCode, + @JsonProperty("error_message") final String errorMessage, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.sid = sid; this.interactionSid = interactionSid; @@ -202,34 +205,41 @@ private InteractionChannel( this.links = links; } - public final String getSid() { - return this.sid; - } - public final String getInteractionSid() { - return this.interactionSid; - } - public final InteractionChannel.Type getType() { - return this.type; - } - public final InteractionChannel.ChannelStatus getStatus() { - return this.status; - } - public final Integer getErrorCode() { - return this.errorCode; - } - public final String getErrorMessage() { - return this.errorMessage; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getSid() { + return this.sid; + } + + public final String getInteractionSid() { + return this.interactionSid; + } + + public final InteractionChannel.Type getType() { + return this.type; + } + + public final InteractionChannel.ChannelStatus getStatus() { + return this.status; + } + + public final Integer getErrorCode() { + return this.errorCode; + } + + public final String getErrorMessage() { + return this.errorMessage; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -239,13 +249,29 @@ public boolean equals(final Object o) { InteractionChannel other = (InteractionChannel) o; - return Objects.equals(sid, other.sid) && Objects.equals(interactionSid, other.interactionSid) && Objects.equals(type, other.type) && Objects.equals(status, other.status) && Objects.equals(errorCode, other.errorCode) && Objects.equals(errorMessage, other.errorMessage) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(interactionSid, other.interactionSid) && + Objects.equals(type, other.type) && + Objects.equals(status, other.status) && + Objects.equals(errorCode, other.errorCode) && + Objects.equals(errorMessage, other.errorMessage) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(sid, interactionSid, type, status, errorCode, errorMessage, url, links); + return Objects.hash( + sid, + interactionSid, + type, + status, + errorCode, + errorMessage, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/flexapi/v1/interaction/InteractionChannelFetcher.java b/src/main/java/com/twilio/rest/flexapi/v1/interaction/InteractionChannelFetcher.java index c12e7646f7..01eb3f28f8 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/interaction/InteractionChannelFetcher.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/interaction/InteractionChannelFetcher.java @@ -24,25 +24,29 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class InteractionChannelFetcher extends Fetcher { + private String pathInteractionSid; private String pathSid; - public InteractionChannelFetcher(final String pathInteractionSid, final String pathSid){ + public InteractionChannelFetcher( + final String pathInteractionSid, + final String pathSid + ) { this.pathInteractionSid = pathInteractionSid; this.pathSid = pathSid; } - @Override public InteractionChannel fetch(final TwilioRestClient client) { String path = "/v1/Interactions/{InteractionSid}/Channels/{Sid}"; - path = path.replace("{"+"InteractionSid"+"}", this.pathInteractionSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "InteractionSid" + "}", + this.pathInteractionSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,15 +56,23 @@ public InteractionChannel fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("InteractionChannel fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "InteractionChannel fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return InteractionChannel.fromJson(response.getStream(), client.getObjectMapper()); + return InteractionChannel.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/flexapi/v1/interaction/InteractionChannelReader.java b/src/main/java/com/twilio/rest/flexapi/v1/interaction/InteractionChannelReader.java index a631979735..4b82a12be3 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/interaction/InteractionChannelReader.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/interaction/InteractionChannelReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.flexapi.v1.interaction; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,19 +25,17 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class InteractionChannelReader extends Reader { + private String pathInteractionSid; private Integer pageSize; - public InteractionChannelReader(final String pathInteractionSid){ + public InteractionChannelReader(final String pathInteractionSid) { this.pathInteractionSid = pathInteractionSid; } - public InteractionChannelReader setPageSize(final Integer pageSize){ + public InteractionChannelReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -48,7 +47,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Interactions/{InteractionSid}/Channels"; - path = path.replace("{"+"InteractionSid"+"}", this.pathInteractionSid.toString()); + path = + path.replace( + "{" + "InteractionSid" + "}", + this.pathInteractionSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -60,13 +63,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("InteractionChannel read failed: Unable to connect to server"); + throw new ApiConnectionException( + "InteractionChannel read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +93,10 @@ private Page pageForRequest(final TwilioRestClient client, f } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.FLEXAPI.toString()) @@ -90,9 +104,11 @@ public Page previousPage(final Page page return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.FLEXAPI.toString()) @@ -101,21 +117,21 @@ public Page nextPage(final Page page, fi } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/flexapi/v1/interaction/InteractionChannelUpdater.java b/src/main/java/com/twilio/rest/flexapi/v1/interaction/InteractionChannelUpdater.java index be5a694d8d..debc471868 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/interaction/InteractionChannelUpdater.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/interaction/InteractionChannelUpdater.java @@ -15,8 +15,9 @@ package com.twilio.rest.flexapi.v1.interaction; import com.twilio.base.Updater; -import com.twilio.exception.ApiConnectionException; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Converter; +import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; @@ -24,67 +25,86 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - import java.util.Map; +public class InteractionChannelUpdater extends Updater { -public class InteractionChannelUpdater extends Updater{ private String pathInteractionSid; private String pathSid; private InteractionChannel.Status status; private Map routing; - public InteractionChannelUpdater(final String pathInteractionSid, final String pathSid, final InteractionChannel.Status status){ + public InteractionChannelUpdater( + final String pathInteractionSid, + final String pathSid, + final InteractionChannel.Status status + ) { this.pathInteractionSid = pathInteractionSid; this.pathSid = pathSid; this.status = status; } - public InteractionChannelUpdater setStatus(final InteractionChannel.Status status){ + public InteractionChannelUpdater setStatus( + final InteractionChannel.Status status + ) { this.status = status; return this; } - public InteractionChannelUpdater setRouting(final Map routing){ + + public InteractionChannelUpdater setRouting( + final Map routing + ) { this.routing = routing; return this; } @Override - public InteractionChannel update(final TwilioRestClient client){ + public InteractionChannel update(final TwilioRestClient client) { String path = "/v1/Interactions/{InteractionSid}/Channels/{Sid}"; - path = path.replace("{"+"InteractionSid"+"}", this.pathInteractionSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); - path = path.replace("{"+"Status"+"}", this.status.toString()); + path = + path.replace( + "{" + "InteractionSid" + "}", + this.pathInteractionSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + path = path.replace("{" + "Status" + "}", this.status.toString()); Request request = new Request( HttpMethod.POST, Domains.FLEXAPI.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("InteractionChannel update failed: Unable to connect to server"); + throw new ApiConnectionException( + "InteractionChannel update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return InteractionChannel.fromJson(response.getStream(), client.getObjectMapper()); + return InteractionChannel.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (status != null) { request.addPostParam("Status", status.toString()); - } if (routing != null) { - request.addPostParam("Routing", Converter.mapToJson(routing)); - + request.addPostParam("Routing", Converter.mapToJson(routing)); } } } diff --git a/src/main/java/com/twilio/rest/flexapi/v1/interaction/interactionchannel/InteractionChannelInvite.java b/src/main/java/com/twilio/rest/flexapi/v1/interaction/interactionchannel/InteractionChannelInvite.java index d1c326fb5a..6a9e79717b 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/interaction/interactionchannel/InteractionChannelInvite.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/interaction/interactionchannel/InteractionChannelInvite.java @@ -22,42 +22,55 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class InteractionChannelInvite extends Resource { + private static final long serialVersionUID = 96456011706810L; - public static InteractionChannelInviteCreator creator(final String pathInteractionSid, final String pathChannelSid, final Map routing){ - return new InteractionChannelInviteCreator(pathInteractionSid, pathChannelSid, routing); + public static InteractionChannelInviteCreator creator( + final String pathInteractionSid, + final String pathChannelSid, + final Map routing + ) { + return new InteractionChannelInviteCreator( + pathInteractionSid, + pathChannelSid, + routing + ); } - public static InteractionChannelInviteReader reader(final String pathInteractionSid, final String pathChannelSid){ - return new InteractionChannelInviteReader(pathInteractionSid, pathChannelSid); + public static InteractionChannelInviteReader reader( + final String pathInteractionSid, + final String pathChannelSid + ) { + return new InteractionChannelInviteReader( + pathInteractionSid, + pathChannelSid + ); } /** - * Converts a JSON String into a InteractionChannelInvite object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return InteractionChannelInvite object represented by the provided JSON - */ - public static InteractionChannelInvite fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a InteractionChannelInvite object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return InteractionChannelInvite object represented by the provided JSON + */ + public static InteractionChannelInvite fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, InteractionChannelInvite.class); @@ -69,14 +82,17 @@ public static InteractionChannelInvite fromJson(final String json, final ObjectM } /** - * Converts a JSON InputStream into a InteractionChannelInvite object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return InteractionChannelInvite object represented by the provided JSON - */ - public static InteractionChannelInvite fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a InteractionChannelInvite object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return InteractionChannelInvite object represented by the provided JSON + */ + public static InteractionChannelInvite fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, InteractionChannelInvite.class); @@ -95,20 +111,11 @@ public static InteractionChannelInvite fromJson(final InputStream json, final Ob @JsonCreator private InteractionChannelInvite( - @JsonProperty("sid") - final String sid, - - @JsonProperty("interaction_sid") - final String interactionSid, - - @JsonProperty("channel_sid") - final String channelSid, - - @JsonProperty("routing") - final Map routing, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("interaction_sid") final String interactionSid, + @JsonProperty("channel_sid") final String channelSid, + @JsonProperty("routing") final Map routing, + @JsonProperty("url") final URI url ) { this.sid = sid; this.interactionSid = interactionSid; @@ -117,25 +124,29 @@ private InteractionChannelInvite( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getInteractionSid() { - return this.interactionSid; - } - public final String getChannelSid() { - return this.channelSid; - } - public final Map getRouting() { - return this.routing; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getInteractionSid() { + return this.interactionSid; + } + + public final String getChannelSid() { + return this.channelSid; + } + + public final Map getRouting() { + return this.routing; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -145,13 +156,17 @@ public boolean equals(final Object o) { InteractionChannelInvite other = (InteractionChannelInvite) o; - return Objects.equals(sid, other.sid) && Objects.equals(interactionSid, other.interactionSid) && Objects.equals(channelSid, other.channelSid) && Objects.equals(routing, other.routing) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(interactionSid, other.interactionSid) && + Objects.equals(channelSid, other.channelSid) && + Objects.equals(routing, other.routing) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { return Objects.hash(sid, interactionSid, channelSid, routing, url); } - } - diff --git a/src/main/java/com/twilio/rest/flexapi/v1/interaction/interactionchannel/InteractionChannelInviteCreator.java b/src/main/java/com/twilio/rest/flexapi/v1/interaction/interactionchannel/InteractionChannelInviteCreator.java index bcb2e4bf5b..eddbe5d2dd 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/interaction/interactionchannel/InteractionChannelInviteCreator.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/interaction/interactionchannel/InteractionChannelInviteCreator.java @@ -15,8 +15,10 @@ package com.twilio.rest.flexapi.v1.interaction.interactionchannel; import com.twilio.base.Creator; -import com.twilio.exception.ApiConnectionException; +import com.twilio.constant.EnumConstants; +import com.twilio.converter.Converter; import com.twilio.converter.Converter; +import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; @@ -25,59 +27,81 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.util.Map; -import com.twilio.converter.Converter; - import java.util.Map; +public class InteractionChannelInviteCreator + extends Creator { - -public class InteractionChannelInviteCreator extends Creator{ private String pathInteractionSid; private String pathChannelSid; private Map routing; - public InteractionChannelInviteCreator(final String pathInteractionSid, final String pathChannelSid, final Map routing) { + public InteractionChannelInviteCreator( + final String pathInteractionSid, + final String pathChannelSid, + final Map routing + ) { this.pathInteractionSid = pathInteractionSid; this.pathChannelSid = pathChannelSid; this.routing = routing; } - public InteractionChannelInviteCreator setRouting(final Map routing){ + public InteractionChannelInviteCreator setRouting( + final Map routing + ) { this.routing = routing; return this; } @Override - public InteractionChannelInvite create(final TwilioRestClient client){ - String path = "/v1/Interactions/{InteractionSid}/Channels/{ChannelSid}/Invites"; + public InteractionChannelInvite create(final TwilioRestClient client) { + String path = + "/v1/Interactions/{InteractionSid}/Channels/{ChannelSid}/Invites"; - path = path.replace("{"+"InteractionSid"+"}", this.pathInteractionSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); - path = path.replace("{"+"Routing"+"}", this.routing.toString()); + path = + path.replace( + "{" + "InteractionSid" + "}", + this.pathInteractionSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Routing" + "}", this.routing.toString()); Request request = new Request( HttpMethod.POST, Domains.FLEXAPI.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("InteractionChannelInvite creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "InteractionChannelInvite creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return InteractionChannelInvite.fromJson(response.getStream(), client.getObjectMapper()); + return InteractionChannelInvite.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (routing != null) { - request.addPostParam("Routing", Converter.mapToJson(routing)); - + request.addPostParam("Routing", Converter.mapToJson(routing)); } } } diff --git a/src/main/java/com/twilio/rest/flexapi/v1/interaction/interactionchannel/InteractionChannelInviteReader.java b/src/main/java/com/twilio/rest/flexapi/v1/interaction/interactionchannel/InteractionChannelInviteReader.java index 8e1c59a578..7e39051794 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/interaction/interactionchannel/InteractionChannelInviteReader.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/interaction/interactionchannel/InteractionChannelInviteReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.flexapi.v1.interaction.interactionchannel; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,34 +25,49 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; +public class InteractionChannelInviteReader + extends Reader { - -public class InteractionChannelInviteReader extends Reader { private String pathInteractionSid; private String pathChannelSid; private Integer pageSize; - public InteractionChannelInviteReader(final String pathInteractionSid, final String pathChannelSid){ + public InteractionChannelInviteReader( + final String pathInteractionSid, + final String pathChannelSid + ) { this.pathInteractionSid = pathInteractionSid; this.pathChannelSid = pathChannelSid; } - public InteractionChannelInviteReader setPageSize(final Integer pageSize){ + public InteractionChannelInviteReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @Override - public ResourceSet read(final TwilioRestClient client) { + public ResourceSet read( + final TwilioRestClient client + ) { return new ResourceSet<>(this, client, firstPage(client)); } - public Page firstPage(final TwilioRestClient client) { - String path = "/v1/Interactions/{InteractionSid}/Channels/{ChannelSid}/Invites"; - path = path.replace("{"+"InteractionSid"+"}", this.pathInteractionSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); + public Page firstPage( + final TwilioRestClient client + ) { + String path = + "/v1/Interactions/{InteractionSid}/Channels/{ChannelSid}/Invites"; + path = + path.replace( + "{" + "InteractionSid" + "}", + this.pathInteractionSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -63,13 +79,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("InteractionChannelInvite read failed: Unable to connect to server"); + throw new ApiConnectionException( + "InteractionChannelInvite read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -85,7 +109,10 @@ private Page pageForRequest(final TwilioRestClient cli } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.FLEXAPI.toString()) @@ -93,9 +120,11 @@ public Page previousPage(final Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.FLEXAPI.toString()) @@ -104,21 +133,21 @@ public Page nextPage(final Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/flexapi/v1/interaction/interactionchannel/InteractionChannelParticipant.java b/src/main/java/com/twilio/rest/flexapi/v1/interaction/interactionchannel/InteractionChannelParticipant.java index 3761f962e5..7f3d51254e 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/interaction/interactionchannel/InteractionChannelParticipant.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/interaction/interactionchannel/InteractionChannelParticipant.java @@ -23,49 +23,77 @@ import com.twilio.base.Resource; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class InteractionChannelParticipant extends Resource { + private static final long serialVersionUID = 108435204885654L; - public static InteractionChannelParticipantCreator creator(final String pathInteractionSid, final String pathChannelSid, final InteractionChannelParticipant.Type type, final Map mediaProperties){ - return new InteractionChannelParticipantCreator(pathInteractionSid, pathChannelSid, type, mediaProperties); + public static InteractionChannelParticipantCreator creator( + final String pathInteractionSid, + final String pathChannelSid, + final InteractionChannelParticipant.Type type, + final Map mediaProperties + ) { + return new InteractionChannelParticipantCreator( + pathInteractionSid, + pathChannelSid, + type, + mediaProperties + ); } - public static InteractionChannelParticipantReader reader(final String pathInteractionSid, final String pathChannelSid){ - return new InteractionChannelParticipantReader(pathInteractionSid, pathChannelSid); + public static InteractionChannelParticipantReader reader( + final String pathInteractionSid, + final String pathChannelSid + ) { + return new InteractionChannelParticipantReader( + pathInteractionSid, + pathChannelSid + ); } - public static InteractionChannelParticipantUpdater updater(final String pathInteractionSid, final String pathChannelSid, final String pathSid, final InteractionChannelParticipant.Status status){ - return new InteractionChannelParticipantUpdater(pathInteractionSid, pathChannelSid, pathSid, status); + public static InteractionChannelParticipantUpdater updater( + final String pathInteractionSid, + final String pathChannelSid, + final String pathSid, + final InteractionChannelParticipant.Status status + ) { + return new InteractionChannelParticipantUpdater( + pathInteractionSid, + pathChannelSid, + pathSid, + status + ); } /** - * Converts a JSON String into a InteractionChannelParticipant object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return InteractionChannelParticipant object represented by the provided JSON - */ - public static InteractionChannelParticipant fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a InteractionChannelParticipant object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return InteractionChannelParticipant object represented by the provided JSON + */ + public static InteractionChannelParticipant fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, InteractionChannelParticipant.class); + return objectMapper.readValue( + json, + InteractionChannelParticipant.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -74,23 +102,30 @@ public static InteractionChannelParticipant fromJson(final String json, final Ob } /** - * Converts a JSON InputStream into a InteractionChannelParticipant object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return InteractionChannelParticipant object represented by the provided JSON - */ - public static InteractionChannelParticipant fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a InteractionChannelParticipant object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return InteractionChannelParticipant object represented by the provided JSON + */ + public static InteractionChannelParticipant fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, InteractionChannelParticipant.class); + return objectMapper.readValue( + json, + InteractionChannelParticipant.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { throw new ApiConnectionException(e.getMessage(), e); } } + public enum Status { CLOSED("closed"), WRAPUP("wrapup"); @@ -110,6 +145,7 @@ public static Status forValue(final String value) { return Promoter.enumFromString(value, Status.values()); } } + public enum Type { SUPERVISOR("supervisor"), CUSTOMER("customer"), @@ -141,20 +177,11 @@ public static Type forValue(final String value) { @JsonCreator private InteractionChannelParticipant( - @JsonProperty("sid") - final String sid, - - @JsonProperty("type") - final InteractionChannelParticipant.Type type, - - @JsonProperty("interaction_sid") - final String interactionSid, - - @JsonProperty("channel_sid") - final String channelSid, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("type") final InteractionChannelParticipant.Type type, + @JsonProperty("interaction_sid") final String interactionSid, + @JsonProperty("channel_sid") final String channelSid, + @JsonProperty("url") final URI url ) { this.sid = sid; this.type = type; @@ -163,25 +190,29 @@ private InteractionChannelParticipant( this.url = url; } - public final String getSid() { - return this.sid; - } - public final InteractionChannelParticipant.Type getType() { - return this.type; - } - public final String getInteractionSid() { - return this.interactionSid; - } - public final String getChannelSid() { - return this.channelSid; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final InteractionChannelParticipant.Type getType() { + return this.type; + } + + public final String getInteractionSid() { + return this.interactionSid; + } + + public final String getChannelSid() { + return this.channelSid; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -191,13 +222,17 @@ public boolean equals(final Object o) { InteractionChannelParticipant other = (InteractionChannelParticipant) o; - return Objects.equals(sid, other.sid) && Objects.equals(type, other.type) && Objects.equals(interactionSid, other.interactionSid) && Objects.equals(channelSid, other.channelSid) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(type, other.type) && + Objects.equals(interactionSid, other.interactionSid) && + Objects.equals(channelSid, other.channelSid) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { return Objects.hash(sid, type, interactionSid, channelSid, url); } - } - diff --git a/src/main/java/com/twilio/rest/flexapi/v1/interaction/interactionchannel/InteractionChannelParticipantCreator.java b/src/main/java/com/twilio/rest/flexapi/v1/interaction/interactionchannel/InteractionChannelParticipantCreator.java index 0b4ff9462a..061ba50172 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/interaction/interactionchannel/InteractionChannelParticipantCreator.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/interaction/interactionchannel/InteractionChannelParticipantCreator.java @@ -15,8 +15,10 @@ package com.twilio.rest.flexapi.v1.interaction.interactionchannel; import com.twilio.base.Creator; -import com.twilio.exception.ApiConnectionException; +import com.twilio.constant.EnumConstants; +import com.twilio.converter.Converter; import com.twilio.converter.Converter; +import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; @@ -25,70 +27,102 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.util.Map; -import com.twilio.converter.Converter; - import java.util.Map; +public class InteractionChannelParticipantCreator + extends Creator { - -public class InteractionChannelParticipantCreator extends Creator{ private String pathInteractionSid; private String pathChannelSid; private InteractionChannelParticipant.Type type; private Map mediaProperties; - public InteractionChannelParticipantCreator(final String pathInteractionSid, final String pathChannelSid, final InteractionChannelParticipant.Type type, final Map mediaProperties) { + public InteractionChannelParticipantCreator( + final String pathInteractionSid, + final String pathChannelSid, + final InteractionChannelParticipant.Type type, + final Map mediaProperties + ) { this.pathInteractionSid = pathInteractionSid; this.pathChannelSid = pathChannelSid; this.type = type; this.mediaProperties = mediaProperties; } - public InteractionChannelParticipantCreator setType(final InteractionChannelParticipant.Type type){ + public InteractionChannelParticipantCreator setType( + final InteractionChannelParticipant.Type type + ) { this.type = type; return this; } - public InteractionChannelParticipantCreator setMediaProperties(final Map mediaProperties){ + + public InteractionChannelParticipantCreator setMediaProperties( + final Map mediaProperties + ) { this.mediaProperties = mediaProperties; return this; } @Override - public InteractionChannelParticipant create(final TwilioRestClient client){ - String path = "/v1/Interactions/{InteractionSid}/Channels/{ChannelSid}/Participants"; + public InteractionChannelParticipant create(final TwilioRestClient client) { + String path = + "/v1/Interactions/{InteractionSid}/Channels/{ChannelSid}/Participants"; - path = path.replace("{"+"InteractionSid"+"}", this.pathInteractionSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); - path = path.replace("{"+"Type"+"}", this.type.toString()); - path = path.replace("{"+"MediaProperties"+"}", this.mediaProperties.toString()); + path = + path.replace( + "{" + "InteractionSid" + "}", + this.pathInteractionSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Type" + "}", this.type.toString()); + path = + path.replace( + "{" + "MediaProperties" + "}", + this.mediaProperties.toString() + ); Request request = new Request( HttpMethod.POST, Domains.FLEXAPI.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("InteractionChannelParticipant creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "InteractionChannelParticipant creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return InteractionChannelParticipant.fromJson(response.getStream(), client.getObjectMapper()); + return InteractionChannelParticipant.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (type != null) { request.addPostParam("Type", type.toString()); - } if (mediaProperties != null) { - request.addPostParam("MediaProperties", Converter.mapToJson(mediaProperties)); - + request.addPostParam( + "MediaProperties", + Converter.mapToJson(mediaProperties) + ); } } } diff --git a/src/main/java/com/twilio/rest/flexapi/v1/interaction/interactionchannel/InteractionChannelParticipantReader.java b/src/main/java/com/twilio/rest/flexapi/v1/interaction/interactionchannel/InteractionChannelParticipantReader.java index 4c244fa79e..0dd5bd971c 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/interaction/interactionchannel/InteractionChannelParticipantReader.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/interaction/interactionchannel/InteractionChannelParticipantReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.flexapi.v1.interaction.interactionchannel; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,34 +25,51 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; +public class InteractionChannelParticipantReader + extends Reader { - -public class InteractionChannelParticipantReader extends Reader { private String pathInteractionSid; private String pathChannelSid; private Integer pageSize; - public InteractionChannelParticipantReader(final String pathInteractionSid, final String pathChannelSid){ + public InteractionChannelParticipantReader( + final String pathInteractionSid, + final String pathChannelSid + ) { this.pathInteractionSid = pathInteractionSid; this.pathChannelSid = pathChannelSid; } - public InteractionChannelParticipantReader setPageSize(final Integer pageSize){ + public InteractionChannelParticipantReader setPageSize( + final Integer pageSize + ) { this.pageSize = pageSize; return this; } @Override - public ResourceSet read(final TwilioRestClient client) { + public ResourceSet read( + final TwilioRestClient client + ) { return new ResourceSet<>(this, client, firstPage(client)); } - public Page firstPage(final TwilioRestClient client) { - String path = "/v1/Interactions/{InteractionSid}/Channels/{ChannelSid}/Participants"; - path = path.replace("{"+"InteractionSid"+"}", this.pathInteractionSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); + public Page firstPage( + final TwilioRestClient client + ) { + String path = + "/v1/Interactions/{InteractionSid}/Channels/{ChannelSid}/Participants"; + path = + path.replace( + "{" + "InteractionSid" + "}", + this.pathInteractionSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -63,13 +81,21 @@ public Page firstPage(final TwilioRestClient clie return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("InteractionChannelParticipant read failed: Unable to connect to server"); + throw new ApiConnectionException( + "InteractionChannelParticipant read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -85,7 +111,10 @@ private Page pageForRequest(final TwilioRestClien } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.FLEXAPI.toString()) @@ -93,9 +122,11 @@ public Page previousPage(final Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.FLEXAPI.toString()) @@ -104,21 +135,21 @@ public Page nextPage(final Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/flexapi/v1/interaction/interactionchannel/InteractionChannelParticipantUpdater.java b/src/main/java/com/twilio/rest/flexapi/v1/interaction/interactionchannel/InteractionChannelParticipantUpdater.java index cee3f7cf4e..5b3eebe860 100644 --- a/src/main/java/com/twilio/rest/flexapi/v1/interaction/interactionchannel/InteractionChannelParticipantUpdater.java +++ b/src/main/java/com/twilio/rest/flexapi/v1/interaction/interactionchannel/InteractionChannelParticipantUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.flexapi.v1.interaction.interactionchannel; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,59 +25,83 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class InteractionChannelParticipantUpdater + extends Updater { - - -public class InteractionChannelParticipantUpdater extends Updater{ private String pathInteractionSid; private String pathChannelSid; private String pathSid; private InteractionChannelParticipant.Status status; - public InteractionChannelParticipantUpdater(final String pathInteractionSid, final String pathChannelSid, final String pathSid, final InteractionChannelParticipant.Status status){ + public InteractionChannelParticipantUpdater( + final String pathInteractionSid, + final String pathChannelSid, + final String pathSid, + final InteractionChannelParticipant.Status status + ) { this.pathInteractionSid = pathInteractionSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; this.status = status; } - public InteractionChannelParticipantUpdater setStatus(final InteractionChannelParticipant.Status status){ + public InteractionChannelParticipantUpdater setStatus( + final InteractionChannelParticipant.Status status + ) { this.status = status; return this; } @Override - public InteractionChannelParticipant update(final TwilioRestClient client){ - String path = "/v1/Interactions/{InteractionSid}/Channels/{ChannelSid}/Participants/{Sid}"; + public InteractionChannelParticipant update(final TwilioRestClient client) { + String path = + "/v1/Interactions/{InteractionSid}/Channels/{ChannelSid}/Participants/{Sid}"; - path = path.replace("{"+"InteractionSid"+"}", this.pathInteractionSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); - path = path.replace("{"+"Status"+"}", this.status.toString()); + path = + path.replace( + "{" + "InteractionSid" + "}", + this.pathInteractionSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + path = path.replace("{" + "Status" + "}", this.status.toString()); Request request = new Request( HttpMethod.POST, Domains.FLEXAPI.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("InteractionChannelParticipant update failed: Unable to connect to server"); + throw new ApiConnectionException( + "InteractionChannelParticipant update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return InteractionChannelParticipant.fromJson(response.getStream(), client.getObjectMapper()); + return InteractionChannelParticipant.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (status != null) { request.addPostParam("Status", status.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/flexapi/v2/WebChannels.java b/src/main/java/com/twilio/rest/flexapi/v2/WebChannels.java index 69751641db..dfa57a58df 100644 --- a/src/main/java/com/twilio/rest/flexapi/v2/WebChannels.java +++ b/src/main/java/com/twilio/rest/flexapi/v2/WebChannels.java @@ -22,35 +22,34 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class WebChannels extends Resource { + private static final long serialVersionUID = 110421660015552L; - public static WebChannelsCreator creator(final String addressSid){ + public static WebChannelsCreator creator(final String addressSid) { return new WebChannelsCreator(addressSid); } /** - * Converts a JSON String into a WebChannels object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return WebChannels object represented by the provided JSON - */ - public static WebChannels fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a WebChannels object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return WebChannels object represented by the provided JSON + */ + public static WebChannels fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, WebChannels.class); @@ -62,14 +61,17 @@ public static WebChannels fromJson(final String json, final ObjectMapper objectM } /** - * Converts a JSON InputStream into a WebChannels object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return WebChannels object represented by the provided JSON - */ - public static WebChannels fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a WebChannels object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return WebChannels object represented by the provided JSON + */ + public static WebChannels fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, WebChannels.class); @@ -85,26 +87,24 @@ public static WebChannels fromJson(final InputStream json, final ObjectMapper ob @JsonCreator private WebChannels( - @JsonProperty("conversation_sid") - final String conversationSid, - - @JsonProperty("identity") - final String identity + @JsonProperty("conversation_sid") final String conversationSid, + @JsonProperty("identity") final String identity ) { this.conversationSid = conversationSid; this.identity = identity; } - public final String getConversationSid() { - return this.conversationSid; - } - public final String getIdentity() { - return this.identity; - } + public final String getConversationSid() { + return this.conversationSid; + } + + public final String getIdentity() { + return this.identity; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -114,13 +114,14 @@ public boolean equals(final Object o) { WebChannels other = (WebChannels) o; - return Objects.equals(conversationSid, other.conversationSid) && Objects.equals(identity, other.identity) ; + return ( + Objects.equals(conversationSid, other.conversationSid) && + Objects.equals(identity, other.identity) + ); } @Override public int hashCode() { return Objects.hash(conversationSid, identity); } - } - diff --git a/src/main/java/com/twilio/rest/flexapi/v2/WebChannelsCreator.java b/src/main/java/com/twilio/rest/flexapi/v2/WebChannelsCreator.java index b4b90ae812..84ca399797 100644 --- a/src/main/java/com/twilio/rest/flexapi/v2/WebChannelsCreator.java +++ b/src/main/java/com/twilio/rest/flexapi/v2/WebChannelsCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.flexapi.v2; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class WebChannelsCreator extends Creator { - - -public class WebChannelsCreator extends Creator{ private String addressSid; private String chatFriendlyName; private String customerFriendlyName; @@ -37,64 +36,80 @@ public WebChannelsCreator(final String addressSid) { this.addressSid = addressSid; } - public WebChannelsCreator setAddressSid(final String addressSid){ + public WebChannelsCreator setAddressSid(final String addressSid) { this.addressSid = addressSid; return this; } - public WebChannelsCreator setChatFriendlyName(final String chatFriendlyName){ + + public WebChannelsCreator setChatFriendlyName( + final String chatFriendlyName + ) { this.chatFriendlyName = chatFriendlyName; return this; } - public WebChannelsCreator setCustomerFriendlyName(final String customerFriendlyName){ + + public WebChannelsCreator setCustomerFriendlyName( + final String customerFriendlyName + ) { this.customerFriendlyName = customerFriendlyName; return this; } - public WebChannelsCreator setPreEngagementData(final String preEngagementData){ + + public WebChannelsCreator setPreEngagementData( + final String preEngagementData + ) { this.preEngagementData = preEngagementData; return this; } @Override - public WebChannels create(final TwilioRestClient client){ + public WebChannels create(final TwilioRestClient client) { String path = "/v2/WebChats"; - path = path.replace("{"+"AddressSid"+"}", this.addressSid.toString()); + path = + path.replace("{" + "AddressSid" + "}", this.addressSid.toString()); Request request = new Request( HttpMethod.POST, Domains.FLEXAPI.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("WebChannels creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "WebChannels creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return WebChannels.fromJson(response.getStream(), client.getObjectMapper()); + return WebChannels.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (addressSid != null) { request.addPostParam("AddressSid", addressSid); - } if (chatFriendlyName != null) { request.addPostParam("ChatFriendlyName", chatFriendlyName); - } if (customerFriendlyName != null) { request.addPostParam("CustomerFriendlyName", customerFriendlyName); - } if (preEngagementData != null) { request.addPostParam("PreEngagementData", preEngagementData); - } } } diff --git a/src/main/java/com/twilio/rest/frontlineapi/v1/User.java b/src/main/java/com/twilio/rest/frontlineapi/v1/User.java index 813d91e6dd..4409e64084 100644 --- a/src/main/java/com/twilio/rest/frontlineapi/v1/User.java +++ b/src/main/java/com/twilio/rest/frontlineapi/v1/User.java @@ -23,40 +23,39 @@ import com.twilio.base.Resource; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class User extends Resource { + private static final long serialVersionUID = 253333531578389L; - public static UserFetcher fetcher(final String pathSid){ + public static UserFetcher fetcher(final String pathSid) { return new UserFetcher(pathSid); } - public static UserUpdater updater(final String pathSid){ + public static UserUpdater updater(final String pathSid) { return new UserUpdater(pathSid); } /** - * Converts a JSON String into a User object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return User object represented by the provided JSON - */ - public static User fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a User object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return User object represented by the provided JSON + */ + public static User fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, User.class); @@ -68,14 +67,17 @@ public static User fromJson(final String json, final ObjectMapper objectMapper) } /** - * Converts a JSON InputStream into a User object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return User object represented by the provided JSON - */ - public static User fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a User object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return User object represented by the provided JSON + */ + public static User fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, User.class); @@ -85,6 +87,7 @@ public static User fromJson(final InputStream json, final ObjectMapper objectMap throw new ApiConnectionException(e.getMessage(), e); } } + public enum StateType { ACTIVE("active"), DEACTIVATED("deactivated"); @@ -115,26 +118,13 @@ public static StateType forValue(final String value) { @JsonCreator private User( - @JsonProperty("sid") - final String sid, - - @JsonProperty("identity") - final String identity, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("avatar") - final String avatar, - - @JsonProperty("state") - final User.StateType state, - - @JsonProperty("is_available") - final Boolean isAvailable, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("identity") final String identity, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("avatar") final String avatar, + @JsonProperty("state") final User.StateType state, + @JsonProperty("is_available") final Boolean isAvailable, + @JsonProperty("url") final URI url ) { this.sid = sid; this.identity = identity; @@ -145,31 +135,37 @@ private User( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getIdentity() { - return this.identity; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getAvatar() { - return this.avatar; - } - public final User.StateType getState() { - return this.state; - } - public final Boolean getIsAvailable() { - return this.isAvailable; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getIdentity() { + return this.identity; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getAvatar() { + return this.avatar; + } + + public final User.StateType getState() { + return this.state; + } + + public final Boolean getIsAvailable() { + return this.isAvailable; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -179,13 +175,27 @@ public boolean equals(final Object o) { User other = (User) o; - return Objects.equals(sid, other.sid) && Objects.equals(identity, other.identity) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(avatar, other.avatar) && Objects.equals(state, other.state) && Objects.equals(isAvailable, other.isAvailable) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(identity, other.identity) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(avatar, other.avatar) && + Objects.equals(state, other.state) && + Objects.equals(isAvailable, other.isAvailable) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, identity, friendlyName, avatar, state, isAvailable, url); + return Objects.hash( + sid, + identity, + friendlyName, + avatar, + state, + isAvailable, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/frontlineapi/v1/UserFetcher.java b/src/main/java/com/twilio/rest/frontlineapi/v1/UserFetcher.java index 0668752dc7..9cec67afd4 100644 --- a/src/main/java/com/twilio/rest/frontlineapi/v1/UserFetcher.java +++ b/src/main/java/com/twilio/rest/frontlineapi/v1/UserFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class UserFetcher extends Fetcher { + private String pathSid; - public UserFetcher(final String pathSid){ + public UserFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public User fetch(final TwilioRestClient client) { String path = "/v1/Users/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,9 +46,14 @@ public User fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("User fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "User fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/frontlineapi/v1/UserUpdater.java b/src/main/java/com/twilio/rest/frontlineapi/v1/UserUpdater.java index 3b2879a28c..ecbed4ef81 100644 --- a/src/main/java/com/twilio/rest/frontlineapi/v1/UserUpdater.java +++ b/src/main/java/com/twilio/rest/frontlineapi/v1/UserUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.frontlineapi.v1; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,54 +25,61 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class UserUpdater extends Updater { - - -public class UserUpdater extends Updater{ private String pathSid; private String friendlyName; private String avatar; private User.StateType state; private Boolean isAvailable; - public UserUpdater(final String pathSid){ + public UserUpdater(final String pathSid) { this.pathSid = pathSid; } - public UserUpdater setFriendlyName(final String friendlyName){ + public UserUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public UserUpdater setAvatar(final String avatar){ + + public UserUpdater setAvatar(final String avatar) { this.avatar = avatar; return this; } - public UserUpdater setState(final User.StateType state){ + + public UserUpdater setState(final User.StateType state) { this.state = state; return this; } - public UserUpdater setIsAvailable(final Boolean isAvailable){ + + public UserUpdater setIsAvailable(final Boolean isAvailable) { this.isAvailable = isAvailable; return this; } @Override - public User update(final TwilioRestClient client){ + public User update(final TwilioRestClient client) { String path = "/v1/Users/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.FRONTLINEAPI.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("User update failed: Unable to connect to server"); + throw new ApiConnectionException( + "User update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -80,22 +88,19 @@ public User update(final TwilioRestClient client){ return User.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (avatar != null) { request.addPostParam("Avatar", avatar); - } if (state != null) { request.addPostParam("State", state.toString()); - } if (isAvailable != null) { request.addPostParam("IsAvailable", isAvailable.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/insights/v1/Call.java b/src/main/java/com/twilio/rest/insights/v1/Call.java index 18e02b33dc..73c6b95c51 100644 --- a/src/main/java/com/twilio/rest/insights/v1/Call.java +++ b/src/main/java/com/twilio/rest/insights/v1/Call.java @@ -22,38 +22,37 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Call extends Resource { + private static final long serialVersionUID = 241148031780577L; - public static CallFetcher fetcher(final String pathSid){ + public static CallFetcher fetcher(final String pathSid) { return new CallFetcher(pathSid); } /** - * Converts a JSON String into a Call object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Call object represented by the provided JSON - */ - public static Call fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Call object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Call object represented by the provided JSON + */ + public static Call fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Call.class); @@ -65,14 +64,17 @@ public static Call fromJson(final String json, final ObjectMapper objectMapper) } /** - * Converts a JSON InputStream into a Call object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Call object represented by the provided JSON - */ - public static Call fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Call object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Call object represented by the provided JSON + */ + public static Call fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Call.class); @@ -89,33 +91,30 @@ public static Call fromJson(final InputStream json, final ObjectMapper objectMap @JsonCreator private Call( - @JsonProperty("sid") - final String sid, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.sid = sid; this.url = url; this.links = links; } - public final String getSid() { - return this.sid; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getSid() { + return this.sid; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -125,13 +124,15 @@ public boolean equals(final Object o) { Call other = (Call) o; - return Objects.equals(sid, other.sid) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { return Objects.hash(sid, url, links); } - } - diff --git a/src/main/java/com/twilio/rest/insights/v1/CallFetcher.java b/src/main/java/com/twilio/rest/insights/v1/CallFetcher.java index a525305889..a54556463c 100644 --- a/src/main/java/com/twilio/rest/insights/v1/CallFetcher.java +++ b/src/main/java/com/twilio/rest/insights/v1/CallFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class CallFetcher extends Fetcher { + private String pathSid; - public CallFetcher(final String pathSid){ + public CallFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public Call fetch(final TwilioRestClient client) { String path = "/v1/Voice/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,9 +46,14 @@ public Call fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Call fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Call fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/insights/v1/CallSummaries.java b/src/main/java/com/twilio/rest/insights/v1/CallSummaries.java index 6b752301c1..53d5b2f1d5 100644 --- a/src/main/java/com/twilio/rest/insights/v1/CallSummaries.java +++ b/src/main/java/com/twilio/rest/insights/v1/CallSummaries.java @@ -24,40 +24,39 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.List; import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class CallSummaries extends Resource { + private static final long serialVersionUID = 2737605187627L; - public static CallSummariesReader reader(){ + public static CallSummariesReader reader() { return new CallSummariesReader(); } /** - * Converts a JSON String into a CallSummaries object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return CallSummaries object represented by the provided JSON - */ - public static CallSummaries fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a CallSummaries object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return CallSummaries object represented by the provided JSON + */ + public static CallSummaries fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, CallSummaries.class); @@ -69,14 +68,17 @@ public static CallSummaries fromJson(final String json, final ObjectMapper objec } /** - * Converts a JSON InputStream into a CallSummaries object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return CallSummaries object represented by the provided JSON - */ - public static CallSummaries fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a CallSummaries object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return CallSummaries object represented by the provided JSON + */ + public static CallSummaries fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, CallSummaries.class); @@ -86,6 +88,7 @@ public static CallSummaries fromJson(final InputStream json, final ObjectMapper throw new ApiConnectionException(e.getMessage(), e); } } + public enum AnsweredBy { UNKNOWN("unknown"), MACHINE_START("machine_start"), @@ -110,6 +113,7 @@ public static AnsweredBy forValue(final String value) { return Promoter.enumFromString(value, AnsweredBy.values()); } } + public enum CallState { RINGING("ringing"), COMPLETED("completed"), @@ -135,6 +139,7 @@ public static CallState forValue(final String value) { return Promoter.enumFromString(value, CallState.values()); } } + public enum CallType { CARRIER("carrier"), SIP("sip"), @@ -156,6 +161,7 @@ public static CallType forValue(final String value) { return Promoter.enumFromString(value, CallType.values()); } } + public enum ProcessingState { COMPLETE("complete"), PARTIAL("partial"); @@ -175,6 +181,7 @@ public static ProcessingState forValue(final String value) { return Promoter.enumFromString(value, ProcessingState.values()); } } + public enum ProcessingStateRequest { COMPLETED("completed"), STARTED("started"), @@ -193,9 +200,13 @@ public String toString() { @JsonCreator public static ProcessingStateRequest forValue(final String value) { - return Promoter.enumFromString(value, ProcessingStateRequest.values()); + return Promoter.enumFromString( + value, + ProcessingStateRequest.values() + ); } } + public enum SortBy { START_TIME("start_time"), END_TIME("end_time"); @@ -242,74 +253,31 @@ public static SortBy forValue(final String value) { @JsonCreator private CallSummaries( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("call_sid") - final String callSid, - - @JsonProperty("answered_by") - final CallSummaries.AnsweredBy answeredBy, - - @JsonProperty("call_type") - final CallSummaries.CallType callType, - - @JsonProperty("call_state") - final CallSummaries.CallState callState, - - @JsonProperty("processing_state") - final CallSummaries.ProcessingState processingState, - - @JsonProperty("created_time") - final String createdTime, - - @JsonProperty("start_time") - final String startTime, - - @JsonProperty("end_time") - final String endTime, - - @JsonProperty("duration") - final Integer duration, - - @JsonProperty("connect_duration") - final Integer connectDuration, - - @JsonProperty("from") - final Map from, - - @JsonProperty("to") - final Map to, - - @JsonProperty("carrier_edge") - final Map carrierEdge, - - @JsonProperty("client_edge") - final Map clientEdge, - - @JsonProperty("sdk_edge") - final Map sdkEdge, - - @JsonProperty("sip_edge") - final Map sipEdge, - - @JsonProperty("tags") - final List tags, - - @JsonProperty("url") - final URI url, - - @JsonProperty("attributes") - final Map attributes, - - @JsonProperty("properties") - final Map properties, - - @JsonProperty("trust") - final Map trust, - - @JsonProperty("annotation") - final Map annotation + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("call_sid") final String callSid, + @JsonProperty("answered_by") final CallSummaries.AnsweredBy answeredBy, + @JsonProperty("call_type") final CallSummaries.CallType callType, + @JsonProperty("call_state") final CallSummaries.CallState callState, + @JsonProperty( + "processing_state" + ) final CallSummaries.ProcessingState processingState, + @JsonProperty("created_time") final String createdTime, + @JsonProperty("start_time") final String startTime, + @JsonProperty("end_time") final String endTime, + @JsonProperty("duration") final Integer duration, + @JsonProperty("connect_duration") final Integer connectDuration, + @JsonProperty("from") final Map from, + @JsonProperty("to") final Map to, + @JsonProperty("carrier_edge") final Map carrierEdge, + @JsonProperty("client_edge") final Map clientEdge, + @JsonProperty("sdk_edge") final Map sdkEdge, + @JsonProperty("sip_edge") final Map sipEdge, + @JsonProperty("tags") final List tags, + @JsonProperty("url") final URI url, + @JsonProperty("attributes") final Map attributes, + @JsonProperty("properties") final Map properties, + @JsonProperty("trust") final Map trust, + @JsonProperty("annotation") final Map annotation ) { this.accountSid = accountSid; this.callSid = callSid; @@ -336,79 +304,101 @@ private CallSummaries( this.annotation = annotation; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getCallSid() { - return this.callSid; - } - public final CallSummaries.AnsweredBy getAnsweredBy() { - return this.answeredBy; - } - public final CallSummaries.CallType getCallType() { - return this.callType; - } - public final CallSummaries.CallState getCallState() { - return this.callState; - } - public final CallSummaries.ProcessingState getProcessingState() { - return this.processingState; - } - public final ZonedDateTime getCreatedTime() { - return this.createdTime; - } - public final ZonedDateTime getStartTime() { - return this.startTime; - } - public final ZonedDateTime getEndTime() { - return this.endTime; - } - public final Integer getDuration() { - return this.duration; - } - public final Integer getConnectDuration() { - return this.connectDuration; - } - public final Map getFrom() { - return this.from; - } - public final Map getTo() { - return this.to; - } - public final Map getCarrierEdge() { - return this.carrierEdge; - } - public final Map getClientEdge() { - return this.clientEdge; - } - public final Map getSdkEdge() { - return this.sdkEdge; - } - public final Map getSipEdge() { - return this.sipEdge; - } - public final List getTags() { - return this.tags; - } - public final URI getUrl() { - return this.url; - } - public final Map getAttributes() { - return this.attributes; - } - public final Map getProperties() { - return this.properties; - } - public final Map getTrust() { - return this.trust; - } - public final Map getAnnotation() { - return this.annotation; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getCallSid() { + return this.callSid; + } + + public final CallSummaries.AnsweredBy getAnsweredBy() { + return this.answeredBy; + } + + public final CallSummaries.CallType getCallType() { + return this.callType; + } + + public final CallSummaries.CallState getCallState() { + return this.callState; + } + + public final CallSummaries.ProcessingState getProcessingState() { + return this.processingState; + } + + public final ZonedDateTime getCreatedTime() { + return this.createdTime; + } + + public final ZonedDateTime getStartTime() { + return this.startTime; + } + + public final ZonedDateTime getEndTime() { + return this.endTime; + } + + public final Integer getDuration() { + return this.duration; + } + + public final Integer getConnectDuration() { + return this.connectDuration; + } + + public final Map getFrom() { + return this.from; + } + + public final Map getTo() { + return this.to; + } + + public final Map getCarrierEdge() { + return this.carrierEdge; + } + + public final Map getClientEdge() { + return this.clientEdge; + } + + public final Map getSdkEdge() { + return this.sdkEdge; + } + + public final Map getSipEdge() { + return this.sipEdge; + } + + public final List getTags() { + return this.tags; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getAttributes() { + return this.attributes; + } + + public final Map getProperties() { + return this.properties; + } + + public final Map getTrust() { + return this.trust; + } + + public final Map getAnnotation() { + return this.annotation; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -418,13 +408,59 @@ public boolean equals(final Object o) { CallSummaries other = (CallSummaries) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(callSid, other.callSid) && Objects.equals(answeredBy, other.answeredBy) && Objects.equals(callType, other.callType) && Objects.equals(callState, other.callState) && Objects.equals(processingState, other.processingState) && Objects.equals(createdTime, other.createdTime) && Objects.equals(startTime, other.startTime) && Objects.equals(endTime, other.endTime) && Objects.equals(duration, other.duration) && Objects.equals(connectDuration, other.connectDuration) && Objects.equals(from, other.from) && Objects.equals(to, other.to) && Objects.equals(carrierEdge, other.carrierEdge) && Objects.equals(clientEdge, other.clientEdge) && Objects.equals(sdkEdge, other.sdkEdge) && Objects.equals(sipEdge, other.sipEdge) && Objects.equals(tags, other.tags) && Objects.equals(url, other.url) && Objects.equals(attributes, other.attributes) && Objects.equals(properties, other.properties) && Objects.equals(trust, other.trust) && Objects.equals(annotation, other.annotation) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(callSid, other.callSid) && + Objects.equals(answeredBy, other.answeredBy) && + Objects.equals(callType, other.callType) && + Objects.equals(callState, other.callState) && + Objects.equals(processingState, other.processingState) && + Objects.equals(createdTime, other.createdTime) && + Objects.equals(startTime, other.startTime) && + Objects.equals(endTime, other.endTime) && + Objects.equals(duration, other.duration) && + Objects.equals(connectDuration, other.connectDuration) && + Objects.equals(from, other.from) && + Objects.equals(to, other.to) && + Objects.equals(carrierEdge, other.carrierEdge) && + Objects.equals(clientEdge, other.clientEdge) && + Objects.equals(sdkEdge, other.sdkEdge) && + Objects.equals(sipEdge, other.sipEdge) && + Objects.equals(tags, other.tags) && + Objects.equals(url, other.url) && + Objects.equals(attributes, other.attributes) && + Objects.equals(properties, other.properties) && + Objects.equals(trust, other.trust) && + Objects.equals(annotation, other.annotation) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, callSid, answeredBy, callType, callState, processingState, createdTime, startTime, endTime, duration, connectDuration, from, to, carrierEdge, clientEdge, sdkEdge, sipEdge, tags, url, attributes, properties, trust, annotation); + return Objects.hash( + accountSid, + callSid, + answeredBy, + callType, + callState, + processingState, + createdTime, + startTime, + endTime, + duration, + connectDuration, + from, + to, + carrierEdge, + clientEdge, + sdkEdge, + sipEdge, + tags, + url, + attributes, + properties, + trust, + annotation + ); } - } - diff --git a/src/main/java/com/twilio/rest/insights/v1/CallSummariesReader.java b/src/main/java/com/twilio/rest/insights/v1/CallSummariesReader.java index 0e59cf427b..0c68db54b1 100644 --- a/src/main/java/com/twilio/rest/insights/v1/CallSummariesReader.java +++ b/src/main/java/com/twilio/rest/insights/v1/CallSummariesReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.insights.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,11 +25,9 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class CallSummariesReader extends Reader { + private String from; private String to; private String fromCarrier; @@ -48,108 +47,152 @@ public class CallSummariesReader extends Reader { private String subaccount; private Boolean abnormalSession; private CallSummaries.AnsweredBy answeredBy; - private String connectivityIssue; - private String qualityIssue; - private Boolean spam; - private String callScore; + private String answeredByAnnotation; + private String connectivityIssueAnnotation; + private String qualityIssueAnnotation; + private Boolean spamAnnotation; + private String callScoreAnnotation; private Integer pageSize; - public CallSummariesReader(){ - } + public CallSummariesReader() {} - public CallSummariesReader setFrom(final String from){ + public CallSummariesReader setFrom(final String from) { this.from = from; return this; } - public CallSummariesReader setTo(final String to){ + + public CallSummariesReader setTo(final String to) { this.to = to; return this; } - public CallSummariesReader setFromCarrier(final String fromCarrier){ + + public CallSummariesReader setFromCarrier(final String fromCarrier) { this.fromCarrier = fromCarrier; return this; } - public CallSummariesReader setToCarrier(final String toCarrier){ + + public CallSummariesReader setToCarrier(final String toCarrier) { this.toCarrier = toCarrier; return this; } - public CallSummariesReader setFromCountryCode(final String fromCountryCode){ + + public CallSummariesReader setFromCountryCode( + final String fromCountryCode + ) { this.fromCountryCode = fromCountryCode; return this; } - public CallSummariesReader setToCountryCode(final String toCountryCode){ + + public CallSummariesReader setToCountryCode(final String toCountryCode) { this.toCountryCode = toCountryCode; return this; } - public CallSummariesReader setBranded(final Boolean branded){ + + public CallSummariesReader setBranded(final Boolean branded) { this.branded = branded; return this; } - public CallSummariesReader setVerifiedCaller(final Boolean verifiedCaller){ + + public CallSummariesReader setVerifiedCaller(final Boolean verifiedCaller) { this.verifiedCaller = verifiedCaller; return this; } - public CallSummariesReader setHasTag(final Boolean hasTag){ + + public CallSummariesReader setHasTag(final Boolean hasTag) { this.hasTag = hasTag; return this; } - public CallSummariesReader setStartTime(final String startTime){ + + public CallSummariesReader setStartTime(final String startTime) { this.startTime = startTime; return this; } - public CallSummariesReader setEndTime(final String endTime){ + + public CallSummariesReader setEndTime(final String endTime) { this.endTime = endTime; return this; } - public CallSummariesReader setCallType(final String callType){ + + public CallSummariesReader setCallType(final String callType) { this.callType = callType; return this; } - public CallSummariesReader setCallState(final String callState){ + + public CallSummariesReader setCallState(final String callState) { this.callState = callState; return this; } - public CallSummariesReader setDirection(final String direction){ + + public CallSummariesReader setDirection(final String direction) { this.direction = direction; return this; } - public CallSummariesReader setProcessingState(final CallSummaries.ProcessingStateRequest processingState){ + + public CallSummariesReader setProcessingState( + final CallSummaries.ProcessingStateRequest processingState + ) { this.processingState = processingState; return this; } - public CallSummariesReader setSortBy(final CallSummaries.SortBy sortBy){ + + public CallSummariesReader setSortBy(final CallSummaries.SortBy sortBy) { this.sortBy = sortBy; return this; } - public CallSummariesReader setSubaccount(final String subaccount){ + + public CallSummariesReader setSubaccount(final String subaccount) { this.subaccount = subaccount; return this; } - public CallSummariesReader setAbnormalSession(final Boolean abnormalSession){ + + public CallSummariesReader setAbnormalSession( + final Boolean abnormalSession + ) { this.abnormalSession = abnormalSession; return this; } - public CallSummariesReader setAnsweredBy(final CallSummaries.AnsweredBy answeredBy){ + + public CallSummariesReader setAnsweredBy( + final CallSummaries.AnsweredBy answeredBy + ) { this.answeredBy = answeredBy; return this; } - public CallSummariesReader setConnectivityIssue(final String connectivityIssue){ - this.connectivityIssue = connectivityIssue; + + public CallSummariesReader setAnsweredByAnnotation( + final String answeredByAnnotation + ) { + this.answeredByAnnotation = answeredByAnnotation; return this; } - public CallSummariesReader setQualityIssue(final String qualityIssue){ - this.qualityIssue = qualityIssue; + + public CallSummariesReader setConnectivityIssueAnnotation( + final String connectivityIssueAnnotation + ) { + this.connectivityIssueAnnotation = connectivityIssueAnnotation; return this; } - public CallSummariesReader setSpam(final Boolean spam){ - this.spam = spam; + + public CallSummariesReader setQualityIssueAnnotation( + final String qualityIssueAnnotation + ) { + this.qualityIssueAnnotation = qualityIssueAnnotation; return this; } - public CallSummariesReader setCallScore(final String callScore){ - this.callScore = callScore; + + public CallSummariesReader setSpamAnnotation(final Boolean spamAnnotation) { + this.spamAnnotation = spamAnnotation; return this; } - public CallSummariesReader setPageSize(final Integer pageSize){ + + public CallSummariesReader setCallScoreAnnotation( + final String callScoreAnnotation + ) { + this.callScoreAnnotation = callScoreAnnotation; + return this; + } + + public CallSummariesReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -172,13 +215,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("CallSummaries read failed: Unable to connect to server"); + throw new ApiConnectionException( + "CallSummaries read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -194,7 +245,10 @@ private Page pageForRequest(final TwilioRestClient client, final } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.INSIGHTS.toString()) @@ -202,9 +256,11 @@ public Page previousPage(final Page page, final Tw return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.INSIGHTS.toString()) @@ -213,113 +269,105 @@ public Page nextPage(final Page page, final Twilio } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (from != null) { - request.addQueryParam("From", from); } if (to != null) { - request.addQueryParam("To", to); } if (fromCarrier != null) { - request.addQueryParam("FromCarrier", fromCarrier); } if (toCarrier != null) { - request.addQueryParam("ToCarrier", toCarrier); } if (fromCountryCode != null) { - request.addQueryParam("FromCountryCode", fromCountryCode); } if (toCountryCode != null) { - request.addQueryParam("ToCountryCode", toCountryCode); } if (branded != null) { - request.addQueryParam("Branded", branded.toString()); } if (verifiedCaller != null) { - request.addQueryParam("VerifiedCaller", verifiedCaller.toString()); } if (hasTag != null) { - request.addQueryParam("HasTag", hasTag.toString()); } if (startTime != null) { - request.addQueryParam("StartTime", startTime); } if (endTime != null) { - request.addQueryParam("EndTime", endTime); } if (callType != null) { - request.addQueryParam("CallType", callType); } if (callState != null) { - request.addQueryParam("CallState", callState); } if (direction != null) { - request.addQueryParam("Direction", direction); } if (processingState != null) { - - request.addQueryParam("ProcessingState", processingState.toString()); + request.addQueryParam( + "ProcessingState", + processingState.toString() + ); } if (sortBy != null) { - request.addQueryParam("SortBy", sortBy.toString()); } if (subaccount != null) { - request.addQueryParam("Subaccount", subaccount); } if (abnormalSession != null) { - - request.addQueryParam("AbnormalSession", abnormalSession.toString()); + request.addQueryParam( + "AbnormalSession", + abnormalSession.toString() + ); } if (answeredBy != null) { - request.addQueryParam("AnsweredBy", answeredBy.toString()); } - if (connectivityIssue != null) { - - request.addQueryParam("ConnectivityIssue", connectivityIssue); + if (answeredByAnnotation != null) { + request.addQueryParam("AnsweredByAnnotation", answeredByAnnotation); + } + if (connectivityIssueAnnotation != null) { + request.addQueryParam( + "ConnectivityIssueAnnotation", + connectivityIssueAnnotation + ); } - if (qualityIssue != null) { - - request.addQueryParam("QualityIssue", qualityIssue); + if (qualityIssueAnnotation != null) { + request.addQueryParam( + "QualityIssueAnnotation", + qualityIssueAnnotation + ); } - if (spam != null) { - - request.addQueryParam("Spam", spam.toString()); + if (spamAnnotation != null) { + request.addQueryParam("SpamAnnotation", spamAnnotation.toString()); } - if (callScore != null) { - - request.addQueryParam("CallScore", callScore); + if (callScoreAnnotation != null) { + request.addQueryParam("CallScoreAnnotation", callScoreAnnotation); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/insights/v1/Conference.java b/src/main/java/com/twilio/rest/insights/v1/Conference.java index 2075afef6d..0f17af13fd 100644 --- a/src/main/java/com/twilio/rest/insights/v1/Conference.java +++ b/src/main/java/com/twilio/rest/insights/v1/Conference.java @@ -24,44 +24,43 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.List; import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Conference extends Resource { + private static final long serialVersionUID = 40059120188961L; - public static ConferenceFetcher fetcher(final String pathConferenceSid){ + public static ConferenceFetcher fetcher(final String pathConferenceSid) { return new ConferenceFetcher(pathConferenceSid); } - public static ConferenceReader reader(){ + public static ConferenceReader reader() { return new ConferenceReader(); } /** - * Converts a JSON String into a Conference object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Conference object represented by the provided JSON - */ - public static Conference fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Conference object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Conference object represented by the provided JSON + */ + public static Conference fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Conference.class); @@ -73,14 +72,17 @@ public static Conference fromJson(final String json, final ObjectMapper objectMa } /** - * Converts a JSON InputStream into a Conference object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Conference object represented by the provided JSON - */ - public static Conference fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Conference object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Conference object represented by the provided JSON + */ + public static Conference fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Conference.class); @@ -90,12 +92,17 @@ public static Conference fromJson(final InputStream json, final ObjectMapper obj throw new ApiConnectionException(e.getMessage(), e); } } + public enum ConferenceEndReason { LAST_PARTICIPANT_LEFT("last_participant_left"), CONFERENCE_ENDED_VIA_API("conference_ended_via_api"), - PARTICIPANT_WITH_END_CONFERENCE_ON_EXIT_LEFT("participant_with_end_conference_on_exit_left"), + PARTICIPANT_WITH_END_CONFERENCE_ON_EXIT_LEFT( + "participant_with_end_conference_on_exit_left" + ), LAST_PARTICIPANT_KICKED("last_participant_kicked"), - PARTICIPANT_WITH_END_CONFERENCE_ON_EXIT_KICKED("participant_with_end_conference_on_exit_kicked"); + PARTICIPANT_WITH_END_CONFERENCE_ON_EXIT_KICKED( + "participant_with_end_conference_on_exit_kicked" + ); private final String value; @@ -112,6 +119,7 @@ public static ConferenceEndReason forValue(final String value) { return Promoter.enumFromString(value, ConferenceEndReason.values()); } } + public enum ConferenceStatus { IN_PROGRESS("in_progress"), NOT_STARTED("not_started"), @@ -133,6 +141,7 @@ public static ConferenceStatus forValue(final String value) { return Promoter.enumFromString(value, ConferenceStatus.values()); } } + public enum ProcessingState { COMPLETE("complete"), IN_PROGRESS("in_progress"), @@ -153,6 +162,7 @@ public static ProcessingState forValue(final String value) { return Promoter.enumFromString(value, ProcessingState.values()); } } + public enum Region { US1("us1"), AU1("au1"), @@ -177,6 +187,7 @@ public static Region forValue(final String value) { return Promoter.enumFromString(value, Region.values()); } } + public enum Tag { INVALID_REQUESTED_REGION("invalid_requested_region"), DUPLICATE_IDENTITY("duplicate_identity"), @@ -232,74 +243,41 @@ public static Tag forValue(final String value) { @JsonCreator private Conference( - @JsonProperty("conference_sid") - final String conferenceSid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("create_time") - final String createTime, - - @JsonProperty("start_time") - final String startTime, - - @JsonProperty("end_time") - final String endTime, - - @JsonProperty("duration_seconds") - final Integer durationSeconds, - - @JsonProperty("connect_duration_seconds") - final Integer connectDurationSeconds, - - @JsonProperty("status") - final Conference.ConferenceStatus status, - - @JsonProperty("max_participants") - final Integer maxParticipants, - - @JsonProperty("max_concurrent_participants") - final Integer maxConcurrentParticipants, - - @JsonProperty("unique_participants") - final Integer uniqueParticipants, - - @JsonProperty("end_reason") - final Conference.ConferenceEndReason endReason, - - @JsonProperty("ended_by") - final String endedBy, - - @JsonProperty("mixer_region") - final Conference.Region mixerRegion, - - @JsonProperty("mixer_region_requested") - final Conference.Region mixerRegionRequested, - - @JsonProperty("recording_enabled") - final Boolean recordingEnabled, - - @JsonProperty("detected_issues") - final Map detectedIssues, - - @JsonProperty("tags") - final List tags, - - @JsonProperty("tag_info") - final Map tagInfo, - - @JsonProperty("processing_state") - final Conference.ProcessingState processingState, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("conference_sid") final String conferenceSid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("create_time") final String createTime, + @JsonProperty("start_time") final String startTime, + @JsonProperty("end_time") final String endTime, + @JsonProperty("duration_seconds") final Integer durationSeconds, + @JsonProperty( + "connect_duration_seconds" + ) final Integer connectDurationSeconds, + @JsonProperty("status") final Conference.ConferenceStatus status, + @JsonProperty("max_participants") final Integer maxParticipants, + @JsonProperty( + "max_concurrent_participants" + ) final Integer maxConcurrentParticipants, + @JsonProperty("unique_participants") final Integer uniqueParticipants, + @JsonProperty( + "end_reason" + ) final Conference.ConferenceEndReason endReason, + @JsonProperty("ended_by") final String endedBy, + @JsonProperty("mixer_region") final Conference.Region mixerRegion, + @JsonProperty( + "mixer_region_requested" + ) final Conference.Region mixerRegionRequested, + @JsonProperty("recording_enabled") final Boolean recordingEnabled, + @JsonProperty( + "detected_issues" + ) final Map detectedIssues, + @JsonProperty("tags") final List tags, + @JsonProperty("tag_info") final Map tagInfo, + @JsonProperty( + "processing_state" + ) final Conference.ProcessingState processingState, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.conferenceSid = conferenceSid; this.accountSid = accountSid; @@ -326,79 +304,101 @@ private Conference( this.links = links; } - public final String getConferenceSid() { - return this.conferenceSid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final ZonedDateTime getCreateTime() { - return this.createTime; - } - public final ZonedDateTime getStartTime() { - return this.startTime; - } - public final ZonedDateTime getEndTime() { - return this.endTime; - } - public final Integer getDurationSeconds() { - return this.durationSeconds; - } - public final Integer getConnectDurationSeconds() { - return this.connectDurationSeconds; - } - public final Conference.ConferenceStatus getStatus() { - return this.status; - } - public final Integer getMaxParticipants() { - return this.maxParticipants; - } - public final Integer getMaxConcurrentParticipants() { - return this.maxConcurrentParticipants; - } - public final Integer getUniqueParticipants() { - return this.uniqueParticipants; - } - public final Conference.ConferenceEndReason getEndReason() { - return this.endReason; - } - public final String getEndedBy() { - return this.endedBy; - } - public final Conference.Region getMixerRegion() { - return this.mixerRegion; - } - public final Conference.Region getMixerRegionRequested() { - return this.mixerRegionRequested; - } - public final Boolean getRecordingEnabled() { - return this.recordingEnabled; - } - public final Map getDetectedIssues() { - return this.detectedIssues; - } - public final List getTags() { - return this.tags; - } - public final Map getTagInfo() { - return this.tagInfo; - } - public final Conference.ProcessingState getProcessingState() { - return this.processingState; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getConferenceSid() { + return this.conferenceSid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final ZonedDateTime getCreateTime() { + return this.createTime; + } + + public final ZonedDateTime getStartTime() { + return this.startTime; + } + + public final ZonedDateTime getEndTime() { + return this.endTime; + } + + public final Integer getDurationSeconds() { + return this.durationSeconds; + } + + public final Integer getConnectDurationSeconds() { + return this.connectDurationSeconds; + } + + public final Conference.ConferenceStatus getStatus() { + return this.status; + } + + public final Integer getMaxParticipants() { + return this.maxParticipants; + } + + public final Integer getMaxConcurrentParticipants() { + return this.maxConcurrentParticipants; + } + + public final Integer getUniqueParticipants() { + return this.uniqueParticipants; + } + + public final Conference.ConferenceEndReason getEndReason() { + return this.endReason; + } + + public final String getEndedBy() { + return this.endedBy; + } + + public final Conference.Region getMixerRegion() { + return this.mixerRegion; + } + + public final Conference.Region getMixerRegionRequested() { + return this.mixerRegionRequested; + } + + public final Boolean getRecordingEnabled() { + return this.recordingEnabled; + } + + public final Map getDetectedIssues() { + return this.detectedIssues; + } + + public final List getTags() { + return this.tags; + } + + public final Map getTagInfo() { + return this.tagInfo; + } + + public final Conference.ProcessingState getProcessingState() { + return this.processingState; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -408,13 +408,65 @@ public boolean equals(final Object o) { Conference other = (Conference) o; - return Objects.equals(conferenceSid, other.conferenceSid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(createTime, other.createTime) && Objects.equals(startTime, other.startTime) && Objects.equals(endTime, other.endTime) && Objects.equals(durationSeconds, other.durationSeconds) && Objects.equals(connectDurationSeconds, other.connectDurationSeconds) && Objects.equals(status, other.status) && Objects.equals(maxParticipants, other.maxParticipants) && Objects.equals(maxConcurrentParticipants, other.maxConcurrentParticipants) && Objects.equals(uniqueParticipants, other.uniqueParticipants) && Objects.equals(endReason, other.endReason) && Objects.equals(endedBy, other.endedBy) && Objects.equals(mixerRegion, other.mixerRegion) && Objects.equals(mixerRegionRequested, other.mixerRegionRequested) && Objects.equals(recordingEnabled, other.recordingEnabled) && Objects.equals(detectedIssues, other.detectedIssues) && Objects.equals(tags, other.tags) && Objects.equals(tagInfo, other.tagInfo) && Objects.equals(processingState, other.processingState) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(conferenceSid, other.conferenceSid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(createTime, other.createTime) && + Objects.equals(startTime, other.startTime) && + Objects.equals(endTime, other.endTime) && + Objects.equals(durationSeconds, other.durationSeconds) && + Objects.equals( + connectDurationSeconds, + other.connectDurationSeconds + ) && + Objects.equals(status, other.status) && + Objects.equals(maxParticipants, other.maxParticipants) && + Objects.equals( + maxConcurrentParticipants, + other.maxConcurrentParticipants + ) && + Objects.equals(uniqueParticipants, other.uniqueParticipants) && + Objects.equals(endReason, other.endReason) && + Objects.equals(endedBy, other.endedBy) && + Objects.equals(mixerRegion, other.mixerRegion) && + Objects.equals(mixerRegionRequested, other.mixerRegionRequested) && + Objects.equals(recordingEnabled, other.recordingEnabled) && + Objects.equals(detectedIssues, other.detectedIssues) && + Objects.equals(tags, other.tags) && + Objects.equals(tagInfo, other.tagInfo) && + Objects.equals(processingState, other.processingState) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(conferenceSid, accountSid, friendlyName, createTime, startTime, endTime, durationSeconds, connectDurationSeconds, status, maxParticipants, maxConcurrentParticipants, uniqueParticipants, endReason, endedBy, mixerRegion, mixerRegionRequested, recordingEnabled, detectedIssues, tags, tagInfo, processingState, url, links); + return Objects.hash( + conferenceSid, + accountSid, + friendlyName, + createTime, + startTime, + endTime, + durationSeconds, + connectDurationSeconds, + status, + maxParticipants, + maxConcurrentParticipants, + uniqueParticipants, + endReason, + endedBy, + mixerRegion, + mixerRegionRequested, + recordingEnabled, + detectedIssues, + tags, + tagInfo, + processingState, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/insights/v1/ConferenceFetcher.java b/src/main/java/com/twilio/rest/insights/v1/ConferenceFetcher.java index 6a98e3d522..5d2289311d 100644 --- a/src/main/java/com/twilio/rest/insights/v1/ConferenceFetcher.java +++ b/src/main/java/com/twilio/rest/insights/v1/ConferenceFetcher.java @@ -24,22 +24,23 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class ConferenceFetcher extends Fetcher { + private String pathConferenceSid; - public ConferenceFetcher(final String pathConferenceSid){ + public ConferenceFetcher(final String pathConferenceSid) { this.pathConferenceSid = pathConferenceSid; } - @Override public Conference fetch(final TwilioRestClient client) { String path = "/v1/Conferences/{ConferenceSid}"; - path = path.replace("{"+"ConferenceSid"+"}", this.pathConferenceSid.toString()); + path = + path.replace( + "{" + "ConferenceSid" + "}", + this.pathConferenceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -49,15 +50,23 @@ public Conference fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Conference fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Conference fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Conference.fromJson(response.getStream(), client.getObjectMapper()); + return Conference.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/insights/v1/ConferenceReader.java b/src/main/java/com/twilio/rest/insights/v1/ConferenceReader.java index e1d69f5bbb..a702b6dbfb 100644 --- a/src/main/java/com/twilio/rest/insights/v1/ConferenceReader.java +++ b/src/main/java/com/twilio/rest/insights/v1/ConferenceReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.insights.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,11 +25,9 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class ConferenceReader extends Reader { + private String conferenceSid; private String friendlyName; private String status; @@ -41,50 +40,59 @@ public class ConferenceReader extends Reader { private String endReason; private Integer pageSize; - public ConferenceReader(){ - } + public ConferenceReader() {} - public ConferenceReader setConferenceSid(final String conferenceSid){ + public ConferenceReader setConferenceSid(final String conferenceSid) { this.conferenceSid = conferenceSid; return this; } - public ConferenceReader setFriendlyName(final String friendlyName){ + + public ConferenceReader setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public ConferenceReader setStatus(final String status){ + + public ConferenceReader setStatus(final String status) { this.status = status; return this; } - public ConferenceReader setCreatedAfter(final String createdAfter){ + + public ConferenceReader setCreatedAfter(final String createdAfter) { this.createdAfter = createdAfter; return this; } - public ConferenceReader setCreatedBefore(final String createdBefore){ + + public ConferenceReader setCreatedBefore(final String createdBefore) { this.createdBefore = createdBefore; return this; } - public ConferenceReader setMixerRegion(final String mixerRegion){ + + public ConferenceReader setMixerRegion(final String mixerRegion) { this.mixerRegion = mixerRegion; return this; } - public ConferenceReader setTags(final String tags){ + + public ConferenceReader setTags(final String tags) { this.tags = tags; return this; } - public ConferenceReader setSubaccount(final String subaccount){ + + public ConferenceReader setSubaccount(final String subaccount) { this.subaccount = subaccount; return this; } - public ConferenceReader setDetectedIssues(final String detectedIssues){ + + public ConferenceReader setDetectedIssues(final String detectedIssues) { this.detectedIssues = detectedIssues; return this; } - public ConferenceReader setEndReason(final String endReason){ + + public ConferenceReader setEndReason(final String endReason) { this.endReason = endReason; return this; } - public ConferenceReader setPageSize(final Integer pageSize){ + + public ConferenceReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -107,13 +115,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Conference read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Conference read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -129,7 +145,10 @@ private Page pageForRequest(final TwilioRestClient client, final Req } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.INSIGHTS.toString()) @@ -137,9 +156,11 @@ public Page previousPage(final Page page, final TwilioRe return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.INSIGHTS.toString()) @@ -148,61 +169,51 @@ public Page nextPage(final Page page, final TwilioRestCl } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (conferenceSid != null) { - request.addQueryParam("ConferenceSid", conferenceSid); } if (friendlyName != null) { - request.addQueryParam("FriendlyName", friendlyName); } if (status != null) { - request.addQueryParam("Status", status); } if (createdAfter != null) { - request.addQueryParam("CreatedAfter", createdAfter); } if (createdBefore != null) { - request.addQueryParam("CreatedBefore", createdBefore); } if (mixerRegion != null) { - request.addQueryParam("MixerRegion", mixerRegion); } if (tags != null) { - request.addQueryParam("Tags", tags); } if (subaccount != null) { - request.addQueryParam("Subaccount", subaccount); } if (detectedIssues != null) { - request.addQueryParam("DetectedIssues", detectedIssues); } if (endReason != null) { - request.addQueryParam("EndReason", endReason); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/insights/v1/Room.java b/src/main/java/com/twilio/rest/insights/v1/Room.java index ba8c327d0d..f4780b16d4 100644 --- a/src/main/java/com/twilio/rest/insights/v1/Room.java +++ b/src/main/java/com/twilio/rest/insights/v1/Room.java @@ -24,45 +24,44 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; import com.twilio.http.HttpMethod; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.List; import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Room extends Resource { + private static final long serialVersionUID = 140614978057184L; - public static RoomFetcher fetcher(final String pathRoomSid){ + public static RoomFetcher fetcher(final String pathRoomSid) { return new RoomFetcher(pathRoomSid); } - public static RoomReader reader(){ + public static RoomReader reader() { return new RoomReader(); } /** - * Converts a JSON String into a Room object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Room object represented by the provided JSON - */ - public static Room fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Room object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Room object represented by the provided JSON + */ + public static Room fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Room.class); @@ -74,14 +73,17 @@ public static Room fromJson(final String json, final ObjectMapper objectMapper) } /** - * Converts a JSON InputStream into a Room object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Room object represented by the provided JSON - */ - public static Room fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Room object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Room object represented by the provided JSON + */ + public static Room fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Room.class); @@ -91,6 +93,7 @@ public static Room fromJson(final InputStream json, final ObjectMapper objectMap throw new ApiConnectionException(e.getMessage(), e); } } + public enum Codec { VP8("VP8"), H264("H264"), @@ -111,6 +114,7 @@ public static Codec forValue(final String value) { return Promoter.enumFromString(value, Codec.values()); } } + public enum CreatedMethod { SDK("sdk"), AD_HOC("ad_hoc"), @@ -131,6 +135,7 @@ public static CreatedMethod forValue(final String value) { return Promoter.enumFromString(value, CreatedMethod.values()); } } + public enum EdgeLocation { ASHBURN("ashburn"), DUBLIN("dublin"), @@ -157,6 +162,7 @@ public static EdgeLocation forValue(final String value) { return Promoter.enumFromString(value, EdgeLocation.values()); } } + public enum EndReason { ROOM_ENDED_VIA_API("room_ended_via_api"), TIMEOUT("timeout"); @@ -176,6 +182,7 @@ public static EndReason forValue(final String value) { return Promoter.enumFromString(value, EndReason.values()); } } + public enum ProcessingState { COMPLETE("complete"), IN_PROGRESS("in_progress"); @@ -195,6 +202,7 @@ public static ProcessingState forValue(final String value) { return Promoter.enumFromString(value, ProcessingState.values()); } } + public enum RoomStatus { IN_PROGRESS("in_progress"), COMPLETED("completed"); @@ -214,6 +222,7 @@ public static RoomStatus forValue(final String value) { return Promoter.enumFromString(value, RoomStatus.values()); } } + public enum RoomType { GO("go"), PEER_TO_PEER("peer_to_peer"), @@ -235,6 +244,7 @@ public static RoomType forValue(final String value) { return Promoter.enumFromString(value, RoomType.values()); } } + public enum TwilioRealm { US1("us1"), US2("us2"), @@ -292,83 +302,46 @@ public static TwilioRealm forValue(final String value) { @JsonCreator private Room( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("room_sid") - final String roomSid, - - @JsonProperty("room_name") - final String roomName, - - @JsonProperty("create_time") - final String createTime, - - @JsonProperty("end_time") - final String endTime, - - @JsonProperty("room_type") - final Room.RoomType roomType, - - @JsonProperty("room_status") - final Room.RoomStatus roomStatus, - - @JsonProperty("status_callback") - final URI statusCallback, - - @JsonProperty("status_callback_method") - final HttpMethod statusCallbackMethod, - - @JsonProperty("created_method") - final Room.CreatedMethod createdMethod, - - @JsonProperty("end_reason") - final Room.EndReason endReason, - - @JsonProperty("max_participants") - final Integer maxParticipants, - - @JsonProperty("unique_participants") - final Integer uniqueParticipants, - - @JsonProperty("unique_participant_identities") - final Integer uniqueParticipantIdentities, - - @JsonProperty("concurrent_participants") - final Integer concurrentParticipants, - - @JsonProperty("max_concurrent_participants") - final Integer maxConcurrentParticipants, - - @JsonProperty("codecs") - final List codecs, - - @JsonProperty("media_region") - final Room.TwilioRealm mediaRegion, - - @JsonProperty("duration_sec") - final Long durationSec, - - @JsonProperty("total_participant_duration_sec") - final Long totalParticipantDurationSec, - - @JsonProperty("total_recording_duration_sec") - final Long totalRecordingDurationSec, - - @JsonProperty("processing_state") - final Room.ProcessingState processingState, - - @JsonProperty("recording_enabled") - final Boolean recordingEnabled, - - @JsonProperty("edge_location") - final Room.EdgeLocation edgeLocation, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("room_sid") final String roomSid, + @JsonProperty("room_name") final String roomName, + @JsonProperty("create_time") final String createTime, + @JsonProperty("end_time") final String endTime, + @JsonProperty("room_type") final Room.RoomType roomType, + @JsonProperty("room_status") final Room.RoomStatus roomStatus, + @JsonProperty("status_callback") final URI statusCallback, + @JsonProperty( + "status_callback_method" + ) final HttpMethod statusCallbackMethod, + @JsonProperty("created_method") final Room.CreatedMethod createdMethod, + @JsonProperty("end_reason") final Room.EndReason endReason, + @JsonProperty("max_participants") final Integer maxParticipants, + @JsonProperty("unique_participants") final Integer uniqueParticipants, + @JsonProperty( + "unique_participant_identities" + ) final Integer uniqueParticipantIdentities, + @JsonProperty( + "concurrent_participants" + ) final Integer concurrentParticipants, + @JsonProperty( + "max_concurrent_participants" + ) final Integer maxConcurrentParticipants, + @JsonProperty("codecs") final List codecs, + @JsonProperty("media_region") final Room.TwilioRealm mediaRegion, + @JsonProperty("duration_sec") final Long durationSec, + @JsonProperty( + "total_participant_duration_sec" + ) final Long totalParticipantDurationSec, + @JsonProperty( + "total_recording_duration_sec" + ) final Long totalRecordingDurationSec, + @JsonProperty( + "processing_state" + ) final Room.ProcessingState processingState, + @JsonProperty("recording_enabled") final Boolean recordingEnabled, + @JsonProperty("edge_location") final Room.EdgeLocation edgeLocation, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.accountSid = accountSid; this.roomSid = roomSid; @@ -398,88 +371,113 @@ private Room( this.links = links; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getRoomSid() { - return this.roomSid; - } - public final String getRoomName() { - return this.roomName; - } - public final ZonedDateTime getCreateTime() { - return this.createTime; - } - public final ZonedDateTime getEndTime() { - return this.endTime; - } - public final Room.RoomType getRoomType() { - return this.roomType; - } - public final Room.RoomStatus getRoomStatus() { - return this.roomStatus; - } - public final URI getStatusCallback() { - return this.statusCallback; - } - public final HttpMethod getStatusCallbackMethod() { - return this.statusCallbackMethod; - } - public final Room.CreatedMethod getCreatedMethod() { - return this.createdMethod; - } - public final Room.EndReason getEndReason() { - return this.endReason; - } - public final Integer getMaxParticipants() { - return this.maxParticipants; - } - public final Integer getUniqueParticipants() { - return this.uniqueParticipants; - } - public final Integer getUniqueParticipantIdentities() { - return this.uniqueParticipantIdentities; - } - public final Integer getConcurrentParticipants() { - return this.concurrentParticipants; - } - public final Integer getMaxConcurrentParticipants() { - return this.maxConcurrentParticipants; - } - public final List getCodecs() { - return this.codecs; - } - public final Room.TwilioRealm getMediaRegion() { - return this.mediaRegion; - } - public final Long getDurationSec() { - return this.durationSec; - } - public final Long getTotalParticipantDurationSec() { - return this.totalParticipantDurationSec; - } - public final Long getTotalRecordingDurationSec() { - return this.totalRecordingDurationSec; - } - public final Room.ProcessingState getProcessingState() { - return this.processingState; - } - public final Boolean getRecordingEnabled() { - return this.recordingEnabled; - } - public final Room.EdgeLocation getEdgeLocation() { - return this.edgeLocation; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getRoomSid() { + return this.roomSid; + } + + public final String getRoomName() { + return this.roomName; + } + + public final ZonedDateTime getCreateTime() { + return this.createTime; + } + + public final ZonedDateTime getEndTime() { + return this.endTime; + } + + public final Room.RoomType getRoomType() { + return this.roomType; + } + + public final Room.RoomStatus getRoomStatus() { + return this.roomStatus; + } + + public final URI getStatusCallback() { + return this.statusCallback; + } + + public final HttpMethod getStatusCallbackMethod() { + return this.statusCallbackMethod; + } + + public final Room.CreatedMethod getCreatedMethod() { + return this.createdMethod; + } + + public final Room.EndReason getEndReason() { + return this.endReason; + } + + public final Integer getMaxParticipants() { + return this.maxParticipants; + } + + public final Integer getUniqueParticipants() { + return this.uniqueParticipants; + } + + public final Integer getUniqueParticipantIdentities() { + return this.uniqueParticipantIdentities; + } + + public final Integer getConcurrentParticipants() { + return this.concurrentParticipants; + } + + public final Integer getMaxConcurrentParticipants() { + return this.maxConcurrentParticipants; + } + + public final List getCodecs() { + return this.codecs; + } + + public final Room.TwilioRealm getMediaRegion() { + return this.mediaRegion; + } + + public final Long getDurationSec() { + return this.durationSec; + } + + public final Long getTotalParticipantDurationSec() { + return this.totalParticipantDurationSec; + } + + public final Long getTotalRecordingDurationSec() { + return this.totalRecordingDurationSec; + } + + public final Room.ProcessingState getProcessingState() { + return this.processingState; + } + + public final Boolean getRecordingEnabled() { + return this.recordingEnabled; + } + + public final Room.EdgeLocation getEdgeLocation() { + return this.edgeLocation; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -489,13 +487,80 @@ public boolean equals(final Object o) { Room other = (Room) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(roomSid, other.roomSid) && Objects.equals(roomName, other.roomName) && Objects.equals(createTime, other.createTime) && Objects.equals(endTime, other.endTime) && Objects.equals(roomType, other.roomType) && Objects.equals(roomStatus, other.roomStatus) && Objects.equals(statusCallback, other.statusCallback) && Objects.equals(statusCallbackMethod, other.statusCallbackMethod) && Objects.equals(createdMethod, other.createdMethod) && Objects.equals(endReason, other.endReason) && Objects.equals(maxParticipants, other.maxParticipants) && Objects.equals(uniqueParticipants, other.uniqueParticipants) && Objects.equals(uniqueParticipantIdentities, other.uniqueParticipantIdentities) && Objects.equals(concurrentParticipants, other.concurrentParticipants) && Objects.equals(maxConcurrentParticipants, other.maxConcurrentParticipants) && Objects.equals(codecs, other.codecs) && Objects.equals(mediaRegion, other.mediaRegion) && Objects.equals(durationSec, other.durationSec) && Objects.equals(totalParticipantDurationSec, other.totalParticipantDurationSec) && Objects.equals(totalRecordingDurationSec, other.totalRecordingDurationSec) && Objects.equals(processingState, other.processingState) && Objects.equals(recordingEnabled, other.recordingEnabled) && Objects.equals(edgeLocation, other.edgeLocation) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(roomSid, other.roomSid) && + Objects.equals(roomName, other.roomName) && + Objects.equals(createTime, other.createTime) && + Objects.equals(endTime, other.endTime) && + Objects.equals(roomType, other.roomType) && + Objects.equals(roomStatus, other.roomStatus) && + Objects.equals(statusCallback, other.statusCallback) && + Objects.equals(statusCallbackMethod, other.statusCallbackMethod) && + Objects.equals(createdMethod, other.createdMethod) && + Objects.equals(endReason, other.endReason) && + Objects.equals(maxParticipants, other.maxParticipants) && + Objects.equals(uniqueParticipants, other.uniqueParticipants) && + Objects.equals( + uniqueParticipantIdentities, + other.uniqueParticipantIdentities + ) && + Objects.equals( + concurrentParticipants, + other.concurrentParticipants + ) && + Objects.equals( + maxConcurrentParticipants, + other.maxConcurrentParticipants + ) && + Objects.equals(codecs, other.codecs) && + Objects.equals(mediaRegion, other.mediaRegion) && + Objects.equals(durationSec, other.durationSec) && + Objects.equals( + totalParticipantDurationSec, + other.totalParticipantDurationSec + ) && + Objects.equals( + totalRecordingDurationSec, + other.totalRecordingDurationSec + ) && + Objects.equals(processingState, other.processingState) && + Objects.equals(recordingEnabled, other.recordingEnabled) && + Objects.equals(edgeLocation, other.edgeLocation) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, roomSid, roomName, createTime, endTime, roomType, roomStatus, statusCallback, statusCallbackMethod, createdMethod, endReason, maxParticipants, uniqueParticipants, uniqueParticipantIdentities, concurrentParticipants, maxConcurrentParticipants, codecs, mediaRegion, durationSec, totalParticipantDurationSec, totalRecordingDurationSec, processingState, recordingEnabled, edgeLocation, url, links); + return Objects.hash( + accountSid, + roomSid, + roomName, + createTime, + endTime, + roomType, + roomStatus, + statusCallback, + statusCallbackMethod, + createdMethod, + endReason, + maxParticipants, + uniqueParticipants, + uniqueParticipantIdentities, + concurrentParticipants, + maxConcurrentParticipants, + codecs, + mediaRegion, + durationSec, + totalParticipantDurationSec, + totalRecordingDurationSec, + processingState, + recordingEnabled, + edgeLocation, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/insights/v1/RoomFetcher.java b/src/main/java/com/twilio/rest/insights/v1/RoomFetcher.java index 8f6196d152..84db44b3fc 100644 --- a/src/main/java/com/twilio/rest/insights/v1/RoomFetcher.java +++ b/src/main/java/com/twilio/rest/insights/v1/RoomFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class RoomFetcher extends Fetcher { + private String pathRoomSid; - public RoomFetcher(final String pathRoomSid){ + public RoomFetcher(final String pathRoomSid) { this.pathRoomSid = pathRoomSid; } - @Override public Room fetch(final TwilioRestClient client) { String path = "/v1/Video/Rooms/{RoomSid}"; - path = path.replace("{"+"RoomSid"+"}", this.pathRoomSid.toString()); + path = path.replace("{" + "RoomSid" + "}", this.pathRoomSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,9 +46,14 @@ public Room fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Room fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Room fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/insights/v1/RoomReader.java b/src/main/java/com/twilio/rest/insights/v1/RoomReader.java index 5e76ee562f..965515002d 100644 --- a/src/main/java/com/twilio/rest/insights/v1/RoomReader.java +++ b/src/main/java/com/twilio/rest/insights/v1/RoomReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.insights.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.converter.Promoter; @@ -25,13 +26,11 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; import java.time.ZonedDateTime; - import java.util.List; - public class RoomReader extends Reader { + private List roomType; private List codec; private String roomName; @@ -39,36 +38,42 @@ public class RoomReader extends Reader { private ZonedDateTime createdBefore; private Integer pageSize; - public RoomReader(){ - } + public RoomReader() {} - public RoomReader setRoomType(final List roomType){ + public RoomReader setRoomType(final List roomType) { this.roomType = roomType; return this; } - public RoomReader setRoomType(final Room.RoomType roomType){ + + public RoomReader setRoomType(final Room.RoomType roomType) { return setRoomType(Promoter.listOfOne(roomType)); } - public RoomReader setCodec(final List codec){ + + public RoomReader setCodec(final List codec) { this.codec = codec; return this; } - public RoomReader setCodec(final Room.Codec codec){ + + public RoomReader setCodec(final Room.Codec codec) { return setCodec(Promoter.listOfOne(codec)); } - public RoomReader setRoomName(final String roomName){ + + public RoomReader setRoomName(final String roomName) { this.roomName = roomName; return this; } - public RoomReader setCreatedAfter(final ZonedDateTime createdAfter){ + + public RoomReader setCreatedAfter(final ZonedDateTime createdAfter) { this.createdAfter = createdAfter; return this; } - public RoomReader setCreatedBefore(final ZonedDateTime createdBefore){ + + public RoomReader setCreatedBefore(final ZonedDateTime createdBefore) { this.createdBefore = createdBefore; return this; } - public RoomReader setPageSize(final Integer pageSize){ + + public RoomReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -91,13 +96,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Room read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Room read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -113,7 +126,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request r } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.INSIGHTS.toString()) @@ -121,9 +137,11 @@ public Page previousPage(final Page page, final TwilioRestClient cli return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.INSIGHTS.toString()) @@ -132,14 +150,15 @@ public Page nextPage(final Page page, final TwilioRestClient client) } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (roomType != null) { for (Room.RoomType prop : roomType) { @@ -152,23 +171,27 @@ private void addQueryParams(final Request request) { } } if (roomName != null) { - request.addQueryParam("RoomName", roomName); } if (createdAfter != null) { - request.addQueryParam("CreatedAfter", createdAfter.toInstant().toString()); + request.addQueryParam( + "CreatedAfter", + createdAfter.toInstant().toString() + ); } if (createdBefore != null) { - request.addQueryParam("CreatedBefore", createdBefore.toInstant().toString()); + request.addQueryParam( + "CreatedBefore", + createdBefore.toInstant().toString() + ); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/insights/v1/Setting.java b/src/main/java/com/twilio/rest/insights/v1/Setting.java index b2c367200a..d2515f77d3 100644 --- a/src/main/java/com/twilio/rest/insights/v1/Setting.java +++ b/src/main/java/com/twilio/rest/insights/v1/Setting.java @@ -22,40 +22,39 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Setting extends Resource { + private static final long serialVersionUID = 24698393526973L; - public static SettingFetcher fetcher(){ + public static SettingFetcher fetcher() { return new SettingFetcher(); } - public static SettingUpdater updater(){ + public static SettingUpdater updater() { return new SettingUpdater(); } /** - * Converts a JSON String into a Setting object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Setting object represented by the provided JSON - */ - public static Setting fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Setting object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Setting object represented by the provided JSON + */ + public static Setting fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Setting.class); @@ -67,14 +66,17 @@ public static Setting fromJson(final String json, final ObjectMapper objectMappe } /** - * Converts a JSON InputStream into a Setting object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Setting object represented by the provided JSON - */ - public static Setting fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Setting object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Setting object represented by the provided JSON + */ + public static Setting fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Setting.class); @@ -92,17 +94,10 @@ public static Setting fromJson(final InputStream json, final ObjectMapper object @JsonCreator private Setting( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("advanced_features") - final Boolean advancedFeatures, - - @JsonProperty("voice_trace") - final Boolean voiceTrace, - - @JsonProperty("url") - final URI url + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("advanced_features") final Boolean advancedFeatures, + @JsonProperty("voice_trace") final Boolean voiceTrace, + @JsonProperty("url") final URI url ) { this.accountSid = accountSid; this.advancedFeatures = advancedFeatures; @@ -110,22 +105,25 @@ private Setting( this.url = url; } - public final String getAccountSid() { - return this.accountSid; - } - public final Boolean getAdvancedFeatures() { - return this.advancedFeatures; - } - public final Boolean getVoiceTrace() { - return this.voiceTrace; - } - public final URI getUrl() { - return this.url; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final Boolean getAdvancedFeatures() { + return this.advancedFeatures; + } + + public final Boolean getVoiceTrace() { + return this.voiceTrace; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -135,13 +133,16 @@ public boolean equals(final Object o) { Setting other = (Setting) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(advancedFeatures, other.advancedFeatures) && Objects.equals(voiceTrace, other.voiceTrace) && Objects.equals(url, other.url) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(advancedFeatures, other.advancedFeatures) && + Objects.equals(voiceTrace, other.voiceTrace) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { return Objects.hash(accountSid, advancedFeatures, voiceTrace, url); } - } - diff --git a/src/main/java/com/twilio/rest/insights/v1/SettingFetcher.java b/src/main/java/com/twilio/rest/insights/v1/SettingFetcher.java index 40625d92dd..259b7e0591 100644 --- a/src/main/java/com/twilio/rest/insights/v1/SettingFetcher.java +++ b/src/main/java/com/twilio/rest/insights/v1/SettingFetcher.java @@ -24,16 +24,13 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class SettingFetcher extends Fetcher { + private String subaccountSid; - public SettingFetcher(){ - } + public SettingFetcher() {} - public SettingFetcher setSubaccountSid(final String subaccountSid){ + public SettingFetcher setSubaccountSid(final String subaccountSid) { this.subaccountSid = subaccountSid; return this; } @@ -42,7 +39,6 @@ public SettingFetcher setSubaccountSid(final String subaccountSid){ public Setting fetch(final TwilioRestClient client) { String path = "/v1/Voice/Settings"; - Request request = new Request( HttpMethod.GET, Domains.INSIGHTS.toString(), @@ -52,9 +48,14 @@ public Setting fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Setting fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Setting fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -63,9 +64,9 @@ public Setting fetch(final TwilioRestClient client) { return Setting.fromJson(response.getStream(), client.getObjectMapper()); } + private void addQueryParams(final Request request) { if (subaccountSid != null) { - request.addQueryParam("SubaccountSid", subaccountSid); } } diff --git a/src/main/java/com/twilio/rest/insights/v1/SettingUpdater.java b/src/main/java/com/twilio/rest/insights/v1/SettingUpdater.java index cfe4343587..0f4324060d 100644 --- a/src/main/java/com/twilio/rest/insights/v1/SettingUpdater.java +++ b/src/main/java/com/twilio/rest/insights/v1/SettingUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.insights.v1; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,46 +25,50 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class SettingUpdater extends Updater { - - -public class SettingUpdater extends Updater{ private Boolean advancedFeatures; private Boolean voiceTrace; private String subaccountSid; - public SettingUpdater(){ - } + public SettingUpdater() {} - public SettingUpdater setAdvancedFeatures(final Boolean advancedFeatures){ + public SettingUpdater setAdvancedFeatures(final Boolean advancedFeatures) { this.advancedFeatures = advancedFeatures; return this; } - public SettingUpdater setVoiceTrace(final Boolean voiceTrace){ + + public SettingUpdater setVoiceTrace(final Boolean voiceTrace) { this.voiceTrace = voiceTrace; return this; } - public SettingUpdater setSubaccountSid(final String subaccountSid){ + + public SettingUpdater setSubaccountSid(final String subaccountSid) { this.subaccountSid = subaccountSid; return this; } @Override - public Setting update(final TwilioRestClient client){ + public Setting update(final TwilioRestClient client) { String path = "/v1/Voice/Settings"; - Request request = new Request( HttpMethod.POST, Domains.INSIGHTS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Setting update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Setting update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -72,18 +77,19 @@ public Setting update(final TwilioRestClient client){ return Setting.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (advancedFeatures != null) { - request.addPostParam("AdvancedFeatures", advancedFeatures.toString()); - + request.addPostParam( + "AdvancedFeatures", + advancedFeatures.toString() + ); } if (voiceTrace != null) { request.addPostParam("VoiceTrace", voiceTrace.toString()); - } if (subaccountSid != null) { request.addPostParam("SubaccountSid", subaccountSid); - } } } diff --git a/src/main/java/com/twilio/rest/insights/v1/call/Annotation.java b/src/main/java/com/twilio/rest/insights/v1/call/Annotation.java index c253eec3c9..efac5b249d 100644 --- a/src/main/java/com/twilio/rest/insights/v1/call/Annotation.java +++ b/src/main/java/com/twilio/rest/insights/v1/call/Annotation.java @@ -23,41 +23,40 @@ import com.twilio.base.Resource; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.List; import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Annotation extends Resource { + private static final long serialVersionUID = 9735005754677L; - public static AnnotationFetcher fetcher(final String pathCallSid){ + public static AnnotationFetcher fetcher(final String pathCallSid) { return new AnnotationFetcher(pathCallSid); } - public static AnnotationUpdater updater(final String pathCallSid){ + public static AnnotationUpdater updater(final String pathCallSid) { return new AnnotationUpdater(pathCallSid); } /** - * Converts a JSON String into a Annotation object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Annotation object represented by the provided JSON - */ - public static Annotation fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Annotation object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Annotation object represented by the provided JSON + */ + public static Annotation fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Annotation.class); @@ -69,14 +68,17 @@ public static Annotation fromJson(final String json, final ObjectMapper objectMa } /** - * Converts a JSON InputStream into a Annotation object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Annotation object represented by the provided JSON - */ - public static Annotation fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Annotation object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Annotation object represented by the provided JSON + */ + public static Annotation fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Annotation.class); @@ -86,6 +88,7 @@ public static Annotation fromJson(final InputStream json, final ObjectMapper obj throw new ApiConnectionException(e.getMessage(), e); } } + public enum AnsweredBy { UNKNOWN_ANSWERED_BY("unknown_answered_by"), HUMAN("human"), @@ -106,6 +109,7 @@ public static AnsweredBy forValue(final String value) { return Promoter.enumFromString(value, AnsweredBy.values()); } } + public enum ConnectivityIssue { UNKNOWN_CONNECTIVITY_ISSUE("unknown_connectivity_issue"), NO_CONNECTIVITY_ISSUE("no_connectivity_issue"), @@ -143,35 +147,18 @@ public static ConnectivityIssue forValue(final String value) { @JsonCreator private Annotation( - @JsonProperty("call_sid") - final String callSid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("answered_by") - final Annotation.AnsweredBy answeredBy, - - @JsonProperty("connectivity_issue") - final Annotation.ConnectivityIssue connectivityIssue, - - @JsonProperty("quality_issues") - final List qualityIssues, - - @JsonProperty("spam") - final Boolean spam, - - @JsonProperty("call_score") - final Integer callScore, - - @JsonProperty("comment") - final String comment, - - @JsonProperty("incident") - final String incident, - - @JsonProperty("url") - final URI url + @JsonProperty("call_sid") final String callSid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("answered_by") final Annotation.AnsweredBy answeredBy, + @JsonProperty( + "connectivity_issue" + ) final Annotation.ConnectivityIssue connectivityIssue, + @JsonProperty("quality_issues") final List qualityIssues, + @JsonProperty("spam") final Boolean spam, + @JsonProperty("call_score") final Integer callScore, + @JsonProperty("comment") final String comment, + @JsonProperty("incident") final String incident, + @JsonProperty("url") final URI url ) { this.callSid = callSid; this.accountSid = accountSid; @@ -185,40 +172,49 @@ private Annotation( this.url = url; } - public final String getCallSid() { - return this.callSid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final Annotation.AnsweredBy getAnsweredBy() { - return this.answeredBy; - } - public final Annotation.ConnectivityIssue getConnectivityIssue() { - return this.connectivityIssue; - } - public final List getQualityIssues() { - return this.qualityIssues; - } - public final Boolean getSpam() { - return this.spam; - } - public final Integer getCallScore() { - return this.callScore; - } - public final String getComment() { - return this.comment; - } - public final String getIncident() { - return this.incident; - } - public final URI getUrl() { - return this.url; - } + public final String getCallSid() { + return this.callSid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final Annotation.AnsweredBy getAnsweredBy() { + return this.answeredBy; + } + + public final Annotation.ConnectivityIssue getConnectivityIssue() { + return this.connectivityIssue; + } + + public final List getQualityIssues() { + return this.qualityIssues; + } + + public final Boolean getSpam() { + return this.spam; + } + + public final Integer getCallScore() { + return this.callScore; + } + + public final String getComment() { + return this.comment; + } + + public final String getIncident() { + return this.incident; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -228,13 +224,33 @@ public boolean equals(final Object o) { Annotation other = (Annotation) o; - return Objects.equals(callSid, other.callSid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(answeredBy, other.answeredBy) && Objects.equals(connectivityIssue, other.connectivityIssue) && Objects.equals(qualityIssues, other.qualityIssues) && Objects.equals(spam, other.spam) && Objects.equals(callScore, other.callScore) && Objects.equals(comment, other.comment) && Objects.equals(incident, other.incident) && Objects.equals(url, other.url) ; + return ( + Objects.equals(callSid, other.callSid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(answeredBy, other.answeredBy) && + Objects.equals(connectivityIssue, other.connectivityIssue) && + Objects.equals(qualityIssues, other.qualityIssues) && + Objects.equals(spam, other.spam) && + Objects.equals(callScore, other.callScore) && + Objects.equals(comment, other.comment) && + Objects.equals(incident, other.incident) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(callSid, accountSid, answeredBy, connectivityIssue, qualityIssues, spam, callScore, comment, incident, url); + return Objects.hash( + callSid, + accountSid, + answeredBy, + connectivityIssue, + qualityIssues, + spam, + callScore, + comment, + incident, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/insights/v1/call/AnnotationFetcher.java b/src/main/java/com/twilio/rest/insights/v1/call/AnnotationFetcher.java index 4387cb68f3..4012b5cba2 100644 --- a/src/main/java/com/twilio/rest/insights/v1/call/AnnotationFetcher.java +++ b/src/main/java/com/twilio/rest/insights/v1/call/AnnotationFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class AnnotationFetcher extends Fetcher { + private String pathCallSid; - public AnnotationFetcher(final String pathCallSid){ + public AnnotationFetcher(final String pathCallSid) { this.pathCallSid = pathCallSid; } - @Override public Annotation fetch(final TwilioRestClient client) { String path = "/v1/Voice/{CallSid}/Annotation"; - path = path.replace("{"+"CallSid"+"}", this.pathCallSid.toString()); + path = path.replace("{" + "CallSid" + "}", this.pathCallSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,15 +46,23 @@ public Annotation fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Annotation fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Annotation fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Annotation.fromJson(response.getStream(), client.getObjectMapper()); + return Annotation.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/insights/v1/call/AnnotationUpdater.java b/src/main/java/com/twilio/rest/insights/v1/call/AnnotationUpdater.java index 05b7e7d2a8..7ac1f6441f 100644 --- a/src/main/java/com/twilio/rest/insights/v1/call/AnnotationUpdater.java +++ b/src/main/java/com/twilio/rest/insights/v1/call/AnnotationUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.insights.v1.call; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class AnnotationUpdater extends Updater { - - -public class AnnotationUpdater extends Updater{ private String pathCallSid; private Annotation.AnsweredBy answeredBy; private Annotation.ConnectivityIssue connectivityIssue; @@ -37,92 +36,108 @@ public class AnnotationUpdater extends Updater{ private String comment; private String incident; - public AnnotationUpdater(final String pathCallSid){ + public AnnotationUpdater(final String pathCallSid) { this.pathCallSid = pathCallSid; } - public AnnotationUpdater setAnsweredBy(final Annotation.AnsweredBy answeredBy){ + public AnnotationUpdater setAnsweredBy( + final Annotation.AnsweredBy answeredBy + ) { this.answeredBy = answeredBy; return this; } - public AnnotationUpdater setConnectivityIssue(final Annotation.ConnectivityIssue connectivityIssue){ + + public AnnotationUpdater setConnectivityIssue( + final Annotation.ConnectivityIssue connectivityIssue + ) { this.connectivityIssue = connectivityIssue; return this; } - public AnnotationUpdater setQualityIssues(final String qualityIssues){ + + public AnnotationUpdater setQualityIssues(final String qualityIssues) { this.qualityIssues = qualityIssues; return this; } - public AnnotationUpdater setSpam(final Boolean spam){ + + public AnnotationUpdater setSpam(final Boolean spam) { this.spam = spam; return this; } - public AnnotationUpdater setCallScore(final Integer callScore){ + + public AnnotationUpdater setCallScore(final Integer callScore) { this.callScore = callScore; return this; } - public AnnotationUpdater setComment(final String comment){ + + public AnnotationUpdater setComment(final String comment) { this.comment = comment; return this; } - public AnnotationUpdater setIncident(final String incident){ + + public AnnotationUpdater setIncident(final String incident) { this.incident = incident; return this; } @Override - public Annotation update(final TwilioRestClient client){ + public Annotation update(final TwilioRestClient client) { String path = "/v1/Voice/{CallSid}/Annotation"; - path = path.replace("{"+"CallSid"+"}", this.pathCallSid.toString()); + path = path.replace("{" + "CallSid" + "}", this.pathCallSid.toString()); Request request = new Request( HttpMethod.POST, Domains.INSIGHTS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Annotation update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Annotation update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Annotation.fromJson(response.getStream(), client.getObjectMapper()); + return Annotation.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (answeredBy != null) { request.addPostParam("AnsweredBy", answeredBy.toString()); - } if (connectivityIssue != null) { - request.addPostParam("ConnectivityIssue", connectivityIssue.toString()); - + request.addPostParam( + "ConnectivityIssue", + connectivityIssue.toString() + ); } if (qualityIssues != null) { request.addPostParam("QualityIssues", qualityIssues); - } if (spam != null) { request.addPostParam("Spam", spam.toString()); - } if (callScore != null) { request.addPostParam("CallScore", callScore.toString()); - } if (comment != null) { request.addPostParam("Comment", comment); - } if (incident != null) { request.addPostParam("Incident", incident); - } } } diff --git a/src/main/java/com/twilio/rest/insights/v1/call/CallSummary.java b/src/main/java/com/twilio/rest/insights/v1/call/CallSummary.java index 35ae90539e..8cdf228141 100644 --- a/src/main/java/com/twilio/rest/insights/v1/call/CallSummary.java +++ b/src/main/java/com/twilio/rest/insights/v1/call/CallSummary.java @@ -24,40 +24,39 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.List; import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class CallSummary extends Resource { + private static final long serialVersionUID = 200007638188409L; - public static CallSummaryFetcher fetcher(final String pathCallSid){ + public static CallSummaryFetcher fetcher(final String pathCallSid) { return new CallSummaryFetcher(pathCallSid); } /** - * Converts a JSON String into a CallSummary object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return CallSummary object represented by the provided JSON - */ - public static CallSummary fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a CallSummary object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return CallSummary object represented by the provided JSON + */ + public static CallSummary fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, CallSummary.class); @@ -69,14 +68,17 @@ public static CallSummary fromJson(final String json, final ObjectMapper objectM } /** - * Converts a JSON InputStream into a CallSummary object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return CallSummary object represented by the provided JSON - */ - public static CallSummary fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a CallSummary object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return CallSummary object represented by the provided JSON + */ + public static CallSummary fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, CallSummary.class); @@ -86,6 +88,7 @@ public static CallSummary fromJson(final InputStream json, final ObjectMapper ob throw new ApiConnectionException(e.getMessage(), e); } } + public enum AnsweredBy { UNKNOWN("unknown"), MACHINE_START("machine_start"), @@ -110,6 +113,7 @@ public static AnsweredBy forValue(final String value) { return Promoter.enumFromString(value, AnsweredBy.values()); } } + public enum CallState { RINGING("ringing"), COMPLETED("completed"), @@ -135,6 +139,7 @@ public static CallState forValue(final String value) { return Promoter.enumFromString(value, CallState.values()); } } + public enum CallType { CARRIER("carrier"), SIP("sip"), @@ -156,6 +161,7 @@ public static CallType forValue(final String value) { return Promoter.enumFromString(value, CallType.values()); } } + public enum ProcessingState { COMPLETE("complete"), PARTIAL("partial"); @@ -202,74 +208,31 @@ public static ProcessingState forValue(final String value) { @JsonCreator private CallSummary( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("call_sid") - final String callSid, - - @JsonProperty("call_type") - final CallSummary.CallType callType, - - @JsonProperty("call_state") - final CallSummary.CallState callState, - - @JsonProperty("answered_by") - final CallSummary.AnsweredBy answeredBy, - - @JsonProperty("processing_state") - final CallSummary.ProcessingState processingState, - - @JsonProperty("created_time") - final String createdTime, - - @JsonProperty("start_time") - final String startTime, - - @JsonProperty("end_time") - final String endTime, - - @JsonProperty("duration") - final Integer duration, - - @JsonProperty("connect_duration") - final Integer connectDuration, - - @JsonProperty("from") - final Map from, - - @JsonProperty("to") - final Map to, - - @JsonProperty("carrier_edge") - final Map carrierEdge, - - @JsonProperty("client_edge") - final Map clientEdge, - - @JsonProperty("sdk_edge") - final Map sdkEdge, - - @JsonProperty("sip_edge") - final Map sipEdge, - - @JsonProperty("tags") - final List tags, - - @JsonProperty("url") - final URI url, - - @JsonProperty("attributes") - final Map attributes, - - @JsonProperty("properties") - final Map properties, - - @JsonProperty("trust") - final Map trust, - - @JsonProperty("annotation") - final Map annotation + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("call_sid") final String callSid, + @JsonProperty("call_type") final CallSummary.CallType callType, + @JsonProperty("call_state") final CallSummary.CallState callState, + @JsonProperty("answered_by") final CallSummary.AnsweredBy answeredBy, + @JsonProperty( + "processing_state" + ) final CallSummary.ProcessingState processingState, + @JsonProperty("created_time") final String createdTime, + @JsonProperty("start_time") final String startTime, + @JsonProperty("end_time") final String endTime, + @JsonProperty("duration") final Integer duration, + @JsonProperty("connect_duration") final Integer connectDuration, + @JsonProperty("from") final Map from, + @JsonProperty("to") final Map to, + @JsonProperty("carrier_edge") final Map carrierEdge, + @JsonProperty("client_edge") final Map clientEdge, + @JsonProperty("sdk_edge") final Map sdkEdge, + @JsonProperty("sip_edge") final Map sipEdge, + @JsonProperty("tags") final List tags, + @JsonProperty("url") final URI url, + @JsonProperty("attributes") final Map attributes, + @JsonProperty("properties") final Map properties, + @JsonProperty("trust") final Map trust, + @JsonProperty("annotation") final Map annotation ) { this.accountSid = accountSid; this.callSid = callSid; @@ -296,79 +259,101 @@ private CallSummary( this.annotation = annotation; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getCallSid() { - return this.callSid; - } - public final CallSummary.CallType getCallType() { - return this.callType; - } - public final CallSummary.CallState getCallState() { - return this.callState; - } - public final CallSummary.AnsweredBy getAnsweredBy() { - return this.answeredBy; - } - public final CallSummary.ProcessingState getProcessingState() { - return this.processingState; - } - public final ZonedDateTime getCreatedTime() { - return this.createdTime; - } - public final ZonedDateTime getStartTime() { - return this.startTime; - } - public final ZonedDateTime getEndTime() { - return this.endTime; - } - public final Integer getDuration() { - return this.duration; - } - public final Integer getConnectDuration() { - return this.connectDuration; - } - public final Map getFrom() { - return this.from; - } - public final Map getTo() { - return this.to; - } - public final Map getCarrierEdge() { - return this.carrierEdge; - } - public final Map getClientEdge() { - return this.clientEdge; - } - public final Map getSdkEdge() { - return this.sdkEdge; - } - public final Map getSipEdge() { - return this.sipEdge; - } - public final List getTags() { - return this.tags; - } - public final URI getUrl() { - return this.url; - } - public final Map getAttributes() { - return this.attributes; - } - public final Map getProperties() { - return this.properties; - } - public final Map getTrust() { - return this.trust; - } - public final Map getAnnotation() { - return this.annotation; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getCallSid() { + return this.callSid; + } + + public final CallSummary.CallType getCallType() { + return this.callType; + } + + public final CallSummary.CallState getCallState() { + return this.callState; + } + + public final CallSummary.AnsweredBy getAnsweredBy() { + return this.answeredBy; + } + + public final CallSummary.ProcessingState getProcessingState() { + return this.processingState; + } + + public final ZonedDateTime getCreatedTime() { + return this.createdTime; + } + + public final ZonedDateTime getStartTime() { + return this.startTime; + } + + public final ZonedDateTime getEndTime() { + return this.endTime; + } + + public final Integer getDuration() { + return this.duration; + } + + public final Integer getConnectDuration() { + return this.connectDuration; + } + + public final Map getFrom() { + return this.from; + } + + public final Map getTo() { + return this.to; + } + + public final Map getCarrierEdge() { + return this.carrierEdge; + } + + public final Map getClientEdge() { + return this.clientEdge; + } + + public final Map getSdkEdge() { + return this.sdkEdge; + } + + public final Map getSipEdge() { + return this.sipEdge; + } + + public final List getTags() { + return this.tags; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getAttributes() { + return this.attributes; + } + + public final Map getProperties() { + return this.properties; + } + + public final Map getTrust() { + return this.trust; + } + + public final Map getAnnotation() { + return this.annotation; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -378,13 +363,59 @@ public boolean equals(final Object o) { CallSummary other = (CallSummary) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(callSid, other.callSid) && Objects.equals(callType, other.callType) && Objects.equals(callState, other.callState) && Objects.equals(answeredBy, other.answeredBy) && Objects.equals(processingState, other.processingState) && Objects.equals(createdTime, other.createdTime) && Objects.equals(startTime, other.startTime) && Objects.equals(endTime, other.endTime) && Objects.equals(duration, other.duration) && Objects.equals(connectDuration, other.connectDuration) && Objects.equals(from, other.from) && Objects.equals(to, other.to) && Objects.equals(carrierEdge, other.carrierEdge) && Objects.equals(clientEdge, other.clientEdge) && Objects.equals(sdkEdge, other.sdkEdge) && Objects.equals(sipEdge, other.sipEdge) && Objects.equals(tags, other.tags) && Objects.equals(url, other.url) && Objects.equals(attributes, other.attributes) && Objects.equals(properties, other.properties) && Objects.equals(trust, other.trust) && Objects.equals(annotation, other.annotation) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(callSid, other.callSid) && + Objects.equals(callType, other.callType) && + Objects.equals(callState, other.callState) && + Objects.equals(answeredBy, other.answeredBy) && + Objects.equals(processingState, other.processingState) && + Objects.equals(createdTime, other.createdTime) && + Objects.equals(startTime, other.startTime) && + Objects.equals(endTime, other.endTime) && + Objects.equals(duration, other.duration) && + Objects.equals(connectDuration, other.connectDuration) && + Objects.equals(from, other.from) && + Objects.equals(to, other.to) && + Objects.equals(carrierEdge, other.carrierEdge) && + Objects.equals(clientEdge, other.clientEdge) && + Objects.equals(sdkEdge, other.sdkEdge) && + Objects.equals(sipEdge, other.sipEdge) && + Objects.equals(tags, other.tags) && + Objects.equals(url, other.url) && + Objects.equals(attributes, other.attributes) && + Objects.equals(properties, other.properties) && + Objects.equals(trust, other.trust) && + Objects.equals(annotation, other.annotation) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, callSid, callType, callState, answeredBy, processingState, createdTime, startTime, endTime, duration, connectDuration, from, to, carrierEdge, clientEdge, sdkEdge, sipEdge, tags, url, attributes, properties, trust, annotation); + return Objects.hash( + accountSid, + callSid, + callType, + callState, + answeredBy, + processingState, + createdTime, + startTime, + endTime, + duration, + connectDuration, + from, + to, + carrierEdge, + clientEdge, + sdkEdge, + sipEdge, + tags, + url, + attributes, + properties, + trust, + annotation + ); } - } - diff --git a/src/main/java/com/twilio/rest/insights/v1/call/CallSummaryFetcher.java b/src/main/java/com/twilio/rest/insights/v1/call/CallSummaryFetcher.java index 0961f602cf..8e90ec8801 100644 --- a/src/main/java/com/twilio/rest/insights/v1/call/CallSummaryFetcher.java +++ b/src/main/java/com/twilio/rest/insights/v1/call/CallSummaryFetcher.java @@ -24,18 +24,18 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class CallSummaryFetcher extends Fetcher { + private String pathCallSid; private CallSummary.ProcessingState processingState; - public CallSummaryFetcher(final String pathCallSid){ + public CallSummaryFetcher(final String pathCallSid) { this.pathCallSid = pathCallSid; } - public CallSummaryFetcher setProcessingState(final CallSummary.ProcessingState processingState){ + public CallSummaryFetcher setProcessingState( + final CallSummary.ProcessingState processingState + ) { this.processingState = processingState; return this; } @@ -44,7 +44,7 @@ public CallSummaryFetcher setProcessingState(final CallSummary.ProcessingState p public CallSummary fetch(final TwilioRestClient client) { String path = "/v1/Voice/{CallSid}/Summary"; - path = path.replace("{"+"CallSid"+"}", this.pathCallSid.toString()); + path = path.replace("{" + "CallSid" + "}", this.pathCallSid.toString()); Request request = new Request( HttpMethod.GET, @@ -55,21 +55,32 @@ public CallSummary fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("CallSummary fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "CallSummary fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return CallSummary.fromJson(response.getStream(), client.getObjectMapper()); + return CallSummary.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addQueryParams(final Request request) { if (processingState != null) { - - request.addQueryParam("ProcessingState", processingState.toString()); + request.addQueryParam( + "ProcessingState", + processingState.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/insights/v1/call/Event.java b/src/main/java/com/twilio/rest/insights/v1/call/Event.java index ee84a803ed..b36f2f55d9 100644 --- a/src/main/java/com/twilio/rest/insights/v1/call/Event.java +++ b/src/main/java/com/twilio/rest/insights/v1/call/Event.java @@ -23,37 +23,36 @@ import com.twilio.base.Resource; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Event extends Resource { + private static final long serialVersionUID = 246803433322501L; - public static EventReader reader(final String pathCallSid){ + public static EventReader reader(final String pathCallSid) { return new EventReader(pathCallSid); } /** - * Converts a JSON String into a Event object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Event object represented by the provided JSON - */ - public static Event fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Event object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Event object represented by the provided JSON + */ + public static Event fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Event.class); @@ -65,14 +64,17 @@ public static Event fromJson(final String json, final ObjectMapper objectMapper) } /** - * Converts a JSON InputStream into a Event object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Event object represented by the provided JSON - */ - public static Event fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Event object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Event object represented by the provided JSON + */ + public static Event fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Event.class); @@ -82,6 +84,7 @@ public static Event fromJson(final InputStream json, final ObjectMapper objectMa throw new ApiConnectionException(e.getMessage(), e); } } + public enum Level { UNKNOWN("UNKNOWN"), DEBUG("DEBUG"), @@ -104,6 +107,7 @@ public static Level forValue(final String value) { return Promoter.enumFromString(value, Level.values()); } } + public enum TwilioEdge { UNKNOWN_EDGE("unknown_edge"), CARRIER_EDGE("carrier_edge"), @@ -141,38 +145,17 @@ public static TwilioEdge forValue(final String value) { @JsonCreator private Event( - @JsonProperty("timestamp") - final String timestamp, - - @JsonProperty("call_sid") - final String callSid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("edge") - final Event.TwilioEdge edge, - - @JsonProperty("group") - final String group, - - @JsonProperty("level") - final Event.Level level, - - @JsonProperty("name") - final String name, - - @JsonProperty("carrier_edge") - final Map carrierEdge, - - @JsonProperty("sip_edge") - final Map sipEdge, - - @JsonProperty("sdk_edge") - final Map sdkEdge, - - @JsonProperty("client_edge") - final Map clientEdge + @JsonProperty("timestamp") final String timestamp, + @JsonProperty("call_sid") final String callSid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("edge") final Event.TwilioEdge edge, + @JsonProperty("group") final String group, + @JsonProperty("level") final Event.Level level, + @JsonProperty("name") final String name, + @JsonProperty("carrier_edge") final Map carrierEdge, + @JsonProperty("sip_edge") final Map sipEdge, + @JsonProperty("sdk_edge") final Map sdkEdge, + @JsonProperty("client_edge") final Map clientEdge ) { this.timestamp = timestamp; this.callSid = callSid; @@ -187,43 +170,53 @@ private Event( this.clientEdge = clientEdge; } - public final String getTimestamp() { - return this.timestamp; - } - public final String getCallSid() { - return this.callSid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final Event.TwilioEdge getEdge() { - return this.edge; - } - public final String getGroup() { - return this.group; - } - public final Event.Level getLevel() { - return this.level; - } - public final String getName() { - return this.name; - } - public final Map getCarrierEdge() { - return this.carrierEdge; - } - public final Map getSipEdge() { - return this.sipEdge; - } - public final Map getSdkEdge() { - return this.sdkEdge; - } - public final Map getClientEdge() { - return this.clientEdge; - } + public final String getTimestamp() { + return this.timestamp; + } + + public final String getCallSid() { + return this.callSid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final Event.TwilioEdge getEdge() { + return this.edge; + } + + public final String getGroup() { + return this.group; + } + + public final Event.Level getLevel() { + return this.level; + } + + public final String getName() { + return this.name; + } + + public final Map getCarrierEdge() { + return this.carrierEdge; + } + + public final Map getSipEdge() { + return this.sipEdge; + } + + public final Map getSdkEdge() { + return this.sdkEdge; + } + + public final Map getClientEdge() { + return this.clientEdge; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -233,13 +226,35 @@ public boolean equals(final Object o) { Event other = (Event) o; - return Objects.equals(timestamp, other.timestamp) && Objects.equals(callSid, other.callSid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(edge, other.edge) && Objects.equals(group, other.group) && Objects.equals(level, other.level) && Objects.equals(name, other.name) && Objects.equals(carrierEdge, other.carrierEdge) && Objects.equals(sipEdge, other.sipEdge) && Objects.equals(sdkEdge, other.sdkEdge) && Objects.equals(clientEdge, other.clientEdge) ; + return ( + Objects.equals(timestamp, other.timestamp) && + Objects.equals(callSid, other.callSid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(edge, other.edge) && + Objects.equals(group, other.group) && + Objects.equals(level, other.level) && + Objects.equals(name, other.name) && + Objects.equals(carrierEdge, other.carrierEdge) && + Objects.equals(sipEdge, other.sipEdge) && + Objects.equals(sdkEdge, other.sdkEdge) && + Objects.equals(clientEdge, other.clientEdge) + ); } @Override public int hashCode() { - return Objects.hash(timestamp, callSid, accountSid, edge, group, level, name, carrierEdge, sipEdge, sdkEdge, clientEdge); + return Objects.hash( + timestamp, + callSid, + accountSid, + edge, + group, + level, + name, + carrierEdge, + sipEdge, + sdkEdge, + clientEdge + ); } - } - diff --git a/src/main/java/com/twilio/rest/insights/v1/call/EventReader.java b/src/main/java/com/twilio/rest/insights/v1/call/EventReader.java index 950f7724ba..a4cb6f1a95 100644 --- a/src/main/java/com/twilio/rest/insights/v1/call/EventReader.java +++ b/src/main/java/com/twilio/rest/insights/v1/call/EventReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.insights.v1.call; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,24 +25,23 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class EventReader extends Reader { + private String pathCallSid; private Event.TwilioEdge edge; private Integer pageSize; - public EventReader(final String pathCallSid){ + public EventReader(final String pathCallSid) { this.pathCallSid = pathCallSid; } - public EventReader setEdge(final Event.TwilioEdge edge){ + public EventReader setEdge(final Event.TwilioEdge edge) { this.edge = edge; return this; } - public EventReader setPageSize(final Integer pageSize){ + + public EventReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -53,7 +53,7 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Voice/{CallSid}/Events"; - path = path.replace("{"+"CallSid"+"}", this.pathCallSid.toString()); + path = path.replace("{" + "CallSid" + "}", this.pathCallSid.toString()); Request request = new Request( HttpMethod.GET, @@ -65,13 +65,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Event read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Event read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -87,7 +95,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.INSIGHTS.toString()) @@ -95,9 +106,11 @@ public Page previousPage(final Page page, final TwilioRestClient c return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.INSIGHTS.toString()) @@ -106,25 +119,24 @@ public Page nextPage(final Page page, final TwilioRestClient clien } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (edge != null) { - request.addQueryParam("Edge", edge.toString()); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/insights/v1/call/Metric.java b/src/main/java/com/twilio/rest/insights/v1/call/Metric.java index e2ce338562..35189688f3 100644 --- a/src/main/java/com/twilio/rest/insights/v1/call/Metric.java +++ b/src/main/java/com/twilio/rest/insights/v1/call/Metric.java @@ -23,37 +23,36 @@ import com.twilio.base.Resource; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Metric extends Resource { + private static final long serialVersionUID = 250651350148240L; - public static MetricReader reader(final String pathCallSid){ + public static MetricReader reader(final String pathCallSid) { return new MetricReader(pathCallSid); } /** - * Converts a JSON String into a Metric object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Metric object represented by the provided JSON - */ - public static Metric fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Metric object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Metric object represented by the provided JSON + */ + public static Metric fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Metric.class); @@ -65,14 +64,17 @@ public static Metric fromJson(final String json, final ObjectMapper objectMapper } /** - * Converts a JSON InputStream into a Metric object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Metric object represented by the provided JSON - */ - public static Metric fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Metric object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Metric object represented by the provided JSON + */ + public static Metric fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Metric.class); @@ -82,6 +84,7 @@ public static Metric fromJson(final InputStream json, final ObjectMapper objectM throw new ApiConnectionException(e.getMessage(), e); } } + public enum StreamDirection { UNKNOWN("unknown"), INBOUND("inbound"), @@ -103,6 +106,7 @@ public static StreamDirection forValue(final String value) { return Promoter.enumFromString(value, StreamDirection.values()); } } + public enum TwilioEdge { UNKNOWN_EDGE("unknown_edge"), CARRIER_EDGE("carrier_edge"), @@ -138,32 +142,15 @@ public static TwilioEdge forValue(final String value) { @JsonCreator private Metric( - @JsonProperty("timestamp") - final String timestamp, - - @JsonProperty("call_sid") - final String callSid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("edge") - final Metric.TwilioEdge edge, - - @JsonProperty("direction") - final Metric.StreamDirection direction, - - @JsonProperty("carrier_edge") - final Map carrierEdge, - - @JsonProperty("sip_edge") - final Map sipEdge, - - @JsonProperty("sdk_edge") - final Map sdkEdge, - - @JsonProperty("client_edge") - final Map clientEdge + @JsonProperty("timestamp") final String timestamp, + @JsonProperty("call_sid") final String callSid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("edge") final Metric.TwilioEdge edge, + @JsonProperty("direction") final Metric.StreamDirection direction, + @JsonProperty("carrier_edge") final Map carrierEdge, + @JsonProperty("sip_edge") final Map sipEdge, + @JsonProperty("sdk_edge") final Map sdkEdge, + @JsonProperty("client_edge") final Map clientEdge ) { this.timestamp = timestamp; this.callSid = callSid; @@ -176,37 +163,45 @@ private Metric( this.clientEdge = clientEdge; } - public final String getTimestamp() { - return this.timestamp; - } - public final String getCallSid() { - return this.callSid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final Metric.TwilioEdge getEdge() { - return this.edge; - } - public final Metric.StreamDirection getDirection() { - return this.direction; - } - public final Map getCarrierEdge() { - return this.carrierEdge; - } - public final Map getSipEdge() { - return this.sipEdge; - } - public final Map getSdkEdge() { - return this.sdkEdge; - } - public final Map getClientEdge() { - return this.clientEdge; - } + public final String getTimestamp() { + return this.timestamp; + } + + public final String getCallSid() { + return this.callSid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final Metric.TwilioEdge getEdge() { + return this.edge; + } + + public final Metric.StreamDirection getDirection() { + return this.direction; + } + + public final Map getCarrierEdge() { + return this.carrierEdge; + } + + public final Map getSipEdge() { + return this.sipEdge; + } + + public final Map getSdkEdge() { + return this.sdkEdge; + } + + public final Map getClientEdge() { + return this.clientEdge; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -216,13 +211,31 @@ public boolean equals(final Object o) { Metric other = (Metric) o; - return Objects.equals(timestamp, other.timestamp) && Objects.equals(callSid, other.callSid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(edge, other.edge) && Objects.equals(direction, other.direction) && Objects.equals(carrierEdge, other.carrierEdge) && Objects.equals(sipEdge, other.sipEdge) && Objects.equals(sdkEdge, other.sdkEdge) && Objects.equals(clientEdge, other.clientEdge) ; + return ( + Objects.equals(timestamp, other.timestamp) && + Objects.equals(callSid, other.callSid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(edge, other.edge) && + Objects.equals(direction, other.direction) && + Objects.equals(carrierEdge, other.carrierEdge) && + Objects.equals(sipEdge, other.sipEdge) && + Objects.equals(sdkEdge, other.sdkEdge) && + Objects.equals(clientEdge, other.clientEdge) + ); } @Override public int hashCode() { - return Objects.hash(timestamp, callSid, accountSid, edge, direction, carrierEdge, sipEdge, sdkEdge, clientEdge); + return Objects.hash( + timestamp, + callSid, + accountSid, + edge, + direction, + carrierEdge, + sipEdge, + sdkEdge, + clientEdge + ); } - } - diff --git a/src/main/java/com/twilio/rest/insights/v1/call/MetricReader.java b/src/main/java/com/twilio/rest/insights/v1/call/MetricReader.java index b3f629aeb0..0e0debec29 100644 --- a/src/main/java/com/twilio/rest/insights/v1/call/MetricReader.java +++ b/src/main/java/com/twilio/rest/insights/v1/call/MetricReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.insights.v1.call; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,29 +25,29 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class MetricReader extends Reader { + private String pathCallSid; private Metric.TwilioEdge edge; private Metric.StreamDirection direction; private Integer pageSize; - public MetricReader(final String pathCallSid){ + public MetricReader(final String pathCallSid) { this.pathCallSid = pathCallSid; } - public MetricReader setEdge(final Metric.TwilioEdge edge){ + public MetricReader setEdge(final Metric.TwilioEdge edge) { this.edge = edge; return this; } - public MetricReader setDirection(final Metric.StreamDirection direction){ + + public MetricReader setDirection(final Metric.StreamDirection direction) { this.direction = direction; return this; } - public MetricReader setPageSize(final Integer pageSize){ + + public MetricReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -58,7 +59,7 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Voice/{CallSid}/Metrics"; - path = path.replace("{"+"CallSid"+"}", this.pathCallSid.toString()); + path = path.replace("{" + "CallSid" + "}", this.pathCallSid.toString()); Request request = new Request( HttpMethod.GET, @@ -70,13 +71,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Metric read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Metric read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -92,7 +101,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.INSIGHTS.toString()) @@ -100,9 +112,11 @@ public Page previousPage(final Page page, final TwilioRestClient return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.INSIGHTS.toString()) @@ -111,29 +125,27 @@ public Page nextPage(final Page page, final TwilioRestClient cli } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (edge != null) { - request.addQueryParam("Edge", edge.toString()); } if (direction != null) { - request.addQueryParam("Direction", direction.toString()); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/insights/v1/conference/ConferenceParticipant.java b/src/main/java/com/twilio/rest/insights/v1/conference/ConferenceParticipant.java index 1cbfbedd98..a84faa326f 100644 --- a/src/main/java/com/twilio/rest/insights/v1/conference/ConferenceParticipant.java +++ b/src/main/java/com/twilio/rest/insights/v1/conference/ConferenceParticipant.java @@ -24,44 +24,51 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.List; import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class ConferenceParticipant extends Resource { + private static final long serialVersionUID = 67216866718855L; - public static ConferenceParticipantFetcher fetcher(final String pathConferenceSid, final String pathParticipantSid){ - return new ConferenceParticipantFetcher(pathConferenceSid, pathParticipantSid); + public static ConferenceParticipantFetcher fetcher( + final String pathConferenceSid, + final String pathParticipantSid + ) { + return new ConferenceParticipantFetcher( + pathConferenceSid, + pathParticipantSid + ); } - public static ConferenceParticipantReader reader(final String pathConferenceSid){ + public static ConferenceParticipantReader reader( + final String pathConferenceSid + ) { return new ConferenceParticipantReader(pathConferenceSid); } /** - * Converts a JSON String into a ConferenceParticipant object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return ConferenceParticipant object represented by the provided JSON - */ - public static ConferenceParticipant fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a ConferenceParticipant object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return ConferenceParticipant object represented by the provided JSON + */ + public static ConferenceParticipant fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, ConferenceParticipant.class); @@ -73,14 +80,17 @@ public static ConferenceParticipant fromJson(final String json, final ObjectMapp } /** - * Converts a JSON InputStream into a ConferenceParticipant object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return ConferenceParticipant object represented by the provided JSON - */ - public static ConferenceParticipant fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a ConferenceParticipant object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return ConferenceParticipant object represented by the provided JSON + */ + public static ConferenceParticipant fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, ConferenceParticipant.class); @@ -90,6 +100,7 @@ public static ConferenceParticipant fromJson(final InputStream json, final Objec throw new ApiConnectionException(e.getMessage(), e); } } + public enum CallDirection { INBOUND("inbound"), OUTBOUND("outbound"); @@ -109,6 +120,7 @@ public static CallDirection forValue(final String value) { return Promoter.enumFromString(value, CallDirection.values()); } } + public enum CallStatus { ANSWERED("answered"), COMPLETED("completed"), @@ -133,6 +145,7 @@ public static CallStatus forValue(final String value) { return Promoter.enumFromString(value, CallStatus.values()); } } + public enum CallType { CARRIER("carrier"), CLIENT("client"), @@ -153,6 +166,7 @@ public static CallType forValue(final String value) { return Promoter.enumFromString(value, CallType.values()); } } + public enum JitterBufferSize { LARGE("large"), SMALL("small"), @@ -174,6 +188,7 @@ public static JitterBufferSize forValue(final String value) { return Promoter.enumFromString(value, JitterBufferSize.values()); } } + public enum ProcessingState { COMPLETE("complete"), IN_PROGRESS("in_progress"), @@ -194,6 +209,7 @@ public static ProcessingState forValue(final String value) { return Promoter.enumFromString(value, ProcessingState.values()); } } + public enum Region { US1("us1"), US2("us2"), @@ -250,86 +266,53 @@ public static Region forValue(final String value) { @JsonCreator private ConferenceParticipant( - @JsonProperty("participant_sid") - final String participantSid, - - @JsonProperty("label") - final String label, - - @JsonProperty("conference_sid") - final String conferenceSid, - - @JsonProperty("call_sid") - final String callSid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("call_direction") - final ConferenceParticipant.CallDirection callDirection, - - @JsonProperty("from") - final String from, - - @JsonProperty("to") - final String to, - - @JsonProperty("call_status") - final ConferenceParticipant.CallStatus callStatus, - - @JsonProperty("country_code") - final String countryCode, - - @JsonProperty("is_moderator") - final Boolean isModerator, - - @JsonProperty("join_time") - final String joinTime, - - @JsonProperty("leave_time") - final String leaveTime, - - @JsonProperty("duration_seconds") - final Integer durationSeconds, - - @JsonProperty("outbound_queue_length") - final Integer outboundQueueLength, - - @JsonProperty("outbound_time_in_queue") - final Integer outboundTimeInQueue, - - @JsonProperty("jitter_buffer_size") - final ConferenceParticipant.JitterBufferSize jitterBufferSize, - - @JsonProperty("is_coach") - final Boolean isCoach, - - @JsonProperty("coached_participants") - final List coachedParticipants, - - @JsonProperty("participant_region") - final ConferenceParticipant.Region participantRegion, - - @JsonProperty("conference_region") - final ConferenceParticipant.Region conferenceRegion, - - @JsonProperty("call_type") - final ConferenceParticipant.CallType callType, - - @JsonProperty("processing_state") - final ConferenceParticipant.ProcessingState processingState, - - @JsonProperty("properties") - final Map properties, - - @JsonProperty("events") - final Map events, - - @JsonProperty("metrics") - final Map metrics, - - @JsonProperty("url") - final URI url + @JsonProperty("participant_sid") final String participantSid, + @JsonProperty("label") final String label, + @JsonProperty("conference_sid") final String conferenceSid, + @JsonProperty("call_sid") final String callSid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty( + "call_direction" + ) final ConferenceParticipant.CallDirection callDirection, + @JsonProperty("from") final String from, + @JsonProperty("to") final String to, + @JsonProperty( + "call_status" + ) final ConferenceParticipant.CallStatus callStatus, + @JsonProperty("country_code") final String countryCode, + @JsonProperty("is_moderator") final Boolean isModerator, + @JsonProperty("join_time") final String joinTime, + @JsonProperty("leave_time") final String leaveTime, + @JsonProperty("duration_seconds") final Integer durationSeconds, + @JsonProperty( + "outbound_queue_length" + ) final Integer outboundQueueLength, + @JsonProperty( + "outbound_time_in_queue" + ) final Integer outboundTimeInQueue, + @JsonProperty( + "jitter_buffer_size" + ) final ConferenceParticipant.JitterBufferSize jitterBufferSize, + @JsonProperty("is_coach") final Boolean isCoach, + @JsonProperty( + "coached_participants" + ) final List coachedParticipants, + @JsonProperty( + "participant_region" + ) final ConferenceParticipant.Region participantRegion, + @JsonProperty( + "conference_region" + ) final ConferenceParticipant.Region conferenceRegion, + @JsonProperty( + "call_type" + ) final ConferenceParticipant.CallType callType, + @JsonProperty( + "processing_state" + ) final ConferenceParticipant.ProcessingState processingState, + @JsonProperty("properties") final Map properties, + @JsonProperty("events") final Map events, + @JsonProperty("metrics") final Map metrics, + @JsonProperty("url") final URI url ) { this.participantSid = participantSid; this.label = label; @@ -360,91 +343,117 @@ private ConferenceParticipant( this.url = url; } - public final String getParticipantSid() { - return this.participantSid; - } - public final String getLabel() { - return this.label; - } - public final String getConferenceSid() { - return this.conferenceSid; - } - public final String getCallSid() { - return this.callSid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final ConferenceParticipant.CallDirection getCallDirection() { - return this.callDirection; - } - public final String getFrom() { - return this.from; - } - public final String getTo() { - return this.to; - } - public final ConferenceParticipant.CallStatus getCallStatus() { - return this.callStatus; - } - public final String getCountryCode() { - return this.countryCode; - } - public final Boolean getIsModerator() { - return this.isModerator; - } - public final ZonedDateTime getJoinTime() { - return this.joinTime; - } - public final ZonedDateTime getLeaveTime() { - return this.leaveTime; - } - public final Integer getDurationSeconds() { - return this.durationSeconds; - } - public final Integer getOutboundQueueLength() { - return this.outboundQueueLength; - } - public final Integer getOutboundTimeInQueue() { - return this.outboundTimeInQueue; - } - public final ConferenceParticipant.JitterBufferSize getJitterBufferSize() { - return this.jitterBufferSize; - } - public final Boolean getIsCoach() { - return this.isCoach; - } - public final List getCoachedParticipants() { - return this.coachedParticipants; - } - public final ConferenceParticipant.Region getParticipantRegion() { - return this.participantRegion; - } - public final ConferenceParticipant.Region getConferenceRegion() { - return this.conferenceRegion; - } - public final ConferenceParticipant.CallType getCallType() { - return this.callType; - } - public final ConferenceParticipant.ProcessingState getProcessingState() { - return this.processingState; - } - public final Map getProperties() { - return this.properties; - } - public final Map getEvents() { - return this.events; - } - public final Map getMetrics() { - return this.metrics; - } - public final URI getUrl() { - return this.url; - } + public final String getParticipantSid() { + return this.participantSid; + } + + public final String getLabel() { + return this.label; + } + + public final String getConferenceSid() { + return this.conferenceSid; + } + + public final String getCallSid() { + return this.callSid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final ConferenceParticipant.CallDirection getCallDirection() { + return this.callDirection; + } + + public final String getFrom() { + return this.from; + } + + public final String getTo() { + return this.to; + } + + public final ConferenceParticipant.CallStatus getCallStatus() { + return this.callStatus; + } + + public final String getCountryCode() { + return this.countryCode; + } + + public final Boolean getIsModerator() { + return this.isModerator; + } + + public final ZonedDateTime getJoinTime() { + return this.joinTime; + } + + public final ZonedDateTime getLeaveTime() { + return this.leaveTime; + } + + public final Integer getDurationSeconds() { + return this.durationSeconds; + } + + public final Integer getOutboundQueueLength() { + return this.outboundQueueLength; + } + + public final Integer getOutboundTimeInQueue() { + return this.outboundTimeInQueue; + } + + public final ConferenceParticipant.JitterBufferSize getJitterBufferSize() { + return this.jitterBufferSize; + } + + public final Boolean getIsCoach() { + return this.isCoach; + } + + public final List getCoachedParticipants() { + return this.coachedParticipants; + } + + public final ConferenceParticipant.Region getParticipantRegion() { + return this.participantRegion; + } + + public final ConferenceParticipant.Region getConferenceRegion() { + return this.conferenceRegion; + } + + public final ConferenceParticipant.CallType getCallType() { + return this.callType; + } + + public final ConferenceParticipant.ProcessingState getProcessingState() { + return this.processingState; + } + + public final Map getProperties() { + return this.properties; + } + + public final Map getEvents() { + return this.events; + } + + public final Map getMetrics() { + return this.metrics; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -454,13 +463,67 @@ public boolean equals(final Object o) { ConferenceParticipant other = (ConferenceParticipant) o; - return Objects.equals(participantSid, other.participantSid) && Objects.equals(label, other.label) && Objects.equals(conferenceSid, other.conferenceSid) && Objects.equals(callSid, other.callSid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(callDirection, other.callDirection) && Objects.equals(from, other.from) && Objects.equals(to, other.to) && Objects.equals(callStatus, other.callStatus) && Objects.equals(countryCode, other.countryCode) && Objects.equals(isModerator, other.isModerator) && Objects.equals(joinTime, other.joinTime) && Objects.equals(leaveTime, other.leaveTime) && Objects.equals(durationSeconds, other.durationSeconds) && Objects.equals(outboundQueueLength, other.outboundQueueLength) && Objects.equals(outboundTimeInQueue, other.outboundTimeInQueue) && Objects.equals(jitterBufferSize, other.jitterBufferSize) && Objects.equals(isCoach, other.isCoach) && Objects.equals(coachedParticipants, other.coachedParticipants) && Objects.equals(participantRegion, other.participantRegion) && Objects.equals(conferenceRegion, other.conferenceRegion) && Objects.equals(callType, other.callType) && Objects.equals(processingState, other.processingState) && Objects.equals(properties, other.properties) && Objects.equals(events, other.events) && Objects.equals(metrics, other.metrics) && Objects.equals(url, other.url) ; + return ( + Objects.equals(participantSid, other.participantSid) && + Objects.equals(label, other.label) && + Objects.equals(conferenceSid, other.conferenceSid) && + Objects.equals(callSid, other.callSid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(callDirection, other.callDirection) && + Objects.equals(from, other.from) && + Objects.equals(to, other.to) && + Objects.equals(callStatus, other.callStatus) && + Objects.equals(countryCode, other.countryCode) && + Objects.equals(isModerator, other.isModerator) && + Objects.equals(joinTime, other.joinTime) && + Objects.equals(leaveTime, other.leaveTime) && + Objects.equals(durationSeconds, other.durationSeconds) && + Objects.equals(outboundQueueLength, other.outboundQueueLength) && + Objects.equals(outboundTimeInQueue, other.outboundTimeInQueue) && + Objects.equals(jitterBufferSize, other.jitterBufferSize) && + Objects.equals(isCoach, other.isCoach) && + Objects.equals(coachedParticipants, other.coachedParticipants) && + Objects.equals(participantRegion, other.participantRegion) && + Objects.equals(conferenceRegion, other.conferenceRegion) && + Objects.equals(callType, other.callType) && + Objects.equals(processingState, other.processingState) && + Objects.equals(properties, other.properties) && + Objects.equals(events, other.events) && + Objects.equals(metrics, other.metrics) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(participantSid, label, conferenceSid, callSid, accountSid, callDirection, from, to, callStatus, countryCode, isModerator, joinTime, leaveTime, durationSeconds, outboundQueueLength, outboundTimeInQueue, jitterBufferSize, isCoach, coachedParticipants, participantRegion, conferenceRegion, callType, processingState, properties, events, metrics, url); + return Objects.hash( + participantSid, + label, + conferenceSid, + callSid, + accountSid, + callDirection, + from, + to, + callStatus, + countryCode, + isModerator, + joinTime, + leaveTime, + durationSeconds, + outboundQueueLength, + outboundTimeInQueue, + jitterBufferSize, + isCoach, + coachedParticipants, + participantRegion, + conferenceRegion, + callType, + processingState, + properties, + events, + metrics, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/insights/v1/conference/ConferenceParticipantFetcher.java b/src/main/java/com/twilio/rest/insights/v1/conference/ConferenceParticipantFetcher.java index 098528f8a3..aa7e28ce36 100644 --- a/src/main/java/com/twilio/rest/insights/v1/conference/ConferenceParticipantFetcher.java +++ b/src/main/java/com/twilio/rest/insights/v1/conference/ConferenceParticipantFetcher.java @@ -24,35 +24,47 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class ConferenceParticipantFetcher + extends Fetcher { - - -public class ConferenceParticipantFetcher extends Fetcher { private String pathConferenceSid; private String pathParticipantSid; private String events; private String metrics; - public ConferenceParticipantFetcher(final String pathConferenceSid, final String pathParticipantSid){ + public ConferenceParticipantFetcher( + final String pathConferenceSid, + final String pathParticipantSid + ) { this.pathConferenceSid = pathConferenceSid; this.pathParticipantSid = pathParticipantSid; } - public ConferenceParticipantFetcher setEvents(final String events){ + public ConferenceParticipantFetcher setEvents(final String events) { this.events = events; return this; } - public ConferenceParticipantFetcher setMetrics(final String metrics){ + + public ConferenceParticipantFetcher setMetrics(final String metrics) { this.metrics = metrics; return this; } @Override public ConferenceParticipant fetch(final TwilioRestClient client) { - String path = "/v1/Conferences/{ConferenceSid}/Participants/{ParticipantSid}"; + String path = + "/v1/Conferences/{ConferenceSid}/Participants/{ParticipantSid}"; - path = path.replace("{"+"ConferenceSid"+"}", this.pathConferenceSid.toString()); - path = path.replace("{"+"ParticipantSid"+"}", this.pathParticipantSid.toString()); + path = + path.replace( + "{" + "ConferenceSid" + "}", + this.pathConferenceSid.toString() + ); + path = + path.replace( + "{" + "ParticipantSid" + "}", + this.pathParticipantSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -63,24 +75,31 @@ public ConferenceParticipant fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("ConferenceParticipant fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "ConferenceParticipant fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return ConferenceParticipant.fromJson(response.getStream(), client.getObjectMapper()); + return ConferenceParticipant.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addQueryParams(final Request request) { if (events != null) { - request.addQueryParam("Events", events); } if (metrics != null) { - request.addQueryParam("Metrics", metrics); } } diff --git a/src/main/java/com/twilio/rest/insights/v1/conference/ConferenceParticipantReader.java b/src/main/java/com/twilio/rest/insights/v1/conference/ConferenceParticipantReader.java index 863e8ec261..dd6735e84a 100644 --- a/src/main/java/com/twilio/rest/insights/v1/conference/ConferenceParticipantReader.java +++ b/src/main/java/com/twilio/rest/insights/v1/conference/ConferenceParticipantReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.insights.v1.conference; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,46 +25,57 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class ConferenceParticipantReader extends Reader { + private String pathConferenceSid; private String participantSid; private String label; private String events; private Integer pageSize; - public ConferenceParticipantReader(final String pathConferenceSid){ + public ConferenceParticipantReader(final String pathConferenceSid) { this.pathConferenceSid = pathConferenceSid; } - public ConferenceParticipantReader setParticipantSid(final String participantSid){ + public ConferenceParticipantReader setParticipantSid( + final String participantSid + ) { this.participantSid = participantSid; return this; } - public ConferenceParticipantReader setLabel(final String label){ + + public ConferenceParticipantReader setLabel(final String label) { this.label = label; return this; } - public ConferenceParticipantReader setEvents(final String events){ + + public ConferenceParticipantReader setEvents(final String events) { this.events = events; return this; } - public ConferenceParticipantReader setPageSize(final Integer pageSize){ + + public ConferenceParticipantReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @Override - public ResourceSet read(final TwilioRestClient client) { + public ResourceSet read( + final TwilioRestClient client + ) { return new ResourceSet<>(this, client, firstPage(client)); } - public Page firstPage(final TwilioRestClient client) { + public Page firstPage( + final TwilioRestClient client + ) { String path = "/v1/Conferences/{ConferenceSid}/Participants"; - path = path.replace("{"+"ConferenceSid"+"}", this.pathConferenceSid.toString()); + path = + path.replace( + "{" + "ConferenceSid" + "}", + this.pathConferenceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -75,13 +87,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("ConferenceParticipant read failed: Unable to connect to server"); + throw new ApiConnectionException( + "ConferenceParticipant read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -97,7 +117,10 @@ private Page pageForRequest(final TwilioRestClient client } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.INSIGHTS.toString()) @@ -105,9 +128,11 @@ public Page previousPage(final Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.INSIGHTS.toString()) @@ -116,33 +141,30 @@ public Page nextPage(final Page pa } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (participantSid != null) { - request.addQueryParam("ParticipantSid", participantSid); } if (label != null) { - request.addQueryParam("Label", label); } if (events != null) { - request.addQueryParam("Events", events); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/insights/v1/room/Participant.java b/src/main/java/com/twilio/rest/insights/v1/room/Participant.java index 3246b8c0c7..80b4efcfac 100644 --- a/src/main/java/com/twilio/rest/insights/v1/room/Participant.java +++ b/src/main/java/com/twilio/rest/insights/v1/room/Participant.java @@ -24,44 +24,46 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.List; import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Participant extends Resource { + private static final long serialVersionUID = 21473393957377L; - public static ParticipantFetcher fetcher(final String pathRoomSid, final String pathParticipantSid){ + public static ParticipantFetcher fetcher( + final String pathRoomSid, + final String pathParticipantSid + ) { return new ParticipantFetcher(pathRoomSid, pathParticipantSid); } - public static ParticipantReader reader(final String pathRoomSid){ + public static ParticipantReader reader(final String pathRoomSid) { return new ParticipantReader(pathRoomSid); } /** - * Converts a JSON String into a Participant object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Participant object represented by the provided JSON - */ - public static Participant fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Participant object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Participant object represented by the provided JSON + */ + public static Participant fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Participant.class); @@ -73,14 +75,17 @@ public static Participant fromJson(final String json, final ObjectMapper objectM } /** - * Converts a JSON InputStream into a Participant object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Participant object represented by the provided JSON - */ - public static Participant fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Participant object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Participant object represented by the provided JSON + */ + public static Participant fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Participant.class); @@ -90,6 +95,7 @@ public static Participant fromJson(final InputStream json, final ObjectMapper ob throw new ApiConnectionException(e.getMessage(), e); } } + public enum Codec { VP8("VP8"), H264("H264"), @@ -110,6 +116,7 @@ public static Codec forValue(final String value) { return Promoter.enumFromString(value, Codec.values()); } } + public enum EdgeLocation { ASHBURN("ashburn"), DUBLIN("dublin"), @@ -136,6 +143,7 @@ public static EdgeLocation forValue(final String value) { return Promoter.enumFromString(value, EdgeLocation.values()); } } + public enum RoomStatus { IN_PROGRESS("in_progress"), COMPLETED("completed"); @@ -155,6 +163,7 @@ public static RoomStatus forValue(final String value) { return Promoter.enumFromString(value, RoomStatus.values()); } } + public enum TwilioRealm { US1("us1"), US2("us2"), @@ -203,56 +212,25 @@ public static TwilioRealm forValue(final String value) { @JsonCreator private Participant( - @JsonProperty("participant_sid") - final String participantSid, - - @JsonProperty("participant_identity") - final String participantIdentity, - - @JsonProperty("join_time") - final String joinTime, - - @JsonProperty("leave_time") - final String leaveTime, - - @JsonProperty("duration_sec") - final Long durationSec, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("room_sid") - final String roomSid, - - @JsonProperty("status") - final Participant.RoomStatus status, - - @JsonProperty("codecs") - final List codecs, - - @JsonProperty("end_reason") - final String endReason, - - @JsonProperty("error_code") - final Integer errorCode, - - @JsonProperty("error_code_url") - final String errorCodeUrl, - - @JsonProperty("media_region") - final Participant.TwilioRealm mediaRegion, - - @JsonProperty("properties") - final Map properties, - - @JsonProperty("edge_location") - final Participant.EdgeLocation edgeLocation, - - @JsonProperty("publisher_info") - final Map publisherInfo, - - @JsonProperty("url") - final URI url + @JsonProperty("participant_sid") final String participantSid, + @JsonProperty("participant_identity") final String participantIdentity, + @JsonProperty("join_time") final String joinTime, + @JsonProperty("leave_time") final String leaveTime, + @JsonProperty("duration_sec") final Long durationSec, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("room_sid") final String roomSid, + @JsonProperty("status") final Participant.RoomStatus status, + @JsonProperty("codecs") final List codecs, + @JsonProperty("end_reason") final String endReason, + @JsonProperty("error_code") final Integer errorCode, + @JsonProperty("error_code_url") final String errorCodeUrl, + @JsonProperty("media_region") final Participant.TwilioRealm mediaRegion, + @JsonProperty("properties") final Map properties, + @JsonProperty( + "edge_location" + ) final Participant.EdgeLocation edgeLocation, + @JsonProperty("publisher_info") final Map publisherInfo, + @JsonProperty("url") final URI url ) { this.participantSid = participantSid; this.participantIdentity = participantIdentity; @@ -273,61 +251,77 @@ private Participant( this.url = url; } - public final String getParticipantSid() { - return this.participantSid; - } - public final String getParticipantIdentity() { - return this.participantIdentity; - } - public final ZonedDateTime getJoinTime() { - return this.joinTime; - } - public final ZonedDateTime getLeaveTime() { - return this.leaveTime; - } - public final Long getDurationSec() { - return this.durationSec; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getRoomSid() { - return this.roomSid; - } - public final Participant.RoomStatus getStatus() { - return this.status; - } - public final List getCodecs() { - return this.codecs; - } - public final String getEndReason() { - return this.endReason; - } - public final Integer getErrorCode() { - return this.errorCode; - } - public final String getErrorCodeUrl() { - return this.errorCodeUrl; - } - public final Participant.TwilioRealm getMediaRegion() { - return this.mediaRegion; - } - public final Map getProperties() { - return this.properties; - } - public final Participant.EdgeLocation getEdgeLocation() { - return this.edgeLocation; - } - public final Map getPublisherInfo() { - return this.publisherInfo; - } - public final URI getUrl() { - return this.url; - } + public final String getParticipantSid() { + return this.participantSid; + } + + public final String getParticipantIdentity() { + return this.participantIdentity; + } + + public final ZonedDateTime getJoinTime() { + return this.joinTime; + } + + public final ZonedDateTime getLeaveTime() { + return this.leaveTime; + } + + public final Long getDurationSec() { + return this.durationSec; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getRoomSid() { + return this.roomSid; + } + + public final Participant.RoomStatus getStatus() { + return this.status; + } + + public final List getCodecs() { + return this.codecs; + } + + public final String getEndReason() { + return this.endReason; + } + + public final Integer getErrorCode() { + return this.errorCode; + } + + public final String getErrorCodeUrl() { + return this.errorCodeUrl; + } + + public final Participant.TwilioRealm getMediaRegion() { + return this.mediaRegion; + } + + public final Map getProperties() { + return this.properties; + } + + public final Participant.EdgeLocation getEdgeLocation() { + return this.edgeLocation; + } + + public final Map getPublisherInfo() { + return this.publisherInfo; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -337,13 +331,47 @@ public boolean equals(final Object o) { Participant other = (Participant) o; - return Objects.equals(participantSid, other.participantSid) && Objects.equals(participantIdentity, other.participantIdentity) && Objects.equals(joinTime, other.joinTime) && Objects.equals(leaveTime, other.leaveTime) && Objects.equals(durationSec, other.durationSec) && Objects.equals(accountSid, other.accountSid) && Objects.equals(roomSid, other.roomSid) && Objects.equals(status, other.status) && Objects.equals(codecs, other.codecs) && Objects.equals(endReason, other.endReason) && Objects.equals(errorCode, other.errorCode) && Objects.equals(errorCodeUrl, other.errorCodeUrl) && Objects.equals(mediaRegion, other.mediaRegion) && Objects.equals(properties, other.properties) && Objects.equals(edgeLocation, other.edgeLocation) && Objects.equals(publisherInfo, other.publisherInfo) && Objects.equals(url, other.url) ; + return ( + Objects.equals(participantSid, other.participantSid) && + Objects.equals(participantIdentity, other.participantIdentity) && + Objects.equals(joinTime, other.joinTime) && + Objects.equals(leaveTime, other.leaveTime) && + Objects.equals(durationSec, other.durationSec) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(roomSid, other.roomSid) && + Objects.equals(status, other.status) && + Objects.equals(codecs, other.codecs) && + Objects.equals(endReason, other.endReason) && + Objects.equals(errorCode, other.errorCode) && + Objects.equals(errorCodeUrl, other.errorCodeUrl) && + Objects.equals(mediaRegion, other.mediaRegion) && + Objects.equals(properties, other.properties) && + Objects.equals(edgeLocation, other.edgeLocation) && + Objects.equals(publisherInfo, other.publisherInfo) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(participantSid, participantIdentity, joinTime, leaveTime, durationSec, accountSid, roomSid, status, codecs, endReason, errorCode, errorCodeUrl, mediaRegion, properties, edgeLocation, publisherInfo, url); + return Objects.hash( + participantSid, + participantIdentity, + joinTime, + leaveTime, + durationSec, + accountSid, + roomSid, + status, + codecs, + endReason, + errorCode, + errorCodeUrl, + mediaRegion, + properties, + edgeLocation, + publisherInfo, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/insights/v1/room/ParticipantFetcher.java b/src/main/java/com/twilio/rest/insights/v1/room/ParticipantFetcher.java index 05c4fc00a3..b3fa7fe400 100644 --- a/src/main/java/com/twilio/rest/insights/v1/room/ParticipantFetcher.java +++ b/src/main/java/com/twilio/rest/insights/v1/room/ParticipantFetcher.java @@ -24,25 +24,29 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class ParticipantFetcher extends Fetcher { + private String pathRoomSid; private String pathParticipantSid; - public ParticipantFetcher(final String pathRoomSid, final String pathParticipantSid){ + public ParticipantFetcher( + final String pathRoomSid, + final String pathParticipantSid + ) { this.pathRoomSid = pathRoomSid; this.pathParticipantSid = pathParticipantSid; } - @Override public Participant fetch(final TwilioRestClient client) { String path = "/v1/Video/Rooms/{RoomSid}/Participants/{ParticipantSid}"; - path = path.replace("{"+"RoomSid"+"}", this.pathRoomSid.toString()); - path = path.replace("{"+"ParticipantSid"+"}", this.pathParticipantSid.toString()); + path = path.replace("{" + "RoomSid" + "}", this.pathRoomSid.toString()); + path = + path.replace( + "{" + "ParticipantSid" + "}", + this.pathParticipantSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -52,15 +56,23 @@ public Participant fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Participant fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Participant fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Participant.fromJson(response.getStream(), client.getObjectMapper()); + return Participant.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/insights/v1/room/ParticipantReader.java b/src/main/java/com/twilio/rest/insights/v1/room/ParticipantReader.java index 17384dee8b..374375a52d 100644 --- a/src/main/java/com/twilio/rest/insights/v1/room/ParticipantReader.java +++ b/src/main/java/com/twilio/rest/insights/v1/room/ParticipantReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.insights.v1.room; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,19 +25,17 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class ParticipantReader extends Reader { + private String pathRoomSid; private Integer pageSize; - public ParticipantReader(final String pathRoomSid){ + public ParticipantReader(final String pathRoomSid) { this.pathRoomSid = pathRoomSid; } - public ParticipantReader setPageSize(final Integer pageSize){ + public ParticipantReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -48,7 +47,7 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Video/Rooms/{RoomSid}/Participants"; - path = path.replace("{"+"RoomSid"+"}", this.pathRoomSid.toString()); + path = path.replace("{" + "RoomSid" + "}", this.pathRoomSid.toString()); Request request = new Request( HttpMethod.GET, @@ -60,13 +59,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Participant read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Participant read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +89,10 @@ private Page pageForRequest(final TwilioRestClient client, final Re } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.INSIGHTS.toString()) @@ -90,9 +100,11 @@ public Page previousPage(final Page page, final Twilio return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.INSIGHTS.toString()) @@ -101,21 +113,21 @@ public Page nextPage(final Page page, final TwilioRest } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/intelligence/v2/Service.java b/src/main/java/com/twilio/rest/intelligence/v2/Service.java index ccf9e6b840..99fdeaf8ee 100644 --- a/src/main/java/com/twilio/rest/intelligence/v2/Service.java +++ b/src/main/java/com/twilio/rest/intelligence/v2/Service.java @@ -24,54 +24,53 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; import com.twilio.http.HttpMethod; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Service extends Resource { + private static final long serialVersionUID = 160239821590245L; - public static ServiceCreator creator(final String uniqueName){ + public static ServiceCreator creator(final String uniqueName) { return new ServiceCreator(uniqueName); } - public static ServiceDeleter deleter(final String pathSid){ + public static ServiceDeleter deleter(final String pathSid) { return new ServiceDeleter(pathSid); } - public static ServiceFetcher fetcher(final String pathSid){ + public static ServiceFetcher fetcher(final String pathSid) { return new ServiceFetcher(pathSid); } - public static ServiceReader reader(){ + public static ServiceReader reader() { return new ServiceReader(); } - public static ServiceUpdater updater(final String pathSid){ + public static ServiceUpdater updater(final String pathSid) { return new ServiceUpdater(pathSid); } /** - * Converts a JSON String into a Service object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Service object represented by the provided JSON - */ - public static Service fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Service object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Service object represented by the provided JSON + */ + public static Service fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Service.class); @@ -83,14 +82,17 @@ public static Service fromJson(final String json, final ObjectMapper objectMappe } /** - * Converts a JSON InputStream into a Service object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Service object represented by the provided JSON - */ - public static Service fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Service object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Service object represented by the provided JSON + */ + public static Service fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Service.class); @@ -100,6 +102,7 @@ public static Service fromJson(final InputStream json, final ObjectMapper object throw new ApiConnectionException(e.getMessage(), e); } } + public enum HttpMethod { GET("GET"), POST("POST"), @@ -139,50 +142,23 @@ public static HttpMethod forValue(final String value) { @JsonCreator private Service( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("auto_redaction") - final Boolean autoRedaction, - - @JsonProperty("media_redaction") - final Boolean mediaRedaction, - - @JsonProperty("auto_transcribe") - final Boolean autoTranscribe, - - @JsonProperty("data_logging") - final Boolean dataLogging, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("language_code") - final String languageCode, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("unique_name") - final String uniqueName, - - @JsonProperty("url") - final URI url, - - @JsonProperty("webhook_url") - final String webhookUrl, - - @JsonProperty("webhook_http_method") - final Service.HttpMethod webhookHttpMethod, - - @JsonProperty("version") - final Integer version + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("auto_redaction") final Boolean autoRedaction, + @JsonProperty("media_redaction") final Boolean mediaRedaction, + @JsonProperty("auto_transcribe") final Boolean autoTranscribe, + @JsonProperty("data_logging") final Boolean dataLogging, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("language_code") final String languageCode, + @JsonProperty("sid") final String sid, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("url") final URI url, + @JsonProperty("webhook_url") final String webhookUrl, + @JsonProperty( + "webhook_http_method" + ) final Service.HttpMethod webhookHttpMethod, + @JsonProperty("version") final Integer version ) { this.accountSid = accountSid; this.autoRedaction = autoRedaction; @@ -201,55 +177,69 @@ private Service( this.version = version; } - public final String getAccountSid() { - return this.accountSid; - } - public final Boolean getAutoRedaction() { - return this.autoRedaction; - } - public final Boolean getMediaRedaction() { - return this.mediaRedaction; - } - public final Boolean getAutoTranscribe() { - return this.autoTranscribe; - } - public final Boolean getDataLogging() { - return this.dataLogging; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getLanguageCode() { - return this.languageCode; - } - public final String getSid() { - return this.sid; - } - public final String getUniqueName() { - return this.uniqueName; - } - public final URI getUrl() { - return this.url; - } - public final String getWebhookUrl() { - return this.webhookUrl; - } - public final Service.HttpMethod getWebhookHttpMethod() { - return this.webhookHttpMethod; - } - public final Integer getVersion() { - return this.version; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final Boolean getAutoRedaction() { + return this.autoRedaction; + } + + public final Boolean getMediaRedaction() { + return this.mediaRedaction; + } + + public final Boolean getAutoTranscribe() { + return this.autoTranscribe; + } + + public final Boolean getDataLogging() { + return this.dataLogging; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getLanguageCode() { + return this.languageCode; + } + + public final String getSid() { + return this.sid; + } + + public final String getUniqueName() { + return this.uniqueName; + } + + public final URI getUrl() { + return this.url; + } + + public final String getWebhookUrl() { + return this.webhookUrl; + } + + public final Service.HttpMethod getWebhookHttpMethod() { + return this.webhookHttpMethod; + } + + public final Integer getVersion() { + return this.version; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -259,13 +249,43 @@ public boolean equals(final Object o) { Service other = (Service) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(autoRedaction, other.autoRedaction) && Objects.equals(mediaRedaction, other.mediaRedaction) && Objects.equals(autoTranscribe, other.autoTranscribe) && Objects.equals(dataLogging, other.dataLogging) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(languageCode, other.languageCode) && Objects.equals(sid, other.sid) && Objects.equals(uniqueName, other.uniqueName) && Objects.equals(url, other.url) && Objects.equals(webhookUrl, other.webhookUrl) && Objects.equals(webhookHttpMethod, other.webhookHttpMethod) && Objects.equals(version, other.version) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(autoRedaction, other.autoRedaction) && + Objects.equals(mediaRedaction, other.mediaRedaction) && + Objects.equals(autoTranscribe, other.autoTranscribe) && + Objects.equals(dataLogging, other.dataLogging) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(languageCode, other.languageCode) && + Objects.equals(sid, other.sid) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(url, other.url) && + Objects.equals(webhookUrl, other.webhookUrl) && + Objects.equals(webhookHttpMethod, other.webhookHttpMethod) && + Objects.equals(version, other.version) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, autoRedaction, mediaRedaction, autoTranscribe, dataLogging, dateCreated, dateUpdated, friendlyName, languageCode, sid, uniqueName, url, webhookUrl, webhookHttpMethod, version); + return Objects.hash( + accountSid, + autoRedaction, + mediaRedaction, + autoTranscribe, + dataLogging, + dateCreated, + dateUpdated, + friendlyName, + languageCode, + sid, + uniqueName, + url, + webhookUrl, + webhookHttpMethod, + version + ); } - } - diff --git a/src/main/java/com/twilio/rest/intelligence/v2/ServiceCreator.java b/src/main/java/com/twilio/rest/intelligence/v2/ServiceCreator.java index 99924871a9..bfd3d9777f 100644 --- a/src/main/java/com/twilio/rest/intelligence/v2/ServiceCreator.java +++ b/src/main/java/com/twilio/rest/intelligence/v2/ServiceCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.intelligence.v2; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class ServiceCreator extends Creator { - - -public class ServiceCreator extends Creator{ private String uniqueName; private Boolean autoTranscribe; private Boolean dataLogging; @@ -42,60 +41,77 @@ public ServiceCreator(final String uniqueName) { this.uniqueName = uniqueName; } - public ServiceCreator setUniqueName(final String uniqueName){ + public ServiceCreator setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - public ServiceCreator setAutoTranscribe(final Boolean autoTranscribe){ + + public ServiceCreator setAutoTranscribe(final Boolean autoTranscribe) { this.autoTranscribe = autoTranscribe; return this; } - public ServiceCreator setDataLogging(final Boolean dataLogging){ + + public ServiceCreator setDataLogging(final Boolean dataLogging) { this.dataLogging = dataLogging; return this; } - public ServiceCreator setFriendlyName(final String friendlyName){ + + public ServiceCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public ServiceCreator setLanguageCode(final String languageCode){ + + public ServiceCreator setLanguageCode(final String languageCode) { this.languageCode = languageCode; return this; } - public ServiceCreator setAutoRedaction(final Boolean autoRedaction){ + + public ServiceCreator setAutoRedaction(final Boolean autoRedaction) { this.autoRedaction = autoRedaction; return this; } - public ServiceCreator setMediaRedaction(final Boolean mediaRedaction){ + + public ServiceCreator setMediaRedaction(final Boolean mediaRedaction) { this.mediaRedaction = mediaRedaction; return this; } - public ServiceCreator setWebhookUrl(final String webhookUrl){ + + public ServiceCreator setWebhookUrl(final String webhookUrl) { this.webhookUrl = webhookUrl; return this; } - public ServiceCreator setWebhookHttpMethod(final Service.HttpMethod webhookHttpMethod){ + + public ServiceCreator setWebhookHttpMethod( + final Service.HttpMethod webhookHttpMethod + ) { this.webhookHttpMethod = webhookHttpMethod; return this; } @Override - public Service create(final TwilioRestClient client){ + public Service create(final TwilioRestClient client) { String path = "/v2/Services"; - path = path.replace("{"+"UniqueName"+"}", this.uniqueName.toString()); + path = + path.replace("{" + "UniqueName" + "}", this.uniqueName.toString()); Request request = new Request( HttpMethod.POST, Domains.INTELLIGENCE.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -104,42 +120,37 @@ public Service create(final TwilioRestClient client){ return Service.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (uniqueName != null) { request.addPostParam("UniqueName", uniqueName); - } if (autoTranscribe != null) { request.addPostParam("AutoTranscribe", autoTranscribe.toString()); - } if (dataLogging != null) { request.addPostParam("DataLogging", dataLogging.toString()); - } if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (languageCode != null) { request.addPostParam("LanguageCode", languageCode); - } if (autoRedaction != null) { request.addPostParam("AutoRedaction", autoRedaction.toString()); - } if (mediaRedaction != null) { request.addPostParam("MediaRedaction", mediaRedaction.toString()); - } if (webhookUrl != null) { request.addPostParam("WebhookUrl", webhookUrl); - } if (webhookHttpMethod != null) { - request.addPostParam("WebhookHttpMethod", webhookHttpMethod.toString()); - + request.addPostParam( + "WebhookHttpMethod", + webhookHttpMethod.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/intelligence/v2/ServiceDeleter.java b/src/main/java/com/twilio/rest/intelligence/v2/ServiceDeleter.java index 855622dd58..9ebd68bd95 100644 --- a/src/main/java/com/twilio/rest/intelligence/v2/ServiceDeleter.java +++ b/src/main/java/com/twilio/rest/intelligence/v2/ServiceDeleter.java @@ -24,21 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class ServiceDeleter extends Deleter { + private String pathSid; - public ServiceDeleter(final String pathSid){ + public ServiceDeleter(final String pathSid) { this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v2/Services/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -48,9 +46,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/intelligence/v2/ServiceFetcher.java b/src/main/java/com/twilio/rest/intelligence/v2/ServiceFetcher.java index 380245ea11..4d34ac46cb 100644 --- a/src/main/java/com/twilio/rest/intelligence/v2/ServiceFetcher.java +++ b/src/main/java/com/twilio/rest/intelligence/v2/ServiceFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class ServiceFetcher extends Fetcher { + private String pathSid; - public ServiceFetcher(final String pathSid){ + public ServiceFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public Service fetch(final TwilioRestClient client) { String path = "/v2/Services/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,9 +46,14 @@ public Service fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/intelligence/v2/ServiceReader.java b/src/main/java/com/twilio/rest/intelligence/v2/ServiceReader.java index 37da4c49f5..eafa321804 100644 --- a/src/main/java/com/twilio/rest/intelligence/v2/ServiceReader.java +++ b/src/main/java/com/twilio/rest/intelligence/v2/ServiceReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.intelligence.v2; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,17 +25,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class ServiceReader extends Reader { + private Integer pageSize; - public ServiceReader(){ - } + public ServiceReader() {} - public ServiceReader setPageSize(final Integer pageSize){ + public ServiceReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -57,13 +55,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -79,7 +85,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reques } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.INTELLIGENCE.toString()) @@ -87,9 +96,11 @@ public Page previousPage(final Page page, final TwilioRestClie return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.INTELLIGENCE.toString()) @@ -98,21 +109,21 @@ public Page nextPage(final Page page, final TwilioRestClient c } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/intelligence/v2/ServiceUpdater.java b/src/main/java/com/twilio/rest/intelligence/v2/ServiceUpdater.java index c1d283a95a..3fea7df56a 100644 --- a/src/main/java/com/twilio/rest/intelligence/v2/ServiceUpdater.java +++ b/src/main/java/com/twilio/rest/intelligence/v2/ServiceUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.intelligence.v2; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class ServiceUpdater extends Updater { - - -public class ServiceUpdater extends Updater{ private String pathSid; private String ifMatch; private Boolean autoTranscribe; @@ -40,69 +39,86 @@ public class ServiceUpdater extends Updater{ private String webhookUrl; private Service.HttpMethod webhookHttpMethod; - public ServiceUpdater(final String pathSid){ + public ServiceUpdater(final String pathSid) { this.pathSid = pathSid; } - public ServiceUpdater setIfMatch(final String ifMatch){ + public ServiceUpdater setIfMatch(final String ifMatch) { this.ifMatch = ifMatch; return this; } - public ServiceUpdater setAutoTranscribe(final Boolean autoTranscribe){ + + public ServiceUpdater setAutoTranscribe(final Boolean autoTranscribe) { this.autoTranscribe = autoTranscribe; return this; } - public ServiceUpdater setDataLogging(final Boolean dataLogging){ + + public ServiceUpdater setDataLogging(final Boolean dataLogging) { this.dataLogging = dataLogging; return this; } - public ServiceUpdater setFriendlyName(final String friendlyName){ + + public ServiceUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public ServiceUpdater setLanguageCode(final String languageCode){ + + public ServiceUpdater setLanguageCode(final String languageCode) { this.languageCode = languageCode; return this; } - public ServiceUpdater setUniqueName(final String uniqueName){ + + public ServiceUpdater setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - public ServiceUpdater setAutoRedaction(final Boolean autoRedaction){ + + public ServiceUpdater setAutoRedaction(final Boolean autoRedaction) { this.autoRedaction = autoRedaction; return this; } - public ServiceUpdater setMediaRedaction(final Boolean mediaRedaction){ + + public ServiceUpdater setMediaRedaction(final Boolean mediaRedaction) { this.mediaRedaction = mediaRedaction; return this; } - public ServiceUpdater setWebhookUrl(final String webhookUrl){ + + public ServiceUpdater setWebhookUrl(final String webhookUrl) { this.webhookUrl = webhookUrl; return this; } - public ServiceUpdater setWebhookHttpMethod(final Service.HttpMethod webhookHttpMethod){ + + public ServiceUpdater setWebhookHttpMethod( + final Service.HttpMethod webhookHttpMethod + ) { this.webhookHttpMethod = webhookHttpMethod; return this; } @Override - public Service update(final TwilioRestClient client){ + public Service update(final TwilioRestClient client) { String path = "/v2/Services/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.INTELLIGENCE.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); addHeaderParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -111,48 +127,43 @@ public Service update(final TwilioRestClient client){ return Service.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (autoTranscribe != null) { request.addPostParam("AutoTranscribe", autoTranscribe.toString()); - } if (dataLogging != null) { request.addPostParam("DataLogging", dataLogging.toString()); - } if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (languageCode != null) { request.addPostParam("LanguageCode", languageCode); - } if (uniqueName != null) { request.addPostParam("UniqueName", uniqueName); - } if (autoRedaction != null) { request.addPostParam("AutoRedaction", autoRedaction.toString()); - } if (mediaRedaction != null) { request.addPostParam("MediaRedaction", mediaRedaction.toString()); - } if (webhookUrl != null) { request.addPostParam("WebhookUrl", webhookUrl); - } if (webhookHttpMethod != null) { - request.addPostParam("WebhookHttpMethod", webhookHttpMethod.toString()); - + request.addPostParam( + "WebhookHttpMethod", + webhookHttpMethod.toString() + ); } } + private void addHeaderParams(final Request request) { if (ifMatch != null) { request.addHeaderParam("If-Match", ifMatch); - } } } diff --git a/src/main/java/com/twilio/rest/intelligence/v2/Transcript.java b/src/main/java/com/twilio/rest/intelligence/v2/Transcript.java index 2ddee966ad..d2e4f4db2d 100644 --- a/src/main/java/com/twilio/rest/intelligence/v2/Transcript.java +++ b/src/main/java/com/twilio/rest/intelligence/v2/Transcript.java @@ -24,51 +24,53 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Transcript extends Resource { + private static final long serialVersionUID = 35462753187463L; - public static TranscriptCreator creator(final String serviceSid, final Map channel){ + public static TranscriptCreator creator( + final String serviceSid, + final Map channel + ) { return new TranscriptCreator(serviceSid, channel); } - public static TranscriptDeleter deleter(final String pathSid){ + public static TranscriptDeleter deleter(final String pathSid) { return new TranscriptDeleter(pathSid); } - public static TranscriptFetcher fetcher(final String pathSid){ + public static TranscriptFetcher fetcher(final String pathSid) { return new TranscriptFetcher(pathSid); } - public static TranscriptReader reader(){ + public static TranscriptReader reader() { return new TranscriptReader(); } /** - * Converts a JSON String into a Transcript object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Transcript object represented by the provided JSON - */ - public static Transcript fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Transcript object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Transcript object represented by the provided JSON + */ + public static Transcript fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Transcript.class); @@ -80,14 +82,17 @@ public static Transcript fromJson(final String json, final ObjectMapper objectMa } /** - * Converts a JSON InputStream into a Transcript object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Transcript object represented by the provided JSON - */ - public static Transcript fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Transcript object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Transcript object represented by the provided JSON + */ + public static Transcript fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Transcript.class); @@ -97,6 +102,7 @@ public static Transcript fromJson(final InputStream json, final ObjectMapper obj throw new ApiConnectionException(e.getMessage(), e); } } + public enum Status { QUEUED("queued"), IN_PROGRESS("in-progress"), @@ -138,50 +144,21 @@ public static Status forValue(final String value) { @JsonCreator private Transcript( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("status") - final Transcript.Status status, - - @JsonProperty("channel") - final Map channel, - - @JsonProperty("data_logging") - final Boolean dataLogging, - - @JsonProperty("language_code") - final String languageCode, - - @JsonProperty("customer_key") - final String customerKey, - - @JsonProperty("media_start_time") - final String mediaStartTime, - - @JsonProperty("duration") - final Integer duration, - - @JsonProperty("url") - final URI url, - - @JsonProperty("redaction") - final Boolean redaction, - - @JsonProperty("links") - final Map links + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("status") final Transcript.Status status, + @JsonProperty("channel") final Map channel, + @JsonProperty("data_logging") final Boolean dataLogging, + @JsonProperty("language_code") final String languageCode, + @JsonProperty("customer_key") final String customerKey, + @JsonProperty("media_start_time") final String mediaStartTime, + @JsonProperty("duration") final Integer duration, + @JsonProperty("url") final URI url, + @JsonProperty("redaction") final Boolean redaction, + @JsonProperty("links") final Map links ) { this.accountSid = accountSid; this.serviceSid = serviceSid; @@ -193,62 +170,77 @@ private Transcript( this.dataLogging = dataLogging; this.languageCode = languageCode; this.customerKey = customerKey; - this.mediaStartTime = DateConverter.iso8601DateTimeFromString(mediaStartTime); + this.mediaStartTime = + DateConverter.iso8601DateTimeFromString(mediaStartTime); this.duration = duration; this.url = url; this.redaction = redaction; this.links = links; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final String getSid() { - return this.sid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final Transcript.Status getStatus() { - return this.status; - } - public final Map getChannel() { - return this.channel; - } - public final Boolean getDataLogging() { - return this.dataLogging; - } - public final String getLanguageCode() { - return this.languageCode; - } - public final String getCustomerKey() { - return this.customerKey; - } - public final ZonedDateTime getMediaStartTime() { - return this.mediaStartTime; - } - public final Integer getDuration() { - return this.duration; - } - public final URI getUrl() { - return this.url; - } - public final Boolean getRedaction() { - return this.redaction; - } - public final Map getLinks() { - return this.links; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final String getSid() { + return this.sid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final Transcript.Status getStatus() { + return this.status; + } + + public final Map getChannel() { + return this.channel; + } + + public final Boolean getDataLogging() { + return this.dataLogging; + } + + public final String getLanguageCode() { + return this.languageCode; + } + + public final String getCustomerKey() { + return this.customerKey; + } + + public final ZonedDateTime getMediaStartTime() { + return this.mediaStartTime; + } + + public final Integer getDuration() { + return this.duration; + } + + public final URI getUrl() { + return this.url; + } + + public final Boolean getRedaction() { + return this.redaction; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -258,13 +250,43 @@ public boolean equals(final Object o) { Transcript other = (Transcript) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(sid, other.sid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(status, other.status) && Objects.equals(channel, other.channel) && Objects.equals(dataLogging, other.dataLogging) && Objects.equals(languageCode, other.languageCode) && Objects.equals(customerKey, other.customerKey) && Objects.equals(mediaStartTime, other.mediaStartTime) && Objects.equals(duration, other.duration) && Objects.equals(url, other.url) && Objects.equals(redaction, other.redaction) && Objects.equals(links, other.links) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(status, other.status) && + Objects.equals(channel, other.channel) && + Objects.equals(dataLogging, other.dataLogging) && + Objects.equals(languageCode, other.languageCode) && + Objects.equals(customerKey, other.customerKey) && + Objects.equals(mediaStartTime, other.mediaStartTime) && + Objects.equals(duration, other.duration) && + Objects.equals(url, other.url) && + Objects.equals(redaction, other.redaction) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, serviceSid, sid, dateCreated, dateUpdated, status, channel, dataLogging, languageCode, customerKey, mediaStartTime, duration, url, redaction, links); + return Objects.hash( + accountSid, + serviceSid, + sid, + dateCreated, + dateUpdated, + status, + channel, + dataLogging, + languageCode, + customerKey, + mediaStartTime, + duration, + url, + redaction, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/intelligence/v2/TranscriptCreator.java b/src/main/java/com/twilio/rest/intelligence/v2/TranscriptCreator.java index fcebd329e3..4f9e422564 100644 --- a/src/main/java/com/twilio/rest/intelligence/v2/TranscriptCreator.java +++ b/src/main/java/com/twilio/rest/intelligence/v2/TranscriptCreator.java @@ -15,8 +15,10 @@ package com.twilio.rest.intelligence.v2; import com.twilio.base.Creator; -import com.twilio.exception.ApiConnectionException; +import com.twilio.constant.EnumConstants; +import com.twilio.converter.Converter; import com.twilio.converter.Converter; +import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; @@ -24,84 +26,99 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import java.util.Map; -import com.twilio.converter.Converter; import java.time.ZonedDateTime; - +import java.util.Map; import java.util.Map; +public class TranscriptCreator extends Creator { - -public class TranscriptCreator extends Creator{ private String serviceSid; private Map channel; private String customerKey; private ZonedDateTime mediaStartTime; - public TranscriptCreator(final String serviceSid, final Map channel) { + public TranscriptCreator( + final String serviceSid, + final Map channel + ) { this.serviceSid = serviceSid; this.channel = channel; } - public TranscriptCreator setServiceSid(final String serviceSid){ + public TranscriptCreator setServiceSid(final String serviceSid) { this.serviceSid = serviceSid; return this; } - public TranscriptCreator setChannel(final Map channel){ + + public TranscriptCreator setChannel(final Map channel) { this.channel = channel; return this; } - public TranscriptCreator setCustomerKey(final String customerKey){ + + public TranscriptCreator setCustomerKey(final String customerKey) { this.customerKey = customerKey; return this; } - public TranscriptCreator setMediaStartTime(final ZonedDateTime mediaStartTime){ + + public TranscriptCreator setMediaStartTime( + final ZonedDateTime mediaStartTime + ) { this.mediaStartTime = mediaStartTime; return this; } @Override - public Transcript create(final TwilioRestClient client){ + public Transcript create(final TwilioRestClient client) { String path = "/v2/Transcripts"; - path = path.replace("{"+"ServiceSid"+"}", this.serviceSid.toString()); - path = path.replace("{"+"Channel"+"}", this.channel.toString()); + path = + path.replace("{" + "ServiceSid" + "}", this.serviceSid.toString()); + path = path.replace("{" + "Channel" + "}", this.channel.toString()); Request request = new Request( HttpMethod.POST, Domains.INTELLIGENCE.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Transcript creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Transcript creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Transcript.fromJson(response.getStream(), client.getObjectMapper()); + return Transcript.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (serviceSid != null) { request.addPostParam("ServiceSid", serviceSid); - } if (channel != null) { - request.addPostParam("Channel", Converter.mapToJson(channel)); - + request.addPostParam("Channel", Converter.mapToJson(channel)); } if (customerKey != null) { request.addPostParam("CustomerKey", customerKey); - } if (mediaStartTime != null) { - request.addPostParam("MediaStartTime", mediaStartTime.toInstant().toString()); - + request.addPostParam( + "MediaStartTime", + mediaStartTime.toInstant().toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/intelligence/v2/TranscriptDeleter.java b/src/main/java/com/twilio/rest/intelligence/v2/TranscriptDeleter.java index f15b4c182c..2732b34746 100644 --- a/src/main/java/com/twilio/rest/intelligence/v2/TranscriptDeleter.java +++ b/src/main/java/com/twilio/rest/intelligence/v2/TranscriptDeleter.java @@ -24,21 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class TranscriptDeleter extends Deleter { + private String pathSid; - public TranscriptDeleter(final String pathSid){ + public TranscriptDeleter(final String pathSid) { this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v2/Transcripts/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -48,9 +46,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Transcript delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Transcript delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/intelligence/v2/TranscriptFetcher.java b/src/main/java/com/twilio/rest/intelligence/v2/TranscriptFetcher.java index a8d6607f93..6bcddc4d02 100644 --- a/src/main/java/com/twilio/rest/intelligence/v2/TranscriptFetcher.java +++ b/src/main/java/com/twilio/rest/intelligence/v2/TranscriptFetcher.java @@ -24,18 +24,16 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class TranscriptFetcher extends Fetcher { + private String pathSid; private Boolean redacted; - public TranscriptFetcher(final String pathSid){ + public TranscriptFetcher(final String pathSid) { this.pathSid = pathSid; } - public TranscriptFetcher setRedacted(final Boolean redacted){ + public TranscriptFetcher setRedacted(final Boolean redacted) { this.redacted = redacted; return this; } @@ -44,7 +42,7 @@ public TranscriptFetcher setRedacted(final Boolean redacted){ public Transcript fetch(final TwilioRestClient client) { String path = "/v2/Transcripts/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -55,20 +53,28 @@ public Transcript fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Transcript fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Transcript fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Transcript.fromJson(response.getStream(), client.getObjectMapper()); + return Transcript.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addQueryParams(final Request request) { if (redacted != null) { - request.addQueryParam("Redacted", redacted.toString()); } } diff --git a/src/main/java/com/twilio/rest/intelligence/v2/TranscriptReader.java b/src/main/java/com/twilio/rest/intelligence/v2/TranscriptReader.java index 7fc2c5ed7d..f446c7c1be 100644 --- a/src/main/java/com/twilio/rest/intelligence/v2/TranscriptReader.java +++ b/src/main/java/com/twilio/rest/intelligence/v2/TranscriptReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.intelligence.v2; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,11 +25,9 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class TranscriptReader extends Reader { + private String serviceSid; private String beforeStartTime; private String afterStartTime; @@ -39,42 +38,51 @@ public class TranscriptReader extends Reader { private String sourceSid; private Integer pageSize; - public TranscriptReader(){ - } + public TranscriptReader() {} - public TranscriptReader setServiceSid(final String serviceSid){ + public TranscriptReader setServiceSid(final String serviceSid) { this.serviceSid = serviceSid; return this; } - public TranscriptReader setBeforeStartTime(final String beforeStartTime){ + + public TranscriptReader setBeforeStartTime(final String beforeStartTime) { this.beforeStartTime = beforeStartTime; return this; } - public TranscriptReader setAfterStartTime(final String afterStartTime){ + + public TranscriptReader setAfterStartTime(final String afterStartTime) { this.afterStartTime = afterStartTime; return this; } - public TranscriptReader setBeforeDateCreated(final String beforeDateCreated){ + + public TranscriptReader setBeforeDateCreated( + final String beforeDateCreated + ) { this.beforeDateCreated = beforeDateCreated; return this; } - public TranscriptReader setAfterDateCreated(final String afterDateCreated){ + + public TranscriptReader setAfterDateCreated(final String afterDateCreated) { this.afterDateCreated = afterDateCreated; return this; } - public TranscriptReader setStatus(final String status){ + + public TranscriptReader setStatus(final String status) { this.status = status; return this; } - public TranscriptReader setLanguageCode(final String languageCode){ + + public TranscriptReader setLanguageCode(final String languageCode) { this.languageCode = languageCode; return this; } - public TranscriptReader setSourceSid(final String sourceSid){ + + public TranscriptReader setSourceSid(final String sourceSid) { this.sourceSid = sourceSid; return this; } - public TranscriptReader setPageSize(final Integer pageSize){ + + public TranscriptReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -97,13 +105,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Transcript read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Transcript read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -119,7 +135,10 @@ private Page pageForRequest(final TwilioRestClient client, final Req } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.INTELLIGENCE.toString()) @@ -127,9 +146,11 @@ public Page previousPage(final Page page, final TwilioRe return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.INTELLIGENCE.toString()) @@ -138,53 +159,45 @@ public Page nextPage(final Page page, final TwilioRestCl } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (serviceSid != null) { - request.addQueryParam("ServiceSid", serviceSid); } if (beforeStartTime != null) { - request.addQueryParam("BeforeStartTime", beforeStartTime); } if (afterStartTime != null) { - request.addQueryParam("AfterStartTime", afterStartTime); } if (beforeDateCreated != null) { - request.addQueryParam("BeforeDateCreated", beforeDateCreated); } if (afterDateCreated != null) { - request.addQueryParam("AfterDateCreated", afterDateCreated); } if (status != null) { - request.addQueryParam("Status", status); } if (languageCode != null) { - request.addQueryParam("LanguageCode", languageCode); } if (sourceSid != null) { - request.addQueryParam("SourceSid", sourceSid); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/intelligence/v2/transcript/Media.java b/src/main/java/com/twilio/rest/intelligence/v2/transcript/Media.java index 85567796df..5ada494f55 100644 --- a/src/main/java/com/twilio/rest/intelligence/v2/transcript/Media.java +++ b/src/main/java/com/twilio/rest/intelligence/v2/transcript/Media.java @@ -22,36 +22,35 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Media extends Resource { + private static final long serialVersionUID = 207829674287272L; - public static MediaFetcher fetcher(final String pathSid){ + public static MediaFetcher fetcher(final String pathSid) { return new MediaFetcher(pathSid); } /** - * Converts a JSON String into a Media object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Media object represented by the provided JSON - */ - public static Media fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Media object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Media object represented by the provided JSON + */ + public static Media fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Media.class); @@ -63,14 +62,17 @@ public static Media fromJson(final String json, final ObjectMapper objectMapper) } /** - * Converts a JSON InputStream into a Media object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Media object represented by the provided JSON - */ - public static Media fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Media object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Media object represented by the provided JSON + */ + public static Media fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Media.class); @@ -89,20 +91,11 @@ public static Media fromJson(final InputStream json, final ObjectMapper objectMa @JsonCreator private Media( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("media_url") - final URI mediaUrl, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("url") - final URI url + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("media_url") final URI mediaUrl, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url ) { this.accountSid = accountSid; this.mediaUrl = mediaUrl; @@ -111,25 +104,29 @@ private Media( this.url = url; } - public final String getAccountSid() { - return this.accountSid; - } - public final URI getMediaUrl() { - return this.mediaUrl; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final String getSid() { - return this.sid; - } - public final URI getUrl() { - return this.url; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final URI getMediaUrl() { + return this.mediaUrl; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final String getSid() { + return this.sid; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -139,13 +136,17 @@ public boolean equals(final Object o) { Media other = (Media) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(mediaUrl, other.mediaUrl) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(sid, other.sid) && Objects.equals(url, other.url) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(mediaUrl, other.mediaUrl) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { return Objects.hash(accountSid, mediaUrl, serviceSid, sid, url); } - } - diff --git a/src/main/java/com/twilio/rest/intelligence/v2/transcript/MediaFetcher.java b/src/main/java/com/twilio/rest/intelligence/v2/transcript/MediaFetcher.java index 281910d820..e85ce1f374 100644 --- a/src/main/java/com/twilio/rest/intelligence/v2/transcript/MediaFetcher.java +++ b/src/main/java/com/twilio/rest/intelligence/v2/transcript/MediaFetcher.java @@ -24,18 +24,16 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class MediaFetcher extends Fetcher { + private String pathSid; private Boolean redacted; - public MediaFetcher(final String pathSid){ + public MediaFetcher(final String pathSid) { this.pathSid = pathSid; } - public MediaFetcher setRedacted(final Boolean redacted){ + public MediaFetcher setRedacted(final Boolean redacted) { this.redacted = redacted; return this; } @@ -44,7 +42,7 @@ public MediaFetcher setRedacted(final Boolean redacted){ public Media fetch(final TwilioRestClient client) { String path = "/v2/Transcripts/{Sid}/Media"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -55,9 +53,14 @@ public Media fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Media fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Media fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -66,9 +69,9 @@ public Media fetch(final TwilioRestClient client) { return Media.fromJson(response.getStream(), client.getObjectMapper()); } + private void addQueryParams(final Request request) { if (redacted != null) { - request.addQueryParam("Redacted", redacted.toString()); } } diff --git a/src/main/java/com/twilio/rest/intelligence/v2/transcript/OperatorResult.java b/src/main/java/com/twilio/rest/intelligence/v2/transcript/OperatorResult.java index 9c96bb910f..d3a5bbdf36 100644 --- a/src/main/java/com/twilio/rest/intelligence/v2/transcript/OperatorResult.java +++ b/src/main/java/com/twilio/rest/intelligence/v2/transcript/OperatorResult.java @@ -23,44 +23,46 @@ import com.twilio.base.Resource; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; +import java.math.BigDecimal; import java.net.URI; - import java.util.List; import java.util.Map; -import java.util.Objects; - - import java.util.Map; -import java.math.BigDecimal; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class OperatorResult extends Resource { + private static final long serialVersionUID = 126254553573605L; - public static OperatorResultFetcher fetcher(final String pathTranscriptSid, final String pathOperatorSid){ + public static OperatorResultFetcher fetcher( + final String pathTranscriptSid, + final String pathOperatorSid + ) { return new OperatorResultFetcher(pathTranscriptSid, pathOperatorSid); } - public static OperatorResultReader reader(final String pathTranscriptSid){ + public static OperatorResultReader reader(final String pathTranscriptSid) { return new OperatorResultReader(pathTranscriptSid); } /** - * Converts a JSON String into a OperatorResult object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return OperatorResult object represented by the provided JSON - */ - public static OperatorResult fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a OperatorResult object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return OperatorResult object represented by the provided JSON + */ + public static OperatorResult fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, OperatorResult.class); @@ -72,14 +74,17 @@ public static OperatorResult fromJson(final String json, final ObjectMapper obje } /** - * Converts a JSON InputStream into a OperatorResult object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return OperatorResult object represented by the provided JSON - */ - public static OperatorResult fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a OperatorResult object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return OperatorResult object represented by the provided JSON + */ + public static OperatorResult fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, OperatorResult.class); @@ -89,6 +94,7 @@ public static OperatorResult fromJson(final InputStream json, final ObjectMapper throw new ApiConnectionException(e.getMessage(), e); } } + public enum OperatorType { CONVERSATION_CLASSIFY("conversation_classify"), UTTERANCE_CLASSIFY("utterance_classify"), @@ -129,47 +135,30 @@ public static OperatorType forValue(final String value) { @JsonCreator private OperatorResult( - @JsonProperty("operator_type") - final OperatorResult.OperatorType operatorType, - - @JsonProperty("name") - final String name, - - @JsonProperty("operator_sid") - final String operatorSid, - - @JsonProperty("extract_match") - final Boolean extractMatch, - - @JsonProperty("match_probability") - final BigDecimal matchProbability, - - @JsonProperty("normalized_result") - final String normalizedResult, - - @JsonProperty("utterance_results") - final List> utteranceResults, - - @JsonProperty("utterance_match") - final Boolean utteranceMatch, - - @JsonProperty("predicted_label") - final String predictedLabel, - - @JsonProperty("predicted_probability") - final BigDecimal predictedProbability, - - @JsonProperty("label_probabilities") - final Map labelProbabilities, - - @JsonProperty("extract_results") - final Map extractResults, - - @JsonProperty("transcript_sid") - final String transcriptSid, - - @JsonProperty("url") - final URI url + @JsonProperty( + "operator_type" + ) final OperatorResult.OperatorType operatorType, + @JsonProperty("name") final String name, + @JsonProperty("operator_sid") final String operatorSid, + @JsonProperty("extract_match") final Boolean extractMatch, + @JsonProperty("match_probability") final BigDecimal matchProbability, + @JsonProperty("normalized_result") final String normalizedResult, + @JsonProperty( + "utterance_results" + ) final List> utteranceResults, + @JsonProperty("utterance_match") final Boolean utteranceMatch, + @JsonProperty("predicted_label") final String predictedLabel, + @JsonProperty( + "predicted_probability" + ) final BigDecimal predictedProbability, + @JsonProperty( + "label_probabilities" + ) final Map labelProbabilities, + @JsonProperty( + "extract_results" + ) final Map extractResults, + @JsonProperty("transcript_sid") final String transcriptSid, + @JsonProperty("url") final URI url ) { this.operatorType = operatorType; this.name = name; @@ -187,52 +176,65 @@ private OperatorResult( this.url = url; } - public final OperatorResult.OperatorType getOperatorType() { - return this.operatorType; - } - public final String getName() { - return this.name; - } - public final String getOperatorSid() { - return this.operatorSid; - } - public final Boolean getExtractMatch() { - return this.extractMatch; - } - public final BigDecimal getMatchProbability() { - return this.matchProbability; - } - public final String getNormalizedResult() { - return this.normalizedResult; - } - public final List> getUtteranceResults() { - return this.utteranceResults; - } - public final Boolean getUtteranceMatch() { - return this.utteranceMatch; - } - public final String getPredictedLabel() { - return this.predictedLabel; - } - public final BigDecimal getPredictedProbability() { - return this.predictedProbability; - } - public final Map getLabelProbabilities() { - return this.labelProbabilities; - } - public final Map getExtractResults() { - return this.extractResults; - } - public final String getTranscriptSid() { - return this.transcriptSid; - } - public final URI getUrl() { - return this.url; - } + public final OperatorResult.OperatorType getOperatorType() { + return this.operatorType; + } + + public final String getName() { + return this.name; + } + + public final String getOperatorSid() { + return this.operatorSid; + } + + public final Boolean getExtractMatch() { + return this.extractMatch; + } + + public final BigDecimal getMatchProbability() { + return this.matchProbability; + } + + public final String getNormalizedResult() { + return this.normalizedResult; + } + + public final List> getUtteranceResults() { + return this.utteranceResults; + } + + public final Boolean getUtteranceMatch() { + return this.utteranceMatch; + } + + public final String getPredictedLabel() { + return this.predictedLabel; + } + + public final BigDecimal getPredictedProbability() { + return this.predictedProbability; + } + + public final Map getLabelProbabilities() { + return this.labelProbabilities; + } + + public final Map getExtractResults() { + return this.extractResults; + } + + public final String getTranscriptSid() { + return this.transcriptSid; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -242,13 +244,41 @@ public boolean equals(final Object o) { OperatorResult other = (OperatorResult) o; - return Objects.equals(operatorType, other.operatorType) && Objects.equals(name, other.name) && Objects.equals(operatorSid, other.operatorSid) && Objects.equals(extractMatch, other.extractMatch) && Objects.equals(matchProbability, other.matchProbability) && Objects.equals(normalizedResult, other.normalizedResult) && Objects.equals(utteranceResults, other.utteranceResults) && Objects.equals(utteranceMatch, other.utteranceMatch) && Objects.equals(predictedLabel, other.predictedLabel) && Objects.equals(predictedProbability, other.predictedProbability) && Objects.equals(labelProbabilities, other.labelProbabilities) && Objects.equals(extractResults, other.extractResults) && Objects.equals(transcriptSid, other.transcriptSid) && Objects.equals(url, other.url) ; + return ( + Objects.equals(operatorType, other.operatorType) && + Objects.equals(name, other.name) && + Objects.equals(operatorSid, other.operatorSid) && + Objects.equals(extractMatch, other.extractMatch) && + Objects.equals(matchProbability, other.matchProbability) && + Objects.equals(normalizedResult, other.normalizedResult) && + Objects.equals(utteranceResults, other.utteranceResults) && + Objects.equals(utteranceMatch, other.utteranceMatch) && + Objects.equals(predictedLabel, other.predictedLabel) && + Objects.equals(predictedProbability, other.predictedProbability) && + Objects.equals(labelProbabilities, other.labelProbabilities) && + Objects.equals(extractResults, other.extractResults) && + Objects.equals(transcriptSid, other.transcriptSid) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(operatorType, name, operatorSid, extractMatch, matchProbability, normalizedResult, utteranceResults, utteranceMatch, predictedLabel, predictedProbability, labelProbabilities, extractResults, transcriptSid, url); + return Objects.hash( + operatorType, + name, + operatorSid, + extractMatch, + matchProbability, + normalizedResult, + utteranceResults, + utteranceMatch, + predictedLabel, + predictedProbability, + labelProbabilities, + extractResults, + transcriptSid, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/intelligence/v2/transcript/OperatorResultFetcher.java b/src/main/java/com/twilio/rest/intelligence/v2/transcript/OperatorResultFetcher.java index 543b8d5813..ac8009cc9b 100644 --- a/src/main/java/com/twilio/rest/intelligence/v2/transcript/OperatorResultFetcher.java +++ b/src/main/java/com/twilio/rest/intelligence/v2/transcript/OperatorResultFetcher.java @@ -24,30 +24,40 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class OperatorResultFetcher extends Fetcher { + private String pathTranscriptSid; private String pathOperatorSid; private Boolean redacted; - public OperatorResultFetcher(final String pathTranscriptSid, final String pathOperatorSid){ + public OperatorResultFetcher( + final String pathTranscriptSid, + final String pathOperatorSid + ) { this.pathTranscriptSid = pathTranscriptSid; this.pathOperatorSid = pathOperatorSid; } - public OperatorResultFetcher setRedacted(final Boolean redacted){ + public OperatorResultFetcher setRedacted(final Boolean redacted) { this.redacted = redacted; return this; } @Override public OperatorResult fetch(final TwilioRestClient client) { - String path = "/v2/Transcripts/{TranscriptSid}/OperatorResults/{OperatorSid}"; + String path = + "/v2/Transcripts/{TranscriptSid}/OperatorResults/{OperatorSid}"; - path = path.replace("{"+"TranscriptSid"+"}", this.pathTranscriptSid.toString()); - path = path.replace("{"+"OperatorSid"+"}", this.pathOperatorSid.toString()); + path = + path.replace( + "{" + "TranscriptSid" + "}", + this.pathTranscriptSid.toString() + ); + path = + path.replace( + "{" + "OperatorSid" + "}", + this.pathOperatorSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -58,20 +68,28 @@ public OperatorResult fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("OperatorResult fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "OperatorResult fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return OperatorResult.fromJson(response.getStream(), client.getObjectMapper()); + return OperatorResult.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addQueryParams(final Request request) { if (redacted != null) { - request.addQueryParam("Redacted", redacted.toString()); } } diff --git a/src/main/java/com/twilio/rest/intelligence/v2/transcript/OperatorResultReader.java b/src/main/java/com/twilio/rest/intelligence/v2/transcript/OperatorResultReader.java index fa6967d065..51ef80cf13 100644 --- a/src/main/java/com/twilio/rest/intelligence/v2/transcript/OperatorResultReader.java +++ b/src/main/java/com/twilio/rest/intelligence/v2/transcript/OperatorResultReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.intelligence.v2.transcript; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,24 +25,23 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class OperatorResultReader extends Reader { + private String pathTranscriptSid; private Boolean redacted; private Integer pageSize; - public OperatorResultReader(final String pathTranscriptSid){ + public OperatorResultReader(final String pathTranscriptSid) { this.pathTranscriptSid = pathTranscriptSid; } - public OperatorResultReader setRedacted(final Boolean redacted){ + public OperatorResultReader setRedacted(final Boolean redacted) { this.redacted = redacted; return this; } - public OperatorResultReader setPageSize(final Integer pageSize){ + + public OperatorResultReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -53,7 +53,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v2/Transcripts/{TranscriptSid}/OperatorResults"; - path = path.replace("{"+"TranscriptSid"+"}", this.pathTranscriptSid.toString()); + path = + path.replace( + "{" + "TranscriptSid" + "}", + this.pathTranscriptSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -65,13 +69,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("OperatorResult read failed: Unable to connect to server"); + throw new ApiConnectionException( + "OperatorResult read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -87,7 +99,10 @@ private Page pageForRequest(final TwilioRestClient client, final } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.INTELLIGENCE.toString()) @@ -95,9 +110,11 @@ public Page previousPage(final Page page, final return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.INTELLIGENCE.toString()) @@ -106,25 +123,24 @@ public Page nextPage(final Page page, final Twil } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (redacted != null) { - request.addQueryParam("Redacted", redacted.toString()); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/intelligence/v2/transcript/Sentence.java b/src/main/java/com/twilio/rest/intelligence/v2/transcript/Sentence.java index c9f2fbbc2a..5296dd6acf 100644 --- a/src/main/java/com/twilio/rest/intelligence/v2/transcript/Sentence.java +++ b/src/main/java/com/twilio/rest/intelligence/v2/transcript/Sentence.java @@ -22,36 +22,35 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; - -import java.util.Objects; - - import java.math.BigDecimal; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Sentence extends Resource { + private static final long serialVersionUID = 210633055908555L; - public static SentenceReader reader(final String pathTranscriptSid){ + public static SentenceReader reader(final String pathTranscriptSid) { return new SentenceReader(pathTranscriptSid); } /** - * Converts a JSON String into a Sentence object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Sentence object represented by the provided JSON - */ - public static Sentence fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Sentence object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Sentence object represented by the provided JSON + */ + public static Sentence fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Sentence.class); @@ -63,14 +62,17 @@ public static Sentence fromJson(final String json, final ObjectMapper objectMapp } /** - * Converts a JSON InputStream into a Sentence object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Sentence object represented by the provided JSON - */ - public static Sentence fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Sentence object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Sentence object represented by the provided JSON + */ + public static Sentence fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Sentence.class); @@ -91,26 +93,13 @@ public static Sentence fromJson(final InputStream json, final ObjectMapper objec @JsonCreator private Sentence( - @JsonProperty("media_channel") - final Integer mediaChannel, - - @JsonProperty("sentence_index") - final Integer sentenceIndex, - - @JsonProperty("start_time") - final BigDecimal startTime, - - @JsonProperty("end_time") - final BigDecimal endTime, - - @JsonProperty("transcript") - final String transcript, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("confidence") - final BigDecimal confidence + @JsonProperty("media_channel") final Integer mediaChannel, + @JsonProperty("sentence_index") final Integer sentenceIndex, + @JsonProperty("start_time") final BigDecimal startTime, + @JsonProperty("end_time") final BigDecimal endTime, + @JsonProperty("transcript") final String transcript, + @JsonProperty("sid") final String sid, + @JsonProperty("confidence") final BigDecimal confidence ) { this.mediaChannel = mediaChannel; this.sentenceIndex = sentenceIndex; @@ -121,31 +110,37 @@ private Sentence( this.confidence = confidence; } - public final Integer getMediaChannel() { - return this.mediaChannel; - } - public final Integer getSentenceIndex() { - return this.sentenceIndex; - } - public final BigDecimal getStartTime() { - return this.startTime; - } - public final BigDecimal getEndTime() { - return this.endTime; - } - public final String getTranscript() { - return this.transcript; - } - public final String getSid() { - return this.sid; - } - public final BigDecimal getConfidence() { - return this.confidence; - } + public final Integer getMediaChannel() { + return this.mediaChannel; + } + + public final Integer getSentenceIndex() { + return this.sentenceIndex; + } + + public final BigDecimal getStartTime() { + return this.startTime; + } + + public final BigDecimal getEndTime() { + return this.endTime; + } + + public final String getTranscript() { + return this.transcript; + } + + public final String getSid() { + return this.sid; + } + + public final BigDecimal getConfidence() { + return this.confidence; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -155,13 +150,27 @@ public boolean equals(final Object o) { Sentence other = (Sentence) o; - return Objects.equals(mediaChannel, other.mediaChannel) && Objects.equals(sentenceIndex, other.sentenceIndex) && Objects.equals(startTime, other.startTime) && Objects.equals(endTime, other.endTime) && Objects.equals(transcript, other.transcript) && Objects.equals(sid, other.sid) && Objects.equals(confidence, other.confidence) ; + return ( + Objects.equals(mediaChannel, other.mediaChannel) && + Objects.equals(sentenceIndex, other.sentenceIndex) && + Objects.equals(startTime, other.startTime) && + Objects.equals(endTime, other.endTime) && + Objects.equals(transcript, other.transcript) && + Objects.equals(sid, other.sid) && + Objects.equals(confidence, other.confidence) + ); } @Override public int hashCode() { - return Objects.hash(mediaChannel, sentenceIndex, startTime, endTime, transcript, sid, confidence); + return Objects.hash( + mediaChannel, + sentenceIndex, + startTime, + endTime, + transcript, + sid, + confidence + ); } - } - diff --git a/src/main/java/com/twilio/rest/intelligence/v2/transcript/SentenceReader.java b/src/main/java/com/twilio/rest/intelligence/v2/transcript/SentenceReader.java index d4dae64035..c6acf9a5df 100644 --- a/src/main/java/com/twilio/rest/intelligence/v2/transcript/SentenceReader.java +++ b/src/main/java/com/twilio/rest/intelligence/v2/transcript/SentenceReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.intelligence.v2.transcript; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,24 +25,23 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class SentenceReader extends Reader { + private String pathTranscriptSid; private Boolean redacted; private Integer pageSize; - public SentenceReader(final String pathTranscriptSid){ + public SentenceReader(final String pathTranscriptSid) { this.pathTranscriptSid = pathTranscriptSid; } - public SentenceReader setRedacted(final Boolean redacted){ + public SentenceReader setRedacted(final Boolean redacted) { this.redacted = redacted; return this; } - public SentenceReader setPageSize(final Integer pageSize){ + + public SentenceReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -53,7 +53,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v2/Transcripts/{TranscriptSid}/Sentences"; - path = path.replace("{"+"TranscriptSid"+"}", this.pathTranscriptSid.toString()); + path = + path.replace( + "{" + "TranscriptSid" + "}", + this.pathTranscriptSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -65,13 +69,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Sentence read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Sentence read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -87,7 +99,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reque } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.INTELLIGENCE.toString()) @@ -95,9 +110,11 @@ public Page previousPage(final Page page, final TwilioRestCl return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.INTELLIGENCE.toString()) @@ -106,25 +123,24 @@ public Page nextPage(final Page page, final TwilioRestClient } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (redacted != null) { - request.addQueryParam("Redacted", redacted.toString()); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/Credential.java b/src/main/java/com/twilio/rest/ipmessaging/v1/Credential.java index e99e4d2b59..1b29bd2cf5 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/Credential.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/Credential.java @@ -24,53 +24,52 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Credential extends Resource { + private static final long serialVersionUID = 161183169234848L; - public static CredentialCreator creator(final Credential.PushService type){ + public static CredentialCreator creator(final Credential.PushService type) { return new CredentialCreator(type); } - public static CredentialDeleter deleter(final String pathSid){ + public static CredentialDeleter deleter(final String pathSid) { return new CredentialDeleter(pathSid); } - public static CredentialFetcher fetcher(final String pathSid){ + public static CredentialFetcher fetcher(final String pathSid) { return new CredentialFetcher(pathSid); } - public static CredentialReader reader(){ + public static CredentialReader reader() { return new CredentialReader(); } - public static CredentialUpdater updater(final String pathSid){ + public static CredentialUpdater updater(final String pathSid) { return new CredentialUpdater(pathSid); } /** - * Converts a JSON String into a Credential object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Credential object represented by the provided JSON - */ - public static Credential fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Credential object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Credential object represented by the provided JSON + */ + public static Credential fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Credential.class); @@ -82,14 +81,17 @@ public static Credential fromJson(final String json, final ObjectMapper objectMa } /** - * Converts a JSON InputStream into a Credential object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Credential object represented by the provided JSON - */ - public static Credential fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Credential object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Credential object represented by the provided JSON + */ + public static Credential fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Credential.class); @@ -99,6 +101,7 @@ public static Credential fromJson(final InputStream json, final ObjectMapper obj throw new ApiConnectionException(e.getMessage(), e); } } + public enum PushService { GCM("gcm"), APN("apn"), @@ -131,29 +134,14 @@ public static PushService forValue(final String value) { @JsonCreator private Credential( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("type") - final Credential.PushService type, - - @JsonProperty("sandbox") - final String sandbox, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("type") final Credential.PushService type, + @JsonProperty("sandbox") final String sandbox, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url ) { this.sid = sid; this.accountSid = accountSid; @@ -165,34 +153,41 @@ private Credential( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final Credential.PushService getType() { - return this.type; - } - public final String getSandbox() { - return this.sandbox; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final Credential.PushService getType() { + return this.type; + } + + public final String getSandbox() { + return this.sandbox; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -202,13 +197,29 @@ public boolean equals(final Object o) { Credential other = (Credential) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(type, other.type) && Objects.equals(sandbox, other.sandbox) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(type, other.type) && + Objects.equals(sandbox, other.sandbox) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, friendlyName, type, sandbox, dateCreated, dateUpdated, url); + return Objects.hash( + sid, + accountSid, + friendlyName, + type, + sandbox, + dateCreated, + dateUpdated, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/CredentialCreator.java b/src/main/java/com/twilio/rest/ipmessaging/v1/CredentialCreator.java index 7fce43ffc3..0d07332ba4 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/CredentialCreator.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/CredentialCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.ipmessaging.v1; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class CredentialCreator extends Creator { - - -public class CredentialCreator extends Creator{ private Credential.PushService type; private String friendlyName; private String certificate; @@ -40,88 +39,97 @@ public CredentialCreator(final Credential.PushService type) { this.type = type; } - public CredentialCreator setType(final Credential.PushService type){ + public CredentialCreator setType(final Credential.PushService type) { this.type = type; return this; } - public CredentialCreator setFriendlyName(final String friendlyName){ + + public CredentialCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public CredentialCreator setCertificate(final String certificate){ + + public CredentialCreator setCertificate(final String certificate) { this.certificate = certificate; return this; } - public CredentialCreator setPrivateKey(final String privateKey){ + + public CredentialCreator setPrivateKey(final String privateKey) { this.privateKey = privateKey; return this; } - public CredentialCreator setSandbox(final Boolean sandbox){ + + public CredentialCreator setSandbox(final Boolean sandbox) { this.sandbox = sandbox; return this; } - public CredentialCreator setApiKey(final String apiKey){ + + public CredentialCreator setApiKey(final String apiKey) { this.apiKey = apiKey; return this; } - public CredentialCreator setSecret(final String secret){ + + public CredentialCreator setSecret(final String secret) { this.secret = secret; return this; } @Override - public Credential create(final TwilioRestClient client){ + public Credential create(final TwilioRestClient client) { String path = "/v1/Credentials"; - path = path.replace("{"+"Type"+"}", this.type.toString()); + path = path.replace("{" + "Type" + "}", this.type.toString()); Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Credential creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Credential creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Credential.fromJson(response.getStream(), client.getObjectMapper()); + return Credential.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (type != null) { request.addPostParam("Type", type.toString()); - } if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (certificate != null) { request.addPostParam("Certificate", certificate); - } if (privateKey != null) { request.addPostParam("PrivateKey", privateKey); - } if (sandbox != null) { request.addPostParam("Sandbox", sandbox.toString()); - } if (apiKey != null) { request.addPostParam("ApiKey", apiKey); - } if (secret != null) { request.addPostParam("Secret", secret); - } } } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/CredentialDeleter.java b/src/main/java/com/twilio/rest/ipmessaging/v1/CredentialDeleter.java index 363fd7eaaa..c53aa2d0e8 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/CredentialDeleter.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/CredentialDeleter.java @@ -24,21 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class CredentialDeleter extends Deleter { + private String pathSid; - public CredentialDeleter(final String pathSid){ + public CredentialDeleter(final String pathSid) { this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Credentials/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -48,9 +46,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Credential delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Credential delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/CredentialFetcher.java b/src/main/java/com/twilio/rest/ipmessaging/v1/CredentialFetcher.java index 6f5f52bb02..ddd0c8ae43 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/CredentialFetcher.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/CredentialFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class CredentialFetcher extends Fetcher { + private String pathSid; - public CredentialFetcher(final String pathSid){ + public CredentialFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public Credential fetch(final TwilioRestClient client) { String path = "/v1/Credentials/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,15 +46,23 @@ public Credential fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Credential fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Credential fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Credential.fromJson(response.getStream(), client.getObjectMapper()); + return Credential.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/CredentialReader.java b/src/main/java/com/twilio/rest/ipmessaging/v1/CredentialReader.java index 4a3cf4d396..532cfbac61 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/CredentialReader.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/CredentialReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.ipmessaging.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,17 +25,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class CredentialReader extends Reader { + private Integer pageSize; - public CredentialReader(){ - } + public CredentialReader() {} - public CredentialReader setPageSize(final Integer pageSize){ + public CredentialReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -57,13 +55,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Credential read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Credential read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -79,7 +85,10 @@ private Page pageForRequest(final TwilioRestClient client, final Req } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.IPMESSAGING.toString()) @@ -87,9 +96,11 @@ public Page previousPage(final Page page, final TwilioRe return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.IPMESSAGING.toString()) @@ -98,21 +109,21 @@ public Page nextPage(final Page page, final TwilioRestCl } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/CredentialUpdater.java b/src/main/java/com/twilio/rest/ipmessaging/v1/CredentialUpdater.java index 32189745e3..e44d1a5b1f 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/CredentialUpdater.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/CredentialUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.ipmessaging.v1; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class CredentialUpdater extends Updater { - - -public class CredentialUpdater extends Updater{ private String pathSid; private String friendlyName; private String certificate; @@ -36,84 +35,93 @@ public class CredentialUpdater extends Updater{ private String apiKey; private String secret; - public CredentialUpdater(final String pathSid){ + public CredentialUpdater(final String pathSid) { this.pathSid = pathSid; } - public CredentialUpdater setFriendlyName(final String friendlyName){ + public CredentialUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public CredentialUpdater setCertificate(final String certificate){ + + public CredentialUpdater setCertificate(final String certificate) { this.certificate = certificate; return this; } - public CredentialUpdater setPrivateKey(final String privateKey){ + + public CredentialUpdater setPrivateKey(final String privateKey) { this.privateKey = privateKey; return this; } - public CredentialUpdater setSandbox(final Boolean sandbox){ + + public CredentialUpdater setSandbox(final Boolean sandbox) { this.sandbox = sandbox; return this; } - public CredentialUpdater setApiKey(final String apiKey){ + + public CredentialUpdater setApiKey(final String apiKey) { this.apiKey = apiKey; return this; } - public CredentialUpdater setSecret(final String secret){ + + public CredentialUpdater setSecret(final String secret) { this.secret = secret; return this; } @Override - public Credential update(final TwilioRestClient client){ + public Credential update(final TwilioRestClient client) { String path = "/v1/Credentials/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Credential update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Credential update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Credential.fromJson(response.getStream(), client.getObjectMapper()); + return Credential.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (certificate != null) { request.addPostParam("Certificate", certificate); - } if (privateKey != null) { request.addPostParam("PrivateKey", privateKey); - } if (sandbox != null) { request.addPostParam("Sandbox", sandbox.toString()); - } if (apiKey != null) { request.addPostParam("ApiKey", apiKey); - } if (secret != null) { request.addPostParam("Secret", secret); - } } } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/Service.java b/src/main/java/com/twilio/rest/ipmessaging/v1/Service.java index 2185e6b23e..d2ffa157c9 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/Service.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/Service.java @@ -23,56 +23,55 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.List; import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Service extends Resource { + private static final long serialVersionUID = 258386577185944L; - public static ServiceCreator creator(final String friendlyName){ + public static ServiceCreator creator(final String friendlyName) { return new ServiceCreator(friendlyName); } - public static ServiceDeleter deleter(final String pathSid){ + public static ServiceDeleter deleter(final String pathSid) { return new ServiceDeleter(pathSid); } - public static ServiceFetcher fetcher(final String pathSid){ + public static ServiceFetcher fetcher(final String pathSid) { return new ServiceFetcher(pathSid); } - public static ServiceReader reader(){ + public static ServiceReader reader() { return new ServiceReader(); } - public static ServiceUpdater updater(final String pathSid){ + public static ServiceUpdater updater(final String pathSid) { return new ServiceUpdater(pathSid); } /** - * Converts a JSON String into a Service object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Service object represented by the provided JSON - */ - public static Service fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Service object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Service object represented by the provided JSON + */ + public static Service fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Service.class); @@ -84,14 +83,17 @@ public static Service fromJson(final String json, final ObjectMapper objectMappe } /** - * Converts a JSON InputStream into a Service object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Service object represented by the provided JSON - */ - public static Service fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Service object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Service object represented by the provided JSON + */ + public static Service fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Service.class); @@ -126,68 +128,37 @@ public static Service fromJson(final InputStream json, final ObjectMapper object @JsonCreator private Service( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("default_service_role_sid") - final String defaultServiceRoleSid, - - @JsonProperty("default_channel_role_sid") - final String defaultChannelRoleSid, - - @JsonProperty("default_channel_creator_role_sid") - final String defaultChannelCreatorRoleSid, - - @JsonProperty("read_status_enabled") - final Boolean readStatusEnabled, - - @JsonProperty("reachability_enabled") - final Boolean reachabilityEnabled, - - @JsonProperty("typing_indicator_timeout") - final Integer typingIndicatorTimeout, - - @JsonProperty("consumption_report_interval") - final Integer consumptionReportInterval, - - @JsonProperty("limits") - final Map limits, - - @JsonProperty("webhooks") - final Map webhooks, - - @JsonProperty("pre_webhook_url") - final String preWebhookUrl, - - @JsonProperty("post_webhook_url") - final String postWebhookUrl, - - @JsonProperty("webhook_method") - final String webhookMethod, - - @JsonProperty("webhook_filters") - final List webhookFilters, - - @JsonProperty("notifications") - final Map notifications, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty( + "default_service_role_sid" + ) final String defaultServiceRoleSid, + @JsonProperty( + "default_channel_role_sid" + ) final String defaultChannelRoleSid, + @JsonProperty( + "default_channel_creator_role_sid" + ) final String defaultChannelCreatorRoleSid, + @JsonProperty("read_status_enabled") final Boolean readStatusEnabled, + @JsonProperty("reachability_enabled") final Boolean reachabilityEnabled, + @JsonProperty( + "typing_indicator_timeout" + ) final Integer typingIndicatorTimeout, + @JsonProperty( + "consumption_report_interval" + ) final Integer consumptionReportInterval, + @JsonProperty("limits") final Map limits, + @JsonProperty("webhooks") final Map webhooks, + @JsonProperty("pre_webhook_url") final String preWebhookUrl, + @JsonProperty("post_webhook_url") final String postWebhookUrl, + @JsonProperty("webhook_method") final String webhookMethod, + @JsonProperty("webhook_filters") final List webhookFilters, + @JsonProperty("notifications") final Map notifications, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.sid = sid; this.accountSid = accountSid; @@ -212,73 +183,93 @@ private Service( this.links = links; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getDefaultServiceRoleSid() { - return this.defaultServiceRoleSid; - } - public final String getDefaultChannelRoleSid() { - return this.defaultChannelRoleSid; - } - public final String getDefaultChannelCreatorRoleSid() { - return this.defaultChannelCreatorRoleSid; - } - public final Boolean getReadStatusEnabled() { - return this.readStatusEnabled; - } - public final Boolean getReachabilityEnabled() { - return this.reachabilityEnabled; - } - public final Integer getTypingIndicatorTimeout() { - return this.typingIndicatorTimeout; - } - public final Integer getConsumptionReportInterval() { - return this.consumptionReportInterval; - } - public final Map getLimits() { - return this.limits; - } - public final Map getWebhooks() { - return this.webhooks; - } - public final String getPreWebhookUrl() { - return this.preWebhookUrl; - } - public final String getPostWebhookUrl() { - return this.postWebhookUrl; - } - public final String getWebhookMethod() { - return this.webhookMethod; - } - public final List getWebhookFilters() { - return this.webhookFilters; - } - public final Map getNotifications() { - return this.notifications; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getDefaultServiceRoleSid() { + return this.defaultServiceRoleSid; + } + + public final String getDefaultChannelRoleSid() { + return this.defaultChannelRoleSid; + } + + public final String getDefaultChannelCreatorRoleSid() { + return this.defaultChannelCreatorRoleSid; + } + + public final Boolean getReadStatusEnabled() { + return this.readStatusEnabled; + } + + public final Boolean getReachabilityEnabled() { + return this.reachabilityEnabled; + } + + public final Integer getTypingIndicatorTimeout() { + return this.typingIndicatorTimeout; + } + + public final Integer getConsumptionReportInterval() { + return this.consumptionReportInterval; + } + + public final Map getLimits() { + return this.limits; + } + + public final Map getWebhooks() { + return this.webhooks; + } + + public final String getPreWebhookUrl() { + return this.preWebhookUrl; + } + + public final String getPostWebhookUrl() { + return this.postWebhookUrl; + } + + public final String getWebhookMethod() { + return this.webhookMethod; + } + + public final List getWebhookFilters() { + return this.webhookFilters; + } + + public final Map getNotifications() { + return this.notifications; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -288,13 +279,70 @@ public boolean equals(final Object o) { Service other = (Service) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(defaultServiceRoleSid, other.defaultServiceRoleSid) && Objects.equals(defaultChannelRoleSid, other.defaultChannelRoleSid) && Objects.equals(defaultChannelCreatorRoleSid, other.defaultChannelCreatorRoleSid) && Objects.equals(readStatusEnabled, other.readStatusEnabled) && Objects.equals(reachabilityEnabled, other.reachabilityEnabled) && Objects.equals(typingIndicatorTimeout, other.typingIndicatorTimeout) && Objects.equals(consumptionReportInterval, other.consumptionReportInterval) && Objects.equals(limits, other.limits) && Objects.equals(webhooks, other.webhooks) && Objects.equals(preWebhookUrl, other.preWebhookUrl) && Objects.equals(postWebhookUrl, other.postWebhookUrl) && Objects.equals(webhookMethod, other.webhookMethod) && Objects.equals(webhookFilters, other.webhookFilters) && Objects.equals(notifications, other.notifications) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals( + defaultServiceRoleSid, + other.defaultServiceRoleSid + ) && + Objects.equals( + defaultChannelRoleSid, + other.defaultChannelRoleSid + ) && + Objects.equals( + defaultChannelCreatorRoleSid, + other.defaultChannelCreatorRoleSid + ) && + Objects.equals(readStatusEnabled, other.readStatusEnabled) && + Objects.equals(reachabilityEnabled, other.reachabilityEnabled) && + Objects.equals( + typingIndicatorTimeout, + other.typingIndicatorTimeout + ) && + Objects.equals( + consumptionReportInterval, + other.consumptionReportInterval + ) && + Objects.equals(limits, other.limits) && + Objects.equals(webhooks, other.webhooks) && + Objects.equals(preWebhookUrl, other.preWebhookUrl) && + Objects.equals(postWebhookUrl, other.postWebhookUrl) && + Objects.equals(webhookMethod, other.webhookMethod) && + Objects.equals(webhookFilters, other.webhookFilters) && + Objects.equals(notifications, other.notifications) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, friendlyName, dateCreated, dateUpdated, defaultServiceRoleSid, defaultChannelRoleSid, defaultChannelCreatorRoleSid, readStatusEnabled, reachabilityEnabled, typingIndicatorTimeout, consumptionReportInterval, limits, webhooks, preWebhookUrl, postWebhookUrl, webhookMethod, webhookFilters, notifications, url, links); + return Objects.hash( + sid, + accountSid, + friendlyName, + dateCreated, + dateUpdated, + defaultServiceRoleSid, + defaultChannelRoleSid, + defaultChannelCreatorRoleSid, + readStatusEnabled, + reachabilityEnabled, + typingIndicatorTimeout, + consumptionReportInterval, + limits, + webhooks, + preWebhookUrl, + postWebhookUrl, + webhookMethod, + webhookFilters, + notifications, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/ServiceCreator.java b/src/main/java/com/twilio/rest/ipmessaging/v1/ServiceCreator.java index 8e54399414..add1872f71 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/ServiceCreator.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/ServiceCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.ipmessaging.v1; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,38 +25,46 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class ServiceCreator extends Creator { - - -public class ServiceCreator extends Creator{ private String friendlyName; public ServiceCreator(final String friendlyName) { this.friendlyName = friendlyName; } - public ServiceCreator setFriendlyName(final String friendlyName){ + public ServiceCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } @Override - public Service create(final TwilioRestClient client){ + public Service create(final TwilioRestClient client) { String path = "/v1/Services"; - path = path.replace("{"+"FriendlyName"+"}", this.friendlyName.toString()); + path = + path.replace( + "{" + "FriendlyName" + "}", + this.friendlyName.toString() + ); Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -64,10 +73,10 @@ public Service create(final TwilioRestClient client){ return Service.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } } } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/ServiceDeleter.java b/src/main/java/com/twilio/rest/ipmessaging/v1/ServiceDeleter.java index c013388efc..c62cb59f03 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/ServiceDeleter.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/ServiceDeleter.java @@ -24,21 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class ServiceDeleter extends Deleter { + private String pathSid; - public ServiceDeleter(final String pathSid){ + public ServiceDeleter(final String pathSid) { this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Services/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -48,9 +46,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/ServiceFetcher.java b/src/main/java/com/twilio/rest/ipmessaging/v1/ServiceFetcher.java index ebb5e4a3f5..c92c2aadb5 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/ServiceFetcher.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/ServiceFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class ServiceFetcher extends Fetcher { + private String pathSid; - public ServiceFetcher(final String pathSid){ + public ServiceFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public Service fetch(final TwilioRestClient client) { String path = "/v1/Services/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,9 +46,14 @@ public Service fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/ServiceReader.java b/src/main/java/com/twilio/rest/ipmessaging/v1/ServiceReader.java index 01119635ed..1d632dbc46 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/ServiceReader.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/ServiceReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.ipmessaging.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,17 +25,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class ServiceReader extends Reader { + private Integer pageSize; - public ServiceReader(){ - } + public ServiceReader() {} - public ServiceReader setPageSize(final Integer pageSize){ + public ServiceReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -57,13 +55,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -79,7 +85,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reques } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.IPMESSAGING.toString()) @@ -87,9 +96,11 @@ public Page previousPage(final Page page, final TwilioRestClie return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.IPMESSAGING.toString()) @@ -98,21 +109,21 @@ public Page nextPage(final Page page, final TwilioRestClient c } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/ServiceUpdater.java b/src/main/java/com/twilio/rest/ipmessaging/v1/ServiceUpdater.java index fe5bfbd976..82e4105998 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/ServiceUpdater.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/ServiceUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.ipmessaging.v1; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -24,13 +25,11 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.net.URI; - import java.util.List; +public class ServiceUpdater extends Updater { -public class ServiceUpdater extends Updater{ private String pathSid; private String friendlyName; private String defaultServiceRoleSid; @@ -87,319 +86,548 @@ public class ServiceUpdater extends Updater{ private Integer limitsChannelMembers; private Integer limitsUserChannels; - public ServiceUpdater(final String pathSid){ + public ServiceUpdater(final String pathSid) { this.pathSid = pathSid; } - public ServiceUpdater setFriendlyName(final String friendlyName){ + public ServiceUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public ServiceUpdater setDefaultServiceRoleSid(final String defaultServiceRoleSid){ + + public ServiceUpdater setDefaultServiceRoleSid( + final String defaultServiceRoleSid + ) { this.defaultServiceRoleSid = defaultServiceRoleSid; return this; } - public ServiceUpdater setDefaultChannelRoleSid(final String defaultChannelRoleSid){ + + public ServiceUpdater setDefaultChannelRoleSid( + final String defaultChannelRoleSid + ) { this.defaultChannelRoleSid = defaultChannelRoleSid; return this; } - public ServiceUpdater setDefaultChannelCreatorRoleSid(final String defaultChannelCreatorRoleSid){ + + public ServiceUpdater setDefaultChannelCreatorRoleSid( + final String defaultChannelCreatorRoleSid + ) { this.defaultChannelCreatorRoleSid = defaultChannelCreatorRoleSid; return this; } - public ServiceUpdater setReadStatusEnabled(final Boolean readStatusEnabled){ + + public ServiceUpdater setReadStatusEnabled( + final Boolean readStatusEnabled + ) { this.readStatusEnabled = readStatusEnabled; return this; } - public ServiceUpdater setReachabilityEnabled(final Boolean reachabilityEnabled){ + + public ServiceUpdater setReachabilityEnabled( + final Boolean reachabilityEnabled + ) { this.reachabilityEnabled = reachabilityEnabled; return this; } - public ServiceUpdater setTypingIndicatorTimeout(final Integer typingIndicatorTimeout){ + + public ServiceUpdater setTypingIndicatorTimeout( + final Integer typingIndicatorTimeout + ) { this.typingIndicatorTimeout = typingIndicatorTimeout; return this; } - public ServiceUpdater setConsumptionReportInterval(final Integer consumptionReportInterval){ + + public ServiceUpdater setConsumptionReportInterval( + final Integer consumptionReportInterval + ) { this.consumptionReportInterval = consumptionReportInterval; return this; } - public ServiceUpdater setNotificationsNewMessageEnabled(final Boolean notificationsNewMessageEnabled){ + + public ServiceUpdater setNotificationsNewMessageEnabled( + final Boolean notificationsNewMessageEnabled + ) { this.notificationsNewMessageEnabled = notificationsNewMessageEnabled; return this; } - public ServiceUpdater setNotificationsNewMessageTemplate(final String notificationsNewMessageTemplate){ + + public ServiceUpdater setNotificationsNewMessageTemplate( + final String notificationsNewMessageTemplate + ) { this.notificationsNewMessageTemplate = notificationsNewMessageTemplate; return this; } - public ServiceUpdater setNotificationsAddedToChannelEnabled(final Boolean notificationsAddedToChannelEnabled){ - this.notificationsAddedToChannelEnabled = notificationsAddedToChannelEnabled; + + public ServiceUpdater setNotificationsAddedToChannelEnabled( + final Boolean notificationsAddedToChannelEnabled + ) { + this.notificationsAddedToChannelEnabled = + notificationsAddedToChannelEnabled; return this; } - public ServiceUpdater setNotificationsAddedToChannelTemplate(final String notificationsAddedToChannelTemplate){ - this.notificationsAddedToChannelTemplate = notificationsAddedToChannelTemplate; + + public ServiceUpdater setNotificationsAddedToChannelTemplate( + final String notificationsAddedToChannelTemplate + ) { + this.notificationsAddedToChannelTemplate = + notificationsAddedToChannelTemplate; return this; } - public ServiceUpdater setNotificationsRemovedFromChannelEnabled(final Boolean notificationsRemovedFromChannelEnabled){ - this.notificationsRemovedFromChannelEnabled = notificationsRemovedFromChannelEnabled; + + public ServiceUpdater setNotificationsRemovedFromChannelEnabled( + final Boolean notificationsRemovedFromChannelEnabled + ) { + this.notificationsRemovedFromChannelEnabled = + notificationsRemovedFromChannelEnabled; return this; } - public ServiceUpdater setNotificationsRemovedFromChannelTemplate(final String notificationsRemovedFromChannelTemplate){ - this.notificationsRemovedFromChannelTemplate = notificationsRemovedFromChannelTemplate; + + public ServiceUpdater setNotificationsRemovedFromChannelTemplate( + final String notificationsRemovedFromChannelTemplate + ) { + this.notificationsRemovedFromChannelTemplate = + notificationsRemovedFromChannelTemplate; return this; } - public ServiceUpdater setNotificationsInvitedToChannelEnabled(final Boolean notificationsInvitedToChannelEnabled){ - this.notificationsInvitedToChannelEnabled = notificationsInvitedToChannelEnabled; + + public ServiceUpdater setNotificationsInvitedToChannelEnabled( + final Boolean notificationsInvitedToChannelEnabled + ) { + this.notificationsInvitedToChannelEnabled = + notificationsInvitedToChannelEnabled; return this; } - public ServiceUpdater setNotificationsInvitedToChannelTemplate(final String notificationsInvitedToChannelTemplate){ - this.notificationsInvitedToChannelTemplate = notificationsInvitedToChannelTemplate; + + public ServiceUpdater setNotificationsInvitedToChannelTemplate( + final String notificationsInvitedToChannelTemplate + ) { + this.notificationsInvitedToChannelTemplate = + notificationsInvitedToChannelTemplate; return this; } - public ServiceUpdater setPreWebhookUrl(final URI preWebhookUrl){ + + public ServiceUpdater setPreWebhookUrl(final URI preWebhookUrl) { this.preWebhookUrl = preWebhookUrl; return this; } - public ServiceUpdater setPreWebhookUrl(final String preWebhookUrl){ + public ServiceUpdater setPreWebhookUrl(final String preWebhookUrl) { return setPreWebhookUrl(Promoter.uriFromString(preWebhookUrl)); } - public ServiceUpdater setPostWebhookUrl(final URI postWebhookUrl){ + + public ServiceUpdater setPostWebhookUrl(final URI postWebhookUrl) { this.postWebhookUrl = postWebhookUrl; return this; } - public ServiceUpdater setPostWebhookUrl(final String postWebhookUrl){ + public ServiceUpdater setPostWebhookUrl(final String postWebhookUrl) { return setPostWebhookUrl(Promoter.uriFromString(postWebhookUrl)); } - public ServiceUpdater setWebhookMethod(final HttpMethod webhookMethod){ + + public ServiceUpdater setWebhookMethod(final HttpMethod webhookMethod) { this.webhookMethod = webhookMethod; return this; } - public ServiceUpdater setWebhookFilters(final List webhookFilters){ + + public ServiceUpdater setWebhookFilters(final List webhookFilters) { this.webhookFilters = webhookFilters; return this; } - public ServiceUpdater setWebhookFilters(final String webhookFilters){ + + public ServiceUpdater setWebhookFilters(final String webhookFilters) { return setWebhookFilters(Promoter.listOfOne(webhookFilters)); } - public ServiceUpdater setWebhooksOnMessageSendUrl(final URI webhooksOnMessageSendUrl){ + + public ServiceUpdater setWebhooksOnMessageSendUrl( + final URI webhooksOnMessageSendUrl + ) { this.webhooksOnMessageSendUrl = webhooksOnMessageSendUrl; return this; } - public ServiceUpdater setWebhooksOnMessageSendUrl(final String webhooksOnMessageSendUrl){ - return setWebhooksOnMessageSendUrl(Promoter.uriFromString(webhooksOnMessageSendUrl)); + public ServiceUpdater setWebhooksOnMessageSendUrl( + final String webhooksOnMessageSendUrl + ) { + return setWebhooksOnMessageSendUrl( + Promoter.uriFromString(webhooksOnMessageSendUrl) + ); } - public ServiceUpdater setWebhooksOnMessageSendMethod(final HttpMethod webhooksOnMessageSendMethod){ + + public ServiceUpdater setWebhooksOnMessageSendMethod( + final HttpMethod webhooksOnMessageSendMethod + ) { this.webhooksOnMessageSendMethod = webhooksOnMessageSendMethod; return this; } - public ServiceUpdater setWebhooksOnMessageUpdateUrl(final URI webhooksOnMessageUpdateUrl){ + + public ServiceUpdater setWebhooksOnMessageUpdateUrl( + final URI webhooksOnMessageUpdateUrl + ) { this.webhooksOnMessageUpdateUrl = webhooksOnMessageUpdateUrl; return this; } - public ServiceUpdater setWebhooksOnMessageUpdateUrl(final String webhooksOnMessageUpdateUrl){ - return setWebhooksOnMessageUpdateUrl(Promoter.uriFromString(webhooksOnMessageUpdateUrl)); + public ServiceUpdater setWebhooksOnMessageUpdateUrl( + final String webhooksOnMessageUpdateUrl + ) { + return setWebhooksOnMessageUpdateUrl( + Promoter.uriFromString(webhooksOnMessageUpdateUrl) + ); } - public ServiceUpdater setWebhooksOnMessageUpdateMethod(final HttpMethod webhooksOnMessageUpdateMethod){ + + public ServiceUpdater setWebhooksOnMessageUpdateMethod( + final HttpMethod webhooksOnMessageUpdateMethod + ) { this.webhooksOnMessageUpdateMethod = webhooksOnMessageUpdateMethod; return this; } - public ServiceUpdater setWebhooksOnMessageRemoveUrl(final URI webhooksOnMessageRemoveUrl){ + + public ServiceUpdater setWebhooksOnMessageRemoveUrl( + final URI webhooksOnMessageRemoveUrl + ) { this.webhooksOnMessageRemoveUrl = webhooksOnMessageRemoveUrl; return this; } - public ServiceUpdater setWebhooksOnMessageRemoveUrl(final String webhooksOnMessageRemoveUrl){ - return setWebhooksOnMessageRemoveUrl(Promoter.uriFromString(webhooksOnMessageRemoveUrl)); + public ServiceUpdater setWebhooksOnMessageRemoveUrl( + final String webhooksOnMessageRemoveUrl + ) { + return setWebhooksOnMessageRemoveUrl( + Promoter.uriFromString(webhooksOnMessageRemoveUrl) + ); } - public ServiceUpdater setWebhooksOnMessageRemoveMethod(final HttpMethod webhooksOnMessageRemoveMethod){ + + public ServiceUpdater setWebhooksOnMessageRemoveMethod( + final HttpMethod webhooksOnMessageRemoveMethod + ) { this.webhooksOnMessageRemoveMethod = webhooksOnMessageRemoveMethod; return this; } - public ServiceUpdater setWebhooksOnChannelAddUrl(final URI webhooksOnChannelAddUrl){ + + public ServiceUpdater setWebhooksOnChannelAddUrl( + final URI webhooksOnChannelAddUrl + ) { this.webhooksOnChannelAddUrl = webhooksOnChannelAddUrl; return this; } - public ServiceUpdater setWebhooksOnChannelAddUrl(final String webhooksOnChannelAddUrl){ - return setWebhooksOnChannelAddUrl(Promoter.uriFromString(webhooksOnChannelAddUrl)); + public ServiceUpdater setWebhooksOnChannelAddUrl( + final String webhooksOnChannelAddUrl + ) { + return setWebhooksOnChannelAddUrl( + Promoter.uriFromString(webhooksOnChannelAddUrl) + ); } - public ServiceUpdater setWebhooksOnChannelAddMethod(final HttpMethod webhooksOnChannelAddMethod){ + + public ServiceUpdater setWebhooksOnChannelAddMethod( + final HttpMethod webhooksOnChannelAddMethod + ) { this.webhooksOnChannelAddMethod = webhooksOnChannelAddMethod; return this; } - public ServiceUpdater setWebhooksOnChannelDestroyUrl(final URI webhooksOnChannelDestroyUrl){ + + public ServiceUpdater setWebhooksOnChannelDestroyUrl( + final URI webhooksOnChannelDestroyUrl + ) { this.webhooksOnChannelDestroyUrl = webhooksOnChannelDestroyUrl; return this; } - public ServiceUpdater setWebhooksOnChannelDestroyUrl(final String webhooksOnChannelDestroyUrl){ - return setWebhooksOnChannelDestroyUrl(Promoter.uriFromString(webhooksOnChannelDestroyUrl)); + public ServiceUpdater setWebhooksOnChannelDestroyUrl( + final String webhooksOnChannelDestroyUrl + ) { + return setWebhooksOnChannelDestroyUrl( + Promoter.uriFromString(webhooksOnChannelDestroyUrl) + ); } - public ServiceUpdater setWebhooksOnChannelDestroyMethod(final HttpMethod webhooksOnChannelDestroyMethod){ + + public ServiceUpdater setWebhooksOnChannelDestroyMethod( + final HttpMethod webhooksOnChannelDestroyMethod + ) { this.webhooksOnChannelDestroyMethod = webhooksOnChannelDestroyMethod; return this; } - public ServiceUpdater setWebhooksOnChannelUpdateUrl(final URI webhooksOnChannelUpdateUrl){ + + public ServiceUpdater setWebhooksOnChannelUpdateUrl( + final URI webhooksOnChannelUpdateUrl + ) { this.webhooksOnChannelUpdateUrl = webhooksOnChannelUpdateUrl; return this; } - public ServiceUpdater setWebhooksOnChannelUpdateUrl(final String webhooksOnChannelUpdateUrl){ - return setWebhooksOnChannelUpdateUrl(Promoter.uriFromString(webhooksOnChannelUpdateUrl)); + public ServiceUpdater setWebhooksOnChannelUpdateUrl( + final String webhooksOnChannelUpdateUrl + ) { + return setWebhooksOnChannelUpdateUrl( + Promoter.uriFromString(webhooksOnChannelUpdateUrl) + ); } - public ServiceUpdater setWebhooksOnChannelUpdateMethod(final HttpMethod webhooksOnChannelUpdateMethod){ + + public ServiceUpdater setWebhooksOnChannelUpdateMethod( + final HttpMethod webhooksOnChannelUpdateMethod + ) { this.webhooksOnChannelUpdateMethod = webhooksOnChannelUpdateMethod; return this; } - public ServiceUpdater setWebhooksOnMemberAddUrl(final URI webhooksOnMemberAddUrl){ + + public ServiceUpdater setWebhooksOnMemberAddUrl( + final URI webhooksOnMemberAddUrl + ) { this.webhooksOnMemberAddUrl = webhooksOnMemberAddUrl; return this; } - public ServiceUpdater setWebhooksOnMemberAddUrl(final String webhooksOnMemberAddUrl){ - return setWebhooksOnMemberAddUrl(Promoter.uriFromString(webhooksOnMemberAddUrl)); + public ServiceUpdater setWebhooksOnMemberAddUrl( + final String webhooksOnMemberAddUrl + ) { + return setWebhooksOnMemberAddUrl( + Promoter.uriFromString(webhooksOnMemberAddUrl) + ); } - public ServiceUpdater setWebhooksOnMemberAddMethod(final HttpMethod webhooksOnMemberAddMethod){ + + public ServiceUpdater setWebhooksOnMemberAddMethod( + final HttpMethod webhooksOnMemberAddMethod + ) { this.webhooksOnMemberAddMethod = webhooksOnMemberAddMethod; return this; } - public ServiceUpdater setWebhooksOnMemberRemoveUrl(final URI webhooksOnMemberRemoveUrl){ + + public ServiceUpdater setWebhooksOnMemberRemoveUrl( + final URI webhooksOnMemberRemoveUrl + ) { this.webhooksOnMemberRemoveUrl = webhooksOnMemberRemoveUrl; return this; } - public ServiceUpdater setWebhooksOnMemberRemoveUrl(final String webhooksOnMemberRemoveUrl){ - return setWebhooksOnMemberRemoveUrl(Promoter.uriFromString(webhooksOnMemberRemoveUrl)); + public ServiceUpdater setWebhooksOnMemberRemoveUrl( + final String webhooksOnMemberRemoveUrl + ) { + return setWebhooksOnMemberRemoveUrl( + Promoter.uriFromString(webhooksOnMemberRemoveUrl) + ); } - public ServiceUpdater setWebhooksOnMemberRemoveMethod(final HttpMethod webhooksOnMemberRemoveMethod){ + + public ServiceUpdater setWebhooksOnMemberRemoveMethod( + final HttpMethod webhooksOnMemberRemoveMethod + ) { this.webhooksOnMemberRemoveMethod = webhooksOnMemberRemoveMethod; return this; } - public ServiceUpdater setWebhooksOnMessageSentUrl(final URI webhooksOnMessageSentUrl){ + + public ServiceUpdater setWebhooksOnMessageSentUrl( + final URI webhooksOnMessageSentUrl + ) { this.webhooksOnMessageSentUrl = webhooksOnMessageSentUrl; return this; } - public ServiceUpdater setWebhooksOnMessageSentUrl(final String webhooksOnMessageSentUrl){ - return setWebhooksOnMessageSentUrl(Promoter.uriFromString(webhooksOnMessageSentUrl)); + public ServiceUpdater setWebhooksOnMessageSentUrl( + final String webhooksOnMessageSentUrl + ) { + return setWebhooksOnMessageSentUrl( + Promoter.uriFromString(webhooksOnMessageSentUrl) + ); } - public ServiceUpdater setWebhooksOnMessageSentMethod(final HttpMethod webhooksOnMessageSentMethod){ + + public ServiceUpdater setWebhooksOnMessageSentMethod( + final HttpMethod webhooksOnMessageSentMethod + ) { this.webhooksOnMessageSentMethod = webhooksOnMessageSentMethod; return this; } - public ServiceUpdater setWebhooksOnMessageUpdatedUrl(final URI webhooksOnMessageUpdatedUrl){ + + public ServiceUpdater setWebhooksOnMessageUpdatedUrl( + final URI webhooksOnMessageUpdatedUrl + ) { this.webhooksOnMessageUpdatedUrl = webhooksOnMessageUpdatedUrl; return this; } - public ServiceUpdater setWebhooksOnMessageUpdatedUrl(final String webhooksOnMessageUpdatedUrl){ - return setWebhooksOnMessageUpdatedUrl(Promoter.uriFromString(webhooksOnMessageUpdatedUrl)); + public ServiceUpdater setWebhooksOnMessageUpdatedUrl( + final String webhooksOnMessageUpdatedUrl + ) { + return setWebhooksOnMessageUpdatedUrl( + Promoter.uriFromString(webhooksOnMessageUpdatedUrl) + ); } - public ServiceUpdater setWebhooksOnMessageUpdatedMethod(final HttpMethod webhooksOnMessageUpdatedMethod){ + + public ServiceUpdater setWebhooksOnMessageUpdatedMethod( + final HttpMethod webhooksOnMessageUpdatedMethod + ) { this.webhooksOnMessageUpdatedMethod = webhooksOnMessageUpdatedMethod; return this; } - public ServiceUpdater setWebhooksOnMessageRemovedUrl(final URI webhooksOnMessageRemovedUrl){ + + public ServiceUpdater setWebhooksOnMessageRemovedUrl( + final URI webhooksOnMessageRemovedUrl + ) { this.webhooksOnMessageRemovedUrl = webhooksOnMessageRemovedUrl; return this; } - public ServiceUpdater setWebhooksOnMessageRemovedUrl(final String webhooksOnMessageRemovedUrl){ - return setWebhooksOnMessageRemovedUrl(Promoter.uriFromString(webhooksOnMessageRemovedUrl)); + public ServiceUpdater setWebhooksOnMessageRemovedUrl( + final String webhooksOnMessageRemovedUrl + ) { + return setWebhooksOnMessageRemovedUrl( + Promoter.uriFromString(webhooksOnMessageRemovedUrl) + ); } - public ServiceUpdater setWebhooksOnMessageRemovedMethod(final HttpMethod webhooksOnMessageRemovedMethod){ + + public ServiceUpdater setWebhooksOnMessageRemovedMethod( + final HttpMethod webhooksOnMessageRemovedMethod + ) { this.webhooksOnMessageRemovedMethod = webhooksOnMessageRemovedMethod; return this; } - public ServiceUpdater setWebhooksOnChannelAddedUrl(final URI webhooksOnChannelAddedUrl){ + + public ServiceUpdater setWebhooksOnChannelAddedUrl( + final URI webhooksOnChannelAddedUrl + ) { this.webhooksOnChannelAddedUrl = webhooksOnChannelAddedUrl; return this; } - public ServiceUpdater setWebhooksOnChannelAddedUrl(final String webhooksOnChannelAddedUrl){ - return setWebhooksOnChannelAddedUrl(Promoter.uriFromString(webhooksOnChannelAddedUrl)); + public ServiceUpdater setWebhooksOnChannelAddedUrl( + final String webhooksOnChannelAddedUrl + ) { + return setWebhooksOnChannelAddedUrl( + Promoter.uriFromString(webhooksOnChannelAddedUrl) + ); } - public ServiceUpdater setWebhooksOnChannelAddedMethod(final HttpMethod webhooksOnChannelAddedMethod){ + + public ServiceUpdater setWebhooksOnChannelAddedMethod( + final HttpMethod webhooksOnChannelAddedMethod + ) { this.webhooksOnChannelAddedMethod = webhooksOnChannelAddedMethod; return this; } - public ServiceUpdater setWebhooksOnChannelDestroyedUrl(final URI webhooksOnChannelDestroyedUrl){ + + public ServiceUpdater setWebhooksOnChannelDestroyedUrl( + final URI webhooksOnChannelDestroyedUrl + ) { this.webhooksOnChannelDestroyedUrl = webhooksOnChannelDestroyedUrl; return this; } - public ServiceUpdater setWebhooksOnChannelDestroyedUrl(final String webhooksOnChannelDestroyedUrl){ - return setWebhooksOnChannelDestroyedUrl(Promoter.uriFromString(webhooksOnChannelDestroyedUrl)); + public ServiceUpdater setWebhooksOnChannelDestroyedUrl( + final String webhooksOnChannelDestroyedUrl + ) { + return setWebhooksOnChannelDestroyedUrl( + Promoter.uriFromString(webhooksOnChannelDestroyedUrl) + ); } - public ServiceUpdater setWebhooksOnChannelDestroyedMethod(final HttpMethod webhooksOnChannelDestroyedMethod){ - this.webhooksOnChannelDestroyedMethod = webhooksOnChannelDestroyedMethod; + + public ServiceUpdater setWebhooksOnChannelDestroyedMethod( + final HttpMethod webhooksOnChannelDestroyedMethod + ) { + this.webhooksOnChannelDestroyedMethod = + webhooksOnChannelDestroyedMethod; return this; } - public ServiceUpdater setWebhooksOnChannelUpdatedUrl(final URI webhooksOnChannelUpdatedUrl){ + + public ServiceUpdater setWebhooksOnChannelUpdatedUrl( + final URI webhooksOnChannelUpdatedUrl + ) { this.webhooksOnChannelUpdatedUrl = webhooksOnChannelUpdatedUrl; return this; } - public ServiceUpdater setWebhooksOnChannelUpdatedUrl(final String webhooksOnChannelUpdatedUrl){ - return setWebhooksOnChannelUpdatedUrl(Promoter.uriFromString(webhooksOnChannelUpdatedUrl)); + public ServiceUpdater setWebhooksOnChannelUpdatedUrl( + final String webhooksOnChannelUpdatedUrl + ) { + return setWebhooksOnChannelUpdatedUrl( + Promoter.uriFromString(webhooksOnChannelUpdatedUrl) + ); } - public ServiceUpdater setWebhooksOnChannelUpdatedMethod(final HttpMethod webhooksOnChannelUpdatedMethod){ + + public ServiceUpdater setWebhooksOnChannelUpdatedMethod( + final HttpMethod webhooksOnChannelUpdatedMethod + ) { this.webhooksOnChannelUpdatedMethod = webhooksOnChannelUpdatedMethod; return this; } - public ServiceUpdater setWebhooksOnMemberAddedUrl(final URI webhooksOnMemberAddedUrl){ + + public ServiceUpdater setWebhooksOnMemberAddedUrl( + final URI webhooksOnMemberAddedUrl + ) { this.webhooksOnMemberAddedUrl = webhooksOnMemberAddedUrl; return this; } - public ServiceUpdater setWebhooksOnMemberAddedUrl(final String webhooksOnMemberAddedUrl){ - return setWebhooksOnMemberAddedUrl(Promoter.uriFromString(webhooksOnMemberAddedUrl)); + public ServiceUpdater setWebhooksOnMemberAddedUrl( + final String webhooksOnMemberAddedUrl + ) { + return setWebhooksOnMemberAddedUrl( + Promoter.uriFromString(webhooksOnMemberAddedUrl) + ); } - public ServiceUpdater setWebhooksOnMemberAddedMethod(final HttpMethod webhooksOnMemberAddedMethod){ + + public ServiceUpdater setWebhooksOnMemberAddedMethod( + final HttpMethod webhooksOnMemberAddedMethod + ) { this.webhooksOnMemberAddedMethod = webhooksOnMemberAddedMethod; return this; } - public ServiceUpdater setWebhooksOnMemberRemovedUrl(final URI webhooksOnMemberRemovedUrl){ + + public ServiceUpdater setWebhooksOnMemberRemovedUrl( + final URI webhooksOnMemberRemovedUrl + ) { this.webhooksOnMemberRemovedUrl = webhooksOnMemberRemovedUrl; return this; } - public ServiceUpdater setWebhooksOnMemberRemovedUrl(final String webhooksOnMemberRemovedUrl){ - return setWebhooksOnMemberRemovedUrl(Promoter.uriFromString(webhooksOnMemberRemovedUrl)); + public ServiceUpdater setWebhooksOnMemberRemovedUrl( + final String webhooksOnMemberRemovedUrl + ) { + return setWebhooksOnMemberRemovedUrl( + Promoter.uriFromString(webhooksOnMemberRemovedUrl) + ); } - public ServiceUpdater setWebhooksOnMemberRemovedMethod(final HttpMethod webhooksOnMemberRemovedMethod){ + + public ServiceUpdater setWebhooksOnMemberRemovedMethod( + final HttpMethod webhooksOnMemberRemovedMethod + ) { this.webhooksOnMemberRemovedMethod = webhooksOnMemberRemovedMethod; return this; } - public ServiceUpdater setLimitsChannelMembers(final Integer limitsChannelMembers){ + + public ServiceUpdater setLimitsChannelMembers( + final Integer limitsChannelMembers + ) { this.limitsChannelMembers = limitsChannelMembers; return this; } - public ServiceUpdater setLimitsUserChannels(final Integer limitsUserChannels){ + + public ServiceUpdater setLimitsUserChannels( + final Integer limitsUserChannels + ) { this.limitsUserChannels = limitsUserChannels; return this; } @Override - public Service update(final TwilioRestClient client){ + public Service update(final TwilioRestClient client) { String path = "/v1/Services/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -408,224 +636,318 @@ public Service update(final TwilioRestClient client){ return Service.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (defaultServiceRoleSid != null) { - request.addPostParam("DefaultServiceRoleSid", defaultServiceRoleSid); - + request.addPostParam( + "DefaultServiceRoleSid", + defaultServiceRoleSid + ); } if (defaultChannelRoleSid != null) { - request.addPostParam("DefaultChannelRoleSid", defaultChannelRoleSid); - + request.addPostParam( + "DefaultChannelRoleSid", + defaultChannelRoleSid + ); } if (defaultChannelCreatorRoleSid != null) { - request.addPostParam("DefaultChannelCreatorRoleSid", defaultChannelCreatorRoleSid); - + request.addPostParam( + "DefaultChannelCreatorRoleSid", + defaultChannelCreatorRoleSid + ); } if (readStatusEnabled != null) { - request.addPostParam("ReadStatusEnabled", readStatusEnabled.toString()); - + request.addPostParam( + "ReadStatusEnabled", + readStatusEnabled.toString() + ); } if (reachabilityEnabled != null) { - request.addPostParam("ReachabilityEnabled", reachabilityEnabled.toString()); - + request.addPostParam( + "ReachabilityEnabled", + reachabilityEnabled.toString() + ); } if (typingIndicatorTimeout != null) { - request.addPostParam("TypingIndicatorTimeout", typingIndicatorTimeout.toString()); - + request.addPostParam( + "TypingIndicatorTimeout", + typingIndicatorTimeout.toString() + ); } if (consumptionReportInterval != null) { - request.addPostParam("ConsumptionReportInterval", consumptionReportInterval.toString()); - + request.addPostParam( + "ConsumptionReportInterval", + consumptionReportInterval.toString() + ); } if (notificationsNewMessageEnabled != null) { - request.addPostParam("Notifications.NewMessage.Enabled", notificationsNewMessageEnabled.toString()); - + request.addPostParam( + "Notifications.NewMessage.Enabled", + notificationsNewMessageEnabled.toString() + ); } if (notificationsNewMessageTemplate != null) { - request.addPostParam("Notifications.NewMessage.Template", notificationsNewMessageTemplate); - + request.addPostParam( + "Notifications.NewMessage.Template", + notificationsNewMessageTemplate + ); } if (notificationsAddedToChannelEnabled != null) { - request.addPostParam("Notifications.AddedToChannel.Enabled", notificationsAddedToChannelEnabled.toString()); - + request.addPostParam( + "Notifications.AddedToChannel.Enabled", + notificationsAddedToChannelEnabled.toString() + ); } if (notificationsAddedToChannelTemplate != null) { - request.addPostParam("Notifications.AddedToChannel.Template", notificationsAddedToChannelTemplate); - + request.addPostParam( + "Notifications.AddedToChannel.Template", + notificationsAddedToChannelTemplate + ); } if (notificationsRemovedFromChannelEnabled != null) { - request.addPostParam("Notifications.RemovedFromChannel.Enabled", notificationsRemovedFromChannelEnabled.toString()); - + request.addPostParam( + "Notifications.RemovedFromChannel.Enabled", + notificationsRemovedFromChannelEnabled.toString() + ); } if (notificationsRemovedFromChannelTemplate != null) { - request.addPostParam("Notifications.RemovedFromChannel.Template", notificationsRemovedFromChannelTemplate); - + request.addPostParam( + "Notifications.RemovedFromChannel.Template", + notificationsRemovedFromChannelTemplate + ); } if (notificationsInvitedToChannelEnabled != null) { - request.addPostParam("Notifications.InvitedToChannel.Enabled", notificationsInvitedToChannelEnabled.toString()); - + request.addPostParam( + "Notifications.InvitedToChannel.Enabled", + notificationsInvitedToChannelEnabled.toString() + ); } if (notificationsInvitedToChannelTemplate != null) { - request.addPostParam("Notifications.InvitedToChannel.Template", notificationsInvitedToChannelTemplate); - + request.addPostParam( + "Notifications.InvitedToChannel.Template", + notificationsInvitedToChannelTemplate + ); } if (preWebhookUrl != null) { request.addPostParam("PreWebhookUrl", preWebhookUrl.toString()); - } if (postWebhookUrl != null) { request.addPostParam("PostWebhookUrl", postWebhookUrl.toString()); - } if (webhookMethod != null) { request.addPostParam("WebhookMethod", webhookMethod.toString()); - } if (webhookFilters != null) { for (String prop : webhookFilters) { request.addPostParam("WebhookFilters", prop); } - } if (webhooksOnMessageSendUrl != null) { - request.addPostParam("Webhooks.OnMessageSend.Url", webhooksOnMessageSendUrl.toString()); - + request.addPostParam( + "Webhooks.OnMessageSend.Url", + webhooksOnMessageSendUrl.toString() + ); } if (webhooksOnMessageSendMethod != null) { - request.addPostParam("Webhooks.OnMessageSend.Method", webhooksOnMessageSendMethod.toString()); - + request.addPostParam( + "Webhooks.OnMessageSend.Method", + webhooksOnMessageSendMethod.toString() + ); } if (webhooksOnMessageUpdateUrl != null) { - request.addPostParam("Webhooks.OnMessageUpdate.Url", webhooksOnMessageUpdateUrl.toString()); - + request.addPostParam( + "Webhooks.OnMessageUpdate.Url", + webhooksOnMessageUpdateUrl.toString() + ); } if (webhooksOnMessageUpdateMethod != null) { - request.addPostParam("Webhooks.OnMessageUpdate.Method", webhooksOnMessageUpdateMethod.toString()); - + request.addPostParam( + "Webhooks.OnMessageUpdate.Method", + webhooksOnMessageUpdateMethod.toString() + ); } if (webhooksOnMessageRemoveUrl != null) { - request.addPostParam("Webhooks.OnMessageRemove.Url", webhooksOnMessageRemoveUrl.toString()); - + request.addPostParam( + "Webhooks.OnMessageRemove.Url", + webhooksOnMessageRemoveUrl.toString() + ); } if (webhooksOnMessageRemoveMethod != null) { - request.addPostParam("Webhooks.OnMessageRemove.Method", webhooksOnMessageRemoveMethod.toString()); - + request.addPostParam( + "Webhooks.OnMessageRemove.Method", + webhooksOnMessageRemoveMethod.toString() + ); } if (webhooksOnChannelAddUrl != null) { - request.addPostParam("Webhooks.OnChannelAdd.Url", webhooksOnChannelAddUrl.toString()); - + request.addPostParam( + "Webhooks.OnChannelAdd.Url", + webhooksOnChannelAddUrl.toString() + ); } if (webhooksOnChannelAddMethod != null) { - request.addPostParam("Webhooks.OnChannelAdd.Method", webhooksOnChannelAddMethod.toString()); - + request.addPostParam( + "Webhooks.OnChannelAdd.Method", + webhooksOnChannelAddMethod.toString() + ); } if (webhooksOnChannelDestroyUrl != null) { - request.addPostParam("Webhooks.OnChannelDestroy.Url", webhooksOnChannelDestroyUrl.toString()); - + request.addPostParam( + "Webhooks.OnChannelDestroy.Url", + webhooksOnChannelDestroyUrl.toString() + ); } if (webhooksOnChannelDestroyMethod != null) { - request.addPostParam("Webhooks.OnChannelDestroy.Method", webhooksOnChannelDestroyMethod.toString()); - + request.addPostParam( + "Webhooks.OnChannelDestroy.Method", + webhooksOnChannelDestroyMethod.toString() + ); } if (webhooksOnChannelUpdateUrl != null) { - request.addPostParam("Webhooks.OnChannelUpdate.Url", webhooksOnChannelUpdateUrl.toString()); - + request.addPostParam( + "Webhooks.OnChannelUpdate.Url", + webhooksOnChannelUpdateUrl.toString() + ); } if (webhooksOnChannelUpdateMethod != null) { - request.addPostParam("Webhooks.OnChannelUpdate.Method", webhooksOnChannelUpdateMethod.toString()); - + request.addPostParam( + "Webhooks.OnChannelUpdate.Method", + webhooksOnChannelUpdateMethod.toString() + ); } if (webhooksOnMemberAddUrl != null) { - request.addPostParam("Webhooks.OnMemberAdd.Url", webhooksOnMemberAddUrl.toString()); - + request.addPostParam( + "Webhooks.OnMemberAdd.Url", + webhooksOnMemberAddUrl.toString() + ); } if (webhooksOnMemberAddMethod != null) { - request.addPostParam("Webhooks.OnMemberAdd.Method", webhooksOnMemberAddMethod.toString()); - + request.addPostParam( + "Webhooks.OnMemberAdd.Method", + webhooksOnMemberAddMethod.toString() + ); } if (webhooksOnMemberRemoveUrl != null) { - request.addPostParam("Webhooks.OnMemberRemove.Url", webhooksOnMemberRemoveUrl.toString()); - + request.addPostParam( + "Webhooks.OnMemberRemove.Url", + webhooksOnMemberRemoveUrl.toString() + ); } if (webhooksOnMemberRemoveMethod != null) { - request.addPostParam("Webhooks.OnMemberRemove.Method", webhooksOnMemberRemoveMethod.toString()); - + request.addPostParam( + "Webhooks.OnMemberRemove.Method", + webhooksOnMemberRemoveMethod.toString() + ); } if (webhooksOnMessageSentUrl != null) { - request.addPostParam("Webhooks.OnMessageSent.Url", webhooksOnMessageSentUrl.toString()); - + request.addPostParam( + "Webhooks.OnMessageSent.Url", + webhooksOnMessageSentUrl.toString() + ); } if (webhooksOnMessageSentMethod != null) { - request.addPostParam("Webhooks.OnMessageSent.Method", webhooksOnMessageSentMethod.toString()); - + request.addPostParam( + "Webhooks.OnMessageSent.Method", + webhooksOnMessageSentMethod.toString() + ); } if (webhooksOnMessageUpdatedUrl != null) { - request.addPostParam("Webhooks.OnMessageUpdated.Url", webhooksOnMessageUpdatedUrl.toString()); - + request.addPostParam( + "Webhooks.OnMessageUpdated.Url", + webhooksOnMessageUpdatedUrl.toString() + ); } if (webhooksOnMessageUpdatedMethod != null) { - request.addPostParam("Webhooks.OnMessageUpdated.Method", webhooksOnMessageUpdatedMethod.toString()); - + request.addPostParam( + "Webhooks.OnMessageUpdated.Method", + webhooksOnMessageUpdatedMethod.toString() + ); } if (webhooksOnMessageRemovedUrl != null) { - request.addPostParam("Webhooks.OnMessageRemoved.Url", webhooksOnMessageRemovedUrl.toString()); - + request.addPostParam( + "Webhooks.OnMessageRemoved.Url", + webhooksOnMessageRemovedUrl.toString() + ); } if (webhooksOnMessageRemovedMethod != null) { - request.addPostParam("Webhooks.OnMessageRemoved.Method", webhooksOnMessageRemovedMethod.toString()); - + request.addPostParam( + "Webhooks.OnMessageRemoved.Method", + webhooksOnMessageRemovedMethod.toString() + ); } if (webhooksOnChannelAddedUrl != null) { - request.addPostParam("Webhooks.OnChannelAdded.Url", webhooksOnChannelAddedUrl.toString()); - + request.addPostParam( + "Webhooks.OnChannelAdded.Url", + webhooksOnChannelAddedUrl.toString() + ); } if (webhooksOnChannelAddedMethod != null) { - request.addPostParam("Webhooks.OnChannelAdded.Method", webhooksOnChannelAddedMethod.toString()); - + request.addPostParam( + "Webhooks.OnChannelAdded.Method", + webhooksOnChannelAddedMethod.toString() + ); } if (webhooksOnChannelDestroyedUrl != null) { - request.addPostParam("Webhooks.OnChannelDestroyed.Url", webhooksOnChannelDestroyedUrl.toString()); - + request.addPostParam( + "Webhooks.OnChannelDestroyed.Url", + webhooksOnChannelDestroyedUrl.toString() + ); } if (webhooksOnChannelDestroyedMethod != null) { - request.addPostParam("Webhooks.OnChannelDestroyed.Method", webhooksOnChannelDestroyedMethod.toString()); - + request.addPostParam( + "Webhooks.OnChannelDestroyed.Method", + webhooksOnChannelDestroyedMethod.toString() + ); } if (webhooksOnChannelUpdatedUrl != null) { - request.addPostParam("Webhooks.OnChannelUpdated.Url", webhooksOnChannelUpdatedUrl.toString()); - + request.addPostParam( + "Webhooks.OnChannelUpdated.Url", + webhooksOnChannelUpdatedUrl.toString() + ); } if (webhooksOnChannelUpdatedMethod != null) { - request.addPostParam("Webhooks.OnChannelUpdated.Method", webhooksOnChannelUpdatedMethod.toString()); - + request.addPostParam( + "Webhooks.OnChannelUpdated.Method", + webhooksOnChannelUpdatedMethod.toString() + ); } if (webhooksOnMemberAddedUrl != null) { - request.addPostParam("Webhooks.OnMemberAdded.Url", webhooksOnMemberAddedUrl.toString()); - + request.addPostParam( + "Webhooks.OnMemberAdded.Url", + webhooksOnMemberAddedUrl.toString() + ); } if (webhooksOnMemberAddedMethod != null) { - request.addPostParam("Webhooks.OnMemberAdded.Method", webhooksOnMemberAddedMethod.toString()); - + request.addPostParam( + "Webhooks.OnMemberAdded.Method", + webhooksOnMemberAddedMethod.toString() + ); } if (webhooksOnMemberRemovedUrl != null) { - request.addPostParam("Webhooks.OnMemberRemoved.Url", webhooksOnMemberRemovedUrl.toString()); - + request.addPostParam( + "Webhooks.OnMemberRemoved.Url", + webhooksOnMemberRemovedUrl.toString() + ); } if (webhooksOnMemberRemovedMethod != null) { - request.addPostParam("Webhooks.OnMemberRemoved.Method", webhooksOnMemberRemovedMethod.toString()); - + request.addPostParam( + "Webhooks.OnMemberRemoved.Method", + webhooksOnMemberRemovedMethod.toString() + ); } if (limitsChannelMembers != null) { - request.addPostParam("Limits.ChannelMembers", limitsChannelMembers.toString()); - + request.addPostParam( + "Limits.ChannelMembers", + limitsChannelMembers.toString() + ); } if (limitsUserChannels != null) { - request.addPostParam("Limits.UserChannels", limitsUserChannels.toString()); - + request.addPostParam( + "Limits.UserChannels", + limitsUserChannels.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/Channel.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/Channel.java index a5793c39bf..c953e64ee6 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/Channel.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/Channel.java @@ -24,55 +24,63 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Channel extends Resource { + private static final long serialVersionUID = 188288773259274L; - public static ChannelCreator creator(final String pathServiceSid){ + public static ChannelCreator creator(final String pathServiceSid) { return new ChannelCreator(pathServiceSid); } - public static ChannelDeleter deleter(final String pathServiceSid, final String pathSid){ + public static ChannelDeleter deleter( + final String pathServiceSid, + final String pathSid + ) { return new ChannelDeleter(pathServiceSid, pathSid); } - public static ChannelFetcher fetcher(final String pathServiceSid, final String pathSid){ + public static ChannelFetcher fetcher( + final String pathServiceSid, + final String pathSid + ) { return new ChannelFetcher(pathServiceSid, pathSid); } - public static ChannelReader reader(final String pathServiceSid){ + public static ChannelReader reader(final String pathServiceSid) { return new ChannelReader(pathServiceSid); } - public static ChannelUpdater updater(final String pathServiceSid, final String pathSid){ + public static ChannelUpdater updater( + final String pathServiceSid, + final String pathSid + ) { return new ChannelUpdater(pathServiceSid, pathSid); } /** - * Converts a JSON String into a Channel object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Channel object represented by the provided JSON - */ - public static Channel fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Channel object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Channel object represented by the provided JSON + */ + public static Channel fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Channel.class); @@ -84,14 +92,17 @@ public static Channel fromJson(final String json, final ObjectMapper objectMappe } /** - * Converts a JSON InputStream into a Channel object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Channel object represented by the provided JSON - */ - public static Channel fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Channel object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Channel object represented by the provided JSON + */ + public static Channel fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Channel.class); @@ -101,6 +112,7 @@ public static Channel fromJson(final InputStream json, final ObjectMapper object throw new ApiConnectionException(e.getMessage(), e); } } + public enum ChannelType { PUBLIC("public"), PRIVATE("private"); @@ -138,47 +150,20 @@ public static ChannelType forValue(final String value) { @JsonCreator private Channel( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("unique_name") - final String uniqueName, - - @JsonProperty("attributes") - final String attributes, - - @JsonProperty("type") - final Channel.ChannelType type, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("created_by") - final String createdBy, - - @JsonProperty("members_count") - final Integer membersCount, - - @JsonProperty("messages_count") - final Integer messagesCount, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("attributes") final String attributes, + @JsonProperty("type") final Channel.ChannelType type, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("created_by") final String createdBy, + @JsonProperty("members_count") final Integer membersCount, + @JsonProperty("messages_count") final Integer messagesCount, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.sid = sid; this.accountSid = accountSid; @@ -196,52 +181,65 @@ private Channel( this.links = links; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getUniqueName() { - return this.uniqueName; - } - public final String getAttributes() { - return this.attributes; - } - public final Channel.ChannelType getType() { - return this.type; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getCreatedBy() { - return this.createdBy; - } - public final Integer getMembersCount() { - return this.membersCount; - } - public final Integer getMessagesCount() { - return this.messagesCount; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getUniqueName() { + return this.uniqueName; + } + + public final String getAttributes() { + return this.attributes; + } + + public final Channel.ChannelType getType() { + return this.type; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getCreatedBy() { + return this.createdBy; + } + + public final Integer getMembersCount() { + return this.membersCount; + } + + public final Integer getMessagesCount() { + return this.messagesCount; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -251,13 +249,41 @@ public boolean equals(final Object o) { Channel other = (Channel) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(uniqueName, other.uniqueName) && Objects.equals(attributes, other.attributes) && Objects.equals(type, other.type) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(createdBy, other.createdBy) && Objects.equals(membersCount, other.membersCount) && Objects.equals(messagesCount, other.messagesCount) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(attributes, other.attributes) && + Objects.equals(type, other.type) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(createdBy, other.createdBy) && + Objects.equals(membersCount, other.membersCount) && + Objects.equals(messagesCount, other.messagesCount) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, serviceSid, friendlyName, uniqueName, attributes, type, dateCreated, dateUpdated, createdBy, membersCount, messagesCount, url, links); + return Objects.hash( + sid, + accountSid, + serviceSid, + friendlyName, + uniqueName, + attributes, + type, + dateCreated, + dateUpdated, + createdBy, + membersCount, + messagesCount, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/ChannelCreator.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/ChannelCreator.java index 353a6b5761..e08db5ba58 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/ChannelCreator.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/ChannelCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.ipmessaging.v1.service; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class ChannelCreator extends Creator { - - -public class ChannelCreator extends Creator{ private String pathServiceSid; private String friendlyName; private String uniqueName; @@ -38,40 +37,53 @@ public ChannelCreator(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - public ChannelCreator setFriendlyName(final String friendlyName){ + public ChannelCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public ChannelCreator setUniqueName(final String uniqueName){ + + public ChannelCreator setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - public ChannelCreator setAttributes(final String attributes){ + + public ChannelCreator setAttributes(final String attributes) { this.attributes = attributes; return this; } - public ChannelCreator setType(final Channel.ChannelType type){ + + public ChannelCreator setType(final Channel.ChannelType type) { this.type = type; return this; } @Override - public Channel create(final TwilioRestClient client){ + public Channel create(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Channels"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Channel creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Channel creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -80,22 +92,19 @@ public Channel create(final TwilioRestClient client){ return Channel.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (uniqueName != null) { request.addPostParam("UniqueName", uniqueName); - } if (attributes != null) { request.addPostParam("Attributes", attributes); - } if (type != null) { request.addPostParam("Type", type.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/ChannelDeleter.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/ChannelDeleter.java index 23ef04756c..d67bec9ed2 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/ChannelDeleter.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/ChannelDeleter.java @@ -24,24 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class ChannelDeleter extends Deleter { + private String pathServiceSid; private String pathSid; - public ChannelDeleter(final String pathServiceSid, final String pathSid){ + public ChannelDeleter(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Channels/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +53,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Channel delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Channel delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/ChannelFetcher.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/ChannelFetcher.java index 420dc208a2..e41b8f3c1f 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/ChannelFetcher.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/ChannelFetcher.java @@ -24,25 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class ChannelFetcher extends Fetcher { + private String pathServiceSid; private String pathSid; - public ChannelFetcher(final String pathServiceSid, final String pathSid){ + public ChannelFetcher(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - @Override public Channel fetch(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Channels/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,9 +53,14 @@ public Channel fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Channel fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Channel fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/ChannelReader.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/ChannelReader.java index 74607a4dcb..f2cce594e3 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/ChannelReader.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/ChannelReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.ipmessaging.v1.service; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.converter.Promoter; @@ -25,28 +26,28 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - import java.util.List; - public class ChannelReader extends Reader { + private String pathServiceSid; private List type; private Integer pageSize; - public ChannelReader(final String pathServiceSid){ + public ChannelReader(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - public ChannelReader setType(final List type){ + public ChannelReader setType(final List type) { this.type = type; return this; } - public ChannelReader setType(final Channel.ChannelType type){ + + public ChannelReader setType(final Channel.ChannelType type) { return setType(Promoter.listOfOne(type)); } - public ChannelReader setPageSize(final Integer pageSize){ + + public ChannelReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -58,7 +59,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Channels"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -70,13 +75,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Channel read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Channel read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -92,7 +105,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reques } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.IPMESSAGING.toString()) @@ -100,9 +116,11 @@ public Page previousPage(final Page page, final TwilioRestClie return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.IPMESSAGING.toString()) @@ -111,14 +129,15 @@ public Page nextPage(final Page page, final TwilioRestClient c } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (type != null) { for (Channel.ChannelType prop : type) { @@ -126,11 +145,10 @@ private void addQueryParams(final Request request) { } } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/ChannelUpdater.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/ChannelUpdater.java index 0e38d6cbda..1debb81634 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/ChannelUpdater.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/ChannelUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.ipmessaging.v1.service; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,52 +25,62 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class ChannelUpdater extends Updater { - - -public class ChannelUpdater extends Updater{ private String pathServiceSid; private String pathSid; private String friendlyName; private String uniqueName; private String attributes; - public ChannelUpdater(final String pathServiceSid, final String pathSid){ + public ChannelUpdater(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - public ChannelUpdater setFriendlyName(final String friendlyName){ + public ChannelUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public ChannelUpdater setUniqueName(final String uniqueName){ + + public ChannelUpdater setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - public ChannelUpdater setAttributes(final String attributes){ + + public ChannelUpdater setAttributes(final String attributes) { this.attributes = attributes; return this; } @Override - public Channel update(final TwilioRestClient client){ + public Channel update(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Channels/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Channel update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Channel update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -78,18 +89,16 @@ public Channel update(final TwilioRestClient client){ return Channel.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (uniqueName != null) { request.addPostParam("UniqueName", uniqueName); - } if (attributes != null) { request.addPostParam("Attributes", attributes); - } } } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/Role.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/Role.java index 8fcf04b00d..7624dcc6d9 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/Role.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/Role.java @@ -24,54 +24,68 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.List; import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Role extends Resource { + private static final long serialVersionUID = 252065084446046L; - public static RoleCreator creator(final String pathServiceSid, final String friendlyName, final Role.RoleType type, final List permission){ + public static RoleCreator creator( + final String pathServiceSid, + final String friendlyName, + final Role.RoleType type, + final List permission + ) { return new RoleCreator(pathServiceSid, friendlyName, type, permission); } - public static RoleDeleter deleter(final String pathServiceSid, final String pathSid){ + public static RoleDeleter deleter( + final String pathServiceSid, + final String pathSid + ) { return new RoleDeleter(pathServiceSid, pathSid); } - public static RoleFetcher fetcher(final String pathServiceSid, final String pathSid){ + public static RoleFetcher fetcher( + final String pathServiceSid, + final String pathSid + ) { return new RoleFetcher(pathServiceSid, pathSid); } - public static RoleReader reader(final String pathServiceSid){ + public static RoleReader reader(final String pathServiceSid) { return new RoleReader(pathServiceSid); } - public static RoleUpdater updater(final String pathServiceSid, final String pathSid, final List permission){ + public static RoleUpdater updater( + final String pathServiceSid, + final String pathSid, + final List permission + ) { return new RoleUpdater(pathServiceSid, pathSid, permission); } /** - * Converts a JSON String into a Role object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Role object represented by the provided JSON - */ - public static Role fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Role object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Role object represented by the provided JSON + */ + public static Role fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Role.class); @@ -83,14 +97,17 @@ public static Role fromJson(final String json, final ObjectMapper objectMapper) } /** - * Converts a JSON InputStream into a Role object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Role object represented by the provided JSON - */ - public static Role fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Role object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Role object represented by the provided JSON + */ + public static Role fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Role.class); @@ -100,6 +117,7 @@ public static Role fromJson(final InputStream json, final ObjectMapper objectMap throw new ApiConnectionException(e.getMessage(), e); } } + public enum RoleType { CHANNEL("channel"), DEPLOYMENT("deployment"); @@ -132,32 +150,15 @@ public static RoleType forValue(final String value) { @JsonCreator private Role( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("type") - final Role.RoleType type, - - @JsonProperty("permissions") - final List permissions, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("type") final Role.RoleType type, + @JsonProperty("permissions") final List permissions, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url ) { this.sid = sid; this.accountSid = accountSid; @@ -170,37 +171,45 @@ private Role( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final Role.RoleType getType() { - return this.type; - } - public final List getPermissions() { - return this.permissions; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final Role.RoleType getType() { + return this.type; + } + + public final List getPermissions() { + return this.permissions; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -210,13 +219,31 @@ public boolean equals(final Object o) { Role other = (Role) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(type, other.type) && Objects.equals(permissions, other.permissions) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(type, other.type) && + Objects.equals(permissions, other.permissions) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, serviceSid, friendlyName, type, permissions, dateCreated, dateUpdated, url); + return Objects.hash( + sid, + accountSid, + serviceSid, + friendlyName, + type, + permissions, + dateCreated, + dateUpdated, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/RoleCreator.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/RoleCreator.java index a196ac158d..348431f29f 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/RoleCreator.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/RoleCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.ipmessaging.v1.service; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -25,60 +26,81 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.util.List; - import java.util.List; +public class RoleCreator extends Creator { - -public class RoleCreator extends Creator{ private String pathServiceSid; private String friendlyName; private Role.RoleType type; private List permission; - public RoleCreator(final String pathServiceSid, final String friendlyName, final Role.RoleType type, final List permission) { + public RoleCreator( + final String pathServiceSid, + final String friendlyName, + final Role.RoleType type, + final List permission + ) { this.pathServiceSid = pathServiceSid; this.friendlyName = friendlyName; this.type = type; this.permission = permission; } - public RoleCreator setFriendlyName(final String friendlyName){ + public RoleCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public RoleCreator setType(final Role.RoleType type){ + + public RoleCreator setType(final Role.RoleType type) { this.type = type; return this; } - public RoleCreator setPermission(final List permission){ + + public RoleCreator setPermission(final List permission) { this.permission = permission; return this; } - public RoleCreator setPermission(final String permission){ + + public RoleCreator setPermission(final String permission) { return setPermission(Promoter.listOfOne(permission)); } @Override - public Role create(final TwilioRestClient client){ + public Role create(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Roles"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"FriendlyName"+"}", this.friendlyName.toString()); - path = path.replace("{"+"Type"+"}", this.type.toString()); - path = path.replace("{"+"Permission"+"}", this.permission.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "FriendlyName" + "}", + this.friendlyName.toString() + ); + path = path.replace("{" + "Type" + "}", this.type.toString()); + path = + path.replace("{" + "Permission" + "}", this.permission.toString()); Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Role creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Role creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -87,20 +109,18 @@ public Role create(final TwilioRestClient client){ return Role.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (type != null) { request.addPostParam("Type", type.toString()); - } if (permission != null) { for (String prop : permission) { request.addPostParam("Permission", prop); } - } } } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/RoleDeleter.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/RoleDeleter.java index db63749266..d78c18e51a 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/RoleDeleter.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/RoleDeleter.java @@ -24,24 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class RoleDeleter extends Deleter { + private String pathServiceSid; private String pathSid; - public RoleDeleter(final String pathServiceSid, final String pathSid){ + public RoleDeleter(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Roles/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +53,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Role delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Role delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/RoleFetcher.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/RoleFetcher.java index 71aaea9121..1b59407bd8 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/RoleFetcher.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/RoleFetcher.java @@ -24,25 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class RoleFetcher extends Fetcher { + private String pathServiceSid; private String pathSid; - public RoleFetcher(final String pathServiceSid, final String pathSid){ + public RoleFetcher(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - @Override public Role fetch(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Roles/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,9 +53,14 @@ public Role fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Role fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Role fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/RoleReader.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/RoleReader.java index 29d730065b..91c410e899 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/RoleReader.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/RoleReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.ipmessaging.v1.service; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,19 +25,17 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class RoleReader extends Reader { + private String pathServiceSid; private Integer pageSize; - public RoleReader(final String pathServiceSid){ + public RoleReader(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - public RoleReader setPageSize(final Integer pageSize){ + public RoleReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -48,7 +47,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Roles"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -60,13 +63,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Role read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Role read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +93,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request r } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.IPMESSAGING.toString()) @@ -90,9 +104,11 @@ public Page previousPage(final Page page, final TwilioRestClient cli return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.IPMESSAGING.toString()) @@ -101,21 +117,21 @@ public Page nextPage(final Page page, final TwilioRestClient client) } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/RoleUpdater.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/RoleUpdater.java index e1ecd89710..eca836791b 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/RoleUpdater.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/RoleUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.ipmessaging.v1.service; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -24,49 +25,63 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - import java.util.List; +public class RoleUpdater extends Updater { -public class RoleUpdater extends Updater{ private String pathServiceSid; private String pathSid; private List permission; - public RoleUpdater(final String pathServiceSid, final String pathSid, final List permission){ + public RoleUpdater( + final String pathServiceSid, + final String pathSid, + final List permission + ) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; this.permission = permission; } - public RoleUpdater setPermission(final List permission){ + public RoleUpdater setPermission(final List permission) { this.permission = permission; return this; } - public RoleUpdater setPermission(final String permission){ + + public RoleUpdater setPermission(final String permission) { return setPermission(Promoter.listOfOne(permission)); } @Override - public Role update(final TwilioRestClient client){ + public Role update(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Roles/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); - path = path.replace("{"+"Permission"+"}", this.permission.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + path = + path.replace("{" + "Permission" + "}", this.permission.toString()); Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Role update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Role update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -75,12 +90,12 @@ public Role update(final TwilioRestClient client){ return Role.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (permission != null) { for (String prop : permission) { request.addPostParam("Permission", prop); } - } } } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/User.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/User.java index 64a5a1e780..2acabb1e47 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/User.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/User.java @@ -23,55 +23,66 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class User extends Resource { + private static final long serialVersionUID = 136391609300437L; - public static UserCreator creator(final String pathServiceSid, final String identity){ + public static UserCreator creator( + final String pathServiceSid, + final String identity + ) { return new UserCreator(pathServiceSid, identity); } - public static UserDeleter deleter(final String pathServiceSid, final String pathSid){ + public static UserDeleter deleter( + final String pathServiceSid, + final String pathSid + ) { return new UserDeleter(pathServiceSid, pathSid); } - public static UserFetcher fetcher(final String pathServiceSid, final String pathSid){ + public static UserFetcher fetcher( + final String pathServiceSid, + final String pathSid + ) { return new UserFetcher(pathServiceSid, pathSid); } - public static UserReader reader(final String pathServiceSid){ + public static UserReader reader(final String pathServiceSid) { return new UserReader(pathServiceSid); } - public static UserUpdater updater(final String pathServiceSid, final String pathSid){ + public static UserUpdater updater( + final String pathServiceSid, + final String pathSid + ) { return new UserUpdater(pathServiceSid, pathSid); } /** - * Converts a JSON String into a User object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return User object represented by the provided JSON - */ - public static User fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a User object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return User object represented by the provided JSON + */ + public static User fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, User.class); @@ -83,14 +94,17 @@ public static User fromJson(final String json, final ObjectMapper objectMapper) } /** - * Converts a JSON InputStream into a User object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return User object represented by the provided JSON - */ - public static User fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a User object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return User object represented by the provided JSON + */ + public static User fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, User.class); @@ -118,47 +132,22 @@ public static User fromJson(final InputStream json, final ObjectMapper objectMap @JsonCreator private User( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("attributes") - final String attributes, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("role_sid") - final String roleSid, - - @JsonProperty("identity") - final String identity, - - @JsonProperty("is_online") - final Boolean isOnline, - - @JsonProperty("is_notifiable") - final Boolean isNotifiable, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("joined_channels_count") - final Integer joinedChannelsCount, - - @JsonProperty("links") - final Map links, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("attributes") final String attributes, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("role_sid") final String roleSid, + @JsonProperty("identity") final String identity, + @JsonProperty("is_online") final Boolean isOnline, + @JsonProperty("is_notifiable") final Boolean isNotifiable, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty( + "joined_channels_count" + ) final Integer joinedChannelsCount, + @JsonProperty("links") final Map links, + @JsonProperty("url") final URI url ) { this.sid = sid; this.accountSid = accountSid; @@ -176,52 +165,65 @@ private User( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final String getAttributes() { - return this.attributes; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getRoleSid() { - return this.roleSid; - } - public final String getIdentity() { - return this.identity; - } - public final Boolean getIsOnline() { - return this.isOnline; - } - public final Boolean getIsNotifiable() { - return this.isNotifiable; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final Integer getJoinedChannelsCount() { - return this.joinedChannelsCount; - } - public final Map getLinks() { - return this.links; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final String getAttributes() { + return this.attributes; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getRoleSid() { + return this.roleSid; + } + + public final String getIdentity() { + return this.identity; + } + + public final Boolean getIsOnline() { + return this.isOnline; + } + + public final Boolean getIsNotifiable() { + return this.isNotifiable; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final Integer getJoinedChannelsCount() { + return this.joinedChannelsCount; + } + + public final Map getLinks() { + return this.links; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -231,13 +233,41 @@ public boolean equals(final Object o) { User other = (User) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(attributes, other.attributes) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(roleSid, other.roleSid) && Objects.equals(identity, other.identity) && Objects.equals(isOnline, other.isOnline) && Objects.equals(isNotifiable, other.isNotifiable) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(joinedChannelsCount, other.joinedChannelsCount) && Objects.equals(links, other.links) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(attributes, other.attributes) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(roleSid, other.roleSid) && + Objects.equals(identity, other.identity) && + Objects.equals(isOnline, other.isOnline) && + Objects.equals(isNotifiable, other.isNotifiable) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(joinedChannelsCount, other.joinedChannelsCount) && + Objects.equals(links, other.links) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, serviceSid, attributes, friendlyName, roleSid, identity, isOnline, isNotifiable, dateCreated, dateUpdated, joinedChannelsCount, links, url); + return Objects.hash( + sid, + accountSid, + serviceSid, + attributes, + friendlyName, + roleSid, + identity, + isOnline, + isNotifiable, + dateCreated, + dateUpdated, + joinedChannelsCount, + links, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/UserCreator.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/UserCreator.java index a16dce646e..29e675ff19 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/UserCreator.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/UserCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.ipmessaging.v1.service; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class UserCreator extends Creator { - - -public class UserCreator extends Creator{ private String pathServiceSid; private String identity; private String roleSid; @@ -39,41 +38,54 @@ public UserCreator(final String pathServiceSid, final String identity) { this.identity = identity; } - public UserCreator setIdentity(final String identity){ + public UserCreator setIdentity(final String identity) { this.identity = identity; return this; } - public UserCreator setRoleSid(final String roleSid){ + + public UserCreator setRoleSid(final String roleSid) { this.roleSid = roleSid; return this; } - public UserCreator setAttributes(final String attributes){ + + public UserCreator setAttributes(final String attributes) { this.attributes = attributes; return this; } - public UserCreator setFriendlyName(final String friendlyName){ + + public UserCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } @Override - public User create(final TwilioRestClient client){ + public User create(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Users"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Identity"+"}", this.identity.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Identity" + "}", this.identity.toString()); Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("User creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "User creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,22 +94,19 @@ public User create(final TwilioRestClient client){ return User.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (identity != null) { request.addPostParam("Identity", identity); - } if (roleSid != null) { request.addPostParam("RoleSid", roleSid); - } if (attributes != null) { request.addPostParam("Attributes", attributes); - } if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } } } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/UserDeleter.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/UserDeleter.java index 844a4337d0..c3941db548 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/UserDeleter.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/UserDeleter.java @@ -24,24 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class UserDeleter extends Deleter { + private String pathServiceSid; private String pathSid; - public UserDeleter(final String pathServiceSid, final String pathSid){ + public UserDeleter(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Users/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +53,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("User delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "User delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/UserFetcher.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/UserFetcher.java index ea94896b5a..1ed90e6a37 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/UserFetcher.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/UserFetcher.java @@ -24,25 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class UserFetcher extends Fetcher { + private String pathServiceSid; private String pathSid; - public UserFetcher(final String pathServiceSid, final String pathSid){ + public UserFetcher(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - @Override public User fetch(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Users/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,9 +53,14 @@ public User fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("User fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "User fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/UserReader.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/UserReader.java index cca35854a2..6fb115b7f0 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/UserReader.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/UserReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.ipmessaging.v1.service; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,19 +25,17 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class UserReader extends Reader { + private String pathServiceSid; private Integer pageSize; - public UserReader(final String pathServiceSid){ + public UserReader(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - public UserReader setPageSize(final Integer pageSize){ + public UserReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -48,7 +47,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Users"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -60,13 +63,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("User read failed: Unable to connect to server"); + throw new ApiConnectionException( + "User read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +93,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request r } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.IPMESSAGING.toString()) @@ -90,9 +104,11 @@ public Page previousPage(final Page page, final TwilioRestClient cli return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.IPMESSAGING.toString()) @@ -101,21 +117,21 @@ public Page nextPage(final Page page, final TwilioRestClient client) } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/UserUpdater.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/UserUpdater.java index 0790890f23..0b616336a9 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/UserUpdater.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/UserUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.ipmessaging.v1.service; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,52 +25,62 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class UserUpdater extends Updater { - - -public class UserUpdater extends Updater{ private String pathServiceSid; private String pathSid; private String roleSid; private String attributes; private String friendlyName; - public UserUpdater(final String pathServiceSid, final String pathSid){ + public UserUpdater(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - public UserUpdater setRoleSid(final String roleSid){ + public UserUpdater setRoleSid(final String roleSid) { this.roleSid = roleSid; return this; } - public UserUpdater setAttributes(final String attributes){ + + public UserUpdater setAttributes(final String attributes) { this.attributes = attributes; return this; } - public UserUpdater setFriendlyName(final String friendlyName){ + + public UserUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } @Override - public User update(final TwilioRestClient client){ + public User update(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Users/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("User update failed: Unable to connect to server"); + throw new ApiConnectionException( + "User update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -78,18 +89,16 @@ public User update(final TwilioRestClient client){ return User.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (roleSid != null) { request.addPostParam("RoleSid", roleSid); - } if (attributes != null) { request.addPostParam("Attributes", attributes); - } if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } } } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/Invite.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/Invite.java index 0d887fccdd..17d716e8e1 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/Invite.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/Invite.java @@ -23,49 +23,63 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Invite extends Resource { + private static final long serialVersionUID = 148273166902210L; - public static InviteCreator creator(final String pathServiceSid, final String pathChannelSid, final String identity){ + public static InviteCreator creator( + final String pathServiceSid, + final String pathChannelSid, + final String identity + ) { return new InviteCreator(pathServiceSid, pathChannelSid, identity); } - public static InviteDeleter deleter(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public static InviteDeleter deleter( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { return new InviteDeleter(pathServiceSid, pathChannelSid, pathSid); } - public static InviteFetcher fetcher(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public static InviteFetcher fetcher( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { return new InviteFetcher(pathServiceSid, pathChannelSid, pathSid); } - public static InviteReader reader(final String pathServiceSid, final String pathChannelSid){ + public static InviteReader reader( + final String pathServiceSid, + final String pathChannelSid + ) { return new InviteReader(pathServiceSid, pathChannelSid); } /** - * Converts a JSON String into a Invite object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Invite object represented by the provided JSON - */ - public static Invite fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Invite object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Invite object represented by the provided JSON + */ + public static Invite fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Invite.class); @@ -77,14 +91,17 @@ public static Invite fromJson(final String json, final ObjectMapper objectMapper } /** - * Converts a JSON InputStream into a Invite object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Invite object represented by the provided JSON - */ - public static Invite fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Invite object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Invite object represented by the provided JSON + */ + public static Invite fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Invite.class); @@ -108,35 +125,16 @@ public static Invite fromJson(final InputStream json, final ObjectMapper objectM @JsonCreator private Invite( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("channel_sid") - final String channelSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("identity") - final String identity, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("role_sid") - final String roleSid, - - @JsonProperty("created_by") - final String createdBy, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("channel_sid") final String channelSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("identity") final String identity, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("role_sid") final String roleSid, + @JsonProperty("created_by") final String createdBy, + @JsonProperty("url") final URI url ) { this.sid = sid; this.accountSid = accountSid; @@ -150,40 +148,49 @@ private Invite( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getChannelSid() { - return this.channelSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final String getIdentity() { - return this.identity; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getRoleSid() { - return this.roleSid; - } - public final String getCreatedBy() { - return this.createdBy; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getChannelSid() { + return this.channelSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final String getIdentity() { + return this.identity; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getRoleSid() { + return this.roleSid; + } + + public final String getCreatedBy() { + return this.createdBy; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -193,13 +200,33 @@ public boolean equals(final Object o) { Invite other = (Invite) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(channelSid, other.channelSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(identity, other.identity) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(roleSid, other.roleSid) && Objects.equals(createdBy, other.createdBy) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(channelSid, other.channelSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(identity, other.identity) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(roleSid, other.roleSid) && + Objects.equals(createdBy, other.createdBy) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, channelSid, serviceSid, identity, dateCreated, dateUpdated, roleSid, createdBy, url); + return Objects.hash( + sid, + accountSid, + channelSid, + serviceSid, + identity, + dateCreated, + dateUpdated, + roleSid, + createdBy, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/InviteCreator.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/InviteCreator.java index b7daf2da21..0cd07e177f 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/InviteCreator.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/InviteCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.ipmessaging.v1.service.channel; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,49 +25,66 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class InviteCreator extends Creator { - - -public class InviteCreator extends Creator{ private String pathServiceSid; private String pathChannelSid; private String identity; private String roleSid; - public InviteCreator(final String pathServiceSid, final String pathChannelSid, final String identity) { + public InviteCreator( + final String pathServiceSid, + final String pathChannelSid, + final String identity + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.identity = identity; } - public InviteCreator setIdentity(final String identity){ + public InviteCreator setIdentity(final String identity) { this.identity = identity; return this; } - public InviteCreator setRoleSid(final String roleSid){ + + public InviteCreator setRoleSid(final String roleSid) { this.roleSid = roleSid; return this; } @Override - public Invite create(final TwilioRestClient client){ + public Invite create(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Invites"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); - path = path.replace("{"+"Identity"+"}", this.identity.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Identity" + "}", this.identity.toString()); Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Invite creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Invite creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -75,14 +93,13 @@ public Invite create(final TwilioRestClient client){ return Invite.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (identity != null) { request.addPostParam("Identity", identity); - } if (roleSid != null) { request.addPostParam("RoleSid", roleSid); - } } } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/InviteDeleter.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/InviteDeleter.java index cf6ae93cbc..2256472b09 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/InviteDeleter.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/InviteDeleter.java @@ -24,27 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class InviteDeleter extends Deleter { + private String pathServiceSid; private String pathChannelSid; private String pathSid; - public InviteDeleter(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public InviteDeleter( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Invites/{Sid}"; + String path = + "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Invites/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -54,9 +65,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Invite delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Invite delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/InviteFetcher.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/InviteFetcher.java index 9ed6b32d46..cb7fe66fb5 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/InviteFetcher.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/InviteFetcher.java @@ -24,28 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class InviteFetcher extends Fetcher { + private String pathServiceSid; private String pathChannelSid; private String pathSid; - public InviteFetcher(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public InviteFetcher( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - @Override public Invite fetch(final TwilioRestClient client) { - String path = "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Invites/{Sid}"; + String path = + "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Invites/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -55,9 +65,14 @@ public Invite fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Invite fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Invite fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/InviteReader.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/InviteReader.java index d708fbd96e..b19c4303ca 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/InviteReader.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/InviteReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.ipmessaging.v1.service.channel; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.converter.Promoter; @@ -25,30 +26,33 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - import java.util.List; - public class InviteReader extends Reader { + private String pathServiceSid; private String pathChannelSid; private List identity; private Integer pageSize; - public InviteReader(final String pathServiceSid, final String pathChannelSid){ + public InviteReader( + final String pathServiceSid, + final String pathChannelSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; } - public InviteReader setIdentity(final List identity){ + public InviteReader setIdentity(final List identity) { this.identity = identity; return this; } - public InviteReader setIdentity(final String identity){ + + public InviteReader setIdentity(final String identity) { return setIdentity(Promoter.listOfOne(identity)); } - public InviteReader setPageSize(final Integer pageSize){ + + public InviteReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -60,8 +64,16 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Invites"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -73,13 +85,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Invite read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Invite read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -95,7 +115,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.IPMESSAGING.toString()) @@ -103,9 +126,11 @@ public Page previousPage(final Page page, final TwilioRestClient return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.IPMESSAGING.toString()) @@ -114,14 +139,15 @@ public Page nextPage(final Page page, final TwilioRestClient cli } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (identity != null) { for (String prop : identity) { @@ -129,11 +155,10 @@ private void addQueryParams(final Request request) { } } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/Member.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/Member.java index 9d7fef4496..e9cc609d97 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/Member.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/Member.java @@ -23,53 +23,71 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Member extends Resource { + private static final long serialVersionUID = 102757132179124L; - public static MemberCreator creator(final String pathServiceSid, final String pathChannelSid, final String identity){ + public static MemberCreator creator( + final String pathServiceSid, + final String pathChannelSid, + final String identity + ) { return new MemberCreator(pathServiceSid, pathChannelSid, identity); } - public static MemberDeleter deleter(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public static MemberDeleter deleter( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { return new MemberDeleter(pathServiceSid, pathChannelSid, pathSid); } - public static MemberFetcher fetcher(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public static MemberFetcher fetcher( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { return new MemberFetcher(pathServiceSid, pathChannelSid, pathSid); } - public static MemberReader reader(final String pathServiceSid, final String pathChannelSid){ + public static MemberReader reader( + final String pathServiceSid, + final String pathChannelSid + ) { return new MemberReader(pathServiceSid, pathChannelSid); } - public static MemberUpdater updater(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public static MemberUpdater updater( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { return new MemberUpdater(pathServiceSid, pathChannelSid, pathSid); } /** - * Converts a JSON String into a Member object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Member object represented by the provided JSON - */ - public static Member fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Member object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Member object represented by the provided JSON + */ + public static Member fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Member.class); @@ -81,14 +99,17 @@ public static Member fromJson(final String json, final ObjectMapper objectMapper } /** - * Converts a JSON InputStream into a Member object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Member object represented by the provided JSON - */ - public static Member fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Member object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Member object represented by the provided JSON + */ + public static Member fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Member.class); @@ -113,38 +134,21 @@ public static Member fromJson(final InputStream json, final ObjectMapper objectM @JsonCreator private Member( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("channel_sid") - final String channelSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("identity") - final String identity, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("role_sid") - final String roleSid, - - @JsonProperty("last_consumed_message_index") - final Integer lastConsumedMessageIndex, - - @JsonProperty("last_consumption_timestamp") - final String lastConsumptionTimestamp, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("channel_sid") final String channelSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("identity") final String identity, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("role_sid") final String roleSid, + @JsonProperty( + "last_consumed_message_index" + ) final Integer lastConsumedMessageIndex, + @JsonProperty( + "last_consumption_timestamp" + ) final String lastConsumptionTimestamp, + @JsonProperty("url") final URI url ) { this.sid = sid; this.accountSid = accountSid; @@ -155,47 +159,58 @@ private Member( this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); this.roleSid = roleSid; this.lastConsumedMessageIndex = lastConsumedMessageIndex; - this.lastConsumptionTimestamp = DateConverter.iso8601DateTimeFromString(lastConsumptionTimestamp); + this.lastConsumptionTimestamp = + DateConverter.iso8601DateTimeFromString(lastConsumptionTimestamp); this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getChannelSid() { - return this.channelSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final String getIdentity() { - return this.identity; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getRoleSid() { - return this.roleSid; - } - public final Integer getLastConsumedMessageIndex() { - return this.lastConsumedMessageIndex; - } - public final ZonedDateTime getLastConsumptionTimestamp() { - return this.lastConsumptionTimestamp; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getChannelSid() { + return this.channelSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final String getIdentity() { + return this.identity; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getRoleSid() { + return this.roleSid; + } + + public final Integer getLastConsumedMessageIndex() { + return this.lastConsumedMessageIndex; + } + + public final ZonedDateTime getLastConsumptionTimestamp() { + return this.lastConsumptionTimestamp; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -205,13 +220,41 @@ public boolean equals(final Object o) { Member other = (Member) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(channelSid, other.channelSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(identity, other.identity) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(roleSid, other.roleSid) && Objects.equals(lastConsumedMessageIndex, other.lastConsumedMessageIndex) && Objects.equals(lastConsumptionTimestamp, other.lastConsumptionTimestamp) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(channelSid, other.channelSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(identity, other.identity) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(roleSid, other.roleSid) && + Objects.equals( + lastConsumedMessageIndex, + other.lastConsumedMessageIndex + ) && + Objects.equals( + lastConsumptionTimestamp, + other.lastConsumptionTimestamp + ) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, channelSid, serviceSid, identity, dateCreated, dateUpdated, roleSid, lastConsumedMessageIndex, lastConsumptionTimestamp, url); + return Objects.hash( + sid, + accountSid, + channelSid, + serviceSid, + identity, + dateCreated, + dateUpdated, + roleSid, + lastConsumedMessageIndex, + lastConsumptionTimestamp, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MemberCreator.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MemberCreator.java index aeb7b56eaf..af237c164b 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MemberCreator.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MemberCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.ipmessaging.v1.service.channel; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,49 +25,66 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class MemberCreator extends Creator { - - -public class MemberCreator extends Creator{ private String pathServiceSid; private String pathChannelSid; private String identity; private String roleSid; - public MemberCreator(final String pathServiceSid, final String pathChannelSid, final String identity) { + public MemberCreator( + final String pathServiceSid, + final String pathChannelSid, + final String identity + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.identity = identity; } - public MemberCreator setIdentity(final String identity){ + public MemberCreator setIdentity(final String identity) { this.identity = identity; return this; } - public MemberCreator setRoleSid(final String roleSid){ + + public MemberCreator setRoleSid(final String roleSid) { this.roleSid = roleSid; return this; } @Override - public Member create(final TwilioRestClient client){ + public Member create(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Members"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); - path = path.replace("{"+"Identity"+"}", this.identity.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Identity" + "}", this.identity.toString()); Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Member creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Member creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -75,14 +93,13 @@ public Member create(final TwilioRestClient client){ return Member.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (identity != null) { request.addPostParam("Identity", identity); - } if (roleSid != null) { request.addPostParam("RoleSid", roleSid); - } } } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MemberDeleter.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MemberDeleter.java index 198b8de97c..a4f77a783c 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MemberDeleter.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MemberDeleter.java @@ -24,27 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class MemberDeleter extends Deleter { + private String pathServiceSid; private String pathChannelSid; private String pathSid; - public MemberDeleter(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public MemberDeleter( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Members/{Sid}"; + String path = + "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Members/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -54,9 +65,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Member delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Member delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MemberFetcher.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MemberFetcher.java index c187486f8d..2e43b6f6d5 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MemberFetcher.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MemberFetcher.java @@ -24,28 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class MemberFetcher extends Fetcher { + private String pathServiceSid; private String pathChannelSid; private String pathSid; - public MemberFetcher(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public MemberFetcher( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - @Override public Member fetch(final TwilioRestClient client) { - String path = "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Members/{Sid}"; + String path = + "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Members/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -55,9 +65,14 @@ public Member fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Member fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Member fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MemberReader.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MemberReader.java index 0bc8854a32..157b230787 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MemberReader.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MemberReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.ipmessaging.v1.service.channel; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.converter.Promoter; @@ -25,30 +26,33 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - import java.util.List; - public class MemberReader extends Reader { + private String pathServiceSid; private String pathChannelSid; private List identity; private Integer pageSize; - public MemberReader(final String pathServiceSid, final String pathChannelSid){ + public MemberReader( + final String pathServiceSid, + final String pathChannelSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; } - public MemberReader setIdentity(final List identity){ + public MemberReader setIdentity(final List identity) { this.identity = identity; return this; } - public MemberReader setIdentity(final String identity){ + + public MemberReader setIdentity(final String identity) { return setIdentity(Promoter.listOfOne(identity)); } - public MemberReader setPageSize(final Integer pageSize){ + + public MemberReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -60,8 +64,16 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Members"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -73,13 +85,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Member read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Member read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -95,7 +115,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.IPMESSAGING.toString()) @@ -103,9 +126,11 @@ public Page previousPage(final Page page, final TwilioRestClient return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.IPMESSAGING.toString()) @@ -114,14 +139,15 @@ public Page nextPage(final Page page, final TwilioRestClient cli } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (identity != null) { for (String prop : identity) { @@ -129,11 +155,10 @@ private void addQueryParams(final Request request) { } } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MemberUpdater.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MemberUpdater.java index 382ae20155..4ab057983c 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MemberUpdater.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MemberUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.ipmessaging.v1.service.channel; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,50 +25,70 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class MemberUpdater extends Updater { - - -public class MemberUpdater extends Updater{ private String pathServiceSid; private String pathChannelSid; private String pathSid; private String roleSid; private Integer lastConsumedMessageIndex; - public MemberUpdater(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public MemberUpdater( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - public MemberUpdater setRoleSid(final String roleSid){ + public MemberUpdater setRoleSid(final String roleSid) { this.roleSid = roleSid; return this; } - public MemberUpdater setLastConsumedMessageIndex(final Integer lastConsumedMessageIndex){ + + public MemberUpdater setLastConsumedMessageIndex( + final Integer lastConsumedMessageIndex + ) { this.lastConsumedMessageIndex = lastConsumedMessageIndex; return this; } @Override - public Member update(final TwilioRestClient client){ - String path = "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Members/{Sid}"; + public Member update(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Members/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Member update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Member update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -76,14 +97,16 @@ public Member update(final TwilioRestClient client){ return Member.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (roleSid != null) { request.addPostParam("RoleSid", roleSid); - } if (lastConsumedMessageIndex != null) { - request.addPostParam("LastConsumedMessageIndex", lastConsumedMessageIndex.toString()); - + request.addPostParam( + "LastConsumedMessageIndex", + lastConsumedMessageIndex.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/Message.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/Message.java index 4306a8b828..b539c0d432 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/Message.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/Message.java @@ -24,53 +24,71 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Message extends Resource { + private static final long serialVersionUID = 148235601690422L; - public static MessageCreator creator(final String pathServiceSid, final String pathChannelSid, final String body){ + public static MessageCreator creator( + final String pathServiceSid, + final String pathChannelSid, + final String body + ) { return new MessageCreator(pathServiceSid, pathChannelSid, body); } - public static MessageDeleter deleter(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public static MessageDeleter deleter( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { return new MessageDeleter(pathServiceSid, pathChannelSid, pathSid); } - public static MessageFetcher fetcher(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public static MessageFetcher fetcher( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { return new MessageFetcher(pathServiceSid, pathChannelSid, pathSid); } - public static MessageReader reader(final String pathServiceSid, final String pathChannelSid){ + public static MessageReader reader( + final String pathServiceSid, + final String pathChannelSid + ) { return new MessageReader(pathServiceSid, pathChannelSid); } - public static MessageUpdater updater(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public static MessageUpdater updater( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { return new MessageUpdater(pathServiceSid, pathChannelSid, pathSid); } /** - * Converts a JSON String into a Message object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Message object represented by the provided JSON - */ - public static Message fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Message object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Message object represented by the provided JSON + */ + public static Message fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Message.class); @@ -82,14 +100,17 @@ public static Message fromJson(final String json, final ObjectMapper objectMappe } /** - * Converts a JSON InputStream into a Message object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Message object represented by the provided JSON - */ - public static Message fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Message object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Message object represented by the provided JSON + */ + public static Message fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Message.class); @@ -99,6 +120,7 @@ public static Message fromJson(final InputStream json, final ObjectMapper object throw new ApiConnectionException(e.getMessage(), e); } } + public enum OrderType { ASC("asc"), DESC("desc"); @@ -135,44 +157,19 @@ public static OrderType forValue(final String value) { @JsonCreator private Message( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("attributes") - final String attributes, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("to") - final String to, - - @JsonProperty("channel_sid") - final String channelSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("was_edited") - final Boolean wasEdited, - - @JsonProperty("from") - final String from, - - @JsonProperty("body") - final String body, - - @JsonProperty("index") - final Integer index, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("attributes") final String attributes, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("to") final String to, + @JsonProperty("channel_sid") final String channelSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("was_edited") final Boolean wasEdited, + @JsonProperty("from") final String from, + @JsonProperty("body") final String body, + @JsonProperty("index") final Integer index, + @JsonProperty("url") final URI url ) { this.sid = sid; this.accountSid = accountSid; @@ -189,49 +186,61 @@ private Message( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getAttributes() { - return this.attributes; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final String getTo() { - return this.to; - } - public final String getChannelSid() { - return this.channelSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final Boolean getWasEdited() { - return this.wasEdited; - } - public final String getFrom() { - return this.from; - } - public final String getBody() { - return this.body; - } - public final Integer getIndex() { - return this.index; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getAttributes() { + return this.attributes; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final String getTo() { + return this.to; + } + + public final String getChannelSid() { + return this.channelSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final Boolean getWasEdited() { + return this.wasEdited; + } + + public final String getFrom() { + return this.from; + } + + public final String getBody() { + return this.body; + } + + public final Integer getIndex() { + return this.index; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -241,13 +250,39 @@ public boolean equals(final Object o) { Message other = (Message) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(attributes, other.attributes) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(to, other.to) && Objects.equals(channelSid, other.channelSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(wasEdited, other.wasEdited) && Objects.equals(from, other.from) && Objects.equals(body, other.body) && Objects.equals(index, other.index) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(attributes, other.attributes) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(to, other.to) && + Objects.equals(channelSid, other.channelSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(wasEdited, other.wasEdited) && + Objects.equals(from, other.from) && + Objects.equals(body, other.body) && + Objects.equals(index, other.index) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, attributes, serviceSid, to, channelSid, dateCreated, dateUpdated, wasEdited, from, body, index, url); + return Objects.hash( + sid, + accountSid, + attributes, + serviceSid, + to, + channelSid, + dateCreated, + dateUpdated, + wasEdited, + from, + body, + index, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MessageCreator.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MessageCreator.java index b496c07f50..019585944c 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MessageCreator.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MessageCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.ipmessaging.v1.service.channel; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,54 +25,73 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class MessageCreator extends Creator { - - -public class MessageCreator extends Creator{ private String pathServiceSid; private String pathChannelSid; private String body; private String from; private String attributes; - public MessageCreator(final String pathServiceSid, final String pathChannelSid, final String body) { + public MessageCreator( + final String pathServiceSid, + final String pathChannelSid, + final String body + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.body = body; } - public MessageCreator setBody(final String body){ + public MessageCreator setBody(final String body) { this.body = body; return this; } - public MessageCreator setFrom(final String from){ + + public MessageCreator setFrom(final String from) { this.from = from; return this; } - public MessageCreator setAttributes(final String attributes){ + + public MessageCreator setAttributes(final String attributes) { this.attributes = attributes; return this; } @Override - public Message create(final TwilioRestClient client){ - String path = "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Messages"; + public Message create(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Messages"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); - path = path.replace("{"+"Body"+"}", this.body.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Body" + "}", this.body.toString()); Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Message creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Message creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -80,18 +100,16 @@ public Message create(final TwilioRestClient client){ return Message.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (body != null) { request.addPostParam("Body", body); - } if (from != null) { request.addPostParam("From", from); - } if (attributes != null) { request.addPostParam("Attributes", attributes); - } } } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MessageDeleter.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MessageDeleter.java index b0031e7c17..d15d6aa211 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MessageDeleter.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MessageDeleter.java @@ -24,27 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class MessageDeleter extends Deleter { + private String pathServiceSid; private String pathChannelSid; private String pathSid; - public MessageDeleter(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public MessageDeleter( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Messages/{Sid}"; + String path = + "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Messages/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -54,9 +65,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Message delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Message delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MessageFetcher.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MessageFetcher.java index d4ca72ce48..27d965b3cb 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MessageFetcher.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MessageFetcher.java @@ -24,28 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class MessageFetcher extends Fetcher { + private String pathServiceSid; private String pathChannelSid; private String pathSid; - public MessageFetcher(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public MessageFetcher( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - @Override public Message fetch(final TwilioRestClient client) { - String path = "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Messages/{Sid}"; + String path = + "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Messages/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -55,9 +65,14 @@ public Message fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Message fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Message fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MessageReader.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MessageReader.java index 20d7437f76..748c1b7390 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MessageReader.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MessageReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.ipmessaging.v1.service.channel; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,26 +25,28 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class MessageReader extends Reader { + private String pathServiceSid; private String pathChannelSid; private Message.OrderType order; private Integer pageSize; - public MessageReader(final String pathServiceSid, final String pathChannelSid){ + public MessageReader( + final String pathServiceSid, + final String pathChannelSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; } - public MessageReader setOrder(final Message.OrderType order){ + public MessageReader setOrder(final Message.OrderType order) { this.order = order; return this; } - public MessageReader setPageSize(final Integer pageSize){ + + public MessageReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -54,9 +57,18 @@ public ResourceSet read(final TwilioRestClient client) { } public Page firstPage(final TwilioRestClient client) { - String path = "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Messages"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); + String path = + "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Messages"; + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -68,13 +80,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Message read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Message read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -90,7 +110,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reques } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.IPMESSAGING.toString()) @@ -98,9 +121,11 @@ public Page previousPage(final Page page, final TwilioRestClie return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.IPMESSAGING.toString()) @@ -109,25 +134,24 @@ public Page nextPage(final Page page, final TwilioRestClient c } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (order != null) { - request.addQueryParam("Order", order.toString()); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MessageUpdater.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MessageUpdater.java index b1fff9a942..25d5587f6f 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MessageUpdater.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MessageUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.ipmessaging.v1.service.channel; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,50 +25,68 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class MessageUpdater extends Updater { - - -public class MessageUpdater extends Updater{ private String pathServiceSid; private String pathChannelSid; private String pathSid; private String body; private String attributes; - public MessageUpdater(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public MessageUpdater( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - public MessageUpdater setBody(final String body){ + public MessageUpdater setBody(final String body) { this.body = body; return this; } - public MessageUpdater setAttributes(final String attributes){ + + public MessageUpdater setAttributes(final String attributes) { this.attributes = attributes; return this; } @Override - public Message update(final TwilioRestClient client){ - String path = "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Messages/{Sid}"; + public Message update(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Messages/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Message update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Message update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -76,14 +95,13 @@ public Message update(final TwilioRestClient client){ return Message.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (body != null) { request.addPostParam("Body", body); - } if (attributes != null) { request.addPostParam("Attributes", attributes); - } } } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/user/UserChannel.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/user/UserChannel.java index b84b1a85d6..588514e44b 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/user/UserChannel.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/user/UserChannel.java @@ -23,37 +23,39 @@ import com.twilio.base.Resource; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class UserChannel extends Resource { + private static final long serialVersionUID = 5311313114138L; - public static UserChannelReader reader(final String pathServiceSid, final String pathUserSid){ + public static UserChannelReader reader( + final String pathServiceSid, + final String pathUserSid + ) { return new UserChannelReader(pathServiceSid, pathUserSid); } /** - * Converts a JSON String into a UserChannel object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return UserChannel object represented by the provided JSON - */ - public static UserChannel fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a UserChannel object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return UserChannel object represented by the provided JSON + */ + public static UserChannel fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, UserChannel.class); @@ -65,14 +67,17 @@ public static UserChannel fromJson(final String json, final ObjectMapper objectM } /** - * Converts a JSON InputStream into a UserChannel object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return UserChannel object represented by the provided JSON - */ - public static UserChannel fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a UserChannel object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return UserChannel object represented by the provided JSON + */ + public static UserChannel fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, UserChannel.class); @@ -82,6 +87,7 @@ public static UserChannel fromJson(final InputStream json, final ObjectMapper ob throw new ApiConnectionException(e.getMessage(), e); } } + public enum ChannelStatus { JOINED("joined"), INVITED("invited"), @@ -114,29 +120,18 @@ public static ChannelStatus forValue(final String value) { @JsonCreator private UserChannel( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("channel_sid") - final String channelSid, - - @JsonProperty("member_sid") - final String memberSid, - - @JsonProperty("status") - final UserChannel.ChannelStatus status, - - @JsonProperty("last_consumed_message_index") - final Integer lastConsumedMessageIndex, - - @JsonProperty("unread_messages_count") - final Integer unreadMessagesCount, - - @JsonProperty("links") - final Map links + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("channel_sid") final String channelSid, + @JsonProperty("member_sid") final String memberSid, + @JsonProperty("status") final UserChannel.ChannelStatus status, + @JsonProperty( + "last_consumed_message_index" + ) final Integer lastConsumedMessageIndex, + @JsonProperty( + "unread_messages_count" + ) final Integer unreadMessagesCount, + @JsonProperty("links") final Map links ) { this.accountSid = accountSid; this.serviceSid = serviceSid; @@ -148,34 +143,41 @@ private UserChannel( this.links = links; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final String getChannelSid() { - return this.channelSid; - } - public final String getMemberSid() { - return this.memberSid; - } - public final UserChannel.ChannelStatus getStatus() { - return this.status; - } - public final Integer getLastConsumedMessageIndex() { - return this.lastConsumedMessageIndex; - } - public final Integer getUnreadMessagesCount() { - return this.unreadMessagesCount; - } - public final Map getLinks() { - return this.links; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final String getChannelSid() { + return this.channelSid; + } + + public final String getMemberSid() { + return this.memberSid; + } + + public final UserChannel.ChannelStatus getStatus() { + return this.status; + } + + public final Integer getLastConsumedMessageIndex() { + return this.lastConsumedMessageIndex; + } + + public final Integer getUnreadMessagesCount() { + return this.unreadMessagesCount; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -185,13 +187,32 @@ public boolean equals(final Object o) { UserChannel other = (UserChannel) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(channelSid, other.channelSid) && Objects.equals(memberSid, other.memberSid) && Objects.equals(status, other.status) && Objects.equals(lastConsumedMessageIndex, other.lastConsumedMessageIndex) && Objects.equals(unreadMessagesCount, other.unreadMessagesCount) && Objects.equals(links, other.links) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(channelSid, other.channelSid) && + Objects.equals(memberSid, other.memberSid) && + Objects.equals(status, other.status) && + Objects.equals( + lastConsumedMessageIndex, + other.lastConsumedMessageIndex + ) && + Objects.equals(unreadMessagesCount, other.unreadMessagesCount) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, serviceSid, channelSid, memberSid, status, lastConsumedMessageIndex, unreadMessagesCount, links); + return Objects.hash( + accountSid, + serviceSid, + channelSid, + memberSid, + status, + lastConsumedMessageIndex, + unreadMessagesCount, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/user/UserChannelReader.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/user/UserChannelReader.java index 6e8ad17a4a..d38a35333a 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/user/UserChannelReader.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/user/UserChannelReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.ipmessaging.v1.service.user; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,21 +25,22 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class UserChannelReader extends Reader { + private String pathServiceSid; private String pathUserSid; private Integer pageSize; - public UserChannelReader(final String pathServiceSid, final String pathUserSid){ + public UserChannelReader( + final String pathServiceSid, + final String pathUserSid + ) { this.pathServiceSid = pathServiceSid; this.pathUserSid = pathUserSid; } - public UserChannelReader setPageSize(final Integer pageSize){ + public UserChannelReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -50,8 +52,12 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Users/{UserSid}/Channels"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"UserSid"+"}", this.pathUserSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "UserSid" + "}", this.pathUserSid.toString()); Request request = new Request( HttpMethod.GET, @@ -63,13 +69,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("UserChannel read failed: Unable to connect to server"); + throw new ApiConnectionException( + "UserChannel read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -85,7 +99,10 @@ private Page pageForRequest(final TwilioRestClient client, final Re } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.IPMESSAGING.toString()) @@ -93,9 +110,11 @@ public Page previousPage(final Page page, final Twilio return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.IPMESSAGING.toString()) @@ -104,21 +123,21 @@ public Page nextPage(final Page page, final TwilioRest } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/Credential.java b/src/main/java/com/twilio/rest/ipmessaging/v2/Credential.java index 07a0b771d3..eba6c95d1c 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/Credential.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/Credential.java @@ -24,53 +24,52 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Credential extends Resource { + private static final long serialVersionUID = 161183169234848L; - public static CredentialCreator creator(final Credential.PushService type){ + public static CredentialCreator creator(final Credential.PushService type) { return new CredentialCreator(type); } - public static CredentialDeleter deleter(final String pathSid){ + public static CredentialDeleter deleter(final String pathSid) { return new CredentialDeleter(pathSid); } - public static CredentialFetcher fetcher(final String pathSid){ + public static CredentialFetcher fetcher(final String pathSid) { return new CredentialFetcher(pathSid); } - public static CredentialReader reader(){ + public static CredentialReader reader() { return new CredentialReader(); } - public static CredentialUpdater updater(final String pathSid){ + public static CredentialUpdater updater(final String pathSid) { return new CredentialUpdater(pathSid); } /** - * Converts a JSON String into a Credential object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Credential object represented by the provided JSON - */ - public static Credential fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Credential object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Credential object represented by the provided JSON + */ + public static Credential fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Credential.class); @@ -82,14 +81,17 @@ public static Credential fromJson(final String json, final ObjectMapper objectMa } /** - * Converts a JSON InputStream into a Credential object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Credential object represented by the provided JSON - */ - public static Credential fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Credential object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Credential object represented by the provided JSON + */ + public static Credential fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Credential.class); @@ -99,6 +101,7 @@ public static Credential fromJson(final InputStream json, final ObjectMapper obj throw new ApiConnectionException(e.getMessage(), e); } } + public enum PushService { GCM("gcm"), APN("apn"), @@ -131,29 +134,14 @@ public static PushService forValue(final String value) { @JsonCreator private Credential( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("type") - final Credential.PushService type, - - @JsonProperty("sandbox") - final String sandbox, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("type") final Credential.PushService type, + @JsonProperty("sandbox") final String sandbox, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url ) { this.sid = sid; this.accountSid = accountSid; @@ -165,34 +153,41 @@ private Credential( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final Credential.PushService getType() { - return this.type; - } - public final String getSandbox() { - return this.sandbox; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final Credential.PushService getType() { + return this.type; + } + + public final String getSandbox() { + return this.sandbox; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -202,13 +197,29 @@ public boolean equals(final Object o) { Credential other = (Credential) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(type, other.type) && Objects.equals(sandbox, other.sandbox) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(type, other.type) && + Objects.equals(sandbox, other.sandbox) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, friendlyName, type, sandbox, dateCreated, dateUpdated, url); + return Objects.hash( + sid, + accountSid, + friendlyName, + type, + sandbox, + dateCreated, + dateUpdated, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/CredentialCreator.java b/src/main/java/com/twilio/rest/ipmessaging/v2/CredentialCreator.java index dd8f73a84c..47835a05d4 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/CredentialCreator.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/CredentialCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.ipmessaging.v2; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class CredentialCreator extends Creator { - - -public class CredentialCreator extends Creator{ private Credential.PushService type; private String friendlyName; private String certificate; @@ -40,88 +39,97 @@ public CredentialCreator(final Credential.PushService type) { this.type = type; } - public CredentialCreator setType(final Credential.PushService type){ + public CredentialCreator setType(final Credential.PushService type) { this.type = type; return this; } - public CredentialCreator setFriendlyName(final String friendlyName){ + + public CredentialCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public CredentialCreator setCertificate(final String certificate){ + + public CredentialCreator setCertificate(final String certificate) { this.certificate = certificate; return this; } - public CredentialCreator setPrivateKey(final String privateKey){ + + public CredentialCreator setPrivateKey(final String privateKey) { this.privateKey = privateKey; return this; } - public CredentialCreator setSandbox(final Boolean sandbox){ + + public CredentialCreator setSandbox(final Boolean sandbox) { this.sandbox = sandbox; return this; } - public CredentialCreator setApiKey(final String apiKey){ + + public CredentialCreator setApiKey(final String apiKey) { this.apiKey = apiKey; return this; } - public CredentialCreator setSecret(final String secret){ + + public CredentialCreator setSecret(final String secret) { this.secret = secret; return this; } @Override - public Credential create(final TwilioRestClient client){ + public Credential create(final TwilioRestClient client) { String path = "/v2/Credentials"; - path = path.replace("{"+"Type"+"}", this.type.toString()); + path = path.replace("{" + "Type" + "}", this.type.toString()); Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Credential creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Credential creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Credential.fromJson(response.getStream(), client.getObjectMapper()); + return Credential.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (type != null) { request.addPostParam("Type", type.toString()); - } if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (certificate != null) { request.addPostParam("Certificate", certificate); - } if (privateKey != null) { request.addPostParam("PrivateKey", privateKey); - } if (sandbox != null) { request.addPostParam("Sandbox", sandbox.toString()); - } if (apiKey != null) { request.addPostParam("ApiKey", apiKey); - } if (secret != null) { request.addPostParam("Secret", secret); - } } } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/CredentialDeleter.java b/src/main/java/com/twilio/rest/ipmessaging/v2/CredentialDeleter.java index b2638f7236..2125b99beb 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/CredentialDeleter.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/CredentialDeleter.java @@ -24,21 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class CredentialDeleter extends Deleter { + private String pathSid; - public CredentialDeleter(final String pathSid){ + public CredentialDeleter(final String pathSid) { this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v2/Credentials/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -48,9 +46,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Credential delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Credential delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/CredentialFetcher.java b/src/main/java/com/twilio/rest/ipmessaging/v2/CredentialFetcher.java index 2c3c09121e..e1913cbaac 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/CredentialFetcher.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/CredentialFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class CredentialFetcher extends Fetcher { + private String pathSid; - public CredentialFetcher(final String pathSid){ + public CredentialFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public Credential fetch(final TwilioRestClient client) { String path = "/v2/Credentials/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,15 +46,23 @@ public Credential fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Credential fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Credential fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Credential.fromJson(response.getStream(), client.getObjectMapper()); + return Credential.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/CredentialReader.java b/src/main/java/com/twilio/rest/ipmessaging/v2/CredentialReader.java index c1b9638921..bc0e49eda0 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/CredentialReader.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/CredentialReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.ipmessaging.v2; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,17 +25,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class CredentialReader extends Reader { + private Integer pageSize; - public CredentialReader(){ - } + public CredentialReader() {} - public CredentialReader setPageSize(final Integer pageSize){ + public CredentialReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -57,13 +55,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Credential read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Credential read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -79,7 +85,10 @@ private Page pageForRequest(final TwilioRestClient client, final Req } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.IPMESSAGING.toString()) @@ -87,9 +96,11 @@ public Page previousPage(final Page page, final TwilioRe return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.IPMESSAGING.toString()) @@ -98,21 +109,21 @@ public Page nextPage(final Page page, final TwilioRestCl } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/CredentialUpdater.java b/src/main/java/com/twilio/rest/ipmessaging/v2/CredentialUpdater.java index 2e07dc53af..3d9435e99e 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/CredentialUpdater.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/CredentialUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.ipmessaging.v2; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class CredentialUpdater extends Updater { - - -public class CredentialUpdater extends Updater{ private String pathSid; private String friendlyName; private String certificate; @@ -36,84 +35,93 @@ public class CredentialUpdater extends Updater{ private String apiKey; private String secret; - public CredentialUpdater(final String pathSid){ + public CredentialUpdater(final String pathSid) { this.pathSid = pathSid; } - public CredentialUpdater setFriendlyName(final String friendlyName){ + public CredentialUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public CredentialUpdater setCertificate(final String certificate){ + + public CredentialUpdater setCertificate(final String certificate) { this.certificate = certificate; return this; } - public CredentialUpdater setPrivateKey(final String privateKey){ + + public CredentialUpdater setPrivateKey(final String privateKey) { this.privateKey = privateKey; return this; } - public CredentialUpdater setSandbox(final Boolean sandbox){ + + public CredentialUpdater setSandbox(final Boolean sandbox) { this.sandbox = sandbox; return this; } - public CredentialUpdater setApiKey(final String apiKey){ + + public CredentialUpdater setApiKey(final String apiKey) { this.apiKey = apiKey; return this; } - public CredentialUpdater setSecret(final String secret){ + + public CredentialUpdater setSecret(final String secret) { this.secret = secret; return this; } @Override - public Credential update(final TwilioRestClient client){ + public Credential update(final TwilioRestClient client) { String path = "/v2/Credentials/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Credential update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Credential update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Credential.fromJson(response.getStream(), client.getObjectMapper()); + return Credential.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (certificate != null) { request.addPostParam("Certificate", certificate); - } if (privateKey != null) { request.addPostParam("PrivateKey", privateKey); - } if (sandbox != null) { request.addPostParam("Sandbox", sandbox.toString()); - } if (apiKey != null) { request.addPostParam("ApiKey", apiKey); - } if (secret != null) { request.addPostParam("Secret", secret); - } } } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/Service.java b/src/main/java/com/twilio/rest/ipmessaging/v2/Service.java index 7cf901c60f..f375007c6d 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/Service.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/Service.java @@ -23,56 +23,55 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.List; import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Service extends Resource { + private static final long serialVersionUID = 187047184630676L; - public static ServiceCreator creator(final String friendlyName){ + public static ServiceCreator creator(final String friendlyName) { return new ServiceCreator(friendlyName); } - public static ServiceDeleter deleter(final String pathSid){ + public static ServiceDeleter deleter(final String pathSid) { return new ServiceDeleter(pathSid); } - public static ServiceFetcher fetcher(final String pathSid){ + public static ServiceFetcher fetcher(final String pathSid) { return new ServiceFetcher(pathSid); } - public static ServiceReader reader(){ + public static ServiceReader reader() { return new ServiceReader(); } - public static ServiceUpdater updater(final String pathSid){ + public static ServiceUpdater updater(final String pathSid) { return new ServiceUpdater(pathSid); } /** - * Converts a JSON String into a Service object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Service object represented by the provided JSON - */ - public static Service fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Service object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Service object represented by the provided JSON + */ + public static Service fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Service.class); @@ -84,14 +83,17 @@ public static Service fromJson(final String json, final ObjectMapper objectMappe } /** - * Converts a JSON InputStream into a Service object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Service object represented by the provided JSON - */ - public static Service fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Service object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Service object represented by the provided JSON + */ + public static Service fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Service.class); @@ -128,74 +130,43 @@ public static Service fromJson(final InputStream json, final ObjectMapper object @JsonCreator private Service( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("default_service_role_sid") - final String defaultServiceRoleSid, - - @JsonProperty("default_channel_role_sid") - final String defaultChannelRoleSid, - - @JsonProperty("default_channel_creator_role_sid") - final String defaultChannelCreatorRoleSid, - - @JsonProperty("read_status_enabled") - final Boolean readStatusEnabled, - - @JsonProperty("reachability_enabled") - final Boolean reachabilityEnabled, - - @JsonProperty("typing_indicator_timeout") - final Integer typingIndicatorTimeout, - - @JsonProperty("consumption_report_interval") - final Integer consumptionReportInterval, - - @JsonProperty("limits") - final Map limits, - - @JsonProperty("pre_webhook_url") - final String preWebhookUrl, - - @JsonProperty("post_webhook_url") - final String postWebhookUrl, - - @JsonProperty("webhook_method") - final String webhookMethod, - - @JsonProperty("webhook_filters") - final List webhookFilters, - - @JsonProperty("pre_webhook_retry_count") - final Integer preWebhookRetryCount, - - @JsonProperty("post_webhook_retry_count") - final Integer postWebhookRetryCount, - - @JsonProperty("notifications") - final Map notifications, - - @JsonProperty("media") - final Map media, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty( + "default_service_role_sid" + ) final String defaultServiceRoleSid, + @JsonProperty( + "default_channel_role_sid" + ) final String defaultChannelRoleSid, + @JsonProperty( + "default_channel_creator_role_sid" + ) final String defaultChannelCreatorRoleSid, + @JsonProperty("read_status_enabled") final Boolean readStatusEnabled, + @JsonProperty("reachability_enabled") final Boolean reachabilityEnabled, + @JsonProperty( + "typing_indicator_timeout" + ) final Integer typingIndicatorTimeout, + @JsonProperty( + "consumption_report_interval" + ) final Integer consumptionReportInterval, + @JsonProperty("limits") final Map limits, + @JsonProperty("pre_webhook_url") final String preWebhookUrl, + @JsonProperty("post_webhook_url") final String postWebhookUrl, + @JsonProperty("webhook_method") final String webhookMethod, + @JsonProperty("webhook_filters") final List webhookFilters, + @JsonProperty( + "pre_webhook_retry_count" + ) final Integer preWebhookRetryCount, + @JsonProperty( + "post_webhook_retry_count" + ) final Integer postWebhookRetryCount, + @JsonProperty("notifications") final Map notifications, + @JsonProperty("media") final Map media, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.sid = sid; this.accountSid = accountSid; @@ -222,79 +193,101 @@ private Service( this.links = links; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getDefaultServiceRoleSid() { - return this.defaultServiceRoleSid; - } - public final String getDefaultChannelRoleSid() { - return this.defaultChannelRoleSid; - } - public final String getDefaultChannelCreatorRoleSid() { - return this.defaultChannelCreatorRoleSid; - } - public final Boolean getReadStatusEnabled() { - return this.readStatusEnabled; - } - public final Boolean getReachabilityEnabled() { - return this.reachabilityEnabled; - } - public final Integer getTypingIndicatorTimeout() { - return this.typingIndicatorTimeout; - } - public final Integer getConsumptionReportInterval() { - return this.consumptionReportInterval; - } - public final Map getLimits() { - return this.limits; - } - public final String getPreWebhookUrl() { - return this.preWebhookUrl; - } - public final String getPostWebhookUrl() { - return this.postWebhookUrl; - } - public final String getWebhookMethod() { - return this.webhookMethod; - } - public final List getWebhookFilters() { - return this.webhookFilters; - } - public final Integer getPreWebhookRetryCount() { - return this.preWebhookRetryCount; - } - public final Integer getPostWebhookRetryCount() { - return this.postWebhookRetryCount; - } - public final Map getNotifications() { - return this.notifications; - } - public final Map getMedia() { - return this.media; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getDefaultServiceRoleSid() { + return this.defaultServiceRoleSid; + } + + public final String getDefaultChannelRoleSid() { + return this.defaultChannelRoleSid; + } + + public final String getDefaultChannelCreatorRoleSid() { + return this.defaultChannelCreatorRoleSid; + } + + public final Boolean getReadStatusEnabled() { + return this.readStatusEnabled; + } + + public final Boolean getReachabilityEnabled() { + return this.reachabilityEnabled; + } + + public final Integer getTypingIndicatorTimeout() { + return this.typingIndicatorTimeout; + } + + public final Integer getConsumptionReportInterval() { + return this.consumptionReportInterval; + } + + public final Map getLimits() { + return this.limits; + } + + public final String getPreWebhookUrl() { + return this.preWebhookUrl; + } + + public final String getPostWebhookUrl() { + return this.postWebhookUrl; + } + + public final String getWebhookMethod() { + return this.webhookMethod; + } + + public final List getWebhookFilters() { + return this.webhookFilters; + } + + public final Integer getPreWebhookRetryCount() { + return this.preWebhookRetryCount; + } + + public final Integer getPostWebhookRetryCount() { + return this.postWebhookRetryCount; + } + + public final Map getNotifications() { + return this.notifications; + } + + public final Map getMedia() { + return this.media; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -304,13 +297,77 @@ public boolean equals(final Object o) { Service other = (Service) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(defaultServiceRoleSid, other.defaultServiceRoleSid) && Objects.equals(defaultChannelRoleSid, other.defaultChannelRoleSid) && Objects.equals(defaultChannelCreatorRoleSid, other.defaultChannelCreatorRoleSid) && Objects.equals(readStatusEnabled, other.readStatusEnabled) && Objects.equals(reachabilityEnabled, other.reachabilityEnabled) && Objects.equals(typingIndicatorTimeout, other.typingIndicatorTimeout) && Objects.equals(consumptionReportInterval, other.consumptionReportInterval) && Objects.equals(limits, other.limits) && Objects.equals(preWebhookUrl, other.preWebhookUrl) && Objects.equals(postWebhookUrl, other.postWebhookUrl) && Objects.equals(webhookMethod, other.webhookMethod) && Objects.equals(webhookFilters, other.webhookFilters) && Objects.equals(preWebhookRetryCount, other.preWebhookRetryCount) && Objects.equals(postWebhookRetryCount, other.postWebhookRetryCount) && Objects.equals(notifications, other.notifications) && Objects.equals(media, other.media) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals( + defaultServiceRoleSid, + other.defaultServiceRoleSid + ) && + Objects.equals( + defaultChannelRoleSid, + other.defaultChannelRoleSid + ) && + Objects.equals( + defaultChannelCreatorRoleSid, + other.defaultChannelCreatorRoleSid + ) && + Objects.equals(readStatusEnabled, other.readStatusEnabled) && + Objects.equals(reachabilityEnabled, other.reachabilityEnabled) && + Objects.equals( + typingIndicatorTimeout, + other.typingIndicatorTimeout + ) && + Objects.equals( + consumptionReportInterval, + other.consumptionReportInterval + ) && + Objects.equals(limits, other.limits) && + Objects.equals(preWebhookUrl, other.preWebhookUrl) && + Objects.equals(postWebhookUrl, other.postWebhookUrl) && + Objects.equals(webhookMethod, other.webhookMethod) && + Objects.equals(webhookFilters, other.webhookFilters) && + Objects.equals(preWebhookRetryCount, other.preWebhookRetryCount) && + Objects.equals( + postWebhookRetryCount, + other.postWebhookRetryCount + ) && + Objects.equals(notifications, other.notifications) && + Objects.equals(media, other.media) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, friendlyName, dateCreated, dateUpdated, defaultServiceRoleSid, defaultChannelRoleSid, defaultChannelCreatorRoleSid, readStatusEnabled, reachabilityEnabled, typingIndicatorTimeout, consumptionReportInterval, limits, preWebhookUrl, postWebhookUrl, webhookMethod, webhookFilters, preWebhookRetryCount, postWebhookRetryCount, notifications, media, url, links); + return Objects.hash( + sid, + accountSid, + friendlyName, + dateCreated, + dateUpdated, + defaultServiceRoleSid, + defaultChannelRoleSid, + defaultChannelCreatorRoleSid, + readStatusEnabled, + reachabilityEnabled, + typingIndicatorTimeout, + consumptionReportInterval, + limits, + preWebhookUrl, + postWebhookUrl, + webhookMethod, + webhookFilters, + preWebhookRetryCount, + postWebhookRetryCount, + notifications, + media, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/ServiceCreator.java b/src/main/java/com/twilio/rest/ipmessaging/v2/ServiceCreator.java index 2dd0371b94..ba11039050 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/ServiceCreator.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/ServiceCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.ipmessaging.v2; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,38 +25,46 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class ServiceCreator extends Creator { - - -public class ServiceCreator extends Creator{ private String friendlyName; public ServiceCreator(final String friendlyName) { this.friendlyName = friendlyName; } - public ServiceCreator setFriendlyName(final String friendlyName){ + public ServiceCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } @Override - public Service create(final TwilioRestClient client){ + public Service create(final TwilioRestClient client) { String path = "/v2/Services"; - path = path.replace("{"+"FriendlyName"+"}", this.friendlyName.toString()); + path = + path.replace( + "{" + "FriendlyName" + "}", + this.friendlyName.toString() + ); Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -64,10 +73,10 @@ public Service create(final TwilioRestClient client){ return Service.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } } } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/ServiceDeleter.java b/src/main/java/com/twilio/rest/ipmessaging/v2/ServiceDeleter.java index 8bfb10e42a..870a150b17 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/ServiceDeleter.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/ServiceDeleter.java @@ -24,21 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class ServiceDeleter extends Deleter { + private String pathSid; - public ServiceDeleter(final String pathSid){ + public ServiceDeleter(final String pathSid) { this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v2/Services/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -48,9 +46,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/ServiceFetcher.java b/src/main/java/com/twilio/rest/ipmessaging/v2/ServiceFetcher.java index dec1e27031..a2fec022a4 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/ServiceFetcher.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/ServiceFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class ServiceFetcher extends Fetcher { + private String pathSid; - public ServiceFetcher(final String pathSid){ + public ServiceFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public Service fetch(final TwilioRestClient client) { String path = "/v2/Services/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,9 +46,14 @@ public Service fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/ServiceReader.java b/src/main/java/com/twilio/rest/ipmessaging/v2/ServiceReader.java index 39dfa9026b..41646a4901 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/ServiceReader.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/ServiceReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.ipmessaging.v2; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,17 +25,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class ServiceReader extends Reader { + private Integer pageSize; - public ServiceReader(){ - } + public ServiceReader() {} - public ServiceReader setPageSize(final Integer pageSize){ + public ServiceReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -57,13 +55,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -79,7 +85,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reques } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.IPMESSAGING.toString()) @@ -87,9 +96,11 @@ public Page previousPage(final Page page, final TwilioRestClie return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.IPMESSAGING.toString()) @@ -98,21 +109,21 @@ public Page nextPage(final Page page, final TwilioRestClient c } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/ServiceUpdater.java b/src/main/java/com/twilio/rest/ipmessaging/v2/ServiceUpdater.java index 73245808e3..47a4191063 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/ServiceUpdater.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/ServiceUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.ipmessaging.v2; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -24,13 +25,11 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.net.URI; - import java.util.List; +public class ServiceUpdater extends Updater { -public class ServiceUpdater extends Updater{ private String pathSid; private String friendlyName; private String defaultServiceRoleSid; @@ -64,163 +63,262 @@ public class ServiceUpdater extends Updater{ private Integer postWebhookRetryCount; private Boolean notificationsLogEnabled; - public ServiceUpdater(final String pathSid){ + public ServiceUpdater(final String pathSid) { this.pathSid = pathSid; } - public ServiceUpdater setFriendlyName(final String friendlyName){ + public ServiceUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public ServiceUpdater setDefaultServiceRoleSid(final String defaultServiceRoleSid){ + + public ServiceUpdater setDefaultServiceRoleSid( + final String defaultServiceRoleSid + ) { this.defaultServiceRoleSid = defaultServiceRoleSid; return this; } - public ServiceUpdater setDefaultChannelRoleSid(final String defaultChannelRoleSid){ + + public ServiceUpdater setDefaultChannelRoleSid( + final String defaultChannelRoleSid + ) { this.defaultChannelRoleSid = defaultChannelRoleSid; return this; } - public ServiceUpdater setDefaultChannelCreatorRoleSid(final String defaultChannelCreatorRoleSid){ + + public ServiceUpdater setDefaultChannelCreatorRoleSid( + final String defaultChannelCreatorRoleSid + ) { this.defaultChannelCreatorRoleSid = defaultChannelCreatorRoleSid; return this; } - public ServiceUpdater setReadStatusEnabled(final Boolean readStatusEnabled){ + + public ServiceUpdater setReadStatusEnabled( + final Boolean readStatusEnabled + ) { this.readStatusEnabled = readStatusEnabled; return this; } - public ServiceUpdater setReachabilityEnabled(final Boolean reachabilityEnabled){ + + public ServiceUpdater setReachabilityEnabled( + final Boolean reachabilityEnabled + ) { this.reachabilityEnabled = reachabilityEnabled; return this; } - public ServiceUpdater setTypingIndicatorTimeout(final Integer typingIndicatorTimeout){ + + public ServiceUpdater setTypingIndicatorTimeout( + final Integer typingIndicatorTimeout + ) { this.typingIndicatorTimeout = typingIndicatorTimeout; return this; } - public ServiceUpdater setConsumptionReportInterval(final Integer consumptionReportInterval){ + + public ServiceUpdater setConsumptionReportInterval( + final Integer consumptionReportInterval + ) { this.consumptionReportInterval = consumptionReportInterval; return this; } - public ServiceUpdater setNotificationsNewMessageEnabled(final Boolean notificationsNewMessageEnabled){ + + public ServiceUpdater setNotificationsNewMessageEnabled( + final Boolean notificationsNewMessageEnabled + ) { this.notificationsNewMessageEnabled = notificationsNewMessageEnabled; return this; } - public ServiceUpdater setNotificationsNewMessageTemplate(final String notificationsNewMessageTemplate){ + + public ServiceUpdater setNotificationsNewMessageTemplate( + final String notificationsNewMessageTemplate + ) { this.notificationsNewMessageTemplate = notificationsNewMessageTemplate; return this; } - public ServiceUpdater setNotificationsNewMessageSound(final String notificationsNewMessageSound){ + + public ServiceUpdater setNotificationsNewMessageSound( + final String notificationsNewMessageSound + ) { this.notificationsNewMessageSound = notificationsNewMessageSound; return this; } - public ServiceUpdater setNotificationsNewMessageBadgeCountEnabled(final Boolean notificationsNewMessageBadgeCountEnabled){ - this.notificationsNewMessageBadgeCountEnabled = notificationsNewMessageBadgeCountEnabled; + + public ServiceUpdater setNotificationsNewMessageBadgeCountEnabled( + final Boolean notificationsNewMessageBadgeCountEnabled + ) { + this.notificationsNewMessageBadgeCountEnabled = + notificationsNewMessageBadgeCountEnabled; return this; } - public ServiceUpdater setNotificationsAddedToChannelEnabled(final Boolean notificationsAddedToChannelEnabled){ - this.notificationsAddedToChannelEnabled = notificationsAddedToChannelEnabled; + + public ServiceUpdater setNotificationsAddedToChannelEnabled( + final Boolean notificationsAddedToChannelEnabled + ) { + this.notificationsAddedToChannelEnabled = + notificationsAddedToChannelEnabled; return this; } - public ServiceUpdater setNotificationsAddedToChannelTemplate(final String notificationsAddedToChannelTemplate){ - this.notificationsAddedToChannelTemplate = notificationsAddedToChannelTemplate; + + public ServiceUpdater setNotificationsAddedToChannelTemplate( + final String notificationsAddedToChannelTemplate + ) { + this.notificationsAddedToChannelTemplate = + notificationsAddedToChannelTemplate; return this; } - public ServiceUpdater setNotificationsAddedToChannelSound(final String notificationsAddedToChannelSound){ - this.notificationsAddedToChannelSound = notificationsAddedToChannelSound; + + public ServiceUpdater setNotificationsAddedToChannelSound( + final String notificationsAddedToChannelSound + ) { + this.notificationsAddedToChannelSound = + notificationsAddedToChannelSound; return this; } - public ServiceUpdater setNotificationsRemovedFromChannelEnabled(final Boolean notificationsRemovedFromChannelEnabled){ - this.notificationsRemovedFromChannelEnabled = notificationsRemovedFromChannelEnabled; + + public ServiceUpdater setNotificationsRemovedFromChannelEnabled( + final Boolean notificationsRemovedFromChannelEnabled + ) { + this.notificationsRemovedFromChannelEnabled = + notificationsRemovedFromChannelEnabled; return this; } - public ServiceUpdater setNotificationsRemovedFromChannelTemplate(final String notificationsRemovedFromChannelTemplate){ - this.notificationsRemovedFromChannelTemplate = notificationsRemovedFromChannelTemplate; + + public ServiceUpdater setNotificationsRemovedFromChannelTemplate( + final String notificationsRemovedFromChannelTemplate + ) { + this.notificationsRemovedFromChannelTemplate = + notificationsRemovedFromChannelTemplate; return this; } - public ServiceUpdater setNotificationsRemovedFromChannelSound(final String notificationsRemovedFromChannelSound){ - this.notificationsRemovedFromChannelSound = notificationsRemovedFromChannelSound; + + public ServiceUpdater setNotificationsRemovedFromChannelSound( + final String notificationsRemovedFromChannelSound + ) { + this.notificationsRemovedFromChannelSound = + notificationsRemovedFromChannelSound; return this; } - public ServiceUpdater setNotificationsInvitedToChannelEnabled(final Boolean notificationsInvitedToChannelEnabled){ - this.notificationsInvitedToChannelEnabled = notificationsInvitedToChannelEnabled; + + public ServiceUpdater setNotificationsInvitedToChannelEnabled( + final Boolean notificationsInvitedToChannelEnabled + ) { + this.notificationsInvitedToChannelEnabled = + notificationsInvitedToChannelEnabled; return this; } - public ServiceUpdater setNotificationsInvitedToChannelTemplate(final String notificationsInvitedToChannelTemplate){ - this.notificationsInvitedToChannelTemplate = notificationsInvitedToChannelTemplate; + + public ServiceUpdater setNotificationsInvitedToChannelTemplate( + final String notificationsInvitedToChannelTemplate + ) { + this.notificationsInvitedToChannelTemplate = + notificationsInvitedToChannelTemplate; return this; } - public ServiceUpdater setNotificationsInvitedToChannelSound(final String notificationsInvitedToChannelSound){ - this.notificationsInvitedToChannelSound = notificationsInvitedToChannelSound; + + public ServiceUpdater setNotificationsInvitedToChannelSound( + final String notificationsInvitedToChannelSound + ) { + this.notificationsInvitedToChannelSound = + notificationsInvitedToChannelSound; return this; } - public ServiceUpdater setPreWebhookUrl(final URI preWebhookUrl){ + + public ServiceUpdater setPreWebhookUrl(final URI preWebhookUrl) { this.preWebhookUrl = preWebhookUrl; return this; } - public ServiceUpdater setPreWebhookUrl(final String preWebhookUrl){ + public ServiceUpdater setPreWebhookUrl(final String preWebhookUrl) { return setPreWebhookUrl(Promoter.uriFromString(preWebhookUrl)); } - public ServiceUpdater setPostWebhookUrl(final URI postWebhookUrl){ + + public ServiceUpdater setPostWebhookUrl(final URI postWebhookUrl) { this.postWebhookUrl = postWebhookUrl; return this; } - public ServiceUpdater setPostWebhookUrl(final String postWebhookUrl){ + public ServiceUpdater setPostWebhookUrl(final String postWebhookUrl) { return setPostWebhookUrl(Promoter.uriFromString(postWebhookUrl)); } - public ServiceUpdater setWebhookMethod(final HttpMethod webhookMethod){ + + public ServiceUpdater setWebhookMethod(final HttpMethod webhookMethod) { this.webhookMethod = webhookMethod; return this; } - public ServiceUpdater setWebhookFilters(final List webhookFilters){ + + public ServiceUpdater setWebhookFilters(final List webhookFilters) { this.webhookFilters = webhookFilters; return this; } - public ServiceUpdater setWebhookFilters(final String webhookFilters){ + + public ServiceUpdater setWebhookFilters(final String webhookFilters) { return setWebhookFilters(Promoter.listOfOne(webhookFilters)); } - public ServiceUpdater setLimitsChannelMembers(final Integer limitsChannelMembers){ + + public ServiceUpdater setLimitsChannelMembers( + final Integer limitsChannelMembers + ) { this.limitsChannelMembers = limitsChannelMembers; return this; } - public ServiceUpdater setLimitsUserChannels(final Integer limitsUserChannels){ + + public ServiceUpdater setLimitsUserChannels( + final Integer limitsUserChannels + ) { this.limitsUserChannels = limitsUserChannels; return this; } - public ServiceUpdater setMediaCompatibilityMessage(final String mediaCompatibilityMessage){ + + public ServiceUpdater setMediaCompatibilityMessage( + final String mediaCompatibilityMessage + ) { this.mediaCompatibilityMessage = mediaCompatibilityMessage; return this; } - public ServiceUpdater setPreWebhookRetryCount(final Integer preWebhookRetryCount){ + + public ServiceUpdater setPreWebhookRetryCount( + final Integer preWebhookRetryCount + ) { this.preWebhookRetryCount = preWebhookRetryCount; return this; } - public ServiceUpdater setPostWebhookRetryCount(final Integer postWebhookRetryCount){ + + public ServiceUpdater setPostWebhookRetryCount( + final Integer postWebhookRetryCount + ) { this.postWebhookRetryCount = postWebhookRetryCount; return this; } - public ServiceUpdater setNotificationsLogEnabled(final Boolean notificationsLogEnabled){ + + public ServiceUpdater setNotificationsLogEnabled( + final Boolean notificationsLogEnabled + ) { this.notificationsLogEnabled = notificationsLogEnabled; return this; } @Override - public Service update(final TwilioRestClient client){ + public Service update(final TwilioRestClient client) { String path = "/v2/Services/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -229,132 +327,180 @@ public Service update(final TwilioRestClient client){ return Service.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (defaultServiceRoleSid != null) { - request.addPostParam("DefaultServiceRoleSid", defaultServiceRoleSid); - + request.addPostParam( + "DefaultServiceRoleSid", + defaultServiceRoleSid + ); } if (defaultChannelRoleSid != null) { - request.addPostParam("DefaultChannelRoleSid", defaultChannelRoleSid); - + request.addPostParam( + "DefaultChannelRoleSid", + defaultChannelRoleSid + ); } if (defaultChannelCreatorRoleSid != null) { - request.addPostParam("DefaultChannelCreatorRoleSid", defaultChannelCreatorRoleSid); - + request.addPostParam( + "DefaultChannelCreatorRoleSid", + defaultChannelCreatorRoleSid + ); } if (readStatusEnabled != null) { - request.addPostParam("ReadStatusEnabled", readStatusEnabled.toString()); - + request.addPostParam( + "ReadStatusEnabled", + readStatusEnabled.toString() + ); } if (reachabilityEnabled != null) { - request.addPostParam("ReachabilityEnabled", reachabilityEnabled.toString()); - + request.addPostParam( + "ReachabilityEnabled", + reachabilityEnabled.toString() + ); } if (typingIndicatorTimeout != null) { - request.addPostParam("TypingIndicatorTimeout", typingIndicatorTimeout.toString()); - + request.addPostParam( + "TypingIndicatorTimeout", + typingIndicatorTimeout.toString() + ); } if (consumptionReportInterval != null) { - request.addPostParam("ConsumptionReportInterval", consumptionReportInterval.toString()); - + request.addPostParam( + "ConsumptionReportInterval", + consumptionReportInterval.toString() + ); } if (notificationsNewMessageEnabled != null) { - request.addPostParam("Notifications.NewMessage.Enabled", notificationsNewMessageEnabled.toString()); - + request.addPostParam( + "Notifications.NewMessage.Enabled", + notificationsNewMessageEnabled.toString() + ); } if (notificationsNewMessageTemplate != null) { - request.addPostParam("Notifications.NewMessage.Template", notificationsNewMessageTemplate); - + request.addPostParam( + "Notifications.NewMessage.Template", + notificationsNewMessageTemplate + ); } if (notificationsNewMessageSound != null) { - request.addPostParam("Notifications.NewMessage.Sound", notificationsNewMessageSound); - + request.addPostParam( + "Notifications.NewMessage.Sound", + notificationsNewMessageSound + ); } if (notificationsNewMessageBadgeCountEnabled != null) { - request.addPostParam("Notifications.NewMessage.BadgeCountEnabled", notificationsNewMessageBadgeCountEnabled.toString()); - + request.addPostParam( + "Notifications.NewMessage.BadgeCountEnabled", + notificationsNewMessageBadgeCountEnabled.toString() + ); } if (notificationsAddedToChannelEnabled != null) { - request.addPostParam("Notifications.AddedToChannel.Enabled", notificationsAddedToChannelEnabled.toString()); - + request.addPostParam( + "Notifications.AddedToChannel.Enabled", + notificationsAddedToChannelEnabled.toString() + ); } if (notificationsAddedToChannelTemplate != null) { - request.addPostParam("Notifications.AddedToChannel.Template", notificationsAddedToChannelTemplate); - + request.addPostParam( + "Notifications.AddedToChannel.Template", + notificationsAddedToChannelTemplate + ); } if (notificationsAddedToChannelSound != null) { - request.addPostParam("Notifications.AddedToChannel.Sound", notificationsAddedToChannelSound); - + request.addPostParam( + "Notifications.AddedToChannel.Sound", + notificationsAddedToChannelSound + ); } if (notificationsRemovedFromChannelEnabled != null) { - request.addPostParam("Notifications.RemovedFromChannel.Enabled", notificationsRemovedFromChannelEnabled.toString()); - + request.addPostParam( + "Notifications.RemovedFromChannel.Enabled", + notificationsRemovedFromChannelEnabled.toString() + ); } if (notificationsRemovedFromChannelTemplate != null) { - request.addPostParam("Notifications.RemovedFromChannel.Template", notificationsRemovedFromChannelTemplate); - + request.addPostParam( + "Notifications.RemovedFromChannel.Template", + notificationsRemovedFromChannelTemplate + ); } if (notificationsRemovedFromChannelSound != null) { - request.addPostParam("Notifications.RemovedFromChannel.Sound", notificationsRemovedFromChannelSound); - + request.addPostParam( + "Notifications.RemovedFromChannel.Sound", + notificationsRemovedFromChannelSound + ); } if (notificationsInvitedToChannelEnabled != null) { - request.addPostParam("Notifications.InvitedToChannel.Enabled", notificationsInvitedToChannelEnabled.toString()); - + request.addPostParam( + "Notifications.InvitedToChannel.Enabled", + notificationsInvitedToChannelEnabled.toString() + ); } if (notificationsInvitedToChannelTemplate != null) { - request.addPostParam("Notifications.InvitedToChannel.Template", notificationsInvitedToChannelTemplate); - + request.addPostParam( + "Notifications.InvitedToChannel.Template", + notificationsInvitedToChannelTemplate + ); } if (notificationsInvitedToChannelSound != null) { - request.addPostParam("Notifications.InvitedToChannel.Sound", notificationsInvitedToChannelSound); - + request.addPostParam( + "Notifications.InvitedToChannel.Sound", + notificationsInvitedToChannelSound + ); } if (preWebhookUrl != null) { request.addPostParam("PreWebhookUrl", preWebhookUrl.toString()); - } if (postWebhookUrl != null) { request.addPostParam("PostWebhookUrl", postWebhookUrl.toString()); - } if (webhookMethod != null) { request.addPostParam("WebhookMethod", webhookMethod.toString()); - } if (webhookFilters != null) { for (String prop : webhookFilters) { request.addPostParam("WebhookFilters", prop); } - } if (limitsChannelMembers != null) { - request.addPostParam("Limits.ChannelMembers", limitsChannelMembers.toString()); - + request.addPostParam( + "Limits.ChannelMembers", + limitsChannelMembers.toString() + ); } if (limitsUserChannels != null) { - request.addPostParam("Limits.UserChannels", limitsUserChannels.toString()); - + request.addPostParam( + "Limits.UserChannels", + limitsUserChannels.toString() + ); } if (mediaCompatibilityMessage != null) { - request.addPostParam("Media.CompatibilityMessage", mediaCompatibilityMessage); - + request.addPostParam( + "Media.CompatibilityMessage", + mediaCompatibilityMessage + ); } if (preWebhookRetryCount != null) { - request.addPostParam("PreWebhookRetryCount", preWebhookRetryCount.toString()); - + request.addPostParam( + "PreWebhookRetryCount", + preWebhookRetryCount.toString() + ); } if (postWebhookRetryCount != null) { - request.addPostParam("PostWebhookRetryCount", postWebhookRetryCount.toString()); - + request.addPostParam( + "PostWebhookRetryCount", + postWebhookRetryCount.toString() + ); } if (notificationsLogEnabled != null) { - request.addPostParam("Notifications.LogEnabled", notificationsLogEnabled.toString()); - + request.addPostParam( + "Notifications.LogEnabled", + notificationsLogEnabled.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/Binding.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/Binding.java index 56f56e4a9c..2052a78ad7 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/Binding.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/Binding.java @@ -24,48 +24,53 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.List; import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Binding extends Resource { + private static final long serialVersionUID = 223064407729885L; - public static BindingDeleter deleter(final String pathServiceSid, final String pathSid){ + public static BindingDeleter deleter( + final String pathServiceSid, + final String pathSid + ) { return new BindingDeleter(pathServiceSid, pathSid); } - public static BindingFetcher fetcher(final String pathServiceSid, final String pathSid){ + public static BindingFetcher fetcher( + final String pathServiceSid, + final String pathSid + ) { return new BindingFetcher(pathServiceSid, pathSid); } - public static BindingReader reader(final String pathServiceSid){ + public static BindingReader reader(final String pathServiceSid) { return new BindingReader(pathServiceSid); } /** - * Converts a JSON String into a Binding object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Binding object represented by the provided JSON - */ - public static Binding fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Binding object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Binding object represented by the provided JSON + */ + public static Binding fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Binding.class); @@ -77,14 +82,17 @@ public static Binding fromJson(final String json, final ObjectMapper objectMappe } /** - * Converts a JSON InputStream into a Binding object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Binding object represented by the provided JSON - */ - public static Binding fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Binding object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Binding object represented by the provided JSON + */ + public static Binding fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Binding.class); @@ -94,6 +102,7 @@ public static Binding fromJson(final InputStream json, final ObjectMapper object throw new ApiConnectionException(e.getMessage(), e); } } + public enum BindingType { GCM("gcm"), APN("apn"), @@ -130,41 +139,18 @@ public static BindingType forValue(final String value) { @JsonCreator private Binding( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("endpoint") - final String endpoint, - - @JsonProperty("identity") - final String identity, - - @JsonProperty("credential_sid") - final String credentialSid, - - @JsonProperty("binding_type") - final Binding.BindingType bindingType, - - @JsonProperty("message_types") - final List messageTypes, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("endpoint") final String endpoint, + @JsonProperty("identity") final String identity, + @JsonProperty("credential_sid") final String credentialSid, + @JsonProperty("binding_type") final Binding.BindingType bindingType, + @JsonProperty("message_types") final List messageTypes, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.sid = sid; this.accountSid = accountSid; @@ -180,46 +166,57 @@ private Binding( this.links = links; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getEndpoint() { - return this.endpoint; - } - public final String getIdentity() { - return this.identity; - } - public final String getCredentialSid() { - return this.credentialSid; - } - public final Binding.BindingType getBindingType() { - return this.bindingType; - } - public final List getMessageTypes() { - return this.messageTypes; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getEndpoint() { + return this.endpoint; + } + + public final String getIdentity() { + return this.identity; + } + + public final String getCredentialSid() { + return this.credentialSid; + } + + public final Binding.BindingType getBindingType() { + return this.bindingType; + } + + public final List getMessageTypes() { + return this.messageTypes; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -229,13 +226,37 @@ public boolean equals(final Object o) { Binding other = (Binding) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(endpoint, other.endpoint) && Objects.equals(identity, other.identity) && Objects.equals(credentialSid, other.credentialSid) && Objects.equals(bindingType, other.bindingType) && Objects.equals(messageTypes, other.messageTypes) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(endpoint, other.endpoint) && + Objects.equals(identity, other.identity) && + Objects.equals(credentialSid, other.credentialSid) && + Objects.equals(bindingType, other.bindingType) && + Objects.equals(messageTypes, other.messageTypes) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, serviceSid, dateCreated, dateUpdated, endpoint, identity, credentialSid, bindingType, messageTypes, url, links); + return Objects.hash( + sid, + accountSid, + serviceSid, + dateCreated, + dateUpdated, + endpoint, + identity, + credentialSid, + bindingType, + messageTypes, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/BindingDeleter.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/BindingDeleter.java index a4e6fb1580..a2749fc19a 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/BindingDeleter.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/BindingDeleter.java @@ -24,24 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class BindingDeleter extends Deleter { + private String pathServiceSid; private String pathSid; - public BindingDeleter(final String pathServiceSid, final String pathSid){ + public BindingDeleter(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v2/Services/{ServiceSid}/Bindings/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +53,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Binding delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Binding delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/BindingFetcher.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/BindingFetcher.java index 0b126d141a..7c8e6484a7 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/BindingFetcher.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/BindingFetcher.java @@ -24,25 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class BindingFetcher extends Fetcher { + private String pathServiceSid; private String pathSid; - public BindingFetcher(final String pathServiceSid, final String pathSid){ + public BindingFetcher(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - @Override public Binding fetch(final TwilioRestClient client) { String path = "/v2/Services/{ServiceSid}/Bindings/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,9 +53,14 @@ public Binding fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Binding fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Binding fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/BindingReader.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/BindingReader.java index 7e69303ba5..f59d03f85f 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/BindingReader.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/BindingReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.ipmessaging.v2.service; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.converter.Promoter; @@ -25,36 +26,40 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - import java.util.List; - public class BindingReader extends Reader { + private String pathServiceSid; private List bindingType; private List identity; private Integer pageSize; - public BindingReader(final String pathServiceSid){ + public BindingReader(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - public BindingReader setBindingType(final List bindingType){ + public BindingReader setBindingType( + final List bindingType + ) { this.bindingType = bindingType; return this; } - public BindingReader setBindingType(final Binding.BindingType bindingType){ + + public BindingReader setBindingType(final Binding.BindingType bindingType) { return setBindingType(Promoter.listOfOne(bindingType)); } - public BindingReader setIdentity(final List identity){ + + public BindingReader setIdentity(final List identity) { this.identity = identity; return this; } - public BindingReader setIdentity(final String identity){ + + public BindingReader setIdentity(final String identity) { return setIdentity(Promoter.listOfOne(identity)); } - public BindingReader setPageSize(final Integer pageSize){ + + public BindingReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -66,7 +71,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v2/Services/{ServiceSid}/Bindings"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -78,13 +87,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Binding read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Binding read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -100,7 +117,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reques } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.IPMESSAGING.toString()) @@ -108,9 +128,11 @@ public Page previousPage(final Page page, final TwilioRestClie return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.IPMESSAGING.toString()) @@ -119,14 +141,15 @@ public Page nextPage(final Page page, final TwilioRestClient c } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (bindingType != null) { for (Binding.BindingType prop : bindingType) { @@ -139,11 +162,10 @@ private void addQueryParams(final Request request) { } } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/Channel.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/Channel.java index 08dbc23436..df09faaee5 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/Channel.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/Channel.java @@ -24,55 +24,63 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Channel extends Resource { + private static final long serialVersionUID = 188288773259274L; - public static ChannelCreator creator(final String pathServiceSid){ + public static ChannelCreator creator(final String pathServiceSid) { return new ChannelCreator(pathServiceSid); } - public static ChannelDeleter deleter(final String pathServiceSid, final String pathSid){ + public static ChannelDeleter deleter( + final String pathServiceSid, + final String pathSid + ) { return new ChannelDeleter(pathServiceSid, pathSid); } - public static ChannelFetcher fetcher(final String pathServiceSid, final String pathSid){ + public static ChannelFetcher fetcher( + final String pathServiceSid, + final String pathSid + ) { return new ChannelFetcher(pathServiceSid, pathSid); } - public static ChannelReader reader(final String pathServiceSid){ + public static ChannelReader reader(final String pathServiceSid) { return new ChannelReader(pathServiceSid); } - public static ChannelUpdater updater(final String pathServiceSid, final String pathSid){ + public static ChannelUpdater updater( + final String pathServiceSid, + final String pathSid + ) { return new ChannelUpdater(pathServiceSid, pathSid); } /** - * Converts a JSON String into a Channel object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Channel object represented by the provided JSON - */ - public static Channel fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Channel object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Channel object represented by the provided JSON + */ + public static Channel fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Channel.class); @@ -84,14 +92,17 @@ public static Channel fromJson(final String json, final ObjectMapper objectMappe } /** - * Converts a JSON InputStream into a Channel object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Channel object represented by the provided JSON - */ - public static Channel fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Channel object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Channel object represented by the provided JSON + */ + public static Channel fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Channel.class); @@ -101,6 +112,7 @@ public static Channel fromJson(final InputStream json, final ObjectMapper object throw new ApiConnectionException(e.getMessage(), e); } } + public enum ChannelType { PUBLIC("public"), PRIVATE("private"); @@ -120,6 +132,7 @@ public static ChannelType forValue(final String value) { return Promoter.enumFromString(value, ChannelType.values()); } } + public enum WebhookEnabledType { TRUE("true"), FALSE("false"); @@ -157,47 +170,20 @@ public static WebhookEnabledType forValue(final String value) { @JsonCreator private Channel( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("unique_name") - final String uniqueName, - - @JsonProperty("attributes") - final String attributes, - - @JsonProperty("type") - final Channel.ChannelType type, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("created_by") - final String createdBy, - - @JsonProperty("members_count") - final Integer membersCount, - - @JsonProperty("messages_count") - final Integer messagesCount, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("attributes") final String attributes, + @JsonProperty("type") final Channel.ChannelType type, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("created_by") final String createdBy, + @JsonProperty("members_count") final Integer membersCount, + @JsonProperty("messages_count") final Integer messagesCount, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.sid = sid; this.accountSid = accountSid; @@ -215,52 +201,65 @@ private Channel( this.links = links; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getUniqueName() { - return this.uniqueName; - } - public final String getAttributes() { - return this.attributes; - } - public final Channel.ChannelType getType() { - return this.type; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getCreatedBy() { - return this.createdBy; - } - public final Integer getMembersCount() { - return this.membersCount; - } - public final Integer getMessagesCount() { - return this.messagesCount; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getUniqueName() { + return this.uniqueName; + } + + public final String getAttributes() { + return this.attributes; + } + + public final Channel.ChannelType getType() { + return this.type; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getCreatedBy() { + return this.createdBy; + } + + public final Integer getMembersCount() { + return this.membersCount; + } + + public final Integer getMessagesCount() { + return this.messagesCount; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -270,13 +269,41 @@ public boolean equals(final Object o) { Channel other = (Channel) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(uniqueName, other.uniqueName) && Objects.equals(attributes, other.attributes) && Objects.equals(type, other.type) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(createdBy, other.createdBy) && Objects.equals(membersCount, other.membersCount) && Objects.equals(messagesCount, other.messagesCount) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(attributes, other.attributes) && + Objects.equals(type, other.type) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(createdBy, other.createdBy) && + Objects.equals(membersCount, other.membersCount) && + Objects.equals(messagesCount, other.messagesCount) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, serviceSid, friendlyName, uniqueName, attributes, type, dateCreated, dateUpdated, createdBy, membersCount, messagesCount, url, links); + return Objects.hash( + sid, + accountSid, + serviceSid, + friendlyName, + uniqueName, + attributes, + type, + dateCreated, + dateUpdated, + createdBy, + membersCount, + messagesCount, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/ChannelCreator.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/ChannelCreator.java index 98c9292885..05e2e2f6c3 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/ChannelCreator.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/ChannelCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.ipmessaging.v2.service; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -25,10 +26,8 @@ import com.twilio.rest.Domains; import java.time.ZonedDateTime; +public class ChannelCreator extends Creator { - - -public class ChannelCreator extends Creator{ private String pathServiceSid; private Channel.WebhookEnabledType xTwilioWebhookEnabled; private String friendlyName; @@ -43,57 +42,76 @@ public ChannelCreator(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - public ChannelCreator setXTwilioWebhookEnabled(final Channel.WebhookEnabledType xTwilioWebhookEnabled){ + public ChannelCreator setXTwilioWebhookEnabled( + final Channel.WebhookEnabledType xTwilioWebhookEnabled + ) { this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; return this; } - public ChannelCreator setFriendlyName(final String friendlyName){ + + public ChannelCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public ChannelCreator setUniqueName(final String uniqueName){ + + public ChannelCreator setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - public ChannelCreator setAttributes(final String attributes){ + + public ChannelCreator setAttributes(final String attributes) { this.attributes = attributes; return this; } - public ChannelCreator setType(final Channel.ChannelType type){ + + public ChannelCreator setType(final Channel.ChannelType type) { this.type = type; return this; } - public ChannelCreator setDateCreated(final ZonedDateTime dateCreated){ + + public ChannelCreator setDateCreated(final ZonedDateTime dateCreated) { this.dateCreated = dateCreated; return this; } - public ChannelCreator setDateUpdated(final ZonedDateTime dateUpdated){ + + public ChannelCreator setDateUpdated(final ZonedDateTime dateUpdated) { this.dateUpdated = dateUpdated; return this; } - public ChannelCreator setCreatedBy(final String createdBy){ + + public ChannelCreator setCreatedBy(final String createdBy) { this.createdBy = createdBy; return this; } @Override - public Channel create(final TwilioRestClient client){ + public Channel create(final TwilioRestClient client) { String path = "/v2/Services/{ServiceSid}/Channels"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); addHeaderParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Channel creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Channel creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -102,40 +120,43 @@ public Channel create(final TwilioRestClient client){ return Channel.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (uniqueName != null) { request.addPostParam("UniqueName", uniqueName); - } if (attributes != null) { request.addPostParam("Attributes", attributes); - } if (type != null) { request.addPostParam("Type", type.toString()); - } if (dateCreated != null) { - request.addPostParam("DateCreated", dateCreated.toInstant().toString()); - + request.addPostParam( + "DateCreated", + dateCreated.toInstant().toString() + ); } if (dateUpdated != null) { - request.addPostParam("DateUpdated", dateUpdated.toInstant().toString()); - + request.addPostParam( + "DateUpdated", + dateUpdated.toInstant().toString() + ); } if (createdBy != null) { request.addPostParam("CreatedBy", createdBy); - } } + private void addHeaderParams(final Request request) { if (xTwilioWebhookEnabled != null) { - request.addHeaderParam("X-Twilio-Webhook-Enabled", xTwilioWebhookEnabled.toString()); - + request.addHeaderParam( + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/ChannelDeleter.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/ChannelDeleter.java index 0a46c1c930..92fbc9705e 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/ChannelDeleter.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/ChannelDeleter.java @@ -24,19 +24,20 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class ChannelDeleter extends Deleter { + private String pathServiceSid; private String pathSid; private Channel.WebhookEnabledType xTwilioWebhookEnabled; - public ChannelDeleter(final String pathServiceSid, final String pathSid){ + public ChannelDeleter(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - public ChannelDeleter setXTwilioWebhookEnabled(final Channel.WebhookEnabledType xTwilioWebhookEnabled){ + public ChannelDeleter setXTwilioWebhookEnabled( + final Channel.WebhookEnabledType xTwilioWebhookEnabled + ) { this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; return this; } @@ -45,8 +46,12 @@ public ChannelDeleter setXTwilioWebhookEnabled(final Channel.WebhookEnabledType public boolean delete(final TwilioRestClient client) { String path = "/v2/Services/{ServiceSid}/Channels/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -57,9 +62,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Channel delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Channel delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -67,10 +77,13 @@ public boolean delete(final TwilioRestClient client) { } return response.getStatusCode() == 204; } + private void addHeaderParams(final Request request) { if (xTwilioWebhookEnabled != null) { - request.addHeaderParam("X-Twilio-Webhook-Enabled", xTwilioWebhookEnabled.toString()); - + request.addHeaderParam( + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/ChannelFetcher.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/ChannelFetcher.java index cf8274fd41..468dbe87d5 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/ChannelFetcher.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/ChannelFetcher.java @@ -24,25 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class ChannelFetcher extends Fetcher { + private String pathServiceSid; private String pathSid; - public ChannelFetcher(final String pathServiceSid, final String pathSid){ + public ChannelFetcher(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - @Override public Channel fetch(final TwilioRestClient client) { String path = "/v2/Services/{ServiceSid}/Channels/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,9 +53,14 @@ public Channel fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Channel fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Channel fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/ChannelReader.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/ChannelReader.java index 8aed1b8ca9..439b7388a5 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/ChannelReader.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/ChannelReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.ipmessaging.v2.service; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.converter.Promoter; @@ -25,28 +26,28 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - import java.util.List; - public class ChannelReader extends Reader { + private String pathServiceSid; private List type; private Integer pageSize; - public ChannelReader(final String pathServiceSid){ + public ChannelReader(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - public ChannelReader setType(final List type){ + public ChannelReader setType(final List type) { this.type = type; return this; } - public ChannelReader setType(final Channel.ChannelType type){ + + public ChannelReader setType(final Channel.ChannelType type) { return setType(Promoter.listOfOne(type)); } - public ChannelReader setPageSize(final Integer pageSize){ + + public ChannelReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -58,7 +59,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v2/Services/{ServiceSid}/Channels"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -70,13 +75,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Channel read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Channel read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -92,7 +105,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reques } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.IPMESSAGING.toString()) @@ -100,9 +116,11 @@ public Page previousPage(final Page page, final TwilioRestClie return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.IPMESSAGING.toString()) @@ -111,14 +129,15 @@ public Page nextPage(final Page page, final TwilioRestClient c } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (type != null) { for (Channel.ChannelType prop : type) { @@ -126,11 +145,10 @@ private void addQueryParams(final Request request) { } } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/ChannelUpdater.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/ChannelUpdater.java index 4c64474f04..7d594ee3db 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/ChannelUpdater.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/ChannelUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.ipmessaging.v2.service; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -23,12 +24,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.time.ZonedDateTime; +public class ChannelUpdater extends Updater { - -public class ChannelUpdater extends Updater{ private String pathServiceSid; private String pathSid; private Channel.WebhookEnabledType xTwilioWebhookEnabled; @@ -39,59 +38,77 @@ public class ChannelUpdater extends Updater{ private ZonedDateTime dateUpdated; private String createdBy; - public ChannelUpdater(final String pathServiceSid, final String pathSid){ + public ChannelUpdater(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - public ChannelUpdater setXTwilioWebhookEnabled(final Channel.WebhookEnabledType xTwilioWebhookEnabled){ + public ChannelUpdater setXTwilioWebhookEnabled( + final Channel.WebhookEnabledType xTwilioWebhookEnabled + ) { this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; return this; } - public ChannelUpdater setFriendlyName(final String friendlyName){ + + public ChannelUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public ChannelUpdater setUniqueName(final String uniqueName){ + + public ChannelUpdater setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - public ChannelUpdater setAttributes(final String attributes){ + + public ChannelUpdater setAttributes(final String attributes) { this.attributes = attributes; return this; } - public ChannelUpdater setDateCreated(final ZonedDateTime dateCreated){ + + public ChannelUpdater setDateCreated(final ZonedDateTime dateCreated) { this.dateCreated = dateCreated; return this; } - public ChannelUpdater setDateUpdated(final ZonedDateTime dateUpdated){ + + public ChannelUpdater setDateUpdated(final ZonedDateTime dateUpdated) { this.dateUpdated = dateUpdated; return this; } - public ChannelUpdater setCreatedBy(final String createdBy){ + + public ChannelUpdater setCreatedBy(final String createdBy) { this.createdBy = createdBy; return this; } @Override - public Channel update(final TwilioRestClient client){ + public Channel update(final TwilioRestClient client) { String path = "/v2/Services/{ServiceSid}/Channels/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); addHeaderParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Channel update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Channel update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -100,36 +117,40 @@ public Channel update(final TwilioRestClient client){ return Channel.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (uniqueName != null) { request.addPostParam("UniqueName", uniqueName); - } if (attributes != null) { request.addPostParam("Attributes", attributes); - } if (dateCreated != null) { - request.addPostParam("DateCreated", dateCreated.toInstant().toString()); - + request.addPostParam( + "DateCreated", + dateCreated.toInstant().toString() + ); } if (dateUpdated != null) { - request.addPostParam("DateUpdated", dateUpdated.toInstant().toString()); - + request.addPostParam( + "DateUpdated", + dateUpdated.toInstant().toString() + ); } if (createdBy != null) { request.addPostParam("CreatedBy", createdBy); - } } + private void addHeaderParams(final Request request) { if (xTwilioWebhookEnabled != null) { - request.addHeaderParam("X-Twilio-Webhook-Enabled", xTwilioWebhookEnabled.toString()); - + request.addHeaderParam( + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/Role.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/Role.java index 5224723faa..7a9025b635 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/Role.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/Role.java @@ -24,54 +24,68 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.List; import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Role extends Resource { + private static final long serialVersionUID = 252065084446046L; - public static RoleCreator creator(final String pathServiceSid, final String friendlyName, final Role.RoleType type, final List permission){ + public static RoleCreator creator( + final String pathServiceSid, + final String friendlyName, + final Role.RoleType type, + final List permission + ) { return new RoleCreator(pathServiceSid, friendlyName, type, permission); } - public static RoleDeleter deleter(final String pathServiceSid, final String pathSid){ + public static RoleDeleter deleter( + final String pathServiceSid, + final String pathSid + ) { return new RoleDeleter(pathServiceSid, pathSid); } - public static RoleFetcher fetcher(final String pathServiceSid, final String pathSid){ + public static RoleFetcher fetcher( + final String pathServiceSid, + final String pathSid + ) { return new RoleFetcher(pathServiceSid, pathSid); } - public static RoleReader reader(final String pathServiceSid){ + public static RoleReader reader(final String pathServiceSid) { return new RoleReader(pathServiceSid); } - public static RoleUpdater updater(final String pathServiceSid, final String pathSid, final List permission){ + public static RoleUpdater updater( + final String pathServiceSid, + final String pathSid, + final List permission + ) { return new RoleUpdater(pathServiceSid, pathSid, permission); } /** - * Converts a JSON String into a Role object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Role object represented by the provided JSON - */ - public static Role fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Role object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Role object represented by the provided JSON + */ + public static Role fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Role.class); @@ -83,14 +97,17 @@ public static Role fromJson(final String json, final ObjectMapper objectMapper) } /** - * Converts a JSON InputStream into a Role object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Role object represented by the provided JSON - */ - public static Role fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Role object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Role object represented by the provided JSON + */ + public static Role fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Role.class); @@ -100,6 +117,7 @@ public static Role fromJson(final InputStream json, final ObjectMapper objectMap throw new ApiConnectionException(e.getMessage(), e); } } + public enum RoleType { CHANNEL("channel"), DEPLOYMENT("deployment"); @@ -132,32 +150,15 @@ public static RoleType forValue(final String value) { @JsonCreator private Role( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("type") - final Role.RoleType type, - - @JsonProperty("permissions") - final List permissions, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("type") final Role.RoleType type, + @JsonProperty("permissions") final List permissions, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url ) { this.sid = sid; this.accountSid = accountSid; @@ -170,37 +171,45 @@ private Role( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final Role.RoleType getType() { - return this.type; - } - public final List getPermissions() { - return this.permissions; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final Role.RoleType getType() { + return this.type; + } + + public final List getPermissions() { + return this.permissions; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -210,13 +219,31 @@ public boolean equals(final Object o) { Role other = (Role) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(type, other.type) && Objects.equals(permissions, other.permissions) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(type, other.type) && + Objects.equals(permissions, other.permissions) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, serviceSid, friendlyName, type, permissions, dateCreated, dateUpdated, url); + return Objects.hash( + sid, + accountSid, + serviceSid, + friendlyName, + type, + permissions, + dateCreated, + dateUpdated, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/RoleCreator.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/RoleCreator.java index ab9466148c..f52a172515 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/RoleCreator.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/RoleCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.ipmessaging.v2.service; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -25,60 +26,81 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.util.List; - import java.util.List; +public class RoleCreator extends Creator { - -public class RoleCreator extends Creator{ private String pathServiceSid; private String friendlyName; private Role.RoleType type; private List permission; - public RoleCreator(final String pathServiceSid, final String friendlyName, final Role.RoleType type, final List permission) { + public RoleCreator( + final String pathServiceSid, + final String friendlyName, + final Role.RoleType type, + final List permission + ) { this.pathServiceSid = pathServiceSid; this.friendlyName = friendlyName; this.type = type; this.permission = permission; } - public RoleCreator setFriendlyName(final String friendlyName){ + public RoleCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public RoleCreator setType(final Role.RoleType type){ + + public RoleCreator setType(final Role.RoleType type) { this.type = type; return this; } - public RoleCreator setPermission(final List permission){ + + public RoleCreator setPermission(final List permission) { this.permission = permission; return this; } - public RoleCreator setPermission(final String permission){ + + public RoleCreator setPermission(final String permission) { return setPermission(Promoter.listOfOne(permission)); } @Override - public Role create(final TwilioRestClient client){ + public Role create(final TwilioRestClient client) { String path = "/v2/Services/{ServiceSid}/Roles"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"FriendlyName"+"}", this.friendlyName.toString()); - path = path.replace("{"+"Type"+"}", this.type.toString()); - path = path.replace("{"+"Permission"+"}", this.permission.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "FriendlyName" + "}", + this.friendlyName.toString() + ); + path = path.replace("{" + "Type" + "}", this.type.toString()); + path = + path.replace("{" + "Permission" + "}", this.permission.toString()); Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Role creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Role creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -87,20 +109,18 @@ public Role create(final TwilioRestClient client){ return Role.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (type != null) { request.addPostParam("Type", type.toString()); - } if (permission != null) { for (String prop : permission) { request.addPostParam("Permission", prop); } - } } } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/RoleDeleter.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/RoleDeleter.java index 9f013e00de..0795ab8f9b 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/RoleDeleter.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/RoleDeleter.java @@ -24,24 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class RoleDeleter extends Deleter { + private String pathServiceSid; private String pathSid; - public RoleDeleter(final String pathServiceSid, final String pathSid){ + public RoleDeleter(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v2/Services/{ServiceSid}/Roles/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +53,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Role delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Role delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/RoleFetcher.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/RoleFetcher.java index 338be63022..be732e440c 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/RoleFetcher.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/RoleFetcher.java @@ -24,25 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class RoleFetcher extends Fetcher { + private String pathServiceSid; private String pathSid; - public RoleFetcher(final String pathServiceSid, final String pathSid){ + public RoleFetcher(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - @Override public Role fetch(final TwilioRestClient client) { String path = "/v2/Services/{ServiceSid}/Roles/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,9 +53,14 @@ public Role fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Role fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Role fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/RoleReader.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/RoleReader.java index b81d261da5..d4ca825520 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/RoleReader.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/RoleReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.ipmessaging.v2.service; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,19 +25,17 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class RoleReader extends Reader { + private String pathServiceSid; private Integer pageSize; - public RoleReader(final String pathServiceSid){ + public RoleReader(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - public RoleReader setPageSize(final Integer pageSize){ + public RoleReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -48,7 +47,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v2/Services/{ServiceSid}/Roles"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -60,13 +63,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Role read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Role read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +93,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request r } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.IPMESSAGING.toString()) @@ -90,9 +104,11 @@ public Page previousPage(final Page page, final TwilioRestClient cli return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.IPMESSAGING.toString()) @@ -101,21 +117,21 @@ public Page nextPage(final Page page, final TwilioRestClient client) } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/RoleUpdater.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/RoleUpdater.java index 8d0b2904a5..f5b49cd94c 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/RoleUpdater.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/RoleUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.ipmessaging.v2.service; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -24,49 +25,63 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - import java.util.List; +public class RoleUpdater extends Updater { -public class RoleUpdater extends Updater{ private String pathServiceSid; private String pathSid; private List permission; - public RoleUpdater(final String pathServiceSid, final String pathSid, final List permission){ + public RoleUpdater( + final String pathServiceSid, + final String pathSid, + final List permission + ) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; this.permission = permission; } - public RoleUpdater setPermission(final List permission){ + public RoleUpdater setPermission(final List permission) { this.permission = permission; return this; } - public RoleUpdater setPermission(final String permission){ + + public RoleUpdater setPermission(final String permission) { return setPermission(Promoter.listOfOne(permission)); } @Override - public Role update(final TwilioRestClient client){ + public Role update(final TwilioRestClient client) { String path = "/v2/Services/{ServiceSid}/Roles/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); - path = path.replace("{"+"Permission"+"}", this.permission.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + path = + path.replace("{" + "Permission" + "}", this.permission.toString()); Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Role update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Role update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -75,12 +90,12 @@ public Role update(final TwilioRestClient client){ return Role.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (permission != null) { for (String prop : permission) { request.addPostParam("Permission", prop); } - } } } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/User.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/User.java index b42014d4c9..0132b668ab 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/User.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/User.java @@ -24,55 +24,66 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class User extends Resource { + private static final long serialVersionUID = 136391609300437L; - public static UserCreator creator(final String pathServiceSid, final String identity){ + public static UserCreator creator( + final String pathServiceSid, + final String identity + ) { return new UserCreator(pathServiceSid, identity); } - public static UserDeleter deleter(final String pathServiceSid, final String pathSid){ + public static UserDeleter deleter( + final String pathServiceSid, + final String pathSid + ) { return new UserDeleter(pathServiceSid, pathSid); } - public static UserFetcher fetcher(final String pathServiceSid, final String pathSid){ + public static UserFetcher fetcher( + final String pathServiceSid, + final String pathSid + ) { return new UserFetcher(pathServiceSid, pathSid); } - public static UserReader reader(final String pathServiceSid){ + public static UserReader reader(final String pathServiceSid) { return new UserReader(pathServiceSid); } - public static UserUpdater updater(final String pathServiceSid, final String pathSid){ + public static UserUpdater updater( + final String pathServiceSid, + final String pathSid + ) { return new UserUpdater(pathServiceSid, pathSid); } /** - * Converts a JSON String into a User object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return User object represented by the provided JSON - */ - public static User fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a User object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return User object represented by the provided JSON + */ + public static User fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, User.class); @@ -84,14 +95,17 @@ public static User fromJson(final String json, final ObjectMapper objectMapper) } /** - * Converts a JSON InputStream into a User object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return User object represented by the provided JSON - */ - public static User fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a User object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return User object represented by the provided JSON + */ + public static User fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, User.class); @@ -101,6 +115,7 @@ public static User fromJson(final InputStream json, final ObjectMapper objectMap throw new ApiConnectionException(e.getMessage(), e); } } + public enum WebhookEnabledType { TRUE("true"), FALSE("false"); @@ -138,47 +153,22 @@ public static WebhookEnabledType forValue(final String value) { @JsonCreator private User( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("attributes") - final String attributes, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("role_sid") - final String roleSid, - - @JsonProperty("identity") - final String identity, - - @JsonProperty("is_online") - final Boolean isOnline, - - @JsonProperty("is_notifiable") - final Boolean isNotifiable, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("joined_channels_count") - final Integer joinedChannelsCount, - - @JsonProperty("links") - final Map links, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("attributes") final String attributes, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("role_sid") final String roleSid, + @JsonProperty("identity") final String identity, + @JsonProperty("is_online") final Boolean isOnline, + @JsonProperty("is_notifiable") final Boolean isNotifiable, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty( + "joined_channels_count" + ) final Integer joinedChannelsCount, + @JsonProperty("links") final Map links, + @JsonProperty("url") final URI url ) { this.sid = sid; this.accountSid = accountSid; @@ -196,52 +186,65 @@ private User( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final String getAttributes() { - return this.attributes; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getRoleSid() { - return this.roleSid; - } - public final String getIdentity() { - return this.identity; - } - public final Boolean getIsOnline() { - return this.isOnline; - } - public final Boolean getIsNotifiable() { - return this.isNotifiable; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final Integer getJoinedChannelsCount() { - return this.joinedChannelsCount; - } - public final Map getLinks() { - return this.links; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final String getAttributes() { + return this.attributes; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getRoleSid() { + return this.roleSid; + } + + public final String getIdentity() { + return this.identity; + } + + public final Boolean getIsOnline() { + return this.isOnline; + } + + public final Boolean getIsNotifiable() { + return this.isNotifiable; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final Integer getJoinedChannelsCount() { + return this.joinedChannelsCount; + } + + public final Map getLinks() { + return this.links; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -251,13 +254,41 @@ public boolean equals(final Object o) { User other = (User) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(attributes, other.attributes) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(roleSid, other.roleSid) && Objects.equals(identity, other.identity) && Objects.equals(isOnline, other.isOnline) && Objects.equals(isNotifiable, other.isNotifiable) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(joinedChannelsCount, other.joinedChannelsCount) && Objects.equals(links, other.links) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(attributes, other.attributes) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(roleSid, other.roleSid) && + Objects.equals(identity, other.identity) && + Objects.equals(isOnline, other.isOnline) && + Objects.equals(isNotifiable, other.isNotifiable) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(joinedChannelsCount, other.joinedChannelsCount) && + Objects.equals(links, other.links) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, serviceSid, attributes, friendlyName, roleSid, identity, isOnline, isNotifiable, dateCreated, dateUpdated, joinedChannelsCount, links, url); + return Objects.hash( + sid, + accountSid, + serviceSid, + attributes, + friendlyName, + roleSid, + identity, + isOnline, + isNotifiable, + dateCreated, + dateUpdated, + joinedChannelsCount, + links, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/UserCreator.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/UserCreator.java index a08298a465..6d2591f131 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/UserCreator.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/UserCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.ipmessaging.v2.service; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class UserCreator extends Creator { - - -public class UserCreator extends Creator{ private String pathServiceSid; private String identity; private User.WebhookEnabledType xTwilioWebhookEnabled; @@ -40,46 +39,62 @@ public UserCreator(final String pathServiceSid, final String identity) { this.identity = identity; } - public UserCreator setIdentity(final String identity){ + public UserCreator setIdentity(final String identity) { this.identity = identity; return this; } - public UserCreator setXTwilioWebhookEnabled(final User.WebhookEnabledType xTwilioWebhookEnabled){ + + public UserCreator setXTwilioWebhookEnabled( + final User.WebhookEnabledType xTwilioWebhookEnabled + ) { this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; return this; } - public UserCreator setRoleSid(final String roleSid){ + + public UserCreator setRoleSid(final String roleSid) { this.roleSid = roleSid; return this; } - public UserCreator setAttributes(final String attributes){ + + public UserCreator setAttributes(final String attributes) { this.attributes = attributes; return this; } - public UserCreator setFriendlyName(final String friendlyName){ + + public UserCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } @Override - public User create(final TwilioRestClient client){ + public User create(final TwilioRestClient client) { String path = "/v2/Services/{ServiceSid}/Users"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Identity"+"}", this.identity.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Identity" + "}", this.identity.toString()); Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); addHeaderParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("User creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "User creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -88,28 +103,28 @@ public User create(final TwilioRestClient client){ return User.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (identity != null) { request.addPostParam("Identity", identity); - } if (roleSid != null) { request.addPostParam("RoleSid", roleSid); - } if (attributes != null) { request.addPostParam("Attributes", attributes); - } if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } } + private void addHeaderParams(final Request request) { if (xTwilioWebhookEnabled != null) { - request.addHeaderParam("X-Twilio-Webhook-Enabled", xTwilioWebhookEnabled.toString()); - + request.addHeaderParam( + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/UserDeleter.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/UserDeleter.java index ef6181d6f8..c8bf7396da 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/UserDeleter.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/UserDeleter.java @@ -24,24 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class UserDeleter extends Deleter { + private String pathServiceSid; private String pathSid; - public UserDeleter(final String pathServiceSid, final String pathSid){ + public UserDeleter(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v2/Services/{ServiceSid}/Users/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +53,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("User delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "User delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/UserFetcher.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/UserFetcher.java index 6274aaf9da..b41870de3a 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/UserFetcher.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/UserFetcher.java @@ -24,25 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class UserFetcher extends Fetcher { + private String pathServiceSid; private String pathSid; - public UserFetcher(final String pathServiceSid, final String pathSid){ + public UserFetcher(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - @Override public User fetch(final TwilioRestClient client) { String path = "/v2/Services/{ServiceSid}/Users/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,9 +53,14 @@ public User fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("User fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "User fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/UserReader.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/UserReader.java index 7f5a981567..2f169b16db 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/UserReader.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/UserReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.ipmessaging.v2.service; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,19 +25,17 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class UserReader extends Reader { + private String pathServiceSid; private Integer pageSize; - public UserReader(final String pathServiceSid){ + public UserReader(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - public UserReader setPageSize(final Integer pageSize){ + public UserReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -48,7 +47,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v2/Services/{ServiceSid}/Users"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -60,13 +63,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("User read failed: Unable to connect to server"); + throw new ApiConnectionException( + "User read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +93,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request r } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.IPMESSAGING.toString()) @@ -90,9 +104,11 @@ public Page previousPage(final Page page, final TwilioRestClient cli return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.IPMESSAGING.toString()) @@ -101,21 +117,21 @@ public Page nextPage(final Page page, final TwilioRestClient client) } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/UserUpdater.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/UserUpdater.java index 7e9c958118..c8a4393ceb 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/UserUpdater.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/UserUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.ipmessaging.v2.service; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class UserUpdater extends Updater { - - -public class UserUpdater extends Updater{ private String pathServiceSid; private String pathSid; private User.WebhookEnabledType xTwilioWebhookEnabled; @@ -35,47 +34,62 @@ public class UserUpdater extends Updater{ private String attributes; private String friendlyName; - public UserUpdater(final String pathServiceSid, final String pathSid){ + public UserUpdater(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - public UserUpdater setXTwilioWebhookEnabled(final User.WebhookEnabledType xTwilioWebhookEnabled){ + public UserUpdater setXTwilioWebhookEnabled( + final User.WebhookEnabledType xTwilioWebhookEnabled + ) { this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; return this; } - public UserUpdater setRoleSid(final String roleSid){ + + public UserUpdater setRoleSid(final String roleSid) { this.roleSid = roleSid; return this; } - public UserUpdater setAttributes(final String attributes){ + + public UserUpdater setAttributes(final String attributes) { this.attributes = attributes; return this; } - public UserUpdater setFriendlyName(final String friendlyName){ + + public UserUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } @Override - public User update(final TwilioRestClient client){ + public User update(final TwilioRestClient client) { String path = "/v2/Services/{ServiceSid}/Users/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); addHeaderParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("User update failed: Unable to connect to server"); + throw new ApiConnectionException( + "User update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -84,24 +98,25 @@ public User update(final TwilioRestClient client){ return User.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (roleSid != null) { request.addPostParam("RoleSid", roleSid); - } if (attributes != null) { request.addPostParam("Attributes", attributes); - } if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } } + private void addHeaderParams(final Request request) { if (xTwilioWebhookEnabled != null) { - request.addHeaderParam("X-Twilio-Webhook-Enabled", xTwilioWebhookEnabled.toString()); - + request.addHeaderParam( + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/Invite.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/Invite.java index a3d2b0bac2..d9dfb25630 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/Invite.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/Invite.java @@ -23,49 +23,63 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Invite extends Resource { + private static final long serialVersionUID = 148273166902210L; - public static InviteCreator creator(final String pathServiceSid, final String pathChannelSid, final String identity){ + public static InviteCreator creator( + final String pathServiceSid, + final String pathChannelSid, + final String identity + ) { return new InviteCreator(pathServiceSid, pathChannelSid, identity); } - public static InviteDeleter deleter(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public static InviteDeleter deleter( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { return new InviteDeleter(pathServiceSid, pathChannelSid, pathSid); } - public static InviteFetcher fetcher(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public static InviteFetcher fetcher( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { return new InviteFetcher(pathServiceSid, pathChannelSid, pathSid); } - public static InviteReader reader(final String pathServiceSid, final String pathChannelSid){ + public static InviteReader reader( + final String pathServiceSid, + final String pathChannelSid + ) { return new InviteReader(pathServiceSid, pathChannelSid); } /** - * Converts a JSON String into a Invite object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Invite object represented by the provided JSON - */ - public static Invite fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Invite object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Invite object represented by the provided JSON + */ + public static Invite fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Invite.class); @@ -77,14 +91,17 @@ public static Invite fromJson(final String json, final ObjectMapper objectMapper } /** - * Converts a JSON InputStream into a Invite object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Invite object represented by the provided JSON - */ - public static Invite fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Invite object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Invite object represented by the provided JSON + */ + public static Invite fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Invite.class); @@ -108,35 +125,16 @@ public static Invite fromJson(final InputStream json, final ObjectMapper objectM @JsonCreator private Invite( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("channel_sid") - final String channelSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("identity") - final String identity, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("role_sid") - final String roleSid, - - @JsonProperty("created_by") - final String createdBy, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("channel_sid") final String channelSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("identity") final String identity, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("role_sid") final String roleSid, + @JsonProperty("created_by") final String createdBy, + @JsonProperty("url") final URI url ) { this.sid = sid; this.accountSid = accountSid; @@ -150,40 +148,49 @@ private Invite( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getChannelSid() { - return this.channelSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final String getIdentity() { - return this.identity; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getRoleSid() { - return this.roleSid; - } - public final String getCreatedBy() { - return this.createdBy; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getChannelSid() { + return this.channelSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final String getIdentity() { + return this.identity; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getRoleSid() { + return this.roleSid; + } + + public final String getCreatedBy() { + return this.createdBy; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -193,13 +200,33 @@ public boolean equals(final Object o) { Invite other = (Invite) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(channelSid, other.channelSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(identity, other.identity) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(roleSid, other.roleSid) && Objects.equals(createdBy, other.createdBy) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(channelSid, other.channelSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(identity, other.identity) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(roleSid, other.roleSid) && + Objects.equals(createdBy, other.createdBy) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, channelSid, serviceSid, identity, dateCreated, dateUpdated, roleSid, createdBy, url); + return Objects.hash( + sid, + accountSid, + channelSid, + serviceSid, + identity, + dateCreated, + dateUpdated, + roleSid, + createdBy, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/InviteCreator.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/InviteCreator.java index 3d8cb7c5d5..b91c1d676e 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/InviteCreator.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/InviteCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.ipmessaging.v2.service.channel; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,49 +25,66 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class InviteCreator extends Creator { - - -public class InviteCreator extends Creator{ private String pathServiceSid; private String pathChannelSid; private String identity; private String roleSid; - public InviteCreator(final String pathServiceSid, final String pathChannelSid, final String identity) { + public InviteCreator( + final String pathServiceSid, + final String pathChannelSid, + final String identity + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.identity = identity; } - public InviteCreator setIdentity(final String identity){ + public InviteCreator setIdentity(final String identity) { this.identity = identity; return this; } - public InviteCreator setRoleSid(final String roleSid){ + + public InviteCreator setRoleSid(final String roleSid) { this.roleSid = roleSid; return this; } @Override - public Invite create(final TwilioRestClient client){ + public Invite create(final TwilioRestClient client) { String path = "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Invites"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); - path = path.replace("{"+"Identity"+"}", this.identity.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Identity" + "}", this.identity.toString()); Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Invite creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Invite creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -75,14 +93,13 @@ public Invite create(final TwilioRestClient client){ return Invite.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (identity != null) { request.addPostParam("Identity", identity); - } if (roleSid != null) { request.addPostParam("RoleSid", roleSid); - } } } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/InviteDeleter.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/InviteDeleter.java index fb1087072f..d83475e0ab 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/InviteDeleter.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/InviteDeleter.java @@ -24,27 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class InviteDeleter extends Deleter { + private String pathServiceSid; private String pathChannelSid; private String pathSid; - public InviteDeleter(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public InviteDeleter( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Invites/{Sid}"; + String path = + "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Invites/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -54,9 +65,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Invite delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Invite delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/InviteFetcher.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/InviteFetcher.java index 9f82450430..74b4a1adf1 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/InviteFetcher.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/InviteFetcher.java @@ -24,28 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class InviteFetcher extends Fetcher { + private String pathServiceSid; private String pathChannelSid; private String pathSid; - public InviteFetcher(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public InviteFetcher( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - @Override public Invite fetch(final TwilioRestClient client) { - String path = "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Invites/{Sid}"; + String path = + "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Invites/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -55,9 +65,14 @@ public Invite fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Invite fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Invite fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/InviteReader.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/InviteReader.java index f407096c12..32b670e143 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/InviteReader.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/InviteReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.ipmessaging.v2.service.channel; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.converter.Promoter; @@ -25,30 +26,33 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - import java.util.List; - public class InviteReader extends Reader { + private String pathServiceSid; private String pathChannelSid; private List identity; private Integer pageSize; - public InviteReader(final String pathServiceSid, final String pathChannelSid){ + public InviteReader( + final String pathServiceSid, + final String pathChannelSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; } - public InviteReader setIdentity(final List identity){ + public InviteReader setIdentity(final List identity) { this.identity = identity; return this; } - public InviteReader setIdentity(final String identity){ + + public InviteReader setIdentity(final String identity) { return setIdentity(Promoter.listOfOne(identity)); } - public InviteReader setPageSize(final Integer pageSize){ + + public InviteReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -60,8 +64,16 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Invites"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -73,13 +85,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Invite read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Invite read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -95,7 +115,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.IPMESSAGING.toString()) @@ -103,9 +126,11 @@ public Page previousPage(final Page page, final TwilioRestClient return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.IPMESSAGING.toString()) @@ -114,14 +139,15 @@ public Page nextPage(final Page page, final TwilioRestClient cli } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (identity != null) { for (String prop : identity) { @@ -129,11 +155,10 @@ private void addQueryParams(final Request request) { } } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/Member.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/Member.java index c411bec408..7f2593f098 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/Member.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/Member.java @@ -24,53 +24,71 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Member extends Resource { + private static final long serialVersionUID = 220317594144302L; - public static MemberCreator creator(final String pathServiceSid, final String pathChannelSid, final String identity){ + public static MemberCreator creator( + final String pathServiceSid, + final String pathChannelSid, + final String identity + ) { return new MemberCreator(pathServiceSid, pathChannelSid, identity); } - public static MemberDeleter deleter(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public static MemberDeleter deleter( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { return new MemberDeleter(pathServiceSid, pathChannelSid, pathSid); } - public static MemberFetcher fetcher(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public static MemberFetcher fetcher( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { return new MemberFetcher(pathServiceSid, pathChannelSid, pathSid); } - public static MemberReader reader(final String pathServiceSid, final String pathChannelSid){ + public static MemberReader reader( + final String pathServiceSid, + final String pathChannelSid + ) { return new MemberReader(pathServiceSid, pathChannelSid); } - public static MemberUpdater updater(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public static MemberUpdater updater( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { return new MemberUpdater(pathServiceSid, pathChannelSid, pathSid); } /** - * Converts a JSON String into a Member object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Member object represented by the provided JSON - */ - public static Member fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Member object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Member object represented by the provided JSON + */ + public static Member fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Member.class); @@ -82,14 +100,17 @@ public static Member fromJson(final String json, final ObjectMapper objectMapper } /** - * Converts a JSON InputStream into a Member object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Member object represented by the provided JSON - */ - public static Member fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Member object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Member object represented by the provided JSON + */ + public static Member fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Member.class); @@ -99,6 +120,7 @@ public static Member fromJson(final InputStream json, final ObjectMapper objectM throw new ApiConnectionException(e.getMessage(), e); } } + public enum WebhookEnabledType { TRUE("true"), FALSE("false"); @@ -134,41 +156,22 @@ public static WebhookEnabledType forValue(final String value) { @JsonCreator private Member( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("channel_sid") - final String channelSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("identity") - final String identity, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("role_sid") - final String roleSid, - - @JsonProperty("last_consumed_message_index") - final Integer lastConsumedMessageIndex, - - @JsonProperty("last_consumption_timestamp") - final String lastConsumptionTimestamp, - - @JsonProperty("url") - final URI url, - - @JsonProperty("attributes") - final String attributes + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("channel_sid") final String channelSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("identity") final String identity, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("role_sid") final String roleSid, + @JsonProperty( + "last_consumed_message_index" + ) final Integer lastConsumedMessageIndex, + @JsonProperty( + "last_consumption_timestamp" + ) final String lastConsumptionTimestamp, + @JsonProperty("url") final URI url, + @JsonProperty("attributes") final String attributes ) { this.sid = sid; this.accountSid = accountSid; @@ -179,51 +182,63 @@ private Member( this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); this.roleSid = roleSid; this.lastConsumedMessageIndex = lastConsumedMessageIndex; - this.lastConsumptionTimestamp = DateConverter.iso8601DateTimeFromString(lastConsumptionTimestamp); + this.lastConsumptionTimestamp = + DateConverter.iso8601DateTimeFromString(lastConsumptionTimestamp); this.url = url; this.attributes = attributes; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getChannelSid() { - return this.channelSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final String getIdentity() { - return this.identity; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getRoleSid() { - return this.roleSid; - } - public final Integer getLastConsumedMessageIndex() { - return this.lastConsumedMessageIndex; - } - public final ZonedDateTime getLastConsumptionTimestamp() { - return this.lastConsumptionTimestamp; - } - public final URI getUrl() { - return this.url; - } - public final String getAttributes() { - return this.attributes; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getChannelSid() { + return this.channelSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final String getIdentity() { + return this.identity; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getRoleSid() { + return this.roleSid; + } + + public final Integer getLastConsumedMessageIndex() { + return this.lastConsumedMessageIndex; + } + + public final ZonedDateTime getLastConsumptionTimestamp() { + return this.lastConsumptionTimestamp; + } + + public final URI getUrl() { + return this.url; + } + + public final String getAttributes() { + return this.attributes; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -233,13 +248,43 @@ public boolean equals(final Object o) { Member other = (Member) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(channelSid, other.channelSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(identity, other.identity) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(roleSid, other.roleSid) && Objects.equals(lastConsumedMessageIndex, other.lastConsumedMessageIndex) && Objects.equals(lastConsumptionTimestamp, other.lastConsumptionTimestamp) && Objects.equals(url, other.url) && Objects.equals(attributes, other.attributes) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(channelSid, other.channelSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(identity, other.identity) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(roleSid, other.roleSid) && + Objects.equals( + lastConsumedMessageIndex, + other.lastConsumedMessageIndex + ) && + Objects.equals( + lastConsumptionTimestamp, + other.lastConsumptionTimestamp + ) && + Objects.equals(url, other.url) && + Objects.equals(attributes, other.attributes) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, channelSid, serviceSid, identity, dateCreated, dateUpdated, roleSid, lastConsumedMessageIndex, lastConsumptionTimestamp, url, attributes); + return Objects.hash( + sid, + accountSid, + channelSid, + serviceSid, + identity, + dateCreated, + dateUpdated, + roleSid, + lastConsumedMessageIndex, + lastConsumptionTimestamp, + url, + attributes + ); } - } - diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MemberCreator.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MemberCreator.java index 9d86f2a5d5..53be525860 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MemberCreator.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MemberCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.ipmessaging.v2.service.channel; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -25,10 +26,8 @@ import com.twilio.rest.Domains; import java.time.ZonedDateTime; +public class MemberCreator extends Creator { - - -public class MemberCreator extends Creator{ private String pathServiceSid; private String pathChannelSid; private String identity; @@ -40,65 +39,96 @@ public class MemberCreator extends Creator{ private ZonedDateTime dateUpdated; private String attributes; - public MemberCreator(final String pathServiceSid, final String pathChannelSid, final String identity) { + public MemberCreator( + final String pathServiceSid, + final String pathChannelSid, + final String identity + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.identity = identity; } - public MemberCreator setIdentity(final String identity){ + public MemberCreator setIdentity(final String identity) { this.identity = identity; return this; } - public MemberCreator setXTwilioWebhookEnabled(final Member.WebhookEnabledType xTwilioWebhookEnabled){ + + public MemberCreator setXTwilioWebhookEnabled( + final Member.WebhookEnabledType xTwilioWebhookEnabled + ) { this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; return this; } - public MemberCreator setRoleSid(final String roleSid){ + + public MemberCreator setRoleSid(final String roleSid) { this.roleSid = roleSid; return this; } - public MemberCreator setLastConsumedMessageIndex(final Integer lastConsumedMessageIndex){ + + public MemberCreator setLastConsumedMessageIndex( + final Integer lastConsumedMessageIndex + ) { this.lastConsumedMessageIndex = lastConsumedMessageIndex; return this; } - public MemberCreator setLastConsumptionTimestamp(final ZonedDateTime lastConsumptionTimestamp){ + + public MemberCreator setLastConsumptionTimestamp( + final ZonedDateTime lastConsumptionTimestamp + ) { this.lastConsumptionTimestamp = lastConsumptionTimestamp; return this; } - public MemberCreator setDateCreated(final ZonedDateTime dateCreated){ + + public MemberCreator setDateCreated(final ZonedDateTime dateCreated) { this.dateCreated = dateCreated; return this; } - public MemberCreator setDateUpdated(final ZonedDateTime dateUpdated){ + + public MemberCreator setDateUpdated(final ZonedDateTime dateUpdated) { this.dateUpdated = dateUpdated; return this; } - public MemberCreator setAttributes(final String attributes){ + + public MemberCreator setAttributes(final String attributes) { this.attributes = attributes; return this; } @Override - public Member create(final TwilioRestClient client){ + public Member create(final TwilioRestClient client) { String path = "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Members"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); - path = path.replace("{"+"Identity"+"}", this.identity.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Identity" + "}", this.identity.toString()); Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); addHeaderParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Member creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Member creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -107,40 +137,49 @@ public Member create(final TwilioRestClient client){ return Member.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (identity != null) { request.addPostParam("Identity", identity); - } if (roleSid != null) { request.addPostParam("RoleSid", roleSid); - } if (lastConsumedMessageIndex != null) { - request.addPostParam("LastConsumedMessageIndex", lastConsumedMessageIndex.toString()); - + request.addPostParam( + "LastConsumedMessageIndex", + lastConsumedMessageIndex.toString() + ); } if (lastConsumptionTimestamp != null) { - request.addPostParam("LastConsumptionTimestamp", lastConsumptionTimestamp.toInstant().toString()); - + request.addPostParam( + "LastConsumptionTimestamp", + lastConsumptionTimestamp.toInstant().toString() + ); } if (dateCreated != null) { - request.addPostParam("DateCreated", dateCreated.toInstant().toString()); - + request.addPostParam( + "DateCreated", + dateCreated.toInstant().toString() + ); } if (dateUpdated != null) { - request.addPostParam("DateUpdated", dateUpdated.toInstant().toString()); - + request.addPostParam( + "DateUpdated", + dateUpdated.toInstant().toString() + ); } if (attributes != null) { request.addPostParam("Attributes", attributes); - } } + private void addHeaderParams(final Request request) { if (xTwilioWebhookEnabled != null) { - request.addHeaderParam("X-Twilio-Webhook-Enabled", xTwilioWebhookEnabled.toString()); - + request.addHeaderParam( + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MemberDeleter.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MemberDeleter.java index b2bc50c76d..1f73b212f2 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MemberDeleter.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MemberDeleter.java @@ -24,32 +24,46 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class MemberDeleter extends Deleter { + private String pathServiceSid; private String pathChannelSid; private String pathSid; private Member.WebhookEnabledType xTwilioWebhookEnabled; - public MemberDeleter(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public MemberDeleter( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - public MemberDeleter setXTwilioWebhookEnabled(final Member.WebhookEnabledType xTwilioWebhookEnabled){ + public MemberDeleter setXTwilioWebhookEnabled( + final Member.WebhookEnabledType xTwilioWebhookEnabled + ) { this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; return this; } @Override public boolean delete(final TwilioRestClient client) { - String path = "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Members/{Sid}"; + String path = + "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Members/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -60,9 +74,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Member delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Member delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -70,10 +89,13 @@ public boolean delete(final TwilioRestClient client) { } return response.getStatusCode() == 204; } + private void addHeaderParams(final Request request) { if (xTwilioWebhookEnabled != null) { - request.addHeaderParam("X-Twilio-Webhook-Enabled", xTwilioWebhookEnabled.toString()); - + request.addHeaderParam( + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MemberFetcher.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MemberFetcher.java index da250c0e92..5a696ff40f 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MemberFetcher.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MemberFetcher.java @@ -24,28 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class MemberFetcher extends Fetcher { + private String pathServiceSid; private String pathChannelSid; private String pathSid; - public MemberFetcher(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public MemberFetcher( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - @Override public Member fetch(final TwilioRestClient client) { - String path = "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Members/{Sid}"; + String path = + "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Members/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -55,9 +65,14 @@ public Member fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Member fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Member fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MemberReader.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MemberReader.java index 627c61477e..dc36b7c162 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MemberReader.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MemberReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.ipmessaging.v2.service.channel; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.converter.Promoter; @@ -25,30 +26,33 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - import java.util.List; - public class MemberReader extends Reader { + private String pathServiceSid; private String pathChannelSid; private List identity; private Integer pageSize; - public MemberReader(final String pathServiceSid, final String pathChannelSid){ + public MemberReader( + final String pathServiceSid, + final String pathChannelSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; } - public MemberReader setIdentity(final List identity){ + public MemberReader setIdentity(final List identity) { this.identity = identity; return this; } - public MemberReader setIdentity(final String identity){ + + public MemberReader setIdentity(final String identity) { return setIdentity(Promoter.listOfOne(identity)); } - public MemberReader setPageSize(final Integer pageSize){ + + public MemberReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -60,8 +64,16 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Members"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -73,13 +85,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Member read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Member read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -95,7 +115,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.IPMESSAGING.toString()) @@ -103,9 +126,11 @@ public Page previousPage(final Page page, final TwilioRestClient return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.IPMESSAGING.toString()) @@ -114,14 +139,15 @@ public Page nextPage(final Page page, final TwilioRestClient cli } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (identity != null) { for (String prop : identity) { @@ -129,11 +155,10 @@ private void addQueryParams(final Request request) { } } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MemberUpdater.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MemberUpdater.java index b9d1453bdf..3f6204f787 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MemberUpdater.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MemberUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.ipmessaging.v2.service.channel; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -23,12 +24,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.time.ZonedDateTime; +public class MemberUpdater extends Updater { - -public class MemberUpdater extends Updater{ private String pathServiceSid; private String pathChannelSid; private String pathSid; @@ -40,61 +39,92 @@ public class MemberUpdater extends Updater{ private ZonedDateTime dateUpdated; private String attributes; - public MemberUpdater(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public MemberUpdater( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - public MemberUpdater setXTwilioWebhookEnabled(final Member.WebhookEnabledType xTwilioWebhookEnabled){ + public MemberUpdater setXTwilioWebhookEnabled( + final Member.WebhookEnabledType xTwilioWebhookEnabled + ) { this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; return this; } - public MemberUpdater setRoleSid(final String roleSid){ + + public MemberUpdater setRoleSid(final String roleSid) { this.roleSid = roleSid; return this; } - public MemberUpdater setLastConsumedMessageIndex(final Integer lastConsumedMessageIndex){ + + public MemberUpdater setLastConsumedMessageIndex( + final Integer lastConsumedMessageIndex + ) { this.lastConsumedMessageIndex = lastConsumedMessageIndex; return this; } - public MemberUpdater setLastConsumptionTimestamp(final ZonedDateTime lastConsumptionTimestamp){ + + public MemberUpdater setLastConsumptionTimestamp( + final ZonedDateTime lastConsumptionTimestamp + ) { this.lastConsumptionTimestamp = lastConsumptionTimestamp; return this; } - public MemberUpdater setDateCreated(final ZonedDateTime dateCreated){ + + public MemberUpdater setDateCreated(final ZonedDateTime dateCreated) { this.dateCreated = dateCreated; return this; } - public MemberUpdater setDateUpdated(final ZonedDateTime dateUpdated){ + + public MemberUpdater setDateUpdated(final ZonedDateTime dateUpdated) { this.dateUpdated = dateUpdated; return this; } - public MemberUpdater setAttributes(final String attributes){ + + public MemberUpdater setAttributes(final String attributes) { this.attributes = attributes; return this; } @Override - public Member update(final TwilioRestClient client){ - String path = "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Members/{Sid}"; - - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + public Member update(final TwilioRestClient client) { + String path = + "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Members/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); addHeaderParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Member update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Member update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -103,36 +133,46 @@ public Member update(final TwilioRestClient client){ return Member.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (roleSid != null) { request.addPostParam("RoleSid", roleSid); - } if (lastConsumedMessageIndex != null) { - request.addPostParam("LastConsumedMessageIndex", lastConsumedMessageIndex.toString()); - + request.addPostParam( + "LastConsumedMessageIndex", + lastConsumedMessageIndex.toString() + ); } if (lastConsumptionTimestamp != null) { - request.addPostParam("LastConsumptionTimestamp", lastConsumptionTimestamp.toInstant().toString()); - + request.addPostParam( + "LastConsumptionTimestamp", + lastConsumptionTimestamp.toInstant().toString() + ); } if (dateCreated != null) { - request.addPostParam("DateCreated", dateCreated.toInstant().toString()); - + request.addPostParam( + "DateCreated", + dateCreated.toInstant().toString() + ); } if (dateUpdated != null) { - request.addPostParam("DateUpdated", dateUpdated.toInstant().toString()); - + request.addPostParam( + "DateUpdated", + dateUpdated.toInstant().toString() + ); } if (attributes != null) { request.addPostParam("Attributes", attributes); - } } + private void addHeaderParams(final Request request) { if (xTwilioWebhookEnabled != null) { - request.addHeaderParam("X-Twilio-Webhook-Enabled", xTwilioWebhookEnabled.toString()); - + request.addHeaderParam( + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/Message.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/Message.java index 78a2d52819..c2270eb3a5 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/Message.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/Message.java @@ -24,55 +24,72 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Message extends Resource { + private static final long serialVersionUID = 210901647084119L; - public static MessageCreator creator(final String pathServiceSid, final String pathChannelSid){ + public static MessageCreator creator( + final String pathServiceSid, + final String pathChannelSid + ) { return new MessageCreator(pathServiceSid, pathChannelSid); } - public static MessageDeleter deleter(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public static MessageDeleter deleter( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { return new MessageDeleter(pathServiceSid, pathChannelSid, pathSid); } - public static MessageFetcher fetcher(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public static MessageFetcher fetcher( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { return new MessageFetcher(pathServiceSid, pathChannelSid, pathSid); } - public static MessageReader reader(final String pathServiceSid, final String pathChannelSid){ + public static MessageReader reader( + final String pathServiceSid, + final String pathChannelSid + ) { return new MessageReader(pathServiceSid, pathChannelSid); } - public static MessageUpdater updater(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public static MessageUpdater updater( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { return new MessageUpdater(pathServiceSid, pathChannelSid, pathSid); } /** - * Converts a JSON String into a Message object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Message object represented by the provided JSON - */ - public static Message fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Message object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Message object represented by the provided JSON + */ + public static Message fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Message.class); @@ -84,14 +101,17 @@ public static Message fromJson(final String json, final ObjectMapper objectMappe } /** - * Converts a JSON InputStream into a Message object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Message object represented by the provided JSON - */ - public static Message fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Message object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Message object represented by the provided JSON + */ + public static Message fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Message.class); @@ -101,6 +121,7 @@ public static Message fromJson(final InputStream json, final ObjectMapper object throw new ApiConnectionException(e.getMessage(), e); } } + public enum OrderType { ASC("asc"), DESC("desc"); @@ -120,6 +141,7 @@ public static OrderType forValue(final String value) { return Promoter.enumFromString(value, OrderType.values()); } } + public enum WebhookEnabledType { TRUE("true"), FALSE("false"); @@ -159,53 +181,22 @@ public static WebhookEnabledType forValue(final String value) { @JsonCreator private Message( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("attributes") - final String attributes, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("to") - final String to, - - @JsonProperty("channel_sid") - final String channelSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("last_updated_by") - final String lastUpdatedBy, - - @JsonProperty("was_edited") - final Boolean wasEdited, - - @JsonProperty("from") - final String from, - - @JsonProperty("body") - final String body, - - @JsonProperty("index") - final Integer index, - - @JsonProperty("type") - final String type, - - @JsonProperty("media") - final Map media, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("attributes") final String attributes, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("to") final String to, + @JsonProperty("channel_sid") final String channelSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("last_updated_by") final String lastUpdatedBy, + @JsonProperty("was_edited") final Boolean wasEdited, + @JsonProperty("from") final String from, + @JsonProperty("body") final String body, + @JsonProperty("index") final Integer index, + @JsonProperty("type") final String type, + @JsonProperty("media") final Map media, + @JsonProperty("url") final URI url ) { this.sid = sid; this.accountSid = accountSid; @@ -225,58 +216,73 @@ private Message( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getAttributes() { - return this.attributes; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final String getTo() { - return this.to; - } - public final String getChannelSid() { - return this.channelSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getLastUpdatedBy() { - return this.lastUpdatedBy; - } - public final Boolean getWasEdited() { - return this.wasEdited; - } - public final String getFrom() { - return this.from; - } - public final String getBody() { - return this.body; - } - public final Integer getIndex() { - return this.index; - } - public final String getType() { - return this.type; - } - public final Map getMedia() { - return this.media; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getAttributes() { + return this.attributes; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final String getTo() { + return this.to; + } + + public final String getChannelSid() { + return this.channelSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getLastUpdatedBy() { + return this.lastUpdatedBy; + } + + public final Boolean getWasEdited() { + return this.wasEdited; + } + + public final String getFrom() { + return this.from; + } + + public final String getBody() { + return this.body; + } + + public final Integer getIndex() { + return this.index; + } + + public final String getType() { + return this.type; + } + + public final Map getMedia() { + return this.media; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -286,13 +292,45 @@ public boolean equals(final Object o) { Message other = (Message) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(attributes, other.attributes) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(to, other.to) && Objects.equals(channelSid, other.channelSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(lastUpdatedBy, other.lastUpdatedBy) && Objects.equals(wasEdited, other.wasEdited) && Objects.equals(from, other.from) && Objects.equals(body, other.body) && Objects.equals(index, other.index) && Objects.equals(type, other.type) && Objects.equals(media, other.media) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(attributes, other.attributes) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(to, other.to) && + Objects.equals(channelSid, other.channelSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(lastUpdatedBy, other.lastUpdatedBy) && + Objects.equals(wasEdited, other.wasEdited) && + Objects.equals(from, other.from) && + Objects.equals(body, other.body) && + Objects.equals(index, other.index) && + Objects.equals(type, other.type) && + Objects.equals(media, other.media) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, attributes, serviceSid, to, channelSid, dateCreated, dateUpdated, lastUpdatedBy, wasEdited, from, body, index, type, media, url); + return Objects.hash( + sid, + accountSid, + attributes, + serviceSid, + to, + channelSid, + dateCreated, + dateUpdated, + lastUpdatedBy, + wasEdited, + from, + body, + index, + type, + media, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MessageCreator.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MessageCreator.java index c768beedf1..c9ffe458bb 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MessageCreator.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MessageCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.ipmessaging.v2.service.channel; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -25,10 +26,8 @@ import com.twilio.rest.Domains; import java.time.ZonedDateTime; +public class MessageCreator extends Creator { - - -public class MessageCreator extends Creator{ private String pathServiceSid; private String pathChannelSid; private Message.WebhookEnabledType xTwilioWebhookEnabled; @@ -40,63 +39,90 @@ public class MessageCreator extends Creator{ private String body; private String mediaSid; - public MessageCreator(final String pathServiceSid, final String pathChannelSid) { + public MessageCreator( + final String pathServiceSid, + final String pathChannelSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; } - public MessageCreator setXTwilioWebhookEnabled(final Message.WebhookEnabledType xTwilioWebhookEnabled){ + public MessageCreator setXTwilioWebhookEnabled( + final Message.WebhookEnabledType xTwilioWebhookEnabled + ) { this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; return this; } - public MessageCreator setFrom(final String from){ + + public MessageCreator setFrom(final String from) { this.from = from; return this; } - public MessageCreator setAttributes(final String attributes){ + + public MessageCreator setAttributes(final String attributes) { this.attributes = attributes; return this; } - public MessageCreator setDateCreated(final ZonedDateTime dateCreated){ + + public MessageCreator setDateCreated(final ZonedDateTime dateCreated) { this.dateCreated = dateCreated; return this; } - public MessageCreator setDateUpdated(final ZonedDateTime dateUpdated){ + + public MessageCreator setDateUpdated(final ZonedDateTime dateUpdated) { this.dateUpdated = dateUpdated; return this; } - public MessageCreator setLastUpdatedBy(final String lastUpdatedBy){ + + public MessageCreator setLastUpdatedBy(final String lastUpdatedBy) { this.lastUpdatedBy = lastUpdatedBy; return this; } - public MessageCreator setBody(final String body){ + + public MessageCreator setBody(final String body) { this.body = body; return this; } - public MessageCreator setMediaSid(final String mediaSid){ + + public MessageCreator setMediaSid(final String mediaSid) { this.mediaSid = mediaSid; return this; } @Override - public Message create(final TwilioRestClient client){ - String path = "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Messages"; + public Message create(final TwilioRestClient client) { + String path = + "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Messages"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); addHeaderParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Message creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Message creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -105,40 +131,43 @@ public Message create(final TwilioRestClient client){ return Message.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (from != null) { request.addPostParam("From", from); - } if (attributes != null) { request.addPostParam("Attributes", attributes); - } if (dateCreated != null) { - request.addPostParam("DateCreated", dateCreated.toInstant().toString()); - + request.addPostParam( + "DateCreated", + dateCreated.toInstant().toString() + ); } if (dateUpdated != null) { - request.addPostParam("DateUpdated", dateUpdated.toInstant().toString()); - + request.addPostParam( + "DateUpdated", + dateUpdated.toInstant().toString() + ); } if (lastUpdatedBy != null) { request.addPostParam("LastUpdatedBy", lastUpdatedBy); - } if (body != null) { request.addPostParam("Body", body); - } if (mediaSid != null) { request.addPostParam("MediaSid", mediaSid); - } } + private void addHeaderParams(final Request request) { if (xTwilioWebhookEnabled != null) { - request.addHeaderParam("X-Twilio-Webhook-Enabled", xTwilioWebhookEnabled.toString()); - + request.addHeaderParam( + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MessageDeleter.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MessageDeleter.java index aef9a2e5a6..b98db30a05 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MessageDeleter.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MessageDeleter.java @@ -24,32 +24,46 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class MessageDeleter extends Deleter { + private String pathServiceSid; private String pathChannelSid; private String pathSid; private Message.WebhookEnabledType xTwilioWebhookEnabled; - public MessageDeleter(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public MessageDeleter( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - public MessageDeleter setXTwilioWebhookEnabled(final Message.WebhookEnabledType xTwilioWebhookEnabled){ + public MessageDeleter setXTwilioWebhookEnabled( + final Message.WebhookEnabledType xTwilioWebhookEnabled + ) { this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; return this; } @Override public boolean delete(final TwilioRestClient client) { - String path = "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Messages/{Sid}"; + String path = + "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Messages/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -60,9 +74,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Message delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Message delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -70,10 +89,13 @@ public boolean delete(final TwilioRestClient client) { } return response.getStatusCode() == 204; } + private void addHeaderParams(final Request request) { if (xTwilioWebhookEnabled != null) { - request.addHeaderParam("X-Twilio-Webhook-Enabled", xTwilioWebhookEnabled.toString()); - + request.addHeaderParam( + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MessageFetcher.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MessageFetcher.java index ddc63ead21..da788c2098 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MessageFetcher.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MessageFetcher.java @@ -24,28 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class MessageFetcher extends Fetcher { + private String pathServiceSid; private String pathChannelSid; private String pathSid; - public MessageFetcher(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public MessageFetcher( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - @Override public Message fetch(final TwilioRestClient client) { - String path = "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Messages/{Sid}"; + String path = + "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Messages/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -55,9 +65,14 @@ public Message fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Message fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Message fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MessageReader.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MessageReader.java index e3aca10f86..4ccdd8563b 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MessageReader.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MessageReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.ipmessaging.v2.service.channel; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,26 +25,28 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class MessageReader extends Reader { + private String pathServiceSid; private String pathChannelSid; private Message.OrderType order; private Integer pageSize; - public MessageReader(final String pathServiceSid, final String pathChannelSid){ + public MessageReader( + final String pathServiceSid, + final String pathChannelSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; } - public MessageReader setOrder(final Message.OrderType order){ + public MessageReader setOrder(final Message.OrderType order) { this.order = order; return this; } - public MessageReader setPageSize(final Integer pageSize){ + + public MessageReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -54,9 +57,18 @@ public ResourceSet read(final TwilioRestClient client) { } public Page firstPage(final TwilioRestClient client) { - String path = "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Messages"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); + String path = + "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Messages"; + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -68,13 +80,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Message read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Message read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -90,7 +110,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reques } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.IPMESSAGING.toString()) @@ -98,9 +121,11 @@ public Page previousPage(final Page page, final TwilioRestClie return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.IPMESSAGING.toString()) @@ -109,25 +134,24 @@ public Page nextPage(final Page page, final TwilioRestClient c } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (order != null) { - request.addQueryParam("Order", order.toString()); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MessageUpdater.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MessageUpdater.java index 2b476b4d39..66d44aa14c 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MessageUpdater.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MessageUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.ipmessaging.v2.service.channel; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -23,12 +24,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.time.ZonedDateTime; +public class MessageUpdater extends Updater { - -public class MessageUpdater extends Updater{ private String pathServiceSid; private String pathChannelSid; private String pathSid; @@ -40,61 +39,88 @@ public class MessageUpdater extends Updater{ private String lastUpdatedBy; private String from; - public MessageUpdater(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public MessageUpdater( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - public MessageUpdater setXTwilioWebhookEnabled(final Message.WebhookEnabledType xTwilioWebhookEnabled){ + public MessageUpdater setXTwilioWebhookEnabled( + final Message.WebhookEnabledType xTwilioWebhookEnabled + ) { this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; return this; } - public MessageUpdater setBody(final String body){ + + public MessageUpdater setBody(final String body) { this.body = body; return this; } - public MessageUpdater setAttributes(final String attributes){ + + public MessageUpdater setAttributes(final String attributes) { this.attributes = attributes; return this; } - public MessageUpdater setDateCreated(final ZonedDateTime dateCreated){ + + public MessageUpdater setDateCreated(final ZonedDateTime dateCreated) { this.dateCreated = dateCreated; return this; } - public MessageUpdater setDateUpdated(final ZonedDateTime dateUpdated){ + + public MessageUpdater setDateUpdated(final ZonedDateTime dateUpdated) { this.dateUpdated = dateUpdated; return this; } - public MessageUpdater setLastUpdatedBy(final String lastUpdatedBy){ + + public MessageUpdater setLastUpdatedBy(final String lastUpdatedBy) { this.lastUpdatedBy = lastUpdatedBy; return this; } - public MessageUpdater setFrom(final String from){ + + public MessageUpdater setFrom(final String from) { this.from = from; return this; } @Override - public Message update(final TwilioRestClient client){ - String path = "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Messages/{Sid}"; + public Message update(final TwilioRestClient client) { + String path = + "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Messages/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); addHeaderParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Message update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Message update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -103,36 +129,40 @@ public Message update(final TwilioRestClient client){ return Message.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (body != null) { request.addPostParam("Body", body); - } if (attributes != null) { request.addPostParam("Attributes", attributes); - } if (dateCreated != null) { - request.addPostParam("DateCreated", dateCreated.toInstant().toString()); - + request.addPostParam( + "DateCreated", + dateCreated.toInstant().toString() + ); } if (dateUpdated != null) { - request.addPostParam("DateUpdated", dateUpdated.toInstant().toString()); - + request.addPostParam( + "DateUpdated", + dateUpdated.toInstant().toString() + ); } if (lastUpdatedBy != null) { request.addPostParam("LastUpdatedBy", lastUpdatedBy); - } if (from != null) { request.addPostParam("From", from); - } } + private void addHeaderParams(final Request request) { if (xTwilioWebhookEnabled != null) { - request.addHeaderParam("X-Twilio-Webhook-Enabled", xTwilioWebhookEnabled.toString()); - + request.addHeaderParam( + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/Webhook.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/Webhook.java index 79f91a4aac..03065d60c5 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/Webhook.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/Webhook.java @@ -24,55 +24,73 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Webhook extends Resource { + private static final long serialVersionUID = 201752828404640L; - public static WebhookCreator creator(final String pathServiceSid, final String pathChannelSid, final Webhook.Type type){ + public static WebhookCreator creator( + final String pathServiceSid, + final String pathChannelSid, + final Webhook.Type type + ) { return new WebhookCreator(pathServiceSid, pathChannelSid, type); } - public static WebhookDeleter deleter(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public static WebhookDeleter deleter( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { return new WebhookDeleter(pathServiceSid, pathChannelSid, pathSid); } - public static WebhookFetcher fetcher(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public static WebhookFetcher fetcher( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { return new WebhookFetcher(pathServiceSid, pathChannelSid, pathSid); } - public static WebhookReader reader(final String pathServiceSid, final String pathChannelSid){ + public static WebhookReader reader( + final String pathServiceSid, + final String pathChannelSid + ) { return new WebhookReader(pathServiceSid, pathChannelSid); } - public static WebhookUpdater updater(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public static WebhookUpdater updater( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { return new WebhookUpdater(pathServiceSid, pathChannelSid, pathSid); } /** - * Converts a JSON String into a Webhook object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Webhook object represented by the provided JSON - */ - public static Webhook fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Webhook object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Webhook object represented by the provided JSON + */ + public static Webhook fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Webhook.class); @@ -84,14 +102,17 @@ public static Webhook fromJson(final String json, final ObjectMapper objectMappe } /** - * Converts a JSON InputStream into a Webhook object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Webhook object represented by the provided JSON - */ - public static Webhook fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Webhook object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Webhook object represented by the provided JSON + */ + public static Webhook fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Webhook.class); @@ -101,6 +122,7 @@ public static Webhook fromJson(final InputStream json, final ObjectMapper object throw new ApiConnectionException(e.getMessage(), e); } } + public enum Method { GET("GET"), POST("POST"); @@ -120,6 +142,7 @@ public static Method forValue(final String value) { return Promoter.enumFromString(value, Method.values()); } } + public enum Type { WEBHOOK("webhook"), TRIGGER("trigger"), @@ -153,32 +176,15 @@ public static Type forValue(final String value) { @JsonCreator private Webhook( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("channel_sid") - final String channelSid, - - @JsonProperty("type") - final String type, - - @JsonProperty("url") - final URI url, - - @JsonProperty("configuration") - final Map configuration, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("channel_sid") final String channelSid, + @JsonProperty("type") final String type, + @JsonProperty("url") final URI url, + @JsonProperty("configuration") final Map configuration, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated ) { this.sid = sid; this.accountSid = accountSid; @@ -191,37 +197,45 @@ private Webhook( this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final String getChannelSid() { - return this.channelSid; - } - public final String getType() { - return this.type; - } - public final URI getUrl() { - return this.url; - } - public final Map getConfiguration() { - return this.configuration; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final String getChannelSid() { + return this.channelSid; + } + + public final String getType() { + return this.type; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getConfiguration() { + return this.configuration; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -231,13 +245,31 @@ public boolean equals(final Object o) { Webhook other = (Webhook) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(channelSid, other.channelSid) && Objects.equals(type, other.type) && Objects.equals(url, other.url) && Objects.equals(configuration, other.configuration) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(channelSid, other.channelSid) && + Objects.equals(type, other.type) && + Objects.equals(url, other.url) && + Objects.equals(configuration, other.configuration) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, serviceSid, channelSid, type, url, configuration, dateCreated, dateUpdated); + return Objects.hash( + sid, + accountSid, + serviceSid, + channelSid, + type, + url, + configuration, + dateCreated, + dateUpdated + ); } - } - diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/WebhookCreator.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/WebhookCreator.java index a8fda7c1b8..921c3d93ae 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/WebhookCreator.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/WebhookCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.ipmessaging.v2.service.channel; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -25,12 +26,10 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.util.List; - import java.util.List; +public class WebhookCreator extends Creator { - -public class WebhookCreator extends Creator{ private String pathServiceSid; private String pathChannelSid; private Webhook.Type type; @@ -41,66 +40,111 @@ public class WebhookCreator extends Creator{ private String configurationFlowSid; private Integer configurationRetryCount; - public WebhookCreator(final String pathServiceSid, final String pathChannelSid, final Webhook.Type type) { + public WebhookCreator( + final String pathServiceSid, + final String pathChannelSid, + final Webhook.Type type + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.type = type; } - public WebhookCreator setType(final Webhook.Type type){ + public WebhookCreator setType(final Webhook.Type type) { this.type = type; return this; } - public WebhookCreator setConfigurationUrl(final String configurationUrl){ + + public WebhookCreator setConfigurationUrl(final String configurationUrl) { this.configurationUrl = configurationUrl; return this; } - public WebhookCreator setConfigurationMethod(final Webhook.Method configurationMethod){ + + public WebhookCreator setConfigurationMethod( + final Webhook.Method configurationMethod + ) { this.configurationMethod = configurationMethod; return this; } - public WebhookCreator setConfigurationFilters(final List configurationFilters){ + + public WebhookCreator setConfigurationFilters( + final List configurationFilters + ) { this.configurationFilters = configurationFilters; return this; } - public WebhookCreator setConfigurationFilters(final String configurationFilters){ - return setConfigurationFilters(Promoter.listOfOne(configurationFilters)); + + public WebhookCreator setConfigurationFilters( + final String configurationFilters + ) { + return setConfigurationFilters( + Promoter.listOfOne(configurationFilters) + ); } - public WebhookCreator setConfigurationTriggers(final List configurationTriggers){ + + public WebhookCreator setConfigurationTriggers( + final List configurationTriggers + ) { this.configurationTriggers = configurationTriggers; return this; } - public WebhookCreator setConfigurationTriggers(final String configurationTriggers){ - return setConfigurationTriggers(Promoter.listOfOne(configurationTriggers)); + + public WebhookCreator setConfigurationTriggers( + final String configurationTriggers + ) { + return setConfigurationTriggers( + Promoter.listOfOne(configurationTriggers) + ); } - public WebhookCreator setConfigurationFlowSid(final String configurationFlowSid){ + + public WebhookCreator setConfigurationFlowSid( + final String configurationFlowSid + ) { this.configurationFlowSid = configurationFlowSid; return this; } - public WebhookCreator setConfigurationRetryCount(final Integer configurationRetryCount){ + + public WebhookCreator setConfigurationRetryCount( + final Integer configurationRetryCount + ) { this.configurationRetryCount = configurationRetryCount; return this; } @Override - public Webhook create(final TwilioRestClient client){ - String path = "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Webhooks"; + public Webhook create(final TwilioRestClient client) { + String path = + "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Webhooks"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); - path = path.replace("{"+"Type"+"}", this.type.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Type" + "}", this.type.toString()); Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Webhook creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Webhook creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -109,38 +153,38 @@ public Webhook create(final TwilioRestClient client){ return Webhook.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (type != null) { request.addPostParam("Type", type.toString()); - } if (configurationUrl != null) { request.addPostParam("Configuration.Url", configurationUrl); - } if (configurationMethod != null) { - request.addPostParam("Configuration.Method", configurationMethod.toString()); - + request.addPostParam( + "Configuration.Method", + configurationMethod.toString() + ); } if (configurationFilters != null) { for (String prop : configurationFilters) { request.addPostParam("Configuration.Filters", prop); } - } if (configurationTriggers != null) { for (String prop : configurationTriggers) { request.addPostParam("Configuration.Triggers", prop); } - } if (configurationFlowSid != null) { request.addPostParam("Configuration.FlowSid", configurationFlowSid); - } if (configurationRetryCount != null) { - request.addPostParam("Configuration.RetryCount", configurationRetryCount.toString()); - + request.addPostParam( + "Configuration.RetryCount", + configurationRetryCount.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/WebhookDeleter.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/WebhookDeleter.java index f7f6d842a7..7876b864d6 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/WebhookDeleter.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/WebhookDeleter.java @@ -24,27 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class WebhookDeleter extends Deleter { + private String pathServiceSid; private String pathChannelSid; private String pathSid; - public WebhookDeleter(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public WebhookDeleter( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Webhooks/{Sid}"; + String path = + "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Webhooks/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -54,9 +65,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Webhook delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Webhook delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/WebhookFetcher.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/WebhookFetcher.java index 4281113aff..8be7898fec 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/WebhookFetcher.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/WebhookFetcher.java @@ -24,28 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class WebhookFetcher extends Fetcher { + private String pathServiceSid; private String pathChannelSid; private String pathSid; - public WebhookFetcher(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public WebhookFetcher( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - @Override public Webhook fetch(final TwilioRestClient client) { - String path = "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Webhooks/{Sid}"; + String path = + "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Webhooks/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -55,9 +65,14 @@ public Webhook fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Webhook fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Webhook fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/WebhookReader.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/WebhookReader.java index 9a8cffd064..6589bda3bc 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/WebhookReader.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/WebhookReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.ipmessaging.v2.service.channel; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,21 +25,22 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class WebhookReader extends Reader { + private String pathServiceSid; private String pathChannelSid; private Integer pageSize; - public WebhookReader(final String pathServiceSid, final String pathChannelSid){ + public WebhookReader( + final String pathServiceSid, + final String pathChannelSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; } - public WebhookReader setPageSize(final Integer pageSize){ + public WebhookReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -49,9 +51,18 @@ public ResourceSet read(final TwilioRestClient client) { } public Page firstPage(final TwilioRestClient client) { - String path = "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Webhooks"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); + String path = + "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Webhooks"; + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -63,13 +74,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Webhook read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Webhook read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -85,7 +104,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reques } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.IPMESSAGING.toString()) @@ -93,9 +115,11 @@ public Page previousPage(final Page page, final TwilioRestClie return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.IPMESSAGING.toString()) @@ -104,21 +128,21 @@ public Page nextPage(final Page page, final TwilioRestClient c } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/WebhookUpdater.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/WebhookUpdater.java index ba6633b515..076ba0c2f4 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/WebhookUpdater.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/WebhookUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.ipmessaging.v2.service.channel; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -24,12 +25,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - import java.util.List; +public class WebhookUpdater extends Updater { -public class WebhookUpdater extends Updater{ private String pathServiceSid; private String pathChannelSid; private String pathSid; @@ -40,62 +39,106 @@ public class WebhookUpdater extends Updater{ private String configurationFlowSid; private Integer configurationRetryCount; - public WebhookUpdater(final String pathServiceSid, final String pathChannelSid, final String pathSid){ + public WebhookUpdater( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - public WebhookUpdater setConfigurationUrl(final String configurationUrl){ + public WebhookUpdater setConfigurationUrl(final String configurationUrl) { this.configurationUrl = configurationUrl; return this; } - public WebhookUpdater setConfigurationMethod(final Webhook.Method configurationMethod){ + + public WebhookUpdater setConfigurationMethod( + final Webhook.Method configurationMethod + ) { this.configurationMethod = configurationMethod; return this; } - public WebhookUpdater setConfigurationFilters(final List configurationFilters){ + + public WebhookUpdater setConfigurationFilters( + final List configurationFilters + ) { this.configurationFilters = configurationFilters; return this; } - public WebhookUpdater setConfigurationFilters(final String configurationFilters){ - return setConfigurationFilters(Promoter.listOfOne(configurationFilters)); + + public WebhookUpdater setConfigurationFilters( + final String configurationFilters + ) { + return setConfigurationFilters( + Promoter.listOfOne(configurationFilters) + ); } - public WebhookUpdater setConfigurationTriggers(final List configurationTriggers){ + + public WebhookUpdater setConfigurationTriggers( + final List configurationTriggers + ) { this.configurationTriggers = configurationTriggers; return this; } - public WebhookUpdater setConfigurationTriggers(final String configurationTriggers){ - return setConfigurationTriggers(Promoter.listOfOne(configurationTriggers)); + + public WebhookUpdater setConfigurationTriggers( + final String configurationTriggers + ) { + return setConfigurationTriggers( + Promoter.listOfOne(configurationTriggers) + ); } - public WebhookUpdater setConfigurationFlowSid(final String configurationFlowSid){ + + public WebhookUpdater setConfigurationFlowSid( + final String configurationFlowSid + ) { this.configurationFlowSid = configurationFlowSid; return this; } - public WebhookUpdater setConfigurationRetryCount(final Integer configurationRetryCount){ + + public WebhookUpdater setConfigurationRetryCount( + final Integer configurationRetryCount + ) { this.configurationRetryCount = configurationRetryCount; return this; } @Override - public Webhook update(final TwilioRestClient client){ - String path = "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Webhooks/{Sid}"; + public Webhook update(final TwilioRestClient client) { + String path = + "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Webhooks/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Webhook update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Webhook update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -104,34 +147,35 @@ public Webhook update(final TwilioRestClient client){ return Webhook.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (configurationUrl != null) { request.addPostParam("Configuration.Url", configurationUrl); - } if (configurationMethod != null) { - request.addPostParam("Configuration.Method", configurationMethod.toString()); - + request.addPostParam( + "Configuration.Method", + configurationMethod.toString() + ); } if (configurationFilters != null) { for (String prop : configurationFilters) { request.addPostParam("Configuration.Filters", prop); } - } if (configurationTriggers != null) { for (String prop : configurationTriggers) { request.addPostParam("Configuration.Triggers", prop); } - } if (configurationFlowSid != null) { request.addPostParam("Configuration.FlowSid", configurationFlowSid); - } if (configurationRetryCount != null) { - request.addPostParam("Configuration.RetryCount", configurationRetryCount.toString()); - + request.addPostParam( + "Configuration.RetryCount", + configurationRetryCount.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserBinding.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserBinding.java index 3161e57a28..4dbce25612 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserBinding.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserBinding.java @@ -24,46 +24,56 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.List; import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class UserBinding extends Resource { + private static final long serialVersionUID = 252068300768529L; - public static UserBindingDeleter deleter(final String pathServiceSid, final String pathUserSid, final String pathSid){ + public static UserBindingDeleter deleter( + final String pathServiceSid, + final String pathUserSid, + final String pathSid + ) { return new UserBindingDeleter(pathServiceSid, pathUserSid, pathSid); } - public static UserBindingFetcher fetcher(final String pathServiceSid, final String pathUserSid, final String pathSid){ + public static UserBindingFetcher fetcher( + final String pathServiceSid, + final String pathUserSid, + final String pathSid + ) { return new UserBindingFetcher(pathServiceSid, pathUserSid, pathSid); } - public static UserBindingReader reader(final String pathServiceSid, final String pathUserSid){ + public static UserBindingReader reader( + final String pathServiceSid, + final String pathUserSid + ) { return new UserBindingReader(pathServiceSid, pathUserSid); } /** - * Converts a JSON String into a UserBinding object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return UserBinding object represented by the provided JSON - */ - public static UserBinding fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a UserBinding object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return UserBinding object represented by the provided JSON + */ + public static UserBinding fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, UserBinding.class); @@ -75,14 +85,17 @@ public static UserBinding fromJson(final String json, final ObjectMapper objectM } /** - * Converts a JSON InputStream into a UserBinding object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return UserBinding object represented by the provided JSON - */ - public static UserBinding fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a UserBinding object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return UserBinding object represented by the provided JSON + */ + public static UserBinding fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, UserBinding.class); @@ -92,6 +105,7 @@ public static UserBinding fromJson(final InputStream json, final ObjectMapper ob throw new ApiConnectionException(e.getMessage(), e); } } + public enum BindingType { GCM("gcm"), APN("apn"), @@ -128,41 +142,18 @@ public static BindingType forValue(final String value) { @JsonCreator private UserBinding( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("endpoint") - final String endpoint, - - @JsonProperty("identity") - final String identity, - - @JsonProperty("user_sid") - final String userSid, - - @JsonProperty("credential_sid") - final String credentialSid, - - @JsonProperty("binding_type") - final UserBinding.BindingType bindingType, - - @JsonProperty("message_types") - final List messageTypes, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("endpoint") final String endpoint, + @JsonProperty("identity") final String identity, + @JsonProperty("user_sid") final String userSid, + @JsonProperty("credential_sid") final String credentialSid, + @JsonProperty("binding_type") final UserBinding.BindingType bindingType, + @JsonProperty("message_types") final List messageTypes, + @JsonProperty("url") final URI url ) { this.sid = sid; this.accountSid = accountSid; @@ -178,46 +169,57 @@ private UserBinding( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getEndpoint() { - return this.endpoint; - } - public final String getIdentity() { - return this.identity; - } - public final String getUserSid() { - return this.userSid; - } - public final String getCredentialSid() { - return this.credentialSid; - } - public final UserBinding.BindingType getBindingType() { - return this.bindingType; - } - public final List getMessageTypes() { - return this.messageTypes; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getEndpoint() { + return this.endpoint; + } + + public final String getIdentity() { + return this.identity; + } + + public final String getUserSid() { + return this.userSid; + } + + public final String getCredentialSid() { + return this.credentialSid; + } + + public final UserBinding.BindingType getBindingType() { + return this.bindingType; + } + + public final List getMessageTypes() { + return this.messageTypes; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -227,13 +229,37 @@ public boolean equals(final Object o) { UserBinding other = (UserBinding) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(endpoint, other.endpoint) && Objects.equals(identity, other.identity) && Objects.equals(userSid, other.userSid) && Objects.equals(credentialSid, other.credentialSid) && Objects.equals(bindingType, other.bindingType) && Objects.equals(messageTypes, other.messageTypes) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(endpoint, other.endpoint) && + Objects.equals(identity, other.identity) && + Objects.equals(userSid, other.userSid) && + Objects.equals(credentialSid, other.credentialSid) && + Objects.equals(bindingType, other.bindingType) && + Objects.equals(messageTypes, other.messageTypes) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, serviceSid, dateCreated, dateUpdated, endpoint, identity, userSid, credentialSid, bindingType, messageTypes, url); + return Objects.hash( + sid, + accountSid, + serviceSid, + dateCreated, + dateUpdated, + endpoint, + identity, + userSid, + credentialSid, + bindingType, + messageTypes, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserBindingDeleter.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserBindingDeleter.java index 053bfac562..45f70392ad 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserBindingDeleter.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserBindingDeleter.java @@ -24,27 +24,34 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class UserBindingDeleter extends Deleter { + private String pathServiceSid; private String pathUserSid; private String pathSid; - public UserBindingDeleter(final String pathServiceSid, final String pathUserSid, final String pathSid){ + public UserBindingDeleter( + final String pathServiceSid, + final String pathUserSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathUserSid = pathUserSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/v2/Services/{ServiceSid}/Users/{UserSid}/Bindings/{Sid}"; + String path = + "/v2/Services/{ServiceSid}/Users/{UserSid}/Bindings/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"UserSid"+"}", this.pathUserSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "UserSid" + "}", this.pathUserSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -54,9 +61,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("UserBinding delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "UserBinding delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserBindingFetcher.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserBindingFetcher.java index b5907df829..228de862fb 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserBindingFetcher.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserBindingFetcher.java @@ -24,28 +24,34 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class UserBindingFetcher extends Fetcher { + private String pathServiceSid; private String pathUserSid; private String pathSid; - public UserBindingFetcher(final String pathServiceSid, final String pathUserSid, final String pathSid){ + public UserBindingFetcher( + final String pathServiceSid, + final String pathUserSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathUserSid = pathUserSid; this.pathSid = pathSid; } - @Override public UserBinding fetch(final TwilioRestClient client) { - String path = "/v2/Services/{ServiceSid}/Users/{UserSid}/Bindings/{Sid}"; + String path = + "/v2/Services/{ServiceSid}/Users/{UserSid}/Bindings/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"UserSid"+"}", this.pathUserSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "UserSid" + "}", this.pathUserSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -55,15 +61,23 @@ public UserBinding fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("UserBinding fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "UserBinding fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return UserBinding.fromJson(response.getStream(), client.getObjectMapper()); + return UserBinding.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserBindingReader.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserBindingReader.java index ecad07911b..d6836556e7 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserBindingReader.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserBindingReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.ipmessaging.v2.service.user; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.converter.Promoter; @@ -25,30 +26,37 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - import java.util.List; - public class UserBindingReader extends Reader { + private String pathServiceSid; private String pathUserSid; private List bindingType; private Integer pageSize; - public UserBindingReader(final String pathServiceSid, final String pathUserSid){ + public UserBindingReader( + final String pathServiceSid, + final String pathUserSid + ) { this.pathServiceSid = pathServiceSid; this.pathUserSid = pathUserSid; } - public UserBindingReader setBindingType(final List bindingType){ + public UserBindingReader setBindingType( + final List bindingType + ) { this.bindingType = bindingType; return this; } - public UserBindingReader setBindingType(final UserBinding.BindingType bindingType){ + + public UserBindingReader setBindingType( + final UserBinding.BindingType bindingType + ) { return setBindingType(Promoter.listOfOne(bindingType)); } - public UserBindingReader setPageSize(final Integer pageSize){ + + public UserBindingReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -60,8 +68,12 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v2/Services/{ServiceSid}/Users/{UserSid}/Bindings"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"UserSid"+"}", this.pathUserSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "UserSid" + "}", this.pathUserSid.toString()); Request request = new Request( HttpMethod.GET, @@ -73,13 +85,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("UserBinding read failed: Unable to connect to server"); + throw new ApiConnectionException( + "UserBinding read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -95,7 +115,10 @@ private Page pageForRequest(final TwilioRestClient client, final Re } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.IPMESSAGING.toString()) @@ -103,9 +126,11 @@ public Page previousPage(final Page page, final Twilio return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.IPMESSAGING.toString()) @@ -114,14 +139,15 @@ public Page nextPage(final Page page, final TwilioRest } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (bindingType != null) { for (UserBinding.BindingType prop : bindingType) { @@ -129,11 +155,10 @@ private void addQueryParams(final Request request) { } } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserChannel.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserChannel.java index 47d4cc30ae..21c9c050fb 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserChannel.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserChannel.java @@ -23,50 +23,76 @@ import com.twilio.base.Resource; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class UserChannel extends Resource { + private static final long serialVersionUID = 104594062960806L; - public static UserChannelDeleter deleter(final String pathServiceSid, final String pathUserSid, final String pathChannelSid){ - return new UserChannelDeleter(pathServiceSid, pathUserSid, pathChannelSid); + public static UserChannelDeleter deleter( + final String pathServiceSid, + final String pathUserSid, + final String pathChannelSid + ) { + return new UserChannelDeleter( + pathServiceSid, + pathUserSid, + pathChannelSid + ); } - public static UserChannelFetcher fetcher(final String pathServiceSid, final String pathUserSid, final String pathChannelSid){ - return new UserChannelFetcher(pathServiceSid, pathUserSid, pathChannelSid); + public static UserChannelFetcher fetcher( + final String pathServiceSid, + final String pathUserSid, + final String pathChannelSid + ) { + return new UserChannelFetcher( + pathServiceSid, + pathUserSid, + pathChannelSid + ); } - public static UserChannelReader reader(final String pathServiceSid, final String pathUserSid){ + public static UserChannelReader reader( + final String pathServiceSid, + final String pathUserSid + ) { return new UserChannelReader(pathServiceSid, pathUserSid); } - public static UserChannelUpdater updater(final String pathServiceSid, final String pathUserSid, final String pathChannelSid){ - return new UserChannelUpdater(pathServiceSid, pathUserSid, pathChannelSid); + public static UserChannelUpdater updater( + final String pathServiceSid, + final String pathUserSid, + final String pathChannelSid + ) { + return new UserChannelUpdater( + pathServiceSid, + pathUserSid, + pathChannelSid + ); } /** - * Converts a JSON String into a UserChannel object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return UserChannel object represented by the provided JSON - */ - public static UserChannel fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a UserChannel object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return UserChannel object represented by the provided JSON + */ + public static UserChannel fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, UserChannel.class); @@ -78,14 +104,17 @@ public static UserChannel fromJson(final String json, final ObjectMapper objectM } /** - * Converts a JSON InputStream into a UserChannel object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return UserChannel object represented by the provided JSON - */ - public static UserChannel fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a UserChannel object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return UserChannel object represented by the provided JSON + */ + public static UserChannel fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, UserChannel.class); @@ -95,6 +124,7 @@ public static UserChannel fromJson(final InputStream json, final ObjectMapper ob throw new ApiConnectionException(e.getMessage(), e); } } + public enum ChannelStatus { JOINED("joined"), INVITED("invited"), @@ -115,6 +145,7 @@ public static ChannelStatus forValue(final String value) { return Promoter.enumFromString(value, ChannelStatus.values()); } } + public enum NotificationLevel { DEFAULT("default"), MUTED("muted"); @@ -149,38 +180,23 @@ public static NotificationLevel forValue(final String value) { @JsonCreator private UserChannel( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("channel_sid") - final String channelSid, - - @JsonProperty("user_sid") - final String userSid, - - @JsonProperty("member_sid") - final String memberSid, - - @JsonProperty("status") - final UserChannel.ChannelStatus status, - - @JsonProperty("last_consumed_message_index") - final Integer lastConsumedMessageIndex, - - @JsonProperty("unread_messages_count") - final Integer unreadMessagesCount, - - @JsonProperty("links") - final Map links, - - @JsonProperty("url") - final URI url, - - @JsonProperty("notification_level") - final UserChannel.NotificationLevel notificationLevel + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("channel_sid") final String channelSid, + @JsonProperty("user_sid") final String userSid, + @JsonProperty("member_sid") final String memberSid, + @JsonProperty("status") final UserChannel.ChannelStatus status, + @JsonProperty( + "last_consumed_message_index" + ) final Integer lastConsumedMessageIndex, + @JsonProperty( + "unread_messages_count" + ) final Integer unreadMessagesCount, + @JsonProperty("links") final Map links, + @JsonProperty("url") final URI url, + @JsonProperty( + "notification_level" + ) final UserChannel.NotificationLevel notificationLevel ) { this.accountSid = accountSid; this.serviceSid = serviceSid; @@ -195,43 +211,53 @@ private UserChannel( this.notificationLevel = notificationLevel; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final String getChannelSid() { - return this.channelSid; - } - public final String getUserSid() { - return this.userSid; - } - public final String getMemberSid() { - return this.memberSid; - } - public final UserChannel.ChannelStatus getStatus() { - return this.status; - } - public final Integer getLastConsumedMessageIndex() { - return this.lastConsumedMessageIndex; - } - public final Integer getUnreadMessagesCount() { - return this.unreadMessagesCount; - } - public final Map getLinks() { - return this.links; - } - public final URI getUrl() { - return this.url; - } - public final UserChannel.NotificationLevel getNotificationLevel() { - return this.notificationLevel; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final String getChannelSid() { + return this.channelSid; + } + + public final String getUserSid() { + return this.userSid; + } + + public final String getMemberSid() { + return this.memberSid; + } + + public final UserChannel.ChannelStatus getStatus() { + return this.status; + } + + public final Integer getLastConsumedMessageIndex() { + return this.lastConsumedMessageIndex; + } + + public final Integer getUnreadMessagesCount() { + return this.unreadMessagesCount; + } + + public final Map getLinks() { + return this.links; + } + + public final URI getUrl() { + return this.url; + } + + public final UserChannel.NotificationLevel getNotificationLevel() { + return this.notificationLevel; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -241,13 +267,38 @@ public boolean equals(final Object o) { UserChannel other = (UserChannel) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(channelSid, other.channelSid) && Objects.equals(userSid, other.userSid) && Objects.equals(memberSid, other.memberSid) && Objects.equals(status, other.status) && Objects.equals(lastConsumedMessageIndex, other.lastConsumedMessageIndex) && Objects.equals(unreadMessagesCount, other.unreadMessagesCount) && Objects.equals(links, other.links) && Objects.equals(url, other.url) && Objects.equals(notificationLevel, other.notificationLevel) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(channelSid, other.channelSid) && + Objects.equals(userSid, other.userSid) && + Objects.equals(memberSid, other.memberSid) && + Objects.equals(status, other.status) && + Objects.equals( + lastConsumedMessageIndex, + other.lastConsumedMessageIndex + ) && + Objects.equals(unreadMessagesCount, other.unreadMessagesCount) && + Objects.equals(links, other.links) && + Objects.equals(url, other.url) && + Objects.equals(notificationLevel, other.notificationLevel) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, serviceSid, channelSid, userSid, memberSid, status, lastConsumedMessageIndex, unreadMessagesCount, links, url, notificationLevel); + return Objects.hash( + accountSid, + serviceSid, + channelSid, + userSid, + memberSid, + status, + lastConsumedMessageIndex, + unreadMessagesCount, + links, + url, + notificationLevel + ); } - } - diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserChannelDeleter.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserChannelDeleter.java index 57cb47799c..0832546845 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserChannelDeleter.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserChannelDeleter.java @@ -24,27 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class UserChannelDeleter extends Deleter { + private String pathServiceSid; private String pathUserSid; private String pathChannelSid; - public UserChannelDeleter(final String pathServiceSid, final String pathUserSid, final String pathChannelSid){ + public UserChannelDeleter( + final String pathServiceSid, + final String pathUserSid, + final String pathChannelSid + ) { this.pathServiceSid = pathServiceSid; this.pathUserSid = pathUserSid; this.pathChannelSid = pathChannelSid; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/v2/Services/{ServiceSid}/Users/{UserSid}/Channels/{ChannelSid}"; + String path = + "/v2/Services/{ServiceSid}/Users/{UserSid}/Channels/{ChannelSid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"UserSid"+"}", this.pathUserSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "UserSid" + "}", this.pathUserSid.toString()); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); Request request = new Request( HttpMethod.DELETE, @@ -54,9 +65,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("UserChannel delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "UserChannel delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserChannelFetcher.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserChannelFetcher.java index eee9db0f4f..75c41d3b3d 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserChannelFetcher.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserChannelFetcher.java @@ -24,28 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class UserChannelFetcher extends Fetcher { + private String pathServiceSid; private String pathUserSid; private String pathChannelSid; - public UserChannelFetcher(final String pathServiceSid, final String pathUserSid, final String pathChannelSid){ + public UserChannelFetcher( + final String pathServiceSid, + final String pathUserSid, + final String pathChannelSid + ) { this.pathServiceSid = pathServiceSid; this.pathUserSid = pathUserSid; this.pathChannelSid = pathChannelSid; } - @Override public UserChannel fetch(final TwilioRestClient client) { - String path = "/v2/Services/{ServiceSid}/Users/{UserSid}/Channels/{ChannelSid}"; + String path = + "/v2/Services/{ServiceSid}/Users/{UserSid}/Channels/{ChannelSid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"UserSid"+"}", this.pathUserSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "UserSid" + "}", this.pathUserSid.toString()); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -55,15 +65,23 @@ public UserChannel fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("UserChannel fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "UserChannel fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return UserChannel.fromJson(response.getStream(), client.getObjectMapper()); + return UserChannel.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserChannelReader.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserChannelReader.java index 5addada610..b58fe52a08 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserChannelReader.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserChannelReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.ipmessaging.v2.service.user; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,21 +25,22 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class UserChannelReader extends Reader { + private String pathServiceSid; private String pathUserSid; private Integer pageSize; - public UserChannelReader(final String pathServiceSid, final String pathUserSid){ + public UserChannelReader( + final String pathServiceSid, + final String pathUserSid + ) { this.pathServiceSid = pathServiceSid; this.pathUserSid = pathUserSid; } - public UserChannelReader setPageSize(final Integer pageSize){ + public UserChannelReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -50,8 +52,12 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v2/Services/{ServiceSid}/Users/{UserSid}/Channels"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"UserSid"+"}", this.pathUserSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "UserSid" + "}", this.pathUserSid.toString()); Request request = new Request( HttpMethod.GET, @@ -63,13 +69,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("UserChannel read failed: Unable to connect to server"); + throw new ApiConnectionException( + "UserChannel read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -85,7 +99,10 @@ private Page pageForRequest(final TwilioRestClient client, final Re } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.IPMESSAGING.toString()) @@ -93,9 +110,11 @@ public Page previousPage(final Page page, final Twilio return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.IPMESSAGING.toString()) @@ -104,21 +123,21 @@ public Page nextPage(final Page page, final TwilioRest } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserChannelUpdater.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserChannelUpdater.java index 6b5a1f3301..55b483d89e 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserChannelUpdater.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserChannelUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.ipmessaging.v2.service.user; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -23,12 +24,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.time.ZonedDateTime; +public class UserChannelUpdater extends Updater { - -public class UserChannelUpdater extends Updater{ private String pathServiceSid; private String pathUserSid; private String pathChannelSid; @@ -36,64 +35,101 @@ public class UserChannelUpdater extends Updater{ private Integer lastConsumedMessageIndex; private ZonedDateTime lastConsumptionTimestamp; - public UserChannelUpdater(final String pathServiceSid, final String pathUserSid, final String pathChannelSid){ + public UserChannelUpdater( + final String pathServiceSid, + final String pathUserSid, + final String pathChannelSid + ) { this.pathServiceSid = pathServiceSid; this.pathUserSid = pathUserSid; this.pathChannelSid = pathChannelSid; } - public UserChannelUpdater setNotificationLevel(final UserChannel.NotificationLevel notificationLevel){ + public UserChannelUpdater setNotificationLevel( + final UserChannel.NotificationLevel notificationLevel + ) { this.notificationLevel = notificationLevel; return this; } - public UserChannelUpdater setLastConsumedMessageIndex(final Integer lastConsumedMessageIndex){ + + public UserChannelUpdater setLastConsumedMessageIndex( + final Integer lastConsumedMessageIndex + ) { this.lastConsumedMessageIndex = lastConsumedMessageIndex; return this; } - public UserChannelUpdater setLastConsumptionTimestamp(final ZonedDateTime lastConsumptionTimestamp){ + + public UserChannelUpdater setLastConsumptionTimestamp( + final ZonedDateTime lastConsumptionTimestamp + ) { this.lastConsumptionTimestamp = lastConsumptionTimestamp; return this; } @Override - public UserChannel update(final TwilioRestClient client){ - String path = "/v2/Services/{ServiceSid}/Users/{UserSid}/Channels/{ChannelSid}"; + public UserChannel update(final TwilioRestClient client) { + String path = + "/v2/Services/{ServiceSid}/Users/{UserSid}/Channels/{ChannelSid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"UserSid"+"}", this.pathUserSid.toString()); - path = path.replace("{"+"ChannelSid"+"}", this.pathChannelSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "UserSid" + "}", this.pathUserSid.toString()); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("UserChannel update failed: Unable to connect to server"); + throw new ApiConnectionException( + "UserChannel update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return UserChannel.fromJson(response.getStream(), client.getObjectMapper()); + return UserChannel.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (notificationLevel != null) { - request.addPostParam("NotificationLevel", notificationLevel.toString()); - + request.addPostParam( + "NotificationLevel", + notificationLevel.toString() + ); } if (lastConsumedMessageIndex != null) { - request.addPostParam("LastConsumedMessageIndex", lastConsumedMessageIndex.toString()); - + request.addPostParam( + "LastConsumedMessageIndex", + lastConsumedMessageIndex.toString() + ); } if (lastConsumptionTimestamp != null) { - request.addPostParam("LastConsumptionTimestamp", lastConsumptionTimestamp.toInstant().toString()); - + request.addPostParam( + "LastConsumptionTimestamp", + lastConsumptionTimestamp.toInstant().toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/lookups/v1/PhoneNumber.java b/src/main/java/com/twilio/rest/lookups/v1/PhoneNumber.java index 9dc68d756d..f5e6df5b59 100644 --- a/src/main/java/com/twilio/rest/lookups/v1/PhoneNumber.java +++ b/src/main/java/com/twilio/rest/lookups/v1/PhoneNumber.java @@ -22,38 +22,39 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class PhoneNumber extends Resource { + private static final long serialVersionUID = 141589309941045L; - public static PhoneNumberFetcher fetcher(final com.twilio.type.PhoneNumber pathPhoneNumber){ + public static PhoneNumberFetcher fetcher( + final com.twilio.type.PhoneNumber pathPhoneNumber + ) { return new PhoneNumberFetcher(pathPhoneNumber); } /** - * Converts a JSON String into a PhoneNumber object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return PhoneNumber object represented by the provided JSON - */ - public static PhoneNumber fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a PhoneNumber object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return PhoneNumber object represented by the provided JSON + */ + public static PhoneNumber fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, PhoneNumber.class); @@ -65,14 +66,17 @@ public static PhoneNumber fromJson(final String json, final ObjectMapper objectM } /** - * Converts a JSON InputStream into a PhoneNumber object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return PhoneNumber object represented by the provided JSON - */ - public static PhoneNumber fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a PhoneNumber object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return PhoneNumber object represented by the provided JSON + */ + public static PhoneNumber fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, PhoneNumber.class); @@ -93,26 +97,15 @@ public static PhoneNumber fromJson(final InputStream json, final ObjectMapper ob @JsonCreator private PhoneNumber( - @JsonProperty("caller_name") - final Map callerName, - - @JsonProperty("country_code") - final String countryCode, - - @JsonProperty("phone_number") - final com.twilio.type.PhoneNumber phoneNumber, - - @JsonProperty("national_format") - final String nationalFormat, - - @JsonProperty("carrier") - final Map carrier, - - @JsonProperty("add_ons") - final Map addOns, - - @JsonProperty("url") - final URI url + @JsonProperty("caller_name") final Map callerName, + @JsonProperty("country_code") final String countryCode, + @JsonProperty( + "phone_number" + ) final com.twilio.type.PhoneNumber phoneNumber, + @JsonProperty("national_format") final String nationalFormat, + @JsonProperty("carrier") final Map carrier, + @JsonProperty("add_ons") final Map addOns, + @JsonProperty("url") final URI url ) { this.callerName = callerName; this.countryCode = countryCode; @@ -123,31 +116,37 @@ private PhoneNumber( this.url = url; } - public final Map getCallerName() { - return this.callerName; - } - public final String getCountryCode() { - return this.countryCode; - } - public final com.twilio.type.PhoneNumber getPhoneNumber() { - return this.phoneNumber; - } - public final String getNationalFormat() { - return this.nationalFormat; - } - public final Map getCarrier() { - return this.carrier; - } - public final Map getAddOns() { - return this.addOns; - } - public final URI getUrl() { - return this.url; - } + public final Map getCallerName() { + return this.callerName; + } + + public final String getCountryCode() { + return this.countryCode; + } + + public final com.twilio.type.PhoneNumber getPhoneNumber() { + return this.phoneNumber; + } + + public final String getNationalFormat() { + return this.nationalFormat; + } + + public final Map getCarrier() { + return this.carrier; + } + + public final Map getAddOns() { + return this.addOns; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -157,13 +156,27 @@ public boolean equals(final Object o) { PhoneNumber other = (PhoneNumber) o; - return Objects.equals(callerName, other.callerName) && Objects.equals(countryCode, other.countryCode) && Objects.equals(phoneNumber, other.phoneNumber) && Objects.equals(nationalFormat, other.nationalFormat) && Objects.equals(carrier, other.carrier) && Objects.equals(addOns, other.addOns) && Objects.equals(url, other.url) ; + return ( + Objects.equals(callerName, other.callerName) && + Objects.equals(countryCode, other.countryCode) && + Objects.equals(phoneNumber, other.phoneNumber) && + Objects.equals(nationalFormat, other.nationalFormat) && + Objects.equals(carrier, other.carrier) && + Objects.equals(addOns, other.addOns) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(callerName, countryCode, phoneNumber, nationalFormat, carrier, addOns, url); + return Objects.hash( + callerName, + countryCode, + phoneNumber, + nationalFormat, + carrier, + addOns, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/lookups/v1/PhoneNumberFetcher.java b/src/main/java/com/twilio/rest/lookups/v1/PhoneNumberFetcher.java index 178438c420..493dc9d172 100644 --- a/src/main/java/com/twilio/rest/lookups/v1/PhoneNumberFetcher.java +++ b/src/main/java/com/twilio/rest/lookups/v1/PhoneNumberFetcher.java @@ -15,9 +15,9 @@ package com.twilio.rest.lookups.v1; import com.twilio.base.Fetcher; +import com.twilio.converter.PrefixedCollapsibleMap; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; -import com.twilio.converter.PrefixedCollapsibleMap; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; @@ -25,42 +25,49 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - import java.util.List; import java.util.Map; - public class PhoneNumberFetcher extends Fetcher { + private com.twilio.type.PhoneNumber pathPhoneNumber; private String countryCode; private List type; private List addOns; private Map addOnsData; - public PhoneNumberFetcher(final com.twilio.type.PhoneNumber pathPhoneNumber){ + public PhoneNumberFetcher( + final com.twilio.type.PhoneNumber pathPhoneNumber + ) { this.pathPhoneNumber = pathPhoneNumber; } - public PhoneNumberFetcher setCountryCode(final String countryCode){ + public PhoneNumberFetcher setCountryCode(final String countryCode) { this.countryCode = countryCode; return this; } - public PhoneNumberFetcher setType(final List type){ + + public PhoneNumberFetcher setType(final List type) { this.type = type; return this; } - public PhoneNumberFetcher setType(final String type){ + + public PhoneNumberFetcher setType(final String type) { return setType(Promoter.listOfOne(type)); } - public PhoneNumberFetcher setAddOns(final List addOns){ + + public PhoneNumberFetcher setAddOns(final List addOns) { this.addOns = addOns; return this; } - public PhoneNumberFetcher setAddOns(final String addOns){ + + public PhoneNumberFetcher setAddOns(final String addOns) { return setAddOns(Promoter.listOfOne(addOns)); } - public PhoneNumberFetcher setAddOnsData(final Map addOnsData){ + + public PhoneNumberFetcher setAddOnsData( + final Map addOnsData + ) { this.addOnsData = addOnsData; return this; } @@ -69,7 +76,11 @@ public PhoneNumberFetcher setAddOnsData(final Map addOnsData){ public PhoneNumber fetch(final TwilioRestClient client) { String path = "/v1/PhoneNumbers/{PhoneNumber}"; - path = path.replace("{"+"PhoneNumber"+"}", this.pathPhoneNumber.encode("utf-8")); + path = + path.replace( + "{" + "PhoneNumber" + "}", + this.pathPhoneNumber.encode("utf-8") + ); Request request = new Request( HttpMethod.GET, @@ -80,20 +91,28 @@ public PhoneNumber fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("PhoneNumber fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "PhoneNumber fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return PhoneNumber.fromJson(response.getStream(), client.getObjectMapper()); + return PhoneNumber.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addQueryParams(final Request request) { if (countryCode != null) { - request.addQueryParam("CountryCode", countryCode); } if (type != null) { @@ -107,7 +126,10 @@ private void addQueryParams(final Request request) { } } if (addOnsData != null) { - Map params = PrefixedCollapsibleMap.serialize(addOnsData, "AddOns"); + Map params = PrefixedCollapsibleMap.serialize( + addOnsData, + "AddOns" + ); for (Map.Entry entry : params.entrySet()) { request.addQueryParam(entry.getKey(), entry.getValue()); } diff --git a/src/main/java/com/twilio/rest/lookups/v2/PhoneNumber.java b/src/main/java/com/twilio/rest/lookups/v2/PhoneNumber.java index ecdc3874c1..1970ca430c 100644 --- a/src/main/java/com/twilio/rest/lookups/v2/PhoneNumber.java +++ b/src/main/java/com/twilio/rest/lookups/v2/PhoneNumber.java @@ -23,39 +23,38 @@ import com.twilio.base.Resource; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.List; import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class PhoneNumber extends Resource { - private static final long serialVersionUID = 170815477017777L; - public static PhoneNumberFetcher fetcher(final String pathPhoneNumber){ + private static final long serialVersionUID = 36409394799926L; + + public static PhoneNumberFetcher fetcher(final String pathPhoneNumber) { return new PhoneNumberFetcher(pathPhoneNumber); } /** - * Converts a JSON String into a PhoneNumber object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return PhoneNumber object represented by the provided JSON - */ - public static PhoneNumber fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a PhoneNumber object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return PhoneNumber object represented by the provided JSON + */ + public static PhoneNumber fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, PhoneNumber.class); @@ -67,14 +66,17 @@ public static PhoneNumber fromJson(final String json, final ObjectMapper objectM } /** - * Converts a JSON InputStream into a PhoneNumber object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return PhoneNumber object represented by the provided JSON - */ - public static PhoneNumber fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a PhoneNumber object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return PhoneNumber object represented by the provided JSON + */ + public static PhoneNumber fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, PhoneNumber.class); @@ -84,6 +86,7 @@ public static PhoneNumber fromJson(final InputStream json, final ObjectMapper ob throw new ApiConnectionException(e.getMessage(), e); } } + public enum ValidationError { TOO_SHORT("TOO_SHORT"), TOO_LONG("TOO_LONG"), @@ -122,54 +125,41 @@ public static ValidationError forValue(final String value) { private final Map identityMatch; private final Map reassignedNumber; private final Map smsPumpingRisk; + private final Map disposablePhoneNumberRisk; private final URI url; @JsonCreator private PhoneNumber( - @JsonProperty("calling_country_code") - final String callingCountryCode, - - @JsonProperty("country_code") - final String countryCode, - - @JsonProperty("phone_number") - final com.twilio.type.PhoneNumber phoneNumber, - - @JsonProperty("national_format") - final String nationalFormat, - - @JsonProperty("valid") - final Boolean valid, - - @JsonProperty("validation_errors") - final List validationErrors, - - @JsonProperty("caller_name") - final Map callerName, - - @JsonProperty("sim_swap") - final Map simSwap, - - @JsonProperty("call_forwarding") - final Map callForwarding, - - @JsonProperty("live_activity") - final Map liveActivity, - - @JsonProperty("line_type_intelligence") - final Map lineTypeIntelligence, - - @JsonProperty("identity_match") - final Map identityMatch, - - @JsonProperty("reassigned_number") - final Map reassignedNumber, - - @JsonProperty("sms_pumping_risk") - final Map smsPumpingRisk, - - @JsonProperty("url") - final URI url + @JsonProperty("calling_country_code") final String callingCountryCode, + @JsonProperty("country_code") final String countryCode, + @JsonProperty( + "phone_number" + ) final com.twilio.type.PhoneNumber phoneNumber, + @JsonProperty("national_format") final String nationalFormat, + @JsonProperty("valid") final Boolean valid, + @JsonProperty( + "validation_errors" + ) final List validationErrors, + @JsonProperty("caller_name") final Map callerName, + @JsonProperty("sim_swap") final Map simSwap, + @JsonProperty( + "call_forwarding" + ) final Map callForwarding, + @JsonProperty("live_activity") final Map liveActivity, + @JsonProperty( + "line_type_intelligence" + ) final Map lineTypeIntelligence, + @JsonProperty("identity_match") final Map identityMatch, + @JsonProperty( + "reassigned_number" + ) final Map reassignedNumber, + @JsonProperty( + "sms_pumping_risk" + ) final Map smsPumpingRisk, + @JsonProperty( + "disposable_phone_number_risk" + ) final Map disposablePhoneNumberRisk, + @JsonProperty("url") final URI url ) { this.callingCountryCode = callingCountryCode; this.countryCode = countryCode; @@ -185,58 +175,77 @@ private PhoneNumber( this.identityMatch = identityMatch; this.reassignedNumber = reassignedNumber; this.smsPumpingRisk = smsPumpingRisk; + this.disposablePhoneNumberRisk = disposablePhoneNumberRisk; this.url = url; } - public final String getCallingCountryCode() { - return this.callingCountryCode; - } - public final String getCountryCode() { - return this.countryCode; - } - public final com.twilio.type.PhoneNumber getPhoneNumber() { - return this.phoneNumber; - } - public final String getNationalFormat() { - return this.nationalFormat; - } - public final Boolean getValid() { - return this.valid; - } - public final List getValidationErrors() { - return this.validationErrors; - } - public final Map getCallerName() { - return this.callerName; - } - public final Map getSimSwap() { - return this.simSwap; - } - public final Map getCallForwarding() { - return this.callForwarding; - } - public final Map getLiveActivity() { - return this.liveActivity; - } - public final Map getLineTypeIntelligence() { - return this.lineTypeIntelligence; - } - public final Map getIdentityMatch() { - return this.identityMatch; - } - public final Map getReassignedNumber() { - return this.reassignedNumber; - } - public final Map getSmsPumpingRisk() { - return this.smsPumpingRisk; - } - public final URI getUrl() { - return this.url; - } + public final String getCallingCountryCode() { + return this.callingCountryCode; + } + + public final String getCountryCode() { + return this.countryCode; + } + + public final com.twilio.type.PhoneNumber getPhoneNumber() { + return this.phoneNumber; + } + + public final String getNationalFormat() { + return this.nationalFormat; + } + + public final Boolean getValid() { + return this.valid; + } + + public final List getValidationErrors() { + return this.validationErrors; + } + + public final Map getCallerName() { + return this.callerName; + } + + public final Map getSimSwap() { + return this.simSwap; + } + + public final Map getCallForwarding() { + return this.callForwarding; + } + + public final Map getLiveActivity() { + return this.liveActivity; + } + + public final Map getLineTypeIntelligence() { + return this.lineTypeIntelligence; + } + + public final Map getIdentityMatch() { + return this.identityMatch; + } + + public final Map getReassignedNumber() { + return this.reassignedNumber; + } + + public final Map getSmsPumpingRisk() { + return this.smsPumpingRisk; + } + + public final Map getDisposablePhoneNumberRisk() { + return this.disposablePhoneNumberRisk; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -246,13 +255,48 @@ public boolean equals(final Object o) { PhoneNumber other = (PhoneNumber) o; - return Objects.equals(callingCountryCode, other.callingCountryCode) && Objects.equals(countryCode, other.countryCode) && Objects.equals(phoneNumber, other.phoneNumber) && Objects.equals(nationalFormat, other.nationalFormat) && Objects.equals(valid, other.valid) && Objects.equals(validationErrors, other.validationErrors) && Objects.equals(callerName, other.callerName) && Objects.equals(simSwap, other.simSwap) && Objects.equals(callForwarding, other.callForwarding) && Objects.equals(liveActivity, other.liveActivity) && Objects.equals(lineTypeIntelligence, other.lineTypeIntelligence) && Objects.equals(identityMatch, other.identityMatch) && Objects.equals(reassignedNumber, other.reassignedNumber) && Objects.equals(smsPumpingRisk, other.smsPumpingRisk) && Objects.equals(url, other.url) ; + return ( + Objects.equals(callingCountryCode, other.callingCountryCode) && + Objects.equals(countryCode, other.countryCode) && + Objects.equals(phoneNumber, other.phoneNumber) && + Objects.equals(nationalFormat, other.nationalFormat) && + Objects.equals(valid, other.valid) && + Objects.equals(validationErrors, other.validationErrors) && + Objects.equals(callerName, other.callerName) && + Objects.equals(simSwap, other.simSwap) && + Objects.equals(callForwarding, other.callForwarding) && + Objects.equals(liveActivity, other.liveActivity) && + Objects.equals(lineTypeIntelligence, other.lineTypeIntelligence) && + Objects.equals(identityMatch, other.identityMatch) && + Objects.equals(reassignedNumber, other.reassignedNumber) && + Objects.equals(smsPumpingRisk, other.smsPumpingRisk) && + Objects.equals( + disposablePhoneNumberRisk, + other.disposablePhoneNumberRisk + ) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(callingCountryCode, countryCode, phoneNumber, nationalFormat, valid, validationErrors, callerName, simSwap, callForwarding, liveActivity, lineTypeIntelligence, identityMatch, reassignedNumber, smsPumpingRisk, url); + return Objects.hash( + callingCountryCode, + countryCode, + phoneNumber, + nationalFormat, + valid, + validationErrors, + callerName, + simSwap, + callForwarding, + liveActivity, + lineTypeIntelligence, + identityMatch, + reassignedNumber, + smsPumpingRisk, + disposablePhoneNumberRisk, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/lookups/v2/PhoneNumberFetcher.java b/src/main/java/com/twilio/rest/lookups/v2/PhoneNumberFetcher.java index 34afa09aca..34b87c7cd3 100644 --- a/src/main/java/com/twilio/rest/lookups/v2/PhoneNumberFetcher.java +++ b/src/main/java/com/twilio/rest/lookups/v2/PhoneNumberFetcher.java @@ -24,10 +24,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class PhoneNumberFetcher extends Fetcher { + private String pathPhoneNumber; private String fields; private String countryCode; @@ -43,59 +41,75 @@ public class PhoneNumberFetcher extends Fetcher { private String dateOfBirth; private String lastVerifiedDate; - public PhoneNumberFetcher(final String pathPhoneNumber){ + public PhoneNumberFetcher(final String pathPhoneNumber) { this.pathPhoneNumber = pathPhoneNumber; } - public PhoneNumberFetcher setFields(final String fields){ + public PhoneNumberFetcher setFields(final String fields) { this.fields = fields; return this; } - public PhoneNumberFetcher setCountryCode(final String countryCode){ + + public PhoneNumberFetcher setCountryCode(final String countryCode) { this.countryCode = countryCode; return this; } - public PhoneNumberFetcher setFirstName(final String firstName){ + + public PhoneNumberFetcher setFirstName(final String firstName) { this.firstName = firstName; return this; } - public PhoneNumberFetcher setLastName(final String lastName){ + + public PhoneNumberFetcher setLastName(final String lastName) { this.lastName = lastName; return this; } - public PhoneNumberFetcher setAddressLine1(final String addressLine1){ + + public PhoneNumberFetcher setAddressLine1(final String addressLine1) { this.addressLine1 = addressLine1; return this; } - public PhoneNumberFetcher setAddressLine2(final String addressLine2){ + + public PhoneNumberFetcher setAddressLine2(final String addressLine2) { this.addressLine2 = addressLine2; return this; } - public PhoneNumberFetcher setCity(final String city){ + + public PhoneNumberFetcher setCity(final String city) { this.city = city; return this; } - public PhoneNumberFetcher setState(final String state){ + + public PhoneNumberFetcher setState(final String state) { this.state = state; return this; } - public PhoneNumberFetcher setPostalCode(final String postalCode){ + + public PhoneNumberFetcher setPostalCode(final String postalCode) { this.postalCode = postalCode; return this; } - public PhoneNumberFetcher setAddressCountryCode(final String addressCountryCode){ + + public PhoneNumberFetcher setAddressCountryCode( + final String addressCountryCode + ) { this.addressCountryCode = addressCountryCode; return this; } - public PhoneNumberFetcher setNationalId(final String nationalId){ + + public PhoneNumberFetcher setNationalId(final String nationalId) { this.nationalId = nationalId; return this; } - public PhoneNumberFetcher setDateOfBirth(final String dateOfBirth){ + + public PhoneNumberFetcher setDateOfBirth(final String dateOfBirth) { this.dateOfBirth = dateOfBirth; return this; } - public PhoneNumberFetcher setLastVerifiedDate(final String lastVerifiedDate){ + + public PhoneNumberFetcher setLastVerifiedDate( + final String lastVerifiedDate + ) { this.lastVerifiedDate = lastVerifiedDate; return this; } @@ -104,7 +118,11 @@ public PhoneNumberFetcher setLastVerifiedDate(final String lastVerifiedDate){ public PhoneNumber fetch(final TwilioRestClient client) { String path = "/v2/PhoneNumbers/{PhoneNumber}"; - path = path.replace("{"+"PhoneNumber"+"}", this.pathPhoneNumber.toString()); + path = + path.replace( + "{" + "PhoneNumber" + "}", + this.pathPhoneNumber.toString() + ); Request request = new Request( HttpMethod.GET, @@ -115,68 +133,64 @@ public PhoneNumber fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("PhoneNumber fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "PhoneNumber fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return PhoneNumber.fromJson(response.getStream(), client.getObjectMapper()); + return PhoneNumber.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addQueryParams(final Request request) { if (fields != null) { - request.addQueryParam("Fields", fields); } if (countryCode != null) { - request.addQueryParam("CountryCode", countryCode); } if (firstName != null) { - request.addQueryParam("FirstName", firstName); } if (lastName != null) { - request.addQueryParam("LastName", lastName); } if (addressLine1 != null) { - request.addQueryParam("AddressLine1", addressLine1); } if (addressLine2 != null) { - request.addQueryParam("AddressLine2", addressLine2); } if (city != null) { - request.addQueryParam("City", city); } if (state != null) { - request.addQueryParam("State", state); } if (postalCode != null) { - request.addQueryParam("PostalCode", postalCode); } if (addressCountryCode != null) { - request.addQueryParam("AddressCountryCode", addressCountryCode); } if (nationalId != null) { - request.addQueryParam("NationalId", nationalId); } if (dateOfBirth != null) { - request.addQueryParam("DateOfBirth", dateOfBirth); } if (lastVerifiedDate != null) { - request.addQueryParam("LastVerifiedDate", lastVerifiedDate); } } diff --git a/src/main/java/com/twilio/rest/media/v1/MediaProcessor.java b/src/main/java/com/twilio/rest/media/v1/MediaProcessor.java index d5648ff489..571dc5038d 100644 --- a/src/main/java/com/twilio/rest/media/v1/MediaProcessor.java +++ b/src/main/java/com/twilio/rest/media/v1/MediaProcessor.java @@ -24,50 +24,55 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; import com.twilio.http.HttpMethod; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class MediaProcessor extends Resource { + private static final long serialVersionUID = 112801700822600L; - public static MediaProcessorCreator creator(final String extension, final String extensionContext){ + public static MediaProcessorCreator creator( + final String extension, + final String extensionContext + ) { return new MediaProcessorCreator(extension, extensionContext); } - public static MediaProcessorFetcher fetcher(final String pathSid){ + public static MediaProcessorFetcher fetcher(final String pathSid) { return new MediaProcessorFetcher(pathSid); } - public static MediaProcessorReader reader(){ + public static MediaProcessorReader reader() { return new MediaProcessorReader(); } - public static MediaProcessorUpdater updater(final String pathSid, final MediaProcessor.UpdateStatus status){ + public static MediaProcessorUpdater updater( + final String pathSid, + final MediaProcessor.UpdateStatus status + ) { return new MediaProcessorUpdater(pathSid, status); } /** - * Converts a JSON String into a MediaProcessor object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return MediaProcessor object represented by the provided JSON - */ - public static MediaProcessor fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a MediaProcessor object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return MediaProcessor object represented by the provided JSON + */ + public static MediaProcessor fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, MediaProcessor.class); @@ -79,14 +84,17 @@ public static MediaProcessor fromJson(final String json, final ObjectMapper obje } /** - * Converts a JSON InputStream into a MediaProcessor object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return MediaProcessor object represented by the provided JSON - */ - public static MediaProcessor fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a MediaProcessor object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return MediaProcessor object represented by the provided JSON + */ + public static MediaProcessor fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, MediaProcessor.class); @@ -96,6 +104,7 @@ public static MediaProcessor fromJson(final InputStream json, final ObjectMapper throw new ApiConnectionException(e.getMessage(), e); } } + public enum Order { ASC("asc"), DESC("desc"); @@ -115,6 +124,7 @@ public static Order forValue(final String value) { return Promoter.enumFromString(value, Order.values()); } } + public enum Status { FAILED("failed"), STARTED("started"), @@ -135,6 +145,7 @@ public static Status forValue(final String value) { return Promoter.enumFromString(value, Status.values()); } } + public enum UpdateStatus { ENDED("ended"); @@ -169,41 +180,20 @@ public static UpdateStatus forValue(final String value) { @JsonCreator private MediaProcessor( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("extension") - final String extension, - - @JsonProperty("extension_context") - final String extensionContext, - - @JsonProperty("status") - final MediaProcessor.Status status, - - @JsonProperty("url") - final URI url, - - @JsonProperty("ended_reason") - final String endedReason, - - @JsonProperty("status_callback") - final URI statusCallback, - - @JsonProperty("status_callback_method") - final HttpMethod statusCallbackMethod, - - @JsonProperty("max_duration") - final Integer maxDuration + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("sid") final String sid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("extension") final String extension, + @JsonProperty("extension_context") final String extensionContext, + @JsonProperty("status") final MediaProcessor.Status status, + @JsonProperty("url") final URI url, + @JsonProperty("ended_reason") final String endedReason, + @JsonProperty("status_callback") final URI statusCallback, + @JsonProperty( + "status_callback_method" + ) final HttpMethod statusCallbackMethod, + @JsonProperty("max_duration") final Integer maxDuration ) { this.accountSid = accountSid; this.sid = sid; @@ -219,46 +209,57 @@ private MediaProcessor( this.maxDuration = maxDuration; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getSid() { - return this.sid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getExtension() { - return this.extension; - } - public final String getExtensionContext() { - return this.extensionContext; - } - public final MediaProcessor.Status getStatus() { - return this.status; - } - public final URI getUrl() { - return this.url; - } - public final String getEndedReason() { - return this.endedReason; - } - public final URI getStatusCallback() { - return this.statusCallback; - } - public final HttpMethod getStatusCallbackMethod() { - return this.statusCallbackMethod; - } - public final Integer getMaxDuration() { - return this.maxDuration; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getSid() { + return this.sid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getExtension() { + return this.extension; + } + + public final String getExtensionContext() { + return this.extensionContext; + } + + public final MediaProcessor.Status getStatus() { + return this.status; + } + + public final URI getUrl() { + return this.url; + } + + public final String getEndedReason() { + return this.endedReason; + } + + public final URI getStatusCallback() { + return this.statusCallback; + } + + public final HttpMethod getStatusCallbackMethod() { + return this.statusCallbackMethod; + } + + public final Integer getMaxDuration() { + return this.maxDuration; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -268,13 +269,37 @@ public boolean equals(final Object o) { MediaProcessor other = (MediaProcessor) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(sid, other.sid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(extension, other.extension) && Objects.equals(extensionContext, other.extensionContext) && Objects.equals(status, other.status) && Objects.equals(url, other.url) && Objects.equals(endedReason, other.endedReason) && Objects.equals(statusCallback, other.statusCallback) && Objects.equals(statusCallbackMethod, other.statusCallbackMethod) && Objects.equals(maxDuration, other.maxDuration) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(sid, other.sid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(extension, other.extension) && + Objects.equals(extensionContext, other.extensionContext) && + Objects.equals(status, other.status) && + Objects.equals(url, other.url) && + Objects.equals(endedReason, other.endedReason) && + Objects.equals(statusCallback, other.statusCallback) && + Objects.equals(statusCallbackMethod, other.statusCallbackMethod) && + Objects.equals(maxDuration, other.maxDuration) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, sid, dateCreated, dateUpdated, extension, extensionContext, status, url, endedReason, statusCallback, statusCallbackMethod, maxDuration); + return Objects.hash( + accountSid, + sid, + dateCreated, + dateUpdated, + extension, + extensionContext, + status, + url, + endedReason, + statusCallback, + statusCallbackMethod, + maxDuration + ); } - } - diff --git a/src/main/java/com/twilio/rest/media/v1/MediaProcessorCreator.java b/src/main/java/com/twilio/rest/media/v1/MediaProcessorCreator.java index 3ae9f00f7b..a7d0f165e8 100644 --- a/src/main/java/com/twilio/rest/media/v1/MediaProcessorCreator.java +++ b/src/main/java/com/twilio/rest/media/v1/MediaProcessorCreator.java @@ -15,9 +15,11 @@ package com.twilio.rest.media.v1; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; +import com.twilio.converter.Converter; +import com.twilio.converter.Converter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; -import com.twilio.converter.Converter; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; @@ -25,16 +27,13 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import java.util.Map; -import com.twilio.converter.Converter; import java.net.URI; - +import java.net.URI; +import java.util.Map; import java.util.Map; +public class MediaProcessorCreator extends Creator { -import java.net.URI; - -public class MediaProcessorCreator extends Creator{ private String extension; private String extensionContext; private Map extensionEnvironment; @@ -42,90 +41,120 @@ public class MediaProcessorCreator extends Creator{ private HttpMethod statusCallbackMethod; private Integer maxDuration; - public MediaProcessorCreator(final String extension, final String extensionContext) { + public MediaProcessorCreator( + final String extension, + final String extensionContext + ) { this.extension = extension; this.extensionContext = extensionContext; } - public MediaProcessorCreator setExtension(final String extension){ + public MediaProcessorCreator setExtension(final String extension) { this.extension = extension; return this; } - public MediaProcessorCreator setExtensionContext(final String extensionContext){ + + public MediaProcessorCreator setExtensionContext( + final String extensionContext + ) { this.extensionContext = extensionContext; return this; } - public MediaProcessorCreator setExtensionEnvironment(final Map extensionEnvironment){ + + public MediaProcessorCreator setExtensionEnvironment( + final Map extensionEnvironment + ) { this.extensionEnvironment = extensionEnvironment; return this; } - public MediaProcessorCreator setStatusCallback(final URI statusCallback){ + + public MediaProcessorCreator setStatusCallback(final URI statusCallback) { this.statusCallback = statusCallback; return this; } - public MediaProcessorCreator setStatusCallback(final String statusCallback){ + public MediaProcessorCreator setStatusCallback( + final String statusCallback + ) { return setStatusCallback(Promoter.uriFromString(statusCallback)); } - public MediaProcessorCreator setStatusCallbackMethod(final HttpMethod statusCallbackMethod){ + + public MediaProcessorCreator setStatusCallbackMethod( + final HttpMethod statusCallbackMethod + ) { this.statusCallbackMethod = statusCallbackMethod; return this; } - public MediaProcessorCreator setMaxDuration(final Integer maxDuration){ + + public MediaProcessorCreator setMaxDuration(final Integer maxDuration) { this.maxDuration = maxDuration; return this; } @Override - public MediaProcessor create(final TwilioRestClient client){ + public MediaProcessor create(final TwilioRestClient client) { String path = "/v1/MediaProcessors"; - path = path.replace("{"+"Extension"+"}", this.extension.toString()); - path = path.replace("{"+"ExtensionContext"+"}", this.extensionContext.toString()); + path = path.replace("{" + "Extension" + "}", this.extension.toString()); + path = + path.replace( + "{" + "ExtensionContext" + "}", + this.extensionContext.toString() + ); Request request = new Request( HttpMethod.POST, Domains.MEDIA.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("MediaProcessor creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "MediaProcessor creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return MediaProcessor.fromJson(response.getStream(), client.getObjectMapper()); + return MediaProcessor.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (extension != null) { request.addPostParam("Extension", extension); - } if (extensionContext != null) { request.addPostParam("ExtensionContext", extensionContext); - } if (extensionEnvironment != null) { - request.addPostParam("ExtensionEnvironment", Converter.mapToJson(extensionEnvironment)); - + request.addPostParam( + "ExtensionEnvironment", + Converter.mapToJson(extensionEnvironment) + ); } if (statusCallback != null) { request.addPostParam("StatusCallback", statusCallback.toString()); - } if (statusCallbackMethod != null) { - request.addPostParam("StatusCallbackMethod", statusCallbackMethod.toString()); - + request.addPostParam( + "StatusCallbackMethod", + statusCallbackMethod.toString() + ); } if (maxDuration != null) { request.addPostParam("MaxDuration", maxDuration.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/media/v1/MediaProcessorFetcher.java b/src/main/java/com/twilio/rest/media/v1/MediaProcessorFetcher.java index cb1cddad64..b7a97432b3 100644 --- a/src/main/java/com/twilio/rest/media/v1/MediaProcessorFetcher.java +++ b/src/main/java/com/twilio/rest/media/v1/MediaProcessorFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class MediaProcessorFetcher extends Fetcher { + private String pathSid; - public MediaProcessorFetcher(final String pathSid){ + public MediaProcessorFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public MediaProcessor fetch(final TwilioRestClient client) { String path = "/v1/MediaProcessors/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,15 +46,23 @@ public MediaProcessor fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("MediaProcessor fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "MediaProcessor fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return MediaProcessor.fromJson(response.getStream(), client.getObjectMapper()); + return MediaProcessor.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/media/v1/MediaProcessorReader.java b/src/main/java/com/twilio/rest/media/v1/MediaProcessorReader.java index e57095cd80..136688c6c6 100644 --- a/src/main/java/com/twilio/rest/media/v1/MediaProcessorReader.java +++ b/src/main/java/com/twilio/rest/media/v1/MediaProcessorReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.media.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,27 +25,26 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class MediaProcessorReader extends Reader { + private MediaProcessor.Order order; private MediaProcessor.Status status; private Integer pageSize; - public MediaProcessorReader(){ - } + public MediaProcessorReader() {} - public MediaProcessorReader setOrder(final MediaProcessor.Order order){ + public MediaProcessorReader setOrder(final MediaProcessor.Order order) { this.order = order; return this; } - public MediaProcessorReader setStatus(final MediaProcessor.Status status){ + + public MediaProcessorReader setStatus(final MediaProcessor.Status status) { this.status = status; return this; } - public MediaProcessorReader setPageSize(final Integer pageSize){ + + public MediaProcessorReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -67,13 +67,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("MediaProcessor read failed: Unable to connect to server"); + throw new ApiConnectionException( + "MediaProcessor read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -89,7 +97,10 @@ private Page pageForRequest(final TwilioRestClient client, final } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.MEDIA.toString()) @@ -97,9 +108,11 @@ public Page previousPage(final Page page, final return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.MEDIA.toString()) @@ -108,29 +121,27 @@ public Page nextPage(final Page page, final Twil } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (order != null) { - request.addQueryParam("Order", order.toString()); } if (status != null) { - request.addQueryParam("Status", status.toString()); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/media/v1/MediaProcessorUpdater.java b/src/main/java/com/twilio/rest/media/v1/MediaProcessorUpdater.java index 7e4880b387..b2a98606aa 100644 --- a/src/main/java/com/twilio/rest/media/v1/MediaProcessorUpdater.java +++ b/src/main/java/com/twilio/rest/media/v1/MediaProcessorUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.media.v1; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,53 +25,65 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class MediaProcessorUpdater extends Updater { - - -public class MediaProcessorUpdater extends Updater{ private String pathSid; private MediaProcessor.UpdateStatus status; - public MediaProcessorUpdater(final String pathSid, final MediaProcessor.UpdateStatus status){ + public MediaProcessorUpdater( + final String pathSid, + final MediaProcessor.UpdateStatus status + ) { this.pathSid = pathSid; this.status = status; } - public MediaProcessorUpdater setStatus(final MediaProcessor.UpdateStatus status){ + public MediaProcessorUpdater setStatus( + final MediaProcessor.UpdateStatus status + ) { this.status = status; return this; } @Override - public MediaProcessor update(final TwilioRestClient client){ + public MediaProcessor update(final TwilioRestClient client) { String path = "/v1/MediaProcessors/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); - path = path.replace("{"+"Status"+"}", this.status.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + path = path.replace("{" + "Status" + "}", this.status.toString()); Request request = new Request( HttpMethod.POST, Domains.MEDIA.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("MediaProcessor update failed: Unable to connect to server"); + throw new ApiConnectionException( + "MediaProcessor update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return MediaProcessor.fromJson(response.getStream(), client.getObjectMapper()); + return MediaProcessor.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (status != null) { request.addPostParam("Status", status.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/media/v1/MediaRecording.java b/src/main/java/com/twilio/rest/media/v1/MediaRecording.java index 2ecb3fac81..12e8a6501b 100644 --- a/src/main/java/com/twilio/rest/media/v1/MediaRecording.java +++ b/src/main/java/com/twilio/rest/media/v1/MediaRecording.java @@ -24,48 +24,47 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; import com.twilio.http.HttpMethod; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class MediaRecording extends Resource { + private static final long serialVersionUID = 72032948872402L; - public static MediaRecordingDeleter deleter(final String pathSid){ + public static MediaRecordingDeleter deleter(final String pathSid) { return new MediaRecordingDeleter(pathSid); } - public static MediaRecordingFetcher fetcher(final String pathSid){ + public static MediaRecordingFetcher fetcher(final String pathSid) { return new MediaRecordingFetcher(pathSid); } - public static MediaRecordingReader reader(){ + public static MediaRecordingReader reader() { return new MediaRecordingReader(); } /** - * Converts a JSON String into a MediaRecording object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return MediaRecording object represented by the provided JSON - */ - public static MediaRecording fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a MediaRecording object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return MediaRecording object represented by the provided JSON + */ + public static MediaRecording fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, MediaRecording.class); @@ -77,14 +76,17 @@ public static MediaRecording fromJson(final String json, final ObjectMapper obje } /** - * Converts a JSON InputStream into a MediaRecording object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return MediaRecording object represented by the provided JSON - */ - public static MediaRecording fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a MediaRecording object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return MediaRecording object represented by the provided JSON + */ + public static MediaRecording fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, MediaRecording.class); @@ -94,6 +96,7 @@ public static MediaRecording fromJson(final InputStream json, final ObjectMapper throw new ApiConnectionException(e.getMessage(), e); } } + public enum Format { MP4("mp4"), WEBM("webm"); @@ -113,6 +116,7 @@ public static Format forValue(final String value) { return Promoter.enumFromString(value, Format.values()); } } + public enum Order { ASC("asc"), DESC("desc"); @@ -132,6 +136,7 @@ public static Order forValue(final String value) { return Promoter.enumFromString(value, Order.values()); } } + public enum Status { PROCESSING("processing"), COMPLETED("completed"), @@ -172,50 +177,23 @@ public static Status forValue(final String value) { @JsonCreator private MediaRecording( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("duration") - final Integer duration, - - @JsonProperty("format") - final MediaRecording.Format format, - - @JsonProperty("links") - final Map links, - - @JsonProperty("processor_sid") - final String processorSid, - - @JsonProperty("resolution") - final String resolution, - - @JsonProperty("source_sid") - final String sourceSid, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("media_size") - final Long mediaSize, - - @JsonProperty("status") - final MediaRecording.Status status, - - @JsonProperty("status_callback") - final URI statusCallback, - - @JsonProperty("status_callback_method") - final HttpMethod statusCallbackMethod, - - @JsonProperty("url") - final URI url + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("duration") final Integer duration, + @JsonProperty("format") final MediaRecording.Format format, + @JsonProperty("links") final Map links, + @JsonProperty("processor_sid") final String processorSid, + @JsonProperty("resolution") final String resolution, + @JsonProperty("source_sid") final String sourceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("media_size") final Long mediaSize, + @JsonProperty("status") final MediaRecording.Status status, + @JsonProperty("status_callback") final URI statusCallback, + @JsonProperty( + "status_callback_method" + ) final HttpMethod statusCallbackMethod, + @JsonProperty("url") final URI url ) { this.accountSid = accountSid; this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); @@ -234,55 +212,69 @@ private MediaRecording( this.url = url; } - public final String getAccountSid() { - return this.accountSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final Integer getDuration() { - return this.duration; - } - public final MediaRecording.Format getFormat() { - return this.format; - } - public final Map getLinks() { - return this.links; - } - public final String getProcessorSid() { - return this.processorSid; - } - public final String getResolution() { - return this.resolution; - } - public final String getSourceSid() { - return this.sourceSid; - } - public final String getSid() { - return this.sid; - } - public final Long getMediaSize() { - return this.mediaSize; - } - public final MediaRecording.Status getStatus() { - return this.status; - } - public final URI getStatusCallback() { - return this.statusCallback; - } - public final HttpMethod getStatusCallbackMethod() { - return this.statusCallbackMethod; - } - public final URI getUrl() { - return this.url; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final Integer getDuration() { + return this.duration; + } + + public final MediaRecording.Format getFormat() { + return this.format; + } + + public final Map getLinks() { + return this.links; + } + + public final String getProcessorSid() { + return this.processorSid; + } + + public final String getResolution() { + return this.resolution; + } + + public final String getSourceSid() { + return this.sourceSid; + } + + public final String getSid() { + return this.sid; + } + + public final Long getMediaSize() { + return this.mediaSize; + } + + public final MediaRecording.Status getStatus() { + return this.status; + } + + public final URI getStatusCallback() { + return this.statusCallback; + } + + public final HttpMethod getStatusCallbackMethod() { + return this.statusCallbackMethod; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -292,13 +284,43 @@ public boolean equals(final Object o) { MediaRecording other = (MediaRecording) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(duration, other.duration) && Objects.equals(format, other.format) && Objects.equals(links, other.links) && Objects.equals(processorSid, other.processorSid) && Objects.equals(resolution, other.resolution) && Objects.equals(sourceSid, other.sourceSid) && Objects.equals(sid, other.sid) && Objects.equals(mediaSize, other.mediaSize) && Objects.equals(status, other.status) && Objects.equals(statusCallback, other.statusCallback) && Objects.equals(statusCallbackMethod, other.statusCallbackMethod) && Objects.equals(url, other.url) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(duration, other.duration) && + Objects.equals(format, other.format) && + Objects.equals(links, other.links) && + Objects.equals(processorSid, other.processorSid) && + Objects.equals(resolution, other.resolution) && + Objects.equals(sourceSid, other.sourceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(mediaSize, other.mediaSize) && + Objects.equals(status, other.status) && + Objects.equals(statusCallback, other.statusCallback) && + Objects.equals(statusCallbackMethod, other.statusCallbackMethod) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, dateCreated, dateUpdated, duration, format, links, processorSid, resolution, sourceSid, sid, mediaSize, status, statusCallback, statusCallbackMethod, url); + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + duration, + format, + links, + processorSid, + resolution, + sourceSid, + sid, + mediaSize, + status, + statusCallback, + statusCallbackMethod, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/media/v1/MediaRecordingDeleter.java b/src/main/java/com/twilio/rest/media/v1/MediaRecordingDeleter.java index acb8cf93b6..0de48ae772 100644 --- a/src/main/java/com/twilio/rest/media/v1/MediaRecordingDeleter.java +++ b/src/main/java/com/twilio/rest/media/v1/MediaRecordingDeleter.java @@ -24,21 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class MediaRecordingDeleter extends Deleter { + private String pathSid; - public MediaRecordingDeleter(final String pathSid){ + public MediaRecordingDeleter(final String pathSid) { this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/MediaRecordings/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -48,9 +46,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("MediaRecording delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "MediaRecording delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/media/v1/MediaRecordingFetcher.java b/src/main/java/com/twilio/rest/media/v1/MediaRecordingFetcher.java index 7bf1c3b62b..1239250e2b 100644 --- a/src/main/java/com/twilio/rest/media/v1/MediaRecordingFetcher.java +++ b/src/main/java/com/twilio/rest/media/v1/MediaRecordingFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class MediaRecordingFetcher extends Fetcher { + private String pathSid; - public MediaRecordingFetcher(final String pathSid){ + public MediaRecordingFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public MediaRecording fetch(final TwilioRestClient client) { String path = "/v1/MediaRecordings/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,15 +46,23 @@ public MediaRecording fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("MediaRecording fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "MediaRecording fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return MediaRecording.fromJson(response.getStream(), client.getObjectMapper()); + return MediaRecording.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/media/v1/MediaRecordingReader.java b/src/main/java/com/twilio/rest/media/v1/MediaRecordingReader.java index 4b55f773a7..47d322fd48 100644 --- a/src/main/java/com/twilio/rest/media/v1/MediaRecordingReader.java +++ b/src/main/java/com/twilio/rest/media/v1/MediaRecordingReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.media.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,37 +25,38 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class MediaRecordingReader extends Reader { + private MediaRecording.Order order; private MediaRecording.Status status; private String processorSid; private String sourceSid; private Integer pageSize; - public MediaRecordingReader(){ - } + public MediaRecordingReader() {} - public MediaRecordingReader setOrder(final MediaRecording.Order order){ + public MediaRecordingReader setOrder(final MediaRecording.Order order) { this.order = order; return this; } - public MediaRecordingReader setStatus(final MediaRecording.Status status){ + + public MediaRecordingReader setStatus(final MediaRecording.Status status) { this.status = status; return this; } - public MediaRecordingReader setProcessorSid(final String processorSid){ + + public MediaRecordingReader setProcessorSid(final String processorSid) { this.processorSid = processorSid; return this; } - public MediaRecordingReader setSourceSid(final String sourceSid){ + + public MediaRecordingReader setSourceSid(final String sourceSid) { this.sourceSid = sourceSid; return this; } - public MediaRecordingReader setPageSize(final Integer pageSize){ + + public MediaRecordingReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -77,13 +79,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("MediaRecording read failed: Unable to connect to server"); + throw new ApiConnectionException( + "MediaRecording read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -99,7 +109,10 @@ private Page pageForRequest(final TwilioRestClient client, final } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.MEDIA.toString()) @@ -107,9 +120,11 @@ public Page previousPage(final Page page, final return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.MEDIA.toString()) @@ -118,37 +133,33 @@ public Page nextPage(final Page page, final Twil } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (order != null) { - request.addQueryParam("Order", order.toString()); } if (status != null) { - request.addQueryParam("Status", status.toString()); } if (processorSid != null) { - request.addQueryParam("ProcessorSid", processorSid); } if (sourceSid != null) { - request.addQueryParam("SourceSid", sourceSid); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/media/v1/PlayerStreamer.java b/src/main/java/com/twilio/rest/media/v1/PlayerStreamer.java index 3581b06f76..53fcb1a42e 100644 --- a/src/main/java/com/twilio/rest/media/v1/PlayerStreamer.java +++ b/src/main/java/com/twilio/rest/media/v1/PlayerStreamer.java @@ -24,52 +24,54 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; import com.twilio.http.HttpMethod; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class PlayerStreamer extends Resource { + private static final long serialVersionUID = 145873037286640L; - public static PlayerStreamerCreator creator(){ + public static PlayerStreamerCreator creator() { return new PlayerStreamerCreator(); } - public static PlayerStreamerFetcher fetcher(final String pathSid){ + public static PlayerStreamerFetcher fetcher(final String pathSid) { return new PlayerStreamerFetcher(pathSid); } - public static PlayerStreamerReader reader(){ + public static PlayerStreamerReader reader() { return new PlayerStreamerReader(); } - public static PlayerStreamerUpdater updater(final String pathSid, final PlayerStreamer.UpdateStatus status){ + public static PlayerStreamerUpdater updater( + final String pathSid, + final PlayerStreamer.UpdateStatus status + ) { return new PlayerStreamerUpdater(pathSid, status); } /** - * Converts a JSON String into a PlayerStreamer object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return PlayerStreamer object represented by the provided JSON - */ - public static PlayerStreamer fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a PlayerStreamer object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return PlayerStreamer object represented by the provided JSON + */ + public static PlayerStreamer fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, PlayerStreamer.class); @@ -81,14 +83,17 @@ public static PlayerStreamer fromJson(final String json, final ObjectMapper obje } /** - * Converts a JSON InputStream into a PlayerStreamer object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return PlayerStreamer object represented by the provided JSON - */ - public static PlayerStreamer fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a PlayerStreamer object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return PlayerStreamer object represented by the provided JSON + */ + public static PlayerStreamer fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, PlayerStreamer.class); @@ -98,6 +103,7 @@ public static PlayerStreamer fromJson(final InputStream json, final ObjectMapper throw new ApiConnectionException(e.getMessage(), e); } } + public enum EndedReason { ENDED_VIA_API("ended-via-api"), MAX_DURATION_EXCEEDED("max-duration-exceeded"), @@ -119,6 +125,7 @@ public static EndedReason forValue(final String value) { return Promoter.enumFromString(value, EndedReason.values()); } } + public enum Order { ASC("asc"), DESC("desc"); @@ -138,6 +145,7 @@ public static Order forValue(final String value) { return Promoter.enumFromString(value, Order.values()); } } + public enum Status { CREATED("created"), STARTED("started"), @@ -159,6 +167,7 @@ public static Status forValue(final String value) { return Promoter.enumFromString(value, Status.values()); } } + public enum UpdateStatus { ENDED("ended"); @@ -193,41 +202,22 @@ public static UpdateStatus forValue(final String value) { @JsonCreator private PlayerStreamer( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("video") - final Boolean video, - - @JsonProperty("links") - final Map links, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("status") - final PlayerStreamer.Status status, - - @JsonProperty("url") - final URI url, - - @JsonProperty("status_callback") - final URI statusCallback, - - @JsonProperty("status_callback_method") - final HttpMethod statusCallbackMethod, - - @JsonProperty("ended_reason") - final PlayerStreamer.EndedReason endedReason, - - @JsonProperty("max_duration") - final Integer maxDuration + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("video") final Boolean video, + @JsonProperty("links") final Map links, + @JsonProperty("sid") final String sid, + @JsonProperty("status") final PlayerStreamer.Status status, + @JsonProperty("url") final URI url, + @JsonProperty("status_callback") final URI statusCallback, + @JsonProperty( + "status_callback_method" + ) final HttpMethod statusCallbackMethod, + @JsonProperty( + "ended_reason" + ) final PlayerStreamer.EndedReason endedReason, + @JsonProperty("max_duration") final Integer maxDuration ) { this.accountSid = accountSid; this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); @@ -243,46 +233,57 @@ private PlayerStreamer( this.maxDuration = maxDuration; } - public final String getAccountSid() { - return this.accountSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final Boolean getVideo() { - return this.video; - } - public final Map getLinks() { - return this.links; - } - public final String getSid() { - return this.sid; - } - public final PlayerStreamer.Status getStatus() { - return this.status; - } - public final URI getUrl() { - return this.url; - } - public final URI getStatusCallback() { - return this.statusCallback; - } - public final HttpMethod getStatusCallbackMethod() { - return this.statusCallbackMethod; - } - public final PlayerStreamer.EndedReason getEndedReason() { - return this.endedReason; - } - public final Integer getMaxDuration() { - return this.maxDuration; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final Boolean getVideo() { + return this.video; + } + + public final Map getLinks() { + return this.links; + } + + public final String getSid() { + return this.sid; + } + + public final PlayerStreamer.Status getStatus() { + return this.status; + } + + public final URI getUrl() { + return this.url; + } + + public final URI getStatusCallback() { + return this.statusCallback; + } + + public final HttpMethod getStatusCallbackMethod() { + return this.statusCallbackMethod; + } + + public final PlayerStreamer.EndedReason getEndedReason() { + return this.endedReason; + } + + public final Integer getMaxDuration() { + return this.maxDuration; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -292,13 +293,37 @@ public boolean equals(final Object o) { PlayerStreamer other = (PlayerStreamer) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(video, other.video) && Objects.equals(links, other.links) && Objects.equals(sid, other.sid) && Objects.equals(status, other.status) && Objects.equals(url, other.url) && Objects.equals(statusCallback, other.statusCallback) && Objects.equals(statusCallbackMethod, other.statusCallbackMethod) && Objects.equals(endedReason, other.endedReason) && Objects.equals(maxDuration, other.maxDuration) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(video, other.video) && + Objects.equals(links, other.links) && + Objects.equals(sid, other.sid) && + Objects.equals(status, other.status) && + Objects.equals(url, other.url) && + Objects.equals(statusCallback, other.statusCallback) && + Objects.equals(statusCallbackMethod, other.statusCallbackMethod) && + Objects.equals(endedReason, other.endedReason) && + Objects.equals(maxDuration, other.maxDuration) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, dateCreated, dateUpdated, video, links, sid, status, url, statusCallback, statusCallbackMethod, endedReason, maxDuration); + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + video, + links, + sid, + status, + url, + statusCallback, + statusCallbackMethod, + endedReason, + maxDuration + ); } - } - diff --git a/src/main/java/com/twilio/rest/media/v1/PlayerStreamerCreator.java b/src/main/java/com/twilio/rest/media/v1/PlayerStreamerCreator.java index 82fbd040f4..bc635e1250 100644 --- a/src/main/java/com/twilio/rest/media/v1/PlayerStreamerCreator.java +++ b/src/main/java/com/twilio/rest/media/v1/PlayerStreamerCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.media.v1; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -25,81 +26,93 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.net.URI; - - - import java.net.URI; -public class PlayerStreamerCreator extends Creator{ +public class PlayerStreamerCreator extends Creator { + private Boolean video; private URI statusCallback; private HttpMethod statusCallbackMethod; private Integer maxDuration; - public PlayerStreamerCreator() { - } + public PlayerStreamerCreator() {} - public PlayerStreamerCreator setVideo(final Boolean video){ + public PlayerStreamerCreator setVideo(final Boolean video) { this.video = video; return this; } - public PlayerStreamerCreator setStatusCallback(final URI statusCallback){ + + public PlayerStreamerCreator setStatusCallback(final URI statusCallback) { this.statusCallback = statusCallback; return this; } - public PlayerStreamerCreator setStatusCallback(final String statusCallback){ + public PlayerStreamerCreator setStatusCallback( + final String statusCallback + ) { return setStatusCallback(Promoter.uriFromString(statusCallback)); } - public PlayerStreamerCreator setStatusCallbackMethod(final HttpMethod statusCallbackMethod){ + + public PlayerStreamerCreator setStatusCallbackMethod( + final HttpMethod statusCallbackMethod + ) { this.statusCallbackMethod = statusCallbackMethod; return this; } - public PlayerStreamerCreator setMaxDuration(final Integer maxDuration){ + + public PlayerStreamerCreator setMaxDuration(final Integer maxDuration) { this.maxDuration = maxDuration; return this; } @Override - public PlayerStreamer create(final TwilioRestClient client){ + public PlayerStreamer create(final TwilioRestClient client) { String path = "/v1/PlayerStreamers"; - Request request = new Request( HttpMethod.POST, Domains.MEDIA.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("PlayerStreamer creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "PlayerStreamer creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return PlayerStreamer.fromJson(response.getStream(), client.getObjectMapper()); + return PlayerStreamer.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (video != null) { request.addPostParam("Video", video.toString()); - } if (statusCallback != null) { request.addPostParam("StatusCallback", statusCallback.toString()); - } if (statusCallbackMethod != null) { - request.addPostParam("StatusCallbackMethod", statusCallbackMethod.toString()); - + request.addPostParam( + "StatusCallbackMethod", + statusCallbackMethod.toString() + ); } if (maxDuration != null) { request.addPostParam("MaxDuration", maxDuration.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/media/v1/PlayerStreamerFetcher.java b/src/main/java/com/twilio/rest/media/v1/PlayerStreamerFetcher.java index 3b00cce265..fdc35c9135 100644 --- a/src/main/java/com/twilio/rest/media/v1/PlayerStreamerFetcher.java +++ b/src/main/java/com/twilio/rest/media/v1/PlayerStreamerFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class PlayerStreamerFetcher extends Fetcher { + private String pathSid; - public PlayerStreamerFetcher(final String pathSid){ + public PlayerStreamerFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public PlayerStreamer fetch(final TwilioRestClient client) { String path = "/v1/PlayerStreamers/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,15 +46,23 @@ public PlayerStreamer fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("PlayerStreamer fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "PlayerStreamer fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return PlayerStreamer.fromJson(response.getStream(), client.getObjectMapper()); + return PlayerStreamer.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/media/v1/PlayerStreamerReader.java b/src/main/java/com/twilio/rest/media/v1/PlayerStreamerReader.java index 8e97aae3f8..3926af0046 100644 --- a/src/main/java/com/twilio/rest/media/v1/PlayerStreamerReader.java +++ b/src/main/java/com/twilio/rest/media/v1/PlayerStreamerReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.media.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,27 +25,26 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class PlayerStreamerReader extends Reader { + private PlayerStreamer.Order order; private PlayerStreamer.Status status; private Integer pageSize; - public PlayerStreamerReader(){ - } + public PlayerStreamerReader() {} - public PlayerStreamerReader setOrder(final PlayerStreamer.Order order){ + public PlayerStreamerReader setOrder(final PlayerStreamer.Order order) { this.order = order; return this; } - public PlayerStreamerReader setStatus(final PlayerStreamer.Status status){ + + public PlayerStreamerReader setStatus(final PlayerStreamer.Status status) { this.status = status; return this; } - public PlayerStreamerReader setPageSize(final Integer pageSize){ + + public PlayerStreamerReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -67,13 +67,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("PlayerStreamer read failed: Unable to connect to server"); + throw new ApiConnectionException( + "PlayerStreamer read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -89,7 +97,10 @@ private Page pageForRequest(final TwilioRestClient client, final } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.MEDIA.toString()) @@ -97,9 +108,11 @@ public Page previousPage(final Page page, final return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.MEDIA.toString()) @@ -108,29 +121,27 @@ public Page nextPage(final Page page, final Twil } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (order != null) { - request.addQueryParam("Order", order.toString()); } if (status != null) { - request.addQueryParam("Status", status.toString()); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/media/v1/PlayerStreamerUpdater.java b/src/main/java/com/twilio/rest/media/v1/PlayerStreamerUpdater.java index 4252c7fcd9..e1cdc32f2d 100644 --- a/src/main/java/com/twilio/rest/media/v1/PlayerStreamerUpdater.java +++ b/src/main/java/com/twilio/rest/media/v1/PlayerStreamerUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.media.v1; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,53 +25,65 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class PlayerStreamerUpdater extends Updater { - - -public class PlayerStreamerUpdater extends Updater{ private String pathSid; private PlayerStreamer.UpdateStatus status; - public PlayerStreamerUpdater(final String pathSid, final PlayerStreamer.UpdateStatus status){ + public PlayerStreamerUpdater( + final String pathSid, + final PlayerStreamer.UpdateStatus status + ) { this.pathSid = pathSid; this.status = status; } - public PlayerStreamerUpdater setStatus(final PlayerStreamer.UpdateStatus status){ + public PlayerStreamerUpdater setStatus( + final PlayerStreamer.UpdateStatus status + ) { this.status = status; return this; } @Override - public PlayerStreamer update(final TwilioRestClient client){ + public PlayerStreamer update(final TwilioRestClient client) { String path = "/v1/PlayerStreamers/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); - path = path.replace("{"+"Status"+"}", this.status.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + path = path.replace("{" + "Status" + "}", this.status.toString()); Request request = new Request( HttpMethod.POST, Domains.MEDIA.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("PlayerStreamer update failed: Unable to connect to server"); + throw new ApiConnectionException( + "PlayerStreamer update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return PlayerStreamer.fromJson(response.getStream(), client.getObjectMapper()); + return PlayerStreamer.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (status != null) { request.addPostParam("Status", status.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/media/v1/playerstreamer/PlaybackGrant.java b/src/main/java/com/twilio/rest/media/v1/playerstreamer/PlaybackGrant.java index 571325929f..07ba5e4968 100644 --- a/src/main/java/com/twilio/rest/media/v1/playerstreamer/PlaybackGrant.java +++ b/src/main/java/com/twilio/rest/media/v1/playerstreamer/PlaybackGrant.java @@ -23,43 +23,42 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class PlaybackGrant extends Resource { + private static final long serialVersionUID = 188445421727262L; - public static PlaybackGrantCreator creator(final String pathSid){ + public static PlaybackGrantCreator creator(final String pathSid) { return new PlaybackGrantCreator(pathSid); } - public static PlaybackGrantFetcher fetcher(final String pathSid){ + public static PlaybackGrantFetcher fetcher(final String pathSid) { return new PlaybackGrantFetcher(pathSid); } /** - * Converts a JSON String into a PlaybackGrant object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return PlaybackGrant object represented by the provided JSON - */ - public static PlaybackGrant fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a PlaybackGrant object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return PlaybackGrant object represented by the provided JSON + */ + public static PlaybackGrant fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, PlaybackGrant.class); @@ -71,14 +70,17 @@ public static PlaybackGrant fromJson(final String json, final ObjectMapper objec } /** - * Converts a JSON InputStream into a PlaybackGrant object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return PlaybackGrant object represented by the provided JSON - */ - public static PlaybackGrant fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a PlaybackGrant object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return PlaybackGrant object represented by the provided JSON + */ + public static PlaybackGrant fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, PlaybackGrant.class); @@ -97,20 +99,11 @@ public static PlaybackGrant fromJson(final InputStream json, final ObjectMapper @JsonCreator private PlaybackGrant( - @JsonProperty("sid") - final String sid, - - @JsonProperty("url") - final URI url, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("grant") - final Map grant + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("grant") final Map grant ) { this.sid = sid; this.url = url; @@ -119,25 +112,29 @@ private PlaybackGrant( this.grant = grant; } - public final String getSid() { - return this.sid; - } - public final URI getUrl() { - return this.url; - } - public final String getAccountSid() { - return this.accountSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final Map getGrant() { - return this.grant; - } + public final String getSid() { + return this.sid; + } + + public final URI getUrl() { + return this.url; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final Map getGrant() { + return this.grant; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -147,13 +144,17 @@ public boolean equals(final Object o) { PlaybackGrant other = (PlaybackGrant) o; - return Objects.equals(sid, other.sid) && Objects.equals(url, other.url) && Objects.equals(accountSid, other.accountSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(grant, other.grant) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(grant, other.grant) + ); } @Override public int hashCode() { return Objects.hash(sid, url, accountSid, dateCreated, grant); } - } - diff --git a/src/main/java/com/twilio/rest/media/v1/playerstreamer/PlaybackGrantCreator.java b/src/main/java/com/twilio/rest/media/v1/playerstreamer/PlaybackGrantCreator.java index 0862edd5ab..4645073c9d 100644 --- a/src/main/java/com/twilio/rest/media/v1/playerstreamer/PlaybackGrantCreator.java +++ b/src/main/java/com/twilio/rest/media/v1/playerstreamer/PlaybackGrantCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.media.v1.playerstreamer; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class PlaybackGrantCreator extends Creator { - - -public class PlaybackGrantCreator extends Creator{ private String pathSid; private Integer ttl; private String accessControlAllowOrigin; @@ -36,48 +35,62 @@ public PlaybackGrantCreator(final String pathSid) { this.pathSid = pathSid; } - public PlaybackGrantCreator setTtl(final Integer ttl){ + public PlaybackGrantCreator setTtl(final Integer ttl) { this.ttl = ttl; return this; } - public PlaybackGrantCreator setAccessControlAllowOrigin(final String accessControlAllowOrigin){ + + public PlaybackGrantCreator setAccessControlAllowOrigin( + final String accessControlAllowOrigin + ) { this.accessControlAllowOrigin = accessControlAllowOrigin; return this; } @Override - public PlaybackGrant create(final TwilioRestClient client){ + public PlaybackGrant create(final TwilioRestClient client) { String path = "/v1/PlayerStreamers/{Sid}/PlaybackGrant"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.MEDIA.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("PlaybackGrant creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "PlaybackGrant creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return PlaybackGrant.fromJson(response.getStream(), client.getObjectMapper()); + return PlaybackGrant.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (ttl != null) { request.addPostParam("Ttl", ttl.toString()); - } if (accessControlAllowOrigin != null) { - request.addPostParam("AccessControlAllowOrigin", accessControlAllowOrigin); - + request.addPostParam( + "AccessControlAllowOrigin", + accessControlAllowOrigin + ); } } } diff --git a/src/main/java/com/twilio/rest/media/v1/playerstreamer/PlaybackGrantFetcher.java b/src/main/java/com/twilio/rest/media/v1/playerstreamer/PlaybackGrantFetcher.java index b48ad1a3e4..59fbc639cc 100644 --- a/src/main/java/com/twilio/rest/media/v1/playerstreamer/PlaybackGrantFetcher.java +++ b/src/main/java/com/twilio/rest/media/v1/playerstreamer/PlaybackGrantFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class PlaybackGrantFetcher extends Fetcher { + private String pathSid; - public PlaybackGrantFetcher(final String pathSid){ + public PlaybackGrantFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public PlaybackGrant fetch(final TwilioRestClient client) { String path = "/v1/PlayerStreamers/{Sid}/PlaybackGrant"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,15 +46,23 @@ public PlaybackGrant fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("PlaybackGrant fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "PlaybackGrant fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return PlaybackGrant.fromJson(response.getStream(), client.getObjectMapper()); + return PlaybackGrant.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/messaging/v1/BrandRegistration.java b/src/main/java/com/twilio/rest/messaging/v1/BrandRegistration.java index fbe22b013c..027f2540d0 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/BrandRegistration.java +++ b/src/main/java/com/twilio/rest/messaging/v1/BrandRegistration.java @@ -24,52 +24,57 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.List; import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class BrandRegistration extends Resource { + private static final long serialVersionUID = 243231933683239L; - public static BrandRegistrationCreator creator(final String customerProfileBundleSid, final String a2PProfileBundleSid){ - return new BrandRegistrationCreator(customerProfileBundleSid, a2PProfileBundleSid); + public static BrandRegistrationCreator creator( + final String customerProfileBundleSid, + final String a2PProfileBundleSid + ) { + return new BrandRegistrationCreator( + customerProfileBundleSid, + a2PProfileBundleSid + ); } - public static BrandRegistrationFetcher fetcher(final String pathSid){ + public static BrandRegistrationFetcher fetcher(final String pathSid) { return new BrandRegistrationFetcher(pathSid); } - public static BrandRegistrationReader reader(){ + public static BrandRegistrationReader reader() { return new BrandRegistrationReader(); } - public static BrandRegistrationUpdater updater(final String pathSid){ + public static BrandRegistrationUpdater updater(final String pathSid) { return new BrandRegistrationUpdater(pathSid); } /** - * Converts a JSON String into a BrandRegistration object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return BrandRegistration object represented by the provided JSON - */ - public static BrandRegistration fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a BrandRegistration object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return BrandRegistration object represented by the provided JSON + */ + public static BrandRegistration fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, BrandRegistration.class); @@ -81,14 +86,17 @@ public static BrandRegistration fromJson(final String json, final ObjectMapper o } /** - * Converts a JSON InputStream into a BrandRegistration object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return BrandRegistration object represented by the provided JSON - */ - public static BrandRegistration fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a BrandRegistration object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return BrandRegistration object represented by the provided JSON + */ + public static BrandRegistration fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, BrandRegistration.class); @@ -98,6 +106,7 @@ public static BrandRegistration fromJson(final InputStream json, final ObjectMap throw new ApiConnectionException(e.getMessage(), e); } } + public enum BrandFeedback { TAX_ID("TAX_ID"), STOCK_SYMBOL("STOCK_SYMBOL"), @@ -120,6 +129,7 @@ public static BrandFeedback forValue(final String value) { return Promoter.enumFromString(value, BrandFeedback.values()); } } + public enum IdentityStatus { SELF_DECLARED("SELF_DECLARED"), UNVERIFIED("UNVERIFIED"), @@ -141,6 +151,7 @@ public static IdentityStatus forValue(final String value) { return Promoter.enumFromString(value, IdentityStatus.values()); } } + public enum Status { PENDING("PENDING"), APPROVED("APPROVED"), @@ -187,65 +198,36 @@ public static Status forValue(final String value) { @JsonCreator private BrandRegistration( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("customer_profile_bundle_sid") - final String customerProfileBundleSid, - - @JsonProperty("a2p_profile_bundle_sid") - final String a2pProfileBundleSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("brand_type") - final String brandType, - - @JsonProperty("status") - final BrandRegistration.Status status, - - @JsonProperty("tcr_id") - final String tcrId, - - @JsonProperty("failure_reason") - final String failureReason, - - @JsonProperty("url") - final URI url, - - @JsonProperty("brand_score") - final Integer brandScore, - - @JsonProperty("brand_feedback") - final List brandFeedback, - - @JsonProperty("identity_status") - final BrandRegistration.IdentityStatus identityStatus, - - @JsonProperty("russell3000") - final Boolean russell3000, - - @JsonProperty("government_entity") - final Boolean governmentEntity, - - @JsonProperty("tax_exempt_status") - final String taxExemptStatus, - - @JsonProperty("skip_automatic_sec_vet") - final Boolean skipAutomaticSecVet, - - @JsonProperty("mock") - final Boolean mock, - - @JsonProperty("links") - final Map links + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty( + "customer_profile_bundle_sid" + ) final String customerProfileBundleSid, + @JsonProperty( + "a2p_profile_bundle_sid" + ) final String a2pProfileBundleSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("brand_type") final String brandType, + @JsonProperty("status") final BrandRegistration.Status status, + @JsonProperty("tcr_id") final String tcrId, + @JsonProperty("failure_reason") final String failureReason, + @JsonProperty("url") final URI url, + @JsonProperty("brand_score") final Integer brandScore, + @JsonProperty( + "brand_feedback" + ) final List brandFeedback, + @JsonProperty( + "identity_status" + ) final BrandRegistration.IdentityStatus identityStatus, + @JsonProperty("russell3000") final Boolean russell3000, + @JsonProperty("government_entity") final Boolean governmentEntity, + @JsonProperty("tax_exempt_status") final String taxExemptStatus, + @JsonProperty( + "skip_automatic_sec_vet" + ) final Boolean skipAutomaticSecVet, + @JsonProperty("mock") final Boolean mock, + @JsonProperty("links") final Map links ) { this.sid = sid; this.accountSid = accountSid; @@ -269,70 +251,89 @@ private BrandRegistration( this.links = links; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getCustomerProfileBundleSid() { - return this.customerProfileBundleSid; - } - public final String getA2pProfileBundleSid() { - return this.a2pProfileBundleSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getBrandType() { - return this.brandType; - } - public final BrandRegistration.Status getStatus() { - return this.status; - } - public final String getTcrId() { - return this.tcrId; - } - public final String getFailureReason() { - return this.failureReason; - } - public final URI getUrl() { - return this.url; - } - public final Integer getBrandScore() { - return this.brandScore; - } - public final List getBrandFeedback() { - return this.brandFeedback; - } - public final BrandRegistration.IdentityStatus getIdentityStatus() { - return this.identityStatus; - } - public final Boolean getRussell3000() { - return this.russell3000; - } - public final Boolean getGovernmentEntity() { - return this.governmentEntity; - } - public final String getTaxExemptStatus() { - return this.taxExemptStatus; - } - public final Boolean getSkipAutomaticSecVet() { - return this.skipAutomaticSecVet; - } - public final Boolean getMock() { - return this.mock; - } - public final Map getLinks() { - return this.links; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getCustomerProfileBundleSid() { + return this.customerProfileBundleSid; + } + + public final String getA2pProfileBundleSid() { + return this.a2pProfileBundleSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getBrandType() { + return this.brandType; + } + + public final BrandRegistration.Status getStatus() { + return this.status; + } + + public final String getTcrId() { + return this.tcrId; + } + + public final String getFailureReason() { + return this.failureReason; + } + + public final URI getUrl() { + return this.url; + } + + public final Integer getBrandScore() { + return this.brandScore; + } + + public final List getBrandFeedback() { + return this.brandFeedback; + } + + public final BrandRegistration.IdentityStatus getIdentityStatus() { + return this.identityStatus; + } + + public final Boolean getRussell3000() { + return this.russell3000; + } + + public final Boolean getGovernmentEntity() { + return this.governmentEntity; + } + + public final String getTaxExemptStatus() { + return this.taxExemptStatus; + } + + public final Boolean getSkipAutomaticSecVet() { + return this.skipAutomaticSecVet; + } + + public final Boolean getMock() { + return this.mock; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -342,13 +343,56 @@ public boolean equals(final Object o) { BrandRegistration other = (BrandRegistration) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(customerProfileBundleSid, other.customerProfileBundleSid) && Objects.equals(a2pProfileBundleSid, other.a2pProfileBundleSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(brandType, other.brandType) && Objects.equals(status, other.status) && Objects.equals(tcrId, other.tcrId) && Objects.equals(failureReason, other.failureReason) && Objects.equals(url, other.url) && Objects.equals(brandScore, other.brandScore) && Objects.equals(brandFeedback, other.brandFeedback) && Objects.equals(identityStatus, other.identityStatus) && Objects.equals(russell3000, other.russell3000) && Objects.equals(governmentEntity, other.governmentEntity) && Objects.equals(taxExemptStatus, other.taxExemptStatus) && Objects.equals(skipAutomaticSecVet, other.skipAutomaticSecVet) && Objects.equals(mock, other.mock) && Objects.equals(links, other.links) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals( + customerProfileBundleSid, + other.customerProfileBundleSid + ) && + Objects.equals(a2pProfileBundleSid, other.a2pProfileBundleSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(brandType, other.brandType) && + Objects.equals(status, other.status) && + Objects.equals(tcrId, other.tcrId) && + Objects.equals(failureReason, other.failureReason) && + Objects.equals(url, other.url) && + Objects.equals(brandScore, other.brandScore) && + Objects.equals(brandFeedback, other.brandFeedback) && + Objects.equals(identityStatus, other.identityStatus) && + Objects.equals(russell3000, other.russell3000) && + Objects.equals(governmentEntity, other.governmentEntity) && + Objects.equals(taxExemptStatus, other.taxExemptStatus) && + Objects.equals(skipAutomaticSecVet, other.skipAutomaticSecVet) && + Objects.equals(mock, other.mock) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, customerProfileBundleSid, a2pProfileBundleSid, dateCreated, dateUpdated, brandType, status, tcrId, failureReason, url, brandScore, brandFeedback, identityStatus, russell3000, governmentEntity, taxExemptStatus, skipAutomaticSecVet, mock, links); + return Objects.hash( + sid, + accountSid, + customerProfileBundleSid, + a2pProfileBundleSid, + dateCreated, + dateUpdated, + brandType, + status, + tcrId, + failureReason, + url, + brandScore, + brandFeedback, + identityStatus, + russell3000, + governmentEntity, + taxExemptStatus, + skipAutomaticSecVet, + mock, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/messaging/v1/BrandRegistrationCreator.java b/src/main/java/com/twilio/rest/messaging/v1/BrandRegistrationCreator.java index ea103d625b..a15dac4836 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/BrandRegistrationCreator.java +++ b/src/main/java/com/twilio/rest/messaging/v1/BrandRegistrationCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.messaging.v1; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,88 +25,118 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class BrandRegistrationCreator extends Creator { - - -public class BrandRegistrationCreator extends Creator{ private String customerProfileBundleSid; private String a2PProfileBundleSid; private String brandType; private Boolean mock; private Boolean skipAutomaticSecVet; - public BrandRegistrationCreator(final String customerProfileBundleSid, final String a2PProfileBundleSid) { + public BrandRegistrationCreator( + final String customerProfileBundleSid, + final String a2PProfileBundleSid + ) { this.customerProfileBundleSid = customerProfileBundleSid; this.a2PProfileBundleSid = a2PProfileBundleSid; } - public BrandRegistrationCreator setCustomerProfileBundleSid(final String customerProfileBundleSid){ + public BrandRegistrationCreator setCustomerProfileBundleSid( + final String customerProfileBundleSid + ) { this.customerProfileBundleSid = customerProfileBundleSid; return this; } - public BrandRegistrationCreator setA2PProfileBundleSid(final String a2PProfileBundleSid){ + + public BrandRegistrationCreator setA2PProfileBundleSid( + final String a2PProfileBundleSid + ) { this.a2PProfileBundleSid = a2PProfileBundleSid; return this; } - public BrandRegistrationCreator setBrandType(final String brandType){ + + public BrandRegistrationCreator setBrandType(final String brandType) { this.brandType = brandType; return this; } - public BrandRegistrationCreator setMock(final Boolean mock){ + + public BrandRegistrationCreator setMock(final Boolean mock) { this.mock = mock; return this; } - public BrandRegistrationCreator setSkipAutomaticSecVet(final Boolean skipAutomaticSecVet){ + + public BrandRegistrationCreator setSkipAutomaticSecVet( + final Boolean skipAutomaticSecVet + ) { this.skipAutomaticSecVet = skipAutomaticSecVet; return this; } @Override - public BrandRegistration create(final TwilioRestClient client){ + public BrandRegistration create(final TwilioRestClient client) { String path = "/v1/a2p/BrandRegistrations"; - path = path.replace("{"+"CustomerProfileBundleSid"+"}", this.customerProfileBundleSid.toString()); - path = path.replace("{"+"A2PProfileBundleSid"+"}", this.a2PProfileBundleSid.toString()); + path = + path.replace( + "{" + "CustomerProfileBundleSid" + "}", + this.customerProfileBundleSid.toString() + ); + path = + path.replace( + "{" + "A2PProfileBundleSid" + "}", + this.a2PProfileBundleSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.MESSAGING.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("BrandRegistration creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "BrandRegistration creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return BrandRegistration.fromJson(response.getStream(), client.getObjectMapper()); + return BrandRegistration.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (customerProfileBundleSid != null) { - request.addPostParam("CustomerProfileBundleSid", customerProfileBundleSid); - + request.addPostParam( + "CustomerProfileBundleSid", + customerProfileBundleSid + ); } if (a2PProfileBundleSid != null) { request.addPostParam("A2PProfileBundleSid", a2PProfileBundleSid); - } if (brandType != null) { request.addPostParam("BrandType", brandType); - } if (mock != null) { request.addPostParam("Mock", mock.toString()); - } if (skipAutomaticSecVet != null) { - request.addPostParam("SkipAutomaticSecVet", skipAutomaticSecVet.toString()); - + request.addPostParam( + "SkipAutomaticSecVet", + skipAutomaticSecVet.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/messaging/v1/BrandRegistrationFetcher.java b/src/main/java/com/twilio/rest/messaging/v1/BrandRegistrationFetcher.java index 4c39ea01fd..8a7a2a3a83 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/BrandRegistrationFetcher.java +++ b/src/main/java/com/twilio/rest/messaging/v1/BrandRegistrationFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class BrandRegistrationFetcher extends Fetcher { + private String pathSid; - public BrandRegistrationFetcher(final String pathSid){ + public BrandRegistrationFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public BrandRegistration fetch(final TwilioRestClient client) { String path = "/v1/a2p/BrandRegistrations/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,15 +46,23 @@ public BrandRegistration fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("BrandRegistration fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "BrandRegistration fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return BrandRegistration.fromJson(response.getStream(), client.getObjectMapper()); + return BrandRegistration.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/messaging/v1/BrandRegistrationReader.java b/src/main/java/com/twilio/rest/messaging/v1/BrandRegistrationReader.java index 92be66e7b8..67841997e6 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/BrandRegistrationReader.java +++ b/src/main/java/com/twilio/rest/messaging/v1/BrandRegistrationReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.messaging.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,17 +25,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class BrandRegistrationReader extends Reader { + private Integer pageSize; - public BrandRegistrationReader(){ - } + public BrandRegistrationReader() {} - public BrandRegistrationReader setPageSize(final Integer pageSize){ + public BrandRegistrationReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -57,13 +55,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("BrandRegistration read failed: Unable to connect to server"); + throw new ApiConnectionException( + "BrandRegistration read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -79,7 +85,10 @@ private Page pageForRequest(final TwilioRestClient client, fi } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.MESSAGING.toString()) @@ -87,9 +96,11 @@ public Page previousPage(final Page page, return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.MESSAGING.toString()) @@ -98,21 +109,21 @@ public Page nextPage(final Page page, fina } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/messaging/v1/BrandRegistrationUpdater.java b/src/main/java/com/twilio/rest/messaging/v1/BrandRegistrationUpdater.java index bdf82acf5a..5f5fd9b249 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/BrandRegistrationUpdater.java +++ b/src/main/java/com/twilio/rest/messaging/v1/BrandRegistrationUpdater.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class BrandRegistrationUpdater extends Updater { - - -public class BrandRegistrationUpdater extends Updater{ private String pathSid; - public BrandRegistrationUpdater(final String pathSid){ + public BrandRegistrationUpdater(final String pathSid) { this.pathSid = pathSid; } - @Override - public BrandRegistration update(final TwilioRestClient client){ + public BrandRegistration update(final TwilioRestClient client) { String path = "/v1/a2p/BrandRegistrations/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, @@ -48,15 +45,23 @@ public BrandRegistration update(final TwilioRestClient client){ ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("BrandRegistration update failed: Unable to connect to server"); + throw new ApiConnectionException( + "BrandRegistration update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return BrandRegistration.fromJson(response.getStream(), client.getObjectMapper()); + return BrandRegistration.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/messaging/v1/Deactivations.java b/src/main/java/com/twilio/rest/messaging/v1/Deactivations.java index b99badd26c..791de912cc 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/Deactivations.java +++ b/src/main/java/com/twilio/rest/messaging/v1/Deactivations.java @@ -22,36 +22,35 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Deactivations extends Resource { + private static final long serialVersionUID = 245900587626041L; - public static DeactivationsFetcher fetcher(){ + public static DeactivationsFetcher fetcher() { return new DeactivationsFetcher(); } /** - * Converts a JSON String into a Deactivations object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Deactivations object represented by the provided JSON - */ - public static Deactivations fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Deactivations object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Deactivations object represented by the provided JSON + */ + public static Deactivations fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Deactivations.class); @@ -63,14 +62,17 @@ public static Deactivations fromJson(final String json, final ObjectMapper objec } /** - * Converts a JSON InputStream into a Deactivations object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Deactivations object represented by the provided JSON - */ - public static Deactivations fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Deactivations object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Deactivations object represented by the provided JSON + */ + public static Deactivations fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Deactivations.class); @@ -84,20 +86,17 @@ public static Deactivations fromJson(final InputStream json, final ObjectMapper private final URI redirectTo; @JsonCreator - private Deactivations( - @JsonProperty("redirect_to") - final URI redirectTo - ) { + private Deactivations(@JsonProperty("redirect_to") final URI redirectTo) { this.redirectTo = redirectTo; } - public final URI getRedirectTo() { - return this.redirectTo; - } + public final URI getRedirectTo() { + return this.redirectTo; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -107,13 +106,11 @@ public boolean equals(final Object o) { Deactivations other = (Deactivations) o; - return Objects.equals(redirectTo, other.redirectTo) ; + return Objects.equals(redirectTo, other.redirectTo); } @Override public int hashCode() { return Objects.hash(redirectTo); } - } - diff --git a/src/main/java/com/twilio/rest/messaging/v1/DeactivationsFetcher.java b/src/main/java/com/twilio/rest/messaging/v1/DeactivationsFetcher.java index a89d69e44f..c0f5d0543c 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/DeactivationsFetcher.java +++ b/src/main/java/com/twilio/rest/messaging/v1/DeactivationsFetcher.java @@ -15,6 +15,7 @@ package com.twilio.rest.messaging.v1; import com.twilio.base.Fetcher; +import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -23,19 +24,15 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.time.LocalDate; -import com.twilio.converter.DateConverter; - - public class DeactivationsFetcher extends Fetcher { + private LocalDate date; - public DeactivationsFetcher(){ - } + public DeactivationsFetcher() {} - public DeactivationsFetcher setDate(final LocalDate date){ + public DeactivationsFetcher setDate(final LocalDate date) { this.date = date; return this; } @@ -44,7 +41,6 @@ public DeactivationsFetcher setDate(final LocalDate date){ public Deactivations fetch(final TwilioRestClient client) { String path = "/v1/Deactivations"; - Request request = new Request( HttpMethod.GET, Domains.MESSAGING.toString(), @@ -54,21 +50,32 @@ public Deactivations fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Deactivations fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Deactivations fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Deactivations.fromJson(response.getStream(), client.getObjectMapper()); + return Deactivations.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addQueryParams(final Request request) { if (date != null) { - request.addQueryParam("Date", DateConverter.dateStringFromLocalDate(date)); + request.addQueryParam( + "Date", + DateConverter.dateStringFromLocalDate(date) + ); } - } } diff --git a/src/main/java/com/twilio/rest/messaging/v1/DomainCerts.java b/src/main/java/com/twilio/rest/messaging/v1/DomainCerts.java index d7adebd683..296d96060b 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/DomainCerts.java +++ b/src/main/java/com/twilio/rest/messaging/v1/DomainCerts.java @@ -23,47 +23,49 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class DomainCerts extends Resource { + private static final long serialVersionUID = 200335100401859L; - public static DomainCertsDeleter deleter(final String pathDomainSid){ + public static DomainCertsDeleter deleter(final String pathDomainSid) { return new DomainCertsDeleter(pathDomainSid); } - public static DomainCertsFetcher fetcher(final String pathDomainSid){ + public static DomainCertsFetcher fetcher(final String pathDomainSid) { return new DomainCertsFetcher(pathDomainSid); } - public static DomainCertsUpdater updater(final String pathDomainSid, final String tlsCert){ + public static DomainCertsUpdater updater( + final String pathDomainSid, + final String tlsCert + ) { return new DomainCertsUpdater(pathDomainSid, tlsCert); } /** - * Converts a JSON String into a DomainCerts object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return DomainCerts object represented by the provided JSON - */ - public static DomainCerts fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a DomainCerts object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return DomainCerts object represented by the provided JSON + */ + public static DomainCerts fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, DomainCerts.class); @@ -75,14 +77,17 @@ public static DomainCerts fromJson(final String json, final ObjectMapper objectM } /** - * Converts a JSON InputStream into a DomainCerts object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return DomainCerts object represented by the provided JSON - */ - public static DomainCerts fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a DomainCerts object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return DomainCerts object represented by the provided JSON + */ + public static DomainCerts fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, DomainCerts.class); @@ -104,29 +109,16 @@ public static DomainCerts fromJson(final InputStream json, final ObjectMapper ob @JsonCreator private DomainCerts( - @JsonProperty("domain_sid") - final String domainSid, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("date_expires") - final String dateExpires, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("domain_name") - final URI domainName, - - @JsonProperty("certificate_sid") - final String certificateSid, - - @JsonProperty("url") - final URI url, - - @JsonProperty("cert_in_validation") - final Map certInValidation + @JsonProperty("domain_sid") final String domainSid, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("date_expires") final String dateExpires, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("domain_name") final URI domainName, + @JsonProperty("certificate_sid") final String certificateSid, + @JsonProperty("url") final URI url, + @JsonProperty( + "cert_in_validation" + ) final Map certInValidation ) { this.domainSid = domainSid; this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); @@ -138,34 +130,41 @@ private DomainCerts( this.certInValidation = certInValidation; } - public final String getDomainSid() { - return this.domainSid; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final ZonedDateTime getDateExpires() { - return this.dateExpires; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final URI getDomainName() { - return this.domainName; - } - public final String getCertificateSid() { - return this.certificateSid; - } - public final URI getUrl() { - return this.url; - } - public final Map getCertInValidation() { - return this.certInValidation; - } + public final String getDomainSid() { + return this.domainSid; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final ZonedDateTime getDateExpires() { + return this.dateExpires; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final URI getDomainName() { + return this.domainName; + } + + public final String getCertificateSid() { + return this.certificateSid; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getCertInValidation() { + return this.certInValidation; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -175,13 +174,29 @@ public boolean equals(final Object o) { DomainCerts other = (DomainCerts) o; - return Objects.equals(domainSid, other.domainSid) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(dateExpires, other.dateExpires) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(domainName, other.domainName) && Objects.equals(certificateSid, other.certificateSid) && Objects.equals(url, other.url) && Objects.equals(certInValidation, other.certInValidation) ; + return ( + Objects.equals(domainSid, other.domainSid) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(dateExpires, other.dateExpires) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(domainName, other.domainName) && + Objects.equals(certificateSid, other.certificateSid) && + Objects.equals(url, other.url) && + Objects.equals(certInValidation, other.certInValidation) + ); } @Override public int hashCode() { - return Objects.hash(domainSid, dateUpdated, dateExpires, dateCreated, domainName, certificateSid, url, certInValidation); + return Objects.hash( + domainSid, + dateUpdated, + dateExpires, + dateCreated, + domainName, + certificateSid, + url, + certInValidation + ); } - } - diff --git a/src/main/java/com/twilio/rest/messaging/v1/DomainCertsDeleter.java b/src/main/java/com/twilio/rest/messaging/v1/DomainCertsDeleter.java index d8a587360d..4467cff710 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/DomainCertsDeleter.java +++ b/src/main/java/com/twilio/rest/messaging/v1/DomainCertsDeleter.java @@ -24,21 +24,23 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class DomainCertsDeleter extends Deleter { + private String pathDomainSid; - public DomainCertsDeleter(final String pathDomainSid){ + public DomainCertsDeleter(final String pathDomainSid) { this.pathDomainSid = pathDomainSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/LinkShortening/Domains/{DomainSid}/Certificate"; - path = path.replace("{"+"DomainSid"+"}", this.pathDomainSid.toString()); + path = + path.replace( + "{" + "DomainSid" + "}", + this.pathDomainSid.toString() + ); Request request = new Request( HttpMethod.DELETE, @@ -48,9 +50,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("DomainCerts delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "DomainCerts delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/messaging/v1/DomainCertsFetcher.java b/src/main/java/com/twilio/rest/messaging/v1/DomainCertsFetcher.java index 89794f2056..18895b4735 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/DomainCertsFetcher.java +++ b/src/main/java/com/twilio/rest/messaging/v1/DomainCertsFetcher.java @@ -24,22 +24,23 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class DomainCertsFetcher extends Fetcher { + private String pathDomainSid; - public DomainCertsFetcher(final String pathDomainSid){ + public DomainCertsFetcher(final String pathDomainSid) { this.pathDomainSid = pathDomainSid; } - @Override public DomainCerts fetch(final TwilioRestClient client) { String path = "/v1/LinkShortening/Domains/{DomainSid}/Certificate"; - path = path.replace("{"+"DomainSid"+"}", this.pathDomainSid.toString()); + path = + path.replace( + "{" + "DomainSid" + "}", + this.pathDomainSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -49,15 +50,23 @@ public DomainCerts fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("DomainCerts fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "DomainCerts fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return DomainCerts.fromJson(response.getStream(), client.getObjectMapper()); + return DomainCerts.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/messaging/v1/DomainCertsUpdater.java b/src/main/java/com/twilio/rest/messaging/v1/DomainCertsUpdater.java index 1db44b1488..61777e8503 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/DomainCertsUpdater.java +++ b/src/main/java/com/twilio/rest/messaging/v1/DomainCertsUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.messaging.v1; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,53 +25,67 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class DomainCertsUpdater extends Updater { - - -public class DomainCertsUpdater extends Updater{ private String pathDomainSid; private String tlsCert; - public DomainCertsUpdater(final String pathDomainSid, final String tlsCert){ + public DomainCertsUpdater( + final String pathDomainSid, + final String tlsCert + ) { this.pathDomainSid = pathDomainSid; this.tlsCert = tlsCert; } - public DomainCertsUpdater setTlsCert(final String tlsCert){ + public DomainCertsUpdater setTlsCert(final String tlsCert) { this.tlsCert = tlsCert; return this; } @Override - public DomainCerts update(final TwilioRestClient client){ + public DomainCerts update(final TwilioRestClient client) { String path = "/v1/LinkShortening/Domains/{DomainSid}/Certificate"; - path = path.replace("{"+"DomainSid"+"}", this.pathDomainSid.toString()); - path = path.replace("{"+"TlsCert"+"}", this.tlsCert.toString()); + path = + path.replace( + "{" + "DomainSid" + "}", + this.pathDomainSid.toString() + ); + path = path.replace("{" + "TlsCert" + "}", this.tlsCert.toString()); Request request = new Request( HttpMethod.POST, Domains.MESSAGING.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("DomainCerts update failed: Unable to connect to server"); + throw new ApiConnectionException( + "DomainCerts update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return DomainCerts.fromJson(response.getStream(), client.getObjectMapper()); + return DomainCerts.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (tlsCert != null) { request.addPostParam("TlsCert", tlsCert); - } } } diff --git a/src/main/java/com/twilio/rest/messaging/v1/DomainConfig.java b/src/main/java/com/twilio/rest/messaging/v1/DomainConfig.java index 0322a97614..e9243efa90 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/DomainConfig.java +++ b/src/main/java/com/twilio/rest/messaging/v1/DomainConfig.java @@ -23,41 +23,40 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class DomainConfig extends Resource { + private static final long serialVersionUID = 278004827100918L; - public static DomainConfigFetcher fetcher(final String pathDomainSid){ + public static DomainConfigFetcher fetcher(final String pathDomainSid) { return new DomainConfigFetcher(pathDomainSid); } - public static DomainConfigUpdater updater(final String pathDomainSid){ + public static DomainConfigUpdater updater(final String pathDomainSid) { return new DomainConfigUpdater(pathDomainSid); } /** - * Converts a JSON String into a DomainConfig object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return DomainConfig object represented by the provided JSON - */ - public static DomainConfig fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a DomainConfig object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return DomainConfig object represented by the provided JSON + */ + public static DomainConfig fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, DomainConfig.class); @@ -69,14 +68,17 @@ public static DomainConfig fromJson(final String json, final ObjectMapper object } /** - * Converts a JSON InputStream into a DomainConfig object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return DomainConfig object represented by the provided JSON - */ - public static DomainConfig fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a DomainConfig object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return DomainConfig object represented by the provided JSON + */ + public static DomainConfig fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, DomainConfig.class); @@ -99,32 +101,15 @@ public static DomainConfig fromJson(final InputStream json, final ObjectMapper o @JsonCreator private DomainConfig( - @JsonProperty("domain_sid") - final String domainSid, - - @JsonProperty("config_sid") - final String configSid, - - @JsonProperty("fallback_url") - final URI fallbackUrl, - - @JsonProperty("callback_url") - final URI callbackUrl, - - @JsonProperty("continue_on_failure") - final Boolean continueOnFailure, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url, - - @JsonProperty("disable_https") - final Boolean disableHttps + @JsonProperty("domain_sid") final String domainSid, + @JsonProperty("config_sid") final String configSid, + @JsonProperty("fallback_url") final URI fallbackUrl, + @JsonProperty("callback_url") final URI callbackUrl, + @JsonProperty("continue_on_failure") final Boolean continueOnFailure, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url, + @JsonProperty("disable_https") final Boolean disableHttps ) { this.domainSid = domainSid; this.configSid = configSid; @@ -137,37 +122,45 @@ private DomainConfig( this.disableHttps = disableHttps; } - public final String getDomainSid() { - return this.domainSid; - } - public final String getConfigSid() { - return this.configSid; - } - public final URI getFallbackUrl() { - return this.fallbackUrl; - } - public final URI getCallbackUrl() { - return this.callbackUrl; - } - public final Boolean getContinueOnFailure() { - return this.continueOnFailure; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } - public final Boolean getDisableHttps() { - return this.disableHttps; - } + public final String getDomainSid() { + return this.domainSid; + } + + public final String getConfigSid() { + return this.configSid; + } + + public final URI getFallbackUrl() { + return this.fallbackUrl; + } + + public final URI getCallbackUrl() { + return this.callbackUrl; + } + + public final Boolean getContinueOnFailure() { + return this.continueOnFailure; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } + + public final Boolean getDisableHttps() { + return this.disableHttps; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -177,13 +170,31 @@ public boolean equals(final Object o) { DomainConfig other = (DomainConfig) o; - return Objects.equals(domainSid, other.domainSid) && Objects.equals(configSid, other.configSid) && Objects.equals(fallbackUrl, other.fallbackUrl) && Objects.equals(callbackUrl, other.callbackUrl) && Objects.equals(continueOnFailure, other.continueOnFailure) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) && Objects.equals(disableHttps, other.disableHttps) ; + return ( + Objects.equals(domainSid, other.domainSid) && + Objects.equals(configSid, other.configSid) && + Objects.equals(fallbackUrl, other.fallbackUrl) && + Objects.equals(callbackUrl, other.callbackUrl) && + Objects.equals(continueOnFailure, other.continueOnFailure) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) && + Objects.equals(disableHttps, other.disableHttps) + ); } @Override public int hashCode() { - return Objects.hash(domainSid, configSid, fallbackUrl, callbackUrl, continueOnFailure, dateCreated, dateUpdated, url, disableHttps); + return Objects.hash( + domainSid, + configSid, + fallbackUrl, + callbackUrl, + continueOnFailure, + dateCreated, + dateUpdated, + url, + disableHttps + ); } - } - diff --git a/src/main/java/com/twilio/rest/messaging/v1/DomainConfigFetcher.java b/src/main/java/com/twilio/rest/messaging/v1/DomainConfigFetcher.java index 73f17e19a1..90ef86f36f 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/DomainConfigFetcher.java +++ b/src/main/java/com/twilio/rest/messaging/v1/DomainConfigFetcher.java @@ -24,22 +24,23 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class DomainConfigFetcher extends Fetcher { + private String pathDomainSid; - public DomainConfigFetcher(final String pathDomainSid){ + public DomainConfigFetcher(final String pathDomainSid) { this.pathDomainSid = pathDomainSid; } - @Override public DomainConfig fetch(final TwilioRestClient client) { String path = "/v1/LinkShortening/Domains/{DomainSid}/Config"; - path = path.replace("{"+"DomainSid"+"}", this.pathDomainSid.toString()); + path = + path.replace( + "{" + "DomainSid" + "}", + this.pathDomainSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -49,15 +50,23 @@ public DomainConfig fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("DomainConfig fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "DomainConfig fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return DomainConfig.fromJson(response.getStream(), client.getObjectMapper()); + return DomainConfig.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/messaging/v1/DomainConfigMessagingService.java b/src/main/java/com/twilio/rest/messaging/v1/DomainConfigMessagingService.java index 1120a1e782..0fd4766e6a 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/DomainConfigMessagingService.java +++ b/src/main/java/com/twilio/rest/messaging/v1/DomainConfigMessagingService.java @@ -23,40 +23,44 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class DomainConfigMessagingService extends Resource { + private static final long serialVersionUID = 37164874125386L; - public static DomainConfigMessagingServiceFetcher fetcher(final String pathMessagingServiceSid){ + public static DomainConfigMessagingServiceFetcher fetcher( + final String pathMessagingServiceSid + ) { return new DomainConfigMessagingServiceFetcher(pathMessagingServiceSid); } /** - * Converts a JSON String into a DomainConfigMessagingService object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return DomainConfigMessagingService object represented by the provided JSON - */ - public static DomainConfigMessagingService fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a DomainConfigMessagingService object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return DomainConfigMessagingService object represented by the provided JSON + */ + public static DomainConfigMessagingService fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, DomainConfigMessagingService.class); + return objectMapper.readValue( + json, + DomainConfigMessagingService.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -65,17 +69,23 @@ public static DomainConfigMessagingService fromJson(final String json, final Obj } /** - * Converts a JSON InputStream into a DomainConfigMessagingService object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return DomainConfigMessagingService object represented by the provided JSON - */ - public static DomainConfigMessagingService fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a DomainConfigMessagingService object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return DomainConfigMessagingService object represented by the provided JSON + */ + public static DomainConfigMessagingService fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, DomainConfigMessagingService.class); + return objectMapper.readValue( + json, + DomainConfigMessagingService.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -95,32 +105,15 @@ public static DomainConfigMessagingService fromJson(final InputStream json, fina @JsonCreator private DomainConfigMessagingService( - @JsonProperty("domain_sid") - final String domainSid, - - @JsonProperty("config_sid") - final String configSid, - - @JsonProperty("messaging_service_sid") - final String messagingServiceSid, - - @JsonProperty("fallback_url") - final URI fallbackUrl, - - @JsonProperty("callback_url") - final URI callbackUrl, - - @JsonProperty("continue_on_failure") - final Boolean continueOnFailure, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url + @JsonProperty("domain_sid") final String domainSid, + @JsonProperty("config_sid") final String configSid, + @JsonProperty("messaging_service_sid") final String messagingServiceSid, + @JsonProperty("fallback_url") final URI fallbackUrl, + @JsonProperty("callback_url") final URI callbackUrl, + @JsonProperty("continue_on_failure") final Boolean continueOnFailure, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url ) { this.domainSid = domainSid; this.configSid = configSid; @@ -133,37 +126,45 @@ private DomainConfigMessagingService( this.url = url; } - public final String getDomainSid() { - return this.domainSid; - } - public final String getConfigSid() { - return this.configSid; - } - public final String getMessagingServiceSid() { - return this.messagingServiceSid; - } - public final URI getFallbackUrl() { - return this.fallbackUrl; - } - public final URI getCallbackUrl() { - return this.callbackUrl; - } - public final Boolean getContinueOnFailure() { - return this.continueOnFailure; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } + public final String getDomainSid() { + return this.domainSid; + } + + public final String getConfigSid() { + return this.configSid; + } + + public final String getMessagingServiceSid() { + return this.messagingServiceSid; + } + + public final URI getFallbackUrl() { + return this.fallbackUrl; + } + + public final URI getCallbackUrl() { + return this.callbackUrl; + } + + public final Boolean getContinueOnFailure() { + return this.continueOnFailure; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -173,13 +174,31 @@ public boolean equals(final Object o) { DomainConfigMessagingService other = (DomainConfigMessagingService) o; - return Objects.equals(domainSid, other.domainSid) && Objects.equals(configSid, other.configSid) && Objects.equals(messagingServiceSid, other.messagingServiceSid) && Objects.equals(fallbackUrl, other.fallbackUrl) && Objects.equals(callbackUrl, other.callbackUrl) && Objects.equals(continueOnFailure, other.continueOnFailure) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) ; + return ( + Objects.equals(domainSid, other.domainSid) && + Objects.equals(configSid, other.configSid) && + Objects.equals(messagingServiceSid, other.messagingServiceSid) && + Objects.equals(fallbackUrl, other.fallbackUrl) && + Objects.equals(callbackUrl, other.callbackUrl) && + Objects.equals(continueOnFailure, other.continueOnFailure) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(domainSid, configSid, messagingServiceSid, fallbackUrl, callbackUrl, continueOnFailure, dateCreated, dateUpdated, url); + return Objects.hash( + domainSid, + configSid, + messagingServiceSid, + fallbackUrl, + callbackUrl, + continueOnFailure, + dateCreated, + dateUpdated, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/messaging/v1/DomainConfigMessagingServiceFetcher.java b/src/main/java/com/twilio/rest/messaging/v1/DomainConfigMessagingServiceFetcher.java index 19ff984a8d..ea6baf07c5 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/DomainConfigMessagingServiceFetcher.java +++ b/src/main/java/com/twilio/rest/messaging/v1/DomainConfigMessagingServiceFetcher.java @@ -24,22 +24,27 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class DomainConfigMessagingServiceFetcher + extends Fetcher { - - -public class DomainConfigMessagingServiceFetcher extends Fetcher { private String pathMessagingServiceSid; - public DomainConfigMessagingServiceFetcher(final String pathMessagingServiceSid){ + public DomainConfigMessagingServiceFetcher( + final String pathMessagingServiceSid + ) { this.pathMessagingServiceSid = pathMessagingServiceSid; } - @Override public DomainConfigMessagingService fetch(final TwilioRestClient client) { - String path = "/v1/LinkShortening/MessagingService/{MessagingServiceSid}/DomainConfig"; + String path = + "/v1/LinkShortening/MessagingService/{MessagingServiceSid}/DomainConfig"; - path = path.replace("{"+"MessagingServiceSid"+"}", this.pathMessagingServiceSid.toString()); + path = + path.replace( + "{" + "MessagingServiceSid" + "}", + this.pathMessagingServiceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -49,15 +54,23 @@ public DomainConfigMessagingService fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("DomainConfigMessagingService fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "DomainConfigMessagingService fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return DomainConfigMessagingService.fromJson(response.getStream(), client.getObjectMapper()); + return DomainConfigMessagingService.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/messaging/v1/DomainConfigUpdater.java b/src/main/java/com/twilio/rest/messaging/v1/DomainConfigUpdater.java index b241a66134..f135754943 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/DomainConfigUpdater.java +++ b/src/main/java/com/twilio/rest/messaging/v1/DomainConfigUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.messaging.v1; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -24,88 +25,104 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.net.URI; +public class DomainConfigUpdater extends Updater { - -public class DomainConfigUpdater extends Updater{ private String pathDomainSid; private URI fallbackUrl; private URI callbackUrl; private Boolean continueOnFailure; private Boolean disableHttps; - public DomainConfigUpdater(final String pathDomainSid){ + public DomainConfigUpdater(final String pathDomainSid) { this.pathDomainSid = pathDomainSid; } - public DomainConfigUpdater setFallbackUrl(final URI fallbackUrl){ + public DomainConfigUpdater setFallbackUrl(final URI fallbackUrl) { this.fallbackUrl = fallbackUrl; return this; } - public DomainConfigUpdater setFallbackUrl(final String fallbackUrl){ + public DomainConfigUpdater setFallbackUrl(final String fallbackUrl) { return setFallbackUrl(Promoter.uriFromString(fallbackUrl)); } - public DomainConfigUpdater setCallbackUrl(final URI callbackUrl){ + + public DomainConfigUpdater setCallbackUrl(final URI callbackUrl) { this.callbackUrl = callbackUrl; return this; } - public DomainConfigUpdater setCallbackUrl(final String callbackUrl){ + public DomainConfigUpdater setCallbackUrl(final String callbackUrl) { return setCallbackUrl(Promoter.uriFromString(callbackUrl)); } - public DomainConfigUpdater setContinueOnFailure(final Boolean continueOnFailure){ + + public DomainConfigUpdater setContinueOnFailure( + final Boolean continueOnFailure + ) { this.continueOnFailure = continueOnFailure; return this; } - public DomainConfigUpdater setDisableHttps(final Boolean disableHttps){ + + public DomainConfigUpdater setDisableHttps(final Boolean disableHttps) { this.disableHttps = disableHttps; return this; } @Override - public DomainConfig update(final TwilioRestClient client){ + public DomainConfig update(final TwilioRestClient client) { String path = "/v1/LinkShortening/Domains/{DomainSid}/Config"; - path = path.replace("{"+"DomainSid"+"}", this.pathDomainSid.toString()); + path = + path.replace( + "{" + "DomainSid" + "}", + this.pathDomainSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.MESSAGING.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("DomainConfig update failed: Unable to connect to server"); + throw new ApiConnectionException( + "DomainConfig update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return DomainConfig.fromJson(response.getStream(), client.getObjectMapper()); + return DomainConfig.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (fallbackUrl != null) { request.addPostParam("FallbackUrl", fallbackUrl.toString()); - } if (callbackUrl != null) { request.addPostParam("CallbackUrl", callbackUrl.toString()); - } if (continueOnFailure != null) { - request.addPostParam("ContinueOnFailure", continueOnFailure.toString()); - + request.addPostParam( + "ContinueOnFailure", + continueOnFailure.toString() + ); } if (disableHttps != null) { request.addPostParam("DisableHttps", disableHttps.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/messaging/v1/ExternalCampaign.java b/src/main/java/com/twilio/rest/messaging/v1/ExternalCampaign.java index 6b1d1d0bcc..f892c314da 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/ExternalCampaign.java +++ b/src/main/java/com/twilio/rest/messaging/v1/ExternalCampaign.java @@ -23,36 +23,38 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class ExternalCampaign extends Resource { + private static final long serialVersionUID = 211920409391157L; - public static ExternalCampaignCreator creator(final String campaignId, final String messagingServiceSid){ + public static ExternalCampaignCreator creator( + final String campaignId, + final String messagingServiceSid + ) { return new ExternalCampaignCreator(campaignId, messagingServiceSid); } /** - * Converts a JSON String into a ExternalCampaign object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return ExternalCampaign object represented by the provided JSON - */ - public static ExternalCampaign fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a ExternalCampaign object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return ExternalCampaign object represented by the provided JSON + */ + public static ExternalCampaign fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, ExternalCampaign.class); @@ -64,14 +66,17 @@ public static ExternalCampaign fromJson(final String json, final ObjectMapper ob } /** - * Converts a JSON InputStream into a ExternalCampaign object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return ExternalCampaign object represented by the provided JSON - */ - public static ExternalCampaign fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a ExternalCampaign object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return ExternalCampaign object represented by the provided JSON + */ + public static ExternalCampaign fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, ExternalCampaign.class); @@ -90,20 +95,11 @@ public static ExternalCampaign fromJson(final InputStream json, final ObjectMapp @JsonCreator private ExternalCampaign( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("campaign_id") - final String campaignId, - - @JsonProperty("messaging_service_sid") - final String messagingServiceSid, - - @JsonProperty("date_created") - final String dateCreated + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("campaign_id") final String campaignId, + @JsonProperty("messaging_service_sid") final String messagingServiceSid, + @JsonProperty("date_created") final String dateCreated ) { this.sid = sid; this.accountSid = accountSid; @@ -112,25 +108,29 @@ private ExternalCampaign( this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getCampaignId() { - return this.campaignId; - } - public final String getMessagingServiceSid() { - return this.messagingServiceSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getCampaignId() { + return this.campaignId; + } + + public final String getMessagingServiceSid() { + return this.messagingServiceSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -140,13 +140,23 @@ public boolean equals(final Object o) { ExternalCampaign other = (ExternalCampaign) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(campaignId, other.campaignId) && Objects.equals(messagingServiceSid, other.messagingServiceSid) && Objects.equals(dateCreated, other.dateCreated) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(campaignId, other.campaignId) && + Objects.equals(messagingServiceSid, other.messagingServiceSid) && + Objects.equals(dateCreated, other.dateCreated) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, campaignId, messagingServiceSid, dateCreated); + return Objects.hash( + sid, + accountSid, + campaignId, + messagingServiceSid, + dateCreated + ); } - } - diff --git a/src/main/java/com/twilio/rest/messaging/v1/ExternalCampaignCreator.java b/src/main/java/com/twilio/rest/messaging/v1/ExternalCampaignCreator.java index 9ce0d08886..69a502e6bb 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/ExternalCampaignCreator.java +++ b/src/main/java/com/twilio/rest/messaging/v1/ExternalCampaignCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.messaging.v1; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,61 +25,78 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class ExternalCampaignCreator extends Creator { - - -public class ExternalCampaignCreator extends Creator{ private String campaignId; private String messagingServiceSid; - public ExternalCampaignCreator(final String campaignId, final String messagingServiceSid) { + public ExternalCampaignCreator( + final String campaignId, + final String messagingServiceSid + ) { this.campaignId = campaignId; this.messagingServiceSid = messagingServiceSid; } - public ExternalCampaignCreator setCampaignId(final String campaignId){ + public ExternalCampaignCreator setCampaignId(final String campaignId) { this.campaignId = campaignId; return this; } - public ExternalCampaignCreator setMessagingServiceSid(final String messagingServiceSid){ + + public ExternalCampaignCreator setMessagingServiceSid( + final String messagingServiceSid + ) { this.messagingServiceSid = messagingServiceSid; return this; } @Override - public ExternalCampaign create(final TwilioRestClient client){ + public ExternalCampaign create(final TwilioRestClient client) { String path = "/v1/Services/PreregisteredUsa2p"; - path = path.replace("{"+"CampaignId"+"}", this.campaignId.toString()); - path = path.replace("{"+"MessagingServiceSid"+"}", this.messagingServiceSid.toString()); + path = + path.replace("{" + "CampaignId" + "}", this.campaignId.toString()); + path = + path.replace( + "{" + "MessagingServiceSid" + "}", + this.messagingServiceSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.MESSAGING.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("ExternalCampaign creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "ExternalCampaign creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return ExternalCampaign.fromJson(response.getStream(), client.getObjectMapper()); + return ExternalCampaign.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (campaignId != null) { request.addPostParam("CampaignId", campaignId); - } if (messagingServiceSid != null) { request.addPostParam("MessagingServiceSid", messagingServiceSid); - } } } diff --git a/src/main/java/com/twilio/rest/messaging/v1/LinkshorteningMessagingService.java b/src/main/java/com/twilio/rest/messaging/v1/LinkshorteningMessagingService.java index 84dc27c0e3..1193f3f6f1 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/LinkshorteningMessagingService.java +++ b/src/main/java/com/twilio/rest/messaging/v1/LinkshorteningMessagingService.java @@ -22,43 +22,57 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class LinkshorteningMessagingService extends Resource { + private static final long serialVersionUID = 242981332247911L; - public static LinkshorteningMessagingServiceCreator creator(final String pathDomainSid, final String pathMessagingServiceSid){ - return new LinkshorteningMessagingServiceCreator(pathDomainSid, pathMessagingServiceSid); + public static LinkshorteningMessagingServiceCreator creator( + final String pathDomainSid, + final String pathMessagingServiceSid + ) { + return new LinkshorteningMessagingServiceCreator( + pathDomainSid, + pathMessagingServiceSid + ); } - public static LinkshorteningMessagingServiceDeleter deleter(final String pathDomainSid, final String pathMessagingServiceSid){ - return new LinkshorteningMessagingServiceDeleter(pathDomainSid, pathMessagingServiceSid); + public static LinkshorteningMessagingServiceDeleter deleter( + final String pathDomainSid, + final String pathMessagingServiceSid + ) { + return new LinkshorteningMessagingServiceDeleter( + pathDomainSid, + pathMessagingServiceSid + ); } /** - * Converts a JSON String into a LinkshorteningMessagingService object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return LinkshorteningMessagingService object represented by the provided JSON - */ - public static LinkshorteningMessagingService fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a LinkshorteningMessagingService object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return LinkshorteningMessagingService object represented by the provided JSON + */ + public static LinkshorteningMessagingService fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, LinkshorteningMessagingService.class); + return objectMapper.readValue( + json, + LinkshorteningMessagingService.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -67,17 +81,23 @@ public static LinkshorteningMessagingService fromJson(final String json, final O } /** - * Converts a JSON InputStream into a LinkshorteningMessagingService object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return LinkshorteningMessagingService object represented by the provided JSON - */ - public static LinkshorteningMessagingService fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a LinkshorteningMessagingService object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return LinkshorteningMessagingService object represented by the provided JSON + */ + public static LinkshorteningMessagingService fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, LinkshorteningMessagingService.class); + return objectMapper.readValue( + json, + LinkshorteningMessagingService.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -91,33 +111,30 @@ public static LinkshorteningMessagingService fromJson(final InputStream json, fi @JsonCreator private LinkshorteningMessagingService( - @JsonProperty("domain_sid") - final String domainSid, - - @JsonProperty("messaging_service_sid") - final String messagingServiceSid, - - @JsonProperty("url") - final URI url + @JsonProperty("domain_sid") final String domainSid, + @JsonProperty("messaging_service_sid") final String messagingServiceSid, + @JsonProperty("url") final URI url ) { this.domainSid = domainSid; this.messagingServiceSid = messagingServiceSid; this.url = url; } - public final String getDomainSid() { - return this.domainSid; - } - public final String getMessagingServiceSid() { - return this.messagingServiceSid; - } - public final URI getUrl() { - return this.url; - } + public final String getDomainSid() { + return this.domainSid; + } + + public final String getMessagingServiceSid() { + return this.messagingServiceSid; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -125,15 +142,18 @@ public boolean equals(final Object o) { return false; } - LinkshorteningMessagingService other = (LinkshorteningMessagingService) o; + LinkshorteningMessagingService other = + (LinkshorteningMessagingService) o; - return Objects.equals(domainSid, other.domainSid) && Objects.equals(messagingServiceSid, other.messagingServiceSid) && Objects.equals(url, other.url) ; + return ( + Objects.equals(domainSid, other.domainSid) && + Objects.equals(messagingServiceSid, other.messagingServiceSid) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { return Objects.hash(domainSid, messagingServiceSid, url); } - } - diff --git a/src/main/java/com/twilio/rest/messaging/v1/LinkshorteningMessagingServiceCreator.java b/src/main/java/com/twilio/rest/messaging/v1/LinkshorteningMessagingServiceCreator.java index 99bd087382..00401d8c3b 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/LinkshorteningMessagingServiceCreator.java +++ b/src/main/java/com/twilio/rest/messaging/v1/LinkshorteningMessagingServiceCreator.java @@ -24,25 +24,37 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class LinkshorteningMessagingServiceCreator + extends Creator { - - -public class LinkshorteningMessagingServiceCreator extends Creator{ private String pathDomainSid; private String pathMessagingServiceSid; - public LinkshorteningMessagingServiceCreator(final String pathDomainSid, final String pathMessagingServiceSid) { + public LinkshorteningMessagingServiceCreator( + final String pathDomainSid, + final String pathMessagingServiceSid + ) { this.pathDomainSid = pathDomainSid; this.pathMessagingServiceSid = pathMessagingServiceSid; } - @Override - public LinkshorteningMessagingService create(final TwilioRestClient client){ - String path = "/v1/LinkShortening/Domains/{DomainSid}/MessagingServices/{MessagingServiceSid}"; + public LinkshorteningMessagingService create( + final TwilioRestClient client + ) { + String path = + "/v1/LinkShortening/Domains/{DomainSid}/MessagingServices/{MessagingServiceSid}"; - path = path.replace("{"+"DomainSid"+"}", this.pathDomainSid.toString()); - path = path.replace("{"+"MessagingServiceSid"+"}", this.pathMessagingServiceSid.toString()); + path = + path.replace( + "{" + "DomainSid" + "}", + this.pathDomainSid.toString() + ); + path = + path.replace( + "{" + "MessagingServiceSid" + "}", + this.pathMessagingServiceSid.toString() + ); Request request = new Request( HttpMethod.POST, @@ -51,15 +63,23 @@ public LinkshorteningMessagingService create(final TwilioRestClient client){ ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("LinkshorteningMessagingService creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "LinkshorteningMessagingService creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return LinkshorteningMessagingService.fromJson(response.getStream(), client.getObjectMapper()); + return LinkshorteningMessagingService.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/messaging/v1/LinkshorteningMessagingServiceDeleter.java b/src/main/java/com/twilio/rest/messaging/v1/LinkshorteningMessagingServiceDeleter.java index 44cffa06d1..5ba05b6d71 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/LinkshorteningMessagingServiceDeleter.java +++ b/src/main/java/com/twilio/rest/messaging/v1/LinkshorteningMessagingServiceDeleter.java @@ -24,24 +24,35 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class LinkshorteningMessagingServiceDeleter + extends Deleter { - -public class LinkshorteningMessagingServiceDeleter extends Deleter { private String pathDomainSid; private String pathMessagingServiceSid; - public LinkshorteningMessagingServiceDeleter(final String pathDomainSid, final String pathMessagingServiceSid){ + public LinkshorteningMessagingServiceDeleter( + final String pathDomainSid, + final String pathMessagingServiceSid + ) { this.pathDomainSid = pathDomainSid; this.pathMessagingServiceSid = pathMessagingServiceSid; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/v1/LinkShortening/Domains/{DomainSid}/MessagingServices/{MessagingServiceSid}"; + String path = + "/v1/LinkShortening/Domains/{DomainSid}/MessagingServices/{MessagingServiceSid}"; - path = path.replace("{"+"DomainSid"+"}", this.pathDomainSid.toString()); - path = path.replace("{"+"MessagingServiceSid"+"}", this.pathMessagingServiceSid.toString()); + path = + path.replace( + "{" + "DomainSid" + "}", + this.pathDomainSid.toString() + ); + path = + path.replace( + "{" + "MessagingServiceSid" + "}", + this.pathMessagingServiceSid.toString() + ); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +62,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("LinkshorteningMessagingService delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "LinkshorteningMessagingService delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/messaging/v1/LinkshorteningMessagingServiceDomainAssociation.java b/src/main/java/com/twilio/rest/messaging/v1/LinkshorteningMessagingServiceDomainAssociation.java index fd8d9cd5cc..a187053131 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/LinkshorteningMessagingServiceDomainAssociation.java +++ b/src/main/java/com/twilio/rest/messaging/v1/LinkshorteningMessagingServiceDomainAssociation.java @@ -22,39 +22,45 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class LinkshorteningMessagingServiceDomainAssociation extends Resource { + private static final long serialVersionUID = 242981332247911L; - public static LinkshorteningMessagingServiceDomainAssociationFetcher fetcher(final String pathMessagingServiceSid){ - return new LinkshorteningMessagingServiceDomainAssociationFetcher(pathMessagingServiceSid); + public static LinkshorteningMessagingServiceDomainAssociationFetcher fetcher( + final String pathMessagingServiceSid + ) { + return new LinkshorteningMessagingServiceDomainAssociationFetcher( + pathMessagingServiceSid + ); } /** - * Converts a JSON String into a LinkshorteningMessagingServiceDomainAssociation object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return LinkshorteningMessagingServiceDomainAssociation object represented by the provided JSON - */ - public static LinkshorteningMessagingServiceDomainAssociation fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a LinkshorteningMessagingServiceDomainAssociation object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return LinkshorteningMessagingServiceDomainAssociation object represented by the provided JSON + */ + public static LinkshorteningMessagingServiceDomainAssociation fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, LinkshorteningMessagingServiceDomainAssociation.class); + return objectMapper.readValue( + json, + LinkshorteningMessagingServiceDomainAssociation.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -63,17 +69,23 @@ public static LinkshorteningMessagingServiceDomainAssociation fromJson(final Str } /** - * Converts a JSON InputStream into a LinkshorteningMessagingServiceDomainAssociation object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return LinkshorteningMessagingServiceDomainAssociation object represented by the provided JSON - */ - public static LinkshorteningMessagingServiceDomainAssociation fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a LinkshorteningMessagingServiceDomainAssociation object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return LinkshorteningMessagingServiceDomainAssociation object represented by the provided JSON + */ + public static LinkshorteningMessagingServiceDomainAssociation fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, LinkshorteningMessagingServiceDomainAssociation.class); + return objectMapper.readValue( + json, + LinkshorteningMessagingServiceDomainAssociation.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -87,33 +99,30 @@ public static LinkshorteningMessagingServiceDomainAssociation fromJson(final Inp @JsonCreator private LinkshorteningMessagingServiceDomainAssociation( - @JsonProperty("domain_sid") - final String domainSid, - - @JsonProperty("messaging_service_sid") - final String messagingServiceSid, - - @JsonProperty("url") - final URI url + @JsonProperty("domain_sid") final String domainSid, + @JsonProperty("messaging_service_sid") final String messagingServiceSid, + @JsonProperty("url") final URI url ) { this.domainSid = domainSid; this.messagingServiceSid = messagingServiceSid; this.url = url; } - public final String getDomainSid() { - return this.domainSid; - } - public final String getMessagingServiceSid() { - return this.messagingServiceSid; - } - public final URI getUrl() { - return this.url; - } + public final String getDomainSid() { + return this.domainSid; + } + + public final String getMessagingServiceSid() { + return this.messagingServiceSid; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -121,15 +130,18 @@ public boolean equals(final Object o) { return false; } - LinkshorteningMessagingServiceDomainAssociation other = (LinkshorteningMessagingServiceDomainAssociation) o; + LinkshorteningMessagingServiceDomainAssociation other = + (LinkshorteningMessagingServiceDomainAssociation) o; - return Objects.equals(domainSid, other.domainSid) && Objects.equals(messagingServiceSid, other.messagingServiceSid) && Objects.equals(url, other.url) ; + return ( + Objects.equals(domainSid, other.domainSid) && + Objects.equals(messagingServiceSid, other.messagingServiceSid) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { return Objects.hash(domainSid, messagingServiceSid, url); } - } - diff --git a/src/main/java/com/twilio/rest/messaging/v1/LinkshorteningMessagingServiceDomainAssociationFetcher.java b/src/main/java/com/twilio/rest/messaging/v1/LinkshorteningMessagingServiceDomainAssociationFetcher.java index 2bd434ab5c..dc23f1a51f 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/LinkshorteningMessagingServiceDomainAssociationFetcher.java +++ b/src/main/java/com/twilio/rest/messaging/v1/LinkshorteningMessagingServiceDomainAssociationFetcher.java @@ -24,22 +24,29 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class LinkshorteningMessagingServiceDomainAssociationFetcher + extends Fetcher { - - -public class LinkshorteningMessagingServiceDomainAssociationFetcher extends Fetcher { private String pathMessagingServiceSid; - public LinkshorteningMessagingServiceDomainAssociationFetcher(final String pathMessagingServiceSid){ + public LinkshorteningMessagingServiceDomainAssociationFetcher( + final String pathMessagingServiceSid + ) { this.pathMessagingServiceSid = pathMessagingServiceSid; } - @Override - public LinkshorteningMessagingServiceDomainAssociation fetch(final TwilioRestClient client) { - String path = "/v1/LinkShortening/MessagingServices/{MessagingServiceSid}/Domain"; + public LinkshorteningMessagingServiceDomainAssociation fetch( + final TwilioRestClient client + ) { + String path = + "/v1/LinkShortening/MessagingServices/{MessagingServiceSid}/Domain"; - path = path.replace("{"+"MessagingServiceSid"+"}", this.pathMessagingServiceSid.toString()); + path = + path.replace( + "{" + "MessagingServiceSid" + "}", + this.pathMessagingServiceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -49,15 +56,23 @@ public LinkshorteningMessagingServiceDomainAssociation fetch(final TwilioRestCli Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("LinkshorteningMessagingServiceDomainAssociation fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "LinkshorteningMessagingServiceDomainAssociation fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return LinkshorteningMessagingServiceDomainAssociation.fromJson(response.getStream(), client.getObjectMapper()); + return LinkshorteningMessagingServiceDomainAssociation.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/messaging/v1/Service.java b/src/main/java/com/twilio/rest/messaging/v1/Service.java index 8fd8755ff1..2194ace3b2 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/Service.java +++ b/src/main/java/com/twilio/rest/messaging/v1/Service.java @@ -24,56 +24,55 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; import com.twilio.http.HttpMethod; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Service extends Resource { + private static final long serialVersionUID = 59018314319448L; - public static ServiceCreator creator(final String friendlyName){ + public static ServiceCreator creator(final String friendlyName) { return new ServiceCreator(friendlyName); } - public static ServiceDeleter deleter(final String pathSid){ + public static ServiceDeleter deleter(final String pathSid) { return new ServiceDeleter(pathSid); } - public static ServiceFetcher fetcher(final String pathSid){ + public static ServiceFetcher fetcher(final String pathSid) { return new ServiceFetcher(pathSid); } - public static ServiceReader reader(){ + public static ServiceReader reader() { return new ServiceReader(); } - public static ServiceUpdater updater(final String pathSid){ + public static ServiceUpdater updater(final String pathSid) { return new ServiceUpdater(pathSid); } /** - * Converts a JSON String into a Service object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Service object represented by the provided JSON - */ - public static Service fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Service object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Service object represented by the provided JSON + */ + public static Service fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Service.class); @@ -85,14 +84,17 @@ public static Service fromJson(final String json, final ObjectMapper objectMappe } /** - * Converts a JSON InputStream into a Service object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Service object represented by the provided JSON - */ - public static Service fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Service object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Service object represented by the provided JSON + */ + public static Service fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Service.class); @@ -102,6 +104,7 @@ public static Service fromJson(final InputStream json, final ObjectMapper object throw new ApiConnectionException(e.getMessage(), e); } } + public enum ScanMessageContent { INHERIT("inherit"), ENABLE("enable"), @@ -149,74 +152,37 @@ public static ScanMessageContent forValue(final String value) { @JsonCreator private Service( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("inbound_request_url") - final URI inboundRequestUrl, - - @JsonProperty("inbound_method") - final HttpMethod inboundMethod, - - @JsonProperty("fallback_url") - final URI fallbackUrl, - - @JsonProperty("fallback_method") - final HttpMethod fallbackMethod, - - @JsonProperty("status_callback") - final URI statusCallback, - - @JsonProperty("sticky_sender") - final Boolean stickySender, - - @JsonProperty("mms_converter") - final Boolean mmsConverter, - - @JsonProperty("smart_encoding") - final Boolean smartEncoding, - - @JsonProperty("scan_message_content") - final Service.ScanMessageContent scanMessageContent, - - @JsonProperty("fallback_to_long_code") - final Boolean fallbackToLongCode, - - @JsonProperty("area_code_geomatch") - final Boolean areaCodeGeomatch, - - @JsonProperty("synchronous_validation") - final Boolean synchronousValidation, - - @JsonProperty("validity_period") - final Integer validityPeriod, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links, - - @JsonProperty("usecase") - final String usecase, - - @JsonProperty("us_app_to_person_registered") - final Boolean usAppToPersonRegistered, - - @JsonProperty("use_inbound_webhook_on_number") - final Boolean useInboundWebhookOnNumber + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("inbound_request_url") final URI inboundRequestUrl, + @JsonProperty("inbound_method") final HttpMethod inboundMethod, + @JsonProperty("fallback_url") final URI fallbackUrl, + @JsonProperty("fallback_method") final HttpMethod fallbackMethod, + @JsonProperty("status_callback") final URI statusCallback, + @JsonProperty("sticky_sender") final Boolean stickySender, + @JsonProperty("mms_converter") final Boolean mmsConverter, + @JsonProperty("smart_encoding") final Boolean smartEncoding, + @JsonProperty( + "scan_message_content" + ) final Service.ScanMessageContent scanMessageContent, + @JsonProperty("fallback_to_long_code") final Boolean fallbackToLongCode, + @JsonProperty("area_code_geomatch") final Boolean areaCodeGeomatch, + @JsonProperty( + "synchronous_validation" + ) final Boolean synchronousValidation, + @JsonProperty("validity_period") final Integer validityPeriod, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links, + @JsonProperty("usecase") final String usecase, + @JsonProperty( + "us_app_to_person_registered" + ) final Boolean usAppToPersonRegistered, + @JsonProperty( + "use_inbound_webhook_on_number" + ) final Boolean useInboundWebhookOnNumber ) { this.sid = sid; this.accountSid = accountSid; @@ -243,79 +209,101 @@ private Service( this.useInboundWebhookOnNumber = useInboundWebhookOnNumber; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getInboundRequestUrl() { - return this.inboundRequestUrl; - } - public final HttpMethod getInboundMethod() { - return this.inboundMethod; - } - public final URI getFallbackUrl() { - return this.fallbackUrl; - } - public final HttpMethod getFallbackMethod() { - return this.fallbackMethod; - } - public final URI getStatusCallback() { - return this.statusCallback; - } - public final Boolean getStickySender() { - return this.stickySender; - } - public final Boolean getMmsConverter() { - return this.mmsConverter; - } - public final Boolean getSmartEncoding() { - return this.smartEncoding; - } - public final Service.ScanMessageContent getScanMessageContent() { - return this.scanMessageContent; - } - public final Boolean getFallbackToLongCode() { - return this.fallbackToLongCode; - } - public final Boolean getAreaCodeGeomatch() { - return this.areaCodeGeomatch; - } - public final Boolean getSynchronousValidation() { - return this.synchronousValidation; - } - public final Integer getValidityPeriod() { - return this.validityPeriod; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } - public final String getUsecase() { - return this.usecase; - } - public final Boolean getUsAppToPersonRegistered() { - return this.usAppToPersonRegistered; - } - public final Boolean getUseInboundWebhookOnNumber() { - return this.useInboundWebhookOnNumber; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getInboundRequestUrl() { + return this.inboundRequestUrl; + } + + public final HttpMethod getInboundMethod() { + return this.inboundMethod; + } + + public final URI getFallbackUrl() { + return this.fallbackUrl; + } + + public final HttpMethod getFallbackMethod() { + return this.fallbackMethod; + } + + public final URI getStatusCallback() { + return this.statusCallback; + } + + public final Boolean getStickySender() { + return this.stickySender; + } + + public final Boolean getMmsConverter() { + return this.mmsConverter; + } + + public final Boolean getSmartEncoding() { + return this.smartEncoding; + } + + public final Service.ScanMessageContent getScanMessageContent() { + return this.scanMessageContent; + } + + public final Boolean getFallbackToLongCode() { + return this.fallbackToLongCode; + } + + public final Boolean getAreaCodeGeomatch() { + return this.areaCodeGeomatch; + } + + public final Boolean getSynchronousValidation() { + return this.synchronousValidation; + } + + public final Integer getValidityPeriod() { + return this.validityPeriod; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } + + public final String getUsecase() { + return this.usecase; + } + + public final Boolean getUsAppToPersonRegistered() { + return this.usAppToPersonRegistered; + } + + public final Boolean getUseInboundWebhookOnNumber() { + return this.useInboundWebhookOnNumber; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -325,13 +313,68 @@ public boolean equals(final Object o) { Service other = (Service) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(inboundRequestUrl, other.inboundRequestUrl) && Objects.equals(inboundMethod, other.inboundMethod) && Objects.equals(fallbackUrl, other.fallbackUrl) && Objects.equals(fallbackMethod, other.fallbackMethod) && Objects.equals(statusCallback, other.statusCallback) && Objects.equals(stickySender, other.stickySender) && Objects.equals(mmsConverter, other.mmsConverter) && Objects.equals(smartEncoding, other.smartEncoding) && Objects.equals(scanMessageContent, other.scanMessageContent) && Objects.equals(fallbackToLongCode, other.fallbackToLongCode) && Objects.equals(areaCodeGeomatch, other.areaCodeGeomatch) && Objects.equals(synchronousValidation, other.synchronousValidation) && Objects.equals(validityPeriod, other.validityPeriod) && Objects.equals(url, other.url) && Objects.equals(links, other.links) && Objects.equals(usecase, other.usecase) && Objects.equals(usAppToPersonRegistered, other.usAppToPersonRegistered) && Objects.equals(useInboundWebhookOnNumber, other.useInboundWebhookOnNumber) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(inboundRequestUrl, other.inboundRequestUrl) && + Objects.equals(inboundMethod, other.inboundMethod) && + Objects.equals(fallbackUrl, other.fallbackUrl) && + Objects.equals(fallbackMethod, other.fallbackMethod) && + Objects.equals(statusCallback, other.statusCallback) && + Objects.equals(stickySender, other.stickySender) && + Objects.equals(mmsConverter, other.mmsConverter) && + Objects.equals(smartEncoding, other.smartEncoding) && + Objects.equals(scanMessageContent, other.scanMessageContent) && + Objects.equals(fallbackToLongCode, other.fallbackToLongCode) && + Objects.equals(areaCodeGeomatch, other.areaCodeGeomatch) && + Objects.equals( + synchronousValidation, + other.synchronousValidation + ) && + Objects.equals(validityPeriod, other.validityPeriod) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) && + Objects.equals(usecase, other.usecase) && + Objects.equals( + usAppToPersonRegistered, + other.usAppToPersonRegistered + ) && + Objects.equals( + useInboundWebhookOnNumber, + other.useInboundWebhookOnNumber + ) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, friendlyName, dateCreated, dateUpdated, inboundRequestUrl, inboundMethod, fallbackUrl, fallbackMethod, statusCallback, stickySender, mmsConverter, smartEncoding, scanMessageContent, fallbackToLongCode, areaCodeGeomatch, synchronousValidation, validityPeriod, url, links, usecase, usAppToPersonRegistered, useInboundWebhookOnNumber); + return Objects.hash( + sid, + accountSid, + friendlyName, + dateCreated, + dateUpdated, + inboundRequestUrl, + inboundMethod, + fallbackUrl, + fallbackMethod, + statusCallback, + stickySender, + mmsConverter, + smartEncoding, + scanMessageContent, + fallbackToLongCode, + areaCodeGeomatch, + synchronousValidation, + validityPeriod, + url, + links, + usecase, + usAppToPersonRegistered, + useInboundWebhookOnNumber + ); } - } - diff --git a/src/main/java/com/twilio/rest/messaging/v1/ServiceCreator.java b/src/main/java/com/twilio/rest/messaging/v1/ServiceCreator.java index b36e25286d..a4a78cb39c 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/ServiceCreator.java +++ b/src/main/java/com/twilio/rest/messaging/v1/ServiceCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.messaging.v1; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -25,12 +26,10 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.net.URI; - - - import java.net.URI; -public class ServiceCreator extends Creator{ +public class ServiceCreator extends Creator { + private String friendlyName; private URI inboundRequestUrl; private HttpMethod inboundMethod; @@ -52,100 +51,133 @@ public ServiceCreator(final String friendlyName) { this.friendlyName = friendlyName; } - public ServiceCreator setFriendlyName(final String friendlyName){ + public ServiceCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public ServiceCreator setInboundRequestUrl(final URI inboundRequestUrl){ + + public ServiceCreator setInboundRequestUrl(final URI inboundRequestUrl) { this.inboundRequestUrl = inboundRequestUrl; return this; } - public ServiceCreator setInboundRequestUrl(final String inboundRequestUrl){ + public ServiceCreator setInboundRequestUrl(final String inboundRequestUrl) { return setInboundRequestUrl(Promoter.uriFromString(inboundRequestUrl)); } - public ServiceCreator setInboundMethod(final HttpMethod inboundMethod){ + + public ServiceCreator setInboundMethod(final HttpMethod inboundMethod) { this.inboundMethod = inboundMethod; return this; } - public ServiceCreator setFallbackUrl(final URI fallbackUrl){ + + public ServiceCreator setFallbackUrl(final URI fallbackUrl) { this.fallbackUrl = fallbackUrl; return this; } - public ServiceCreator setFallbackUrl(final String fallbackUrl){ + public ServiceCreator setFallbackUrl(final String fallbackUrl) { return setFallbackUrl(Promoter.uriFromString(fallbackUrl)); } - public ServiceCreator setFallbackMethod(final HttpMethod fallbackMethod){ + + public ServiceCreator setFallbackMethod(final HttpMethod fallbackMethod) { this.fallbackMethod = fallbackMethod; return this; } - public ServiceCreator setStatusCallback(final URI statusCallback){ + + public ServiceCreator setStatusCallback(final URI statusCallback) { this.statusCallback = statusCallback; return this; } - public ServiceCreator setStatusCallback(final String statusCallback){ + public ServiceCreator setStatusCallback(final String statusCallback) { return setStatusCallback(Promoter.uriFromString(statusCallback)); } - public ServiceCreator setStickySender(final Boolean stickySender){ + + public ServiceCreator setStickySender(final Boolean stickySender) { this.stickySender = stickySender; return this; } - public ServiceCreator setMmsConverter(final Boolean mmsConverter){ + + public ServiceCreator setMmsConverter(final Boolean mmsConverter) { this.mmsConverter = mmsConverter; return this; } - public ServiceCreator setSmartEncoding(final Boolean smartEncoding){ + + public ServiceCreator setSmartEncoding(final Boolean smartEncoding) { this.smartEncoding = smartEncoding; return this; } - public ServiceCreator setScanMessageContent(final Service.ScanMessageContent scanMessageContent){ + + public ServiceCreator setScanMessageContent( + final Service.ScanMessageContent scanMessageContent + ) { this.scanMessageContent = scanMessageContent; return this; } - public ServiceCreator setFallbackToLongCode(final Boolean fallbackToLongCode){ + + public ServiceCreator setFallbackToLongCode( + final Boolean fallbackToLongCode + ) { this.fallbackToLongCode = fallbackToLongCode; return this; } - public ServiceCreator setAreaCodeGeomatch(final Boolean areaCodeGeomatch){ + + public ServiceCreator setAreaCodeGeomatch(final Boolean areaCodeGeomatch) { this.areaCodeGeomatch = areaCodeGeomatch; return this; } - public ServiceCreator setValidityPeriod(final Integer validityPeriod){ + + public ServiceCreator setValidityPeriod(final Integer validityPeriod) { this.validityPeriod = validityPeriod; return this; } - public ServiceCreator setSynchronousValidation(final Boolean synchronousValidation){ + + public ServiceCreator setSynchronousValidation( + final Boolean synchronousValidation + ) { this.synchronousValidation = synchronousValidation; return this; } - public ServiceCreator setUsecase(final String usecase){ + + public ServiceCreator setUsecase(final String usecase) { this.usecase = usecase; return this; } - public ServiceCreator setUseInboundWebhookOnNumber(final Boolean useInboundWebhookOnNumber){ + + public ServiceCreator setUseInboundWebhookOnNumber( + final Boolean useInboundWebhookOnNumber + ) { this.useInboundWebhookOnNumber = useInboundWebhookOnNumber; return this; } @Override - public Service create(final TwilioRestClient client){ + public Service create(final TwilioRestClient client) { String path = "/v1/Services"; - path = path.replace("{"+"FriendlyName"+"}", this.friendlyName.toString()); + path = + path.replace( + "{" + "FriendlyName" + "}", + this.friendlyName.toString() + ); Request request = new Request( HttpMethod.POST, Domains.MESSAGING.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -154,70 +186,73 @@ public Service create(final TwilioRestClient client){ return Service.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (inboundRequestUrl != null) { - request.addPostParam("InboundRequestUrl", inboundRequestUrl.toString()); - + request.addPostParam( + "InboundRequestUrl", + inboundRequestUrl.toString() + ); } if (inboundMethod != null) { request.addPostParam("InboundMethod", inboundMethod.toString()); - } if (fallbackUrl != null) { request.addPostParam("FallbackUrl", fallbackUrl.toString()); - } if (fallbackMethod != null) { request.addPostParam("FallbackMethod", fallbackMethod.toString()); - } if (statusCallback != null) { request.addPostParam("StatusCallback", statusCallback.toString()); - } if (stickySender != null) { request.addPostParam("StickySender", stickySender.toString()); - } if (mmsConverter != null) { request.addPostParam("MmsConverter", mmsConverter.toString()); - } if (smartEncoding != null) { request.addPostParam("SmartEncoding", smartEncoding.toString()); - } if (scanMessageContent != null) { - request.addPostParam("ScanMessageContent", scanMessageContent.toString()); - + request.addPostParam( + "ScanMessageContent", + scanMessageContent.toString() + ); } if (fallbackToLongCode != null) { - request.addPostParam("FallbackToLongCode", fallbackToLongCode.toString()); - + request.addPostParam( + "FallbackToLongCode", + fallbackToLongCode.toString() + ); } if (areaCodeGeomatch != null) { - request.addPostParam("AreaCodeGeomatch", areaCodeGeomatch.toString()); - + request.addPostParam( + "AreaCodeGeomatch", + areaCodeGeomatch.toString() + ); } if (validityPeriod != null) { request.addPostParam("ValidityPeriod", validityPeriod.toString()); - } if (synchronousValidation != null) { - request.addPostParam("SynchronousValidation", synchronousValidation.toString()); - + request.addPostParam( + "SynchronousValidation", + synchronousValidation.toString() + ); } if (usecase != null) { request.addPostParam("Usecase", usecase); - } if (useInboundWebhookOnNumber != null) { - request.addPostParam("UseInboundWebhookOnNumber", useInboundWebhookOnNumber.toString()); - + request.addPostParam( + "UseInboundWebhookOnNumber", + useInboundWebhookOnNumber.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/messaging/v1/ServiceDeleter.java b/src/main/java/com/twilio/rest/messaging/v1/ServiceDeleter.java index 9118bb9812..80b2b41052 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/ServiceDeleter.java +++ b/src/main/java/com/twilio/rest/messaging/v1/ServiceDeleter.java @@ -24,21 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class ServiceDeleter extends Deleter { + private String pathSid; - public ServiceDeleter(final String pathSid){ + public ServiceDeleter(final String pathSid) { this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Services/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -48,9 +46,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/messaging/v1/ServiceFetcher.java b/src/main/java/com/twilio/rest/messaging/v1/ServiceFetcher.java index 777159f331..ceee543f12 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/ServiceFetcher.java +++ b/src/main/java/com/twilio/rest/messaging/v1/ServiceFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class ServiceFetcher extends Fetcher { + private String pathSid; - public ServiceFetcher(final String pathSid){ + public ServiceFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public Service fetch(final TwilioRestClient client) { String path = "/v1/Services/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,9 +46,14 @@ public Service fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/messaging/v1/ServiceReader.java b/src/main/java/com/twilio/rest/messaging/v1/ServiceReader.java index 926dfec01c..94c050cf60 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/ServiceReader.java +++ b/src/main/java/com/twilio/rest/messaging/v1/ServiceReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.messaging.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,17 +25,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class ServiceReader extends Reader { + private Integer pageSize; - public ServiceReader(){ - } + public ServiceReader() {} - public ServiceReader setPageSize(final Integer pageSize){ + public ServiceReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -57,13 +55,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -79,7 +85,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reques } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.MESSAGING.toString()) @@ -87,9 +96,11 @@ public Page previousPage(final Page page, final TwilioRestClie return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.MESSAGING.toString()) @@ -98,21 +109,21 @@ public Page nextPage(final Page page, final TwilioRestClient c } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/messaging/v1/ServiceUpdater.java b/src/main/java/com/twilio/rest/messaging/v1/ServiceUpdater.java index e589a6e50d..193d190ec5 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/ServiceUpdater.java +++ b/src/main/java/com/twilio/rest/messaging/v1/ServiceUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.messaging.v1; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -24,12 +25,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.net.URI; +public class ServiceUpdater extends Updater { - -public class ServiceUpdater extends Updater{ private String pathSid; private String friendlyName; private URI inboundRequestUrl; @@ -48,104 +47,133 @@ public class ServiceUpdater extends Updater{ private String usecase; private Boolean useInboundWebhookOnNumber; - public ServiceUpdater(final String pathSid){ + public ServiceUpdater(final String pathSid) { this.pathSid = pathSid; } - public ServiceUpdater setFriendlyName(final String friendlyName){ + public ServiceUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public ServiceUpdater setInboundRequestUrl(final URI inboundRequestUrl){ + + public ServiceUpdater setInboundRequestUrl(final URI inboundRequestUrl) { this.inboundRequestUrl = inboundRequestUrl; return this; } - public ServiceUpdater setInboundRequestUrl(final String inboundRequestUrl){ + public ServiceUpdater setInboundRequestUrl(final String inboundRequestUrl) { return setInboundRequestUrl(Promoter.uriFromString(inboundRequestUrl)); } - public ServiceUpdater setInboundMethod(final HttpMethod inboundMethod){ + + public ServiceUpdater setInboundMethod(final HttpMethod inboundMethod) { this.inboundMethod = inboundMethod; return this; } - public ServiceUpdater setFallbackUrl(final URI fallbackUrl){ + + public ServiceUpdater setFallbackUrl(final URI fallbackUrl) { this.fallbackUrl = fallbackUrl; return this; } - public ServiceUpdater setFallbackUrl(final String fallbackUrl){ + public ServiceUpdater setFallbackUrl(final String fallbackUrl) { return setFallbackUrl(Promoter.uriFromString(fallbackUrl)); } - public ServiceUpdater setFallbackMethod(final HttpMethod fallbackMethod){ + + public ServiceUpdater setFallbackMethod(final HttpMethod fallbackMethod) { this.fallbackMethod = fallbackMethod; return this; } - public ServiceUpdater setStatusCallback(final URI statusCallback){ + + public ServiceUpdater setStatusCallback(final URI statusCallback) { this.statusCallback = statusCallback; return this; } - public ServiceUpdater setStatusCallback(final String statusCallback){ + public ServiceUpdater setStatusCallback(final String statusCallback) { return setStatusCallback(Promoter.uriFromString(statusCallback)); } - public ServiceUpdater setStickySender(final Boolean stickySender){ + + public ServiceUpdater setStickySender(final Boolean stickySender) { this.stickySender = stickySender; return this; } - public ServiceUpdater setMmsConverter(final Boolean mmsConverter){ + + public ServiceUpdater setMmsConverter(final Boolean mmsConverter) { this.mmsConverter = mmsConverter; return this; } - public ServiceUpdater setSmartEncoding(final Boolean smartEncoding){ + + public ServiceUpdater setSmartEncoding(final Boolean smartEncoding) { this.smartEncoding = smartEncoding; return this; } - public ServiceUpdater setScanMessageContent(final Service.ScanMessageContent scanMessageContent){ + + public ServiceUpdater setScanMessageContent( + final Service.ScanMessageContent scanMessageContent + ) { this.scanMessageContent = scanMessageContent; return this; } - public ServiceUpdater setFallbackToLongCode(final Boolean fallbackToLongCode){ + + public ServiceUpdater setFallbackToLongCode( + final Boolean fallbackToLongCode + ) { this.fallbackToLongCode = fallbackToLongCode; return this; } - public ServiceUpdater setAreaCodeGeomatch(final Boolean areaCodeGeomatch){ + + public ServiceUpdater setAreaCodeGeomatch(final Boolean areaCodeGeomatch) { this.areaCodeGeomatch = areaCodeGeomatch; return this; } - public ServiceUpdater setValidityPeriod(final Integer validityPeriod){ + + public ServiceUpdater setValidityPeriod(final Integer validityPeriod) { this.validityPeriod = validityPeriod; return this; } - public ServiceUpdater setSynchronousValidation(final Boolean synchronousValidation){ + + public ServiceUpdater setSynchronousValidation( + final Boolean synchronousValidation + ) { this.synchronousValidation = synchronousValidation; return this; } - public ServiceUpdater setUsecase(final String usecase){ + + public ServiceUpdater setUsecase(final String usecase) { this.usecase = usecase; return this; } - public ServiceUpdater setUseInboundWebhookOnNumber(final Boolean useInboundWebhookOnNumber){ + + public ServiceUpdater setUseInboundWebhookOnNumber( + final Boolean useInboundWebhookOnNumber + ) { this.useInboundWebhookOnNumber = useInboundWebhookOnNumber; return this; } @Override - public Service update(final TwilioRestClient client){ + public Service update(final TwilioRestClient client) { String path = "/v1/Services/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.MESSAGING.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -154,70 +182,73 @@ public Service update(final TwilioRestClient client){ return Service.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (inboundRequestUrl != null) { - request.addPostParam("InboundRequestUrl", inboundRequestUrl.toString()); - + request.addPostParam( + "InboundRequestUrl", + inboundRequestUrl.toString() + ); } if (inboundMethod != null) { request.addPostParam("InboundMethod", inboundMethod.toString()); - } if (fallbackUrl != null) { request.addPostParam("FallbackUrl", fallbackUrl.toString()); - } if (fallbackMethod != null) { request.addPostParam("FallbackMethod", fallbackMethod.toString()); - } if (statusCallback != null) { request.addPostParam("StatusCallback", statusCallback.toString()); - } if (stickySender != null) { request.addPostParam("StickySender", stickySender.toString()); - } if (mmsConverter != null) { request.addPostParam("MmsConverter", mmsConverter.toString()); - } if (smartEncoding != null) { request.addPostParam("SmartEncoding", smartEncoding.toString()); - } if (scanMessageContent != null) { - request.addPostParam("ScanMessageContent", scanMessageContent.toString()); - + request.addPostParam( + "ScanMessageContent", + scanMessageContent.toString() + ); } if (fallbackToLongCode != null) { - request.addPostParam("FallbackToLongCode", fallbackToLongCode.toString()); - + request.addPostParam( + "FallbackToLongCode", + fallbackToLongCode.toString() + ); } if (areaCodeGeomatch != null) { - request.addPostParam("AreaCodeGeomatch", areaCodeGeomatch.toString()); - + request.addPostParam( + "AreaCodeGeomatch", + areaCodeGeomatch.toString() + ); } if (validityPeriod != null) { request.addPostParam("ValidityPeriod", validityPeriod.toString()); - } if (synchronousValidation != null) { - request.addPostParam("SynchronousValidation", synchronousValidation.toString()); - + request.addPostParam( + "SynchronousValidation", + synchronousValidation.toString() + ); } if (usecase != null) { request.addPostParam("Usecase", usecase); - } if (useInboundWebhookOnNumber != null) { - request.addPostParam("UseInboundWebhookOnNumber", useInboundWebhookOnNumber.toString()); - + request.addPostParam( + "UseInboundWebhookOnNumber", + useInboundWebhookOnNumber.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/messaging/v1/TollfreeVerification.java b/src/main/java/com/twilio/rest/messaging/v1/TollfreeVerification.java new file mode 100644 index 0000000000..32f1d340b1 --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/TollfreeVerification.java @@ -0,0 +1,562 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.converter.DateConverter; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Map; +import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class TollfreeVerification extends Resource { + + private static final long serialVersionUID = 58037728146886L; + + public static TollfreeVerificationCreator creator( + final String businessName, + final String businessWebsite, + final String notificationEmail, + final List useCaseCategories, + final String useCaseSummary, + final String productionMessageSample, + final List optInImageUrls, + final TollfreeVerification.OptInType optInType, + final String messageVolume, + final String tollfreePhoneNumberSid + ) { + return new TollfreeVerificationCreator( + businessName, + businessWebsite, + notificationEmail, + useCaseCategories, + useCaseSummary, + productionMessageSample, + optInImageUrls, + optInType, + messageVolume, + tollfreePhoneNumberSid + ); + } + + public static TollfreeVerificationFetcher fetcher(final String pathSid) { + return new TollfreeVerificationFetcher(pathSid); + } + + public static TollfreeVerificationReader reader() { + return new TollfreeVerificationReader(); + } + + public static TollfreeVerificationUpdater updater(final String pathSid) { + return new TollfreeVerificationUpdater(pathSid); + } + + /** + * Converts a JSON String into a TollfreeVerification object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return TollfreeVerification object represented by the provided JSON + */ + public static TollfreeVerification fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, TollfreeVerification.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a TollfreeVerification object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return TollfreeVerification object represented by the provided JSON + */ + public static TollfreeVerification fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, TollfreeVerification.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public enum OptInType { + VERBAL("VERBAL"), + WEB_FORM("WEB_FORM"), + PAPER_FORM("PAPER_FORM"), + VIA_TEXT("VIA_TEXT"), + MOBILE_QR_CODE("MOBILE_QR_CODE"); + + private final String value; + + private OptInType(final String value) { + this.value = value; + } + + public String toString() { + return value; + } + + @JsonCreator + public static OptInType forValue(final String value) { + return Promoter.enumFromString(value, OptInType.values()); + } + } + + public enum Status { + PENDING_REVIEW("PENDING_REVIEW"), + IN_REVIEW("IN_REVIEW"), + TWILIO_APPROVED("TWILIO_APPROVED"), + TWILIO_REJECTED("TWILIO_REJECTED"); + + private final String value; + + private Status(final String value) { + this.value = value; + } + + public String toString() { + return value; + } + + @JsonCreator + public static Status forValue(final String value) { + return Promoter.enumFromString(value, Status.values()); + } + } + + private final String sid; + private final String accountSid; + private final String customerProfileSid; + private final String trustProductSid; + private final ZonedDateTime dateCreated; + private final ZonedDateTime dateUpdated; + private final String regulatedItemSid; + private final String businessName; + private final String businessStreetAddress; + private final String businessStreetAddress2; + private final String businessCity; + private final String businessStateProvinceRegion; + private final String businessPostalCode; + private final String businessCountry; + private final String businessWebsite; + private final String businessContactFirstName; + private final String businessContactLastName; + private final String businessContactEmail; + private final com.twilio.type.PhoneNumber businessContactPhone; + private final String notificationEmail; + private final List useCaseCategories; + private final String useCaseSummary; + private final String productionMessageSample; + private final List optInImageUrls; + private final TollfreeVerification.OptInType optInType; + private final String messageVolume; + private final String additionalInformation; + private final String tollfreePhoneNumberSid; + private final TollfreeVerification.Status status; + private final URI url; + private final String rejectionReason; + private final Integer errorCode; + private final ZonedDateTime editExpiration; + private final Map resourceLinks; + private final String externalReferenceId; + + @JsonCreator + private TollfreeVerification( + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("customer_profile_sid") final String customerProfileSid, + @JsonProperty("trust_product_sid") final String trustProductSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("regulated_item_sid") final String regulatedItemSid, + @JsonProperty("business_name") final String businessName, + @JsonProperty( + "business_street_address" + ) final String businessStreetAddress, + @JsonProperty( + "business_street_address2" + ) final String businessStreetAddress2, + @JsonProperty("business_city") final String businessCity, + @JsonProperty( + "business_state_province_region" + ) final String businessStateProvinceRegion, + @JsonProperty("business_postal_code") final String businessPostalCode, + @JsonProperty("business_country") final String businessCountry, + @JsonProperty("business_website") final String businessWebsite, + @JsonProperty( + "business_contact_first_name" + ) final String businessContactFirstName, + @JsonProperty( + "business_contact_last_name" + ) final String businessContactLastName, + @JsonProperty( + "business_contact_email" + ) final String businessContactEmail, + @JsonProperty( + "business_contact_phone" + ) final com.twilio.type.PhoneNumber businessContactPhone, + @JsonProperty("notification_email") final String notificationEmail, + @JsonProperty( + "use_case_categories" + ) final List useCaseCategories, + @JsonProperty("use_case_summary") final String useCaseSummary, + @JsonProperty( + "production_message_sample" + ) final String productionMessageSample, + @JsonProperty("opt_in_image_urls") final List optInImageUrls, + @JsonProperty( + "opt_in_type" + ) final TollfreeVerification.OptInType optInType, + @JsonProperty("message_volume") final String messageVolume, + @JsonProperty( + "additional_information" + ) final String additionalInformation, + @JsonProperty( + "tollfree_phone_number_sid" + ) final String tollfreePhoneNumberSid, + @JsonProperty("status") final TollfreeVerification.Status status, + @JsonProperty("url") final URI url, + @JsonProperty("rejection_reason") final String rejectionReason, + @JsonProperty("error_code") final Integer errorCode, + @JsonProperty("edit_expiration") final String editExpiration, + @JsonProperty("resource_links") final Map resourceLinks, + @JsonProperty("external_reference_id") final String externalReferenceId + ) { + this.sid = sid; + this.accountSid = accountSid; + this.customerProfileSid = customerProfileSid; + this.trustProductSid = trustProductSid; + this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); + this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); + this.regulatedItemSid = regulatedItemSid; + this.businessName = businessName; + this.businessStreetAddress = businessStreetAddress; + this.businessStreetAddress2 = businessStreetAddress2; + this.businessCity = businessCity; + this.businessStateProvinceRegion = businessStateProvinceRegion; + this.businessPostalCode = businessPostalCode; + this.businessCountry = businessCountry; + this.businessWebsite = businessWebsite; + this.businessContactFirstName = businessContactFirstName; + this.businessContactLastName = businessContactLastName; + this.businessContactEmail = businessContactEmail; + this.businessContactPhone = businessContactPhone; + this.notificationEmail = notificationEmail; + this.useCaseCategories = useCaseCategories; + this.useCaseSummary = useCaseSummary; + this.productionMessageSample = productionMessageSample; + this.optInImageUrls = optInImageUrls; + this.optInType = optInType; + this.messageVolume = messageVolume; + this.additionalInformation = additionalInformation; + this.tollfreePhoneNumberSid = tollfreePhoneNumberSid; + this.status = status; + this.url = url; + this.rejectionReason = rejectionReason; + this.errorCode = errorCode; + this.editExpiration = + DateConverter.iso8601DateTimeFromString(editExpiration); + this.resourceLinks = resourceLinks; + this.externalReferenceId = externalReferenceId; + } + + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getCustomerProfileSid() { + return this.customerProfileSid; + } + + public final String getTrustProductSid() { + return this.trustProductSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getRegulatedItemSid() { + return this.regulatedItemSid; + } + + public final String getBusinessName() { + return this.businessName; + } + + public final String getBusinessStreetAddress() { + return this.businessStreetAddress; + } + + public final String getBusinessStreetAddress2() { + return this.businessStreetAddress2; + } + + public final String getBusinessCity() { + return this.businessCity; + } + + public final String getBusinessStateProvinceRegion() { + return this.businessStateProvinceRegion; + } + + public final String getBusinessPostalCode() { + return this.businessPostalCode; + } + + public final String getBusinessCountry() { + return this.businessCountry; + } + + public final String getBusinessWebsite() { + return this.businessWebsite; + } + + public final String getBusinessContactFirstName() { + return this.businessContactFirstName; + } + + public final String getBusinessContactLastName() { + return this.businessContactLastName; + } + + public final String getBusinessContactEmail() { + return this.businessContactEmail; + } + + public final com.twilio.type.PhoneNumber getBusinessContactPhone() { + return this.businessContactPhone; + } + + public final String getNotificationEmail() { + return this.notificationEmail; + } + + public final List getUseCaseCategories() { + return this.useCaseCategories; + } + + public final String getUseCaseSummary() { + return this.useCaseSummary; + } + + public final String getProductionMessageSample() { + return this.productionMessageSample; + } + + public final List getOptInImageUrls() { + return this.optInImageUrls; + } + + public final TollfreeVerification.OptInType getOptInType() { + return this.optInType; + } + + public final String getMessageVolume() { + return this.messageVolume; + } + + public final String getAdditionalInformation() { + return this.additionalInformation; + } + + public final String getTollfreePhoneNumberSid() { + return this.tollfreePhoneNumberSid; + } + + public final TollfreeVerification.Status getStatus() { + return this.status; + } + + public final URI getUrl() { + return this.url; + } + + public final String getRejectionReason() { + return this.rejectionReason; + } + + public final Integer getErrorCode() { + return this.errorCode; + } + + public final ZonedDateTime getEditExpiration() { + return this.editExpiration; + } + + public final Map getResourceLinks() { + return this.resourceLinks; + } + + public final String getExternalReferenceId() { + return this.externalReferenceId; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + TollfreeVerification other = (TollfreeVerification) o; + + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(customerProfileSid, other.customerProfileSid) && + Objects.equals(trustProductSid, other.trustProductSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(regulatedItemSid, other.regulatedItemSid) && + Objects.equals(businessName, other.businessName) && + Objects.equals( + businessStreetAddress, + other.businessStreetAddress + ) && + Objects.equals( + businessStreetAddress2, + other.businessStreetAddress2 + ) && + Objects.equals(businessCity, other.businessCity) && + Objects.equals( + businessStateProvinceRegion, + other.businessStateProvinceRegion + ) && + Objects.equals(businessPostalCode, other.businessPostalCode) && + Objects.equals(businessCountry, other.businessCountry) && + Objects.equals(businessWebsite, other.businessWebsite) && + Objects.equals( + businessContactFirstName, + other.businessContactFirstName + ) && + Objects.equals( + businessContactLastName, + other.businessContactLastName + ) && + Objects.equals(businessContactEmail, other.businessContactEmail) && + Objects.equals(businessContactPhone, other.businessContactPhone) && + Objects.equals(notificationEmail, other.notificationEmail) && + Objects.equals(useCaseCategories, other.useCaseCategories) && + Objects.equals(useCaseSummary, other.useCaseSummary) && + Objects.equals( + productionMessageSample, + other.productionMessageSample + ) && + Objects.equals(optInImageUrls, other.optInImageUrls) && + Objects.equals(optInType, other.optInType) && + Objects.equals(messageVolume, other.messageVolume) && + Objects.equals( + additionalInformation, + other.additionalInformation + ) && + Objects.equals( + tollfreePhoneNumberSid, + other.tollfreePhoneNumberSid + ) && + Objects.equals(status, other.status) && + Objects.equals(url, other.url) && + Objects.equals(rejectionReason, other.rejectionReason) && + Objects.equals(errorCode, other.errorCode) && + Objects.equals(editExpiration, other.editExpiration) && + Objects.equals(resourceLinks, other.resourceLinks) && + Objects.equals(externalReferenceId, other.externalReferenceId) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + sid, + accountSid, + customerProfileSid, + trustProductSid, + dateCreated, + dateUpdated, + regulatedItemSid, + businessName, + businessStreetAddress, + businessStreetAddress2, + businessCity, + businessStateProvinceRegion, + businessPostalCode, + businessCountry, + businessWebsite, + businessContactFirstName, + businessContactLastName, + businessContactEmail, + businessContactPhone, + notificationEmail, + useCaseCategories, + useCaseSummary, + productionMessageSample, + optInImageUrls, + optInType, + messageVolume, + additionalInformation, + tollfreePhoneNumberSid, + status, + url, + rejectionReason, + errorCode, + editExpiration, + resourceLinks, + externalReferenceId + ); + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/TollfreeVerificationCreator.java b/src/main/java/com/twilio/rest/messaging/v1/TollfreeVerificationCreator.java new file mode 100644 index 0000000000..8fdd48ee93 --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/TollfreeVerificationCreator.java @@ -0,0 +1,444 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1; + +import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import java.util.List; +import java.util.List; + +public class TollfreeVerificationCreator extends Creator { + + private String businessName; + private String businessWebsite; + private String notificationEmail; + private List useCaseCategories; + private String useCaseSummary; + private String productionMessageSample; + private List optInImageUrls; + private TollfreeVerification.OptInType optInType; + private String messageVolume; + private String tollfreePhoneNumberSid; + private String customerProfileSid; + private String businessStreetAddress; + private String businessStreetAddress2; + private String businessCity; + private String businessStateProvinceRegion; + private String businessPostalCode; + private String businessCountry; + private String additionalInformation; + private String businessContactFirstName; + private String businessContactLastName; + private String businessContactEmail; + private com.twilio.type.PhoneNumber businessContactPhone; + private String externalReferenceId; + + public TollfreeVerificationCreator( + final String businessName, + final String businessWebsite, + final String notificationEmail, + final List useCaseCategories, + final String useCaseSummary, + final String productionMessageSample, + final List optInImageUrls, + final TollfreeVerification.OptInType optInType, + final String messageVolume, + final String tollfreePhoneNumberSid + ) { + this.businessName = businessName; + this.businessWebsite = businessWebsite; + this.notificationEmail = notificationEmail; + this.useCaseCategories = useCaseCategories; + this.useCaseSummary = useCaseSummary; + this.productionMessageSample = productionMessageSample; + this.optInImageUrls = optInImageUrls; + this.optInType = optInType; + this.messageVolume = messageVolume; + this.tollfreePhoneNumberSid = tollfreePhoneNumberSid; + } + + public TollfreeVerificationCreator setBusinessName( + final String businessName + ) { + this.businessName = businessName; + return this; + } + + public TollfreeVerificationCreator setBusinessWebsite( + final String businessWebsite + ) { + this.businessWebsite = businessWebsite; + return this; + } + + public TollfreeVerificationCreator setNotificationEmail( + final String notificationEmail + ) { + this.notificationEmail = notificationEmail; + return this; + } + + public TollfreeVerificationCreator setUseCaseCategories( + final List useCaseCategories + ) { + this.useCaseCategories = useCaseCategories; + return this; + } + + public TollfreeVerificationCreator setUseCaseCategories( + final String useCaseCategories + ) { + return setUseCaseCategories(Promoter.listOfOne(useCaseCategories)); + } + + public TollfreeVerificationCreator setUseCaseSummary( + final String useCaseSummary + ) { + this.useCaseSummary = useCaseSummary; + return this; + } + + public TollfreeVerificationCreator setProductionMessageSample( + final String productionMessageSample + ) { + this.productionMessageSample = productionMessageSample; + return this; + } + + public TollfreeVerificationCreator setOptInImageUrls( + final List optInImageUrls + ) { + this.optInImageUrls = optInImageUrls; + return this; + } + + public TollfreeVerificationCreator setOptInImageUrls( + final String optInImageUrls + ) { + return setOptInImageUrls(Promoter.listOfOne(optInImageUrls)); + } + + public TollfreeVerificationCreator setOptInType( + final TollfreeVerification.OptInType optInType + ) { + this.optInType = optInType; + return this; + } + + public TollfreeVerificationCreator setMessageVolume( + final String messageVolume + ) { + this.messageVolume = messageVolume; + return this; + } + + public TollfreeVerificationCreator setTollfreePhoneNumberSid( + final String tollfreePhoneNumberSid + ) { + this.tollfreePhoneNumberSid = tollfreePhoneNumberSid; + return this; + } + + public TollfreeVerificationCreator setCustomerProfileSid( + final String customerProfileSid + ) { + this.customerProfileSid = customerProfileSid; + return this; + } + + public TollfreeVerificationCreator setBusinessStreetAddress( + final String businessStreetAddress + ) { + this.businessStreetAddress = businessStreetAddress; + return this; + } + + public TollfreeVerificationCreator setBusinessStreetAddress2( + final String businessStreetAddress2 + ) { + this.businessStreetAddress2 = businessStreetAddress2; + return this; + } + + public TollfreeVerificationCreator setBusinessCity( + final String businessCity + ) { + this.businessCity = businessCity; + return this; + } + + public TollfreeVerificationCreator setBusinessStateProvinceRegion( + final String businessStateProvinceRegion + ) { + this.businessStateProvinceRegion = businessStateProvinceRegion; + return this; + } + + public TollfreeVerificationCreator setBusinessPostalCode( + final String businessPostalCode + ) { + this.businessPostalCode = businessPostalCode; + return this; + } + + public TollfreeVerificationCreator setBusinessCountry( + final String businessCountry + ) { + this.businessCountry = businessCountry; + return this; + } + + public TollfreeVerificationCreator setAdditionalInformation( + final String additionalInformation + ) { + this.additionalInformation = additionalInformation; + return this; + } + + public TollfreeVerificationCreator setBusinessContactFirstName( + final String businessContactFirstName + ) { + this.businessContactFirstName = businessContactFirstName; + return this; + } + + public TollfreeVerificationCreator setBusinessContactLastName( + final String businessContactLastName + ) { + this.businessContactLastName = businessContactLastName; + return this; + } + + public TollfreeVerificationCreator setBusinessContactEmail( + final String businessContactEmail + ) { + this.businessContactEmail = businessContactEmail; + return this; + } + + public TollfreeVerificationCreator setBusinessContactPhone( + final com.twilio.type.PhoneNumber businessContactPhone + ) { + this.businessContactPhone = businessContactPhone; + return this; + } + + public TollfreeVerificationCreator setBusinessContactPhone( + final String businessContactPhone + ) { + return setBusinessContactPhone( + Promoter.phoneNumberFromString(businessContactPhone) + ); + } + + public TollfreeVerificationCreator setExternalReferenceId( + final String externalReferenceId + ) { + this.externalReferenceId = externalReferenceId; + return this; + } + + @Override + public TollfreeVerification create(final TwilioRestClient client) { + String path = "/v1/Tollfree/Verifications"; + + path = + path.replace( + "{" + "BusinessName" + "}", + this.businessName.toString() + ); + path = + path.replace( + "{" + "BusinessWebsite" + "}", + this.businessWebsite.toString() + ); + path = + path.replace( + "{" + "NotificationEmail" + "}", + this.notificationEmail.toString() + ); + path = + path.replace( + "{" + "UseCaseCategories" + "}", + this.useCaseCategories.toString() + ); + path = + path.replace( + "{" + "UseCaseSummary" + "}", + this.useCaseSummary.toString() + ); + path = + path.replace( + "{" + "ProductionMessageSample" + "}", + this.productionMessageSample.toString() + ); + path = + path.replace( + "{" + "OptInImageUrls" + "}", + this.optInImageUrls.toString() + ); + path = path.replace("{" + "OptInType" + "}", this.optInType.toString()); + path = + path.replace( + "{" + "MessageVolume" + "}", + this.messageVolume.toString() + ); + path = + path.replace( + "{" + "TollfreePhoneNumberSid" + "}", + this.tollfreePhoneNumberSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.MESSAGING.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "TollfreeVerification creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException("Server Error, no content"); + } + throw new ApiException(restException); + } + + return TollfreeVerification.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + private void addPostParams(final Request request) { + if (businessName != null) { + request.addPostParam("BusinessName", businessName); + } + if (businessWebsite != null) { + request.addPostParam("BusinessWebsite", businessWebsite); + } + if (notificationEmail != null) { + request.addPostParam("NotificationEmail", notificationEmail); + } + if (useCaseCategories != null) { + for (String prop : useCaseCategories) { + request.addPostParam("UseCaseCategories", prop); + } + } + if (useCaseSummary != null) { + request.addPostParam("UseCaseSummary", useCaseSummary); + } + if (productionMessageSample != null) { + request.addPostParam( + "ProductionMessageSample", + productionMessageSample + ); + } + if (optInImageUrls != null) { + for (String prop : optInImageUrls) { + request.addPostParam("OptInImageUrls", prop); + } + } + if (optInType != null) { + request.addPostParam("OptInType", optInType.toString()); + } + if (messageVolume != null) { + request.addPostParam("MessageVolume", messageVolume); + } + if (tollfreePhoneNumberSid != null) { + request.addPostParam( + "TollfreePhoneNumberSid", + tollfreePhoneNumberSid + ); + } + if (customerProfileSid != null) { + request.addPostParam("CustomerProfileSid", customerProfileSid); + } + if (businessStreetAddress != null) { + request.addPostParam( + "BusinessStreetAddress", + businessStreetAddress + ); + } + if (businessStreetAddress2 != null) { + request.addPostParam( + "BusinessStreetAddress2", + businessStreetAddress2 + ); + } + if (businessCity != null) { + request.addPostParam("BusinessCity", businessCity); + } + if (businessStateProvinceRegion != null) { + request.addPostParam( + "BusinessStateProvinceRegion", + businessStateProvinceRegion + ); + } + if (businessPostalCode != null) { + request.addPostParam("BusinessPostalCode", businessPostalCode); + } + if (businessCountry != null) { + request.addPostParam("BusinessCountry", businessCountry); + } + if (additionalInformation != null) { + request.addPostParam( + "AdditionalInformation", + additionalInformation + ); + } + if (businessContactFirstName != null) { + request.addPostParam( + "BusinessContactFirstName", + businessContactFirstName + ); + } + if (businessContactLastName != null) { + request.addPostParam( + "BusinessContactLastName", + businessContactLastName + ); + } + if (businessContactEmail != null) { + request.addPostParam("BusinessContactEmail", businessContactEmail); + } + if (businessContactPhone != null) { + request.addPostParam( + "BusinessContactPhone", + businessContactPhone.toString() + ); + } + if (externalReferenceId != null) { + request.addPostParam("ExternalReferenceId", externalReferenceId); + } + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/TollfreeVerificationFetcher.java b/src/main/java/com/twilio/rest/messaging/v1/TollfreeVerificationFetcher.java new file mode 100644 index 0000000000..c8ff707580 --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/TollfreeVerificationFetcher.java @@ -0,0 +1,68 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1; + +import com.twilio.base.Fetcher; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; + +public class TollfreeVerificationFetcher extends Fetcher { + + private String pathSid; + + public TollfreeVerificationFetcher(final String pathSid) { + this.pathSid = pathSid; + } + + @Override + public TollfreeVerification fetch(final TwilioRestClient client) { + String path = "/v1/Tollfree/Verifications/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.MESSAGING.toString(), + path + ); + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "TollfreeVerification fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException("Server Error, no content"); + } + throw new ApiException(restException); + } + + return TollfreeVerification.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/TollfreeVerificationReader.java b/src/main/java/com/twilio/rest/messaging/v1/TollfreeVerificationReader.java new file mode 100644 index 0000000000..bc665d0aa0 --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/TollfreeVerificationReader.java @@ -0,0 +1,157 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; + +public class TollfreeVerificationReader extends Reader { + + private String tollfreePhoneNumberSid; + private TollfreeVerification.Status status; + private Integer pageSize; + + public TollfreeVerificationReader() {} + + public TollfreeVerificationReader setTollfreePhoneNumberSid( + final String tollfreePhoneNumberSid + ) { + this.tollfreePhoneNumberSid = tollfreePhoneNumberSid; + return this; + } + + public TollfreeVerificationReader setStatus( + final TollfreeVerification.Status status + ) { + this.status = status; + return this; + } + + public TollfreeVerificationReader setPageSize(final Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + @Override + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + String path = "/v1/Tollfree/Verifications"; + + Request request = new Request( + HttpMethod.GET, + Domains.MESSAGING.toString(), + path + ); + + addQueryParams(request); + return pageForRequest(client, request); + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "TollfreeVerification read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException("Server Error, no content"); + } + throw new ApiException(restException); + } + + return Page.fromJson( + "verifications", + response.getContent(), + TollfreeVerification.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.MESSAGING.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.MESSAGING.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); + + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (tollfreePhoneNumberSid != null) { + request.addQueryParam( + "TollfreePhoneNumberSid", + tollfreePhoneNumberSid + ); + } + if (status != null) { + request.addQueryParam("Status", status.toString()); + } + if (pageSize != null) { + request.addQueryParam("PageSize", pageSize.toString()); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/TollfreeVerificationUpdater.java b/src/main/java/com/twilio/rest/messaging/v1/TollfreeVerificationUpdater.java new file mode 100644 index 0000000000..b1676c1b42 --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/TollfreeVerificationUpdater.java @@ -0,0 +1,343 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1; + +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import java.util.List; + +public class TollfreeVerificationUpdater extends Updater { + + private String pathSid; + private String businessName; + private String businessWebsite; + private String notificationEmail; + private List useCaseCategories; + private String useCaseSummary; + private String productionMessageSample; + private List optInImageUrls; + private TollfreeVerification.OptInType optInType; + private String messageVolume; + private String businessStreetAddress; + private String businessStreetAddress2; + private String businessCity; + private String businessStateProvinceRegion; + private String businessPostalCode; + private String businessCountry; + private String additionalInformation; + private String businessContactFirstName; + private String businessContactLastName; + private String businessContactEmail; + private com.twilio.type.PhoneNumber businessContactPhone; + + public TollfreeVerificationUpdater(final String pathSid) { + this.pathSid = pathSid; + } + + public TollfreeVerificationUpdater setBusinessName( + final String businessName + ) { + this.businessName = businessName; + return this; + } + + public TollfreeVerificationUpdater setBusinessWebsite( + final String businessWebsite + ) { + this.businessWebsite = businessWebsite; + return this; + } + + public TollfreeVerificationUpdater setNotificationEmail( + final String notificationEmail + ) { + this.notificationEmail = notificationEmail; + return this; + } + + public TollfreeVerificationUpdater setUseCaseCategories( + final List useCaseCategories + ) { + this.useCaseCategories = useCaseCategories; + return this; + } + + public TollfreeVerificationUpdater setUseCaseCategories( + final String useCaseCategories + ) { + return setUseCaseCategories(Promoter.listOfOne(useCaseCategories)); + } + + public TollfreeVerificationUpdater setUseCaseSummary( + final String useCaseSummary + ) { + this.useCaseSummary = useCaseSummary; + return this; + } + + public TollfreeVerificationUpdater setProductionMessageSample( + final String productionMessageSample + ) { + this.productionMessageSample = productionMessageSample; + return this; + } + + public TollfreeVerificationUpdater setOptInImageUrls( + final List optInImageUrls + ) { + this.optInImageUrls = optInImageUrls; + return this; + } + + public TollfreeVerificationUpdater setOptInImageUrls( + final String optInImageUrls + ) { + return setOptInImageUrls(Promoter.listOfOne(optInImageUrls)); + } + + public TollfreeVerificationUpdater setOptInType( + final TollfreeVerification.OptInType optInType + ) { + this.optInType = optInType; + return this; + } + + public TollfreeVerificationUpdater setMessageVolume( + final String messageVolume + ) { + this.messageVolume = messageVolume; + return this; + } + + public TollfreeVerificationUpdater setBusinessStreetAddress( + final String businessStreetAddress + ) { + this.businessStreetAddress = businessStreetAddress; + return this; + } + + public TollfreeVerificationUpdater setBusinessStreetAddress2( + final String businessStreetAddress2 + ) { + this.businessStreetAddress2 = businessStreetAddress2; + return this; + } + + public TollfreeVerificationUpdater setBusinessCity( + final String businessCity + ) { + this.businessCity = businessCity; + return this; + } + + public TollfreeVerificationUpdater setBusinessStateProvinceRegion( + final String businessStateProvinceRegion + ) { + this.businessStateProvinceRegion = businessStateProvinceRegion; + return this; + } + + public TollfreeVerificationUpdater setBusinessPostalCode( + final String businessPostalCode + ) { + this.businessPostalCode = businessPostalCode; + return this; + } + + public TollfreeVerificationUpdater setBusinessCountry( + final String businessCountry + ) { + this.businessCountry = businessCountry; + return this; + } + + public TollfreeVerificationUpdater setAdditionalInformation( + final String additionalInformation + ) { + this.additionalInformation = additionalInformation; + return this; + } + + public TollfreeVerificationUpdater setBusinessContactFirstName( + final String businessContactFirstName + ) { + this.businessContactFirstName = businessContactFirstName; + return this; + } + + public TollfreeVerificationUpdater setBusinessContactLastName( + final String businessContactLastName + ) { + this.businessContactLastName = businessContactLastName; + return this; + } + + public TollfreeVerificationUpdater setBusinessContactEmail( + final String businessContactEmail + ) { + this.businessContactEmail = businessContactEmail; + return this; + } + + public TollfreeVerificationUpdater setBusinessContactPhone( + final com.twilio.type.PhoneNumber businessContactPhone + ) { + this.businessContactPhone = businessContactPhone; + return this; + } + + public TollfreeVerificationUpdater setBusinessContactPhone( + final String businessContactPhone + ) { + return setBusinessContactPhone( + Promoter.phoneNumberFromString(businessContactPhone) + ); + } + + @Override + public TollfreeVerification update(final TwilioRestClient client) { + String path = "/v1/Tollfree/Verifications/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.MESSAGING.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "TollfreeVerification update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException("Server Error, no content"); + } + throw new ApiException(restException); + } + + return TollfreeVerification.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + private void addPostParams(final Request request) { + if (businessName != null) { + request.addPostParam("BusinessName", businessName); + } + if (businessWebsite != null) { + request.addPostParam("BusinessWebsite", businessWebsite); + } + if (notificationEmail != null) { + request.addPostParam("NotificationEmail", notificationEmail); + } + if (useCaseCategories != null) { + for (String prop : useCaseCategories) { + request.addPostParam("UseCaseCategories", prop); + } + } + if (useCaseSummary != null) { + request.addPostParam("UseCaseSummary", useCaseSummary); + } + if (productionMessageSample != null) { + request.addPostParam( + "ProductionMessageSample", + productionMessageSample + ); + } + if (optInImageUrls != null) { + for (String prop : optInImageUrls) { + request.addPostParam("OptInImageUrls", prop); + } + } + if (optInType != null) { + request.addPostParam("OptInType", optInType.toString()); + } + if (messageVolume != null) { + request.addPostParam("MessageVolume", messageVolume); + } + if (businessStreetAddress != null) { + request.addPostParam( + "BusinessStreetAddress", + businessStreetAddress + ); + } + if (businessStreetAddress2 != null) { + request.addPostParam( + "BusinessStreetAddress2", + businessStreetAddress2 + ); + } + if (businessCity != null) { + request.addPostParam("BusinessCity", businessCity); + } + if (businessStateProvinceRegion != null) { + request.addPostParam( + "BusinessStateProvinceRegion", + businessStateProvinceRegion + ); + } + if (businessPostalCode != null) { + request.addPostParam("BusinessPostalCode", businessPostalCode); + } + if (businessCountry != null) { + request.addPostParam("BusinessCountry", businessCountry); + } + if (additionalInformation != null) { + request.addPostParam( + "AdditionalInformation", + additionalInformation + ); + } + if (businessContactFirstName != null) { + request.addPostParam( + "BusinessContactFirstName", + businessContactFirstName + ); + } + if (businessContactLastName != null) { + request.addPostParam( + "BusinessContactLastName", + businessContactLastName + ); + } + if (businessContactEmail != null) { + request.addPostParam("BusinessContactEmail", businessContactEmail); + } + if (businessContactPhone != null) { + request.addPostParam( + "BusinessContactPhone", + businessContactPhone.toString() + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/Usecase.java b/src/main/java/com/twilio/rest/messaging/v1/Usecase.java index 864a3a981e..292cfb83b1 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/Usecase.java +++ b/src/main/java/com/twilio/rest/messaging/v1/Usecase.java @@ -22,38 +22,37 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; - import java.util.List; import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Usecase extends Resource { + private static final long serialVersionUID = 232787447190817L; - public static UsecaseFetcher fetcher(){ + public static UsecaseFetcher fetcher() { return new UsecaseFetcher(); } /** - * Converts a JSON String into a Usecase object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Usecase object represented by the provided JSON - */ - public static Usecase fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Usecase object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Usecase object represented by the provided JSON + */ + public static Usecase fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Usecase.class); @@ -65,14 +64,17 @@ public static Usecase fromJson(final String json, final ObjectMapper objectMappe } /** - * Converts a JSON InputStream into a Usecase object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Usecase object represented by the provided JSON - */ - public static Usecase fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Usecase object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Usecase object represented by the provided JSON + */ + public static Usecase fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Usecase.class); @@ -87,19 +89,18 @@ public static Usecase fromJson(final InputStream json, final ObjectMapper object @JsonCreator private Usecase( - @JsonProperty("usecases") - final List> usecases + @JsonProperty("usecases") final List> usecases ) { this.usecases = usecases; } - public final List> getUsecases() { - return this.usecases; - } + public final List> getUsecases() { + return this.usecases; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -109,13 +110,11 @@ public boolean equals(final Object o) { Usecase other = (Usecase) o; - return Objects.equals(usecases, other.usecases) ; + return Objects.equals(usecases, other.usecases); } @Override public int hashCode() { return Objects.hash(usecases); } - } - diff --git a/src/main/java/com/twilio/rest/messaging/v1/UsecaseFetcher.java b/src/main/java/com/twilio/rest/messaging/v1/UsecaseFetcher.java index 05ff187192..5decc12cf7 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/UsecaseFetcher.java +++ b/src/main/java/com/twilio/rest/messaging/v1/UsecaseFetcher.java @@ -24,20 +24,14 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class UsecaseFetcher extends Fetcher { - public UsecaseFetcher(){ - } - + public UsecaseFetcher() {} @Override public Usecase fetch(final TwilioRestClient client) { String path = "/v1/Services/Usecases"; - Request request = new Request( HttpMethod.GET, Domains.MESSAGING.toString(), @@ -46,9 +40,14 @@ public Usecase fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Usecase fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Usecase fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/messaging/v1/brandregistration/BrandRegistrationOtp.java b/src/main/java/com/twilio/rest/messaging/v1/brandregistration/BrandRegistrationOtp.java index e8f1e9f7b0..165f5acc23 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/brandregistration/BrandRegistrationOtp.java +++ b/src/main/java/com/twilio/rest/messaging/v1/brandregistration/BrandRegistrationOtp.java @@ -22,35 +22,36 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class BrandRegistrationOtp extends Resource { + private static final long serialVersionUID = 131615733171627L; - public static BrandRegistrationOtpCreator creator(final String pathBrandRegistrationSid){ + public static BrandRegistrationOtpCreator creator( + final String pathBrandRegistrationSid + ) { return new BrandRegistrationOtpCreator(pathBrandRegistrationSid); } /** - * Converts a JSON String into a BrandRegistrationOtp object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return BrandRegistrationOtp object represented by the provided JSON - */ - public static BrandRegistrationOtp fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a BrandRegistrationOtp object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return BrandRegistrationOtp object represented by the provided JSON + */ + public static BrandRegistrationOtp fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, BrandRegistrationOtp.class); @@ -62,14 +63,17 @@ public static BrandRegistrationOtp fromJson(final String json, final ObjectMappe } /** - * Converts a JSON InputStream into a BrandRegistrationOtp object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return BrandRegistrationOtp object represented by the provided JSON - */ - public static BrandRegistrationOtp fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a BrandRegistrationOtp object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return BrandRegistrationOtp object represented by the provided JSON + */ + public static BrandRegistrationOtp fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, BrandRegistrationOtp.class); @@ -85,26 +89,26 @@ public static BrandRegistrationOtp fromJson(final InputStream json, final Object @JsonCreator private BrandRegistrationOtp( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("brand_registration_sid") - final String brandRegistrationSid + @JsonProperty("account_sid") final String accountSid, + @JsonProperty( + "brand_registration_sid" + ) final String brandRegistrationSid ) { this.accountSid = accountSid; this.brandRegistrationSid = brandRegistrationSid; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getBrandRegistrationSid() { - return this.brandRegistrationSid; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getBrandRegistrationSid() { + return this.brandRegistrationSid; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -114,13 +118,14 @@ public boolean equals(final Object o) { BrandRegistrationOtp other = (BrandRegistrationOtp) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(brandRegistrationSid, other.brandRegistrationSid) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(brandRegistrationSid, other.brandRegistrationSid) + ); } @Override public int hashCode() { return Objects.hash(accountSid, brandRegistrationSid); } - } - diff --git a/src/main/java/com/twilio/rest/messaging/v1/brandregistration/BrandRegistrationOtpCreator.java b/src/main/java/com/twilio/rest/messaging/v1/brandregistration/BrandRegistrationOtpCreator.java index 77878cc2e0..a0762d3733 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/brandregistration/BrandRegistrationOtpCreator.java +++ b/src/main/java/com/twilio/rest/messaging/v1/brandregistration/BrandRegistrationOtpCreator.java @@ -24,22 +24,24 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class BrandRegistrationOtpCreator extends Creator { - - -public class BrandRegistrationOtpCreator extends Creator{ private String pathBrandRegistrationSid; public BrandRegistrationOtpCreator(final String pathBrandRegistrationSid) { this.pathBrandRegistrationSid = pathBrandRegistrationSid; } - @Override - public BrandRegistrationOtp create(final TwilioRestClient client){ - String path = "/v1/a2p/BrandRegistrations/{BrandRegistrationSid}/SmsOtp"; + public BrandRegistrationOtp create(final TwilioRestClient client) { + String path = + "/v1/a2p/BrandRegistrations/{BrandRegistrationSid}/SmsOtp"; - path = path.replace("{"+"BrandRegistrationSid"+"}", this.pathBrandRegistrationSid.toString()); + path = + path.replace( + "{" + "BrandRegistrationSid" + "}", + this.pathBrandRegistrationSid.toString() + ); Request request = new Request( HttpMethod.POST, @@ -48,15 +50,23 @@ public BrandRegistrationOtp create(final TwilioRestClient client){ ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("BrandRegistrationOtp creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "BrandRegistrationOtp creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return BrandRegistrationOtp.fromJson(response.getStream(), client.getObjectMapper()); + return BrandRegistrationOtp.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/messaging/v1/brandregistration/BrandVetting.java b/src/main/java/com/twilio/rest/messaging/v1/brandregistration/BrandVetting.java index b7cea631d8..b6028b9b5e 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/brandregistration/BrandVetting.java +++ b/src/main/java/com/twilio/rest/messaging/v1/brandregistration/BrandVetting.java @@ -24,45 +24,50 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class BrandVetting extends Resource { + private static final long serialVersionUID = 122020517475795L; - public static BrandVettingCreator creator(final String pathBrandSid, final BrandVetting.VettingProvider vettingProvider){ + public static BrandVettingCreator creator( + final String pathBrandSid, + final BrandVetting.VettingProvider vettingProvider + ) { return new BrandVettingCreator(pathBrandSid, vettingProvider); } - public static BrandVettingFetcher fetcher(final String pathBrandSid, final String pathBrandVettingSid){ + public static BrandVettingFetcher fetcher( + final String pathBrandSid, + final String pathBrandVettingSid + ) { return new BrandVettingFetcher(pathBrandSid, pathBrandVettingSid); } - public static BrandVettingReader reader(final String pathBrandSid){ + public static BrandVettingReader reader(final String pathBrandSid) { return new BrandVettingReader(pathBrandSid); } /** - * Converts a JSON String into a BrandVetting object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return BrandVetting object represented by the provided JSON - */ - public static BrandVetting fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a BrandVetting object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return BrandVetting object represented by the provided JSON + */ + public static BrandVetting fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, BrandVetting.class); @@ -74,14 +79,17 @@ public static BrandVetting fromJson(final String json, final ObjectMapper object } /** - * Converts a JSON InputStream into a BrandVetting object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return BrandVetting object represented by the provided JSON - */ - public static BrandVetting fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a BrandVetting object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return BrandVetting object represented by the provided JSON + */ + public static BrandVetting fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, BrandVetting.class); @@ -91,6 +99,7 @@ public static BrandVetting fromJson(final InputStream json, final ObjectMapper o throw new ApiConnectionException(e.getMessage(), e); } } + public enum VettingProvider { CAMPAIGN_VERIFY("campaign-verify"); @@ -123,35 +132,18 @@ public static VettingProvider forValue(final String value) { @JsonCreator private BrandVetting( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("brand_sid") - final String brandSid, - - @JsonProperty("brand_vetting_sid") - final String brandVettingSid, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("vetting_id") - final String vettingId, - - @JsonProperty("vetting_class") - final String vettingClass, - - @JsonProperty("vetting_status") - final String vettingStatus, - - @JsonProperty("vetting_provider") - final BrandVetting.VettingProvider vettingProvider, - - @JsonProperty("url") - final URI url + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("brand_sid") final String brandSid, + @JsonProperty("brand_vetting_sid") final String brandVettingSid, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("vetting_id") final String vettingId, + @JsonProperty("vetting_class") final String vettingClass, + @JsonProperty("vetting_status") final String vettingStatus, + @JsonProperty( + "vetting_provider" + ) final BrandVetting.VettingProvider vettingProvider, + @JsonProperty("url") final URI url ) { this.accountSid = accountSid; this.brandSid = brandSid; @@ -165,40 +157,49 @@ private BrandVetting( this.url = url; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getBrandSid() { - return this.brandSid; - } - public final String getBrandVettingSid() { - return this.brandVettingSid; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final String getVettingId() { - return this.vettingId; - } - public final String getVettingClass() { - return this.vettingClass; - } - public final String getVettingStatus() { - return this.vettingStatus; - } - public final BrandVetting.VettingProvider getVettingProvider() { - return this.vettingProvider; - } - public final URI getUrl() { - return this.url; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getBrandSid() { + return this.brandSid; + } + + public final String getBrandVettingSid() { + return this.brandVettingSid; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final String getVettingId() { + return this.vettingId; + } + + public final String getVettingClass() { + return this.vettingClass; + } + + public final String getVettingStatus() { + return this.vettingStatus; + } + + public final BrandVetting.VettingProvider getVettingProvider() { + return this.vettingProvider; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -208,13 +209,33 @@ public boolean equals(final Object o) { BrandVetting other = (BrandVetting) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(brandSid, other.brandSid) && Objects.equals(brandVettingSid, other.brandVettingSid) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(vettingId, other.vettingId) && Objects.equals(vettingClass, other.vettingClass) && Objects.equals(vettingStatus, other.vettingStatus) && Objects.equals(vettingProvider, other.vettingProvider) && Objects.equals(url, other.url) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(brandSid, other.brandSid) && + Objects.equals(brandVettingSid, other.brandVettingSid) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(vettingId, other.vettingId) && + Objects.equals(vettingClass, other.vettingClass) && + Objects.equals(vettingStatus, other.vettingStatus) && + Objects.equals(vettingProvider, other.vettingProvider) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, brandSid, brandVettingSid, dateUpdated, dateCreated, vettingId, vettingClass, vettingStatus, vettingProvider, url); + return Objects.hash( + accountSid, + brandSid, + brandVettingSid, + dateUpdated, + dateCreated, + vettingId, + vettingClass, + vettingStatus, + vettingProvider, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/messaging/v1/brandregistration/BrandVettingCreator.java b/src/main/java/com/twilio/rest/messaging/v1/brandregistration/BrandVettingCreator.java index 7e71bf6a57..8d29830345 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/brandregistration/BrandVettingCreator.java +++ b/src/main/java/com/twilio/rest/messaging/v1/brandregistration/BrandVettingCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.messaging.v1.brandregistration; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,62 +25,79 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class BrandVettingCreator extends Creator { - - -public class BrandVettingCreator extends Creator{ private String pathBrandSid; private BrandVetting.VettingProvider vettingProvider; private String vettingId; - public BrandVettingCreator(final String pathBrandSid, final BrandVetting.VettingProvider vettingProvider) { + public BrandVettingCreator( + final String pathBrandSid, + final BrandVetting.VettingProvider vettingProvider + ) { this.pathBrandSid = pathBrandSid; this.vettingProvider = vettingProvider; } - public BrandVettingCreator setVettingProvider(final BrandVetting.VettingProvider vettingProvider){ + public BrandVettingCreator setVettingProvider( + final BrandVetting.VettingProvider vettingProvider + ) { this.vettingProvider = vettingProvider; return this; } - public BrandVettingCreator setVettingId(final String vettingId){ + + public BrandVettingCreator setVettingId(final String vettingId) { this.vettingId = vettingId; return this; } @Override - public BrandVetting create(final TwilioRestClient client){ + public BrandVetting create(final TwilioRestClient client) { String path = "/v1/a2p/BrandRegistrations/{BrandSid}/Vettings"; - path = path.replace("{"+"BrandSid"+"}", this.pathBrandSid.toString()); - path = path.replace("{"+"VettingProvider"+"}", this.vettingProvider.toString()); + path = + path.replace("{" + "BrandSid" + "}", this.pathBrandSid.toString()); + path = + path.replace( + "{" + "VettingProvider" + "}", + this.vettingProvider.toString() + ); Request request = new Request( HttpMethod.POST, Domains.MESSAGING.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("BrandVetting creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "BrandVetting creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return BrandVetting.fromJson(response.getStream(), client.getObjectMapper()); + return BrandVetting.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (vettingProvider != null) { request.addPostParam("VettingProvider", vettingProvider.toString()); - } if (vettingId != null) { request.addPostParam("VettingId", vettingId); - } } } diff --git a/src/main/java/com/twilio/rest/messaging/v1/brandregistration/BrandVettingFetcher.java b/src/main/java/com/twilio/rest/messaging/v1/brandregistration/BrandVettingFetcher.java index c49239677a..e15dbe2995 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/brandregistration/BrandVettingFetcher.java +++ b/src/main/java/com/twilio/rest/messaging/v1/brandregistration/BrandVettingFetcher.java @@ -24,25 +24,31 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class BrandVettingFetcher extends Fetcher { + private String pathBrandSid; private String pathBrandVettingSid; - public BrandVettingFetcher(final String pathBrandSid, final String pathBrandVettingSid){ + public BrandVettingFetcher( + final String pathBrandSid, + final String pathBrandVettingSid + ) { this.pathBrandSid = pathBrandSid; this.pathBrandVettingSid = pathBrandVettingSid; } - @Override public BrandVetting fetch(final TwilioRestClient client) { - String path = "/v1/a2p/BrandRegistrations/{BrandSid}/Vettings/{BrandVettingSid}"; + String path = + "/v1/a2p/BrandRegistrations/{BrandSid}/Vettings/{BrandVettingSid}"; - path = path.replace("{"+"BrandSid"+"}", this.pathBrandSid.toString()); - path = path.replace("{"+"BrandVettingSid"+"}", this.pathBrandVettingSid.toString()); + path = + path.replace("{" + "BrandSid" + "}", this.pathBrandSid.toString()); + path = + path.replace( + "{" + "BrandVettingSid" + "}", + this.pathBrandVettingSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -52,15 +58,23 @@ public BrandVetting fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("BrandVetting fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "BrandVetting fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return BrandVetting.fromJson(response.getStream(), client.getObjectMapper()); + return BrandVetting.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/messaging/v1/brandregistration/BrandVettingReader.java b/src/main/java/com/twilio/rest/messaging/v1/brandregistration/BrandVettingReader.java index e6ebf8b883..3ebcd9fc0f 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/brandregistration/BrandVettingReader.java +++ b/src/main/java/com/twilio/rest/messaging/v1/brandregistration/BrandVettingReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.messaging.v1.brandregistration; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,24 +25,25 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class BrandVettingReader extends Reader { + private String pathBrandSid; private BrandVetting.VettingProvider vettingProvider; private Integer pageSize; - public BrandVettingReader(final String pathBrandSid){ + public BrandVettingReader(final String pathBrandSid) { this.pathBrandSid = pathBrandSid; } - public BrandVettingReader setVettingProvider(final BrandVetting.VettingProvider vettingProvider){ + public BrandVettingReader setVettingProvider( + final BrandVetting.VettingProvider vettingProvider + ) { this.vettingProvider = vettingProvider; return this; } - public BrandVettingReader setPageSize(final Integer pageSize){ + + public BrandVettingReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -53,7 +55,8 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/a2p/BrandRegistrations/{BrandSid}/Vettings"; - path = path.replace("{"+"BrandSid"+"}", this.pathBrandSid.toString()); + path = + path.replace("{" + "BrandSid" + "}", this.pathBrandSid.toString()); Request request = new Request( HttpMethod.GET, @@ -65,13 +68,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("BrandVetting read failed: Unable to connect to server"); + throw new ApiConnectionException( + "BrandVetting read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -87,7 +98,10 @@ private Page pageForRequest(final TwilioRestClient client, final R } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.MESSAGING.toString()) @@ -95,9 +109,11 @@ public Page previousPage(final Page page, final Twil return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.MESSAGING.toString()) @@ -106,25 +122,27 @@ public Page nextPage(final Page page, final TwilioRe } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (vettingProvider != null) { - - request.addQueryParam("VettingProvider", vettingProvider.toString()); + request.addQueryParam( + "VettingProvider", + vettingProvider.toString() + ); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/messaging/v1/service/AlphaSender.java b/src/main/java/com/twilio/rest/messaging/v1/service/AlphaSender.java index 63267d8ab3..d13ad27315 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/service/AlphaSender.java +++ b/src/main/java/com/twilio/rest/messaging/v1/service/AlphaSender.java @@ -23,50 +23,58 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.List; import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class AlphaSender extends Resource { + private static final long serialVersionUID = 147044042659249L; - public static AlphaSenderCreator creator(final String pathServiceSid, final String alphaSender){ + public static AlphaSenderCreator creator( + final String pathServiceSid, + final String alphaSender + ) { return new AlphaSenderCreator(pathServiceSid, alphaSender); } - public static AlphaSenderDeleter deleter(final String pathServiceSid, final String pathSid){ + public static AlphaSenderDeleter deleter( + final String pathServiceSid, + final String pathSid + ) { return new AlphaSenderDeleter(pathServiceSid, pathSid); } - public static AlphaSenderFetcher fetcher(final String pathServiceSid, final String pathSid){ + public static AlphaSenderFetcher fetcher( + final String pathServiceSid, + final String pathSid + ) { return new AlphaSenderFetcher(pathServiceSid, pathSid); } - public static AlphaSenderReader reader(final String pathServiceSid){ + public static AlphaSenderReader reader(final String pathServiceSid) { return new AlphaSenderReader(pathServiceSid); } /** - * Converts a JSON String into a AlphaSender object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return AlphaSender object represented by the provided JSON - */ - public static AlphaSender fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a AlphaSender object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return AlphaSender object represented by the provided JSON + */ + public static AlphaSender fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, AlphaSender.class); @@ -78,14 +86,17 @@ public static AlphaSender fromJson(final String json, final ObjectMapper objectM } /** - * Converts a JSON InputStream into a AlphaSender object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return AlphaSender object represented by the provided JSON - */ - public static AlphaSender fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a AlphaSender object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return AlphaSender object represented by the provided JSON + */ + public static AlphaSender fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, AlphaSender.class); @@ -107,29 +118,14 @@ public static AlphaSender fromJson(final InputStream json, final ObjectMapper ob @JsonCreator private AlphaSender( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("alpha_sender") - final String alphaSender, - - @JsonProperty("capabilities") - final List capabilities, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("alpha_sender") final String alphaSender, + @JsonProperty("capabilities") final List capabilities, + @JsonProperty("url") final URI url ) { this.sid = sid; this.accountSid = accountSid; @@ -141,34 +137,41 @@ private AlphaSender( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getAlphaSender() { - return this.alphaSender; - } - public final List getCapabilities() { - return this.capabilities; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getAlphaSender() { + return this.alphaSender; + } + + public final List getCapabilities() { + return this.capabilities; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -178,13 +181,29 @@ public boolean equals(final Object o) { AlphaSender other = (AlphaSender) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(alphaSender, other.alphaSender) && Objects.equals(capabilities, other.capabilities) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(alphaSender, other.alphaSender) && + Objects.equals(capabilities, other.capabilities) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, serviceSid, dateCreated, dateUpdated, alphaSender, capabilities, url); + return Objects.hash( + sid, + accountSid, + serviceSid, + dateCreated, + dateUpdated, + alphaSender, + capabilities, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/messaging/v1/service/AlphaSenderCreator.java b/src/main/java/com/twilio/rest/messaging/v1/service/AlphaSenderCreator.java index 368cc70580..cf5ebc2292 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/service/AlphaSenderCreator.java +++ b/src/main/java/com/twilio/rest/messaging/v1/service/AlphaSenderCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.messaging.v1.service; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,53 +25,71 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class AlphaSenderCreator extends Creator { - - -public class AlphaSenderCreator extends Creator{ private String pathServiceSid; private String alphaSender; - public AlphaSenderCreator(final String pathServiceSid, final String alphaSender) { + public AlphaSenderCreator( + final String pathServiceSid, + final String alphaSender + ) { this.pathServiceSid = pathServiceSid; this.alphaSender = alphaSender; } - public AlphaSenderCreator setAlphaSender(final String alphaSender){ + public AlphaSenderCreator setAlphaSender(final String alphaSender) { this.alphaSender = alphaSender; return this; } @Override - public AlphaSender create(final TwilioRestClient client){ + public AlphaSender create(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/AlphaSenders"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"AlphaSender"+"}", this.alphaSender.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "AlphaSender" + "}", + this.alphaSender.toString() + ); Request request = new Request( HttpMethod.POST, Domains.MESSAGING.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AlphaSender creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "AlphaSender creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return AlphaSender.fromJson(response.getStream(), client.getObjectMapper()); + return AlphaSender.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (alphaSender != null) { request.addPostParam("AlphaSender", alphaSender); - } } } diff --git a/src/main/java/com/twilio/rest/messaging/v1/service/AlphaSenderDeleter.java b/src/main/java/com/twilio/rest/messaging/v1/service/AlphaSenderDeleter.java index 00f6ab2d6e..89344f281b 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/service/AlphaSenderDeleter.java +++ b/src/main/java/com/twilio/rest/messaging/v1/service/AlphaSenderDeleter.java @@ -24,24 +24,29 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class AlphaSenderDeleter extends Deleter { + private String pathServiceSid; private String pathSid; - public AlphaSenderDeleter(final String pathServiceSid, final String pathSid){ + public AlphaSenderDeleter( + final String pathServiceSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/AlphaSenders/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +56,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AlphaSender delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "AlphaSender delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/messaging/v1/service/AlphaSenderFetcher.java b/src/main/java/com/twilio/rest/messaging/v1/service/AlphaSenderFetcher.java index 645aca5a78..25e0a1f05d 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/service/AlphaSenderFetcher.java +++ b/src/main/java/com/twilio/rest/messaging/v1/service/AlphaSenderFetcher.java @@ -24,25 +24,29 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class AlphaSenderFetcher extends Fetcher { + private String pathServiceSid; private String pathSid; - public AlphaSenderFetcher(final String pathServiceSid, final String pathSid){ + public AlphaSenderFetcher( + final String pathServiceSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - @Override public AlphaSender fetch(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/AlphaSenders/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,15 +56,23 @@ public AlphaSender fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AlphaSender fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "AlphaSender fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return AlphaSender.fromJson(response.getStream(), client.getObjectMapper()); + return AlphaSender.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/messaging/v1/service/AlphaSenderReader.java b/src/main/java/com/twilio/rest/messaging/v1/service/AlphaSenderReader.java index 6046584a9f..9e537a61d2 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/service/AlphaSenderReader.java +++ b/src/main/java/com/twilio/rest/messaging/v1/service/AlphaSenderReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.messaging.v1.service; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,19 +25,17 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class AlphaSenderReader extends Reader { + private String pathServiceSid; private Integer pageSize; - public AlphaSenderReader(final String pathServiceSid){ + public AlphaSenderReader(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - public AlphaSenderReader setPageSize(final Integer pageSize){ + public AlphaSenderReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -48,7 +47,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/AlphaSenders"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -60,13 +63,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AlphaSender read failed: Unable to connect to server"); + throw new ApiConnectionException( + "AlphaSender read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +93,10 @@ private Page pageForRequest(final TwilioRestClient client, final Re } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.MESSAGING.toString()) @@ -90,9 +104,11 @@ public Page previousPage(final Page page, final Twilio return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.MESSAGING.toString()) @@ -101,21 +117,21 @@ public Page nextPage(final Page page, final TwilioRest } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/messaging/v1/service/PhoneNumber.java b/src/main/java/com/twilio/rest/messaging/v1/service/PhoneNumber.java index 3d1a01d8a4..453f546a87 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/service/PhoneNumber.java +++ b/src/main/java/com/twilio/rest/messaging/v1/service/PhoneNumber.java @@ -23,50 +23,58 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.List; import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class PhoneNumber extends Resource { + private static final long serialVersionUID = 272509077394294L; - public static PhoneNumberCreator creator(final String pathServiceSid, final String phoneNumberSid){ + public static PhoneNumberCreator creator( + final String pathServiceSid, + final String phoneNumberSid + ) { return new PhoneNumberCreator(pathServiceSid, phoneNumberSid); } - public static PhoneNumberDeleter deleter(final String pathServiceSid, final String pathSid){ + public static PhoneNumberDeleter deleter( + final String pathServiceSid, + final String pathSid + ) { return new PhoneNumberDeleter(pathServiceSid, pathSid); } - public static PhoneNumberFetcher fetcher(final String pathServiceSid, final String pathSid){ + public static PhoneNumberFetcher fetcher( + final String pathServiceSid, + final String pathSid + ) { return new PhoneNumberFetcher(pathServiceSid, pathSid); } - public static PhoneNumberReader reader(final String pathServiceSid){ + public static PhoneNumberReader reader(final String pathServiceSid) { return new PhoneNumberReader(pathServiceSid); } /** - * Converts a JSON String into a PhoneNumber object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return PhoneNumber object represented by the provided JSON - */ - public static PhoneNumber fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a PhoneNumber object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return PhoneNumber object represented by the provided JSON + */ + public static PhoneNumber fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, PhoneNumber.class); @@ -78,14 +86,17 @@ public static PhoneNumber fromJson(final String json, final ObjectMapper objectM } /** - * Converts a JSON InputStream into a PhoneNumber object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return PhoneNumber object represented by the provided JSON - */ - public static PhoneNumber fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a PhoneNumber object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return PhoneNumber object represented by the provided JSON + */ + public static PhoneNumber fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, PhoneNumber.class); @@ -108,32 +119,17 @@ public static PhoneNumber fromJson(final InputStream json, final ObjectMapper ob @JsonCreator private PhoneNumber( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("phone_number") - final com.twilio.type.PhoneNumber phoneNumber, - - @JsonProperty("country_code") - final String countryCode, - - @JsonProperty("capabilities") - final List capabilities, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty( + "phone_number" + ) final com.twilio.type.PhoneNumber phoneNumber, + @JsonProperty("country_code") final String countryCode, + @JsonProperty("capabilities") final List capabilities, + @JsonProperty("url") final URI url ) { this.sid = sid; this.accountSid = accountSid; @@ -146,37 +142,45 @@ private PhoneNumber( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final com.twilio.type.PhoneNumber getPhoneNumber() { - return this.phoneNumber; - } - public final String getCountryCode() { - return this.countryCode; - } - public final List getCapabilities() { - return this.capabilities; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final com.twilio.type.PhoneNumber getPhoneNumber() { + return this.phoneNumber; + } + + public final String getCountryCode() { + return this.countryCode; + } + + public final List getCapabilities() { + return this.capabilities; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -186,13 +190,31 @@ public boolean equals(final Object o) { PhoneNumber other = (PhoneNumber) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(phoneNumber, other.phoneNumber) && Objects.equals(countryCode, other.countryCode) && Objects.equals(capabilities, other.capabilities) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(phoneNumber, other.phoneNumber) && + Objects.equals(countryCode, other.countryCode) && + Objects.equals(capabilities, other.capabilities) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, serviceSid, dateCreated, dateUpdated, phoneNumber, countryCode, capabilities, url); + return Objects.hash( + sid, + accountSid, + serviceSid, + dateCreated, + dateUpdated, + phoneNumber, + countryCode, + capabilities, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/messaging/v1/service/PhoneNumberCreator.java b/src/main/java/com/twilio/rest/messaging/v1/service/PhoneNumberCreator.java index 3e82d1fa87..5b9e843d94 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/service/PhoneNumberCreator.java +++ b/src/main/java/com/twilio/rest/messaging/v1/service/PhoneNumberCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.messaging.v1.service; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,53 +25,71 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class PhoneNumberCreator extends Creator { - - -public class PhoneNumberCreator extends Creator{ private String pathServiceSid; private String phoneNumberSid; - public PhoneNumberCreator(final String pathServiceSid, final String phoneNumberSid) { + public PhoneNumberCreator( + final String pathServiceSid, + final String phoneNumberSid + ) { this.pathServiceSid = pathServiceSid; this.phoneNumberSid = phoneNumberSid; } - public PhoneNumberCreator setPhoneNumberSid(final String phoneNumberSid){ + public PhoneNumberCreator setPhoneNumberSid(final String phoneNumberSid) { this.phoneNumberSid = phoneNumberSid; return this; } @Override - public PhoneNumber create(final TwilioRestClient client){ + public PhoneNumber create(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/PhoneNumbers"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"PhoneNumberSid"+"}", this.phoneNumberSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "PhoneNumberSid" + "}", + this.phoneNumberSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.MESSAGING.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("PhoneNumber creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "PhoneNumber creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return PhoneNumber.fromJson(response.getStream(), client.getObjectMapper()); + return PhoneNumber.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (phoneNumberSid != null) { request.addPostParam("PhoneNumberSid", phoneNumberSid); - } } } diff --git a/src/main/java/com/twilio/rest/messaging/v1/service/PhoneNumberDeleter.java b/src/main/java/com/twilio/rest/messaging/v1/service/PhoneNumberDeleter.java index 5e4d5f6b00..e7d51ec5cc 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/service/PhoneNumberDeleter.java +++ b/src/main/java/com/twilio/rest/messaging/v1/service/PhoneNumberDeleter.java @@ -24,24 +24,29 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class PhoneNumberDeleter extends Deleter { + private String pathServiceSid; private String pathSid; - public PhoneNumberDeleter(final String pathServiceSid, final String pathSid){ + public PhoneNumberDeleter( + final String pathServiceSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/PhoneNumbers/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +56,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("PhoneNumber delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "PhoneNumber delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/messaging/v1/service/PhoneNumberFetcher.java b/src/main/java/com/twilio/rest/messaging/v1/service/PhoneNumberFetcher.java index 34767c0d67..5dd24bc78d 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/service/PhoneNumberFetcher.java +++ b/src/main/java/com/twilio/rest/messaging/v1/service/PhoneNumberFetcher.java @@ -24,25 +24,29 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class PhoneNumberFetcher extends Fetcher { + private String pathServiceSid; private String pathSid; - public PhoneNumberFetcher(final String pathServiceSid, final String pathSid){ + public PhoneNumberFetcher( + final String pathServiceSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - @Override public PhoneNumber fetch(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/PhoneNumbers/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,15 +56,23 @@ public PhoneNumber fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("PhoneNumber fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "PhoneNumber fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return PhoneNumber.fromJson(response.getStream(), client.getObjectMapper()); + return PhoneNumber.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/messaging/v1/service/PhoneNumberReader.java b/src/main/java/com/twilio/rest/messaging/v1/service/PhoneNumberReader.java index 6df7e19aa3..8f20cf5938 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/service/PhoneNumberReader.java +++ b/src/main/java/com/twilio/rest/messaging/v1/service/PhoneNumberReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.messaging.v1.service; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,19 +25,17 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class PhoneNumberReader extends Reader { + private String pathServiceSid; private Integer pageSize; - public PhoneNumberReader(final String pathServiceSid){ + public PhoneNumberReader(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - public PhoneNumberReader setPageSize(final Integer pageSize){ + public PhoneNumberReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -48,7 +47,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/PhoneNumbers"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -60,13 +63,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("PhoneNumber read failed: Unable to connect to server"); + throw new ApiConnectionException( + "PhoneNumber read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +93,10 @@ private Page pageForRequest(final TwilioRestClient client, final Re } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.MESSAGING.toString()) @@ -90,9 +104,11 @@ public Page previousPage(final Page page, final Twilio return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.MESSAGING.toString()) @@ -101,21 +117,21 @@ public Page nextPage(final Page page, final TwilioRest } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/messaging/v1/service/ShortCode.java b/src/main/java/com/twilio/rest/messaging/v1/service/ShortCode.java index 4669d8dd08..bafe69a882 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/service/ShortCode.java +++ b/src/main/java/com/twilio/rest/messaging/v1/service/ShortCode.java @@ -23,50 +23,58 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.List; import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class ShortCode extends Resource { + private static final long serialVersionUID = 25601319717810L; - public static ShortCodeCreator creator(final String pathServiceSid, final String shortCodeSid){ + public static ShortCodeCreator creator( + final String pathServiceSid, + final String shortCodeSid + ) { return new ShortCodeCreator(pathServiceSid, shortCodeSid); } - public static ShortCodeDeleter deleter(final String pathServiceSid, final String pathSid){ + public static ShortCodeDeleter deleter( + final String pathServiceSid, + final String pathSid + ) { return new ShortCodeDeleter(pathServiceSid, pathSid); } - public static ShortCodeFetcher fetcher(final String pathServiceSid, final String pathSid){ + public static ShortCodeFetcher fetcher( + final String pathServiceSid, + final String pathSid + ) { return new ShortCodeFetcher(pathServiceSid, pathSid); } - public static ShortCodeReader reader(final String pathServiceSid){ + public static ShortCodeReader reader(final String pathServiceSid) { return new ShortCodeReader(pathServiceSid); } /** - * Converts a JSON String into a ShortCode object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return ShortCode object represented by the provided JSON - */ - public static ShortCode fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a ShortCode object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return ShortCode object represented by the provided JSON + */ + public static ShortCode fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, ShortCode.class); @@ -78,14 +86,17 @@ public static ShortCode fromJson(final String json, final ObjectMapper objectMap } /** - * Converts a JSON InputStream into a ShortCode object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return ShortCode object represented by the provided JSON - */ - public static ShortCode fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a ShortCode object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return ShortCode object represented by the provided JSON + */ + public static ShortCode fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, ShortCode.class); @@ -108,32 +119,15 @@ public static ShortCode fromJson(final InputStream json, final ObjectMapper obje @JsonCreator private ShortCode( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("short_code") - final String shortCode, - - @JsonProperty("country_code") - final String countryCode, - - @JsonProperty("capabilities") - final List capabilities, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("short_code") final String shortCode, + @JsonProperty("country_code") final String countryCode, + @JsonProperty("capabilities") final List capabilities, + @JsonProperty("url") final URI url ) { this.sid = sid; this.accountSid = accountSid; @@ -146,37 +140,45 @@ private ShortCode( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getShortCode() { - return this.shortCode; - } - public final String getCountryCode() { - return this.countryCode; - } - public final List getCapabilities() { - return this.capabilities; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getShortCode() { + return this.shortCode; + } + + public final String getCountryCode() { + return this.countryCode; + } + + public final List getCapabilities() { + return this.capabilities; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -186,13 +188,31 @@ public boolean equals(final Object o) { ShortCode other = (ShortCode) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(shortCode, other.shortCode) && Objects.equals(countryCode, other.countryCode) && Objects.equals(capabilities, other.capabilities) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(shortCode, other.shortCode) && + Objects.equals(countryCode, other.countryCode) && + Objects.equals(capabilities, other.capabilities) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, serviceSid, dateCreated, dateUpdated, shortCode, countryCode, capabilities, url); + return Objects.hash( + sid, + accountSid, + serviceSid, + dateCreated, + dateUpdated, + shortCode, + countryCode, + capabilities, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/messaging/v1/service/ShortCodeCreator.java b/src/main/java/com/twilio/rest/messaging/v1/service/ShortCodeCreator.java index fb3ed6cbba..ec22bea0b0 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/service/ShortCodeCreator.java +++ b/src/main/java/com/twilio/rest/messaging/v1/service/ShortCodeCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.messaging.v1.service; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,53 +25,71 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class ShortCodeCreator extends Creator { - - -public class ShortCodeCreator extends Creator{ private String pathServiceSid; private String shortCodeSid; - public ShortCodeCreator(final String pathServiceSid, final String shortCodeSid) { + public ShortCodeCreator( + final String pathServiceSid, + final String shortCodeSid + ) { this.pathServiceSid = pathServiceSid; this.shortCodeSid = shortCodeSid; } - public ShortCodeCreator setShortCodeSid(final String shortCodeSid){ + public ShortCodeCreator setShortCodeSid(final String shortCodeSid) { this.shortCodeSid = shortCodeSid; return this; } @Override - public ShortCode create(final TwilioRestClient client){ + public ShortCode create(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/ShortCodes"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ShortCodeSid"+"}", this.shortCodeSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ShortCodeSid" + "}", + this.shortCodeSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.MESSAGING.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("ShortCode creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "ShortCode creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return ShortCode.fromJson(response.getStream(), client.getObjectMapper()); + return ShortCode.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (shortCodeSid != null) { request.addPostParam("ShortCodeSid", shortCodeSid); - } } } diff --git a/src/main/java/com/twilio/rest/messaging/v1/service/ShortCodeDeleter.java b/src/main/java/com/twilio/rest/messaging/v1/service/ShortCodeDeleter.java index 9dc6af1427..f1b42c2bd4 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/service/ShortCodeDeleter.java +++ b/src/main/java/com/twilio/rest/messaging/v1/service/ShortCodeDeleter.java @@ -24,24 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class ShortCodeDeleter extends Deleter { + private String pathServiceSid; private String pathSid; - public ShortCodeDeleter(final String pathServiceSid, final String pathSid){ + public ShortCodeDeleter(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/ShortCodes/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +53,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("ShortCode delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "ShortCode delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/messaging/v1/service/ShortCodeFetcher.java b/src/main/java/com/twilio/rest/messaging/v1/service/ShortCodeFetcher.java index 25c29382fc..ab8b77624e 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/service/ShortCodeFetcher.java +++ b/src/main/java/com/twilio/rest/messaging/v1/service/ShortCodeFetcher.java @@ -24,25 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class ShortCodeFetcher extends Fetcher { + private String pathServiceSid; private String pathSid; - public ShortCodeFetcher(final String pathServiceSid, final String pathSid){ + public ShortCodeFetcher(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - @Override public ShortCode fetch(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/ShortCodes/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,15 +53,23 @@ public ShortCode fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("ShortCode fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "ShortCode fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return ShortCode.fromJson(response.getStream(), client.getObjectMapper()); + return ShortCode.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/messaging/v1/service/ShortCodeReader.java b/src/main/java/com/twilio/rest/messaging/v1/service/ShortCodeReader.java index fa5723ebdd..bbae1546e3 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/service/ShortCodeReader.java +++ b/src/main/java/com/twilio/rest/messaging/v1/service/ShortCodeReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.messaging.v1.service; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,19 +25,17 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class ShortCodeReader extends Reader { + private String pathServiceSid; private Integer pageSize; - public ShortCodeReader(final String pathServiceSid){ + public ShortCodeReader(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - public ShortCodeReader setPageSize(final Integer pageSize){ + public ShortCodeReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -48,7 +47,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/ShortCodes"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -60,13 +63,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("ShortCode read failed: Unable to connect to server"); + throw new ApiConnectionException( + "ShortCode read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +93,10 @@ private Page pageForRequest(final TwilioRestClient client, final Requ } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.MESSAGING.toString()) @@ -90,9 +104,11 @@ public Page previousPage(final Page page, final TwilioRest return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.MESSAGING.toString()) @@ -101,21 +117,21 @@ public Page nextPage(final Page page, final TwilioRestClie } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/messaging/v1/service/UsAppToPerson.java b/src/main/java/com/twilio/rest/messaging/v1/service/UsAppToPerson.java index e2ab83ee48..7c3d638611 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/service/UsAppToPerson.java +++ b/src/main/java/com/twilio/rest/messaging/v1/service/UsAppToPerson.java @@ -23,52 +23,77 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.List; import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class UsAppToPerson extends Resource { + private static final long serialVersionUID = 67793860949596L; - public static UsAppToPersonCreator creator(final String pathMessagingServiceSid, final String brandRegistrationSid, final String description, final String messageFlow, final List messageSamples, final String usAppToPersonUsecase, final Boolean hasEmbeddedLinks, final Boolean hasEmbeddedPhone){ - return new UsAppToPersonCreator(pathMessagingServiceSid, brandRegistrationSid, description, messageFlow, messageSamples, usAppToPersonUsecase, hasEmbeddedLinks, hasEmbeddedPhone); + public static UsAppToPersonCreator creator( + final String pathMessagingServiceSid, + final String brandRegistrationSid, + final String description, + final String messageFlow, + final List messageSamples, + final String usAppToPersonUsecase, + final Boolean hasEmbeddedLinks, + final Boolean hasEmbeddedPhone + ) { + return new UsAppToPersonCreator( + pathMessagingServiceSid, + brandRegistrationSid, + description, + messageFlow, + messageSamples, + usAppToPersonUsecase, + hasEmbeddedLinks, + hasEmbeddedPhone + ); } - public static UsAppToPersonDeleter deleter(final String pathMessagingServiceSid, final String pathSid){ + public static UsAppToPersonDeleter deleter( + final String pathMessagingServiceSid, + final String pathSid + ) { return new UsAppToPersonDeleter(pathMessagingServiceSid, pathSid); } - public static UsAppToPersonFetcher fetcher(final String pathMessagingServiceSid, final String pathSid){ + public static UsAppToPersonFetcher fetcher( + final String pathMessagingServiceSid, + final String pathSid + ) { return new UsAppToPersonFetcher(pathMessagingServiceSid, pathSid); } - public static UsAppToPersonReader reader(final String pathMessagingServiceSid){ + public static UsAppToPersonReader reader( + final String pathMessagingServiceSid + ) { return new UsAppToPersonReader(pathMessagingServiceSid); } /** - * Converts a JSON String into a UsAppToPerson object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return UsAppToPerson object represented by the provided JSON - */ - public static UsAppToPerson fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a UsAppToPerson object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return UsAppToPerson object represented by the provided JSON + */ + public static UsAppToPerson fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, UsAppToPerson.class); @@ -80,14 +105,17 @@ public static UsAppToPerson fromJson(final String json, final ObjectMapper objec } /** - * Converts a JSON InputStream into a UsAppToPerson object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return UsAppToPerson object represented by the provided JSON - */ - public static UsAppToPerson fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a UsAppToPerson object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return UsAppToPerson object represented by the provided JSON + */ + public static UsAppToPerson fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, UsAppToPerson.class); @@ -126,80 +154,37 @@ public static UsAppToPerson fromJson(final InputStream json, final ObjectMapper @JsonCreator private UsAppToPerson( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("brand_registration_sid") - final String brandRegistrationSid, - - @JsonProperty("messaging_service_sid") - final String messagingServiceSid, - - @JsonProperty("description") - final String description, - - @JsonProperty("message_samples") - final List messageSamples, - - @JsonProperty("us_app_to_person_usecase") - final String usAppToPersonUsecase, - - @JsonProperty("has_embedded_links") - final Boolean hasEmbeddedLinks, - - @JsonProperty("has_embedded_phone") - final Boolean hasEmbeddedPhone, - - @JsonProperty("campaign_status") - final String campaignStatus, - - @JsonProperty("campaign_id") - final String campaignId, - - @JsonProperty("is_externally_registered") - final Boolean isExternallyRegistered, - - @JsonProperty("rate_limits") - final Map rateLimits, - - @JsonProperty("message_flow") - final String messageFlow, - - @JsonProperty("opt_in_message") - final String optInMessage, - - @JsonProperty("opt_out_message") - final String optOutMessage, - - @JsonProperty("help_message") - final String helpMessage, - - @JsonProperty("opt_in_keywords") - final List optInKeywords, - - @JsonProperty("opt_out_keywords") - final List optOutKeywords, - - @JsonProperty("help_keywords") - final List helpKeywords, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url, - - @JsonProperty("mock") - final Boolean mock, - - @JsonProperty("errors") - final List> errors + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty( + "brand_registration_sid" + ) final String brandRegistrationSid, + @JsonProperty("messaging_service_sid") final String messagingServiceSid, + @JsonProperty("description") final String description, + @JsonProperty("message_samples") final List messageSamples, + @JsonProperty( + "us_app_to_person_usecase" + ) final String usAppToPersonUsecase, + @JsonProperty("has_embedded_links") final Boolean hasEmbeddedLinks, + @JsonProperty("has_embedded_phone") final Boolean hasEmbeddedPhone, + @JsonProperty("campaign_status") final String campaignStatus, + @JsonProperty("campaign_id") final String campaignId, + @JsonProperty( + "is_externally_registered" + ) final Boolean isExternallyRegistered, + @JsonProperty("rate_limits") final Map rateLimits, + @JsonProperty("message_flow") final String messageFlow, + @JsonProperty("opt_in_message") final String optInMessage, + @JsonProperty("opt_out_message") final String optOutMessage, + @JsonProperty("help_message") final String helpMessage, + @JsonProperty("opt_in_keywords") final List optInKeywords, + @JsonProperty("opt_out_keywords") final List optOutKeywords, + @JsonProperty("help_keywords") final List helpKeywords, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url, + @JsonProperty("mock") final Boolean mock, + @JsonProperty("errors") final List> errors ) { this.sid = sid; this.accountSid = accountSid; @@ -228,85 +213,109 @@ private UsAppToPerson( this.errors = errors; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getBrandRegistrationSid() { - return this.brandRegistrationSid; - } - public final String getMessagingServiceSid() { - return this.messagingServiceSid; - } - public final String getDescription() { - return this.description; - } - public final List getMessageSamples() { - return this.messageSamples; - } - public final String getUsAppToPersonUsecase() { - return this.usAppToPersonUsecase; - } - public final Boolean getHasEmbeddedLinks() { - return this.hasEmbeddedLinks; - } - public final Boolean getHasEmbeddedPhone() { - return this.hasEmbeddedPhone; - } - public final String getCampaignStatus() { - return this.campaignStatus; - } - public final String getCampaignId() { - return this.campaignId; - } - public final Boolean getIsExternallyRegistered() { - return this.isExternallyRegistered; - } - public final Map getRateLimits() { - return this.rateLimits; - } - public final String getMessageFlow() { - return this.messageFlow; - } - public final String getOptInMessage() { - return this.optInMessage; - } - public final String getOptOutMessage() { - return this.optOutMessage; - } - public final String getHelpMessage() { - return this.helpMessage; - } - public final List getOptInKeywords() { - return this.optInKeywords; - } - public final List getOptOutKeywords() { - return this.optOutKeywords; - } - public final List getHelpKeywords() { - return this.helpKeywords; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } - public final Boolean getMock() { - return this.mock; - } - public final List> getErrors() { - return this.errors; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getBrandRegistrationSid() { + return this.brandRegistrationSid; + } + + public final String getMessagingServiceSid() { + return this.messagingServiceSid; + } + + public final String getDescription() { + return this.description; + } + + public final List getMessageSamples() { + return this.messageSamples; + } + + public final String getUsAppToPersonUsecase() { + return this.usAppToPersonUsecase; + } + + public final Boolean getHasEmbeddedLinks() { + return this.hasEmbeddedLinks; + } + + public final Boolean getHasEmbeddedPhone() { + return this.hasEmbeddedPhone; + } + + public final String getCampaignStatus() { + return this.campaignStatus; + } + + public final String getCampaignId() { + return this.campaignId; + } + + public final Boolean getIsExternallyRegistered() { + return this.isExternallyRegistered; + } + + public final Map getRateLimits() { + return this.rateLimits; + } + + public final String getMessageFlow() { + return this.messageFlow; + } + + public final String getOptInMessage() { + return this.optInMessage; + } + + public final String getOptOutMessage() { + return this.optOutMessage; + } + + public final String getHelpMessage() { + return this.helpMessage; + } + + public final List getOptInKeywords() { + return this.optInKeywords; + } + + public final List getOptOutKeywords() { + return this.optOutKeywords; + } + + public final List getHelpKeywords() { + return this.helpKeywords; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } + + public final Boolean getMock() { + return this.mock; + } + + public final List> getErrors() { + return this.errors; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -316,13 +325,66 @@ public boolean equals(final Object o) { UsAppToPerson other = (UsAppToPerson) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(brandRegistrationSid, other.brandRegistrationSid) && Objects.equals(messagingServiceSid, other.messagingServiceSid) && Objects.equals(description, other.description) && Objects.equals(messageSamples, other.messageSamples) && Objects.equals(usAppToPersonUsecase, other.usAppToPersonUsecase) && Objects.equals(hasEmbeddedLinks, other.hasEmbeddedLinks) && Objects.equals(hasEmbeddedPhone, other.hasEmbeddedPhone) && Objects.equals(campaignStatus, other.campaignStatus) && Objects.equals(campaignId, other.campaignId) && Objects.equals(isExternallyRegistered, other.isExternallyRegistered) && Objects.equals(rateLimits, other.rateLimits) && Objects.equals(messageFlow, other.messageFlow) && Objects.equals(optInMessage, other.optInMessage) && Objects.equals(optOutMessage, other.optOutMessage) && Objects.equals(helpMessage, other.helpMessage) && Objects.equals(optInKeywords, other.optInKeywords) && Objects.equals(optOutKeywords, other.optOutKeywords) && Objects.equals(helpKeywords, other.helpKeywords) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) && Objects.equals(mock, other.mock) && Objects.equals(errors, other.errors) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(brandRegistrationSid, other.brandRegistrationSid) && + Objects.equals(messagingServiceSid, other.messagingServiceSid) && + Objects.equals(description, other.description) && + Objects.equals(messageSamples, other.messageSamples) && + Objects.equals(usAppToPersonUsecase, other.usAppToPersonUsecase) && + Objects.equals(hasEmbeddedLinks, other.hasEmbeddedLinks) && + Objects.equals(hasEmbeddedPhone, other.hasEmbeddedPhone) && + Objects.equals(campaignStatus, other.campaignStatus) && + Objects.equals(campaignId, other.campaignId) && + Objects.equals( + isExternallyRegistered, + other.isExternallyRegistered + ) && + Objects.equals(rateLimits, other.rateLimits) && + Objects.equals(messageFlow, other.messageFlow) && + Objects.equals(optInMessage, other.optInMessage) && + Objects.equals(optOutMessage, other.optOutMessage) && + Objects.equals(helpMessage, other.helpMessage) && + Objects.equals(optInKeywords, other.optInKeywords) && + Objects.equals(optOutKeywords, other.optOutKeywords) && + Objects.equals(helpKeywords, other.helpKeywords) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) && + Objects.equals(mock, other.mock) && + Objects.equals(errors, other.errors) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, brandRegistrationSid, messagingServiceSid, description, messageSamples, usAppToPersonUsecase, hasEmbeddedLinks, hasEmbeddedPhone, campaignStatus, campaignId, isExternallyRegistered, rateLimits, messageFlow, optInMessage, optOutMessage, helpMessage, optInKeywords, optOutKeywords, helpKeywords, dateCreated, dateUpdated, url, mock, errors); + return Objects.hash( + sid, + accountSid, + brandRegistrationSid, + messagingServiceSid, + description, + messageSamples, + usAppToPersonUsecase, + hasEmbeddedLinks, + hasEmbeddedPhone, + campaignStatus, + campaignId, + isExternallyRegistered, + rateLimits, + messageFlow, + optInMessage, + optOutMessage, + helpMessage, + optInKeywords, + optOutKeywords, + helpKeywords, + dateCreated, + dateUpdated, + url, + mock, + errors + ); } - } - diff --git a/src/main/java/com/twilio/rest/messaging/v1/service/UsAppToPersonCreator.java b/src/main/java/com/twilio/rest/messaging/v1/service/UsAppToPersonCreator.java index dc5045af57..c24158c8ef 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/service/UsAppToPersonCreator.java +++ b/src/main/java/com/twilio/rest/messaging/v1/service/UsAppToPersonCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.messaging.v1.service; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -25,12 +26,10 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.util.List; - import java.util.List; +public class UsAppToPersonCreator extends Creator { - -public class UsAppToPersonCreator extends Creator{ private String pathMessagingServiceSid; private String brandRegistrationSid; private String description; @@ -46,7 +45,16 @@ public class UsAppToPersonCreator extends Creator{ private List optOutKeywords; private List helpKeywords; - public UsAppToPersonCreator(final String pathMessagingServiceSid, final String brandRegistrationSid, final String description, final String messageFlow, final List messageSamples, final String usAppToPersonUsecase, final Boolean hasEmbeddedLinks, final Boolean hasEmbeddedPhone) { + public UsAppToPersonCreator( + final String pathMessagingServiceSid, + final String brandRegistrationSid, + final String description, + final String messageFlow, + final List messageSamples, + final String usAppToPersonUsecase, + final Boolean hasEmbeddedLinks, + final Boolean hasEmbeddedPhone + ) { this.pathMessagingServiceSid = pathMessagingServiceSid; this.brandRegistrationSid = brandRegistrationSid; this.description = description; @@ -57,163 +65,230 @@ public UsAppToPersonCreator(final String pathMessagingServiceSid, final String b this.hasEmbeddedPhone = hasEmbeddedPhone; } - public UsAppToPersonCreator setBrandRegistrationSid(final String brandRegistrationSid){ + public UsAppToPersonCreator setBrandRegistrationSid( + final String brandRegistrationSid + ) { this.brandRegistrationSid = brandRegistrationSid; return this; } - public UsAppToPersonCreator setDescription(final String description){ + + public UsAppToPersonCreator setDescription(final String description) { this.description = description; return this; } - public UsAppToPersonCreator setMessageFlow(final String messageFlow){ + + public UsAppToPersonCreator setMessageFlow(final String messageFlow) { this.messageFlow = messageFlow; return this; } - public UsAppToPersonCreator setMessageSamples(final List messageSamples){ + + public UsAppToPersonCreator setMessageSamples( + final List messageSamples + ) { this.messageSamples = messageSamples; return this; } - public UsAppToPersonCreator setMessageSamples(final String messageSamples){ + + public UsAppToPersonCreator setMessageSamples(final String messageSamples) { return setMessageSamples(Promoter.listOfOne(messageSamples)); } - public UsAppToPersonCreator setUsAppToPersonUsecase(final String usAppToPersonUsecase){ + + public UsAppToPersonCreator setUsAppToPersonUsecase( + final String usAppToPersonUsecase + ) { this.usAppToPersonUsecase = usAppToPersonUsecase; return this; } - public UsAppToPersonCreator setHasEmbeddedLinks(final Boolean hasEmbeddedLinks){ + + public UsAppToPersonCreator setHasEmbeddedLinks( + final Boolean hasEmbeddedLinks + ) { this.hasEmbeddedLinks = hasEmbeddedLinks; return this; } - public UsAppToPersonCreator setHasEmbeddedPhone(final Boolean hasEmbeddedPhone){ + + public UsAppToPersonCreator setHasEmbeddedPhone( + final Boolean hasEmbeddedPhone + ) { this.hasEmbeddedPhone = hasEmbeddedPhone; return this; } - public UsAppToPersonCreator setOptInMessage(final String optInMessage){ + + public UsAppToPersonCreator setOptInMessage(final String optInMessage) { this.optInMessage = optInMessage; return this; } - public UsAppToPersonCreator setOptOutMessage(final String optOutMessage){ + + public UsAppToPersonCreator setOptOutMessage(final String optOutMessage) { this.optOutMessage = optOutMessage; return this; } - public UsAppToPersonCreator setHelpMessage(final String helpMessage){ + + public UsAppToPersonCreator setHelpMessage(final String helpMessage) { this.helpMessage = helpMessage; return this; } - public UsAppToPersonCreator setOptInKeywords(final List optInKeywords){ + + public UsAppToPersonCreator setOptInKeywords( + final List optInKeywords + ) { this.optInKeywords = optInKeywords; return this; } - public UsAppToPersonCreator setOptInKeywords(final String optInKeywords){ + + public UsAppToPersonCreator setOptInKeywords(final String optInKeywords) { return setOptInKeywords(Promoter.listOfOne(optInKeywords)); } - public UsAppToPersonCreator setOptOutKeywords(final List optOutKeywords){ + + public UsAppToPersonCreator setOptOutKeywords( + final List optOutKeywords + ) { this.optOutKeywords = optOutKeywords; return this; } - public UsAppToPersonCreator setOptOutKeywords(final String optOutKeywords){ + + public UsAppToPersonCreator setOptOutKeywords(final String optOutKeywords) { return setOptOutKeywords(Promoter.listOfOne(optOutKeywords)); } - public UsAppToPersonCreator setHelpKeywords(final List helpKeywords){ + + public UsAppToPersonCreator setHelpKeywords( + final List helpKeywords + ) { this.helpKeywords = helpKeywords; return this; } - public UsAppToPersonCreator setHelpKeywords(final String helpKeywords){ + + public UsAppToPersonCreator setHelpKeywords(final String helpKeywords) { return setHelpKeywords(Promoter.listOfOne(helpKeywords)); } @Override - public UsAppToPerson create(final TwilioRestClient client){ + public UsAppToPerson create(final TwilioRestClient client) { String path = "/v1/Services/{MessagingServiceSid}/Compliance/Usa2p"; - path = path.replace("{"+"MessagingServiceSid"+"}", this.pathMessagingServiceSid.toString()); - path = path.replace("{"+"BrandRegistrationSid"+"}", this.brandRegistrationSid.toString()); - path = path.replace("{"+"Description"+"}", this.description.toString()); - path = path.replace("{"+"MessageFlow"+"}", this.messageFlow.toString()); - path = path.replace("{"+"MessageSamples"+"}", this.messageSamples.toString()); - path = path.replace("{"+"UsAppToPersonUsecase"+"}", this.usAppToPersonUsecase.toString()); - path = path.replace("{"+"HasEmbeddedLinks"+"}", this.hasEmbeddedLinks.toString()); - path = path.replace("{"+"HasEmbeddedPhone"+"}", this.hasEmbeddedPhone.toString()); + path = + path.replace( + "{" + "MessagingServiceSid" + "}", + this.pathMessagingServiceSid.toString() + ); + path = + path.replace( + "{" + "BrandRegistrationSid" + "}", + this.brandRegistrationSid.toString() + ); + path = + path.replace( + "{" + "Description" + "}", + this.description.toString() + ); + path = + path.replace( + "{" + "MessageFlow" + "}", + this.messageFlow.toString() + ); + path = + path.replace( + "{" + "MessageSamples" + "}", + this.messageSamples.toString() + ); + path = + path.replace( + "{" + "UsAppToPersonUsecase" + "}", + this.usAppToPersonUsecase.toString() + ); + path = + path.replace( + "{" + "HasEmbeddedLinks" + "}", + this.hasEmbeddedLinks.toString() + ); + path = + path.replace( + "{" + "HasEmbeddedPhone" + "}", + this.hasEmbeddedPhone.toString() + ); Request request = new Request( HttpMethod.POST, Domains.MESSAGING.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("UsAppToPerson creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "UsAppToPerson creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return UsAppToPerson.fromJson(response.getStream(), client.getObjectMapper()); + return UsAppToPerson.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (brandRegistrationSid != null) { request.addPostParam("BrandRegistrationSid", brandRegistrationSid); - } if (description != null) { request.addPostParam("Description", description); - } if (messageFlow != null) { request.addPostParam("MessageFlow", messageFlow); - } if (messageSamples != null) { for (String prop : messageSamples) { request.addPostParam("MessageSamples", prop); } - } if (usAppToPersonUsecase != null) { request.addPostParam("UsAppToPersonUsecase", usAppToPersonUsecase); - } if (hasEmbeddedLinks != null) { - request.addPostParam("HasEmbeddedLinks", hasEmbeddedLinks.toString()); - + request.addPostParam( + "HasEmbeddedLinks", + hasEmbeddedLinks.toString() + ); } if (hasEmbeddedPhone != null) { - request.addPostParam("HasEmbeddedPhone", hasEmbeddedPhone.toString()); - + request.addPostParam( + "HasEmbeddedPhone", + hasEmbeddedPhone.toString() + ); } if (optInMessage != null) { request.addPostParam("OptInMessage", optInMessage); - } if (optOutMessage != null) { request.addPostParam("OptOutMessage", optOutMessage); - } if (helpMessage != null) { request.addPostParam("HelpMessage", helpMessage); - } if (optInKeywords != null) { for (String prop : optInKeywords) { request.addPostParam("OptInKeywords", prop); } - } if (optOutKeywords != null) { for (String prop : optOutKeywords) { request.addPostParam("OptOutKeywords", prop); } - } if (helpKeywords != null) { for (String prop : helpKeywords) { request.addPostParam("HelpKeywords", prop); } - } } } diff --git a/src/main/java/com/twilio/rest/messaging/v1/service/UsAppToPersonDeleter.java b/src/main/java/com/twilio/rest/messaging/v1/service/UsAppToPersonDeleter.java index e3ca2046aa..a9605ad344 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/service/UsAppToPersonDeleter.java +++ b/src/main/java/com/twilio/rest/messaging/v1/service/UsAppToPersonDeleter.java @@ -24,24 +24,30 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class UsAppToPersonDeleter extends Deleter { + private String pathMessagingServiceSid; private String pathSid; - public UsAppToPersonDeleter(final String pathMessagingServiceSid, final String pathSid){ + public UsAppToPersonDeleter( + final String pathMessagingServiceSid, + final String pathSid + ) { this.pathMessagingServiceSid = pathMessagingServiceSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/v1/Services/{MessagingServiceSid}/Compliance/Usa2p/{Sid}"; + String path = + "/v1/Services/{MessagingServiceSid}/Compliance/Usa2p/{Sid}"; - path = path.replace("{"+"MessagingServiceSid"+"}", this.pathMessagingServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "MessagingServiceSid" + "}", + this.pathMessagingServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +57,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("UsAppToPerson delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "UsAppToPerson delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/messaging/v1/service/UsAppToPersonFetcher.java b/src/main/java/com/twilio/rest/messaging/v1/service/UsAppToPersonFetcher.java index d4cc56f295..f07f78ec60 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/service/UsAppToPersonFetcher.java +++ b/src/main/java/com/twilio/rest/messaging/v1/service/UsAppToPersonFetcher.java @@ -24,25 +24,30 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class UsAppToPersonFetcher extends Fetcher { + private String pathMessagingServiceSid; private String pathSid; - public UsAppToPersonFetcher(final String pathMessagingServiceSid, final String pathSid){ + public UsAppToPersonFetcher( + final String pathMessagingServiceSid, + final String pathSid + ) { this.pathMessagingServiceSid = pathMessagingServiceSid; this.pathSid = pathSid; } - @Override public UsAppToPerson fetch(final TwilioRestClient client) { - String path = "/v1/Services/{MessagingServiceSid}/Compliance/Usa2p/{Sid}"; + String path = + "/v1/Services/{MessagingServiceSid}/Compliance/Usa2p/{Sid}"; - path = path.replace("{"+"MessagingServiceSid"+"}", this.pathMessagingServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "MessagingServiceSid" + "}", + this.pathMessagingServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,15 +57,23 @@ public UsAppToPerson fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("UsAppToPerson fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "UsAppToPerson fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return UsAppToPerson.fromJson(response.getStream(), client.getObjectMapper()); + return UsAppToPerson.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/messaging/v1/service/UsAppToPersonReader.java b/src/main/java/com/twilio/rest/messaging/v1/service/UsAppToPersonReader.java index ebd9eb96e0..07134f2e86 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/service/UsAppToPersonReader.java +++ b/src/main/java/com/twilio/rest/messaging/v1/service/UsAppToPersonReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.messaging.v1.service; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,19 +25,17 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class UsAppToPersonReader extends Reader { + private String pathMessagingServiceSid; private Integer pageSize; - public UsAppToPersonReader(final String pathMessagingServiceSid){ + public UsAppToPersonReader(final String pathMessagingServiceSid) { this.pathMessagingServiceSid = pathMessagingServiceSid; } - public UsAppToPersonReader setPageSize(final Integer pageSize){ + public UsAppToPersonReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -48,7 +47,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Services/{MessagingServiceSid}/Compliance/Usa2p"; - path = path.replace("{"+"MessagingServiceSid"+"}", this.pathMessagingServiceSid.toString()); + path = + path.replace( + "{" + "MessagingServiceSid" + "}", + this.pathMessagingServiceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -60,13 +63,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("UsAppToPerson read failed: Unable to connect to server"); + throw new ApiConnectionException( + "UsAppToPerson read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +93,10 @@ private Page pageForRequest(final TwilioRestClient client, final } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.MESSAGING.toString()) @@ -90,9 +104,11 @@ public Page previousPage(final Page page, final Tw return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.MESSAGING.toString()) @@ -101,21 +117,21 @@ public Page nextPage(final Page page, final Twilio } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/messaging/v1/service/UsAppToPersonUsecase.java b/src/main/java/com/twilio/rest/messaging/v1/service/UsAppToPersonUsecase.java index b89b65b0f8..be8dc3f736 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/service/UsAppToPersonUsecase.java +++ b/src/main/java/com/twilio/rest/messaging/v1/service/UsAppToPersonUsecase.java @@ -22,38 +22,39 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; - import java.util.List; import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class UsAppToPersonUsecase extends Resource { + private static final long serialVersionUID = 181251380697241L; - public static UsAppToPersonUsecaseFetcher fetcher(final String pathMessagingServiceSid){ + public static UsAppToPersonUsecaseFetcher fetcher( + final String pathMessagingServiceSid + ) { return new UsAppToPersonUsecaseFetcher(pathMessagingServiceSid); } /** - * Converts a JSON String into a UsAppToPersonUsecase object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return UsAppToPersonUsecase object represented by the provided JSON - */ - public static UsAppToPersonUsecase fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a UsAppToPersonUsecase object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return UsAppToPersonUsecase object represented by the provided JSON + */ + public static UsAppToPersonUsecase fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, UsAppToPersonUsecase.class); @@ -65,14 +66,17 @@ public static UsAppToPersonUsecase fromJson(final String json, final ObjectMappe } /** - * Converts a JSON InputStream into a UsAppToPersonUsecase object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return UsAppToPersonUsecase object represented by the provided JSON - */ - public static UsAppToPersonUsecase fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a UsAppToPersonUsecase object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return UsAppToPersonUsecase object represented by the provided JSON + */ + public static UsAppToPersonUsecase fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, UsAppToPersonUsecase.class); @@ -87,19 +91,20 @@ public static UsAppToPersonUsecase fromJson(final InputStream json, final Object @JsonCreator private UsAppToPersonUsecase( - @JsonProperty("us_app_to_person_usecases") - final List> usAppToPersonUsecases + @JsonProperty( + "us_app_to_person_usecases" + ) final List> usAppToPersonUsecases ) { this.usAppToPersonUsecases = usAppToPersonUsecases; } - public final List> getUsAppToPersonUsecases() { - return this.usAppToPersonUsecases; - } + public final List> getUsAppToPersonUsecases() { + return this.usAppToPersonUsecases; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -109,13 +114,14 @@ public boolean equals(final Object o) { UsAppToPersonUsecase other = (UsAppToPersonUsecase) o; - return Objects.equals(usAppToPersonUsecases, other.usAppToPersonUsecases) ; + return Objects.equals( + usAppToPersonUsecases, + other.usAppToPersonUsecases + ); } @Override public int hashCode() { return Objects.hash(usAppToPersonUsecases); } - } - diff --git a/src/main/java/com/twilio/rest/messaging/v1/service/UsAppToPersonUsecaseFetcher.java b/src/main/java/com/twilio/rest/messaging/v1/service/UsAppToPersonUsecaseFetcher.java index 39f3cde821..f331bc188e 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/service/UsAppToPersonUsecaseFetcher.java +++ b/src/main/java/com/twilio/rest/messaging/v1/service/UsAppToPersonUsecaseFetcher.java @@ -24,27 +24,32 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class UsAppToPersonUsecaseFetcher extends Fetcher { + private String pathMessagingServiceSid; private String brandRegistrationSid; - public UsAppToPersonUsecaseFetcher(final String pathMessagingServiceSid){ + public UsAppToPersonUsecaseFetcher(final String pathMessagingServiceSid) { this.pathMessagingServiceSid = pathMessagingServiceSid; } - public UsAppToPersonUsecaseFetcher setBrandRegistrationSid(final String brandRegistrationSid){ + public UsAppToPersonUsecaseFetcher setBrandRegistrationSid( + final String brandRegistrationSid + ) { this.brandRegistrationSid = brandRegistrationSid; return this; } @Override public UsAppToPersonUsecase fetch(final TwilioRestClient client) { - String path = "/v1/Services/{MessagingServiceSid}/Compliance/Usa2p/Usecases"; + String path = + "/v1/Services/{MessagingServiceSid}/Compliance/Usa2p/Usecases"; - path = path.replace("{"+"MessagingServiceSid"+"}", this.pathMessagingServiceSid.toString()); + path = + path.replace( + "{" + "MessagingServiceSid" + "}", + this.pathMessagingServiceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -55,20 +60,28 @@ public UsAppToPersonUsecase fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("UsAppToPersonUsecase fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "UsAppToPersonUsecase fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return UsAppToPersonUsecase.fromJson(response.getStream(), client.getObjectMapper()); + return UsAppToPersonUsecase.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addQueryParams(final Request request) { if (brandRegistrationSid != null) { - request.addQueryParam("BrandRegistrationSid", brandRegistrationSid); } } diff --git a/src/main/java/com/twilio/rest/microvisor/v1/AccountConfig.java b/src/main/java/com/twilio/rest/microvisor/v1/AccountConfig.java index e3c4ff47a2..f51341b9ef 100644 --- a/src/main/java/com/twilio/rest/microvisor/v1/AccountConfig.java +++ b/src/main/java/com/twilio/rest/microvisor/v1/AccountConfig.java @@ -23,53 +23,58 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class AccountConfig extends Resource { + private static final long serialVersionUID = 212393375904180L; - public static AccountConfigCreator creator(final String key, final String value){ + public static AccountConfigCreator creator( + final String key, + final String value + ) { return new AccountConfigCreator(key, value); } - public static AccountConfigDeleter deleter(final String pathKey){ + public static AccountConfigDeleter deleter(final String pathKey) { return new AccountConfigDeleter(pathKey); } - public static AccountConfigFetcher fetcher(final String pathKey){ + public static AccountConfigFetcher fetcher(final String pathKey) { return new AccountConfigFetcher(pathKey); } - public static AccountConfigReader reader(){ + public static AccountConfigReader reader() { return new AccountConfigReader(); } - public static AccountConfigUpdater updater(final String pathKey, final String value){ + public static AccountConfigUpdater updater( + final String pathKey, + final String value + ) { return new AccountConfigUpdater(pathKey, value); } /** - * Converts a JSON String into a AccountConfig object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return AccountConfig object represented by the provided JSON - */ - public static AccountConfig fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a AccountConfig object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return AccountConfig object represented by the provided JSON + */ + public static AccountConfig fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, AccountConfig.class); @@ -81,14 +86,17 @@ public static AccountConfig fromJson(final String json, final ObjectMapper objec } /** - * Converts a JSON InputStream into a AccountConfig object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return AccountConfig object represented by the provided JSON - */ - public static AccountConfig fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a AccountConfig object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return AccountConfig object represented by the provided JSON + */ + public static AccountConfig fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, AccountConfig.class); @@ -106,17 +114,10 @@ public static AccountConfig fromJson(final InputStream json, final ObjectMapper @JsonCreator private AccountConfig( - @JsonProperty("key") - final String key, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("value") - final String value, - - @JsonProperty("url") - final URI url + @JsonProperty("key") final String key, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("value") final String value, + @JsonProperty("url") final URI url ) { this.key = key; this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); @@ -124,22 +125,25 @@ private AccountConfig( this.url = url; } - public final String getKey() { - return this.key; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getValue() { - return this.value; - } - public final URI getUrl() { - return this.url; - } + public final String getKey() { + return this.key; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getValue() { + return this.value; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -149,13 +153,16 @@ public boolean equals(final Object o) { AccountConfig other = (AccountConfig) o; - return Objects.equals(key, other.key) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(value, other.value) && Objects.equals(url, other.url) ; + return ( + Objects.equals(key, other.key) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(value, other.value) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { return Objects.hash(key, dateUpdated, value, url); } - } - diff --git a/src/main/java/com/twilio/rest/microvisor/v1/AccountConfigCreator.java b/src/main/java/com/twilio/rest/microvisor/v1/AccountConfigCreator.java index f2fba79158..119fef7bfe 100644 --- a/src/main/java/com/twilio/rest/microvisor/v1/AccountConfigCreator.java +++ b/src/main/java/com/twilio/rest/microvisor/v1/AccountConfigCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.microvisor.v1; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class AccountConfigCreator extends Creator { - - -public class AccountConfigCreator extends Creator{ private String key; private String value; @@ -36,49 +35,58 @@ public AccountConfigCreator(final String key, final String value) { this.value = value; } - public AccountConfigCreator setKey(final String key){ + public AccountConfigCreator setKey(final String key) { this.key = key; return this; } - public AccountConfigCreator setValue(final String value){ + + public AccountConfigCreator setValue(final String value) { this.value = value; return this; } @Override - public AccountConfig create(final TwilioRestClient client){ + public AccountConfig create(final TwilioRestClient client) { String path = "/v1/Configs"; - path = path.replace("{"+"Key"+"}", this.key.toString()); - path = path.replace("{"+"Value"+"}", this.value.toString()); + path = path.replace("{" + "Key" + "}", this.key.toString()); + path = path.replace("{" + "Value" + "}", this.value.toString()); Request request = new Request( HttpMethod.POST, Domains.MICROVISOR.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AccountConfig creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "AccountConfig creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return AccountConfig.fromJson(response.getStream(), client.getObjectMapper()); + return AccountConfig.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (key != null) { request.addPostParam("Key", key); - } if (value != null) { request.addPostParam("Value", value); - } } } diff --git a/src/main/java/com/twilio/rest/microvisor/v1/AccountConfigDeleter.java b/src/main/java/com/twilio/rest/microvisor/v1/AccountConfigDeleter.java index 4b8c277c95..2f878e43ba 100644 --- a/src/main/java/com/twilio/rest/microvisor/v1/AccountConfigDeleter.java +++ b/src/main/java/com/twilio/rest/microvisor/v1/AccountConfigDeleter.java @@ -24,21 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class AccountConfigDeleter extends Deleter { + private String pathKey; - public AccountConfigDeleter(final String pathKey){ + public AccountConfigDeleter(final String pathKey) { this.pathKey = pathKey; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Configs/{Key}"; - path = path.replace("{"+"Key"+"}", this.pathKey.toString()); + path = path.replace("{" + "Key" + "}", this.pathKey.toString()); Request request = new Request( HttpMethod.DELETE, @@ -48,9 +46,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AccountConfig delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "AccountConfig delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/microvisor/v1/AccountConfigFetcher.java b/src/main/java/com/twilio/rest/microvisor/v1/AccountConfigFetcher.java index 092b3886fd..9d39ac419f 100644 --- a/src/main/java/com/twilio/rest/microvisor/v1/AccountConfigFetcher.java +++ b/src/main/java/com/twilio/rest/microvisor/v1/AccountConfigFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class AccountConfigFetcher extends Fetcher { + private String pathKey; - public AccountConfigFetcher(final String pathKey){ + public AccountConfigFetcher(final String pathKey) { this.pathKey = pathKey; } - @Override public AccountConfig fetch(final TwilioRestClient client) { String path = "/v1/Configs/{Key}"; - path = path.replace("{"+"Key"+"}", this.pathKey.toString()); + path = path.replace("{" + "Key" + "}", this.pathKey.toString()); Request request = new Request( HttpMethod.GET, @@ -49,15 +46,23 @@ public AccountConfig fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AccountConfig fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "AccountConfig fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return AccountConfig.fromJson(response.getStream(), client.getObjectMapper()); + return AccountConfig.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/microvisor/v1/AccountConfigReader.java b/src/main/java/com/twilio/rest/microvisor/v1/AccountConfigReader.java index 3262f2eb7c..9941a737d8 100644 --- a/src/main/java/com/twilio/rest/microvisor/v1/AccountConfigReader.java +++ b/src/main/java/com/twilio/rest/microvisor/v1/AccountConfigReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.microvisor.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,17 +25,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class AccountConfigReader extends Reader { + private Integer pageSize; - public AccountConfigReader(){ - } + public AccountConfigReader() {} - public AccountConfigReader setPageSize(final Integer pageSize){ + public AccountConfigReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -57,13 +55,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AccountConfig read failed: Unable to connect to server"); + throw new ApiConnectionException( + "AccountConfig read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -79,7 +85,10 @@ private Page pageForRequest(final TwilioRestClient client, final } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.MICROVISOR.toString()) @@ -87,9 +96,11 @@ public Page previousPage(final Page page, final Tw return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.MICROVISOR.toString()) @@ -98,21 +109,21 @@ public Page nextPage(final Page page, final Twilio } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/microvisor/v1/AccountConfigUpdater.java b/src/main/java/com/twilio/rest/microvisor/v1/AccountConfigUpdater.java index 2aef848d2e..ad30dd6f6c 100644 --- a/src/main/java/com/twilio/rest/microvisor/v1/AccountConfigUpdater.java +++ b/src/main/java/com/twilio/rest/microvisor/v1/AccountConfigUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.microvisor.v1; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,53 +25,60 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class AccountConfigUpdater extends Updater { - - -public class AccountConfigUpdater extends Updater{ private String pathKey; private String value; - public AccountConfigUpdater(final String pathKey, final String value){ + public AccountConfigUpdater(final String pathKey, final String value) { this.pathKey = pathKey; this.value = value; } - public AccountConfigUpdater setValue(final String value){ + public AccountConfigUpdater setValue(final String value) { this.value = value; return this; } @Override - public AccountConfig update(final TwilioRestClient client){ + public AccountConfig update(final TwilioRestClient client) { String path = "/v1/Configs/{Key}"; - path = path.replace("{"+"Key"+"}", this.pathKey.toString()); - path = path.replace("{"+"Value"+"}", this.value.toString()); + path = path.replace("{" + "Key" + "}", this.pathKey.toString()); + path = path.replace("{" + "Value" + "}", this.value.toString()); Request request = new Request( HttpMethod.POST, Domains.MICROVISOR.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AccountConfig update failed: Unable to connect to server"); + throw new ApiConnectionException( + "AccountConfig update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return AccountConfig.fromJson(response.getStream(), client.getObjectMapper()); + return AccountConfig.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (value != null) { request.addPostParam("Value", value); - } } } diff --git a/src/main/java/com/twilio/rest/microvisor/v1/AccountSecret.java b/src/main/java/com/twilio/rest/microvisor/v1/AccountSecret.java index c4b924af62..65fab57e56 100644 --- a/src/main/java/com/twilio/rest/microvisor/v1/AccountSecret.java +++ b/src/main/java/com/twilio/rest/microvisor/v1/AccountSecret.java @@ -23,53 +23,58 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class AccountSecret extends Resource { + private static final long serialVersionUID = 245444757442788L; - public static AccountSecretCreator creator(final String key, final String value){ + public static AccountSecretCreator creator( + final String key, + final String value + ) { return new AccountSecretCreator(key, value); } - public static AccountSecretDeleter deleter(final String pathKey){ + public static AccountSecretDeleter deleter(final String pathKey) { return new AccountSecretDeleter(pathKey); } - public static AccountSecretFetcher fetcher(final String pathKey){ + public static AccountSecretFetcher fetcher(final String pathKey) { return new AccountSecretFetcher(pathKey); } - public static AccountSecretReader reader(){ + public static AccountSecretReader reader() { return new AccountSecretReader(); } - public static AccountSecretUpdater updater(final String pathKey, final String value){ + public static AccountSecretUpdater updater( + final String pathKey, + final String value + ) { return new AccountSecretUpdater(pathKey, value); } /** - * Converts a JSON String into a AccountSecret object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return AccountSecret object represented by the provided JSON - */ - public static AccountSecret fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a AccountSecret object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return AccountSecret object represented by the provided JSON + */ + public static AccountSecret fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, AccountSecret.class); @@ -81,14 +86,17 @@ public static AccountSecret fromJson(final String json, final ObjectMapper objec } /** - * Converts a JSON InputStream into a AccountSecret object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return AccountSecret object represented by the provided JSON - */ - public static AccountSecret fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a AccountSecret object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return AccountSecret object represented by the provided JSON + */ + public static AccountSecret fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, AccountSecret.class); @@ -105,33 +113,30 @@ public static AccountSecret fromJson(final InputStream json, final ObjectMapper @JsonCreator private AccountSecret( - @JsonProperty("key") - final String key, - - @JsonProperty("date_rotated") - final String dateRotated, - - @JsonProperty("url") - final URI url + @JsonProperty("key") final String key, + @JsonProperty("date_rotated") final String dateRotated, + @JsonProperty("url") final URI url ) { this.key = key; this.dateRotated = DateConverter.iso8601DateTimeFromString(dateRotated); this.url = url; } - public final String getKey() { - return this.key; - } - public final ZonedDateTime getDateRotated() { - return this.dateRotated; - } - public final URI getUrl() { - return this.url; - } + public final String getKey() { + return this.key; + } + + public final ZonedDateTime getDateRotated() { + return this.dateRotated; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -141,13 +146,15 @@ public boolean equals(final Object o) { AccountSecret other = (AccountSecret) o; - return Objects.equals(key, other.key) && Objects.equals(dateRotated, other.dateRotated) && Objects.equals(url, other.url) ; + return ( + Objects.equals(key, other.key) && + Objects.equals(dateRotated, other.dateRotated) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { return Objects.hash(key, dateRotated, url); } - } - diff --git a/src/main/java/com/twilio/rest/microvisor/v1/AccountSecretCreator.java b/src/main/java/com/twilio/rest/microvisor/v1/AccountSecretCreator.java index d39c8ef121..e05875ba93 100644 --- a/src/main/java/com/twilio/rest/microvisor/v1/AccountSecretCreator.java +++ b/src/main/java/com/twilio/rest/microvisor/v1/AccountSecretCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.microvisor.v1; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class AccountSecretCreator extends Creator { - - -public class AccountSecretCreator extends Creator{ private String key; private String value; @@ -36,49 +35,58 @@ public AccountSecretCreator(final String key, final String value) { this.value = value; } - public AccountSecretCreator setKey(final String key){ + public AccountSecretCreator setKey(final String key) { this.key = key; return this; } - public AccountSecretCreator setValue(final String value){ + + public AccountSecretCreator setValue(final String value) { this.value = value; return this; } @Override - public AccountSecret create(final TwilioRestClient client){ + public AccountSecret create(final TwilioRestClient client) { String path = "/v1/Secrets"; - path = path.replace("{"+"Key"+"}", this.key.toString()); - path = path.replace("{"+"Value"+"}", this.value.toString()); + path = path.replace("{" + "Key" + "}", this.key.toString()); + path = path.replace("{" + "Value" + "}", this.value.toString()); Request request = new Request( HttpMethod.POST, Domains.MICROVISOR.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AccountSecret creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "AccountSecret creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return AccountSecret.fromJson(response.getStream(), client.getObjectMapper()); + return AccountSecret.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (key != null) { request.addPostParam("Key", key); - } if (value != null) { request.addPostParam("Value", value); - } } } diff --git a/src/main/java/com/twilio/rest/microvisor/v1/AccountSecretDeleter.java b/src/main/java/com/twilio/rest/microvisor/v1/AccountSecretDeleter.java index 786a9c3b9a..47fe1562e5 100644 --- a/src/main/java/com/twilio/rest/microvisor/v1/AccountSecretDeleter.java +++ b/src/main/java/com/twilio/rest/microvisor/v1/AccountSecretDeleter.java @@ -24,21 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class AccountSecretDeleter extends Deleter { + private String pathKey; - public AccountSecretDeleter(final String pathKey){ + public AccountSecretDeleter(final String pathKey) { this.pathKey = pathKey; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Secrets/{Key}"; - path = path.replace("{"+"Key"+"}", this.pathKey.toString()); + path = path.replace("{" + "Key" + "}", this.pathKey.toString()); Request request = new Request( HttpMethod.DELETE, @@ -48,9 +46,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AccountSecret delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "AccountSecret delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/microvisor/v1/AccountSecretFetcher.java b/src/main/java/com/twilio/rest/microvisor/v1/AccountSecretFetcher.java index 7686a3dea5..a9af73d1fd 100644 --- a/src/main/java/com/twilio/rest/microvisor/v1/AccountSecretFetcher.java +++ b/src/main/java/com/twilio/rest/microvisor/v1/AccountSecretFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class AccountSecretFetcher extends Fetcher { + private String pathKey; - public AccountSecretFetcher(final String pathKey){ + public AccountSecretFetcher(final String pathKey) { this.pathKey = pathKey; } - @Override public AccountSecret fetch(final TwilioRestClient client) { String path = "/v1/Secrets/{Key}"; - path = path.replace("{"+"Key"+"}", this.pathKey.toString()); + path = path.replace("{" + "Key" + "}", this.pathKey.toString()); Request request = new Request( HttpMethod.GET, @@ -49,15 +46,23 @@ public AccountSecret fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AccountSecret fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "AccountSecret fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return AccountSecret.fromJson(response.getStream(), client.getObjectMapper()); + return AccountSecret.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/microvisor/v1/AccountSecretReader.java b/src/main/java/com/twilio/rest/microvisor/v1/AccountSecretReader.java index b34b71795e..7690f3f668 100644 --- a/src/main/java/com/twilio/rest/microvisor/v1/AccountSecretReader.java +++ b/src/main/java/com/twilio/rest/microvisor/v1/AccountSecretReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.microvisor.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,17 +25,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class AccountSecretReader extends Reader { + private Integer pageSize; - public AccountSecretReader(){ - } + public AccountSecretReader() {} - public AccountSecretReader setPageSize(final Integer pageSize){ + public AccountSecretReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -57,13 +55,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AccountSecret read failed: Unable to connect to server"); + throw new ApiConnectionException( + "AccountSecret read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -79,7 +85,10 @@ private Page pageForRequest(final TwilioRestClient client, final } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.MICROVISOR.toString()) @@ -87,9 +96,11 @@ public Page previousPage(final Page page, final Tw return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.MICROVISOR.toString()) @@ -98,21 +109,21 @@ public Page nextPage(final Page page, final Twilio } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/microvisor/v1/AccountSecretUpdater.java b/src/main/java/com/twilio/rest/microvisor/v1/AccountSecretUpdater.java index fa3c954f0a..2f56720913 100644 --- a/src/main/java/com/twilio/rest/microvisor/v1/AccountSecretUpdater.java +++ b/src/main/java/com/twilio/rest/microvisor/v1/AccountSecretUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.microvisor.v1; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,53 +25,60 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class AccountSecretUpdater extends Updater { - - -public class AccountSecretUpdater extends Updater{ private String pathKey; private String value; - public AccountSecretUpdater(final String pathKey, final String value){ + public AccountSecretUpdater(final String pathKey, final String value) { this.pathKey = pathKey; this.value = value; } - public AccountSecretUpdater setValue(final String value){ + public AccountSecretUpdater setValue(final String value) { this.value = value; return this; } @Override - public AccountSecret update(final TwilioRestClient client){ + public AccountSecret update(final TwilioRestClient client) { String path = "/v1/Secrets/{Key}"; - path = path.replace("{"+"Key"+"}", this.pathKey.toString()); - path = path.replace("{"+"Value"+"}", this.value.toString()); + path = path.replace("{" + "Key" + "}", this.pathKey.toString()); + path = path.replace("{" + "Value" + "}", this.value.toString()); Request request = new Request( HttpMethod.POST, Domains.MICROVISOR.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AccountSecret update failed: Unable to connect to server"); + throw new ApiConnectionException( + "AccountSecret update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return AccountSecret.fromJson(response.getStream(), client.getObjectMapper()); + return AccountSecret.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (value != null) { request.addPostParam("Value", value); - } } } diff --git a/src/main/java/com/twilio/rest/microvisor/v1/App.java b/src/main/java/com/twilio/rest/microvisor/v1/App.java index c142b96e16..23827af572 100644 --- a/src/main/java/com/twilio/rest/microvisor/v1/App.java +++ b/src/main/java/com/twilio/rest/microvisor/v1/App.java @@ -23,47 +23,46 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class App extends Resource { + private static final long serialVersionUID = 223120562272974L; - public static AppDeleter deleter(final String pathSid){ + public static AppDeleter deleter(final String pathSid) { return new AppDeleter(pathSid); } - public static AppFetcher fetcher(final String pathSid){ + public static AppFetcher fetcher(final String pathSid) { return new AppFetcher(pathSid); } - public static AppReader reader(){ + public static AppReader reader() { return new AppReader(); } /** - * Converts a JSON String into a App object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return App object represented by the provided JSON - */ - public static App fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a App object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return App object represented by the provided JSON + */ + public static App fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, App.class); @@ -75,14 +74,17 @@ public static App fromJson(final String json, final ObjectMapper objectMapper) { } /** - * Converts a JSON InputStream into a App object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return App object represented by the provided JSON - */ - public static App fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a App object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return App object represented by the provided JSON + */ + public static App fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, App.class); @@ -104,29 +106,14 @@ public static App fromJson(final InputStream json, final ObjectMapper objectMapp @JsonCreator private App( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("hash") - final String hash, - - @JsonProperty("unique_name") - final String uniqueName, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("hash") final String hash, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.sid = sid; this.accountSid = accountSid; @@ -138,34 +125,41 @@ private App( this.links = links; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getHash() { - return this.hash; - } - public final String getUniqueName() { - return this.uniqueName; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getHash() { + return this.hash; + } + + public final String getUniqueName() { + return this.uniqueName; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -175,13 +169,29 @@ public boolean equals(final Object o) { App other = (App) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(hash, other.hash) && Objects.equals(uniqueName, other.uniqueName) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(hash, other.hash) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, hash, uniqueName, dateCreated, dateUpdated, url, links); + return Objects.hash( + sid, + accountSid, + hash, + uniqueName, + dateCreated, + dateUpdated, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/microvisor/v1/AppDeleter.java b/src/main/java/com/twilio/rest/microvisor/v1/AppDeleter.java index e75a14c286..c17c907936 100644 --- a/src/main/java/com/twilio/rest/microvisor/v1/AppDeleter.java +++ b/src/main/java/com/twilio/rest/microvisor/v1/AppDeleter.java @@ -24,21 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class AppDeleter extends Deleter { + private String pathSid; - public AppDeleter(final String pathSid){ + public AppDeleter(final String pathSid) { this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Apps/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -48,9 +46,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("App delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "App delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/microvisor/v1/AppFetcher.java b/src/main/java/com/twilio/rest/microvisor/v1/AppFetcher.java index aecd6ac1a1..b8fed80bd8 100644 --- a/src/main/java/com/twilio/rest/microvisor/v1/AppFetcher.java +++ b/src/main/java/com/twilio/rest/microvisor/v1/AppFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class AppFetcher extends Fetcher { + private String pathSid; - public AppFetcher(final String pathSid){ + public AppFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public App fetch(final TwilioRestClient client) { String path = "/v1/Apps/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,9 +46,14 @@ public App fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("App fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "App fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/microvisor/v1/AppReader.java b/src/main/java/com/twilio/rest/microvisor/v1/AppReader.java index 1ee022a562..158f299ab2 100644 --- a/src/main/java/com/twilio/rest/microvisor/v1/AppReader.java +++ b/src/main/java/com/twilio/rest/microvisor/v1/AppReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.microvisor.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,17 +25,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class AppReader extends Reader { + private Integer pageSize; - public AppReader(){ - } + public AppReader() {} - public AppReader setPageSize(final Integer pageSize){ + public AppReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -57,13 +55,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("App read failed: Unable to connect to server"); + throw new ApiConnectionException( + "App read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -79,7 +85,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request re } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.MICROVISOR.toString()) @@ -87,9 +96,11 @@ public Page previousPage(final Page page, final TwilioRestClient clien return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.MICROVISOR.toString()) @@ -98,21 +109,21 @@ public Page nextPage(final Page page, final TwilioRestClient client) { } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/microvisor/v1/Device.java b/src/main/java/com/twilio/rest/microvisor/v1/Device.java index c9ae311600..6775341645 100644 --- a/src/main/java/com/twilio/rest/microvisor/v1/Device.java +++ b/src/main/java/com/twilio/rest/microvisor/v1/Device.java @@ -23,47 +23,46 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Device extends Resource { + private static final long serialVersionUID = 266652017538801L; - public static DeviceFetcher fetcher(final String pathSid){ + public static DeviceFetcher fetcher(final String pathSid) { return new DeviceFetcher(pathSid); } - public static DeviceReader reader(){ + public static DeviceReader reader() { return new DeviceReader(); } - public static DeviceUpdater updater(final String pathSid){ + public static DeviceUpdater updater(final String pathSid) { return new DeviceUpdater(pathSid); } /** - * Converts a JSON String into a Device object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Device object represented by the provided JSON - */ - public static Device fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Device object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Device object represented by the provided JSON + */ + public static Device fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Device.class); @@ -75,14 +74,17 @@ public static Device fromJson(final String json, final ObjectMapper objectMapper } /** - * Converts a JSON InputStream into a Device object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Device object represented by the provided JSON - */ - public static Device fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Device object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Device object represented by the provided JSON + */ + public static Device fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Device.class); @@ -105,32 +107,15 @@ public static Device fromJson(final InputStream json, final ObjectMapper objectM @JsonCreator private Device( - @JsonProperty("sid") - final String sid, - - @JsonProperty("unique_name") - final String uniqueName, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("app") - final Map app, - - @JsonProperty("logging") - final Map logging, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("sid") final String sid, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("app") final Map app, + @JsonProperty("logging") final Map logging, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.sid = sid; this.uniqueName = uniqueName; @@ -143,37 +128,45 @@ private Device( this.links = links; } - public final String getSid() { - return this.sid; - } - public final String getUniqueName() { - return this.uniqueName; - } - public final String getAccountSid() { - return this.accountSid; - } - public final Map getApp() { - return this.app; - } - public final Map getLogging() { - return this.logging; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getSid() { + return this.sid; + } + + public final String getUniqueName() { + return this.uniqueName; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final Map getApp() { + return this.app; + } + + public final Map getLogging() { + return this.logging; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -183,13 +176,31 @@ public boolean equals(final Object o) { Device other = (Device) o; - return Objects.equals(sid, other.sid) && Objects.equals(uniqueName, other.uniqueName) && Objects.equals(accountSid, other.accountSid) && Objects.equals(app, other.app) && Objects.equals(logging, other.logging) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(app, other.app) && + Objects.equals(logging, other.logging) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(sid, uniqueName, accountSid, app, logging, dateCreated, dateUpdated, url, links); + return Objects.hash( + sid, + uniqueName, + accountSid, + app, + logging, + dateCreated, + dateUpdated, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/microvisor/v1/DeviceFetcher.java b/src/main/java/com/twilio/rest/microvisor/v1/DeviceFetcher.java index 884b94f3a7..0ced361979 100644 --- a/src/main/java/com/twilio/rest/microvisor/v1/DeviceFetcher.java +++ b/src/main/java/com/twilio/rest/microvisor/v1/DeviceFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class DeviceFetcher extends Fetcher { + private String pathSid; - public DeviceFetcher(final String pathSid){ + public DeviceFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public Device fetch(final TwilioRestClient client) { String path = "/v1/Devices/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,9 +46,14 @@ public Device fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Device fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Device fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/microvisor/v1/DeviceReader.java b/src/main/java/com/twilio/rest/microvisor/v1/DeviceReader.java index 38db05bf33..b30cae5e37 100644 --- a/src/main/java/com/twilio/rest/microvisor/v1/DeviceReader.java +++ b/src/main/java/com/twilio/rest/microvisor/v1/DeviceReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.microvisor.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,17 +25,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class DeviceReader extends Reader { + private Integer pageSize; - public DeviceReader(){ - } + public DeviceReader() {} - public DeviceReader setPageSize(final Integer pageSize){ + public DeviceReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -57,13 +55,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Device read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Device read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -79,7 +85,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.MICROVISOR.toString()) @@ -87,9 +96,11 @@ public Page previousPage(final Page page, final TwilioRestClient return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.MICROVISOR.toString()) @@ -98,21 +109,21 @@ public Page nextPage(final Page page, final TwilioRestClient cli } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/microvisor/v1/DeviceUpdater.java b/src/main/java/com/twilio/rest/microvisor/v1/DeviceUpdater.java index 7b3c872dac..d047487ad2 100644 --- a/src/main/java/com/twilio/rest/microvisor/v1/DeviceUpdater.java +++ b/src/main/java/com/twilio/rest/microvisor/v1/DeviceUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.microvisor.v1; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,49 +25,61 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class DeviceUpdater extends Updater { - - -public class DeviceUpdater extends Updater{ private String pathSid; private String uniqueName; private String targetApp; private Boolean loggingEnabled; + private Boolean restartApp; - public DeviceUpdater(final String pathSid){ + public DeviceUpdater(final String pathSid) { this.pathSid = pathSid; } - public DeviceUpdater setUniqueName(final String uniqueName){ + public DeviceUpdater setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - public DeviceUpdater setTargetApp(final String targetApp){ + + public DeviceUpdater setTargetApp(final String targetApp) { this.targetApp = targetApp; return this; } - public DeviceUpdater setLoggingEnabled(final Boolean loggingEnabled){ + + public DeviceUpdater setLoggingEnabled(final Boolean loggingEnabled) { this.loggingEnabled = loggingEnabled; return this; } + public DeviceUpdater setRestartApp(final Boolean restartApp) { + this.restartApp = restartApp; + return this; + } + @Override - public Device update(final TwilioRestClient client){ + public Device update(final TwilioRestClient client) { String path = "/v1/Devices/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.MICROVISOR.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Device update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Device update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -75,18 +88,19 @@ public Device update(final TwilioRestClient client){ return Device.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (uniqueName != null) { request.addPostParam("UniqueName", uniqueName); - } if (targetApp != null) { request.addPostParam("TargetApp", targetApp); - } if (loggingEnabled != null) { request.addPostParam("LoggingEnabled", loggingEnabled.toString()); - + } + if (restartApp != null) { + request.addPostParam("RestartApp", restartApp.toString()); } } } diff --git a/src/main/java/com/twilio/rest/microvisor/v1/app/AppManifest.java b/src/main/java/com/twilio/rest/microvisor/v1/app/AppManifest.java index caab90d4e3..9beb04ce48 100644 --- a/src/main/java/com/twilio/rest/microvisor/v1/app/AppManifest.java +++ b/src/main/java/com/twilio/rest/microvisor/v1/app/AppManifest.java @@ -22,36 +22,35 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class AppManifest extends Resource { + private static final long serialVersionUID = 249809073531699L; - public static AppManifestFetcher fetcher(final String pathAppSid){ + public static AppManifestFetcher fetcher(final String pathAppSid) { return new AppManifestFetcher(pathAppSid); } /** - * Converts a JSON String into a AppManifest object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return AppManifest object represented by the provided JSON - */ - public static AppManifest fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a AppManifest object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return AppManifest object represented by the provided JSON + */ + public static AppManifest fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, AppManifest.class); @@ -63,14 +62,17 @@ public static AppManifest fromJson(final String json, final ObjectMapper objectM } /** - * Converts a JSON InputStream into a AppManifest object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return AppManifest object represented by the provided JSON - */ - public static AppManifest fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a AppManifest object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return AppManifest object represented by the provided JSON + */ + public static AppManifest fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, AppManifest.class); @@ -88,17 +90,10 @@ public static AppManifest fromJson(final InputStream json, final ObjectMapper ob @JsonCreator private AppManifest( - @JsonProperty("app_sid") - final String appSid, - - @JsonProperty("hash") - final String hash, - - @JsonProperty("encoded_bytes") - final String encodedBytes, - - @JsonProperty("url") - final URI url + @JsonProperty("app_sid") final String appSid, + @JsonProperty("hash") final String hash, + @JsonProperty("encoded_bytes") final String encodedBytes, + @JsonProperty("url") final URI url ) { this.appSid = appSid; this.hash = hash; @@ -106,22 +101,25 @@ private AppManifest( this.url = url; } - public final String getAppSid() { - return this.appSid; - } - public final String getHash() { - return this.hash; - } - public final String getEncodedBytes() { - return this.encodedBytes; - } - public final URI getUrl() { - return this.url; - } + public final String getAppSid() { + return this.appSid; + } + + public final String getHash() { + return this.hash; + } + + public final String getEncodedBytes() { + return this.encodedBytes; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -131,13 +129,16 @@ public boolean equals(final Object o) { AppManifest other = (AppManifest) o; - return Objects.equals(appSid, other.appSid) && Objects.equals(hash, other.hash) && Objects.equals(encodedBytes, other.encodedBytes) && Objects.equals(url, other.url) ; + return ( + Objects.equals(appSid, other.appSid) && + Objects.equals(hash, other.hash) && + Objects.equals(encodedBytes, other.encodedBytes) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { return Objects.hash(appSid, hash, encodedBytes, url); } - } - diff --git a/src/main/java/com/twilio/rest/microvisor/v1/app/AppManifestFetcher.java b/src/main/java/com/twilio/rest/microvisor/v1/app/AppManifestFetcher.java index 1fda8336d6..7cdeec76fd 100644 --- a/src/main/java/com/twilio/rest/microvisor/v1/app/AppManifestFetcher.java +++ b/src/main/java/com/twilio/rest/microvisor/v1/app/AppManifestFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class AppManifestFetcher extends Fetcher { + private String pathAppSid; - public AppManifestFetcher(final String pathAppSid){ + public AppManifestFetcher(final String pathAppSid) { this.pathAppSid = pathAppSid; } - @Override public AppManifest fetch(final TwilioRestClient client) { String path = "/v1/Apps/{AppSid}/Manifest"; - path = path.replace("{"+"AppSid"+"}", this.pathAppSid.toString()); + path = path.replace("{" + "AppSid" + "}", this.pathAppSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,15 +46,23 @@ public AppManifest fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AppManifest fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "AppManifest fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return AppManifest.fromJson(response.getStream(), client.getObjectMapper()); + return AppManifest.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/microvisor/v1/device/DeviceConfig.java b/src/main/java/com/twilio/rest/microvisor/v1/device/DeviceConfig.java index e9a2e41e6b..3574a6e773 100644 --- a/src/main/java/com/twilio/rest/microvisor/v1/device/DeviceConfig.java +++ b/src/main/java/com/twilio/rest/microvisor/v1/device/DeviceConfig.java @@ -23,53 +23,66 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class DeviceConfig extends Resource { + private static final long serialVersionUID = 4121523224128L; - public static DeviceConfigCreator creator(final String pathDeviceSid, final String key, final String value){ + public static DeviceConfigCreator creator( + final String pathDeviceSid, + final String key, + final String value + ) { return new DeviceConfigCreator(pathDeviceSid, key, value); } - public static DeviceConfigDeleter deleter(final String pathDeviceSid, final String pathKey){ + public static DeviceConfigDeleter deleter( + final String pathDeviceSid, + final String pathKey + ) { return new DeviceConfigDeleter(pathDeviceSid, pathKey); } - public static DeviceConfigFetcher fetcher(final String pathDeviceSid, final String pathKey){ + public static DeviceConfigFetcher fetcher( + final String pathDeviceSid, + final String pathKey + ) { return new DeviceConfigFetcher(pathDeviceSid, pathKey); } - public static DeviceConfigReader reader(final String pathDeviceSid){ + public static DeviceConfigReader reader(final String pathDeviceSid) { return new DeviceConfigReader(pathDeviceSid); } - public static DeviceConfigUpdater updater(final String pathDeviceSid, final String pathKey, final String value){ + public static DeviceConfigUpdater updater( + final String pathDeviceSid, + final String pathKey, + final String value + ) { return new DeviceConfigUpdater(pathDeviceSid, pathKey, value); } /** - * Converts a JSON String into a DeviceConfig object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return DeviceConfig object represented by the provided JSON - */ - public static DeviceConfig fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a DeviceConfig object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return DeviceConfig object represented by the provided JSON + */ + public static DeviceConfig fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, DeviceConfig.class); @@ -81,14 +94,17 @@ public static DeviceConfig fromJson(final String json, final ObjectMapper object } /** - * Converts a JSON InputStream into a DeviceConfig object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return DeviceConfig object represented by the provided JSON - */ - public static DeviceConfig fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a DeviceConfig object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return DeviceConfig object represented by the provided JSON + */ + public static DeviceConfig fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, DeviceConfig.class); @@ -107,20 +123,11 @@ public static DeviceConfig fromJson(final InputStream json, final ObjectMapper o @JsonCreator private DeviceConfig( - @JsonProperty("device_sid") - final String deviceSid, - - @JsonProperty("key") - final String key, - - @JsonProperty("value") - final String value, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url + @JsonProperty("device_sid") final String deviceSid, + @JsonProperty("key") final String key, + @JsonProperty("value") final String value, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url ) { this.deviceSid = deviceSid; this.key = key; @@ -129,25 +136,29 @@ private DeviceConfig( this.url = url; } - public final String getDeviceSid() { - return this.deviceSid; - } - public final String getKey() { - return this.key; - } - public final String getValue() { - return this.value; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } + public final String getDeviceSid() { + return this.deviceSid; + } + + public final String getKey() { + return this.key; + } + + public final String getValue() { + return this.value; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -157,13 +168,17 @@ public boolean equals(final Object o) { DeviceConfig other = (DeviceConfig) o; - return Objects.equals(deviceSid, other.deviceSid) && Objects.equals(key, other.key) && Objects.equals(value, other.value) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) ; + return ( + Objects.equals(deviceSid, other.deviceSid) && + Objects.equals(key, other.key) && + Objects.equals(value, other.value) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { return Objects.hash(deviceSid, key, value, dateUpdated, url); } - } - diff --git a/src/main/java/com/twilio/rest/microvisor/v1/device/DeviceConfigCreator.java b/src/main/java/com/twilio/rest/microvisor/v1/device/DeviceConfigCreator.java index 772c4da0ae..9458a41b13 100644 --- a/src/main/java/com/twilio/rest/microvisor/v1/device/DeviceConfigCreator.java +++ b/src/main/java/com/twilio/rest/microvisor/v1/device/DeviceConfigCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.microvisor.v1.device; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,64 +25,79 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class DeviceConfigCreator extends Creator { - - -public class DeviceConfigCreator extends Creator{ private String pathDeviceSid; private String key; private String value; - public DeviceConfigCreator(final String pathDeviceSid, final String key, final String value) { + public DeviceConfigCreator( + final String pathDeviceSid, + final String key, + final String value + ) { this.pathDeviceSid = pathDeviceSid; this.key = key; this.value = value; } - public DeviceConfigCreator setKey(final String key){ + public DeviceConfigCreator setKey(final String key) { this.key = key; return this; } - public DeviceConfigCreator setValue(final String value){ + + public DeviceConfigCreator setValue(final String value) { this.value = value; return this; } @Override - public DeviceConfig create(final TwilioRestClient client){ + public DeviceConfig create(final TwilioRestClient client) { String path = "/v1/Devices/{DeviceSid}/Configs"; - path = path.replace("{"+"DeviceSid"+"}", this.pathDeviceSid.toString()); - path = path.replace("{"+"Key"+"}", this.key.toString()); - path = path.replace("{"+"Value"+"}", this.value.toString()); + path = + path.replace( + "{" + "DeviceSid" + "}", + this.pathDeviceSid.toString() + ); + path = path.replace("{" + "Key" + "}", this.key.toString()); + path = path.replace("{" + "Value" + "}", this.value.toString()); Request request = new Request( HttpMethod.POST, Domains.MICROVISOR.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("DeviceConfig creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "DeviceConfig creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return DeviceConfig.fromJson(response.getStream(), client.getObjectMapper()); + return DeviceConfig.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (key != null) { request.addPostParam("Key", key); - } if (value != null) { request.addPostParam("Value", value); - } } } diff --git a/src/main/java/com/twilio/rest/microvisor/v1/device/DeviceConfigDeleter.java b/src/main/java/com/twilio/rest/microvisor/v1/device/DeviceConfigDeleter.java index bac6504bc8..7e810b6dae 100644 --- a/src/main/java/com/twilio/rest/microvisor/v1/device/DeviceConfigDeleter.java +++ b/src/main/java/com/twilio/rest/microvisor/v1/device/DeviceConfigDeleter.java @@ -24,24 +24,29 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class DeviceConfigDeleter extends Deleter { + private String pathDeviceSid; private String pathKey; - public DeviceConfigDeleter(final String pathDeviceSid, final String pathKey){ + public DeviceConfigDeleter( + final String pathDeviceSid, + final String pathKey + ) { this.pathDeviceSid = pathDeviceSid; this.pathKey = pathKey; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Devices/{DeviceSid}/Configs/{Key}"; - path = path.replace("{"+"DeviceSid"+"}", this.pathDeviceSid.toString()); - path = path.replace("{"+"Key"+"}", this.pathKey.toString()); + path = + path.replace( + "{" + "DeviceSid" + "}", + this.pathDeviceSid.toString() + ); + path = path.replace("{" + "Key" + "}", this.pathKey.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +56,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("DeviceConfig delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "DeviceConfig delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/microvisor/v1/device/DeviceConfigFetcher.java b/src/main/java/com/twilio/rest/microvisor/v1/device/DeviceConfigFetcher.java index 96c1dde387..8d35e0203f 100644 --- a/src/main/java/com/twilio/rest/microvisor/v1/device/DeviceConfigFetcher.java +++ b/src/main/java/com/twilio/rest/microvisor/v1/device/DeviceConfigFetcher.java @@ -24,25 +24,29 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class DeviceConfigFetcher extends Fetcher { + private String pathDeviceSid; private String pathKey; - public DeviceConfigFetcher(final String pathDeviceSid, final String pathKey){ + public DeviceConfigFetcher( + final String pathDeviceSid, + final String pathKey + ) { this.pathDeviceSid = pathDeviceSid; this.pathKey = pathKey; } - @Override public DeviceConfig fetch(final TwilioRestClient client) { String path = "/v1/Devices/{DeviceSid}/Configs/{Key}"; - path = path.replace("{"+"DeviceSid"+"}", this.pathDeviceSid.toString()); - path = path.replace("{"+"Key"+"}", this.pathKey.toString()); + path = + path.replace( + "{" + "DeviceSid" + "}", + this.pathDeviceSid.toString() + ); + path = path.replace("{" + "Key" + "}", this.pathKey.toString()); Request request = new Request( HttpMethod.GET, @@ -52,15 +56,23 @@ public DeviceConfig fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("DeviceConfig fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "DeviceConfig fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return DeviceConfig.fromJson(response.getStream(), client.getObjectMapper()); + return DeviceConfig.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/microvisor/v1/device/DeviceConfigReader.java b/src/main/java/com/twilio/rest/microvisor/v1/device/DeviceConfigReader.java index 56ba0b4234..5fd97ae849 100644 --- a/src/main/java/com/twilio/rest/microvisor/v1/device/DeviceConfigReader.java +++ b/src/main/java/com/twilio/rest/microvisor/v1/device/DeviceConfigReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.microvisor.v1.device; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,19 +25,17 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class DeviceConfigReader extends Reader { + private String pathDeviceSid; private Integer pageSize; - public DeviceConfigReader(final String pathDeviceSid){ + public DeviceConfigReader(final String pathDeviceSid) { this.pathDeviceSid = pathDeviceSid; } - public DeviceConfigReader setPageSize(final Integer pageSize){ + public DeviceConfigReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -48,7 +47,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Devices/{DeviceSid}/Configs"; - path = path.replace("{"+"DeviceSid"+"}", this.pathDeviceSid.toString()); + path = + path.replace( + "{" + "DeviceSid" + "}", + this.pathDeviceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -60,13 +63,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("DeviceConfig read failed: Unable to connect to server"); + throw new ApiConnectionException( + "DeviceConfig read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +93,10 @@ private Page pageForRequest(final TwilioRestClient client, final R } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.MICROVISOR.toString()) @@ -90,9 +104,11 @@ public Page previousPage(final Page page, final Twil return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.MICROVISOR.toString()) @@ -101,21 +117,21 @@ public Page nextPage(final Page page, final TwilioRe } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/microvisor/v1/device/DeviceConfigUpdater.java b/src/main/java/com/twilio/rest/microvisor/v1/device/DeviceConfigUpdater.java index faf9bd2016..78d3a405e7 100644 --- a/src/main/java/com/twilio/rest/microvisor/v1/device/DeviceConfigUpdater.java +++ b/src/main/java/com/twilio/rest/microvisor/v1/device/DeviceConfigUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.microvisor.v1.device; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,56 +25,71 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class DeviceConfigUpdater extends Updater { - - -public class DeviceConfigUpdater extends Updater{ private String pathDeviceSid; private String pathKey; private String value; - public DeviceConfigUpdater(final String pathDeviceSid, final String pathKey, final String value){ + public DeviceConfigUpdater( + final String pathDeviceSid, + final String pathKey, + final String value + ) { this.pathDeviceSid = pathDeviceSid; this.pathKey = pathKey; this.value = value; } - public DeviceConfigUpdater setValue(final String value){ + public DeviceConfigUpdater setValue(final String value) { this.value = value; return this; } @Override - public DeviceConfig update(final TwilioRestClient client){ + public DeviceConfig update(final TwilioRestClient client) { String path = "/v1/Devices/{DeviceSid}/Configs/{Key}"; - path = path.replace("{"+"DeviceSid"+"}", this.pathDeviceSid.toString()); - path = path.replace("{"+"Key"+"}", this.pathKey.toString()); - path = path.replace("{"+"Value"+"}", this.value.toString()); + path = + path.replace( + "{" + "DeviceSid" + "}", + this.pathDeviceSid.toString() + ); + path = path.replace("{" + "Key" + "}", this.pathKey.toString()); + path = path.replace("{" + "Value" + "}", this.value.toString()); Request request = new Request( HttpMethod.POST, Domains.MICROVISOR.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("DeviceConfig update failed: Unable to connect to server"); + throw new ApiConnectionException( + "DeviceConfig update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return DeviceConfig.fromJson(response.getStream(), client.getObjectMapper()); + return DeviceConfig.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (value != null) { request.addPostParam("Value", value); - } } } diff --git a/src/main/java/com/twilio/rest/microvisor/v1/device/DeviceSecret.java b/src/main/java/com/twilio/rest/microvisor/v1/device/DeviceSecret.java index 30f795bd1b..36e7e8916a 100644 --- a/src/main/java/com/twilio/rest/microvisor/v1/device/DeviceSecret.java +++ b/src/main/java/com/twilio/rest/microvisor/v1/device/DeviceSecret.java @@ -23,53 +23,66 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class DeviceSecret extends Resource { + private static final long serialVersionUID = 4318157927104L; - public static DeviceSecretCreator creator(final String pathDeviceSid, final String key, final String value){ + public static DeviceSecretCreator creator( + final String pathDeviceSid, + final String key, + final String value + ) { return new DeviceSecretCreator(pathDeviceSid, key, value); } - public static DeviceSecretDeleter deleter(final String pathDeviceSid, final String pathKey){ + public static DeviceSecretDeleter deleter( + final String pathDeviceSid, + final String pathKey + ) { return new DeviceSecretDeleter(pathDeviceSid, pathKey); } - public static DeviceSecretFetcher fetcher(final String pathDeviceSid, final String pathKey){ + public static DeviceSecretFetcher fetcher( + final String pathDeviceSid, + final String pathKey + ) { return new DeviceSecretFetcher(pathDeviceSid, pathKey); } - public static DeviceSecretReader reader(final String pathDeviceSid){ + public static DeviceSecretReader reader(final String pathDeviceSid) { return new DeviceSecretReader(pathDeviceSid); } - public static DeviceSecretUpdater updater(final String pathDeviceSid, final String pathKey, final String value){ + public static DeviceSecretUpdater updater( + final String pathDeviceSid, + final String pathKey, + final String value + ) { return new DeviceSecretUpdater(pathDeviceSid, pathKey, value); } /** - * Converts a JSON String into a DeviceSecret object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return DeviceSecret object represented by the provided JSON - */ - public static DeviceSecret fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a DeviceSecret object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return DeviceSecret object represented by the provided JSON + */ + public static DeviceSecret fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, DeviceSecret.class); @@ -81,14 +94,17 @@ public static DeviceSecret fromJson(final String json, final ObjectMapper object } /** - * Converts a JSON InputStream into a DeviceSecret object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return DeviceSecret object represented by the provided JSON - */ - public static DeviceSecret fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a DeviceSecret object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return DeviceSecret object represented by the provided JSON + */ + public static DeviceSecret fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, DeviceSecret.class); @@ -106,17 +122,10 @@ public static DeviceSecret fromJson(final InputStream json, final ObjectMapper o @JsonCreator private DeviceSecret( - @JsonProperty("device_sid") - final String deviceSid, - - @JsonProperty("key") - final String key, - - @JsonProperty("date_rotated") - final String dateRotated, - - @JsonProperty("url") - final URI url + @JsonProperty("device_sid") final String deviceSid, + @JsonProperty("key") final String key, + @JsonProperty("date_rotated") final String dateRotated, + @JsonProperty("url") final URI url ) { this.deviceSid = deviceSid; this.key = key; @@ -124,22 +133,25 @@ private DeviceSecret( this.url = url; } - public final String getDeviceSid() { - return this.deviceSid; - } - public final String getKey() { - return this.key; - } - public final ZonedDateTime getDateRotated() { - return this.dateRotated; - } - public final URI getUrl() { - return this.url; - } + public final String getDeviceSid() { + return this.deviceSid; + } + + public final String getKey() { + return this.key; + } + + public final ZonedDateTime getDateRotated() { + return this.dateRotated; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -149,13 +161,16 @@ public boolean equals(final Object o) { DeviceSecret other = (DeviceSecret) o; - return Objects.equals(deviceSid, other.deviceSid) && Objects.equals(key, other.key) && Objects.equals(dateRotated, other.dateRotated) && Objects.equals(url, other.url) ; + return ( + Objects.equals(deviceSid, other.deviceSid) && + Objects.equals(key, other.key) && + Objects.equals(dateRotated, other.dateRotated) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { return Objects.hash(deviceSid, key, dateRotated, url); } - } - diff --git a/src/main/java/com/twilio/rest/microvisor/v1/device/DeviceSecretCreator.java b/src/main/java/com/twilio/rest/microvisor/v1/device/DeviceSecretCreator.java index f5b60e8c23..246884cb71 100644 --- a/src/main/java/com/twilio/rest/microvisor/v1/device/DeviceSecretCreator.java +++ b/src/main/java/com/twilio/rest/microvisor/v1/device/DeviceSecretCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.microvisor.v1.device; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,64 +25,79 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class DeviceSecretCreator extends Creator { - - -public class DeviceSecretCreator extends Creator{ private String pathDeviceSid; private String key; private String value; - public DeviceSecretCreator(final String pathDeviceSid, final String key, final String value) { + public DeviceSecretCreator( + final String pathDeviceSid, + final String key, + final String value + ) { this.pathDeviceSid = pathDeviceSid; this.key = key; this.value = value; } - public DeviceSecretCreator setKey(final String key){ + public DeviceSecretCreator setKey(final String key) { this.key = key; return this; } - public DeviceSecretCreator setValue(final String value){ + + public DeviceSecretCreator setValue(final String value) { this.value = value; return this; } @Override - public DeviceSecret create(final TwilioRestClient client){ + public DeviceSecret create(final TwilioRestClient client) { String path = "/v1/Devices/{DeviceSid}/Secrets"; - path = path.replace("{"+"DeviceSid"+"}", this.pathDeviceSid.toString()); - path = path.replace("{"+"Key"+"}", this.key.toString()); - path = path.replace("{"+"Value"+"}", this.value.toString()); + path = + path.replace( + "{" + "DeviceSid" + "}", + this.pathDeviceSid.toString() + ); + path = path.replace("{" + "Key" + "}", this.key.toString()); + path = path.replace("{" + "Value" + "}", this.value.toString()); Request request = new Request( HttpMethod.POST, Domains.MICROVISOR.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("DeviceSecret creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "DeviceSecret creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return DeviceSecret.fromJson(response.getStream(), client.getObjectMapper()); + return DeviceSecret.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (key != null) { request.addPostParam("Key", key); - } if (value != null) { request.addPostParam("Value", value); - } } } diff --git a/src/main/java/com/twilio/rest/microvisor/v1/device/DeviceSecretDeleter.java b/src/main/java/com/twilio/rest/microvisor/v1/device/DeviceSecretDeleter.java index 013e4c9d9a..3fc78e4f57 100644 --- a/src/main/java/com/twilio/rest/microvisor/v1/device/DeviceSecretDeleter.java +++ b/src/main/java/com/twilio/rest/microvisor/v1/device/DeviceSecretDeleter.java @@ -24,24 +24,29 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class DeviceSecretDeleter extends Deleter { + private String pathDeviceSid; private String pathKey; - public DeviceSecretDeleter(final String pathDeviceSid, final String pathKey){ + public DeviceSecretDeleter( + final String pathDeviceSid, + final String pathKey + ) { this.pathDeviceSid = pathDeviceSid; this.pathKey = pathKey; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Devices/{DeviceSid}/Secrets/{Key}"; - path = path.replace("{"+"DeviceSid"+"}", this.pathDeviceSid.toString()); - path = path.replace("{"+"Key"+"}", this.pathKey.toString()); + path = + path.replace( + "{" + "DeviceSid" + "}", + this.pathDeviceSid.toString() + ); + path = path.replace("{" + "Key" + "}", this.pathKey.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +56,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("DeviceSecret delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "DeviceSecret delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/microvisor/v1/device/DeviceSecretFetcher.java b/src/main/java/com/twilio/rest/microvisor/v1/device/DeviceSecretFetcher.java index e67a252069..a76028e92e 100644 --- a/src/main/java/com/twilio/rest/microvisor/v1/device/DeviceSecretFetcher.java +++ b/src/main/java/com/twilio/rest/microvisor/v1/device/DeviceSecretFetcher.java @@ -24,25 +24,29 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class DeviceSecretFetcher extends Fetcher { + private String pathDeviceSid; private String pathKey; - public DeviceSecretFetcher(final String pathDeviceSid, final String pathKey){ + public DeviceSecretFetcher( + final String pathDeviceSid, + final String pathKey + ) { this.pathDeviceSid = pathDeviceSid; this.pathKey = pathKey; } - @Override public DeviceSecret fetch(final TwilioRestClient client) { String path = "/v1/Devices/{DeviceSid}/Secrets/{Key}"; - path = path.replace("{"+"DeviceSid"+"}", this.pathDeviceSid.toString()); - path = path.replace("{"+"Key"+"}", this.pathKey.toString()); + path = + path.replace( + "{" + "DeviceSid" + "}", + this.pathDeviceSid.toString() + ); + path = path.replace("{" + "Key" + "}", this.pathKey.toString()); Request request = new Request( HttpMethod.GET, @@ -52,15 +56,23 @@ public DeviceSecret fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("DeviceSecret fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "DeviceSecret fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return DeviceSecret.fromJson(response.getStream(), client.getObjectMapper()); + return DeviceSecret.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/microvisor/v1/device/DeviceSecretReader.java b/src/main/java/com/twilio/rest/microvisor/v1/device/DeviceSecretReader.java index 35c4bc3712..66b74f7d1b 100644 --- a/src/main/java/com/twilio/rest/microvisor/v1/device/DeviceSecretReader.java +++ b/src/main/java/com/twilio/rest/microvisor/v1/device/DeviceSecretReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.microvisor.v1.device; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,19 +25,17 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class DeviceSecretReader extends Reader { + private String pathDeviceSid; private Integer pageSize; - public DeviceSecretReader(final String pathDeviceSid){ + public DeviceSecretReader(final String pathDeviceSid) { this.pathDeviceSid = pathDeviceSid; } - public DeviceSecretReader setPageSize(final Integer pageSize){ + public DeviceSecretReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -48,7 +47,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Devices/{DeviceSid}/Secrets"; - path = path.replace("{"+"DeviceSid"+"}", this.pathDeviceSid.toString()); + path = + path.replace( + "{" + "DeviceSid" + "}", + this.pathDeviceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -60,13 +63,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("DeviceSecret read failed: Unable to connect to server"); + throw new ApiConnectionException( + "DeviceSecret read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +93,10 @@ private Page pageForRequest(final TwilioRestClient client, final R } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.MICROVISOR.toString()) @@ -90,9 +104,11 @@ public Page previousPage(final Page page, final Twil return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.MICROVISOR.toString()) @@ -101,21 +117,21 @@ public Page nextPage(final Page page, final TwilioRe } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/microvisor/v1/device/DeviceSecretUpdater.java b/src/main/java/com/twilio/rest/microvisor/v1/device/DeviceSecretUpdater.java index 1ca03114ad..f72a25ccbf 100644 --- a/src/main/java/com/twilio/rest/microvisor/v1/device/DeviceSecretUpdater.java +++ b/src/main/java/com/twilio/rest/microvisor/v1/device/DeviceSecretUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.microvisor.v1.device; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,56 +25,71 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class DeviceSecretUpdater extends Updater { - - -public class DeviceSecretUpdater extends Updater{ private String pathDeviceSid; private String pathKey; private String value; - public DeviceSecretUpdater(final String pathDeviceSid, final String pathKey, final String value){ + public DeviceSecretUpdater( + final String pathDeviceSid, + final String pathKey, + final String value + ) { this.pathDeviceSid = pathDeviceSid; this.pathKey = pathKey; this.value = value; } - public DeviceSecretUpdater setValue(final String value){ + public DeviceSecretUpdater setValue(final String value) { this.value = value; return this; } @Override - public DeviceSecret update(final TwilioRestClient client){ + public DeviceSecret update(final TwilioRestClient client) { String path = "/v1/Devices/{DeviceSid}/Secrets/{Key}"; - path = path.replace("{"+"DeviceSid"+"}", this.pathDeviceSid.toString()); - path = path.replace("{"+"Key"+"}", this.pathKey.toString()); - path = path.replace("{"+"Value"+"}", this.value.toString()); + path = + path.replace( + "{" + "DeviceSid" + "}", + this.pathDeviceSid.toString() + ); + path = path.replace("{" + "Key" + "}", this.pathKey.toString()); + path = path.replace("{" + "Value" + "}", this.value.toString()); Request request = new Request( HttpMethod.POST, Domains.MICROVISOR.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("DeviceSecret update failed: Unable to connect to server"); + throw new ApiConnectionException( + "DeviceSecret update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return DeviceSecret.fromJson(response.getStream(), client.getObjectMapper()); + return DeviceSecret.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (value != null) { request.addPostParam("Value", value); - } } } diff --git a/src/main/java/com/twilio/rest/monitor/v1/Alert.java b/src/main/java/com/twilio/rest/monitor/v1/Alert.java index 60ecc5e2b0..b716f30f62 100644 --- a/src/main/java/com/twilio/rest/monitor/v1/Alert.java +++ b/src/main/java/com/twilio/rest/monitor/v1/Alert.java @@ -23,42 +23,41 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; import com.twilio.http.HttpMethod; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Alert extends Resource { + private static final long serialVersionUID = 14184743930644L; - public static AlertFetcher fetcher(final String pathSid){ + public static AlertFetcher fetcher(final String pathSid) { return new AlertFetcher(pathSid); } - public static AlertReader reader(){ + public static AlertReader reader() { return new AlertReader(); } /** - * Converts a JSON String into a Alert object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Alert object represented by the provided JSON - */ - public static Alert fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Alert object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Alert object represented by the provided JSON + */ + public static Alert fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Alert.class); @@ -70,14 +69,17 @@ public static Alert fromJson(final String json, final ObjectMapper objectMapper) } /** - * Converts a JSON InputStream into a Alert object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Alert object represented by the provided JSON - */ - public static Alert fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Alert object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Alert object represented by the provided JSON + */ + public static Alert fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Alert.class); @@ -110,68 +112,32 @@ public static Alert fromJson(final InputStream json, final ObjectMapper objectMa @JsonCreator private Alert( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("alert_text") - final String alertText, - - @JsonProperty("api_version") - final String apiVersion, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_generated") - final String dateGenerated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("error_code") - final String errorCode, - - @JsonProperty("log_level") - final String logLevel, - - @JsonProperty("more_info") - final String moreInfo, - - @JsonProperty("request_method") - final HttpMethod requestMethod, - - @JsonProperty("request_url") - final String requestUrl, - - @JsonProperty("request_variables") - final String requestVariables, - - @JsonProperty("resource_sid") - final String resourceSid, - - @JsonProperty("response_body") - final String responseBody, - - @JsonProperty("response_headers") - final String responseHeaders, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("url") - final URI url, - - @JsonProperty("request_headers") - final String requestHeaders, - - @JsonProperty("service_sid") - final String serviceSid + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("alert_text") final String alertText, + @JsonProperty("api_version") final String apiVersion, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_generated") final String dateGenerated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("error_code") final String errorCode, + @JsonProperty("log_level") final String logLevel, + @JsonProperty("more_info") final String moreInfo, + @JsonProperty("request_method") final HttpMethod requestMethod, + @JsonProperty("request_url") final String requestUrl, + @JsonProperty("request_variables") final String requestVariables, + @JsonProperty("resource_sid") final String resourceSid, + @JsonProperty("response_body") final String responseBody, + @JsonProperty("response_headers") final String responseHeaders, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url, + @JsonProperty("request_headers") final String requestHeaders, + @JsonProperty("service_sid") final String serviceSid ) { this.accountSid = accountSid; this.alertText = alertText; this.apiVersion = apiVersion; this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateGenerated = DateConverter.iso8601DateTimeFromString(dateGenerated); + this.dateGenerated = + DateConverter.iso8601DateTimeFromString(dateGenerated); this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); this.errorCode = errorCode; this.logLevel = logLevel; @@ -188,67 +154,85 @@ private Alert( this.serviceSid = serviceSid; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getAlertText() { - return this.alertText; - } - public final String getApiVersion() { - return this.apiVersion; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateGenerated() { - return this.dateGenerated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getErrorCode() { - return this.errorCode; - } - public final String getLogLevel() { - return this.logLevel; - } - public final String getMoreInfo() { - return this.moreInfo; - } - public final HttpMethod getRequestMethod() { - return this.requestMethod; - } - public final String getRequestUrl() { - return this.requestUrl; - } - public final String getRequestVariables() { - return this.requestVariables; - } - public final String getResourceSid() { - return this.resourceSid; - } - public final String getResponseBody() { - return this.responseBody; - } - public final String getResponseHeaders() { - return this.responseHeaders; - } - public final String getSid() { - return this.sid; - } - public final URI getUrl() { - return this.url; - } - public final String getRequestHeaders() { - return this.requestHeaders; - } - public final String getServiceSid() { - return this.serviceSid; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getAlertText() { + return this.alertText; + } + + public final String getApiVersion() { + return this.apiVersion; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateGenerated() { + return this.dateGenerated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getErrorCode() { + return this.errorCode; + } + + public final String getLogLevel() { + return this.logLevel; + } + + public final String getMoreInfo() { + return this.moreInfo; + } + + public final HttpMethod getRequestMethod() { + return this.requestMethod; + } + + public final String getRequestUrl() { + return this.requestUrl; + } + + public final String getRequestVariables() { + return this.requestVariables; + } + + public final String getResourceSid() { + return this.resourceSid; + } + + public final String getResponseBody() { + return this.responseBody; + } + + public final String getResponseHeaders() { + return this.responseHeaders; + } + + public final String getSid() { + return this.sid; + } + + public final URI getUrl() { + return this.url; + } + + public final String getRequestHeaders() { + return this.requestHeaders; + } + + public final String getServiceSid() { + return this.serviceSid; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -258,13 +242,51 @@ public boolean equals(final Object o) { Alert other = (Alert) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(alertText, other.alertText) && Objects.equals(apiVersion, other.apiVersion) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateGenerated, other.dateGenerated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(errorCode, other.errorCode) && Objects.equals(logLevel, other.logLevel) && Objects.equals(moreInfo, other.moreInfo) && Objects.equals(requestMethod, other.requestMethod) && Objects.equals(requestUrl, other.requestUrl) && Objects.equals(requestVariables, other.requestVariables) && Objects.equals(resourceSid, other.resourceSid) && Objects.equals(responseBody, other.responseBody) && Objects.equals(responseHeaders, other.responseHeaders) && Objects.equals(sid, other.sid) && Objects.equals(url, other.url) && Objects.equals(requestHeaders, other.requestHeaders) && Objects.equals(serviceSid, other.serviceSid) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(alertText, other.alertText) && + Objects.equals(apiVersion, other.apiVersion) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateGenerated, other.dateGenerated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(errorCode, other.errorCode) && + Objects.equals(logLevel, other.logLevel) && + Objects.equals(moreInfo, other.moreInfo) && + Objects.equals(requestMethod, other.requestMethod) && + Objects.equals(requestUrl, other.requestUrl) && + Objects.equals(requestVariables, other.requestVariables) && + Objects.equals(resourceSid, other.resourceSid) && + Objects.equals(responseBody, other.responseBody) && + Objects.equals(responseHeaders, other.responseHeaders) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) && + Objects.equals(requestHeaders, other.requestHeaders) && + Objects.equals(serviceSid, other.serviceSid) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, alertText, apiVersion, dateCreated, dateGenerated, dateUpdated, errorCode, logLevel, moreInfo, requestMethod, requestUrl, requestVariables, resourceSid, responseBody, responseHeaders, sid, url, requestHeaders, serviceSid); + return Objects.hash( + accountSid, + alertText, + apiVersion, + dateCreated, + dateGenerated, + dateUpdated, + errorCode, + logLevel, + moreInfo, + requestMethod, + requestUrl, + requestVariables, + resourceSid, + responseBody, + responseHeaders, + sid, + url, + requestHeaders, + serviceSid + ); } - } - diff --git a/src/main/java/com/twilio/rest/monitor/v1/AlertFetcher.java b/src/main/java/com/twilio/rest/monitor/v1/AlertFetcher.java index b906251988..d7fd55d17c 100644 --- a/src/main/java/com/twilio/rest/monitor/v1/AlertFetcher.java +++ b/src/main/java/com/twilio/rest/monitor/v1/AlertFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class AlertFetcher extends Fetcher { + private String pathSid; - public AlertFetcher(final String pathSid){ + public AlertFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public Alert fetch(final TwilioRestClient client) { String path = "/v1/Alerts/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,9 +46,14 @@ public Alert fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Alert fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Alert fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/monitor/v1/AlertReader.java b/src/main/java/com/twilio/rest/monitor/v1/AlertReader.java index 612431b75f..39665f11ff 100644 --- a/src/main/java/com/twilio/rest/monitor/v1/AlertReader.java +++ b/src/main/java/com/twilio/rest/monitor/v1/AlertReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.monitor.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,33 +25,33 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; import java.time.ZonedDateTime; - - public class AlertReader extends Reader { + private String logLevel; private ZonedDateTime startDate; private ZonedDateTime endDate; private Integer pageSize; - public AlertReader(){ - } + public AlertReader() {} - public AlertReader setLogLevel(final String logLevel){ + public AlertReader setLogLevel(final String logLevel) { this.logLevel = logLevel; return this; } - public AlertReader setStartDate(final ZonedDateTime startDate){ + + public AlertReader setStartDate(final ZonedDateTime startDate) { this.startDate = startDate; return this; } - public AlertReader setEndDate(final ZonedDateTime endDate){ + + public AlertReader setEndDate(final ZonedDateTime endDate) { this.endDate = endDate; return this; } - public AlertReader setPageSize(final Integer pageSize){ + + public AlertReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -73,13 +74,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Alert read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Alert read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -95,7 +104,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.MONITOR.toString()) @@ -103,9 +115,11 @@ public Page previousPage(final Page page, final TwilioRestClient c return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.MONITOR.toString()) @@ -114,21 +128,24 @@ public Page nextPage(final Page page, final TwilioRestClient clien } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (logLevel != null) { - request.addQueryParam("LogLevel", logLevel); } if (startDate != null) { - request.addQueryParam("StartDate", startDate.toInstant().toString()); + request.addQueryParam( + "StartDate", + startDate.toInstant().toString() + ); } if (endDate != null) { @@ -136,11 +153,10 @@ private void addQueryParams(final Request request) { } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/monitor/v1/Event.java b/src/main/java/com/twilio/rest/monitor/v1/Event.java index f7be6bd6af..fdac28b2c2 100644 --- a/src/main/java/com/twilio/rest/monitor/v1/Event.java +++ b/src/main/java/com/twilio/rest/monitor/v1/Event.java @@ -23,43 +23,42 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Event extends Resource { + private static final long serialVersionUID = 206221188315695L; - public static EventFetcher fetcher(final String pathSid){ + public static EventFetcher fetcher(final String pathSid) { return new EventFetcher(pathSid); } - public static EventReader reader(){ + public static EventReader reader() { return new EventReader(); } /** - * Converts a JSON String into a Event object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Event object represented by the provided JSON - */ - public static Event fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Event object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Event object represented by the provided JSON + */ + public static Event fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Event.class); @@ -71,14 +70,17 @@ public static Event fromJson(final String json, final ObjectMapper objectMapper) } /** - * Converts a JSON InputStream into a Event object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Event object represented by the provided JSON - */ - public static Event fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Event object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Event object represented by the provided JSON + */ + public static Event fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Event.class); @@ -106,47 +108,20 @@ public static Event fromJson(final InputStream json, final ObjectMapper objectMa @JsonCreator private Event( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("actor_sid") - final String actorSid, - - @JsonProperty("actor_type") - final String actorType, - - @JsonProperty("description") - final String description, - - @JsonProperty("event_data") - final Map eventData, - - @JsonProperty("event_date") - final String eventDate, - - @JsonProperty("event_type") - final String eventType, - - @JsonProperty("resource_sid") - final String resourceSid, - - @JsonProperty("resource_type") - final String resourceType, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("source") - final String source, - - @JsonProperty("source_ip_address") - final String sourceIpAddress, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("actor_sid") final String actorSid, + @JsonProperty("actor_type") final String actorType, + @JsonProperty("description") final String description, + @JsonProperty("event_data") final Map eventData, + @JsonProperty("event_date") final String eventDate, + @JsonProperty("event_type") final String eventType, + @JsonProperty("resource_sid") final String resourceSid, + @JsonProperty("resource_type") final String resourceType, + @JsonProperty("sid") final String sid, + @JsonProperty("source") final String source, + @JsonProperty("source_ip_address") final String sourceIpAddress, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.accountSid = accountSid; this.actorSid = actorSid; @@ -164,52 +139,65 @@ private Event( this.links = links; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getActorSid() { - return this.actorSid; - } - public final String getActorType() { - return this.actorType; - } - public final String getDescription() { - return this.description; - } - public final Map getEventData() { - return this.eventData; - } - public final ZonedDateTime getEventDate() { - return this.eventDate; - } - public final String getEventType() { - return this.eventType; - } - public final String getResourceSid() { - return this.resourceSid; - } - public final String getResourceType() { - return this.resourceType; - } - public final String getSid() { - return this.sid; - } - public final String getSource() { - return this.source; - } - public final String getSourceIpAddress() { - return this.sourceIpAddress; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getActorSid() { + return this.actorSid; + } + + public final String getActorType() { + return this.actorType; + } + + public final String getDescription() { + return this.description; + } + + public final Map getEventData() { + return this.eventData; + } + + public final ZonedDateTime getEventDate() { + return this.eventDate; + } + + public final String getEventType() { + return this.eventType; + } + + public final String getResourceSid() { + return this.resourceSid; + } + + public final String getResourceType() { + return this.resourceType; + } + + public final String getSid() { + return this.sid; + } + + public final String getSource() { + return this.source; + } + + public final String getSourceIpAddress() { + return this.sourceIpAddress; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -219,13 +207,41 @@ public boolean equals(final Object o) { Event other = (Event) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(actorSid, other.actorSid) && Objects.equals(actorType, other.actorType) && Objects.equals(description, other.description) && Objects.equals(eventData, other.eventData) && Objects.equals(eventDate, other.eventDate) && Objects.equals(eventType, other.eventType) && Objects.equals(resourceSid, other.resourceSid) && Objects.equals(resourceType, other.resourceType) && Objects.equals(sid, other.sid) && Objects.equals(source, other.source) && Objects.equals(sourceIpAddress, other.sourceIpAddress) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(actorSid, other.actorSid) && + Objects.equals(actorType, other.actorType) && + Objects.equals(description, other.description) && + Objects.equals(eventData, other.eventData) && + Objects.equals(eventDate, other.eventDate) && + Objects.equals(eventType, other.eventType) && + Objects.equals(resourceSid, other.resourceSid) && + Objects.equals(resourceType, other.resourceType) && + Objects.equals(sid, other.sid) && + Objects.equals(source, other.source) && + Objects.equals(sourceIpAddress, other.sourceIpAddress) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, actorSid, actorType, description, eventData, eventDate, eventType, resourceSid, resourceType, sid, source, sourceIpAddress, url, links); + return Objects.hash( + accountSid, + actorSid, + actorType, + description, + eventData, + eventDate, + eventType, + resourceSid, + resourceType, + sid, + source, + sourceIpAddress, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/monitor/v1/EventFetcher.java b/src/main/java/com/twilio/rest/monitor/v1/EventFetcher.java index c67571d495..bebc22439e 100644 --- a/src/main/java/com/twilio/rest/monitor/v1/EventFetcher.java +++ b/src/main/java/com/twilio/rest/monitor/v1/EventFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class EventFetcher extends Fetcher { + private String pathSid; - public EventFetcher(final String pathSid){ + public EventFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public Event fetch(final TwilioRestClient client) { String path = "/v1/Events/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,9 +46,14 @@ public Event fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Event fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Event fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/monitor/v1/EventReader.java b/src/main/java/com/twilio/rest/monitor/v1/EventReader.java index 3afcd9b296..2af736a660 100644 --- a/src/main/java/com/twilio/rest/monitor/v1/EventReader.java +++ b/src/main/java/com/twilio/rest/monitor/v1/EventReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.monitor.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,12 +25,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; import java.time.ZonedDateTime; - - public class EventReader extends Reader { + private String actorSid; private String eventType; private String resourceSid; @@ -38,34 +37,39 @@ public class EventReader extends Reader { private ZonedDateTime endDate; private Integer pageSize; - public EventReader(){ - } + public EventReader() {} - public EventReader setActorSid(final String actorSid){ + public EventReader setActorSid(final String actorSid) { this.actorSid = actorSid; return this; } - public EventReader setEventType(final String eventType){ + + public EventReader setEventType(final String eventType) { this.eventType = eventType; return this; } - public EventReader setResourceSid(final String resourceSid){ + + public EventReader setResourceSid(final String resourceSid) { this.resourceSid = resourceSid; return this; } - public EventReader setSourceIpAddress(final String sourceIpAddress){ + + public EventReader setSourceIpAddress(final String sourceIpAddress) { this.sourceIpAddress = sourceIpAddress; return this; } - public EventReader setStartDate(final ZonedDateTime startDate){ + + public EventReader setStartDate(final ZonedDateTime startDate) { this.startDate = startDate; return this; } - public EventReader setEndDate(final ZonedDateTime endDate){ + + public EventReader setEndDate(final ZonedDateTime endDate) { this.endDate = endDate; return this; } - public EventReader setPageSize(final Integer pageSize){ + + public EventReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -88,13 +92,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Event read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Event read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -110,7 +122,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.MONITOR.toString()) @@ -118,9 +133,11 @@ public Page previousPage(final Page page, final TwilioRestClient c return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.MONITOR.toString()) @@ -129,33 +146,33 @@ public Page nextPage(final Page page, final TwilioRestClient clien } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (actorSid != null) { - request.addQueryParam("ActorSid", actorSid); } if (eventType != null) { - request.addQueryParam("EventType", eventType); } if (resourceSid != null) { - request.addQueryParam("ResourceSid", resourceSid); } if (sourceIpAddress != null) { - request.addQueryParam("SourceIpAddress", sourceIpAddress); } if (startDate != null) { - request.addQueryParam("StartDate", startDate.toInstant().toString()); + request.addQueryParam( + "StartDate", + startDate.toInstant().toString() + ); } if (endDate != null) { @@ -163,11 +180,10 @@ private void addQueryParams(final Request request) { } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/notify/v1/Credential.java b/src/main/java/com/twilio/rest/notify/v1/Credential.java index d47aba76a7..5ff7b27625 100644 --- a/src/main/java/com/twilio/rest/notify/v1/Credential.java +++ b/src/main/java/com/twilio/rest/notify/v1/Credential.java @@ -24,53 +24,52 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Credential extends Resource { + private static final long serialVersionUID = 161183169234848L; - public static CredentialCreator creator(final Credential.PushService type){ + public static CredentialCreator creator(final Credential.PushService type) { return new CredentialCreator(type); } - public static CredentialDeleter deleter(final String pathSid){ + public static CredentialDeleter deleter(final String pathSid) { return new CredentialDeleter(pathSid); } - public static CredentialFetcher fetcher(final String pathSid){ + public static CredentialFetcher fetcher(final String pathSid) { return new CredentialFetcher(pathSid); } - public static CredentialReader reader(){ + public static CredentialReader reader() { return new CredentialReader(); } - public static CredentialUpdater updater(final String pathSid){ + public static CredentialUpdater updater(final String pathSid) { return new CredentialUpdater(pathSid); } /** - * Converts a JSON String into a Credential object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Credential object represented by the provided JSON - */ - public static Credential fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Credential object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Credential object represented by the provided JSON + */ + public static Credential fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Credential.class); @@ -82,14 +81,17 @@ public static Credential fromJson(final String json, final ObjectMapper objectMa } /** - * Converts a JSON InputStream into a Credential object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Credential object represented by the provided JSON - */ - public static Credential fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Credential object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Credential object represented by the provided JSON + */ + public static Credential fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Credential.class); @@ -99,6 +101,7 @@ public static Credential fromJson(final InputStream json, final ObjectMapper obj throw new ApiConnectionException(e.getMessage(), e); } } + public enum PushService { GCM("gcm"), APN("apn"), @@ -131,29 +134,14 @@ public static PushService forValue(final String value) { @JsonCreator private Credential( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("type") - final Credential.PushService type, - - @JsonProperty("sandbox") - final String sandbox, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("type") final Credential.PushService type, + @JsonProperty("sandbox") final String sandbox, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url ) { this.sid = sid; this.accountSid = accountSid; @@ -165,34 +153,41 @@ private Credential( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final Credential.PushService getType() { - return this.type; - } - public final String getSandbox() { - return this.sandbox; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final Credential.PushService getType() { + return this.type; + } + + public final String getSandbox() { + return this.sandbox; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -202,13 +197,29 @@ public boolean equals(final Object o) { Credential other = (Credential) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(type, other.type) && Objects.equals(sandbox, other.sandbox) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(type, other.type) && + Objects.equals(sandbox, other.sandbox) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, friendlyName, type, sandbox, dateCreated, dateUpdated, url); + return Objects.hash( + sid, + accountSid, + friendlyName, + type, + sandbox, + dateCreated, + dateUpdated, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/notify/v1/CredentialCreator.java b/src/main/java/com/twilio/rest/notify/v1/CredentialCreator.java index 3bad75fed6..8ee045e48c 100644 --- a/src/main/java/com/twilio/rest/notify/v1/CredentialCreator.java +++ b/src/main/java/com/twilio/rest/notify/v1/CredentialCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.notify.v1; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class CredentialCreator extends Creator { - - -public class CredentialCreator extends Creator{ private Credential.PushService type; private String friendlyName; private String certificate; @@ -40,88 +39,97 @@ public CredentialCreator(final Credential.PushService type) { this.type = type; } - public CredentialCreator setType(final Credential.PushService type){ + public CredentialCreator setType(final Credential.PushService type) { this.type = type; return this; } - public CredentialCreator setFriendlyName(final String friendlyName){ + + public CredentialCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public CredentialCreator setCertificate(final String certificate){ + + public CredentialCreator setCertificate(final String certificate) { this.certificate = certificate; return this; } - public CredentialCreator setPrivateKey(final String privateKey){ + + public CredentialCreator setPrivateKey(final String privateKey) { this.privateKey = privateKey; return this; } - public CredentialCreator setSandbox(final Boolean sandbox){ + + public CredentialCreator setSandbox(final Boolean sandbox) { this.sandbox = sandbox; return this; } - public CredentialCreator setApiKey(final String apiKey){ + + public CredentialCreator setApiKey(final String apiKey) { this.apiKey = apiKey; return this; } - public CredentialCreator setSecret(final String secret){ + + public CredentialCreator setSecret(final String secret) { this.secret = secret; return this; } @Override - public Credential create(final TwilioRestClient client){ + public Credential create(final TwilioRestClient client) { String path = "/v1/Credentials"; - path = path.replace("{"+"Type"+"}", this.type.toString()); + path = path.replace("{" + "Type" + "}", this.type.toString()); Request request = new Request( HttpMethod.POST, Domains.NOTIFY.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Credential creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Credential creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Credential.fromJson(response.getStream(), client.getObjectMapper()); + return Credential.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (type != null) { request.addPostParam("Type", type.toString()); - } if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (certificate != null) { request.addPostParam("Certificate", certificate); - } if (privateKey != null) { request.addPostParam("PrivateKey", privateKey); - } if (sandbox != null) { request.addPostParam("Sandbox", sandbox.toString()); - } if (apiKey != null) { request.addPostParam("ApiKey", apiKey); - } if (secret != null) { request.addPostParam("Secret", secret); - } } } diff --git a/src/main/java/com/twilio/rest/notify/v1/CredentialDeleter.java b/src/main/java/com/twilio/rest/notify/v1/CredentialDeleter.java index 4f5721283b..68945381f2 100644 --- a/src/main/java/com/twilio/rest/notify/v1/CredentialDeleter.java +++ b/src/main/java/com/twilio/rest/notify/v1/CredentialDeleter.java @@ -24,21 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class CredentialDeleter extends Deleter { + private String pathSid; - public CredentialDeleter(final String pathSid){ + public CredentialDeleter(final String pathSid) { this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Credentials/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -48,9 +46,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Credential delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Credential delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/notify/v1/CredentialFetcher.java b/src/main/java/com/twilio/rest/notify/v1/CredentialFetcher.java index 8c84506d4f..cb904092fe 100644 --- a/src/main/java/com/twilio/rest/notify/v1/CredentialFetcher.java +++ b/src/main/java/com/twilio/rest/notify/v1/CredentialFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class CredentialFetcher extends Fetcher { + private String pathSid; - public CredentialFetcher(final String pathSid){ + public CredentialFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public Credential fetch(final TwilioRestClient client) { String path = "/v1/Credentials/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,15 +46,23 @@ public Credential fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Credential fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Credential fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Credential.fromJson(response.getStream(), client.getObjectMapper()); + return Credential.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/notify/v1/CredentialReader.java b/src/main/java/com/twilio/rest/notify/v1/CredentialReader.java index 566fe6ea6a..ce73ab93dc 100644 --- a/src/main/java/com/twilio/rest/notify/v1/CredentialReader.java +++ b/src/main/java/com/twilio/rest/notify/v1/CredentialReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.notify.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,17 +25,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class CredentialReader extends Reader { + private Integer pageSize; - public CredentialReader(){ - } + public CredentialReader() {} - public CredentialReader setPageSize(final Integer pageSize){ + public CredentialReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -57,13 +55,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Credential read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Credential read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -79,7 +85,10 @@ private Page pageForRequest(final TwilioRestClient client, final Req } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.NOTIFY.toString()) @@ -87,9 +96,11 @@ public Page previousPage(final Page page, final TwilioRe return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.NOTIFY.toString()) @@ -98,21 +109,21 @@ public Page nextPage(final Page page, final TwilioRestCl } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/notify/v1/CredentialUpdater.java b/src/main/java/com/twilio/rest/notify/v1/CredentialUpdater.java index 8ca2edeb39..1dc6a67362 100644 --- a/src/main/java/com/twilio/rest/notify/v1/CredentialUpdater.java +++ b/src/main/java/com/twilio/rest/notify/v1/CredentialUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.notify.v1; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class CredentialUpdater extends Updater { - - -public class CredentialUpdater extends Updater{ private String pathSid; private String friendlyName; private String certificate; @@ -36,84 +35,93 @@ public class CredentialUpdater extends Updater{ private String apiKey; private String secret; - public CredentialUpdater(final String pathSid){ + public CredentialUpdater(final String pathSid) { this.pathSid = pathSid; } - public CredentialUpdater setFriendlyName(final String friendlyName){ + public CredentialUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public CredentialUpdater setCertificate(final String certificate){ + + public CredentialUpdater setCertificate(final String certificate) { this.certificate = certificate; return this; } - public CredentialUpdater setPrivateKey(final String privateKey){ + + public CredentialUpdater setPrivateKey(final String privateKey) { this.privateKey = privateKey; return this; } - public CredentialUpdater setSandbox(final Boolean sandbox){ + + public CredentialUpdater setSandbox(final Boolean sandbox) { this.sandbox = sandbox; return this; } - public CredentialUpdater setApiKey(final String apiKey){ + + public CredentialUpdater setApiKey(final String apiKey) { this.apiKey = apiKey; return this; } - public CredentialUpdater setSecret(final String secret){ + + public CredentialUpdater setSecret(final String secret) { this.secret = secret; return this; } @Override - public Credential update(final TwilioRestClient client){ + public Credential update(final TwilioRestClient client) { String path = "/v1/Credentials/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.NOTIFY.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Credential update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Credential update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Credential.fromJson(response.getStream(), client.getObjectMapper()); + return Credential.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (certificate != null) { request.addPostParam("Certificate", certificate); - } if (privateKey != null) { request.addPostParam("PrivateKey", privateKey); - } if (sandbox != null) { request.addPostParam("Sandbox", sandbox.toString()); - } if (apiKey != null) { request.addPostParam("ApiKey", apiKey); - } if (secret != null) { request.addPostParam("Secret", secret); - } } } diff --git a/src/main/java/com/twilio/rest/notify/v1/Service.java b/src/main/java/com/twilio/rest/notify/v1/Service.java index 8fc50d0962..d051e43198 100644 --- a/src/main/java/com/twilio/rest/notify/v1/Service.java +++ b/src/main/java/com/twilio/rest/notify/v1/Service.java @@ -23,55 +23,54 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Service extends Resource { + private static final long serialVersionUID = 212409990270052L; - public static ServiceCreator creator(){ + public static ServiceCreator creator() { return new ServiceCreator(); } - public static ServiceDeleter deleter(final String pathSid){ + public static ServiceDeleter deleter(final String pathSid) { return new ServiceDeleter(pathSid); } - public static ServiceFetcher fetcher(final String pathSid){ + public static ServiceFetcher fetcher(final String pathSid) { return new ServiceFetcher(pathSid); } - public static ServiceReader reader(){ + public static ServiceReader reader() { return new ServiceReader(); } - public static ServiceUpdater updater(final String pathSid){ + public static ServiceUpdater updater(final String pathSid) { return new ServiceUpdater(pathSid); } /** - * Converts a JSON String into a Service object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Service object represented by the provided JSON - */ - public static Service fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Service object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Service object represented by the provided JSON + */ + public static Service fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Service.class); @@ -83,14 +82,17 @@ public static Service fromJson(final String json, final ObjectMapper objectMappe } /** - * Converts a JSON InputStream into a Service object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Service object represented by the provided JSON - */ - public static Service fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Service object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Service object represented by the provided JSON + */ + public static Service fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Service.class); @@ -124,152 +126,148 @@ public static Service fromJson(final InputStream json, final ObjectMapper object @JsonCreator private Service( - @JsonProperty("sid") - final String sid, + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("apn_credential_sid") final String apnCredentialSid, + @JsonProperty("gcm_credential_sid") final String gcmCredentialSid, + @JsonProperty("fcm_credential_sid") final String fcmCredentialSid, + @JsonProperty("messaging_service_sid") final String messagingServiceSid, + @JsonProperty( + "facebook_messenger_page_id" + ) final String facebookMessengerPageId, + @JsonProperty( + "default_apn_notification_protocol_version" + ) final String defaultApnNotificationProtocolVersion, + @JsonProperty( + "default_gcm_notification_protocol_version" + ) final String defaultGcmNotificationProtocolVersion, + @JsonProperty( + "default_fcm_notification_protocol_version" + ) final String defaultFcmNotificationProtocolVersion, + @JsonProperty("log_enabled") final Boolean logEnabled, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links, + @JsonProperty("alexa_skill_id") final String alexaSkillId, + @JsonProperty( + "default_alexa_notification_protocol_version" + ) final String defaultAlexaNotificationProtocolVersion, + @JsonProperty("delivery_callback_url") final String deliveryCallbackUrl, + @JsonProperty( + "delivery_callback_enabled" + ) final Boolean deliveryCallbackEnabled + ) { + this.sid = sid; + this.accountSid = accountSid; + this.friendlyName = friendlyName; + this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); + this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); + this.apnCredentialSid = apnCredentialSid; + this.gcmCredentialSid = gcmCredentialSid; + this.fcmCredentialSid = fcmCredentialSid; + this.messagingServiceSid = messagingServiceSid; + this.facebookMessengerPageId = facebookMessengerPageId; + this.defaultApnNotificationProtocolVersion = + defaultApnNotificationProtocolVersion; + this.defaultGcmNotificationProtocolVersion = + defaultGcmNotificationProtocolVersion; + this.defaultFcmNotificationProtocolVersion = + defaultFcmNotificationProtocolVersion; + this.logEnabled = logEnabled; + this.url = url; + this.links = links; + this.alexaSkillId = alexaSkillId; + this.defaultAlexaNotificationProtocolVersion = + defaultAlexaNotificationProtocolVersion; + this.deliveryCallbackUrl = deliveryCallbackUrl; + this.deliveryCallbackEnabled = deliveryCallbackEnabled; + } - @JsonProperty("account_sid") - final String accountSid, + public final String getSid() { + return this.sid; + } - @JsonProperty("friendly_name") - final String friendlyName, + public final String getAccountSid() { + return this.accountSid; + } - @JsonProperty("date_created") - final String dateCreated, + public final String getFriendlyName() { + return this.friendlyName; + } - @JsonProperty("date_updated") - final String dateUpdated, + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } - @JsonProperty("apn_credential_sid") - final String apnCredentialSid, + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } - @JsonProperty("gcm_credential_sid") - final String gcmCredentialSid, + public final String getApnCredentialSid() { + return this.apnCredentialSid; + } - @JsonProperty("fcm_credential_sid") - final String fcmCredentialSid, + public final String getGcmCredentialSid() { + return this.gcmCredentialSid; + } - @JsonProperty("messaging_service_sid") - final String messagingServiceSid, + public final String getFcmCredentialSid() { + return this.fcmCredentialSid; + } - @JsonProperty("facebook_messenger_page_id") - final String facebookMessengerPageId, + public final String getMessagingServiceSid() { + return this.messagingServiceSid; + } - @JsonProperty("default_apn_notification_protocol_version") - final String defaultApnNotificationProtocolVersion, + public final String getFacebookMessengerPageId() { + return this.facebookMessengerPageId; + } - @JsonProperty("default_gcm_notification_protocol_version") - final String defaultGcmNotificationProtocolVersion, + public final String getDefaultApnNotificationProtocolVersion() { + return this.defaultApnNotificationProtocolVersion; + } - @JsonProperty("default_fcm_notification_protocol_version") - final String defaultFcmNotificationProtocolVersion, + public final String getDefaultGcmNotificationProtocolVersion() { + return this.defaultGcmNotificationProtocolVersion; + } - @JsonProperty("log_enabled") - final Boolean logEnabled, + public final String getDefaultFcmNotificationProtocolVersion() { + return this.defaultFcmNotificationProtocolVersion; + } - @JsonProperty("url") - final URI url, + public final Boolean getLogEnabled() { + return this.logEnabled; + } - @JsonProperty("links") - final Map links, + public final URI getUrl() { + return this.url; + } - @JsonProperty("alexa_skill_id") - final String alexaSkillId, + public final Map getLinks() { + return this.links; + } - @JsonProperty("default_alexa_notification_protocol_version") - final String defaultAlexaNotificationProtocolVersion, + public final String getAlexaSkillId() { + return this.alexaSkillId; + } - @JsonProperty("delivery_callback_url") - final String deliveryCallbackUrl, + public final String getDefaultAlexaNotificationProtocolVersion() { + return this.defaultAlexaNotificationProtocolVersion; + } - @JsonProperty("delivery_callback_enabled") - final Boolean deliveryCallbackEnabled - ) { - this.sid = sid; - this.accountSid = accountSid; - this.friendlyName = friendlyName; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.apnCredentialSid = apnCredentialSid; - this.gcmCredentialSid = gcmCredentialSid; - this.fcmCredentialSid = fcmCredentialSid; - this.messagingServiceSid = messagingServiceSid; - this.facebookMessengerPageId = facebookMessengerPageId; - this.defaultApnNotificationProtocolVersion = defaultApnNotificationProtocolVersion; - this.defaultGcmNotificationProtocolVersion = defaultGcmNotificationProtocolVersion; - this.defaultFcmNotificationProtocolVersion = defaultFcmNotificationProtocolVersion; - this.logEnabled = logEnabled; - this.url = url; - this.links = links; - this.alexaSkillId = alexaSkillId; - this.defaultAlexaNotificationProtocolVersion = defaultAlexaNotificationProtocolVersion; - this.deliveryCallbackUrl = deliveryCallbackUrl; - this.deliveryCallbackEnabled = deliveryCallbackEnabled; + public final String getDeliveryCallbackUrl() { + return this.deliveryCallbackUrl; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getApnCredentialSid() { - return this.apnCredentialSid; - } - public final String getGcmCredentialSid() { - return this.gcmCredentialSid; - } - public final String getFcmCredentialSid() { - return this.fcmCredentialSid; - } - public final String getMessagingServiceSid() { - return this.messagingServiceSid; - } - public final String getFacebookMessengerPageId() { - return this.facebookMessengerPageId; - } - public final String getDefaultApnNotificationProtocolVersion() { - return this.defaultApnNotificationProtocolVersion; - } - public final String getDefaultGcmNotificationProtocolVersion() { - return this.defaultGcmNotificationProtocolVersion; - } - public final String getDefaultFcmNotificationProtocolVersion() { - return this.defaultFcmNotificationProtocolVersion; - } - public final Boolean getLogEnabled() { - return this.logEnabled; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } - public final String getAlexaSkillId() { - return this.alexaSkillId; - } - public final String getDefaultAlexaNotificationProtocolVersion() { - return this.defaultAlexaNotificationProtocolVersion; - } - public final String getDeliveryCallbackUrl() { - return this.deliveryCallbackUrl; - } - public final Boolean getDeliveryCallbackEnabled() { - return this.deliveryCallbackEnabled; - } + public final Boolean getDeliveryCallbackEnabled() { + return this.deliveryCallbackEnabled; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -279,13 +277,71 @@ public boolean equals(final Object o) { Service other = (Service) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(apnCredentialSid, other.apnCredentialSid) && Objects.equals(gcmCredentialSid, other.gcmCredentialSid) && Objects.equals(fcmCredentialSid, other.fcmCredentialSid) && Objects.equals(messagingServiceSid, other.messagingServiceSid) && Objects.equals(facebookMessengerPageId, other.facebookMessengerPageId) && Objects.equals(defaultApnNotificationProtocolVersion, other.defaultApnNotificationProtocolVersion) && Objects.equals(defaultGcmNotificationProtocolVersion, other.defaultGcmNotificationProtocolVersion) && Objects.equals(defaultFcmNotificationProtocolVersion, other.defaultFcmNotificationProtocolVersion) && Objects.equals(logEnabled, other.logEnabled) && Objects.equals(url, other.url) && Objects.equals(links, other.links) && Objects.equals(alexaSkillId, other.alexaSkillId) && Objects.equals(defaultAlexaNotificationProtocolVersion, other.defaultAlexaNotificationProtocolVersion) && Objects.equals(deliveryCallbackUrl, other.deliveryCallbackUrl) && Objects.equals(deliveryCallbackEnabled, other.deliveryCallbackEnabled) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(apnCredentialSid, other.apnCredentialSid) && + Objects.equals(gcmCredentialSid, other.gcmCredentialSid) && + Objects.equals(fcmCredentialSid, other.fcmCredentialSid) && + Objects.equals(messagingServiceSid, other.messagingServiceSid) && + Objects.equals( + facebookMessengerPageId, + other.facebookMessengerPageId + ) && + Objects.equals( + defaultApnNotificationProtocolVersion, + other.defaultApnNotificationProtocolVersion + ) && + Objects.equals( + defaultGcmNotificationProtocolVersion, + other.defaultGcmNotificationProtocolVersion + ) && + Objects.equals( + defaultFcmNotificationProtocolVersion, + other.defaultFcmNotificationProtocolVersion + ) && + Objects.equals(logEnabled, other.logEnabled) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) && + Objects.equals(alexaSkillId, other.alexaSkillId) && + Objects.equals( + defaultAlexaNotificationProtocolVersion, + other.defaultAlexaNotificationProtocolVersion + ) && + Objects.equals(deliveryCallbackUrl, other.deliveryCallbackUrl) && + Objects.equals( + deliveryCallbackEnabled, + other.deliveryCallbackEnabled + ) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, friendlyName, dateCreated, dateUpdated, apnCredentialSid, gcmCredentialSid, fcmCredentialSid, messagingServiceSid, facebookMessengerPageId, defaultApnNotificationProtocolVersion, defaultGcmNotificationProtocolVersion, defaultFcmNotificationProtocolVersion, logEnabled, url, links, alexaSkillId, defaultAlexaNotificationProtocolVersion, deliveryCallbackUrl, deliveryCallbackEnabled); + return Objects.hash( + sid, + accountSid, + friendlyName, + dateCreated, + dateUpdated, + apnCredentialSid, + gcmCredentialSid, + fcmCredentialSid, + messagingServiceSid, + facebookMessengerPageId, + defaultApnNotificationProtocolVersion, + defaultGcmNotificationProtocolVersion, + defaultFcmNotificationProtocolVersion, + logEnabled, + url, + links, + alexaSkillId, + defaultAlexaNotificationProtocolVersion, + deliveryCallbackUrl, + deliveryCallbackEnabled + ); } - } - diff --git a/src/main/java/com/twilio/rest/notify/v1/ServiceCreator.java b/src/main/java/com/twilio/rest/notify/v1/ServiceCreator.java index ebb6240b0e..10b009c9fd 100644 --- a/src/main/java/com/twilio/rest/notify/v1/ServiceCreator.java +++ b/src/main/java/com/twilio/rest/notify/v1/ServiceCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.notify.v1; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class ServiceCreator extends Creator { - - -public class ServiceCreator extends Creator{ private String friendlyName; private String apnCredentialSid; private String gcmCredentialSid; @@ -43,82 +42,119 @@ public class ServiceCreator extends Creator{ private String deliveryCallbackUrl; private Boolean deliveryCallbackEnabled; - public ServiceCreator() { - } + public ServiceCreator() {} - public ServiceCreator setFriendlyName(final String friendlyName){ + public ServiceCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public ServiceCreator setApnCredentialSid(final String apnCredentialSid){ + + public ServiceCreator setApnCredentialSid(final String apnCredentialSid) { this.apnCredentialSid = apnCredentialSid; return this; } - public ServiceCreator setGcmCredentialSid(final String gcmCredentialSid){ + + public ServiceCreator setGcmCredentialSid(final String gcmCredentialSid) { this.gcmCredentialSid = gcmCredentialSid; return this; } - public ServiceCreator setMessagingServiceSid(final String messagingServiceSid){ + + public ServiceCreator setMessagingServiceSid( + final String messagingServiceSid + ) { this.messagingServiceSid = messagingServiceSid; return this; } - public ServiceCreator setFacebookMessengerPageId(final String facebookMessengerPageId){ + + public ServiceCreator setFacebookMessengerPageId( + final String facebookMessengerPageId + ) { this.facebookMessengerPageId = facebookMessengerPageId; return this; } - public ServiceCreator setDefaultApnNotificationProtocolVersion(final String defaultApnNotificationProtocolVersion){ - this.defaultApnNotificationProtocolVersion = defaultApnNotificationProtocolVersion; + + public ServiceCreator setDefaultApnNotificationProtocolVersion( + final String defaultApnNotificationProtocolVersion + ) { + this.defaultApnNotificationProtocolVersion = + defaultApnNotificationProtocolVersion; return this; } - public ServiceCreator setDefaultGcmNotificationProtocolVersion(final String defaultGcmNotificationProtocolVersion){ - this.defaultGcmNotificationProtocolVersion = defaultGcmNotificationProtocolVersion; + + public ServiceCreator setDefaultGcmNotificationProtocolVersion( + final String defaultGcmNotificationProtocolVersion + ) { + this.defaultGcmNotificationProtocolVersion = + defaultGcmNotificationProtocolVersion; return this; } - public ServiceCreator setFcmCredentialSid(final String fcmCredentialSid){ + + public ServiceCreator setFcmCredentialSid(final String fcmCredentialSid) { this.fcmCredentialSid = fcmCredentialSid; return this; } - public ServiceCreator setDefaultFcmNotificationProtocolVersion(final String defaultFcmNotificationProtocolVersion){ - this.defaultFcmNotificationProtocolVersion = defaultFcmNotificationProtocolVersion; + + public ServiceCreator setDefaultFcmNotificationProtocolVersion( + final String defaultFcmNotificationProtocolVersion + ) { + this.defaultFcmNotificationProtocolVersion = + defaultFcmNotificationProtocolVersion; return this; } - public ServiceCreator setLogEnabled(final Boolean logEnabled){ + + public ServiceCreator setLogEnabled(final Boolean logEnabled) { this.logEnabled = logEnabled; return this; } - public ServiceCreator setAlexaSkillId(final String alexaSkillId){ + + public ServiceCreator setAlexaSkillId(final String alexaSkillId) { this.alexaSkillId = alexaSkillId; return this; } - public ServiceCreator setDefaultAlexaNotificationProtocolVersion(final String defaultAlexaNotificationProtocolVersion){ - this.defaultAlexaNotificationProtocolVersion = defaultAlexaNotificationProtocolVersion; + + public ServiceCreator setDefaultAlexaNotificationProtocolVersion( + final String defaultAlexaNotificationProtocolVersion + ) { + this.defaultAlexaNotificationProtocolVersion = + defaultAlexaNotificationProtocolVersion; return this; } - public ServiceCreator setDeliveryCallbackUrl(final String deliveryCallbackUrl){ + + public ServiceCreator setDeliveryCallbackUrl( + final String deliveryCallbackUrl + ) { this.deliveryCallbackUrl = deliveryCallbackUrl; return this; } - public ServiceCreator setDeliveryCallbackEnabled(final Boolean deliveryCallbackEnabled){ + + public ServiceCreator setDeliveryCallbackEnabled( + final Boolean deliveryCallbackEnabled + ) { this.deliveryCallbackEnabled = deliveryCallbackEnabled; return this; } @Override - public Service create(final TwilioRestClient client){ + public Service create(final TwilioRestClient client) { String path = "/v1/Services"; - Request request = new Request( HttpMethod.POST, Domains.NOTIFY.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -127,62 +163,67 @@ public Service create(final TwilioRestClient client){ return Service.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (apnCredentialSid != null) { request.addPostParam("ApnCredentialSid", apnCredentialSid); - } if (gcmCredentialSid != null) { request.addPostParam("GcmCredentialSid", gcmCredentialSid); - } if (messagingServiceSid != null) { request.addPostParam("MessagingServiceSid", messagingServiceSid); - } if (facebookMessengerPageId != null) { - request.addPostParam("FacebookMessengerPageId", facebookMessengerPageId); - + request.addPostParam( + "FacebookMessengerPageId", + facebookMessengerPageId + ); } if (defaultApnNotificationProtocolVersion != null) { - request.addPostParam("DefaultApnNotificationProtocolVersion", defaultApnNotificationProtocolVersion); - + request.addPostParam( + "DefaultApnNotificationProtocolVersion", + defaultApnNotificationProtocolVersion + ); } if (defaultGcmNotificationProtocolVersion != null) { - request.addPostParam("DefaultGcmNotificationProtocolVersion", defaultGcmNotificationProtocolVersion); - + request.addPostParam( + "DefaultGcmNotificationProtocolVersion", + defaultGcmNotificationProtocolVersion + ); } if (fcmCredentialSid != null) { request.addPostParam("FcmCredentialSid", fcmCredentialSid); - } if (defaultFcmNotificationProtocolVersion != null) { - request.addPostParam("DefaultFcmNotificationProtocolVersion", defaultFcmNotificationProtocolVersion); - + request.addPostParam( + "DefaultFcmNotificationProtocolVersion", + defaultFcmNotificationProtocolVersion + ); } if (logEnabled != null) { request.addPostParam("LogEnabled", logEnabled.toString()); - } if (alexaSkillId != null) { request.addPostParam("AlexaSkillId", alexaSkillId); - } if (defaultAlexaNotificationProtocolVersion != null) { - request.addPostParam("DefaultAlexaNotificationProtocolVersion", defaultAlexaNotificationProtocolVersion); - + request.addPostParam( + "DefaultAlexaNotificationProtocolVersion", + defaultAlexaNotificationProtocolVersion + ); } if (deliveryCallbackUrl != null) { request.addPostParam("DeliveryCallbackUrl", deliveryCallbackUrl); - } if (deliveryCallbackEnabled != null) { - request.addPostParam("DeliveryCallbackEnabled", deliveryCallbackEnabled.toString()); - + request.addPostParam( + "DeliveryCallbackEnabled", + deliveryCallbackEnabled.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/notify/v1/ServiceDeleter.java b/src/main/java/com/twilio/rest/notify/v1/ServiceDeleter.java index 9571a4ad05..98e26682ed 100644 --- a/src/main/java/com/twilio/rest/notify/v1/ServiceDeleter.java +++ b/src/main/java/com/twilio/rest/notify/v1/ServiceDeleter.java @@ -24,21 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class ServiceDeleter extends Deleter { + private String pathSid; - public ServiceDeleter(final String pathSid){ + public ServiceDeleter(final String pathSid) { this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Services/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -48,9 +46,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/notify/v1/ServiceFetcher.java b/src/main/java/com/twilio/rest/notify/v1/ServiceFetcher.java index dd26a4d27d..2eebf24989 100644 --- a/src/main/java/com/twilio/rest/notify/v1/ServiceFetcher.java +++ b/src/main/java/com/twilio/rest/notify/v1/ServiceFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class ServiceFetcher extends Fetcher { + private String pathSid; - public ServiceFetcher(final String pathSid){ + public ServiceFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public Service fetch(final TwilioRestClient client) { String path = "/v1/Services/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,9 +46,14 @@ public Service fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/notify/v1/ServiceReader.java b/src/main/java/com/twilio/rest/notify/v1/ServiceReader.java index 59313cab44..5393c0beec 100644 --- a/src/main/java/com/twilio/rest/notify/v1/ServiceReader.java +++ b/src/main/java/com/twilio/rest/notify/v1/ServiceReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.notify.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,22 +25,20 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class ServiceReader extends Reader { + private String friendlyName; private Integer pageSize; - public ServiceReader(){ - } + public ServiceReader() {} - public ServiceReader setFriendlyName(final String friendlyName){ + public ServiceReader setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public ServiceReader setPageSize(final Integer pageSize){ + + public ServiceReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -62,13 +61,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -84,7 +91,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reques } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.NOTIFY.toString()) @@ -92,9 +102,11 @@ public Page previousPage(final Page page, final TwilioRestClie return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.NOTIFY.toString()) @@ -103,25 +115,24 @@ public Page nextPage(final Page page, final TwilioRestClient c } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (friendlyName != null) { - request.addQueryParam("FriendlyName", friendlyName); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/notify/v1/ServiceUpdater.java b/src/main/java/com/twilio/rest/notify/v1/ServiceUpdater.java index efbd64110d..ab94a08a41 100644 --- a/src/main/java/com/twilio/rest/notify/v1/ServiceUpdater.java +++ b/src/main/java/com/twilio/rest/notify/v1/ServiceUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.notify.v1; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class ServiceUpdater extends Updater { - - -public class ServiceUpdater extends Updater{ private String pathSid; private String friendlyName; private String apnCredentialSid; @@ -44,84 +43,123 @@ public class ServiceUpdater extends Updater{ private String deliveryCallbackUrl; private Boolean deliveryCallbackEnabled; - public ServiceUpdater(final String pathSid){ + public ServiceUpdater(final String pathSid) { this.pathSid = pathSid; } - public ServiceUpdater setFriendlyName(final String friendlyName){ + public ServiceUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public ServiceUpdater setApnCredentialSid(final String apnCredentialSid){ + + public ServiceUpdater setApnCredentialSid(final String apnCredentialSid) { this.apnCredentialSid = apnCredentialSid; return this; } - public ServiceUpdater setGcmCredentialSid(final String gcmCredentialSid){ + + public ServiceUpdater setGcmCredentialSid(final String gcmCredentialSid) { this.gcmCredentialSid = gcmCredentialSid; return this; } - public ServiceUpdater setMessagingServiceSid(final String messagingServiceSid){ + + public ServiceUpdater setMessagingServiceSid( + final String messagingServiceSid + ) { this.messagingServiceSid = messagingServiceSid; return this; } - public ServiceUpdater setFacebookMessengerPageId(final String facebookMessengerPageId){ + + public ServiceUpdater setFacebookMessengerPageId( + final String facebookMessengerPageId + ) { this.facebookMessengerPageId = facebookMessengerPageId; return this; } - public ServiceUpdater setDefaultApnNotificationProtocolVersion(final String defaultApnNotificationProtocolVersion){ - this.defaultApnNotificationProtocolVersion = defaultApnNotificationProtocolVersion; + + public ServiceUpdater setDefaultApnNotificationProtocolVersion( + final String defaultApnNotificationProtocolVersion + ) { + this.defaultApnNotificationProtocolVersion = + defaultApnNotificationProtocolVersion; return this; } - public ServiceUpdater setDefaultGcmNotificationProtocolVersion(final String defaultGcmNotificationProtocolVersion){ - this.defaultGcmNotificationProtocolVersion = defaultGcmNotificationProtocolVersion; + + public ServiceUpdater setDefaultGcmNotificationProtocolVersion( + final String defaultGcmNotificationProtocolVersion + ) { + this.defaultGcmNotificationProtocolVersion = + defaultGcmNotificationProtocolVersion; return this; } - public ServiceUpdater setFcmCredentialSid(final String fcmCredentialSid){ + + public ServiceUpdater setFcmCredentialSid(final String fcmCredentialSid) { this.fcmCredentialSid = fcmCredentialSid; return this; } - public ServiceUpdater setDefaultFcmNotificationProtocolVersion(final String defaultFcmNotificationProtocolVersion){ - this.defaultFcmNotificationProtocolVersion = defaultFcmNotificationProtocolVersion; + + public ServiceUpdater setDefaultFcmNotificationProtocolVersion( + final String defaultFcmNotificationProtocolVersion + ) { + this.defaultFcmNotificationProtocolVersion = + defaultFcmNotificationProtocolVersion; return this; } - public ServiceUpdater setLogEnabled(final Boolean logEnabled){ + + public ServiceUpdater setLogEnabled(final Boolean logEnabled) { this.logEnabled = logEnabled; return this; } - public ServiceUpdater setAlexaSkillId(final String alexaSkillId){ + + public ServiceUpdater setAlexaSkillId(final String alexaSkillId) { this.alexaSkillId = alexaSkillId; return this; } - public ServiceUpdater setDefaultAlexaNotificationProtocolVersion(final String defaultAlexaNotificationProtocolVersion){ - this.defaultAlexaNotificationProtocolVersion = defaultAlexaNotificationProtocolVersion; + + public ServiceUpdater setDefaultAlexaNotificationProtocolVersion( + final String defaultAlexaNotificationProtocolVersion + ) { + this.defaultAlexaNotificationProtocolVersion = + defaultAlexaNotificationProtocolVersion; return this; } - public ServiceUpdater setDeliveryCallbackUrl(final String deliveryCallbackUrl){ + + public ServiceUpdater setDeliveryCallbackUrl( + final String deliveryCallbackUrl + ) { this.deliveryCallbackUrl = deliveryCallbackUrl; return this; } - public ServiceUpdater setDeliveryCallbackEnabled(final Boolean deliveryCallbackEnabled){ + + public ServiceUpdater setDeliveryCallbackEnabled( + final Boolean deliveryCallbackEnabled + ) { this.deliveryCallbackEnabled = deliveryCallbackEnabled; return this; } @Override - public Service update(final TwilioRestClient client){ + public Service update(final TwilioRestClient client) { String path = "/v1/Services/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.NOTIFY.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -130,62 +168,67 @@ public Service update(final TwilioRestClient client){ return Service.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (apnCredentialSid != null) { request.addPostParam("ApnCredentialSid", apnCredentialSid); - } if (gcmCredentialSid != null) { request.addPostParam("GcmCredentialSid", gcmCredentialSid); - } if (messagingServiceSid != null) { request.addPostParam("MessagingServiceSid", messagingServiceSid); - } if (facebookMessengerPageId != null) { - request.addPostParam("FacebookMessengerPageId", facebookMessengerPageId); - + request.addPostParam( + "FacebookMessengerPageId", + facebookMessengerPageId + ); } if (defaultApnNotificationProtocolVersion != null) { - request.addPostParam("DefaultApnNotificationProtocolVersion", defaultApnNotificationProtocolVersion); - + request.addPostParam( + "DefaultApnNotificationProtocolVersion", + defaultApnNotificationProtocolVersion + ); } if (defaultGcmNotificationProtocolVersion != null) { - request.addPostParam("DefaultGcmNotificationProtocolVersion", defaultGcmNotificationProtocolVersion); - + request.addPostParam( + "DefaultGcmNotificationProtocolVersion", + defaultGcmNotificationProtocolVersion + ); } if (fcmCredentialSid != null) { request.addPostParam("FcmCredentialSid", fcmCredentialSid); - } if (defaultFcmNotificationProtocolVersion != null) { - request.addPostParam("DefaultFcmNotificationProtocolVersion", defaultFcmNotificationProtocolVersion); - + request.addPostParam( + "DefaultFcmNotificationProtocolVersion", + defaultFcmNotificationProtocolVersion + ); } if (logEnabled != null) { request.addPostParam("LogEnabled", logEnabled.toString()); - } if (alexaSkillId != null) { request.addPostParam("AlexaSkillId", alexaSkillId); - } if (defaultAlexaNotificationProtocolVersion != null) { - request.addPostParam("DefaultAlexaNotificationProtocolVersion", defaultAlexaNotificationProtocolVersion); - + request.addPostParam( + "DefaultAlexaNotificationProtocolVersion", + defaultAlexaNotificationProtocolVersion + ); } if (deliveryCallbackUrl != null) { request.addPostParam("DeliveryCallbackUrl", deliveryCallbackUrl); - } if (deliveryCallbackEnabled != null) { - request.addPostParam("DeliveryCallbackEnabled", deliveryCallbackEnabled.toString()); - + request.addPostParam( + "DeliveryCallbackEnabled", + deliveryCallbackEnabled.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/notify/v1/service/Binding.java b/src/main/java/com/twilio/rest/notify/v1/service/Binding.java index 50a48bb73e..f23c9bd758 100644 --- a/src/main/java/com/twilio/rest/notify/v1/service/Binding.java +++ b/src/main/java/com/twilio/rest/notify/v1/service/Binding.java @@ -24,52 +24,67 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.List; import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Binding extends Resource { + private static final long serialVersionUID = 204710880064403L; - public static BindingCreator creator(final String pathServiceSid, final String identity, final Binding.BindingType bindingType, final String address){ - return new BindingCreator(pathServiceSid, identity, bindingType, address); + public static BindingCreator creator( + final String pathServiceSid, + final String identity, + final Binding.BindingType bindingType, + final String address + ) { + return new BindingCreator( + pathServiceSid, + identity, + bindingType, + address + ); } - public static BindingDeleter deleter(final String pathServiceSid, final String pathSid){ + public static BindingDeleter deleter( + final String pathServiceSid, + final String pathSid + ) { return new BindingDeleter(pathServiceSid, pathSid); } - public static BindingFetcher fetcher(final String pathServiceSid, final String pathSid){ + public static BindingFetcher fetcher( + final String pathServiceSid, + final String pathSid + ) { return new BindingFetcher(pathServiceSid, pathSid); } - public static BindingReader reader(final String pathServiceSid){ + public static BindingReader reader(final String pathServiceSid) { return new BindingReader(pathServiceSid); } /** - * Converts a JSON String into a Binding object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Binding object represented by the provided JSON - */ - public static Binding fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Binding object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Binding object represented by the provided JSON + */ + public static Binding fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Binding.class); @@ -81,14 +96,17 @@ public static Binding fromJson(final String json, final ObjectMapper objectMappe } /** - * Converts a JSON InputStream into a Binding object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Binding object represented by the provided JSON - */ - public static Binding fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Binding object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Binding object represented by the provided JSON + */ + public static Binding fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Binding.class); @@ -98,6 +116,7 @@ public static Binding fromJson(final InputStream json, final ObjectMapper object throw new ApiConnectionException(e.getMessage(), e); } } + public enum BindingType { APN("apn"), GCM("gcm"), @@ -139,47 +158,22 @@ public static BindingType forValue(final String value) { @JsonCreator private Binding( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("credential_sid") - final String credentialSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("notification_protocol_version") - final String notificationProtocolVersion, - - @JsonProperty("endpoint") - final String endpoint, - - @JsonProperty("identity") - final String identity, - - @JsonProperty("binding_type") - final String bindingType, - - @JsonProperty("address") - final String address, - - @JsonProperty("tags") - final List tags, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("credential_sid") final String credentialSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty( + "notification_protocol_version" + ) final String notificationProtocolVersion, + @JsonProperty("endpoint") final String endpoint, + @JsonProperty("identity") final String identity, + @JsonProperty("binding_type") final String bindingType, + @JsonProperty("address") final String address, + @JsonProperty("tags") final List tags, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.sid = sid; this.accountSid = accountSid; @@ -197,52 +191,65 @@ private Binding( this.links = links; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final String getCredentialSid() { - return this.credentialSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getNotificationProtocolVersion() { - return this.notificationProtocolVersion; - } - public final String getEndpoint() { - return this.endpoint; - } - public final String getIdentity() { - return this.identity; - } - public final String getBindingType() { - return this.bindingType; - } - public final String getAddress() { - return this.address; - } - public final List getTags() { - return this.tags; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final String getCredentialSid() { + return this.credentialSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getNotificationProtocolVersion() { + return this.notificationProtocolVersion; + } + + public final String getEndpoint() { + return this.endpoint; + } + + public final String getIdentity() { + return this.identity; + } + + public final String getBindingType() { + return this.bindingType; + } + + public final String getAddress() { + return this.address; + } + + public final List getTags() { + return this.tags; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -252,13 +259,44 @@ public boolean equals(final Object o) { Binding other = (Binding) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(credentialSid, other.credentialSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(notificationProtocolVersion, other.notificationProtocolVersion) && Objects.equals(endpoint, other.endpoint) && Objects.equals(identity, other.identity) && Objects.equals(bindingType, other.bindingType) && Objects.equals(address, other.address) && Objects.equals(tags, other.tags) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(credentialSid, other.credentialSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals( + notificationProtocolVersion, + other.notificationProtocolVersion + ) && + Objects.equals(endpoint, other.endpoint) && + Objects.equals(identity, other.identity) && + Objects.equals(bindingType, other.bindingType) && + Objects.equals(address, other.address) && + Objects.equals(tags, other.tags) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, serviceSid, credentialSid, dateCreated, dateUpdated, notificationProtocolVersion, endpoint, identity, bindingType, address, tags, url, links); + return Objects.hash( + sid, + accountSid, + serviceSid, + credentialSid, + dateCreated, + dateUpdated, + notificationProtocolVersion, + endpoint, + identity, + bindingType, + address, + tags, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/notify/v1/service/BindingCreator.java b/src/main/java/com/twilio/rest/notify/v1/service/BindingCreator.java index c93c52b632..dde0128bf9 100644 --- a/src/main/java/com/twilio/rest/notify/v1/service/BindingCreator.java +++ b/src/main/java/com/twilio/rest/notify/v1/service/BindingCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.notify.v1.service; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -25,12 +26,10 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.util.List; - import java.util.List; +public class BindingCreator extends Creator { - -public class BindingCreator extends Creator{ private String pathServiceSid; private String identity; private Binding.BindingType bindingType; @@ -40,65 +39,95 @@ public class BindingCreator extends Creator{ private String credentialSid; private String endpoint; - public BindingCreator(final String pathServiceSid, final String identity, final Binding.BindingType bindingType, final String address) { + public BindingCreator( + final String pathServiceSid, + final String identity, + final Binding.BindingType bindingType, + final String address + ) { this.pathServiceSid = pathServiceSid; this.identity = identity; this.bindingType = bindingType; this.address = address; } - public BindingCreator setIdentity(final String identity){ + public BindingCreator setIdentity(final String identity) { this.identity = identity; return this; } - public BindingCreator setBindingType(final Binding.BindingType bindingType){ + + public BindingCreator setBindingType( + final Binding.BindingType bindingType + ) { this.bindingType = bindingType; return this; } - public BindingCreator setAddress(final String address){ + + public BindingCreator setAddress(final String address) { this.address = address; return this; } - public BindingCreator setTag(final List tag){ + + public BindingCreator setTag(final List tag) { this.tag = tag; return this; } - public BindingCreator setTag(final String tag){ + + public BindingCreator setTag(final String tag) { return setTag(Promoter.listOfOne(tag)); } - public BindingCreator setNotificationProtocolVersion(final String notificationProtocolVersion){ + + public BindingCreator setNotificationProtocolVersion( + final String notificationProtocolVersion + ) { this.notificationProtocolVersion = notificationProtocolVersion; return this; } - public BindingCreator setCredentialSid(final String credentialSid){ + + public BindingCreator setCredentialSid(final String credentialSid) { this.credentialSid = credentialSid; return this; } - public BindingCreator setEndpoint(final String endpoint){ + + public BindingCreator setEndpoint(final String endpoint) { this.endpoint = endpoint; return this; } @Override - public Binding create(final TwilioRestClient client){ + public Binding create(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Bindings"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Identity"+"}", this.identity.toString()); - path = path.replace("{"+"BindingType"+"}", this.bindingType.toString()); - path = path.replace("{"+"Address"+"}", this.address.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Identity" + "}", this.identity.toString()); + path = + path.replace( + "{" + "BindingType" + "}", + this.bindingType.toString() + ); + path = path.replace("{" + "Address" + "}", this.address.toString()); Request request = new Request( HttpMethod.POST, Domains.NOTIFY.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Binding creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Binding creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -107,36 +136,33 @@ public Binding create(final TwilioRestClient client){ return Binding.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (identity != null) { request.addPostParam("Identity", identity); - } if (bindingType != null) { request.addPostParam("BindingType", bindingType.toString()); - } if (address != null) { request.addPostParam("Address", address); - } if (tag != null) { for (String prop : tag) { request.addPostParam("Tag", prop); } - } if (notificationProtocolVersion != null) { - request.addPostParam("NotificationProtocolVersion", notificationProtocolVersion); - + request.addPostParam( + "NotificationProtocolVersion", + notificationProtocolVersion + ); } if (credentialSid != null) { request.addPostParam("CredentialSid", credentialSid); - } if (endpoint != null) { request.addPostParam("Endpoint", endpoint); - } } } diff --git a/src/main/java/com/twilio/rest/notify/v1/service/BindingDeleter.java b/src/main/java/com/twilio/rest/notify/v1/service/BindingDeleter.java index 3d4d9515df..a9b9dae785 100644 --- a/src/main/java/com/twilio/rest/notify/v1/service/BindingDeleter.java +++ b/src/main/java/com/twilio/rest/notify/v1/service/BindingDeleter.java @@ -24,24 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class BindingDeleter extends Deleter { + private String pathServiceSid; private String pathSid; - public BindingDeleter(final String pathServiceSid, final String pathSid){ + public BindingDeleter(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Bindings/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +53,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Binding delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Binding delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/notify/v1/service/BindingFetcher.java b/src/main/java/com/twilio/rest/notify/v1/service/BindingFetcher.java index d9d355944c..d3b11a0a44 100644 --- a/src/main/java/com/twilio/rest/notify/v1/service/BindingFetcher.java +++ b/src/main/java/com/twilio/rest/notify/v1/service/BindingFetcher.java @@ -24,25 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class BindingFetcher extends Fetcher { + private String pathServiceSid; private String pathSid; - public BindingFetcher(final String pathServiceSid, final String pathSid){ + public BindingFetcher(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - @Override public Binding fetch(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Bindings/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,9 +53,14 @@ public Binding fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Binding fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Binding fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/notify/v1/service/BindingReader.java b/src/main/java/com/twilio/rest/notify/v1/service/BindingReader.java index 7985f45a84..fcaffedbf4 100644 --- a/src/main/java/com/twilio/rest/notify/v1/service/BindingReader.java +++ b/src/main/java/com/twilio/rest/notify/v1/service/BindingReader.java @@ -14,8 +14,10 @@ package com.twilio.rest.notify.v1.service; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -25,14 +27,11 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; import java.time.LocalDate; -import com.twilio.converter.DateConverter; - import java.util.List; - public class BindingReader extends Reader { + private String pathServiceSid; private LocalDate startDate; private LocalDate endDate; @@ -40,33 +39,39 @@ public class BindingReader extends Reader { private List tag; private Integer pageSize; - public BindingReader(final String pathServiceSid){ + public BindingReader(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - public BindingReader setStartDate(final LocalDate startDate){ + public BindingReader setStartDate(final LocalDate startDate) { this.startDate = startDate; return this; } - public BindingReader setEndDate(final LocalDate endDate){ + + public BindingReader setEndDate(final LocalDate endDate) { this.endDate = endDate; return this; } - public BindingReader setIdentity(final List identity){ + + public BindingReader setIdentity(final List identity) { this.identity = identity; return this; } - public BindingReader setIdentity(final String identity){ + + public BindingReader setIdentity(final String identity) { return setIdentity(Promoter.listOfOne(identity)); } - public BindingReader setTag(final List tag){ + + public BindingReader setTag(final List tag) { this.tag = tag; return this; } - public BindingReader setTag(final String tag){ + + public BindingReader setTag(final String tag) { return setTag(Promoter.listOfOne(tag)); } - public BindingReader setPageSize(final Integer pageSize){ + + public BindingReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -78,7 +83,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Bindings"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -90,13 +99,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Binding read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Binding read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -112,7 +129,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reques } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.NOTIFY.toString()) @@ -120,9 +140,11 @@ public Page previousPage(final Page page, final TwilioRestClie return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.NOTIFY.toString()) @@ -131,21 +153,28 @@ public Page nextPage(final Page page, final TwilioRestClient c } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (startDate != null) { - request.addQueryParam("StartDate", DateConverter.dateStringFromLocalDate(startDate)); + request.addQueryParam( + "StartDate", + DateConverter.dateStringFromLocalDate(startDate) + ); } if (endDate != null) { - request.addQueryParam("EndDate", DateConverter.dateStringFromLocalDate(endDate)); + request.addQueryParam( + "EndDate", + DateConverter.dateStringFromLocalDate(endDate) + ); } if (identity != null) { @@ -159,11 +188,10 @@ private void addQueryParams(final Request request) { } } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/notify/v1/service/Notification.java b/src/main/java/com/twilio/rest/notify/v1/service/Notification.java index 24c969b3d0..619a0abdab 100644 --- a/src/main/java/com/twilio/rest/notify/v1/service/Notification.java +++ b/src/main/java/com/twilio/rest/notify/v1/service/Notification.java @@ -24,39 +24,38 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.time.ZonedDateTime; - import java.util.List; import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Notification extends Resource { + private static final long serialVersionUID = 129411229878484L; - public static NotificationCreator creator(final String pathServiceSid){ + public static NotificationCreator creator(final String pathServiceSid) { return new NotificationCreator(pathServiceSid); } /** - * Converts a JSON String into a Notification object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Notification object represented by the provided JSON - */ - public static Notification fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Notification object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Notification object represented by the provided JSON + */ + public static Notification fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Notification.class); @@ -68,14 +67,17 @@ public static Notification fromJson(final String json, final ObjectMapper object } /** - * Converts a JSON InputStream into a Notification object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Notification object represented by the provided JSON - */ - public static Notification fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Notification object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Notification object represented by the provided JSON + */ + public static Notification fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Notification.class); @@ -85,6 +87,7 @@ public static Notification fromJson(final InputStream json, final ObjectMapper o throw new ApiConnectionException(e.getMessage(), e); } } + public enum Priority { HIGH("high"), LOW("low"); @@ -128,65 +131,28 @@ public static Priority forValue(final String value) { @JsonCreator private Notification( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("identities") - final List identities, - - @JsonProperty("tags") - final List tags, - - @JsonProperty("segments") - final List segments, - - @JsonProperty("priority") - final Notification.Priority priority, - - @JsonProperty("ttl") - final Integer ttl, - - @JsonProperty("title") - final String title, - - @JsonProperty("body") - final String body, - - @JsonProperty("sound") - final String sound, - - @JsonProperty("action") - final String action, - - @JsonProperty("data") - final Map data, - - @JsonProperty("apn") - final Map apn, - - @JsonProperty("gcm") - final Map gcm, - - @JsonProperty("fcm") - final Map fcm, - - @JsonProperty("sms") - final Map sms, - - @JsonProperty("facebook_messenger") - final Map facebookMessenger, - - @JsonProperty("alexa") - final Map alexa + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("identities") final List identities, + @JsonProperty("tags") final List tags, + @JsonProperty("segments") final List segments, + @JsonProperty("priority") final Notification.Priority priority, + @JsonProperty("ttl") final Integer ttl, + @JsonProperty("title") final String title, + @JsonProperty("body") final String body, + @JsonProperty("sound") final String sound, + @JsonProperty("action") final String action, + @JsonProperty("data") final Map data, + @JsonProperty("apn") final Map apn, + @JsonProperty("gcm") final Map gcm, + @JsonProperty("fcm") final Map fcm, + @JsonProperty("sms") final Map sms, + @JsonProperty( + "facebook_messenger" + ) final Map facebookMessenger, + @JsonProperty("alexa") final Map alexa ) { this.sid = sid; this.accountSid = accountSid; @@ -210,70 +176,89 @@ private Notification( this.alexa = alexa; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final List getIdentities() { - return this.identities; - } - public final List getTags() { - return this.tags; - } - public final List getSegments() { - return this.segments; - } - public final Notification.Priority getPriority() { - return this.priority; - } - public final Integer getTtl() { - return this.ttl; - } - public final String getTitle() { - return this.title; - } - public final String getBody() { - return this.body; - } - public final String getSound() { - return this.sound; - } - public final String getAction() { - return this.action; - } - public final Map getData() { - return this.data; - } - public final Map getApn() { - return this.apn; - } - public final Map getGcm() { - return this.gcm; - } - public final Map getFcm() { - return this.fcm; - } - public final Map getSms() { - return this.sms; - } - public final Map getFacebookMessenger() { - return this.facebookMessenger; - } - public final Map getAlexa() { - return this.alexa; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final List getIdentities() { + return this.identities; + } + + public final List getTags() { + return this.tags; + } + + public final List getSegments() { + return this.segments; + } + + public final Notification.Priority getPriority() { + return this.priority; + } + + public final Integer getTtl() { + return this.ttl; + } + + public final String getTitle() { + return this.title; + } + + public final String getBody() { + return this.body; + } + + public final String getSound() { + return this.sound; + } + + public final String getAction() { + return this.action; + } + + public final Map getData() { + return this.data; + } + + public final Map getApn() { + return this.apn; + } + + public final Map getGcm() { + return this.gcm; + } + + public final Map getFcm() { + return this.fcm; + } + + public final Map getSms() { + return this.sms; + } + + public final Map getFacebookMessenger() { + return this.facebookMessenger; + } + + public final Map getAlexa() { + return this.alexa; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -283,13 +268,53 @@ public boolean equals(final Object o) { Notification other = (Notification) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(identities, other.identities) && Objects.equals(tags, other.tags) && Objects.equals(segments, other.segments) && Objects.equals(priority, other.priority) && Objects.equals(ttl, other.ttl) && Objects.equals(title, other.title) && Objects.equals(body, other.body) && Objects.equals(sound, other.sound) && Objects.equals(action, other.action) && Objects.equals(data, other.data) && Objects.equals(apn, other.apn) && Objects.equals(gcm, other.gcm) && Objects.equals(fcm, other.fcm) && Objects.equals(sms, other.sms) && Objects.equals(facebookMessenger, other.facebookMessenger) && Objects.equals(alexa, other.alexa) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(identities, other.identities) && + Objects.equals(tags, other.tags) && + Objects.equals(segments, other.segments) && + Objects.equals(priority, other.priority) && + Objects.equals(ttl, other.ttl) && + Objects.equals(title, other.title) && + Objects.equals(body, other.body) && + Objects.equals(sound, other.sound) && + Objects.equals(action, other.action) && + Objects.equals(data, other.data) && + Objects.equals(apn, other.apn) && + Objects.equals(gcm, other.gcm) && + Objects.equals(fcm, other.fcm) && + Objects.equals(sms, other.sms) && + Objects.equals(facebookMessenger, other.facebookMessenger) && + Objects.equals(alexa, other.alexa) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, serviceSid, dateCreated, identities, tags, segments, priority, ttl, title, body, sound, action, data, apn, gcm, fcm, sms, facebookMessenger, alexa); + return Objects.hash( + sid, + accountSid, + serviceSid, + dateCreated, + identities, + tags, + segments, + priority, + ttl, + title, + body, + sound, + action, + data, + apn, + gcm, + fcm, + sms, + facebookMessenger, + alexa + ); } - } - diff --git a/src/main/java/com/twilio/rest/notify/v1/service/NotificationCreator.java b/src/main/java/com/twilio/rest/notify/v1/service/NotificationCreator.java index 90c5357b1a..5cd4fd6766 100644 --- a/src/main/java/com/twilio/rest/notify/v1/service/NotificationCreator.java +++ b/src/main/java/com/twilio/rest/notify/v1/service/NotificationCreator.java @@ -15,9 +15,11 @@ package com.twilio.rest.notify.v1.service; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; +import com.twilio.converter.Converter; +import com.twilio.converter.Converter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; -import com.twilio.converter.Converter; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; @@ -26,15 +28,12 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.util.List; -import java.util.Map; -import com.twilio.converter.Converter; - import java.util.List; import java.util.Map; +import java.util.Map; +public class NotificationCreator extends Creator { - -public class NotificationCreator extends Creator{ private String pathServiceSid; private String body; private Notification.Priority priority; @@ -59,196 +58,222 @@ public NotificationCreator(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - public NotificationCreator setBody(final String body){ + public NotificationCreator setBody(final String body) { this.body = body; return this; } - public NotificationCreator setPriority(final Notification.Priority priority){ + + public NotificationCreator setPriority( + final Notification.Priority priority + ) { this.priority = priority; return this; } - public NotificationCreator setTtl(final Integer ttl){ + + public NotificationCreator setTtl(final Integer ttl) { this.ttl = ttl; return this; } - public NotificationCreator setTitle(final String title){ + + public NotificationCreator setTitle(final String title) { this.title = title; return this; } - public NotificationCreator setSound(final String sound){ + + public NotificationCreator setSound(final String sound) { this.sound = sound; return this; } - public NotificationCreator setAction(final String action){ + + public NotificationCreator setAction(final String action) { this.action = action; return this; } - public NotificationCreator setData(final Map data){ + + public NotificationCreator setData(final Map data) { this.data = data; return this; } - public NotificationCreator setApn(final Map apn){ + + public NotificationCreator setApn(final Map apn) { this.apn = apn; return this; } - public NotificationCreator setGcm(final Map gcm){ + + public NotificationCreator setGcm(final Map gcm) { this.gcm = gcm; return this; } - public NotificationCreator setSms(final Map sms){ + + public NotificationCreator setSms(final Map sms) { this.sms = sms; return this; } - public NotificationCreator setFacebookMessenger(final Map facebookMessenger){ + + public NotificationCreator setFacebookMessenger( + final Map facebookMessenger + ) { this.facebookMessenger = facebookMessenger; return this; } - public NotificationCreator setFcm(final Map fcm){ + + public NotificationCreator setFcm(final Map fcm) { this.fcm = fcm; return this; } - public NotificationCreator setSegment(final List segment){ + + public NotificationCreator setSegment(final List segment) { this.segment = segment; return this; } - public NotificationCreator setSegment(final String segment){ + + public NotificationCreator setSegment(final String segment) { return setSegment(Promoter.listOfOne(segment)); } - public NotificationCreator setAlexa(final Map alexa){ + + public NotificationCreator setAlexa(final Map alexa) { this.alexa = alexa; return this; } - public NotificationCreator setToBinding(final List toBinding){ + + public NotificationCreator setToBinding(final List toBinding) { this.toBinding = toBinding; return this; } - public NotificationCreator setToBinding(final String toBinding){ + + public NotificationCreator setToBinding(final String toBinding) { return setToBinding(Promoter.listOfOne(toBinding)); } - public NotificationCreator setDeliveryCallbackUrl(final String deliveryCallbackUrl){ + + public NotificationCreator setDeliveryCallbackUrl( + final String deliveryCallbackUrl + ) { this.deliveryCallbackUrl = deliveryCallbackUrl; return this; } - public NotificationCreator setIdentity(final List identity){ + + public NotificationCreator setIdentity(final List identity) { this.identity = identity; return this; } - public NotificationCreator setIdentity(final String identity){ + + public NotificationCreator setIdentity(final String identity) { return setIdentity(Promoter.listOfOne(identity)); } - public NotificationCreator setTag(final List tag){ + + public NotificationCreator setTag(final List tag) { this.tag = tag; return this; } - public NotificationCreator setTag(final String tag){ + + public NotificationCreator setTag(final String tag) { return setTag(Promoter.listOfOne(tag)); } @Override - public Notification create(final TwilioRestClient client){ + public Notification create(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Notifications"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.NOTIFY.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Notification creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Notification creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Notification.fromJson(response.getStream(), client.getObjectMapper()); + return Notification.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (body != null) { request.addPostParam("Body", body); - } if (priority != null) { request.addPostParam("Priority", priority.toString()); - } if (ttl != null) { request.addPostParam("Ttl", ttl.toString()); - } if (title != null) { request.addPostParam("Title", title); - } if (sound != null) { request.addPostParam("Sound", sound); - } if (action != null) { request.addPostParam("Action", action); - } if (data != null) { - request.addPostParam("Data", Converter.mapToJson(data)); - + request.addPostParam("Data", Converter.mapToJson(data)); } if (apn != null) { - request.addPostParam("Apn", Converter.mapToJson(apn)); - + request.addPostParam("Apn", Converter.mapToJson(apn)); } if (gcm != null) { - request.addPostParam("Gcm", Converter.mapToJson(gcm)); - + request.addPostParam("Gcm", Converter.mapToJson(gcm)); } if (sms != null) { - request.addPostParam("Sms", Converter.mapToJson(sms)); - + request.addPostParam("Sms", Converter.mapToJson(sms)); } if (facebookMessenger != null) { - request.addPostParam("FacebookMessenger", Converter.mapToJson(facebookMessenger)); - + request.addPostParam( + "FacebookMessenger", + Converter.mapToJson(facebookMessenger) + ); } if (fcm != null) { - request.addPostParam("Fcm", Converter.mapToJson(fcm)); - + request.addPostParam("Fcm", Converter.mapToJson(fcm)); } if (segment != null) { for (String prop : segment) { request.addPostParam("Segment", prop); } - } if (alexa != null) { - request.addPostParam("Alexa", Converter.mapToJson(alexa)); - + request.addPostParam("Alexa", Converter.mapToJson(alexa)); } if (toBinding != null) { for (String prop : toBinding) { request.addPostParam("ToBinding", prop); } - } if (deliveryCallbackUrl != null) { request.addPostParam("DeliveryCallbackUrl", deliveryCallbackUrl); - } if (identity != null) { for (String prop : identity) { request.addPostParam("Identity", prop); } - } if (tag != null) { for (String prop : tag) { request.addPostParam("Tag", prop); } - } } } diff --git a/src/main/java/com/twilio/rest/numbers/v1/BulkEligibility.java b/src/main/java/com/twilio/rest/numbers/v1/BulkEligibility.java index e317c8a813..453673b6ac 100644 --- a/src/main/java/com/twilio/rest/numbers/v1/BulkEligibility.java +++ b/src/main/java/com/twilio/rest/numbers/v1/BulkEligibility.java @@ -23,40 +23,39 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.List; import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class BulkEligibility extends Resource { + private static final long serialVersionUID = 38354491175250L; - public static BulkEligibilityFetcher fetcher(final String pathRequestId){ + public static BulkEligibilityFetcher fetcher(final String pathRequestId) { return new BulkEligibilityFetcher(pathRequestId); } /** - * Converts a JSON String into a BulkEligibility object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return BulkEligibility object represented by the provided JSON - */ - public static BulkEligibility fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a BulkEligibility object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return BulkEligibility object represented by the provided JSON + */ + public static BulkEligibility fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, BulkEligibility.class); @@ -68,14 +67,17 @@ public static BulkEligibility fromJson(final String json, final ObjectMapper obj } /** - * Converts a JSON InputStream into a BulkEligibility object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return BulkEligibility object represented by the provided JSON - */ - public static BulkEligibility fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a BulkEligibility object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return BulkEligibility object represented by the provided JSON + */ + public static BulkEligibility fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, BulkEligibility.class); @@ -96,26 +98,13 @@ public static BulkEligibility fromJson(final InputStream json, final ObjectMappe @JsonCreator private BulkEligibility( - @JsonProperty("request_id") - final String requestId, - - @JsonProperty("url") - final URI url, - - @JsonProperty("results") - final List> results, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("status") - final String status, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_completed") - final String dateCompleted + @JsonProperty("request_id") final String requestId, + @JsonProperty("url") final URI url, + @JsonProperty("results") final List> results, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("status") final String status, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_completed") final String dateCompleted ) { this.requestId = requestId; this.url = url; @@ -123,34 +112,41 @@ private BulkEligibility( this.friendlyName = friendlyName; this.status = status; this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateCompleted = DateConverter.iso8601DateTimeFromString(dateCompleted); + this.dateCompleted = + DateConverter.iso8601DateTimeFromString(dateCompleted); } - public final String getRequestId() { - return this.requestId; - } - public final URI getUrl() { - return this.url; - } - public final List> getResults() { - return this.results; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getStatus() { - return this.status; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateCompleted() { - return this.dateCompleted; - } + public final String getRequestId() { + return this.requestId; + } + + public final URI getUrl() { + return this.url; + } + + public final List> getResults() { + return this.results; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getStatus() { + return this.status; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateCompleted() { + return this.dateCompleted; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -160,13 +156,27 @@ public boolean equals(final Object o) { BulkEligibility other = (BulkEligibility) o; - return Objects.equals(requestId, other.requestId) && Objects.equals(url, other.url) && Objects.equals(results, other.results) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(status, other.status) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateCompleted, other.dateCompleted) ; + return ( + Objects.equals(requestId, other.requestId) && + Objects.equals(url, other.url) && + Objects.equals(results, other.results) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(status, other.status) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateCompleted, other.dateCompleted) + ); } @Override public int hashCode() { - return Objects.hash(requestId, url, results, friendlyName, status, dateCreated, dateCompleted); + return Objects.hash( + requestId, + url, + results, + friendlyName, + status, + dateCreated, + dateCompleted + ); } - } - diff --git a/src/main/java/com/twilio/rest/numbers/v1/BulkEligibilityFetcher.java b/src/main/java/com/twilio/rest/numbers/v1/BulkEligibilityFetcher.java index d7120ea988..7efc47ee00 100644 --- a/src/main/java/com/twilio/rest/numbers/v1/BulkEligibilityFetcher.java +++ b/src/main/java/com/twilio/rest/numbers/v1/BulkEligibilityFetcher.java @@ -24,22 +24,23 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class BulkEligibilityFetcher extends Fetcher { + private String pathRequestId; - public BulkEligibilityFetcher(final String pathRequestId){ + public BulkEligibilityFetcher(final String pathRequestId) { this.pathRequestId = pathRequestId; } - @Override public BulkEligibility fetch(final TwilioRestClient client) { String path = "/v1/HostedNumber/Eligibility/Bulk/{RequestId}"; - path = path.replace("{"+"RequestId"+"}", this.pathRequestId.toString()); + path = + path.replace( + "{" + "RequestId" + "}", + this.pathRequestId.toString() + ); Request request = new Request( HttpMethod.GET, @@ -49,15 +50,23 @@ public BulkEligibility fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("BulkEligibility fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "BulkEligibility fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return BulkEligibility.fromJson(response.getStream(), client.getObjectMapper()); + return BulkEligibility.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/numbers/v1/PortingBulkPortability.java b/src/main/java/com/twilio/rest/numbers/v1/PortingBulkPortability.java index 178514ec03..5c412c564b 100644 --- a/src/main/java/com/twilio/rest/numbers/v1/PortingBulkPortability.java +++ b/src/main/java/com/twilio/rest/numbers/v1/PortingBulkPortability.java @@ -24,44 +24,45 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.List; import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class PortingBulkPortability extends Resource { + private static final long serialVersionUID = 54521824330020L; - public static PortingBulkPortabilityCreator creator(final List phoneNumbers){ + public static PortingBulkPortabilityCreator creator( + final List phoneNumbers + ) { return new PortingBulkPortabilityCreator(phoneNumbers); } - public static PortingBulkPortabilityFetcher fetcher(final String pathSid){ + public static PortingBulkPortabilityFetcher fetcher(final String pathSid) { return new PortingBulkPortabilityFetcher(pathSid); } /** - * Converts a JSON String into a PortingBulkPortability object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return PortingBulkPortability object represented by the provided JSON - */ - public static PortingBulkPortability fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a PortingBulkPortability object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return PortingBulkPortability object represented by the provided JSON + */ + public static PortingBulkPortability fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, PortingBulkPortability.class); @@ -73,14 +74,17 @@ public static PortingBulkPortability fromJson(final String json, final ObjectMap } /** - * Converts a JSON InputStream into a PortingBulkPortability object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return PortingBulkPortability object represented by the provided JSON - */ - public static PortingBulkPortability fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a PortingBulkPortability object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return PortingBulkPortability object represented by the provided JSON + */ + public static PortingBulkPortability fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, PortingBulkPortability.class); @@ -90,6 +94,7 @@ public static PortingBulkPortability fromJson(final InputStream json, final Obje throw new ApiConnectionException(e.getMessage(), e); } } + public enum Status { IN_PROGRESS("in-progress"), COMPLETED("completed"), @@ -119,47 +124,45 @@ public static Status forValue(final String value) { @JsonCreator private PortingBulkPortability( - @JsonProperty("sid") - final String sid, - - @JsonProperty("status") - final PortingBulkPortability.Status status, - - @JsonProperty("datetime_created") - final String datetimeCreated, - - @JsonProperty("phone_numbers") - final List> phoneNumbers, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("status") final PortingBulkPortability.Status status, + @JsonProperty("datetime_created") final String datetimeCreated, + @JsonProperty( + "phone_numbers" + ) final List> phoneNumbers, + @JsonProperty("url") final URI url ) { this.sid = sid; this.status = status; - this.datetimeCreated = DateConverter.iso8601DateTimeFromString(datetimeCreated); + this.datetimeCreated = + DateConverter.iso8601DateTimeFromString(datetimeCreated); this.phoneNumbers = phoneNumbers; this.url = url; } - public final String getSid() { - return this.sid; - } - public final PortingBulkPortability.Status getStatus() { - return this.status; - } - public final ZonedDateTime getDatetimeCreated() { - return this.datetimeCreated; - } - public final List> getPhoneNumbers() { - return this.phoneNumbers; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final PortingBulkPortability.Status getStatus() { + return this.status; + } + + public final ZonedDateTime getDatetimeCreated() { + return this.datetimeCreated; + } + + public final List> getPhoneNumbers() { + return this.phoneNumbers; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -169,13 +172,17 @@ public boolean equals(final Object o) { PortingBulkPortability other = (PortingBulkPortability) o; - return Objects.equals(sid, other.sid) && Objects.equals(status, other.status) && Objects.equals(datetimeCreated, other.datetimeCreated) && Objects.equals(phoneNumbers, other.phoneNumbers) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(status, other.status) && + Objects.equals(datetimeCreated, other.datetimeCreated) && + Objects.equals(phoneNumbers, other.phoneNumbers) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { return Objects.hash(sid, status, datetimeCreated, phoneNumbers, url); } - } - diff --git a/src/main/java/com/twilio/rest/numbers/v1/PortingBulkPortabilityCreator.java b/src/main/java/com/twilio/rest/numbers/v1/PortingBulkPortabilityCreator.java index 965607906b..74b1869218 100644 --- a/src/main/java/com/twilio/rest/numbers/v1/PortingBulkPortabilityCreator.java +++ b/src/main/java/com/twilio/rest/numbers/v1/PortingBulkPortabilityCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.numbers.v1; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -25,57 +26,74 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.util.List; - import java.util.List; +public class PortingBulkPortabilityCreator + extends Creator { - -public class PortingBulkPortabilityCreator extends Creator{ private List phoneNumbers; public PortingBulkPortabilityCreator(final List phoneNumbers) { this.phoneNumbers = phoneNumbers; } - public PortingBulkPortabilityCreator setPhoneNumbers(final List phoneNumbers){ + public PortingBulkPortabilityCreator setPhoneNumbers( + final List phoneNumbers + ) { this.phoneNumbers = phoneNumbers; return this; } - public PortingBulkPortabilityCreator setPhoneNumbers(final String phoneNumbers){ + + public PortingBulkPortabilityCreator setPhoneNumbers( + final String phoneNumbers + ) { return setPhoneNumbers(Promoter.listOfOne(phoneNumbers)); } @Override - public PortingBulkPortability create(final TwilioRestClient client){ + public PortingBulkPortability create(final TwilioRestClient client) { String path = "/v1/Porting/Portability"; - path = path.replace("{"+"PhoneNumbers"+"}", this.phoneNumbers.toString()); + path = + path.replace( + "{" + "PhoneNumbers" + "}", + this.phoneNumbers.toString() + ); Request request = new Request( HttpMethod.POST, Domains.NUMBERS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("PortingBulkPortability creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "PortingBulkPortability creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return PortingBulkPortability.fromJson(response.getStream(), client.getObjectMapper()); + return PortingBulkPortability.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (phoneNumbers != null) { for (String prop : phoneNumbers) { request.addPostParam("PhoneNumbers", prop); } - } } } diff --git a/src/main/java/com/twilio/rest/numbers/v1/PortingBulkPortabilityFetcher.java b/src/main/java/com/twilio/rest/numbers/v1/PortingBulkPortabilityFetcher.java index abb652927a..5ae7a25bd1 100644 --- a/src/main/java/com/twilio/rest/numbers/v1/PortingBulkPortabilityFetcher.java +++ b/src/main/java/com/twilio/rest/numbers/v1/PortingBulkPortabilityFetcher.java @@ -24,22 +24,20 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class PortingBulkPortabilityFetcher + extends Fetcher { - - -public class PortingBulkPortabilityFetcher extends Fetcher { private String pathSid; - public PortingBulkPortabilityFetcher(final String pathSid){ + public PortingBulkPortabilityFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public PortingBulkPortability fetch(final TwilioRestClient client) { String path = "/v1/Porting/Portability/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,15 +47,23 @@ public PortingBulkPortability fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("PortingBulkPortability fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "PortingBulkPortability fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return PortingBulkPortability.fromJson(response.getStream(), client.getObjectMapper()); + return PortingBulkPortability.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/numbers/v1/PortingPortability.java b/src/main/java/com/twilio/rest/numbers/v1/PortingPortability.java index dafdf192ca..7b00ccf408 100644 --- a/src/main/java/com/twilio/rest/numbers/v1/PortingPortability.java +++ b/src/main/java/com/twilio/rest/numbers/v1/PortingPortability.java @@ -23,36 +23,37 @@ import com.twilio.base.Resource; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class PortingPortability extends Resource { - private static final long serialVersionUID = 188812883844687L; - public static PortingPortabilityFetcher fetcher(final com.twilio.type.PhoneNumber pathPhoneNumber){ + private static final long serialVersionUID = 225988214270980L; + + public static PortingPortabilityFetcher fetcher( + final com.twilio.type.PhoneNumber pathPhoneNumber + ) { return new PortingPortabilityFetcher(pathPhoneNumber); } /** - * Converts a JSON String into a PortingPortability object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return PortingPortability object represented by the provided JSON - */ - public static PortingPortability fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a PortingPortability object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return PortingPortability object represented by the provided JSON + */ + public static PortingPortability fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, PortingPortability.class); @@ -64,14 +65,17 @@ public static PortingPortability fromJson(final String json, final ObjectMapper } /** - * Converts a JSON InputStream into a PortingPortability object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return PortingPortability object represented by the provided JSON - */ - public static PortingPortability fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a PortingPortability object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return PortingPortability object represented by the provided JSON + */ + public static PortingPortability fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, PortingPortability.class); @@ -81,6 +85,7 @@ public static PortingPortability fromJson(final InputStream json, final ObjectMa throw new ApiConnectionException(e.getMessage(), e); } } + public enum NumberType { LOCAL("LOCAL"), UNKNOWN("UNKNOWN"), @@ -104,6 +109,7 @@ public static NumberType forValue(final String value) { } private final com.twilio.type.PhoneNumber phoneNumber; + private final String accountSid; private final Boolean portable; private final Boolean pinAndAccountNumberRequired; private final String notPortableReason; @@ -116,37 +122,28 @@ public static NumberType forValue(final String value) { @JsonCreator private PortingPortability( - @JsonProperty("phone_number") - final com.twilio.type.PhoneNumber phoneNumber, - - @JsonProperty("portable") - final Boolean portable, - - @JsonProperty("pin_and_account_number_required") - final Boolean pinAndAccountNumberRequired, - - @JsonProperty("not_portable_reason") - final String notPortableReason, - - @JsonProperty("not_portable_reason_code") - final Integer notPortableReasonCode, - - @JsonProperty("number_type") - final PortingPortability.NumberType numberType, - - @JsonProperty("country") - final String country, - - @JsonProperty("messaging_carrier") - final String messagingCarrier, - - @JsonProperty("voice_carrier") - final String voiceCarrier, - - @JsonProperty("url") - final URI url + @JsonProperty( + "phone_number" + ) final com.twilio.type.PhoneNumber phoneNumber, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("portable") final Boolean portable, + @JsonProperty( + "pin_and_account_number_required" + ) final Boolean pinAndAccountNumberRequired, + @JsonProperty("not_portable_reason") final String notPortableReason, + @JsonProperty( + "not_portable_reason_code" + ) final Integer notPortableReasonCode, + @JsonProperty( + "number_type" + ) final PortingPortability.NumberType numberType, + @JsonProperty("country") final String country, + @JsonProperty("messaging_carrier") final String messagingCarrier, + @JsonProperty("voice_carrier") final String voiceCarrier, + @JsonProperty("url") final URI url ) { this.phoneNumber = phoneNumber; + this.accountSid = accountSid; this.portable = portable; this.pinAndAccountNumberRequired = pinAndAccountNumberRequired; this.notPortableReason = notPortableReason; @@ -158,40 +155,53 @@ private PortingPortability( this.url = url; } - public final com.twilio.type.PhoneNumber getPhoneNumber() { - return this.phoneNumber; - } - public final Boolean getPortable() { - return this.portable; - } - public final Boolean getPinAndAccountNumberRequired() { - return this.pinAndAccountNumberRequired; - } - public final String getNotPortableReason() { - return this.notPortableReason; - } - public final Integer getNotPortableReasonCode() { - return this.notPortableReasonCode; - } - public final PortingPortability.NumberType getNumberType() { - return this.numberType; - } - public final String getCountry() { - return this.country; - } - public final String getMessagingCarrier() { - return this.messagingCarrier; - } - public final String getVoiceCarrier() { - return this.voiceCarrier; - } - public final URI getUrl() { - return this.url; - } + public final com.twilio.type.PhoneNumber getPhoneNumber() { + return this.phoneNumber; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final Boolean getPortable() { + return this.portable; + } + + public final Boolean getPinAndAccountNumberRequired() { + return this.pinAndAccountNumberRequired; + } + + public final String getNotPortableReason() { + return this.notPortableReason; + } + + public final Integer getNotPortableReasonCode() { + return this.notPortableReasonCode; + } + + public final PortingPortability.NumberType getNumberType() { + return this.numberType; + } + + public final String getCountry() { + return this.country; + } + + public final String getMessagingCarrier() { + return this.messagingCarrier; + } + + public final String getVoiceCarrier() { + return this.voiceCarrier; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -201,13 +211,41 @@ public boolean equals(final Object o) { PortingPortability other = (PortingPortability) o; - return Objects.equals(phoneNumber, other.phoneNumber) && Objects.equals(portable, other.portable) && Objects.equals(pinAndAccountNumberRequired, other.pinAndAccountNumberRequired) && Objects.equals(notPortableReason, other.notPortableReason) && Objects.equals(notPortableReasonCode, other.notPortableReasonCode) && Objects.equals(numberType, other.numberType) && Objects.equals(country, other.country) && Objects.equals(messagingCarrier, other.messagingCarrier) && Objects.equals(voiceCarrier, other.voiceCarrier) && Objects.equals(url, other.url) ; + return ( + Objects.equals(phoneNumber, other.phoneNumber) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(portable, other.portable) && + Objects.equals( + pinAndAccountNumberRequired, + other.pinAndAccountNumberRequired + ) && + Objects.equals(notPortableReason, other.notPortableReason) && + Objects.equals( + notPortableReasonCode, + other.notPortableReasonCode + ) && + Objects.equals(numberType, other.numberType) && + Objects.equals(country, other.country) && + Objects.equals(messagingCarrier, other.messagingCarrier) && + Objects.equals(voiceCarrier, other.voiceCarrier) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(phoneNumber, portable, pinAndAccountNumberRequired, notPortableReason, notPortableReasonCode, numberType, country, messagingCarrier, voiceCarrier, url); + return Objects.hash( + phoneNumber, + accountSid, + portable, + pinAndAccountNumberRequired, + notPortableReason, + notPortableReasonCode, + numberType, + country, + messagingCarrier, + voiceCarrier, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/numbers/v1/PortingPortabilityFetcher.java b/src/main/java/com/twilio/rest/numbers/v1/PortingPortabilityFetcher.java index 1043070369..63537e21f1 100644 --- a/src/main/java/com/twilio/rest/numbers/v1/PortingPortabilityFetcher.java +++ b/src/main/java/com/twilio/rest/numbers/v1/PortingPortabilityFetcher.java @@ -24,40 +24,66 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class PortingPortabilityFetcher extends Fetcher { + private com.twilio.type.PhoneNumber pathPhoneNumber; + private String targetAccountSid; - public PortingPortabilityFetcher(final com.twilio.type.PhoneNumber pathPhoneNumber){ + public PortingPortabilityFetcher( + final com.twilio.type.PhoneNumber pathPhoneNumber + ) { this.pathPhoneNumber = pathPhoneNumber; } + public PortingPortabilityFetcher setTargetAccountSid( + final String targetAccountSid + ) { + this.targetAccountSid = targetAccountSid; + return this; + } @Override public PortingPortability fetch(final TwilioRestClient client) { String path = "/v1/Porting/Portability/PhoneNumber/{PhoneNumber}"; - path = path.replace("{"+"PhoneNumber"+"}", this.pathPhoneNumber.encode("utf-8")); + path = + path.replace( + "{" + "PhoneNumber" + "}", + this.pathPhoneNumber.encode("utf-8") + ); Request request = new Request( HttpMethod.GET, Domains.NUMBERS.toString(), path ); + addQueryParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("PortingPortability fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "PortingPortability fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return PortingPortability.fromJson(response.getStream(), client.getObjectMapper()); + return PortingPortability.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + private void addQueryParams(final Request request) { + if (targetAccountSid != null) { + request.addQueryParam("TargetAccountSid", targetAccountSid); + } } } diff --git a/src/main/java/com/twilio/rest/numbers/v2/AuthorizationDocument.java b/src/main/java/com/twilio/rest/numbers/v2/AuthorizationDocument.java index 8518dc18ff..88b223dc64 100644 --- a/src/main/java/com/twilio/rest/numbers/v2/AuthorizationDocument.java +++ b/src/main/java/com/twilio/rest/numbers/v2/AuthorizationDocument.java @@ -24,52 +24,61 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.List; import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class AuthorizationDocument extends Resource { + private static final long serialVersionUID = 7314983531290L; - public static AuthorizationDocumentCreator creator(final String addressSid, final String email, final com.twilio.type.PhoneNumber contactPhoneNumber){ - return new AuthorizationDocumentCreator(addressSid, email, contactPhoneNumber); + public static AuthorizationDocumentCreator creator( + final String addressSid, + final String email, + final com.twilio.type.PhoneNumber contactPhoneNumber, + final List hostedNumberOrderSids + ) { + return new AuthorizationDocumentCreator( + addressSid, + email, + contactPhoneNumber, + hostedNumberOrderSids + ); } - public static AuthorizationDocumentDeleter deleter(final String pathSid){ + public static AuthorizationDocumentDeleter deleter(final String pathSid) { return new AuthorizationDocumentDeleter(pathSid); } - public static AuthorizationDocumentFetcher fetcher(final String pathSid){ + public static AuthorizationDocumentFetcher fetcher(final String pathSid) { return new AuthorizationDocumentFetcher(pathSid); } - public static AuthorizationDocumentReader reader(){ + public static AuthorizationDocumentReader reader() { return new AuthorizationDocumentReader(); } /** - * Converts a JSON String into a AuthorizationDocument object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return AuthorizationDocument object represented by the provided JSON - */ - public static AuthorizationDocument fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a AuthorizationDocument object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return AuthorizationDocument object represented by the provided JSON + */ + public static AuthorizationDocument fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, AuthorizationDocument.class); @@ -81,14 +90,17 @@ public static AuthorizationDocument fromJson(final String json, final ObjectMapp } /** - * Converts a JSON InputStream into a AuthorizationDocument object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return AuthorizationDocument object represented by the provided JSON - */ - public static AuthorizationDocument fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a AuthorizationDocument object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return AuthorizationDocument object represented by the provided JSON + */ + public static AuthorizationDocument fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, AuthorizationDocument.class); @@ -98,6 +110,7 @@ public static AuthorizationDocument fromJson(final InputStream json, final Objec throw new ApiConnectionException(e.getMessage(), e); } } + public enum Status { OPENED("opened"), SIGNING("signing"), @@ -133,32 +146,15 @@ public static Status forValue(final String value) { @JsonCreator private AuthorizationDocument( - @JsonProperty("sid") - final String sid, - - @JsonProperty("address_sid") - final String addressSid, - - @JsonProperty("status") - final AuthorizationDocument.Status status, - - @JsonProperty("email") - final String email, - - @JsonProperty("cc_emails") - final List ccEmails, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("sid") final String sid, + @JsonProperty("address_sid") final String addressSid, + @JsonProperty("status") final AuthorizationDocument.Status status, + @JsonProperty("email") final String email, + @JsonProperty("cc_emails") final List ccEmails, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.sid = sid; this.addressSid = addressSid; @@ -171,37 +167,45 @@ private AuthorizationDocument( this.links = links; } - public final String getSid() { - return this.sid; - } - public final String getAddressSid() { - return this.addressSid; - } - public final AuthorizationDocument.Status getStatus() { - return this.status; - } - public final String getEmail() { - return this.email; - } - public final List getCcEmails() { - return this.ccEmails; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getSid() { + return this.sid; + } + + public final String getAddressSid() { + return this.addressSid; + } + + public final AuthorizationDocument.Status getStatus() { + return this.status; + } + + public final String getEmail() { + return this.email; + } + + public final List getCcEmails() { + return this.ccEmails; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -211,13 +215,31 @@ public boolean equals(final Object o) { AuthorizationDocument other = (AuthorizationDocument) o; - return Objects.equals(sid, other.sid) && Objects.equals(addressSid, other.addressSid) && Objects.equals(status, other.status) && Objects.equals(email, other.email) && Objects.equals(ccEmails, other.ccEmails) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(addressSid, other.addressSid) && + Objects.equals(status, other.status) && + Objects.equals(email, other.email) && + Objects.equals(ccEmails, other.ccEmails) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(sid, addressSid, status, email, ccEmails, dateCreated, dateUpdated, url, links); + return Objects.hash( + sid, + addressSid, + status, + email, + ccEmails, + dateCreated, + dateUpdated, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/numbers/v2/AuthorizationDocumentCreator.java b/src/main/java/com/twilio/rest/numbers/v2/AuthorizationDocumentCreator.java index 28e4f97d1a..ab07d30986 100644 --- a/src/main/java/com/twilio/rest/numbers/v2/AuthorizationDocumentCreator.java +++ b/src/main/java/com/twilio/rest/numbers/v2/AuthorizationDocumentCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.numbers.v2; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -25,101 +26,160 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.util.List; - import java.util.List; +public class AuthorizationDocumentCreator + extends Creator { - -public class AuthorizationDocumentCreator extends Creator{ private String addressSid; private String email; private com.twilio.type.PhoneNumber contactPhoneNumber; + private List hostedNumberOrderSids; private String contactTitle; private List ccEmails; - public AuthorizationDocumentCreator(final String addressSid, final String email, final com.twilio.type.PhoneNumber contactPhoneNumber) { + public AuthorizationDocumentCreator( + final String addressSid, + final String email, + final com.twilio.type.PhoneNumber contactPhoneNumber, + final List hostedNumberOrderSids + ) { this.addressSid = addressSid; this.email = email; this.contactPhoneNumber = contactPhoneNumber; + this.hostedNumberOrderSids = hostedNumberOrderSids; } - public AuthorizationDocumentCreator setAddressSid(final String addressSid){ + public AuthorizationDocumentCreator setAddressSid(final String addressSid) { this.addressSid = addressSid; return this; } - public AuthorizationDocumentCreator setEmail(final String email){ + + public AuthorizationDocumentCreator setEmail(final String email) { this.email = email; return this; } - public AuthorizationDocumentCreator setContactPhoneNumber(final com.twilio.type.PhoneNumber contactPhoneNumber){ + + public AuthorizationDocumentCreator setContactPhoneNumber( + final com.twilio.type.PhoneNumber contactPhoneNumber + ) { this.contactPhoneNumber = contactPhoneNumber; return this; } - public AuthorizationDocumentCreator setContactPhoneNumber(final String contactPhoneNumber){ - return setContactPhoneNumber(Promoter.phoneNumberFromString(contactPhoneNumber)); + public AuthorizationDocumentCreator setContactPhoneNumber( + final String contactPhoneNumber + ) { + return setContactPhoneNumber( + Promoter.phoneNumberFromString(contactPhoneNumber) + ); + } + + public AuthorizationDocumentCreator setHostedNumberOrderSids( + final List hostedNumberOrderSids + ) { + this.hostedNumberOrderSids = hostedNumberOrderSids; + return this; + } + + public AuthorizationDocumentCreator setHostedNumberOrderSids( + final String hostedNumberOrderSids + ) { + return setHostedNumberOrderSids( + Promoter.listOfOne(hostedNumberOrderSids) + ); } - public AuthorizationDocumentCreator setContactTitle(final String contactTitle){ + + public AuthorizationDocumentCreator setContactTitle( + final String contactTitle + ) { this.contactTitle = contactTitle; return this; } - public AuthorizationDocumentCreator setCcEmails(final List ccEmails){ + + public AuthorizationDocumentCreator setCcEmails( + final List ccEmails + ) { this.ccEmails = ccEmails; return this; } - public AuthorizationDocumentCreator setCcEmails(final String ccEmails){ + + public AuthorizationDocumentCreator setCcEmails(final String ccEmails) { return setCcEmails(Promoter.listOfOne(ccEmails)); } @Override - public AuthorizationDocument create(final TwilioRestClient client){ + public AuthorizationDocument create(final TwilioRestClient client) { String path = "/v2/HostedNumber/AuthorizationDocuments"; - path = path.replace("{"+"AddressSid"+"}", this.addressSid.toString()); - path = path.replace("{"+"Email"+"}", this.email.toString()); - path = path.replace("{"+"ContactPhoneNumber"+"}", this.contactPhoneNumber.encode("utf-8")); + path = + path.replace("{" + "AddressSid" + "}", this.addressSid.toString()); + path = path.replace("{" + "Email" + "}", this.email.toString()); + path = + path.replace( + "{" + "ContactPhoneNumber" + "}", + this.contactPhoneNumber.encode("utf-8") + ); + path = + path.replace( + "{" + "HostedNumberOrderSids" + "}", + this.hostedNumberOrderSids.toString() + ); Request request = new Request( HttpMethod.POST, Domains.NUMBERS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AuthorizationDocument creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "AuthorizationDocument creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return AuthorizationDocument.fromJson(response.getStream(), client.getObjectMapper()); + return AuthorizationDocument.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (addressSid != null) { request.addPostParam("AddressSid", addressSid); - } if (email != null) { request.addPostParam("Email", email); - } if (contactPhoneNumber != null) { - request.addPostParam("ContactPhoneNumber", contactPhoneNumber.toString()); - + request.addPostParam( + "ContactPhoneNumber", + contactPhoneNumber.toString() + ); + } + if (hostedNumberOrderSids != null) { + for (String prop : hostedNumberOrderSids) { + request.addPostParam("HostedNumberOrderSids", prop); + } } if (contactTitle != null) { request.addPostParam("ContactTitle", contactTitle); - } if (ccEmails != null) { for (String prop : ccEmails) { request.addPostParam("CcEmails", prop); } - } } } diff --git a/src/main/java/com/twilio/rest/numbers/v2/AuthorizationDocumentDeleter.java b/src/main/java/com/twilio/rest/numbers/v2/AuthorizationDocumentDeleter.java index b6f1ea6d6f..2ae9fe78ec 100644 --- a/src/main/java/com/twilio/rest/numbers/v2/AuthorizationDocumentDeleter.java +++ b/src/main/java/com/twilio/rest/numbers/v2/AuthorizationDocumentDeleter.java @@ -24,21 +24,20 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class AuthorizationDocumentDeleter + extends Deleter { - -public class AuthorizationDocumentDeleter extends Deleter { private String pathSid; - public AuthorizationDocumentDeleter(final String pathSid){ + public AuthorizationDocumentDeleter(final String pathSid) { this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v2/HostedNumber/AuthorizationDocuments/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -48,9 +47,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AuthorizationDocument delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "AuthorizationDocument delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/numbers/v2/AuthorizationDocumentFetcher.java b/src/main/java/com/twilio/rest/numbers/v2/AuthorizationDocumentFetcher.java index 04db3c945f..6268ad9d9f 100644 --- a/src/main/java/com/twilio/rest/numbers/v2/AuthorizationDocumentFetcher.java +++ b/src/main/java/com/twilio/rest/numbers/v2/AuthorizationDocumentFetcher.java @@ -24,22 +24,20 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class AuthorizationDocumentFetcher + extends Fetcher { - - -public class AuthorizationDocumentFetcher extends Fetcher { private String pathSid; - public AuthorizationDocumentFetcher(final String pathSid){ + public AuthorizationDocumentFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public AuthorizationDocument fetch(final TwilioRestClient client) { String path = "/v2/HostedNumber/AuthorizationDocuments/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,15 +47,23 @@ public AuthorizationDocument fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AuthorizationDocument fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "AuthorizationDocument fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return AuthorizationDocument.fromJson(response.getStream(), client.getObjectMapper()); + return AuthorizationDocument.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/numbers/v2/AuthorizationDocumentReader.java b/src/main/java/com/twilio/rest/numbers/v2/AuthorizationDocumentReader.java index eeec6066d8..3d9b75e44b 100644 --- a/src/main/java/com/twilio/rest/numbers/v2/AuthorizationDocumentReader.java +++ b/src/main/java/com/twilio/rest/numbers/v2/AuthorizationDocumentReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.numbers.v2; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,37 +25,42 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class AuthorizationDocumentReader extends Reader { + private String email; private AuthorizationDocument.Status status; private Integer pageSize; - public AuthorizationDocumentReader(){ - } + public AuthorizationDocumentReader() {} - public AuthorizationDocumentReader setEmail(final String email){ + public AuthorizationDocumentReader setEmail(final String email) { this.email = email; return this; } - public AuthorizationDocumentReader setStatus(final AuthorizationDocument.Status status){ + + public AuthorizationDocumentReader setStatus( + final AuthorizationDocument.Status status + ) { this.status = status; return this; } - public AuthorizationDocumentReader setPageSize(final Integer pageSize){ + + public AuthorizationDocumentReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @Override - public ResourceSet read(final TwilioRestClient client) { + public ResourceSet read( + final TwilioRestClient client + ) { return new ResourceSet<>(this, client, firstPage(client)); } - public Page firstPage(final TwilioRestClient client) { + public Page firstPage( + final TwilioRestClient client + ) { String path = "/v2/HostedNumber/AuthorizationDocuments"; Request request = new Request( @@ -67,13 +73,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AuthorizationDocument read failed: Unable to connect to server"); + throw new ApiConnectionException( + "AuthorizationDocument read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -89,7 +103,10 @@ private Page pageForRequest(final TwilioRestClient client } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.NUMBERS.toString()) @@ -97,9 +114,11 @@ public Page previousPage(final Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.NUMBERS.toString()) @@ -108,29 +127,27 @@ public Page nextPage(final Page pa } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (email != null) { - request.addQueryParam("Email", email); } if (status != null) { - request.addQueryParam("Status", status.toString()); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/numbers/v2/HostedNumberOrder.java b/src/main/java/com/twilio/rest/numbers/v2/HostedNumberOrder.java index 4fda3db0a4..b77dded9fb 100644 --- a/src/main/java/com/twilio/rest/numbers/v2/HostedNumberOrder.java +++ b/src/main/java/com/twilio/rest/numbers/v2/HostedNumberOrder.java @@ -24,51 +24,60 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - +import com.twilio.type.PhoneNumberCapabilities; import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.List; import java.util.Objects; - - -import com.twilio.type.PhoneNumberCapabilities; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class HostedNumberOrder extends Resource { - private static final long serialVersionUID = 193746671017979L; - public static HostedNumberOrderCreator creator(final com.twilio.type.PhoneNumber phoneNumber, final com.twilio.type.PhoneNumber contactPhoneNumber, final String addressSid, final String email){ - return new HostedNumberOrderCreator(phoneNumber, contactPhoneNumber, addressSid, email); + private static final long serialVersionUID = 181489495524580L; + + public static HostedNumberOrderCreator creator( + final com.twilio.type.PhoneNumber phoneNumber, + final com.twilio.type.PhoneNumber contactPhoneNumber, + final String addressSid, + final String email + ) { + return new HostedNumberOrderCreator( + phoneNumber, + contactPhoneNumber, + addressSid, + email + ); } - public static HostedNumberOrderDeleter deleter(final String pathSid){ + public static HostedNumberOrderDeleter deleter(final String pathSid) { return new HostedNumberOrderDeleter(pathSid); } - public static HostedNumberOrderFetcher fetcher(final String pathSid){ + public static HostedNumberOrderFetcher fetcher(final String pathSid) { return new HostedNumberOrderFetcher(pathSid); } - public static HostedNumberOrderReader reader(){ + public static HostedNumberOrderReader reader() { return new HostedNumberOrderReader(); } /** - * Converts a JSON String into a HostedNumberOrder object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return HostedNumberOrder object represented by the provided JSON - */ - public static HostedNumberOrder fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a HostedNumberOrder object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return HostedNumberOrder object represented by the provided JSON + */ + public static HostedNumberOrder fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, HostedNumberOrder.class); @@ -80,14 +89,17 @@ public static HostedNumberOrder fromJson(final String json, final ObjectMapper o } /** - * Converts a JSON InputStream into a HostedNumberOrder object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return HostedNumberOrder object represented by the provided JSON - */ - public static HostedNumberOrder fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a HostedNumberOrder object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return HostedNumberOrder object represented by the provided JSON + */ + public static HostedNumberOrder fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, HostedNumberOrder.class); @@ -97,6 +109,7 @@ public static HostedNumberOrder fromJson(final InputStream json, final ObjectMap throw new ApiConnectionException(e.getMessage(), e); } } + public enum Status { RECEIVED("received"), VERIFIED("verified"), @@ -133,7 +146,6 @@ public static Status forValue(final String value) { private final HostedNumberOrder.Status status; private final String failureReason; private final ZonedDateTime dateCreated; - private final Boolean smsCapability; private final ZonedDateTime dateUpdated; private final String email; private final List ccEmails; @@ -145,65 +157,35 @@ public static Status forValue(final String value) { @JsonCreator private HostedNumberOrder( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("incoming_phone_number_sid") - final String incomingPhoneNumberSid, - - @JsonProperty("address_sid") - final String addressSid, - - @JsonProperty("signing_document_sid") - final String signingDocumentSid, - - @JsonProperty("phone_number") - final com.twilio.type.PhoneNumber phoneNumber, - - @JsonProperty("capabilities") - final PhoneNumberCapabilities capabilities, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("status") - final HostedNumberOrder.Status status, - - @JsonProperty("failure_reason") - final String failureReason, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("sms_capability") - final Boolean smsCapability, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("email") - final String email, - - @JsonProperty("cc_emails") - final List ccEmails, - - @JsonProperty("url") - final URI url, - - @JsonProperty("contact_title") - final String contactTitle, - - @JsonProperty("contact_phone_number") - final com.twilio.type.PhoneNumber contactPhoneNumber, - - @JsonProperty("bulk_hosting_request_sid") - final String bulkHostingRequestSid, - - @JsonProperty("next_step") - final String nextStep + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty( + "incoming_phone_number_sid" + ) final String incomingPhoneNumberSid, + @JsonProperty("address_sid") final String addressSid, + @JsonProperty("signing_document_sid") final String signingDocumentSid, + @JsonProperty( + "phone_number" + ) final com.twilio.type.PhoneNumber phoneNumber, + @JsonProperty( + "capabilities" + ) final PhoneNumberCapabilities capabilities, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("status") final HostedNumberOrder.Status status, + @JsonProperty("failure_reason") final String failureReason, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("email") final String email, + @JsonProperty("cc_emails") final List ccEmails, + @JsonProperty("url") final URI url, + @JsonProperty("contact_title") final String contactTitle, + @JsonProperty( + "contact_phone_number" + ) final com.twilio.type.PhoneNumber contactPhoneNumber, + @JsonProperty( + "bulk_hosting_request_sid" + ) final String bulkHostingRequestSid, + @JsonProperty("next_step") final String nextStep ) { this.sid = sid; this.accountSid = accountSid; @@ -216,7 +198,6 @@ private HostedNumberOrder( this.status = status; this.failureReason = failureReason; this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.smsCapability = smsCapability; this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); this.email = email; this.ccEmails = ccEmails; @@ -227,70 +208,85 @@ private HostedNumberOrder( this.nextStep = nextStep; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getIncomingPhoneNumberSid() { - return this.incomingPhoneNumberSid; - } - public final String getAddressSid() { - return this.addressSid; - } - public final String getSigningDocumentSid() { - return this.signingDocumentSid; - } - public final com.twilio.type.PhoneNumber getPhoneNumber() { - return this.phoneNumber; - } - public final PhoneNumberCapabilities getCapabilities() { - return this.capabilities; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final HostedNumberOrder.Status getStatus() { - return this.status; - } - public final String getFailureReason() { - return this.failureReason; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final Boolean getSmsCapability() { - return this.smsCapability; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getEmail() { - return this.email; - } - public final List getCcEmails() { - return this.ccEmails; - } - public final URI getUrl() { - return this.url; - } - public final String getContactTitle() { - return this.contactTitle; - } - public final com.twilio.type.PhoneNumber getContactPhoneNumber() { - return this.contactPhoneNumber; - } - public final String getBulkHostingRequestSid() { - return this.bulkHostingRequestSid; - } - public final String getNextStep() { - return this.nextStep; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getIncomingPhoneNumberSid() { + return this.incomingPhoneNumberSid; + } + + public final String getAddressSid() { + return this.addressSid; + } + + public final String getSigningDocumentSid() { + return this.signingDocumentSid; + } + + public final com.twilio.type.PhoneNumber getPhoneNumber() { + return this.phoneNumber; + } + + public final PhoneNumberCapabilities getCapabilities() { + return this.capabilities; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final HostedNumberOrder.Status getStatus() { + return this.status; + } + + public final String getFailureReason() { + return this.failureReason; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getEmail() { + return this.email; + } + + public final List getCcEmails() { + return this.ccEmails; + } + + public final URI getUrl() { + return this.url; + } + + public final String getContactTitle() { + return this.contactTitle; + } + + public final com.twilio.type.PhoneNumber getContactPhoneNumber() { + return this.contactPhoneNumber; + } + + public final String getBulkHostingRequestSid() { + return this.bulkHostingRequestSid; + } + + public final String getNextStep() { + return this.nextStep; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -300,13 +296,57 @@ public boolean equals(final Object o) { HostedNumberOrder other = (HostedNumberOrder) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(incomingPhoneNumberSid, other.incomingPhoneNumberSid) && Objects.equals(addressSid, other.addressSid) && Objects.equals(signingDocumentSid, other.signingDocumentSid) && Objects.equals(phoneNumber, other.phoneNumber) && Objects.equals(capabilities, other.capabilities) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(status, other.status) && Objects.equals(failureReason, other.failureReason) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(smsCapability, other.smsCapability) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(email, other.email) && Objects.equals(ccEmails, other.ccEmails) && Objects.equals(url, other.url) && Objects.equals(contactTitle, other.contactTitle) && Objects.equals(contactPhoneNumber, other.contactPhoneNumber) && Objects.equals(bulkHostingRequestSid, other.bulkHostingRequestSid) && Objects.equals(nextStep, other.nextStep) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals( + incomingPhoneNumberSid, + other.incomingPhoneNumberSid + ) && + Objects.equals(addressSid, other.addressSid) && + Objects.equals(signingDocumentSid, other.signingDocumentSid) && + Objects.equals(phoneNumber, other.phoneNumber) && + Objects.equals(capabilities, other.capabilities) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(status, other.status) && + Objects.equals(failureReason, other.failureReason) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(email, other.email) && + Objects.equals(ccEmails, other.ccEmails) && + Objects.equals(url, other.url) && + Objects.equals(contactTitle, other.contactTitle) && + Objects.equals(contactPhoneNumber, other.contactPhoneNumber) && + Objects.equals( + bulkHostingRequestSid, + other.bulkHostingRequestSid + ) && + Objects.equals(nextStep, other.nextStep) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, incomingPhoneNumberSid, addressSid, signingDocumentSid, phoneNumber, capabilities, friendlyName, status, failureReason, dateCreated, smsCapability, dateUpdated, email, ccEmails, url, contactTitle, contactPhoneNumber, bulkHostingRequestSid, nextStep); + return Objects.hash( + sid, + accountSid, + incomingPhoneNumberSid, + addressSid, + signingDocumentSid, + phoneNumber, + capabilities, + friendlyName, + status, + failureReason, + dateCreated, + dateUpdated, + email, + ccEmails, + url, + contactTitle, + contactPhoneNumber, + bulkHostingRequestSid, + nextStep + ); } - } - diff --git a/src/main/java/com/twilio/rest/numbers/v2/HostedNumberOrderCreator.java b/src/main/java/com/twilio/rest/numbers/v2/HostedNumberOrderCreator.java index 97ee7d6a2f..104fc6015e 100644 --- a/src/main/java/com/twilio/rest/numbers/v2/HostedNumberOrderCreator.java +++ b/src/main/java/com/twilio/rest/numbers/v2/HostedNumberOrderCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.numbers.v2; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -24,15 +25,13 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import java.util.List; import java.net.URI; - +import java.net.URI; +import java.util.List; import java.util.List; +public class HostedNumberOrderCreator extends Creator { -import java.net.URI; - -public class HostedNumberOrderCreator extends Creator{ private com.twilio.type.PhoneNumber phoneNumber; private com.twilio.type.PhoneNumber contactPhoneNumber; private String addressSid; @@ -50,195 +49,255 @@ public class HostedNumberOrderCreator extends Creator{ private String smsApplicationSid; private String contactTitle; - public HostedNumberOrderCreator(final com.twilio.type.PhoneNumber phoneNumber, final com.twilio.type.PhoneNumber contactPhoneNumber, final String addressSid, final String email) { + public HostedNumberOrderCreator( + final com.twilio.type.PhoneNumber phoneNumber, + final com.twilio.type.PhoneNumber contactPhoneNumber, + final String addressSid, + final String email + ) { this.phoneNumber = phoneNumber; this.contactPhoneNumber = contactPhoneNumber; this.addressSid = addressSid; this.email = email; } - public HostedNumberOrderCreator setPhoneNumber(final com.twilio.type.PhoneNumber phoneNumber){ + public HostedNumberOrderCreator setPhoneNumber( + final com.twilio.type.PhoneNumber phoneNumber + ) { this.phoneNumber = phoneNumber; return this; } - public HostedNumberOrderCreator setPhoneNumber(final String phoneNumber){ + public HostedNumberOrderCreator setPhoneNumber(final String phoneNumber) { return setPhoneNumber(Promoter.phoneNumberFromString(phoneNumber)); } - public HostedNumberOrderCreator setContactPhoneNumber(final com.twilio.type.PhoneNumber contactPhoneNumber){ + + public HostedNumberOrderCreator setContactPhoneNumber( + final com.twilio.type.PhoneNumber contactPhoneNumber + ) { this.contactPhoneNumber = contactPhoneNumber; return this; } - public HostedNumberOrderCreator setContactPhoneNumber(final String contactPhoneNumber){ - return setContactPhoneNumber(Promoter.phoneNumberFromString(contactPhoneNumber)); + public HostedNumberOrderCreator setContactPhoneNumber( + final String contactPhoneNumber + ) { + return setContactPhoneNumber( + Promoter.phoneNumberFromString(contactPhoneNumber) + ); } - public HostedNumberOrderCreator setAddressSid(final String addressSid){ + + public HostedNumberOrderCreator setAddressSid(final String addressSid) { this.addressSid = addressSid; return this; } - public HostedNumberOrderCreator setEmail(final String email){ + + public HostedNumberOrderCreator setEmail(final String email) { this.email = email; return this; } - public HostedNumberOrderCreator setAccountSid(final String accountSid){ + + public HostedNumberOrderCreator setAccountSid(final String accountSid) { this.accountSid = accountSid; return this; } - public HostedNumberOrderCreator setFriendlyName(final String friendlyName){ + + public HostedNumberOrderCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public HostedNumberOrderCreator setCcEmails(final List ccEmails){ + + public HostedNumberOrderCreator setCcEmails(final List ccEmails) { this.ccEmails = ccEmails; return this; } - public HostedNumberOrderCreator setCcEmails(final String ccEmails){ + + public HostedNumberOrderCreator setCcEmails(final String ccEmails) { return setCcEmails(Promoter.listOfOne(ccEmails)); } - public HostedNumberOrderCreator setSmsUrl(final URI smsUrl){ + + public HostedNumberOrderCreator setSmsUrl(final URI smsUrl) { this.smsUrl = smsUrl; return this; } - public HostedNumberOrderCreator setSmsUrl(final String smsUrl){ + public HostedNumberOrderCreator setSmsUrl(final String smsUrl) { return setSmsUrl(Promoter.uriFromString(smsUrl)); } - public HostedNumberOrderCreator setSmsMethod(final HttpMethod smsMethod){ + + public HostedNumberOrderCreator setSmsMethod(final HttpMethod smsMethod) { this.smsMethod = smsMethod; return this; } - public HostedNumberOrderCreator setSmsFallbackUrl(final URI smsFallbackUrl){ + + public HostedNumberOrderCreator setSmsFallbackUrl( + final URI smsFallbackUrl + ) { this.smsFallbackUrl = smsFallbackUrl; return this; } - public HostedNumberOrderCreator setSmsFallbackUrl(final String smsFallbackUrl){ + public HostedNumberOrderCreator setSmsFallbackUrl( + final String smsFallbackUrl + ) { return setSmsFallbackUrl(Promoter.uriFromString(smsFallbackUrl)); } - public HostedNumberOrderCreator setSmsCapability(final Boolean smsCapability){ + + public HostedNumberOrderCreator setSmsCapability( + final Boolean smsCapability + ) { this.smsCapability = smsCapability; return this; } - public HostedNumberOrderCreator setSmsFallbackMethod(final HttpMethod smsFallbackMethod){ + + public HostedNumberOrderCreator setSmsFallbackMethod( + final HttpMethod smsFallbackMethod + ) { this.smsFallbackMethod = smsFallbackMethod; return this; } - public HostedNumberOrderCreator setStatusCallbackUrl(final URI statusCallbackUrl){ + + public HostedNumberOrderCreator setStatusCallbackUrl( + final URI statusCallbackUrl + ) { this.statusCallbackUrl = statusCallbackUrl; return this; } - public HostedNumberOrderCreator setStatusCallbackUrl(final String statusCallbackUrl){ + public HostedNumberOrderCreator setStatusCallbackUrl( + final String statusCallbackUrl + ) { return setStatusCallbackUrl(Promoter.uriFromString(statusCallbackUrl)); } - public HostedNumberOrderCreator setStatusCallbackMethod(final HttpMethod statusCallbackMethod){ + + public HostedNumberOrderCreator setStatusCallbackMethod( + final HttpMethod statusCallbackMethod + ) { this.statusCallbackMethod = statusCallbackMethod; return this; } - public HostedNumberOrderCreator setSmsApplicationSid(final String smsApplicationSid){ + + public HostedNumberOrderCreator setSmsApplicationSid( + final String smsApplicationSid + ) { this.smsApplicationSid = smsApplicationSid; return this; } - public HostedNumberOrderCreator setContactTitle(final String contactTitle){ + + public HostedNumberOrderCreator setContactTitle(final String contactTitle) { this.contactTitle = contactTitle; return this; } @Override - public HostedNumberOrder create(final TwilioRestClient client){ + public HostedNumberOrder create(final TwilioRestClient client) { String path = "/v2/HostedNumber/Orders"; - path = path.replace("{"+"PhoneNumber"+"}", this.phoneNumber.encode("utf-8")); - path = path.replace("{"+"ContactPhoneNumber"+"}", this.contactPhoneNumber.encode("utf-8")); - path = path.replace("{"+"AddressSid"+"}", this.addressSid.toString()); - path = path.replace("{"+"Email"+"}", this.email.toString()); + path = + path.replace( + "{" + "PhoneNumber" + "}", + this.phoneNumber.encode("utf-8") + ); + path = + path.replace( + "{" + "ContactPhoneNumber" + "}", + this.contactPhoneNumber.encode("utf-8") + ); + path = + path.replace("{" + "AddressSid" + "}", this.addressSid.toString()); + path = path.replace("{" + "Email" + "}", this.email.toString()); Request request = new Request( HttpMethod.POST, Domains.NUMBERS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("HostedNumberOrder creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "HostedNumberOrder creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return HostedNumberOrder.fromJson(response.getStream(), client.getObjectMapper()); + return HostedNumberOrder.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (phoneNumber != null) { request.addPostParam("PhoneNumber", phoneNumber.toString()); - } if (contactPhoneNumber != null) { - request.addPostParam("ContactPhoneNumber", contactPhoneNumber.toString()); - + request.addPostParam( + "ContactPhoneNumber", + contactPhoneNumber.toString() + ); } if (addressSid != null) { request.addPostParam("AddressSid", addressSid); - } if (email != null) { request.addPostParam("Email", email); - } if (accountSid != null) { request.addPostParam("AccountSid", accountSid); - } if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (ccEmails != null) { for (String prop : ccEmails) { request.addPostParam("CcEmails", prop); } - } if (smsUrl != null) { request.addPostParam("SmsUrl", smsUrl.toString()); - } if (smsMethod != null) { request.addPostParam("SmsMethod", smsMethod.toString()); - } if (smsFallbackUrl != null) { request.addPostParam("SmsFallbackUrl", smsFallbackUrl.toString()); - } if (smsCapability != null) { request.addPostParam("SmsCapability", smsCapability.toString()); - } if (smsFallbackMethod != null) { - request.addPostParam("SmsFallbackMethod", smsFallbackMethod.toString()); - + request.addPostParam( + "SmsFallbackMethod", + smsFallbackMethod.toString() + ); } if (statusCallbackUrl != null) { - request.addPostParam("StatusCallbackUrl", statusCallbackUrl.toString()); - + request.addPostParam( + "StatusCallbackUrl", + statusCallbackUrl.toString() + ); } if (statusCallbackMethod != null) { - request.addPostParam("StatusCallbackMethod", statusCallbackMethod.toString()); - + request.addPostParam( + "StatusCallbackMethod", + statusCallbackMethod.toString() + ); } if (smsApplicationSid != null) { request.addPostParam("SmsApplicationSid", smsApplicationSid); - } if (contactTitle != null) { request.addPostParam("ContactTitle", contactTitle); - } } } diff --git a/src/main/java/com/twilio/rest/numbers/v2/HostedNumberOrderDeleter.java b/src/main/java/com/twilio/rest/numbers/v2/HostedNumberOrderDeleter.java index 81afe71489..799692072f 100644 --- a/src/main/java/com/twilio/rest/numbers/v2/HostedNumberOrderDeleter.java +++ b/src/main/java/com/twilio/rest/numbers/v2/HostedNumberOrderDeleter.java @@ -24,21 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class HostedNumberOrderDeleter extends Deleter { + private String pathSid; - public HostedNumberOrderDeleter(final String pathSid){ + public HostedNumberOrderDeleter(final String pathSid) { this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v2/HostedNumber/Orders/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -48,9 +46,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("HostedNumberOrder delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "HostedNumberOrder delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/numbers/v2/HostedNumberOrderFetcher.java b/src/main/java/com/twilio/rest/numbers/v2/HostedNumberOrderFetcher.java index aa5fb2cb51..01fad4d5b2 100644 --- a/src/main/java/com/twilio/rest/numbers/v2/HostedNumberOrderFetcher.java +++ b/src/main/java/com/twilio/rest/numbers/v2/HostedNumberOrderFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class HostedNumberOrderFetcher extends Fetcher { + private String pathSid; - public HostedNumberOrderFetcher(final String pathSid){ + public HostedNumberOrderFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public HostedNumberOrder fetch(final TwilioRestClient client) { String path = "/v2/HostedNumber/Orders/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,15 +46,23 @@ public HostedNumberOrder fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("HostedNumberOrder fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "HostedNumberOrder fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return HostedNumberOrder.fromJson(response.getStream(), client.getObjectMapper()); + return HostedNumberOrder.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/numbers/v2/HostedNumberOrderReader.java b/src/main/java/com/twilio/rest/numbers/v2/HostedNumberOrderReader.java index 77d822290b..b4b4122c4d 100644 --- a/src/main/java/com/twilio/rest/numbers/v2/HostedNumberOrderReader.java +++ b/src/main/java/com/twilio/rest/numbers/v2/HostedNumberOrderReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.numbers.v2; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.converter.Promoter; @@ -25,11 +26,9 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class HostedNumberOrderReader extends Reader { + private HostedNumberOrder.Status status; private Boolean smsCapability; private com.twilio.type.PhoneNumber phoneNumber; @@ -37,34 +36,46 @@ public class HostedNumberOrderReader extends Reader { private String friendlyName; private Integer pageSize; - public HostedNumberOrderReader(){ - } + public HostedNumberOrderReader() {} - public HostedNumberOrderReader setStatus(final HostedNumberOrder.Status status){ + public HostedNumberOrderReader setStatus( + final HostedNumberOrder.Status status + ) { this.status = status; return this; } - public HostedNumberOrderReader setSmsCapability(final Boolean smsCapability){ + + public HostedNumberOrderReader setSmsCapability( + final Boolean smsCapability + ) { this.smsCapability = smsCapability; return this; } - public HostedNumberOrderReader setPhoneNumber(final com.twilio.type.PhoneNumber phoneNumber){ + + public HostedNumberOrderReader setPhoneNumber( + final com.twilio.type.PhoneNumber phoneNumber + ) { this.phoneNumber = phoneNumber; return this; } - public HostedNumberOrderReader setPhoneNumber(final String phoneNumber){ + public HostedNumberOrderReader setPhoneNumber(final String phoneNumber) { return setPhoneNumber(Promoter.phoneNumberFromString(phoneNumber)); } - public HostedNumberOrderReader setIncomingPhoneNumberSid(final String incomingPhoneNumberSid){ + + public HostedNumberOrderReader setIncomingPhoneNumberSid( + final String incomingPhoneNumberSid + ) { this.incomingPhoneNumberSid = incomingPhoneNumberSid; return this; } - public HostedNumberOrderReader setFriendlyName(final String friendlyName){ + + public HostedNumberOrderReader setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public HostedNumberOrderReader setPageSize(final Integer pageSize){ + + public HostedNumberOrderReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -87,13 +98,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("HostedNumberOrder read failed: Unable to connect to server"); + throw new ApiConnectionException( + "HostedNumberOrder read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -109,7 +128,10 @@ private Page pageForRequest(final TwilioRestClient client, fi } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.NUMBERS.toString()) @@ -117,9 +139,11 @@ public Page previousPage(final Page page, return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.NUMBERS.toString()) @@ -128,41 +152,39 @@ public Page nextPage(final Page page, fina } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (status != null) { - request.addQueryParam("Status", status.toString()); } if (smsCapability != null) { - request.addQueryParam("SmsCapability", smsCapability.toString()); } if (phoneNumber != null) { - request.addQueryParam("PhoneNumber", phoneNumber.toString()); } if (incomingPhoneNumberSid != null) { - - request.addQueryParam("IncomingPhoneNumberSid", incomingPhoneNumberSid); + request.addQueryParam( + "IncomingPhoneNumberSid", + incomingPhoneNumberSid + ); } if (friendlyName != null) { - request.addQueryParam("FriendlyName", friendlyName); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/numbers/v2/authorizationdocument/DependentHostedNumberOrder.java b/src/main/java/com/twilio/rest/numbers/v2/authorizationdocument/DependentHostedNumberOrder.java index 915fae78f7..8aa8eff34b 100644 --- a/src/main/java/com/twilio/rest/numbers/v2/authorizationdocument/DependentHostedNumberOrder.java +++ b/src/main/java/com/twilio/rest/numbers/v2/authorizationdocument/DependentHostedNumberOrder.java @@ -24,41 +24,45 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - +import com.twilio.type.PhoneNumberCapabilities; import java.io.IOException; import java.io.InputStream; import java.time.ZonedDateTime; - import java.util.List; import java.util.Objects; - - -import com.twilio.type.PhoneNumberCapabilities; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class DependentHostedNumberOrder extends Resource { + private static final long serialVersionUID = 76724825729320L; - public static DependentHostedNumberOrderReader reader(final String pathSigningDocumentSid){ + public static DependentHostedNumberOrderReader reader( + final String pathSigningDocumentSid + ) { return new DependentHostedNumberOrderReader(pathSigningDocumentSid); } /** - * Converts a JSON String into a DependentHostedNumberOrder object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return DependentHostedNumberOrder object represented by the provided JSON - */ - public static DependentHostedNumberOrder fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a DependentHostedNumberOrder object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return DependentHostedNumberOrder object represented by the provided JSON + */ + public static DependentHostedNumberOrder fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, DependentHostedNumberOrder.class); + return objectMapper.readValue( + json, + DependentHostedNumberOrder.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -67,23 +71,30 @@ public static DependentHostedNumberOrder fromJson(final String json, final Objec } /** - * Converts a JSON InputStream into a DependentHostedNumberOrder object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return DependentHostedNumberOrder object represented by the provided JSON - */ - public static DependentHostedNumberOrder fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a DependentHostedNumberOrder object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return DependentHostedNumberOrder object represented by the provided JSON + */ + public static DependentHostedNumberOrder fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, DependentHostedNumberOrder.class); + return objectMapper.readValue( + json, + DependentHostedNumberOrder.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { throw new ApiConnectionException(e.getMessage(), e); } } + public enum Status { RECEIVED("received"), VERIFIED("verified"), @@ -130,59 +141,34 @@ public static Status forValue(final String value) { @JsonCreator private DependentHostedNumberOrder( - @JsonProperty("sid") - final String sid, - - @JsonProperty("bulk_hosting_request_sid") - final String bulkHostingRequestSid, - - @JsonProperty("next_step") - final String nextStep, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("incoming_phone_number_sid") - final String incomingPhoneNumberSid, - - @JsonProperty("address_sid") - final String addressSid, - - @JsonProperty("signing_document_sid") - final String signingDocumentSid, - - @JsonProperty("phone_number") - final com.twilio.type.PhoneNumber phoneNumber, - - @JsonProperty("capabilities") - final PhoneNumberCapabilities capabilities, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("status") - final DependentHostedNumberOrder.Status status, - - @JsonProperty("failure_reason") - final String failureReason, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("email") - final String email, - - @JsonProperty("cc_emails") - final List ccEmails, - - @JsonProperty("contact_title") - final String contactTitle, - - @JsonProperty("contact_phone_number") - final com.twilio.type.PhoneNumber contactPhoneNumber + @JsonProperty("sid") final String sid, + @JsonProperty( + "bulk_hosting_request_sid" + ) final String bulkHostingRequestSid, + @JsonProperty("next_step") final String nextStep, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty( + "incoming_phone_number_sid" + ) final String incomingPhoneNumberSid, + @JsonProperty("address_sid") final String addressSid, + @JsonProperty("signing_document_sid") final String signingDocumentSid, + @JsonProperty( + "phone_number" + ) final com.twilio.type.PhoneNumber phoneNumber, + @JsonProperty( + "capabilities" + ) final PhoneNumberCapabilities capabilities, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("status") final DependentHostedNumberOrder.Status status, + @JsonProperty("failure_reason") final String failureReason, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("email") final String email, + @JsonProperty("cc_emails") final List ccEmails, + @JsonProperty("contact_title") final String contactTitle, + @JsonProperty( + "contact_phone_number" + ) final com.twilio.type.PhoneNumber contactPhoneNumber ) { this.sid = sid; this.bulkHostingRequestSid = bulkHostingRequestSid; @@ -204,64 +190,81 @@ private DependentHostedNumberOrder( this.contactPhoneNumber = contactPhoneNumber; } - public final String getSid() { - return this.sid; - } - public final String getBulkHostingRequestSid() { - return this.bulkHostingRequestSid; - } - public final String getNextStep() { - return this.nextStep; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getIncomingPhoneNumberSid() { - return this.incomingPhoneNumberSid; - } - public final String getAddressSid() { - return this.addressSid; - } - public final String getSigningDocumentSid() { - return this.signingDocumentSid; - } - public final com.twilio.type.PhoneNumber getPhoneNumber() { - return this.phoneNumber; - } - public final PhoneNumberCapabilities getCapabilities() { - return this.capabilities; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final DependentHostedNumberOrder.Status getStatus() { - return this.status; - } - public final String getFailureReason() { - return this.failureReason; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getEmail() { - return this.email; - } - public final List getCcEmails() { - return this.ccEmails; - } - public final String getContactTitle() { - return this.contactTitle; - } - public final com.twilio.type.PhoneNumber getContactPhoneNumber() { - return this.contactPhoneNumber; - } + public final String getSid() { + return this.sid; + } + + public final String getBulkHostingRequestSid() { + return this.bulkHostingRequestSid; + } + + public final String getNextStep() { + return this.nextStep; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getIncomingPhoneNumberSid() { + return this.incomingPhoneNumberSid; + } + + public final String getAddressSid() { + return this.addressSid; + } + + public final String getSigningDocumentSid() { + return this.signingDocumentSid; + } + + public final com.twilio.type.PhoneNumber getPhoneNumber() { + return this.phoneNumber; + } + + public final PhoneNumberCapabilities getCapabilities() { + return this.capabilities; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final DependentHostedNumberOrder.Status getStatus() { + return this.status; + } + + public final String getFailureReason() { + return this.failureReason; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getEmail() { + return this.email; + } + + public final List getCcEmails() { + return this.ccEmails; + } + + public final String getContactTitle() { + return this.contactTitle; + } + + public final com.twilio.type.PhoneNumber getContactPhoneNumber() { + return this.contactPhoneNumber; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -271,13 +274,55 @@ public boolean equals(final Object o) { DependentHostedNumberOrder other = (DependentHostedNumberOrder) o; - return Objects.equals(sid, other.sid) && Objects.equals(bulkHostingRequestSid, other.bulkHostingRequestSid) && Objects.equals(nextStep, other.nextStep) && Objects.equals(accountSid, other.accountSid) && Objects.equals(incomingPhoneNumberSid, other.incomingPhoneNumberSid) && Objects.equals(addressSid, other.addressSid) && Objects.equals(signingDocumentSid, other.signingDocumentSid) && Objects.equals(phoneNumber, other.phoneNumber) && Objects.equals(capabilities, other.capabilities) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(status, other.status) && Objects.equals(failureReason, other.failureReason) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(email, other.email) && Objects.equals(ccEmails, other.ccEmails) && Objects.equals(contactTitle, other.contactTitle) && Objects.equals(contactPhoneNumber, other.contactPhoneNumber) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals( + bulkHostingRequestSid, + other.bulkHostingRequestSid + ) && + Objects.equals(nextStep, other.nextStep) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals( + incomingPhoneNumberSid, + other.incomingPhoneNumberSid + ) && + Objects.equals(addressSid, other.addressSid) && + Objects.equals(signingDocumentSid, other.signingDocumentSid) && + Objects.equals(phoneNumber, other.phoneNumber) && + Objects.equals(capabilities, other.capabilities) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(status, other.status) && + Objects.equals(failureReason, other.failureReason) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(email, other.email) && + Objects.equals(ccEmails, other.ccEmails) && + Objects.equals(contactTitle, other.contactTitle) && + Objects.equals(contactPhoneNumber, other.contactPhoneNumber) + ); } @Override public int hashCode() { - return Objects.hash(sid, bulkHostingRequestSid, nextStep, accountSid, incomingPhoneNumberSid, addressSid, signingDocumentSid, phoneNumber, capabilities, friendlyName, status, failureReason, dateCreated, dateUpdated, email, ccEmails, contactTitle, contactPhoneNumber); + return Objects.hash( + sid, + bulkHostingRequestSid, + nextStep, + accountSid, + incomingPhoneNumberSid, + addressSid, + signingDocumentSid, + phoneNumber, + capabilities, + friendlyName, + status, + failureReason, + dateCreated, + dateUpdated, + email, + ccEmails, + contactTitle, + contactPhoneNumber + ); } - } - diff --git a/src/main/java/com/twilio/rest/numbers/v2/authorizationdocument/DependentHostedNumberOrderReader.java b/src/main/java/com/twilio/rest/numbers/v2/authorizationdocument/DependentHostedNumberOrderReader.java index c74f0d3223..5f699cb2cb 100644 --- a/src/main/java/com/twilio/rest/numbers/v2/authorizationdocument/DependentHostedNumberOrderReader.java +++ b/src/main/java/com/twilio/rest/numbers/v2/authorizationdocument/DependentHostedNumberOrderReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.numbers.v2.authorizationdocument; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.converter.Promoter; @@ -25,11 +26,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - +public class DependentHostedNumberOrderReader + extends Reader { -public class DependentHostedNumberOrderReader extends Reader { private String pathSigningDocumentSid; private DependentHostedNumberOrder.Status status; private com.twilio.type.PhoneNumber phoneNumber; @@ -37,43 +37,70 @@ public class DependentHostedNumberOrderReader extends Reader read(final TwilioRestClient client) { + public ResourceSet read( + final TwilioRestClient client + ) { return new ResourceSet<>(this, client, firstPage(client)); } - public Page firstPage(final TwilioRestClient client) { - String path = "/v2/HostedNumber/AuthorizationDocuments/{SigningDocumentSid}/DependentHostedNumberOrders"; - path = path.replace("{"+"SigningDocumentSid"+"}", this.pathSigningDocumentSid.toString()); + public Page firstPage( + final TwilioRestClient client + ) { + String path = + "/v2/HostedNumber/AuthorizationDocuments/{SigningDocumentSid}/DependentHostedNumberOrders"; + path = + path.replace( + "{" + "SigningDocumentSid" + "}", + this.pathSigningDocumentSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -85,13 +112,21 @@ public Page firstPage(final TwilioRestClient client) return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("DependentHostedNumberOrder read failed: Unable to connect to server"); + throw new ApiConnectionException( + "DependentHostedNumberOrder read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -107,7 +142,10 @@ private Page pageForRequest(final TwilioRestClient c } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.NUMBERS.toString()) @@ -115,9 +153,11 @@ public Page previousPage(final Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.NUMBERS.toString()) @@ -126,37 +166,36 @@ public Page nextPage(final Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (status != null) { - request.addQueryParam("Status", status.toString()); } if (phoneNumber != null) { - request.addQueryParam("PhoneNumber", phoneNumber.toString()); } if (incomingPhoneNumberSid != null) { - - request.addQueryParam("IncomingPhoneNumberSid", incomingPhoneNumberSid); + request.addQueryParam( + "IncomingPhoneNumberSid", + incomingPhoneNumberSid + ); } if (friendlyName != null) { - request.addQueryParam("FriendlyName", friendlyName); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/Bundle.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/Bundle.java index 5aaa824b67..2e35f241a6 100644 --- a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/Bundle.java +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/Bundle.java @@ -24,55 +24,57 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Bundle extends Resource { + private static final long serialVersionUID = 198185819431201L; - public static BundleCreator creator(final String friendlyName, final String email){ + public static BundleCreator creator( + final String friendlyName, + final String email + ) { return new BundleCreator(friendlyName, email); } - public static BundleDeleter deleter(final String pathSid){ + public static BundleDeleter deleter(final String pathSid) { return new BundleDeleter(pathSid); } - public static BundleFetcher fetcher(final String pathSid){ + public static BundleFetcher fetcher(final String pathSid) { return new BundleFetcher(pathSid); } - public static BundleReader reader(){ + public static BundleReader reader() { return new BundleReader(); } - public static BundleUpdater updater(final String pathSid){ + public static BundleUpdater updater(final String pathSid) { return new BundleUpdater(pathSid); } /** - * Converts a JSON String into a Bundle object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Bundle object represented by the provided JSON - */ - public static Bundle fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Bundle object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Bundle object represented by the provided JSON + */ + public static Bundle fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Bundle.class); @@ -84,14 +86,17 @@ public static Bundle fromJson(final String json, final ObjectMapper objectMapper } /** - * Converts a JSON InputStream into a Bundle object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Bundle object represented by the provided JSON - */ - public static Bundle fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Bundle object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Bundle object represented by the provided JSON + */ + public static Bundle fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Bundle.class); @@ -101,6 +106,7 @@ public static Bundle fromJson(final InputStream json, final ObjectMapper objectM throw new ApiConnectionException(e.getMessage(), e); } } + public enum EndUserType { INDIVIDUAL("individual"), BUSINESS("business"); @@ -120,6 +126,7 @@ public static EndUserType forValue(final String value) { return Promoter.enumFromString(value, EndUserType.values()); } } + public enum SortBy { VALID_UNTIL("valid-until"), DATE_UPDATED("date-updated"); @@ -139,6 +146,7 @@ public static SortBy forValue(final String value) { return Promoter.enumFromString(value, SortBy.values()); } } + public enum SortDirection { ASC("ASC"), DESC("DESC"); @@ -158,6 +166,7 @@ public static SortDirection forValue(final String value) { return Promoter.enumFromString(value, SortDirection.values()); } } + public enum Status { DRAFT("draft"), PENDING_REVIEW("pending-review"), @@ -197,41 +206,18 @@ public static Status forValue(final String value) { @JsonCreator private Bundle( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("regulation_sid") - final String regulationSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("status") - final Bundle.Status status, - - @JsonProperty("valid_until") - final String validUntil, - - @JsonProperty("email") - final String email, - - @JsonProperty("status_callback") - final URI statusCallback, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("regulation_sid") final String regulationSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("status") final Bundle.Status status, + @JsonProperty("valid_until") final String validUntil, + @JsonProperty("email") final String email, + @JsonProperty("status_callback") final URI statusCallback, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.sid = sid; this.accountSid = accountSid; @@ -247,46 +233,57 @@ private Bundle( this.links = links; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getRegulationSid() { - return this.regulationSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final Bundle.Status getStatus() { - return this.status; - } - public final ZonedDateTime getValidUntil() { - return this.validUntil; - } - public final String getEmail() { - return this.email; - } - public final URI getStatusCallback() { - return this.statusCallback; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getRegulationSid() { + return this.regulationSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final Bundle.Status getStatus() { + return this.status; + } + + public final ZonedDateTime getValidUntil() { + return this.validUntil; + } + + public final String getEmail() { + return this.email; + } + + public final URI getStatusCallback() { + return this.statusCallback; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -296,13 +293,37 @@ public boolean equals(final Object o) { Bundle other = (Bundle) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(regulationSid, other.regulationSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(status, other.status) && Objects.equals(validUntil, other.validUntil) && Objects.equals(email, other.email) && Objects.equals(statusCallback, other.statusCallback) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(regulationSid, other.regulationSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(status, other.status) && + Objects.equals(validUntil, other.validUntil) && + Objects.equals(email, other.email) && + Objects.equals(statusCallback, other.statusCallback) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, regulationSid, friendlyName, status, validUntil, email, statusCallback, dateCreated, dateUpdated, url, links); + return Objects.hash( + sid, + accountSid, + regulationSid, + friendlyName, + status, + validUntil, + email, + statusCallback, + dateCreated, + dateUpdated, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/BundleCreator.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/BundleCreator.java index b91d42af12..a95bd4df9f 100644 --- a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/BundleCreator.java +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/BundleCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.numbers.v2.regulatorycompliance; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -25,12 +26,10 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.net.URI; - - - import java.net.URI; -public class BundleCreator extends Creator{ +public class BundleCreator extends Creator { + private String friendlyName; private String email; private URI statusCallback; @@ -44,57 +43,73 @@ public BundleCreator(final String friendlyName, final String email) { this.email = email; } - public BundleCreator setFriendlyName(final String friendlyName){ + public BundleCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public BundleCreator setEmail(final String email){ + + public BundleCreator setEmail(final String email) { this.email = email; return this; } - public BundleCreator setStatusCallback(final URI statusCallback){ + + public BundleCreator setStatusCallback(final URI statusCallback) { this.statusCallback = statusCallback; return this; } - public BundleCreator setStatusCallback(final String statusCallback){ + public BundleCreator setStatusCallback(final String statusCallback) { return setStatusCallback(Promoter.uriFromString(statusCallback)); } - public BundleCreator setRegulationSid(final String regulationSid){ + + public BundleCreator setRegulationSid(final String regulationSid) { this.regulationSid = regulationSid; return this; } - public BundleCreator setIsoCountry(final String isoCountry){ + + public BundleCreator setIsoCountry(final String isoCountry) { this.isoCountry = isoCountry; return this; } - public BundleCreator setEndUserType(final Bundle.EndUserType endUserType){ + + public BundleCreator setEndUserType(final Bundle.EndUserType endUserType) { this.endUserType = endUserType; return this; } - public BundleCreator setNumberType(final String numberType){ + + public BundleCreator setNumberType(final String numberType) { this.numberType = numberType; return this; } @Override - public Bundle create(final TwilioRestClient client){ + public Bundle create(final TwilioRestClient client) { String path = "/v2/RegulatoryCompliance/Bundles"; - path = path.replace("{"+"FriendlyName"+"}", this.friendlyName.toString()); - path = path.replace("{"+"Email"+"}", this.email.toString()); + path = + path.replace( + "{" + "FriendlyName" + "}", + this.friendlyName.toString() + ); + path = path.replace("{" + "Email" + "}", this.email.toString()); Request request = new Request( HttpMethod.POST, Domains.NUMBERS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Bundle creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Bundle creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -103,34 +118,28 @@ public Bundle create(final TwilioRestClient client){ return Bundle.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (email != null) { request.addPostParam("Email", email); - } if (statusCallback != null) { request.addPostParam("StatusCallback", statusCallback.toString()); - } if (regulationSid != null) { request.addPostParam("RegulationSid", regulationSid); - } if (isoCountry != null) { request.addPostParam("IsoCountry", isoCountry); - } if (endUserType != null) { request.addPostParam("EndUserType", endUserType.toString()); - } if (numberType != null) { request.addPostParam("NumberType", numberType); - } } } diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/BundleDeleter.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/BundleDeleter.java index d1143b1863..4ca0e1a6a4 100644 --- a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/BundleDeleter.java +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/BundleDeleter.java @@ -24,21 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class BundleDeleter extends Deleter { + private String pathSid; - public BundleDeleter(final String pathSid){ + public BundleDeleter(final String pathSid) { this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v2/RegulatoryCompliance/Bundles/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -48,9 +46,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Bundle delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Bundle delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/BundleFetcher.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/BundleFetcher.java index 92e4465ecf..94b171ad4b 100644 --- a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/BundleFetcher.java +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/BundleFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class BundleFetcher extends Fetcher { + private String pathSid; - public BundleFetcher(final String pathSid){ + public BundleFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public Bundle fetch(final TwilioRestClient client) { String path = "/v2/RegulatoryCompliance/Bundles/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,9 +46,14 @@ public Bundle fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Bundle fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Bundle fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/BundleReader.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/BundleReader.java index 7f0c3e46cb..80abfc1abc 100644 --- a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/BundleReader.java +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/BundleReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.numbers.v2.regulatorycompliance; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,13 +25,11 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; - - public class BundleReader extends Reader { + private Bundle.Status status; private String friendlyName; private String regulationSid; @@ -44,54 +43,70 @@ public class BundleReader extends Reader { private ZonedDateTime validUntilDateAfter; private Integer pageSize; - public BundleReader(){ - } + public BundleReader() {} - public BundleReader setStatus(final Bundle.Status status){ + public BundleReader setStatus(final Bundle.Status status) { this.status = status; return this; } - public BundleReader setFriendlyName(final String friendlyName){ + + public BundleReader setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public BundleReader setRegulationSid(final String regulationSid){ + + public BundleReader setRegulationSid(final String regulationSid) { this.regulationSid = regulationSid; return this; } - public BundleReader setIsoCountry(final String isoCountry){ + + public BundleReader setIsoCountry(final String isoCountry) { this.isoCountry = isoCountry; return this; } - public BundleReader setNumberType(final String numberType){ + + public BundleReader setNumberType(final String numberType) { this.numberType = numberType; return this; } - public BundleReader setHasValidUntilDate(final Boolean hasValidUntilDate){ + + public BundleReader setHasValidUntilDate(final Boolean hasValidUntilDate) { this.hasValidUntilDate = hasValidUntilDate; return this; } - public BundleReader setSortBy(final Bundle.SortBy sortBy){ + + public BundleReader setSortBy(final Bundle.SortBy sortBy) { this.sortBy = sortBy; return this; } - public BundleReader setSortDirection(final Bundle.SortDirection sortDirection){ + + public BundleReader setSortDirection( + final Bundle.SortDirection sortDirection + ) { this.sortDirection = sortDirection; return this; } - public BundleReader setValidUntilDate(final ZonedDateTime validUntilDate){ + + public BundleReader setValidUntilDate(final ZonedDateTime validUntilDate) { this.validUntilDate = validUntilDate; return this; } - public BundleReader setValidUntilDateBefore(final ZonedDateTime validUntilDateBefore){ + + public BundleReader setValidUntilDateBefore( + final ZonedDateTime validUntilDateBefore + ) { this.validUntilDateBefore = validUntilDateBefore; return this; } - public BundleReader setValidUntilDateAfter(final ZonedDateTime validUntilDateAfter){ + + public BundleReader setValidUntilDateAfter( + final ZonedDateTime validUntilDateAfter + ) { this.validUntilDateAfter = validUntilDateAfter; return this; } - public BundleReader setPageSize(final Integer pageSize){ + + public BundleReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -114,13 +129,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Bundle read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Bundle read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -136,7 +159,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.NUMBERS.toString()) @@ -144,9 +170,11 @@ public Page previousPage(final Page page, final TwilioRestClient return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.NUMBERS.toString()) @@ -155,59 +183,66 @@ public Page nextPage(final Page page, final TwilioRestClient cli } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (status != null) { - request.addQueryParam("Status", status.toString()); } if (friendlyName != null) { - request.addQueryParam("FriendlyName", friendlyName); } if (regulationSid != null) { - request.addQueryParam("RegulationSid", regulationSid); } if (isoCountry != null) { - request.addQueryParam("IsoCountry", isoCountry); } if (numberType != null) { - request.addQueryParam("NumberType", numberType); } if (hasValidUntilDate != null) { - - request.addQueryParam("HasValidUntilDate", hasValidUntilDate.toString()); + request.addQueryParam( + "HasValidUntilDate", + hasValidUntilDate.toString() + ); } if (sortBy != null) { - request.addQueryParam("SortBy", sortBy.toString()); } if (sortDirection != null) { - request.addQueryParam("SortDirection", sortDirection.toString()); } if (validUntilDate != null) { - request.addQueryParam("ValidUntilDate", validUntilDate.format(DateTimeFormatter.ofPattern(Request.QUERY_STRING_DATE_TIME_FORMAT))); - } - else if (validUntilDateAfter != null || validUntilDateBefore != null) { - request.addQueryDateTimeRange("ValidUntilDate", validUntilDateAfter, validUntilDateBefore); + request.addQueryParam( + "ValidUntilDate", + validUntilDate.format( + DateTimeFormatter.ofPattern( + Request.QUERY_STRING_DATE_TIME_FORMAT + ) + ) + ); + } else if ( + validUntilDateAfter != null || validUntilDateBefore != null + ) { + request.addQueryDateTimeRange( + "ValidUntilDate", + validUntilDateAfter, + validUntilDateBefore + ); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/BundleUpdater.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/BundleUpdater.java index 89451b0ff1..c2a5fc2e28 100644 --- a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/BundleUpdater.java +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/BundleUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.numbers.v2.regulatorycompliance; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -24,60 +25,67 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.net.URI; +public class BundleUpdater extends Updater { - -public class BundleUpdater extends Updater{ private String pathSid; private Bundle.Status status; private URI statusCallback; private String friendlyName; private String email; - public BundleUpdater(final String pathSid){ + public BundleUpdater(final String pathSid) { this.pathSid = pathSid; } - public BundleUpdater setStatus(final Bundle.Status status){ + public BundleUpdater setStatus(final Bundle.Status status) { this.status = status; return this; } - public BundleUpdater setStatusCallback(final URI statusCallback){ + + public BundleUpdater setStatusCallback(final URI statusCallback) { this.statusCallback = statusCallback; return this; } - public BundleUpdater setStatusCallback(final String statusCallback){ + public BundleUpdater setStatusCallback(final String statusCallback) { return setStatusCallback(Promoter.uriFromString(statusCallback)); } - public BundleUpdater setFriendlyName(final String friendlyName){ + + public BundleUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public BundleUpdater setEmail(final String email){ + + public BundleUpdater setEmail(final String email) { this.email = email; return this; } @Override - public Bundle update(final TwilioRestClient client){ + public Bundle update(final TwilioRestClient client) { String path = "/v2/RegulatoryCompliance/Bundles/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.NUMBERS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Bundle update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Bundle update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -86,22 +94,19 @@ public Bundle update(final TwilioRestClient client){ return Bundle.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (status != null) { request.addPostParam("Status", status.toString()); - } if (statusCallback != null) { request.addPostParam("StatusCallback", statusCallback.toString()); - } if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (email != null) { request.addPostParam("Email", email); - } } } diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/EndUser.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/EndUser.java index 728ac4e963..f620b19e3a 100644 --- a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/EndUser.java +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/EndUser.java @@ -24,55 +24,57 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class EndUser extends Resource { + private static final long serialVersionUID = 94888387451102L; - public static EndUserCreator creator(final String friendlyName, final EndUser.Type type){ + public static EndUserCreator creator( + final String friendlyName, + final EndUser.Type type + ) { return new EndUserCreator(friendlyName, type); } - public static EndUserDeleter deleter(final String pathSid){ + public static EndUserDeleter deleter(final String pathSid) { return new EndUserDeleter(pathSid); } - public static EndUserFetcher fetcher(final String pathSid){ + public static EndUserFetcher fetcher(final String pathSid) { return new EndUserFetcher(pathSid); } - public static EndUserReader reader(){ + public static EndUserReader reader() { return new EndUserReader(); } - public static EndUserUpdater updater(final String pathSid){ + public static EndUserUpdater updater(final String pathSid) { return new EndUserUpdater(pathSid); } /** - * Converts a JSON String into a EndUser object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return EndUser object represented by the provided JSON - */ - public static EndUser fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a EndUser object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return EndUser object represented by the provided JSON + */ + public static EndUser fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, EndUser.class); @@ -84,14 +86,17 @@ public static EndUser fromJson(final String json, final ObjectMapper objectMappe } /** - * Converts a JSON InputStream into a EndUser object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return EndUser object represented by the provided JSON - */ - public static EndUser fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a EndUser object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return EndUser object represented by the provided JSON + */ + public static EndUser fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, EndUser.class); @@ -101,6 +106,7 @@ public static EndUser fromJson(final InputStream json, final ObjectMapper object throw new ApiConnectionException(e.getMessage(), e); } } + public enum Type { INDIVIDUAL("individual"), BUSINESS("business"); @@ -132,29 +138,14 @@ public static Type forValue(final String value) { @JsonCreator private EndUser( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("type") - final EndUser.Type type, - - @JsonProperty("attributes") - final Map attributes, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("type") final EndUser.Type type, + @JsonProperty("attributes") final Map attributes, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url ) { this.sid = sid; this.accountSid = accountSid; @@ -166,34 +157,41 @@ private EndUser( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final EndUser.Type getType() { - return this.type; - } - public final Map getAttributes() { - return this.attributes; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final EndUser.Type getType() { + return this.type; + } + + public final Map getAttributes() { + return this.attributes; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -203,13 +201,29 @@ public boolean equals(final Object o) { EndUser other = (EndUser) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(type, other.type) && Objects.equals(attributes, other.attributes) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(type, other.type) && + Objects.equals(attributes, other.attributes) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, friendlyName, type, attributes, dateCreated, dateUpdated, url); + return Objects.hash( + sid, + accountSid, + friendlyName, + type, + attributes, + dateCreated, + dateUpdated, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/EndUserCreator.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/EndUserCreator.java index f24173967a..4238c4f00b 100644 --- a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/EndUserCreator.java +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/EndUserCreator.java @@ -15,8 +15,10 @@ package com.twilio.rest.numbers.v2.regulatorycompliance; import com.twilio.base.Creator; -import com.twilio.exception.ApiConnectionException; +import com.twilio.constant.EnumConstants; +import com.twilio.converter.Converter; import com.twilio.converter.Converter; +import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; @@ -25,13 +27,10 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.util.Map; -import com.twilio.converter.Converter; - import java.util.Map; +public class EndUserCreator extends Creator { - -public class EndUserCreator extends Creator{ private String friendlyName; private EndUser.Type type; private Map attributes; @@ -41,37 +40,49 @@ public EndUserCreator(final String friendlyName, final EndUser.Type type) { this.type = type; } - public EndUserCreator setFriendlyName(final String friendlyName){ + public EndUserCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public EndUserCreator setType(final EndUser.Type type){ + + public EndUserCreator setType(final EndUser.Type type) { this.type = type; return this; } - public EndUserCreator setAttributes(final Map attributes){ + + public EndUserCreator setAttributes(final Map attributes) { this.attributes = attributes; return this; } @Override - public EndUser create(final TwilioRestClient client){ + public EndUser create(final TwilioRestClient client) { String path = "/v2/RegulatoryCompliance/EndUsers"; - path = path.replace("{"+"FriendlyName"+"}", this.friendlyName.toString()); - path = path.replace("{"+"Type"+"}", this.type.toString()); + path = + path.replace( + "{" + "FriendlyName" + "}", + this.friendlyName.toString() + ); + path = path.replace("{" + "Type" + "}", this.type.toString()); Request request = new Request( HttpMethod.POST, Domains.NUMBERS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("EndUser creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "EndUser creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -80,18 +91,16 @@ public EndUser create(final TwilioRestClient client){ return EndUser.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (type != null) { request.addPostParam("Type", type.toString()); - } if (attributes != null) { - request.addPostParam("Attributes", Converter.mapToJson(attributes)); - + request.addPostParam("Attributes", Converter.mapToJson(attributes)); } } } diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/EndUserDeleter.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/EndUserDeleter.java index 046e0b8ec5..4dd97b3b09 100644 --- a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/EndUserDeleter.java +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/EndUserDeleter.java @@ -24,21 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class EndUserDeleter extends Deleter { + private String pathSid; - public EndUserDeleter(final String pathSid){ + public EndUserDeleter(final String pathSid) { this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v2/RegulatoryCompliance/EndUsers/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -48,9 +46,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("EndUser delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "EndUser delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/EndUserFetcher.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/EndUserFetcher.java index 9d7df06f5e..f9b80f5229 100644 --- a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/EndUserFetcher.java +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/EndUserFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class EndUserFetcher extends Fetcher { + private String pathSid; - public EndUserFetcher(final String pathSid){ + public EndUserFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public EndUser fetch(final TwilioRestClient client) { String path = "/v2/RegulatoryCompliance/EndUsers/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,9 +46,14 @@ public EndUser fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("EndUser fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "EndUser fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/EndUserReader.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/EndUserReader.java index 4aeda14c40..3d0c655e9e 100644 --- a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/EndUserReader.java +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/EndUserReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.numbers.v2.regulatorycompliance; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,17 +25,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class EndUserReader extends Reader { + private Integer pageSize; - public EndUserReader(){ - } + public EndUserReader() {} - public EndUserReader setPageSize(final Integer pageSize){ + public EndUserReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -57,13 +55,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("EndUser read failed: Unable to connect to server"); + throw new ApiConnectionException( + "EndUser read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -79,7 +85,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reques } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.NUMBERS.toString()) @@ -87,9 +96,11 @@ public Page previousPage(final Page page, final TwilioRestClie return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.NUMBERS.toString()) @@ -98,21 +109,21 @@ public Page nextPage(final Page page, final TwilioRestClient c } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/EndUserType.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/EndUserType.java index 79d55418d7..ecbfa77468 100644 --- a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/EndUserType.java +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/EndUserType.java @@ -22,43 +22,42 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.List; import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class EndUserType extends Resource { + private static final long serialVersionUID = 67038001521206L; - public static EndUserTypeFetcher fetcher(final String pathSid){ + public static EndUserTypeFetcher fetcher(final String pathSid) { return new EndUserTypeFetcher(pathSid); } - public static EndUserTypeReader reader(){ + public static EndUserTypeReader reader() { return new EndUserTypeReader(); } /** - * Converts a JSON String into a EndUserType object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return EndUserType object represented by the provided JSON - */ - public static EndUserType fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a EndUserType object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return EndUserType object represented by the provided JSON + */ + public static EndUserType fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, EndUserType.class); @@ -70,14 +69,17 @@ public static EndUserType fromJson(final String json, final ObjectMapper objectM } /** - * Converts a JSON InputStream into a EndUserType object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return EndUserType object represented by the provided JSON - */ - public static EndUserType fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a EndUserType object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return EndUserType object represented by the provided JSON + */ + public static EndUserType fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, EndUserType.class); @@ -96,20 +98,11 @@ public static EndUserType fromJson(final InputStream json, final ObjectMapper ob @JsonCreator private EndUserType( - @JsonProperty("sid") - final String sid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("machine_name") - final String machineName, - - @JsonProperty("fields") - final List> fields, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("machine_name") final String machineName, + @JsonProperty("fields") final List> fields, + @JsonProperty("url") final URI url ) { this.sid = sid; this.friendlyName = friendlyName; @@ -118,25 +111,29 @@ private EndUserType( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getMachineName() { - return this.machineName; - } - public final List> getFields() { - return this.fields; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getMachineName() { + return this.machineName; + } + + public final List> getFields() { + return this.fields; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -146,13 +143,17 @@ public boolean equals(final Object o) { EndUserType other = (EndUserType) o; - return Objects.equals(sid, other.sid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(machineName, other.machineName) && Objects.equals(fields, other.fields) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(machineName, other.machineName) && + Objects.equals(fields, other.fields) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { return Objects.hash(sid, friendlyName, machineName, fields, url); } - } - diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/EndUserTypeFetcher.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/EndUserTypeFetcher.java index 0431877cd5..0e4df0015a 100644 --- a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/EndUserTypeFetcher.java +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/EndUserTypeFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class EndUserTypeFetcher extends Fetcher { + private String pathSid; - public EndUserTypeFetcher(final String pathSid){ + public EndUserTypeFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public EndUserType fetch(final TwilioRestClient client) { String path = "/v2/RegulatoryCompliance/EndUserTypes/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,15 +46,23 @@ public EndUserType fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("EndUserType fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "EndUserType fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return EndUserType.fromJson(response.getStream(), client.getObjectMapper()); + return EndUserType.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/EndUserTypeReader.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/EndUserTypeReader.java index ea538be270..22573d6a0d 100644 --- a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/EndUserTypeReader.java +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/EndUserTypeReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.numbers.v2.regulatorycompliance; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,17 +25,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class EndUserTypeReader extends Reader { + private Integer pageSize; - public EndUserTypeReader(){ - } + public EndUserTypeReader() {} - public EndUserTypeReader setPageSize(final Integer pageSize){ + public EndUserTypeReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -57,13 +55,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("EndUserType read failed: Unable to connect to server"); + throw new ApiConnectionException( + "EndUserType read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -79,7 +85,10 @@ private Page pageForRequest(final TwilioRestClient client, final Re } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.NUMBERS.toString()) @@ -87,9 +96,11 @@ public Page previousPage(final Page page, final Twilio return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.NUMBERS.toString()) @@ -98,21 +109,21 @@ public Page nextPage(final Page page, final TwilioRest } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/EndUserUpdater.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/EndUserUpdater.java index 6f18111132..f43163a918 100644 --- a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/EndUserUpdater.java +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/EndUserUpdater.java @@ -15,8 +15,9 @@ package com.twilio.rest.numbers.v2.regulatorycompliance; import com.twilio.base.Updater; -import com.twilio.exception.ApiConnectionException; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Converter; +import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; @@ -24,46 +25,51 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - import java.util.Map; +public class EndUserUpdater extends Updater { -public class EndUserUpdater extends Updater{ private String pathSid; private String friendlyName; private Map attributes; - public EndUserUpdater(final String pathSid){ + public EndUserUpdater(final String pathSid) { this.pathSid = pathSid; } - public EndUserUpdater setFriendlyName(final String friendlyName){ + public EndUserUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public EndUserUpdater setAttributes(final Map attributes){ + + public EndUserUpdater setAttributes(final Map attributes) { this.attributes = attributes; return this; } @Override - public EndUser update(final TwilioRestClient client){ + public EndUser update(final TwilioRestClient client) { String path = "/v2/RegulatoryCompliance/EndUsers/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.NUMBERS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("EndUser update failed: Unable to connect to server"); + throw new ApiConnectionException( + "EndUser update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -72,14 +78,13 @@ public EndUser update(final TwilioRestClient client){ return EndUser.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (attributes != null) { - request.addPostParam("Attributes", Converter.mapToJson(attributes)); - + request.addPostParam("Attributes", Converter.mapToJson(attributes)); } } } diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/Regulation.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/Regulation.java index 894c1156cc..773f5920f3 100644 --- a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/Regulation.java +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/Regulation.java @@ -23,42 +23,41 @@ import com.twilio.base.Resource; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Regulation extends Resource { + private static final long serialVersionUID = 10727481359923L; - public static RegulationFetcher fetcher(final String pathSid){ + public static RegulationFetcher fetcher(final String pathSid) { return new RegulationFetcher(pathSid); } - public static RegulationReader reader(){ + public static RegulationReader reader() { return new RegulationReader(); } /** - * Converts a JSON String into a Regulation object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Regulation object represented by the provided JSON - */ - public static Regulation fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Regulation object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Regulation object represented by the provided JSON + */ + public static Regulation fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Regulation.class); @@ -70,14 +69,17 @@ public static Regulation fromJson(final String json, final ObjectMapper objectMa } /** - * Converts a JSON InputStream into a Regulation object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Regulation object represented by the provided JSON - */ - public static Regulation fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Regulation object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Regulation object represented by the provided JSON + */ + public static Regulation fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Regulation.class); @@ -87,6 +89,7 @@ public static Regulation fromJson(final InputStream json, final ObjectMapper obj throw new ApiConnectionException(e.getMessage(), e); } } + public enum EndUserType { INDIVIDUAL("individual"), BUSINESS("business"); @@ -117,26 +120,13 @@ public static EndUserType forValue(final String value) { @JsonCreator private Regulation( - @JsonProperty("sid") - final String sid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("iso_country") - final String isoCountry, - - @JsonProperty("number_type") - final String numberType, - - @JsonProperty("end_user_type") - final Regulation.EndUserType endUserType, - - @JsonProperty("requirements") - final Map requirements, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("iso_country") final String isoCountry, + @JsonProperty("number_type") final String numberType, + @JsonProperty("end_user_type") final Regulation.EndUserType endUserType, + @JsonProperty("requirements") final Map requirements, + @JsonProperty("url") final URI url ) { this.sid = sid; this.friendlyName = friendlyName; @@ -147,31 +137,37 @@ private Regulation( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getIsoCountry() { - return this.isoCountry; - } - public final String getNumberType() { - return this.numberType; - } - public final Regulation.EndUserType getEndUserType() { - return this.endUserType; - } - public final Map getRequirements() { - return this.requirements; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getIsoCountry() { + return this.isoCountry; + } + + public final String getNumberType() { + return this.numberType; + } + + public final Regulation.EndUserType getEndUserType() { + return this.endUserType; + } + + public final Map getRequirements() { + return this.requirements; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -181,13 +177,27 @@ public boolean equals(final Object o) { Regulation other = (Regulation) o; - return Objects.equals(sid, other.sid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(isoCountry, other.isoCountry) && Objects.equals(numberType, other.numberType) && Objects.equals(endUserType, other.endUserType) && Objects.equals(requirements, other.requirements) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(isoCountry, other.isoCountry) && + Objects.equals(numberType, other.numberType) && + Objects.equals(endUserType, other.endUserType) && + Objects.equals(requirements, other.requirements) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, friendlyName, isoCountry, numberType, endUserType, requirements, url); + return Objects.hash( + sid, + friendlyName, + isoCountry, + numberType, + endUserType, + requirements, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/RegulationFetcher.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/RegulationFetcher.java index 0fa5909bb9..9a9f376185 100644 --- a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/RegulationFetcher.java +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/RegulationFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class RegulationFetcher extends Fetcher { + private String pathSid; - public RegulationFetcher(final String pathSid){ + public RegulationFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public Regulation fetch(final TwilioRestClient client) { String path = "/v2/RegulatoryCompliance/Regulations/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,15 +46,23 @@ public Regulation fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Regulation fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Regulation fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Regulation.fromJson(response.getStream(), client.getObjectMapper()); + return Regulation.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/RegulationReader.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/RegulationReader.java index f62c16623f..5ebe081cab 100644 --- a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/RegulationReader.java +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/RegulationReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.numbers.v2.regulatorycompliance; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,32 +25,34 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class RegulationReader extends Reader { + private Regulation.EndUserType endUserType; private String isoCountry; private String numberType; private Integer pageSize; - public RegulationReader(){ - } + public RegulationReader() {} - public RegulationReader setEndUserType(final Regulation.EndUserType endUserType){ + public RegulationReader setEndUserType( + final Regulation.EndUserType endUserType + ) { this.endUserType = endUserType; return this; } - public RegulationReader setIsoCountry(final String isoCountry){ + + public RegulationReader setIsoCountry(final String isoCountry) { this.isoCountry = isoCountry; return this; } - public RegulationReader setNumberType(final String numberType){ + + public RegulationReader setNumberType(final String numberType) { this.numberType = numberType; return this; } - public RegulationReader setPageSize(final Integer pageSize){ + + public RegulationReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -72,13 +75,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Regulation read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Regulation read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -94,7 +105,10 @@ private Page pageForRequest(final TwilioRestClient client, final Req } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.NUMBERS.toString()) @@ -102,9 +116,11 @@ public Page previousPage(final Page page, final TwilioRe return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.NUMBERS.toString()) @@ -113,33 +129,30 @@ public Page nextPage(final Page page, final TwilioRestCl } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (endUserType != null) { - request.addQueryParam("EndUserType", endUserType.toString()); } if (isoCountry != null) { - request.addQueryParam("IsoCountry", isoCountry); } if (numberType != null) { - request.addQueryParam("NumberType", numberType); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/SupportingDocument.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/SupportingDocument.java index 1c5918f45f..08614ba302 100644 --- a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/SupportingDocument.java +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/SupportingDocument.java @@ -24,55 +24,57 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class SupportingDocument extends Resource { + private static final long serialVersionUID = 24162340566274L; - public static SupportingDocumentCreator creator(final String friendlyName, final String type){ + public static SupportingDocumentCreator creator( + final String friendlyName, + final String type + ) { return new SupportingDocumentCreator(friendlyName, type); } - public static SupportingDocumentDeleter deleter(final String pathSid){ + public static SupportingDocumentDeleter deleter(final String pathSid) { return new SupportingDocumentDeleter(pathSid); } - public static SupportingDocumentFetcher fetcher(final String pathSid){ + public static SupportingDocumentFetcher fetcher(final String pathSid) { return new SupportingDocumentFetcher(pathSid); } - public static SupportingDocumentReader reader(){ + public static SupportingDocumentReader reader() { return new SupportingDocumentReader(); } - public static SupportingDocumentUpdater updater(final String pathSid){ + public static SupportingDocumentUpdater updater(final String pathSid) { return new SupportingDocumentUpdater(pathSid); } /** - * Converts a JSON String into a SupportingDocument object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return SupportingDocument object represented by the provided JSON - */ - public static SupportingDocument fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a SupportingDocument object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return SupportingDocument object represented by the provided JSON + */ + public static SupportingDocument fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SupportingDocument.class); @@ -84,14 +86,17 @@ public static SupportingDocument fromJson(final String json, final ObjectMapper } /** - * Converts a JSON InputStream into a SupportingDocument object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return SupportingDocument object represented by the provided JSON - */ - public static SupportingDocument fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a SupportingDocument object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return SupportingDocument object represented by the provided JSON + */ + public static SupportingDocument fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SupportingDocument.class); @@ -101,6 +106,7 @@ public static SupportingDocument fromJson(final InputStream json, final ObjectMa throw new ApiConnectionException(e.getMessage(), e); } } + public enum Status { DRAFT("draft"), PENDING_REVIEW("pending-review"), @@ -139,38 +145,17 @@ public static Status forValue(final String value) { @JsonCreator private SupportingDocument( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("mime_type") - final String mimeType, - - @JsonProperty("status") - final SupportingDocument.Status status, - - @JsonProperty("failure_reason") - final String failureReason, - - @JsonProperty("type") - final String type, - - @JsonProperty("attributes") - final Map attributes, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("mime_type") final String mimeType, + @JsonProperty("status") final SupportingDocument.Status status, + @JsonProperty("failure_reason") final String failureReason, + @JsonProperty("type") final String type, + @JsonProperty("attributes") final Map attributes, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url ) { this.sid = sid; this.accountSid = accountSid; @@ -185,43 +170,53 @@ private SupportingDocument( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getMimeType() { - return this.mimeType; - } - public final SupportingDocument.Status getStatus() { - return this.status; - } - public final String getFailureReason() { - return this.failureReason; - } - public final String getType() { - return this.type; - } - public final Map getAttributes() { - return this.attributes; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getMimeType() { + return this.mimeType; + } + + public final SupportingDocument.Status getStatus() { + return this.status; + } + + public final String getFailureReason() { + return this.failureReason; + } + + public final String getType() { + return this.type; + } + + public final Map getAttributes() { + return this.attributes; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -231,13 +226,35 @@ public boolean equals(final Object o) { SupportingDocument other = (SupportingDocument) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(mimeType, other.mimeType) && Objects.equals(status, other.status) && Objects.equals(failureReason, other.failureReason) && Objects.equals(type, other.type) && Objects.equals(attributes, other.attributes) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(mimeType, other.mimeType) && + Objects.equals(status, other.status) && + Objects.equals(failureReason, other.failureReason) && + Objects.equals(type, other.type) && + Objects.equals(attributes, other.attributes) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, friendlyName, mimeType, status, failureReason, type, attributes, dateCreated, dateUpdated, url); + return Objects.hash( + sid, + accountSid, + friendlyName, + mimeType, + status, + failureReason, + type, + attributes, + dateCreated, + dateUpdated, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/SupportingDocumentCreator.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/SupportingDocumentCreator.java index d01831006b..8e4cf5f3ae 100644 --- a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/SupportingDocumentCreator.java +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/SupportingDocumentCreator.java @@ -15,8 +15,10 @@ package com.twilio.rest.numbers.v2.regulatorycompliance; import com.twilio.base.Creator; -import com.twilio.exception.ApiConnectionException; +import com.twilio.constant.EnumConstants; +import com.twilio.converter.Converter; import com.twilio.converter.Converter; +import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; @@ -25,73 +27,90 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.util.Map; -import com.twilio.converter.Converter; - import java.util.Map; +public class SupportingDocumentCreator extends Creator { - -public class SupportingDocumentCreator extends Creator{ private String friendlyName; private String type; private Map attributes; - public SupportingDocumentCreator(final String friendlyName, final String type) { + public SupportingDocumentCreator( + final String friendlyName, + final String type + ) { this.friendlyName = friendlyName; this.type = type; } - public SupportingDocumentCreator setFriendlyName(final String friendlyName){ + public SupportingDocumentCreator setFriendlyName( + final String friendlyName + ) { this.friendlyName = friendlyName; return this; } - public SupportingDocumentCreator setType(final String type){ + + public SupportingDocumentCreator setType(final String type) { this.type = type; return this; } - public SupportingDocumentCreator setAttributes(final Map attributes){ + + public SupportingDocumentCreator setAttributes( + final Map attributes + ) { this.attributes = attributes; return this; } @Override - public SupportingDocument create(final TwilioRestClient client){ + public SupportingDocument create(final TwilioRestClient client) { String path = "/v2/RegulatoryCompliance/SupportingDocuments"; - path = path.replace("{"+"FriendlyName"+"}", this.friendlyName.toString()); - path = path.replace("{"+"Type"+"}", this.type.toString()); + path = + path.replace( + "{" + "FriendlyName" + "}", + this.friendlyName.toString() + ); + path = path.replace("{" + "Type" + "}", this.type.toString()); Request request = new Request( HttpMethod.POST, Domains.NUMBERS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SupportingDocument creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "SupportingDocument creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return SupportingDocument.fromJson(response.getStream(), client.getObjectMapper()); + return SupportingDocument.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (type != null) { request.addPostParam("Type", type); - } if (attributes != null) { - request.addPostParam("Attributes", Converter.mapToJson(attributes)); - + request.addPostParam("Attributes", Converter.mapToJson(attributes)); } } } diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/SupportingDocumentDeleter.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/SupportingDocumentDeleter.java index 7d1489323f..5cfb18e37a 100644 --- a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/SupportingDocumentDeleter.java +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/SupportingDocumentDeleter.java @@ -24,21 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class SupportingDocumentDeleter extends Deleter { + private String pathSid; - public SupportingDocumentDeleter(final String pathSid){ + public SupportingDocumentDeleter(final String pathSid) { this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v2/RegulatoryCompliance/SupportingDocuments/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -48,9 +46,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SupportingDocument delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "SupportingDocument delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/SupportingDocumentFetcher.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/SupportingDocumentFetcher.java index f22a3e9892..b9e503b3f6 100644 --- a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/SupportingDocumentFetcher.java +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/SupportingDocumentFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class SupportingDocumentFetcher extends Fetcher { + private String pathSid; - public SupportingDocumentFetcher(final String pathSid){ + public SupportingDocumentFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public SupportingDocument fetch(final TwilioRestClient client) { String path = "/v2/RegulatoryCompliance/SupportingDocuments/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,15 +46,23 @@ public SupportingDocument fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SupportingDocument fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "SupportingDocument fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return SupportingDocument.fromJson(response.getStream(), client.getObjectMapper()); + return SupportingDocument.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/SupportingDocumentReader.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/SupportingDocumentReader.java index 93105298be..bd20fb1548 100644 --- a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/SupportingDocumentReader.java +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/SupportingDocumentReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.numbers.v2.regulatorycompliance; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,17 +25,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class SupportingDocumentReader extends Reader { + private Integer pageSize; - public SupportingDocumentReader(){ - } + public SupportingDocumentReader() {} - public SupportingDocumentReader setPageSize(final Integer pageSize){ + public SupportingDocumentReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -57,13 +55,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SupportingDocument read failed: Unable to connect to server"); + throw new ApiConnectionException( + "SupportingDocument read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -79,7 +85,10 @@ private Page pageForRequest(final TwilioRestClient client, f } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.NUMBERS.toString()) @@ -87,9 +96,11 @@ public Page previousPage(final Page page return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.NUMBERS.toString()) @@ -98,21 +109,21 @@ public Page nextPage(final Page page, fi } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/SupportingDocumentType.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/SupportingDocumentType.java index d91ab8a9cc..6e49f965c4 100644 --- a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/SupportingDocumentType.java +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/SupportingDocumentType.java @@ -22,43 +22,42 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.List; import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class SupportingDocumentType extends Resource { + private static final long serialVersionUID = 67038001521206L; - public static SupportingDocumentTypeFetcher fetcher(final String pathSid){ + public static SupportingDocumentTypeFetcher fetcher(final String pathSid) { return new SupportingDocumentTypeFetcher(pathSid); } - public static SupportingDocumentTypeReader reader(){ + public static SupportingDocumentTypeReader reader() { return new SupportingDocumentTypeReader(); } /** - * Converts a JSON String into a SupportingDocumentType object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return SupportingDocumentType object represented by the provided JSON - */ - public static SupportingDocumentType fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a SupportingDocumentType object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return SupportingDocumentType object represented by the provided JSON + */ + public static SupportingDocumentType fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SupportingDocumentType.class); @@ -70,14 +69,17 @@ public static SupportingDocumentType fromJson(final String json, final ObjectMap } /** - * Converts a JSON InputStream into a SupportingDocumentType object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return SupportingDocumentType object represented by the provided JSON - */ - public static SupportingDocumentType fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a SupportingDocumentType object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return SupportingDocumentType object represented by the provided JSON + */ + public static SupportingDocumentType fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SupportingDocumentType.class); @@ -96,20 +98,11 @@ public static SupportingDocumentType fromJson(final InputStream json, final Obje @JsonCreator private SupportingDocumentType( - @JsonProperty("sid") - final String sid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("machine_name") - final String machineName, - - @JsonProperty("fields") - final List> fields, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("machine_name") final String machineName, + @JsonProperty("fields") final List> fields, + @JsonProperty("url") final URI url ) { this.sid = sid; this.friendlyName = friendlyName; @@ -118,25 +111,29 @@ private SupportingDocumentType( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getMachineName() { - return this.machineName; - } - public final List> getFields() { - return this.fields; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getMachineName() { + return this.machineName; + } + + public final List> getFields() { + return this.fields; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -146,13 +143,17 @@ public boolean equals(final Object o) { SupportingDocumentType other = (SupportingDocumentType) o; - return Objects.equals(sid, other.sid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(machineName, other.machineName) && Objects.equals(fields, other.fields) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(machineName, other.machineName) && + Objects.equals(fields, other.fields) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { return Objects.hash(sid, friendlyName, machineName, fields, url); } - } - diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/SupportingDocumentTypeFetcher.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/SupportingDocumentTypeFetcher.java index 0c87afdd17..0a5648dea8 100644 --- a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/SupportingDocumentTypeFetcher.java +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/SupportingDocumentTypeFetcher.java @@ -24,22 +24,20 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class SupportingDocumentTypeFetcher + extends Fetcher { - - -public class SupportingDocumentTypeFetcher extends Fetcher { private String pathSid; - public SupportingDocumentTypeFetcher(final String pathSid){ + public SupportingDocumentTypeFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public SupportingDocumentType fetch(final TwilioRestClient client) { String path = "/v2/RegulatoryCompliance/SupportingDocumentTypes/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,15 +47,23 @@ public SupportingDocumentType fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SupportingDocumentType fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "SupportingDocumentType fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return SupportingDocumentType.fromJson(response.getStream(), client.getObjectMapper()); + return SupportingDocumentType.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/SupportingDocumentTypeReader.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/SupportingDocumentTypeReader.java index 67e99783ce..2f265a98e3 100644 --- a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/SupportingDocumentTypeReader.java +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/SupportingDocumentTypeReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.numbers.v2.regulatorycompliance; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,27 +25,29 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - +public class SupportingDocumentTypeReader + extends Reader { -public class SupportingDocumentTypeReader extends Reader { private Integer pageSize; - public SupportingDocumentTypeReader(){ - } + public SupportingDocumentTypeReader() {} - public SupportingDocumentTypeReader setPageSize(final Integer pageSize){ + public SupportingDocumentTypeReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @Override - public ResourceSet read(final TwilioRestClient client) { + public ResourceSet read( + final TwilioRestClient client + ) { return new ResourceSet<>(this, client, firstPage(client)); } - public Page firstPage(final TwilioRestClient client) { + public Page firstPage( + final TwilioRestClient client + ) { String path = "/v2/RegulatoryCompliance/SupportingDocumentTypes"; Request request = new Request( @@ -57,13 +60,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SupportingDocumentType read failed: Unable to connect to server"); + throw new ApiConnectionException( + "SupportingDocumentType read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -79,7 +90,10 @@ private Page pageForRequest(final TwilioRestClient clien } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.NUMBERS.toString()) @@ -87,9 +101,11 @@ public Page previousPage(final Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.NUMBERS.toString()) @@ -98,21 +114,21 @@ public Page nextPage(final Page } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/SupportingDocumentUpdater.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/SupportingDocumentUpdater.java index 6e86e4db9b..c8f55c5ff9 100644 --- a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/SupportingDocumentUpdater.java +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/SupportingDocumentUpdater.java @@ -15,8 +15,9 @@ package com.twilio.rest.numbers.v2.regulatorycompliance; import com.twilio.base.Updater; -import com.twilio.exception.ApiConnectionException; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Converter; +import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; @@ -24,62 +25,73 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - import java.util.Map; +public class SupportingDocumentUpdater extends Updater { -public class SupportingDocumentUpdater extends Updater{ private String pathSid; private String friendlyName; private Map attributes; - public SupportingDocumentUpdater(final String pathSid){ + public SupportingDocumentUpdater(final String pathSid) { this.pathSid = pathSid; } - public SupportingDocumentUpdater setFriendlyName(final String friendlyName){ + public SupportingDocumentUpdater setFriendlyName( + final String friendlyName + ) { this.friendlyName = friendlyName; return this; } - public SupportingDocumentUpdater setAttributes(final Map attributes){ + + public SupportingDocumentUpdater setAttributes( + final Map attributes + ) { this.attributes = attributes; return this; } @Override - public SupportingDocument update(final TwilioRestClient client){ + public SupportingDocument update(final TwilioRestClient client) { String path = "/v2/RegulatoryCompliance/SupportingDocuments/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.NUMBERS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SupportingDocument update failed: Unable to connect to server"); + throw new ApiConnectionException( + "SupportingDocument update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return SupportingDocument.fromJson(response.getStream(), client.getObjectMapper()); + return SupportingDocument.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (attributes != null) { - request.addPostParam("Attributes", Converter.mapToJson(attributes)); - + request.addPostParam("Attributes", Converter.mapToJson(attributes)); } } } diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/BundleCopy.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/BundleCopy.java index 0fd0321910..68440ad7ce 100644 --- a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/BundleCopy.java +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/BundleCopy.java @@ -24,41 +24,40 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class BundleCopy extends Resource { + private static final long serialVersionUID = 169816383944206L; - public static BundleCopyCreator creator(final String pathBundleSid){ + public static BundleCopyCreator creator(final String pathBundleSid) { return new BundleCopyCreator(pathBundleSid); } - public static BundleCopyReader reader(final String pathBundleSid){ + public static BundleCopyReader reader(final String pathBundleSid) { return new BundleCopyReader(pathBundleSid); } /** - * Converts a JSON String into a BundleCopy object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return BundleCopy object represented by the provided JSON - */ - public static BundleCopy fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a BundleCopy object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return BundleCopy object represented by the provided JSON + */ + public static BundleCopy fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, BundleCopy.class); @@ -70,14 +69,17 @@ public static BundleCopy fromJson(final String json, final ObjectMapper objectMa } /** - * Converts a JSON InputStream into a BundleCopy object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return BundleCopy object represented by the provided JSON - */ - public static BundleCopy fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a BundleCopy object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return BundleCopy object represented by the provided JSON + */ + public static BundleCopy fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, BundleCopy.class); @@ -87,6 +89,7 @@ public static BundleCopy fromJson(final InputStream json, final ObjectMapper obj throw new ApiConnectionException(e.getMessage(), e); } } + public enum Status { DRAFT("draft"), PENDING_REVIEW("pending-review"), @@ -124,35 +127,16 @@ public static Status forValue(final String value) { @JsonCreator private BundleCopy( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("regulation_sid") - final String regulationSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("status") - final BundleCopy.Status status, - - @JsonProperty("valid_until") - final String validUntil, - - @JsonProperty("email") - final String email, - - @JsonProperty("status_callback") - final URI statusCallback, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("regulation_sid") final String regulationSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("status") final BundleCopy.Status status, + @JsonProperty("valid_until") final String validUntil, + @JsonProperty("email") final String email, + @JsonProperty("status_callback") final URI statusCallback, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated ) { this.sid = sid; this.accountSid = accountSid; @@ -166,40 +150,49 @@ private BundleCopy( this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getRegulationSid() { - return this.regulationSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final BundleCopy.Status getStatus() { - return this.status; - } - public final ZonedDateTime getValidUntil() { - return this.validUntil; - } - public final String getEmail() { - return this.email; - } - public final URI getStatusCallback() { - return this.statusCallback; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getRegulationSid() { + return this.regulationSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final BundleCopy.Status getStatus() { + return this.status; + } + + public final ZonedDateTime getValidUntil() { + return this.validUntil; + } + + public final String getEmail() { + return this.email; + } + + public final URI getStatusCallback() { + return this.statusCallback; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -209,13 +202,33 @@ public boolean equals(final Object o) { BundleCopy other = (BundleCopy) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(regulationSid, other.regulationSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(status, other.status) && Objects.equals(validUntil, other.validUntil) && Objects.equals(email, other.email) && Objects.equals(statusCallback, other.statusCallback) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(regulationSid, other.regulationSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(status, other.status) && + Objects.equals(validUntil, other.validUntil) && + Objects.equals(email, other.email) && + Objects.equals(statusCallback, other.statusCallback) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, regulationSid, friendlyName, status, validUntil, email, statusCallback, dateCreated, dateUpdated); + return Objects.hash( + sid, + accountSid, + regulationSid, + friendlyName, + status, + validUntil, + email, + statusCallback, + dateCreated, + dateUpdated + ); } - } - diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/BundleCopyCreator.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/BundleCopyCreator.java index c31b5b77e2..b83f5b2894 100644 --- a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/BundleCopyCreator.java +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/BundleCopyCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.numbers.v2.regulatorycompliance.bundle; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class BundleCopyCreator extends Creator { - - -public class BundleCopyCreator extends Creator{ private String pathBundleSid; private String friendlyName; @@ -35,40 +34,53 @@ public BundleCopyCreator(final String pathBundleSid) { this.pathBundleSid = pathBundleSid; } - public BundleCopyCreator setFriendlyName(final String friendlyName){ + public BundleCopyCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } @Override - public BundleCopy create(final TwilioRestClient client){ + public BundleCopy create(final TwilioRestClient client) { String path = "/v2/RegulatoryCompliance/Bundles/{BundleSid}/Copies"; - path = path.replace("{"+"BundleSid"+"}", this.pathBundleSid.toString()); + path = + path.replace( + "{" + "BundleSid" + "}", + this.pathBundleSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.NUMBERS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("BundleCopy creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "BundleCopy creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return BundleCopy.fromJson(response.getStream(), client.getObjectMapper()); + return BundleCopy.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } } } diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/BundleCopyReader.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/BundleCopyReader.java index 02963c3075..b033700c7e 100644 --- a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/BundleCopyReader.java +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/BundleCopyReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.numbers.v2.regulatorycompliance.bundle; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,19 +25,17 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class BundleCopyReader extends Reader { + private String pathBundleSid; private Integer pageSize; - public BundleCopyReader(final String pathBundleSid){ + public BundleCopyReader(final String pathBundleSid) { this.pathBundleSid = pathBundleSid; } - public BundleCopyReader setPageSize(final Integer pageSize){ + public BundleCopyReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -48,7 +47,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v2/RegulatoryCompliance/Bundles/{BundleSid}/Copies"; - path = path.replace("{"+"BundleSid"+"}", this.pathBundleSid.toString()); + path = + path.replace( + "{" + "BundleSid" + "}", + this.pathBundleSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -60,13 +63,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("BundleCopy read failed: Unable to connect to server"); + throw new ApiConnectionException( + "BundleCopy read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +93,10 @@ private Page pageForRequest(final TwilioRestClient client, final Req } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.NUMBERS.toString()) @@ -90,9 +104,11 @@ public Page previousPage(final Page page, final TwilioRe return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.NUMBERS.toString()) @@ -101,21 +117,21 @@ public Page nextPage(final Page page, final TwilioRestCl } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/Evaluation.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/Evaluation.java index caaf4e54ce..04b5e4ce2d 100644 --- a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/Evaluation.java +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/Evaluation.java @@ -24,48 +24,50 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.List; import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Evaluation extends Resource { + private static final long serialVersionUID = 28761307513576L; - public static EvaluationCreator creator(final String pathBundleSid){ + public static EvaluationCreator creator(final String pathBundleSid) { return new EvaluationCreator(pathBundleSid); } - public static EvaluationFetcher fetcher(final String pathBundleSid, final String pathSid){ + public static EvaluationFetcher fetcher( + final String pathBundleSid, + final String pathSid + ) { return new EvaluationFetcher(pathBundleSid, pathSid); } - public static EvaluationReader reader(final String pathBundleSid){ + public static EvaluationReader reader(final String pathBundleSid) { return new EvaluationReader(pathBundleSid); } /** - * Converts a JSON String into a Evaluation object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Evaluation object represented by the provided JSON - */ - public static Evaluation fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Evaluation object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Evaluation object represented by the provided JSON + */ + public static Evaluation fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Evaluation.class); @@ -77,14 +79,17 @@ public static Evaluation fromJson(final String json, final ObjectMapper objectMa } /** - * Converts a JSON InputStream into a Evaluation object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Evaluation object represented by the provided JSON - */ - public static Evaluation fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Evaluation object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Evaluation object represented by the provided JSON + */ + public static Evaluation fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Evaluation.class); @@ -94,6 +99,7 @@ public static Evaluation fromJson(final InputStream json, final ObjectMapper obj throw new ApiConnectionException(e.getMessage(), e); } } + public enum Status { COMPLIANT("compliant"), NONCOMPLIANT("noncompliant"); @@ -125,29 +131,14 @@ public static Status forValue(final String value) { @JsonCreator private Evaluation( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("regulation_sid") - final String regulationSid, - - @JsonProperty("bundle_sid") - final String bundleSid, - - @JsonProperty("status") - final Evaluation.Status status, - - @JsonProperty("results") - final List> results, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("regulation_sid") final String regulationSid, + @JsonProperty("bundle_sid") final String bundleSid, + @JsonProperty("status") final Evaluation.Status status, + @JsonProperty("results") final List> results, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("url") final URI url ) { this.sid = sid; this.accountSid = accountSid; @@ -159,34 +150,41 @@ private Evaluation( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getRegulationSid() { - return this.regulationSid; - } - public final String getBundleSid() { - return this.bundleSid; - } - public final Evaluation.Status getStatus() { - return this.status; - } - public final List> getResults() { - return this.results; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getRegulationSid() { + return this.regulationSid; + } + + public final String getBundleSid() { + return this.bundleSid; + } + + public final Evaluation.Status getStatus() { + return this.status; + } + + public final List> getResults() { + return this.results; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -196,13 +194,29 @@ public boolean equals(final Object o) { Evaluation other = (Evaluation) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(regulationSid, other.regulationSid) && Objects.equals(bundleSid, other.bundleSid) && Objects.equals(status, other.status) && Objects.equals(results, other.results) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(regulationSid, other.regulationSid) && + Objects.equals(bundleSid, other.bundleSid) && + Objects.equals(status, other.status) && + Objects.equals(results, other.results) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, regulationSid, bundleSid, status, results, dateCreated, url); + return Objects.hash( + sid, + accountSid, + regulationSid, + bundleSid, + status, + results, + dateCreated, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/EvaluationCreator.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/EvaluationCreator.java index d524bf2e3a..87b7813f42 100644 --- a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/EvaluationCreator.java +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/EvaluationCreator.java @@ -24,22 +24,24 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class EvaluationCreator extends Creator { - - -public class EvaluationCreator extends Creator{ private String pathBundleSid; public EvaluationCreator(final String pathBundleSid) { this.pathBundleSid = pathBundleSid; } - @Override - public Evaluation create(final TwilioRestClient client){ - String path = "/v2/RegulatoryCompliance/Bundles/{BundleSid}/Evaluations"; + public Evaluation create(final TwilioRestClient client) { + String path = + "/v2/RegulatoryCompliance/Bundles/{BundleSid}/Evaluations"; - path = path.replace("{"+"BundleSid"+"}", this.pathBundleSid.toString()); + path = + path.replace( + "{" + "BundleSid" + "}", + this.pathBundleSid.toString() + ); Request request = new Request( HttpMethod.POST, @@ -48,15 +50,23 @@ public Evaluation create(final TwilioRestClient client){ ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Evaluation creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Evaluation creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Evaluation.fromJson(response.getStream(), client.getObjectMapper()); + return Evaluation.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/EvaluationFetcher.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/EvaluationFetcher.java index a434ffc6a7..9fccf06370 100644 --- a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/EvaluationFetcher.java +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/EvaluationFetcher.java @@ -24,25 +24,27 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class EvaluationFetcher extends Fetcher { + private String pathBundleSid; private String pathSid; - public EvaluationFetcher(final String pathBundleSid, final String pathSid){ + public EvaluationFetcher(final String pathBundleSid, final String pathSid) { this.pathBundleSid = pathBundleSid; this.pathSid = pathSid; } - @Override public Evaluation fetch(final TwilioRestClient client) { - String path = "/v2/RegulatoryCompliance/Bundles/{BundleSid}/Evaluations/{Sid}"; + String path = + "/v2/RegulatoryCompliance/Bundles/{BundleSid}/Evaluations/{Sid}"; - path = path.replace("{"+"BundleSid"+"}", this.pathBundleSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "BundleSid" + "}", + this.pathBundleSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,15 +54,23 @@ public Evaluation fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Evaluation fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Evaluation fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Evaluation.fromJson(response.getStream(), client.getObjectMapper()); + return Evaluation.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/EvaluationReader.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/EvaluationReader.java index ad483efb9f..aecf841688 100644 --- a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/EvaluationReader.java +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/EvaluationReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.numbers.v2.regulatorycompliance.bundle; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,19 +25,17 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class EvaluationReader extends Reader { + private String pathBundleSid; private Integer pageSize; - public EvaluationReader(final String pathBundleSid){ + public EvaluationReader(final String pathBundleSid) { this.pathBundleSid = pathBundleSid; } - public EvaluationReader setPageSize(final Integer pageSize){ + public EvaluationReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -47,8 +46,13 @@ public ResourceSet read(final TwilioRestClient client) { } public Page firstPage(final TwilioRestClient client) { - String path = "/v2/RegulatoryCompliance/Bundles/{BundleSid}/Evaluations"; - path = path.replace("{"+"BundleSid"+"}", this.pathBundleSid.toString()); + String path = + "/v2/RegulatoryCompliance/Bundles/{BundleSid}/Evaluations"; + path = + path.replace( + "{" + "BundleSid" + "}", + this.pathBundleSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -60,13 +64,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Evaluation read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Evaluation read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +94,10 @@ private Page pageForRequest(final TwilioRestClient client, final Req } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.NUMBERS.toString()) @@ -90,9 +105,11 @@ public Page previousPage(final Page page, final TwilioRe return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.NUMBERS.toString()) @@ -101,21 +118,21 @@ public Page nextPage(final Page page, final TwilioRestCl } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/ItemAssignment.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/ItemAssignment.java index e1502e0262..39b8640921 100644 --- a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/ItemAssignment.java +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/ItemAssignment.java @@ -23,49 +23,57 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class ItemAssignment extends Resource { + private static final long serialVersionUID = 241370748977037L; - public static ItemAssignmentCreator creator(final String pathBundleSid, final String objectSid){ + public static ItemAssignmentCreator creator( + final String pathBundleSid, + final String objectSid + ) { return new ItemAssignmentCreator(pathBundleSid, objectSid); } - public static ItemAssignmentDeleter deleter(final String pathBundleSid, final String pathSid){ + public static ItemAssignmentDeleter deleter( + final String pathBundleSid, + final String pathSid + ) { return new ItemAssignmentDeleter(pathBundleSid, pathSid); } - public static ItemAssignmentFetcher fetcher(final String pathBundleSid, final String pathSid){ + public static ItemAssignmentFetcher fetcher( + final String pathBundleSid, + final String pathSid + ) { return new ItemAssignmentFetcher(pathBundleSid, pathSid); } - public static ItemAssignmentReader reader(final String pathBundleSid){ + public static ItemAssignmentReader reader(final String pathBundleSid) { return new ItemAssignmentReader(pathBundleSid); } /** - * Converts a JSON String into a ItemAssignment object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return ItemAssignment object represented by the provided JSON - */ - public static ItemAssignment fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a ItemAssignment object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return ItemAssignment object represented by the provided JSON + */ + public static ItemAssignment fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, ItemAssignment.class); @@ -77,14 +85,17 @@ public static ItemAssignment fromJson(final String json, final ObjectMapper obje } /** - * Converts a JSON InputStream into a ItemAssignment object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return ItemAssignment object represented by the provided JSON - */ - public static ItemAssignment fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a ItemAssignment object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return ItemAssignment object represented by the provided JSON + */ + public static ItemAssignment fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, ItemAssignment.class); @@ -104,23 +115,12 @@ public static ItemAssignment fromJson(final InputStream json, final ObjectMapper @JsonCreator private ItemAssignment( - @JsonProperty("sid") - final String sid, - - @JsonProperty("bundle_sid") - final String bundleSid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("object_sid") - final String objectSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("bundle_sid") final String bundleSid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("object_sid") final String objectSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("url") final URI url ) { this.sid = sid; this.bundleSid = bundleSid; @@ -130,28 +130,33 @@ private ItemAssignment( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getBundleSid() { - return this.bundleSid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getObjectSid() { - return this.objectSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getBundleSid() { + return this.bundleSid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getObjectSid() { + return this.objectSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -161,13 +166,25 @@ public boolean equals(final Object o) { ItemAssignment other = (ItemAssignment) o; - return Objects.equals(sid, other.sid) && Objects.equals(bundleSid, other.bundleSid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(objectSid, other.objectSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(bundleSid, other.bundleSid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(objectSid, other.objectSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, bundleSid, accountSid, objectSid, dateCreated, url); + return Objects.hash( + sid, + bundleSid, + accountSid, + objectSid, + dateCreated, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/ItemAssignmentCreator.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/ItemAssignmentCreator.java index f433651a9f..89d564c98c 100644 --- a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/ItemAssignmentCreator.java +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/ItemAssignmentCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.numbers.v2.regulatorycompliance.bundle; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,53 +25,68 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class ItemAssignmentCreator extends Creator { - - -public class ItemAssignmentCreator extends Creator{ private String pathBundleSid; private String objectSid; - public ItemAssignmentCreator(final String pathBundleSid, final String objectSid) { + public ItemAssignmentCreator( + final String pathBundleSid, + final String objectSid + ) { this.pathBundleSid = pathBundleSid; this.objectSid = objectSid; } - public ItemAssignmentCreator setObjectSid(final String objectSid){ + public ItemAssignmentCreator setObjectSid(final String objectSid) { this.objectSid = objectSid; return this; } @Override - public ItemAssignment create(final TwilioRestClient client){ - String path = "/v2/RegulatoryCompliance/Bundles/{BundleSid}/ItemAssignments"; + public ItemAssignment create(final TwilioRestClient client) { + String path = + "/v2/RegulatoryCompliance/Bundles/{BundleSid}/ItemAssignments"; - path = path.replace("{"+"BundleSid"+"}", this.pathBundleSid.toString()); - path = path.replace("{"+"ObjectSid"+"}", this.objectSid.toString()); + path = + path.replace( + "{" + "BundleSid" + "}", + this.pathBundleSid.toString() + ); + path = path.replace("{" + "ObjectSid" + "}", this.objectSid.toString()); Request request = new Request( HttpMethod.POST, Domains.NUMBERS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("ItemAssignment creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "ItemAssignment creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return ItemAssignment.fromJson(response.getStream(), client.getObjectMapper()); + return ItemAssignment.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (objectSid != null) { request.addPostParam("ObjectSid", objectSid); - } } } diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/ItemAssignmentDeleter.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/ItemAssignmentDeleter.java index 46ff50d0aa..db4088ec69 100644 --- a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/ItemAssignmentDeleter.java +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/ItemAssignmentDeleter.java @@ -24,24 +24,30 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class ItemAssignmentDeleter extends Deleter { + private String pathBundleSid; private String pathSid; - public ItemAssignmentDeleter(final String pathBundleSid, final String pathSid){ + public ItemAssignmentDeleter( + final String pathBundleSid, + final String pathSid + ) { this.pathBundleSid = pathBundleSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/v2/RegulatoryCompliance/Bundles/{BundleSid}/ItemAssignments/{Sid}"; + String path = + "/v2/RegulatoryCompliance/Bundles/{BundleSid}/ItemAssignments/{Sid}"; - path = path.replace("{"+"BundleSid"+"}", this.pathBundleSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "BundleSid" + "}", + this.pathBundleSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +57,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("ItemAssignment delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "ItemAssignment delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/ItemAssignmentFetcher.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/ItemAssignmentFetcher.java index 8493d5ce0f..a4381b1b77 100644 --- a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/ItemAssignmentFetcher.java +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/ItemAssignmentFetcher.java @@ -24,25 +24,30 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class ItemAssignmentFetcher extends Fetcher { + private String pathBundleSid; private String pathSid; - public ItemAssignmentFetcher(final String pathBundleSid, final String pathSid){ + public ItemAssignmentFetcher( + final String pathBundleSid, + final String pathSid + ) { this.pathBundleSid = pathBundleSid; this.pathSid = pathSid; } - @Override public ItemAssignment fetch(final TwilioRestClient client) { - String path = "/v2/RegulatoryCompliance/Bundles/{BundleSid}/ItemAssignments/{Sid}"; + String path = + "/v2/RegulatoryCompliance/Bundles/{BundleSid}/ItemAssignments/{Sid}"; - path = path.replace("{"+"BundleSid"+"}", this.pathBundleSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "BundleSid" + "}", + this.pathBundleSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,15 +57,23 @@ public ItemAssignment fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("ItemAssignment fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "ItemAssignment fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return ItemAssignment.fromJson(response.getStream(), client.getObjectMapper()); + return ItemAssignment.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/ItemAssignmentReader.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/ItemAssignmentReader.java index af842cc2c5..e29d98206b 100644 --- a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/ItemAssignmentReader.java +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/ItemAssignmentReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.numbers.v2.regulatorycompliance.bundle; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,19 +25,17 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class ItemAssignmentReader extends Reader { + private String pathBundleSid; private Integer pageSize; - public ItemAssignmentReader(final String pathBundleSid){ + public ItemAssignmentReader(final String pathBundleSid) { this.pathBundleSid = pathBundleSid; } - public ItemAssignmentReader setPageSize(final Integer pageSize){ + public ItemAssignmentReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -47,8 +46,13 @@ public ResourceSet read(final TwilioRestClient client) { } public Page firstPage(final TwilioRestClient client) { - String path = "/v2/RegulatoryCompliance/Bundles/{BundleSid}/ItemAssignments"; - path = path.replace("{"+"BundleSid"+"}", this.pathBundleSid.toString()); + String path = + "/v2/RegulatoryCompliance/Bundles/{BundleSid}/ItemAssignments"; + path = + path.replace( + "{" + "BundleSid" + "}", + this.pathBundleSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -60,13 +64,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("ItemAssignment read failed: Unable to connect to server"); + throw new ApiConnectionException( + "ItemAssignment read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +94,10 @@ private Page pageForRequest(final TwilioRestClient client, final } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.NUMBERS.toString()) @@ -90,9 +105,11 @@ public Page previousPage(final Page page, final return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.NUMBERS.toString()) @@ -101,21 +118,21 @@ public Page nextPage(final Page page, final Twil } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/ReplaceItems.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/ReplaceItems.java index e8231bccf3..a39ea808d1 100644 --- a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/ReplaceItems.java +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/ReplaceItems.java @@ -24,37 +24,39 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class ReplaceItems extends Resource { + private static final long serialVersionUID = 154268646541269L; - public static ReplaceItemsCreator creator(final String pathBundleSid, final String fromBundleSid){ + public static ReplaceItemsCreator creator( + final String pathBundleSid, + final String fromBundleSid + ) { return new ReplaceItemsCreator(pathBundleSid, fromBundleSid); } /** - * Converts a JSON String into a ReplaceItems object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return ReplaceItems object represented by the provided JSON - */ - public static ReplaceItems fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a ReplaceItems object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return ReplaceItems object represented by the provided JSON + */ + public static ReplaceItems fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, ReplaceItems.class); @@ -66,14 +68,17 @@ public static ReplaceItems fromJson(final String json, final ObjectMapper object } /** - * Converts a JSON InputStream into a ReplaceItems object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return ReplaceItems object represented by the provided JSON - */ - public static ReplaceItems fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a ReplaceItems object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return ReplaceItems object represented by the provided JSON + */ + public static ReplaceItems fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, ReplaceItems.class); @@ -83,6 +88,7 @@ public static ReplaceItems fromJson(final InputStream json, final ObjectMapper o throw new ApiConnectionException(e.getMessage(), e); } } + public enum Status { DRAFT("draft"), PENDING_REVIEW("pending-review"), @@ -120,35 +126,16 @@ public static Status forValue(final String value) { @JsonCreator private ReplaceItems( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("regulation_sid") - final String regulationSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("status") - final ReplaceItems.Status status, - - @JsonProperty("valid_until") - final String validUntil, - - @JsonProperty("email") - final String email, - - @JsonProperty("status_callback") - final URI statusCallback, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("regulation_sid") final String regulationSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("status") final ReplaceItems.Status status, + @JsonProperty("valid_until") final String validUntil, + @JsonProperty("email") final String email, + @JsonProperty("status_callback") final URI statusCallback, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated ) { this.sid = sid; this.accountSid = accountSid; @@ -162,40 +149,49 @@ private ReplaceItems( this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getRegulationSid() { - return this.regulationSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final ReplaceItems.Status getStatus() { - return this.status; - } - public final ZonedDateTime getValidUntil() { - return this.validUntil; - } - public final String getEmail() { - return this.email; - } - public final URI getStatusCallback() { - return this.statusCallback; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getRegulationSid() { + return this.regulationSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final ReplaceItems.Status getStatus() { + return this.status; + } + + public final ZonedDateTime getValidUntil() { + return this.validUntil; + } + + public final String getEmail() { + return this.email; + } + + public final URI getStatusCallback() { + return this.statusCallback; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -205,13 +201,33 @@ public boolean equals(final Object o) { ReplaceItems other = (ReplaceItems) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(regulationSid, other.regulationSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(status, other.status) && Objects.equals(validUntil, other.validUntil) && Objects.equals(email, other.email) && Objects.equals(statusCallback, other.statusCallback) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(regulationSid, other.regulationSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(status, other.status) && + Objects.equals(validUntil, other.validUntil) && + Objects.equals(email, other.email) && + Objects.equals(statusCallback, other.statusCallback) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, regulationSid, friendlyName, status, validUntil, email, statusCallback, dateCreated, dateUpdated); + return Objects.hash( + sid, + accountSid, + regulationSid, + friendlyName, + status, + validUntil, + email, + statusCallback, + dateCreated, + dateUpdated + ); } - } - diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/ReplaceItemsCreator.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/ReplaceItemsCreator.java index e17cf86c1d..24148584ef 100644 --- a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/ReplaceItemsCreator.java +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/ReplaceItemsCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.numbers.v2.regulatorycompliance.bundle; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,53 +25,72 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class ReplaceItemsCreator extends Creator { - - -public class ReplaceItemsCreator extends Creator{ private String pathBundleSid; private String fromBundleSid; - public ReplaceItemsCreator(final String pathBundleSid, final String fromBundleSid) { + public ReplaceItemsCreator( + final String pathBundleSid, + final String fromBundleSid + ) { this.pathBundleSid = pathBundleSid; this.fromBundleSid = fromBundleSid; } - public ReplaceItemsCreator setFromBundleSid(final String fromBundleSid){ + public ReplaceItemsCreator setFromBundleSid(final String fromBundleSid) { this.fromBundleSid = fromBundleSid; return this; } @Override - public ReplaceItems create(final TwilioRestClient client){ - String path = "/v2/RegulatoryCompliance/Bundles/{BundleSid}/ReplaceItems"; + public ReplaceItems create(final TwilioRestClient client) { + String path = + "/v2/RegulatoryCompliance/Bundles/{BundleSid}/ReplaceItems"; - path = path.replace("{"+"BundleSid"+"}", this.pathBundleSid.toString()); - path = path.replace("{"+"FromBundleSid"+"}", this.fromBundleSid.toString()); + path = + path.replace( + "{" + "BundleSid" + "}", + this.pathBundleSid.toString() + ); + path = + path.replace( + "{" + "FromBundleSid" + "}", + this.fromBundleSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.NUMBERS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("ReplaceItems creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "ReplaceItems creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return ReplaceItems.fromJson(response.getStream(), client.getObjectMapper()); + return ReplaceItems.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (fromBundleSid != null) { request.addPostParam("FromBundleSid", fromBundleSid); - } } } diff --git a/src/main/java/com/twilio/rest/oauth/v1/DeviceCode.java b/src/main/java/com/twilio/rest/oauth/v1/DeviceCode.java index d126cd7023..020f335c3f 100644 --- a/src/main/java/com/twilio/rest/oauth/v1/DeviceCode.java +++ b/src/main/java/com/twilio/rest/oauth/v1/DeviceCode.java @@ -22,36 +22,38 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; - import java.util.List; import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class DeviceCode extends Resource { + private static final long serialVersionUID = 153107871213953L; - public static DeviceCodeCreator creator(final String clientSid, final List scopes){ + public static DeviceCodeCreator creator( + final String clientSid, + final List scopes + ) { return new DeviceCodeCreator(clientSid, scopes); } /** - * Converts a JSON String into a DeviceCode object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return DeviceCode object represented by the provided JSON - */ - public static DeviceCode fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a DeviceCode object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return DeviceCode object represented by the provided JSON + */ + public static DeviceCode fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, DeviceCode.class); @@ -63,14 +65,17 @@ public static DeviceCode fromJson(final String json, final ObjectMapper objectMa } /** - * Converts a JSON InputStream into a DeviceCode object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return DeviceCode object represented by the provided JSON - */ - public static DeviceCode fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a DeviceCode object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return DeviceCode object represented by the provided JSON + */ + public static DeviceCode fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, DeviceCode.class); @@ -90,23 +95,14 @@ public static DeviceCode fromJson(final InputStream json, final ObjectMapper obj @JsonCreator private DeviceCode( - @JsonProperty("device_code") - final String deviceCode, - - @JsonProperty("user_code") - final String userCode, - - @JsonProperty("verification_uri") - final String verificationUri, - - @JsonProperty("verification_uri_complete") - final String verificationUriComplete, - - @JsonProperty("expires_in") - final Long expiresIn, - - @JsonProperty("interval") - final Integer interval + @JsonProperty("device_code") final String deviceCode, + @JsonProperty("user_code") final String userCode, + @JsonProperty("verification_uri") final String verificationUri, + @JsonProperty( + "verification_uri_complete" + ) final String verificationUriComplete, + @JsonProperty("expires_in") final Long expiresIn, + @JsonProperty("interval") final Integer interval ) { this.deviceCode = deviceCode; this.userCode = userCode; @@ -116,28 +112,33 @@ private DeviceCode( this.interval = interval; } - public final String getDeviceCode() { - return this.deviceCode; - } - public final String getUserCode() { - return this.userCode; - } - public final String getVerificationUri() { - return this.verificationUri; - } - public final String getVerificationUriComplete() { - return this.verificationUriComplete; - } - public final Long getExpiresIn() { - return this.expiresIn; - } - public final Integer getInterval() { - return this.interval; - } + public final String getDeviceCode() { + return this.deviceCode; + } + + public final String getUserCode() { + return this.userCode; + } + + public final String getVerificationUri() { + return this.verificationUri; + } + + public final String getVerificationUriComplete() { + return this.verificationUriComplete; + } + + public final Long getExpiresIn() { + return this.expiresIn; + } + + public final Integer getInterval() { + return this.interval; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -147,13 +148,28 @@ public boolean equals(final Object o) { DeviceCode other = (DeviceCode) o; - return Objects.equals(deviceCode, other.deviceCode) && Objects.equals(userCode, other.userCode) && Objects.equals(verificationUri, other.verificationUri) && Objects.equals(verificationUriComplete, other.verificationUriComplete) && Objects.equals(expiresIn, other.expiresIn) && Objects.equals(interval, other.interval) ; + return ( + Objects.equals(deviceCode, other.deviceCode) && + Objects.equals(userCode, other.userCode) && + Objects.equals(verificationUri, other.verificationUri) && + Objects.equals( + verificationUriComplete, + other.verificationUriComplete + ) && + Objects.equals(expiresIn, other.expiresIn) && + Objects.equals(interval, other.interval) + ); } @Override public int hashCode() { - return Objects.hash(deviceCode, userCode, verificationUri, verificationUriComplete, expiresIn, interval); + return Objects.hash( + deviceCode, + userCode, + verificationUri, + verificationUriComplete, + expiresIn, + interval + ); } - } - diff --git a/src/main/java/com/twilio/rest/oauth/v1/DeviceCodeCreator.java b/src/main/java/com/twilio/rest/oauth/v1/DeviceCodeCreator.java index 3d200409a8..bc95cce726 100644 --- a/src/main/java/com/twilio/rest/oauth/v1/DeviceCodeCreator.java +++ b/src/main/java/com/twilio/rest/oauth/v1/DeviceCodeCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.oauth.v1; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -25,82 +26,94 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.util.List; - import java.util.List; +public class DeviceCodeCreator extends Creator { - -public class DeviceCodeCreator extends Creator{ private String clientSid; private List scopes; private List audiences; - public DeviceCodeCreator(final String clientSid, final List scopes) { + public DeviceCodeCreator( + final String clientSid, + final List scopes + ) { this.clientSid = clientSid; this.scopes = scopes; } - public DeviceCodeCreator setClientSid(final String clientSid){ + public DeviceCodeCreator setClientSid(final String clientSid) { this.clientSid = clientSid; return this; } - public DeviceCodeCreator setScopes(final List scopes){ + + public DeviceCodeCreator setScopes(final List scopes) { this.scopes = scopes; return this; } - public DeviceCodeCreator setScopes(final String scopes){ + + public DeviceCodeCreator setScopes(final String scopes) { return setScopes(Promoter.listOfOne(scopes)); } - public DeviceCodeCreator setAudiences(final List audiences){ + + public DeviceCodeCreator setAudiences(final List audiences) { this.audiences = audiences; return this; } - public DeviceCodeCreator setAudiences(final String audiences){ + + public DeviceCodeCreator setAudiences(final String audiences) { return setAudiences(Promoter.listOfOne(audiences)); } @Override - public DeviceCode create(final TwilioRestClient client){ + public DeviceCode create(final TwilioRestClient client) { String path = "/v1/device/code"; - path = path.replace("{"+"ClientSid"+"}", this.clientSid.toString()); - path = path.replace("{"+"Scopes"+"}", this.scopes.toString()); + path = path.replace("{" + "ClientSid" + "}", this.clientSid.toString()); + path = path.replace("{" + "Scopes" + "}", this.scopes.toString()); Request request = new Request( HttpMethod.POST, Domains.OAUTH.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("DeviceCode creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "DeviceCode creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return DeviceCode.fromJson(response.getStream(), client.getObjectMapper()); + return DeviceCode.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (clientSid != null) { request.addPostParam("ClientSid", clientSid); - } if (scopes != null) { for (String prop : scopes) { request.addPostParam("Scopes", prop); } - } if (audiences != null) { for (String prop : audiences) { request.addPostParam("Audiences", prop); } - } } } diff --git a/src/main/java/com/twilio/rest/oauth/v1/Oauth.java b/src/main/java/com/twilio/rest/oauth/v1/Oauth.java index 48ce261037..ab90f36b75 100644 --- a/src/main/java/com/twilio/rest/oauth/v1/Oauth.java +++ b/src/main/java/com/twilio/rest/oauth/v1/Oauth.java @@ -22,38 +22,37 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Oauth extends Resource { + private static final long serialVersionUID = 95485483905123L; - public static OauthFetcher fetcher(){ + public static OauthFetcher fetcher() { return new OauthFetcher(); } /** - * Converts a JSON String into a Oauth object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Oauth object represented by the provided JSON - */ - public static Oauth fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Oauth object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Oauth object represented by the provided JSON + */ + public static Oauth fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Oauth.class); @@ -65,14 +64,17 @@ public static Oauth fromJson(final String json, final ObjectMapper objectMapper) } /** - * Converts a JSON InputStream into a Oauth object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Oauth object represented by the provided JSON - */ - public static Oauth fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Oauth object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Oauth object represented by the provided JSON + */ + public static Oauth fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Oauth.class); @@ -88,26 +90,24 @@ public static Oauth fromJson(final InputStream json, final ObjectMapper objectMa @JsonCreator private Oauth( - @JsonProperty("keys") - final Map keys, - - @JsonProperty("url") - final URI url + @JsonProperty("keys") final Map keys, + @JsonProperty("url") final URI url ) { this.keys = keys; this.url = url; } - public final Map getKeys() { - return this.keys; - } - public final URI getUrl() { - return this.url; - } + public final Map getKeys() { + return this.keys; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -117,13 +117,13 @@ public boolean equals(final Object o) { Oauth other = (Oauth) o; - return Objects.equals(keys, other.keys) && Objects.equals(url, other.url) ; + return ( + Objects.equals(keys, other.keys) && Objects.equals(url, other.url) + ); } @Override public int hashCode() { return Objects.hash(keys, url); } - } - diff --git a/src/main/java/com/twilio/rest/oauth/v1/OauthFetcher.java b/src/main/java/com/twilio/rest/oauth/v1/OauthFetcher.java index bcb28e4c55..a0c5ca23cf 100644 --- a/src/main/java/com/twilio/rest/oauth/v1/OauthFetcher.java +++ b/src/main/java/com/twilio/rest/oauth/v1/OauthFetcher.java @@ -24,20 +24,14 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class OauthFetcher extends Fetcher { - public OauthFetcher(){ - } - + public OauthFetcher() {} @Override public Oauth fetch(final TwilioRestClient client) { String path = "/v1/certs"; - Request request = new Request( HttpMethod.GET, Domains.OAUTH.toString(), @@ -46,9 +40,14 @@ public Oauth fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Oauth fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Oauth fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/oauth/v1/OpenidDiscovery.java b/src/main/java/com/twilio/rest/oauth/v1/OpenidDiscovery.java index 15ae145df4..5e9ef2edf9 100644 --- a/src/main/java/com/twilio/rest/oauth/v1/OpenidDiscovery.java +++ b/src/main/java/com/twilio/rest/oauth/v1/OpenidDiscovery.java @@ -22,37 +22,36 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.List; import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class OpenidDiscovery extends Resource { + private static final long serialVersionUID = 213503115925852L; - public static OpenidDiscoveryFetcher fetcher(){ + public static OpenidDiscoveryFetcher fetcher() { return new OpenidDiscoveryFetcher(); } /** - * Converts a JSON String into a OpenidDiscovery object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return OpenidDiscovery object represented by the provided JSON - */ - public static OpenidDiscovery fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a OpenidDiscovery object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return OpenidDiscovery object represented by the provided JSON + */ + public static OpenidDiscovery fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, OpenidDiscovery.class); @@ -64,14 +63,17 @@ public static OpenidDiscovery fromJson(final String json, final ObjectMapper obj } /** - * Converts a JSON InputStream into a OpenidDiscovery object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return OpenidDiscovery object represented by the provided JSON - */ - public static OpenidDiscovery fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a OpenidDiscovery object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return OpenidDiscovery object represented by the provided JSON + */ + public static OpenidDiscovery fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, OpenidDiscovery.class); @@ -98,44 +100,27 @@ public static OpenidDiscovery fromJson(final InputStream json, final ObjectMappe @JsonCreator private OpenidDiscovery( - @JsonProperty("issuer") - final URI issuer, - - @JsonProperty("authorization_endpoint") - final URI authorizationEndpoint, - - @JsonProperty("device_authorization_endpoint") - final URI deviceAuthorizationEndpoint, - - @JsonProperty("token_endpoint") - final URI tokenEndpoint, - - @JsonProperty("userinfo_endpoint") - final URI userinfoEndpoint, - - @JsonProperty("revocation_endpoint") - final URI revocationEndpoint, - - @JsonProperty("jwk_uri") - final URI jwkUri, - - @JsonProperty("response_type_supported") - final List responseTypeSupported, - - @JsonProperty("subject_type_supported") - final List subjectTypeSupported, - - @JsonProperty("id_token_signing_alg_values_supported") - final List idTokenSigningAlgValuesSupported, - - @JsonProperty("scopes_supported") - final List scopesSupported, - - @JsonProperty("claims_supported") - final List claimsSupported, - - @JsonProperty("url") - final URI url + @JsonProperty("issuer") final URI issuer, + @JsonProperty("authorization_endpoint") final URI authorizationEndpoint, + @JsonProperty( + "device_authorization_endpoint" + ) final URI deviceAuthorizationEndpoint, + @JsonProperty("token_endpoint") final URI tokenEndpoint, + @JsonProperty("userinfo_endpoint") final URI userinfoEndpoint, + @JsonProperty("revocation_endpoint") final URI revocationEndpoint, + @JsonProperty("jwk_uri") final URI jwkUri, + @JsonProperty( + "response_type_supported" + ) final List responseTypeSupported, + @JsonProperty( + "subject_type_supported" + ) final List subjectTypeSupported, + @JsonProperty( + "id_token_signing_alg_values_supported" + ) final List idTokenSigningAlgValuesSupported, + @JsonProperty("scopes_supported") final List scopesSupported, + @JsonProperty("claims_supported") final List claimsSupported, + @JsonProperty("url") final URI url ) { this.issuer = issuer; this.authorizationEndpoint = authorizationEndpoint; @@ -146,55 +131,68 @@ private OpenidDiscovery( this.jwkUri = jwkUri; this.responseTypeSupported = responseTypeSupported; this.subjectTypeSupported = subjectTypeSupported; - this.idTokenSigningAlgValuesSupported = idTokenSigningAlgValuesSupported; + this.idTokenSigningAlgValuesSupported = + idTokenSigningAlgValuesSupported; this.scopesSupported = scopesSupported; this.claimsSupported = claimsSupported; this.url = url; } - public final URI getIssuer() { - return this.issuer; - } - public final URI getAuthorizationEndpoint() { - return this.authorizationEndpoint; - } - public final URI getDeviceAuthorizationEndpoint() { - return this.deviceAuthorizationEndpoint; - } - public final URI getTokenEndpoint() { - return this.tokenEndpoint; - } - public final URI getUserinfoEndpoint() { - return this.userinfoEndpoint; - } - public final URI getRevocationEndpoint() { - return this.revocationEndpoint; - } - public final URI getJwkUri() { - return this.jwkUri; - } - public final List getResponseTypeSupported() { - return this.responseTypeSupported; - } - public final List getSubjectTypeSupported() { - return this.subjectTypeSupported; - } - public final List getIdTokenSigningAlgValuesSupported() { - return this.idTokenSigningAlgValuesSupported; - } - public final List getScopesSupported() { - return this.scopesSupported; - } - public final List getClaimsSupported() { - return this.claimsSupported; - } - public final URI getUrl() { - return this.url; - } + public final URI getIssuer() { + return this.issuer; + } + + public final URI getAuthorizationEndpoint() { + return this.authorizationEndpoint; + } + + public final URI getDeviceAuthorizationEndpoint() { + return this.deviceAuthorizationEndpoint; + } + + public final URI getTokenEndpoint() { + return this.tokenEndpoint; + } + + public final URI getUserinfoEndpoint() { + return this.userinfoEndpoint; + } + + public final URI getRevocationEndpoint() { + return this.revocationEndpoint; + } + + public final URI getJwkUri() { + return this.jwkUri; + } + + public final List getResponseTypeSupported() { + return this.responseTypeSupported; + } + + public final List getSubjectTypeSupported() { + return this.subjectTypeSupported; + } + + public final List getIdTokenSigningAlgValuesSupported() { + return this.idTokenSigningAlgValuesSupported; + } + + public final List getScopesSupported() { + return this.scopesSupported; + } + + public final List getClaimsSupported() { + return this.claimsSupported; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -204,13 +202,51 @@ public boolean equals(final Object o) { OpenidDiscovery other = (OpenidDiscovery) o; - return Objects.equals(issuer, other.issuer) && Objects.equals(authorizationEndpoint, other.authorizationEndpoint) && Objects.equals(deviceAuthorizationEndpoint, other.deviceAuthorizationEndpoint) && Objects.equals(tokenEndpoint, other.tokenEndpoint) && Objects.equals(userinfoEndpoint, other.userinfoEndpoint) && Objects.equals(revocationEndpoint, other.revocationEndpoint) && Objects.equals(jwkUri, other.jwkUri) && Objects.equals(responseTypeSupported, other.responseTypeSupported) && Objects.equals(subjectTypeSupported, other.subjectTypeSupported) && Objects.equals(idTokenSigningAlgValuesSupported, other.idTokenSigningAlgValuesSupported) && Objects.equals(scopesSupported, other.scopesSupported) && Objects.equals(claimsSupported, other.claimsSupported) && Objects.equals(url, other.url) ; + return ( + Objects.equals(issuer, other.issuer) && + Objects.equals( + authorizationEndpoint, + other.authorizationEndpoint + ) && + Objects.equals( + deviceAuthorizationEndpoint, + other.deviceAuthorizationEndpoint + ) && + Objects.equals(tokenEndpoint, other.tokenEndpoint) && + Objects.equals(userinfoEndpoint, other.userinfoEndpoint) && + Objects.equals(revocationEndpoint, other.revocationEndpoint) && + Objects.equals(jwkUri, other.jwkUri) && + Objects.equals( + responseTypeSupported, + other.responseTypeSupported + ) && + Objects.equals(subjectTypeSupported, other.subjectTypeSupported) && + Objects.equals( + idTokenSigningAlgValuesSupported, + other.idTokenSigningAlgValuesSupported + ) && + Objects.equals(scopesSupported, other.scopesSupported) && + Objects.equals(claimsSupported, other.claimsSupported) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(issuer, authorizationEndpoint, deviceAuthorizationEndpoint, tokenEndpoint, userinfoEndpoint, revocationEndpoint, jwkUri, responseTypeSupported, subjectTypeSupported, idTokenSigningAlgValuesSupported, scopesSupported, claimsSupported, url); + return Objects.hash( + issuer, + authorizationEndpoint, + deviceAuthorizationEndpoint, + tokenEndpoint, + userinfoEndpoint, + revocationEndpoint, + jwkUri, + responseTypeSupported, + subjectTypeSupported, + idTokenSigningAlgValuesSupported, + scopesSupported, + claimsSupported, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/oauth/v1/OpenidDiscoveryFetcher.java b/src/main/java/com/twilio/rest/oauth/v1/OpenidDiscoveryFetcher.java index cc73576344..0ec1a213dd 100644 --- a/src/main/java/com/twilio/rest/oauth/v1/OpenidDiscoveryFetcher.java +++ b/src/main/java/com/twilio/rest/oauth/v1/OpenidDiscoveryFetcher.java @@ -24,20 +24,14 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class OpenidDiscoveryFetcher extends Fetcher { - public OpenidDiscoveryFetcher(){ - } - + public OpenidDiscoveryFetcher() {} @Override public OpenidDiscovery fetch(final TwilioRestClient client) { String path = "/v1/.well-known/openid-configuration"; - Request request = new Request( HttpMethod.GET, Domains.OAUTH.toString(), @@ -46,15 +40,23 @@ public OpenidDiscovery fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("OpenidDiscovery fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "OpenidDiscovery fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return OpenidDiscovery.fromJson(response.getStream(), client.getObjectMapper()); + return OpenidDiscovery.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/oauth/v1/Token.java b/src/main/java/com/twilio/rest/oauth/v1/Token.java index 8ff3d2e213..159edfe40d 100644 --- a/src/main/java/com/twilio/rest/oauth/v1/Token.java +++ b/src/main/java/com/twilio/rest/oauth/v1/Token.java @@ -23,36 +23,38 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Token extends Resource { + private static final long serialVersionUID = 233151022011558L; - public static TokenCreator creator(final String grantType, final String clientSid){ + public static TokenCreator creator( + final String grantType, + final String clientSid + ) { return new TokenCreator(grantType, clientSid); } /** - * Converts a JSON String into a Token object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Token object represented by the provided JSON - */ - public static Token fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Token object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Token object represented by the provided JSON + */ + public static Token fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Token.class); @@ -64,14 +66,17 @@ public static Token fromJson(final String json, final ObjectMapper objectMapper) } /** - * Converts a JSON InputStream into a Token object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Token object represented by the provided JSON - */ - public static Token fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Token object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Token object represented by the provided JSON + */ + public static Token fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Token.class); @@ -90,47 +95,48 @@ public static Token fromJson(final InputStream json, final ObjectMapper objectMa @JsonCreator private Token( - @JsonProperty("access_token") - final String accessToken, - - @JsonProperty("refresh_token") - final String refreshToken, - - @JsonProperty("id_token") - final String idToken, - - @JsonProperty("refresh_token_expires_at") - final String refreshTokenExpiresAt, - - @JsonProperty("access_token_expires_at") - final String accessTokenExpiresAt + @JsonProperty("access_token") final String accessToken, + @JsonProperty("refresh_token") final String refreshToken, + @JsonProperty("id_token") final String idToken, + @JsonProperty( + "refresh_token_expires_at" + ) final String refreshTokenExpiresAt, + @JsonProperty( + "access_token_expires_at" + ) final String accessTokenExpiresAt ) { this.accessToken = accessToken; this.refreshToken = refreshToken; this.idToken = idToken; - this.refreshTokenExpiresAt = DateConverter.iso8601DateTimeFromString(refreshTokenExpiresAt); - this.accessTokenExpiresAt = DateConverter.iso8601DateTimeFromString(accessTokenExpiresAt); + this.refreshTokenExpiresAt = + DateConverter.iso8601DateTimeFromString(refreshTokenExpiresAt); + this.accessTokenExpiresAt = + DateConverter.iso8601DateTimeFromString(accessTokenExpiresAt); } - public final String getAccessToken() { - return this.accessToken; - } - public final String getRefreshToken() { - return this.refreshToken; - } - public final String getIdToken() { - return this.idToken; - } - public final ZonedDateTime getRefreshTokenExpiresAt() { - return this.refreshTokenExpiresAt; - } - public final ZonedDateTime getAccessTokenExpiresAt() { - return this.accessTokenExpiresAt; - } + public final String getAccessToken() { + return this.accessToken; + } + + public final String getRefreshToken() { + return this.refreshToken; + } + + public final String getIdToken() { + return this.idToken; + } + + public final ZonedDateTime getRefreshTokenExpiresAt() { + return this.refreshTokenExpiresAt; + } + + public final ZonedDateTime getAccessTokenExpiresAt() { + return this.accessTokenExpiresAt; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -140,13 +146,26 @@ public boolean equals(final Object o) { Token other = (Token) o; - return Objects.equals(accessToken, other.accessToken) && Objects.equals(refreshToken, other.refreshToken) && Objects.equals(idToken, other.idToken) && Objects.equals(refreshTokenExpiresAt, other.refreshTokenExpiresAt) && Objects.equals(accessTokenExpiresAt, other.accessTokenExpiresAt) ; + return ( + Objects.equals(accessToken, other.accessToken) && + Objects.equals(refreshToken, other.refreshToken) && + Objects.equals(idToken, other.idToken) && + Objects.equals( + refreshTokenExpiresAt, + other.refreshTokenExpiresAt + ) && + Objects.equals(accessTokenExpiresAt, other.accessTokenExpiresAt) + ); } @Override public int hashCode() { - return Objects.hash(accessToken, refreshToken, idToken, refreshTokenExpiresAt, accessTokenExpiresAt); + return Objects.hash( + accessToken, + refreshToken, + idToken, + refreshTokenExpiresAt, + accessTokenExpiresAt + ); } - } - diff --git a/src/main/java/com/twilio/rest/oauth/v1/TokenCreator.java b/src/main/java/com/twilio/rest/oauth/v1/TokenCreator.java index 80dd43193e..e92a8fe90d 100644 --- a/src/main/java/com/twilio/rest/oauth/v1/TokenCreator.java +++ b/src/main/java/com/twilio/rest/oauth/v1/TokenCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.oauth.v1; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class TokenCreator extends Creator { - - -public class TokenCreator extends Creator{ private String grantType; private String clientSid; private String clientSecret; @@ -42,57 +41,70 @@ public TokenCreator(final String grantType, final String clientSid) { this.clientSid = clientSid; } - public TokenCreator setGrantType(final String grantType){ + public TokenCreator setGrantType(final String grantType) { this.grantType = grantType; return this; } - public TokenCreator setClientSid(final String clientSid){ + + public TokenCreator setClientSid(final String clientSid) { this.clientSid = clientSid; return this; } - public TokenCreator setClientSecret(final String clientSecret){ + + public TokenCreator setClientSecret(final String clientSecret) { this.clientSecret = clientSecret; return this; } - public TokenCreator setCode(final String code){ + + public TokenCreator setCode(final String code) { this.code = code; return this; } - public TokenCreator setCodeVerifier(final String codeVerifier){ + + public TokenCreator setCodeVerifier(final String codeVerifier) { this.codeVerifier = codeVerifier; return this; } - public TokenCreator setDeviceCode(final String deviceCode){ + + public TokenCreator setDeviceCode(final String deviceCode) { this.deviceCode = deviceCode; return this; } - public TokenCreator setRefreshToken(final String refreshToken){ + + public TokenCreator setRefreshToken(final String refreshToken) { this.refreshToken = refreshToken; return this; } - public TokenCreator setDeviceId(final String deviceId){ + + public TokenCreator setDeviceId(final String deviceId) { this.deviceId = deviceId; return this; } @Override - public Token create(final TwilioRestClient client){ + public Token create(final TwilioRestClient client) { String path = "/v1/token"; - path = path.replace("{"+"GrantType"+"}", this.grantType.toString()); - path = path.replace("{"+"ClientSid"+"}", this.clientSid.toString()); + path = path.replace("{" + "GrantType" + "}", this.grantType.toString()); + path = path.replace("{" + "ClientSid" + "}", this.clientSid.toString()); Request request = new Request( HttpMethod.POST, Domains.OAUTH.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Token creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Token creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -101,38 +113,31 @@ public Token create(final TwilioRestClient client){ return Token.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (grantType != null) { request.addPostParam("GrantType", grantType); - } if (clientSid != null) { request.addPostParam("ClientSid", clientSid); - } if (clientSecret != null) { request.addPostParam("ClientSecret", clientSecret); - } if (code != null) { request.addPostParam("Code", code); - } if (codeVerifier != null) { request.addPostParam("CodeVerifier", codeVerifier); - } if (deviceCode != null) { request.addPostParam("DeviceCode", deviceCode); - } if (refreshToken != null) { request.addPostParam("RefreshToken", refreshToken); - } if (deviceId != null) { request.addPostParam("DeviceId", deviceId); - } } } diff --git a/src/main/java/com/twilio/rest/oauth/v1/UserInfo.java b/src/main/java/com/twilio/rest/oauth/v1/UserInfo.java index 1f519e09a7..062f7370eb 100644 --- a/src/main/java/com/twilio/rest/oauth/v1/UserInfo.java +++ b/src/main/java/com/twilio/rest/oauth/v1/UserInfo.java @@ -22,36 +22,35 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class UserInfo extends Resource { + private static final long serialVersionUID = 74270157944596L; - public static UserInfoFetcher fetcher(){ + public static UserInfoFetcher fetcher() { return new UserInfoFetcher(); } /** - * Converts a JSON String into a UserInfo object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return UserInfo object represented by the provided JSON - */ - public static UserInfo fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a UserInfo object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return UserInfo object represented by the provided JSON + */ + public static UserInfo fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, UserInfo.class); @@ -63,14 +62,17 @@ public static UserInfo fromJson(final String json, final ObjectMapper objectMapp } /** - * Converts a JSON InputStream into a UserInfo object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return UserInfo object represented by the provided JSON - */ - public static UserInfo fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a UserInfo object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return UserInfo object represented by the provided JSON + */ + public static UserInfo fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, UserInfo.class); @@ -90,23 +92,12 @@ public static UserInfo fromJson(final InputStream json, final ObjectMapper objec @JsonCreator private UserInfo( - @JsonProperty("user_sid") - final String userSid, - - @JsonProperty("first_name") - final String firstName, - - @JsonProperty("last_name") - final String lastName, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("email") - final String email, - - @JsonProperty("url") - final URI url + @JsonProperty("user_sid") final String userSid, + @JsonProperty("first_name") final String firstName, + @JsonProperty("last_name") final String lastName, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("email") final String email, + @JsonProperty("url") final URI url ) { this.userSid = userSid; this.firstName = firstName; @@ -116,28 +107,33 @@ private UserInfo( this.url = url; } - public final String getUserSid() { - return this.userSid; - } - public final String getFirstName() { - return this.firstName; - } - public final String getLastName() { - return this.lastName; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getEmail() { - return this.email; - } - public final URI getUrl() { - return this.url; - } + public final String getUserSid() { + return this.userSid; + } + + public final String getFirstName() { + return this.firstName; + } + + public final String getLastName() { + return this.lastName; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getEmail() { + return this.email; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -147,13 +143,25 @@ public boolean equals(final Object o) { UserInfo other = (UserInfo) o; - return Objects.equals(userSid, other.userSid) && Objects.equals(firstName, other.firstName) && Objects.equals(lastName, other.lastName) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(email, other.email) && Objects.equals(url, other.url) ; + return ( + Objects.equals(userSid, other.userSid) && + Objects.equals(firstName, other.firstName) && + Objects.equals(lastName, other.lastName) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(email, other.email) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(userSid, firstName, lastName, friendlyName, email, url); + return Objects.hash( + userSid, + firstName, + lastName, + friendlyName, + email, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/oauth/v1/UserInfoFetcher.java b/src/main/java/com/twilio/rest/oauth/v1/UserInfoFetcher.java index 3396c8f432..e77a1e3105 100644 --- a/src/main/java/com/twilio/rest/oauth/v1/UserInfoFetcher.java +++ b/src/main/java/com/twilio/rest/oauth/v1/UserInfoFetcher.java @@ -24,20 +24,14 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class UserInfoFetcher extends Fetcher { - public UserInfoFetcher(){ - } - + public UserInfoFetcher() {} @Override public UserInfo fetch(final TwilioRestClient client) { String path = "/v1/userinfo"; - Request request = new Request( HttpMethod.GET, Domains.OAUTH.toString(), @@ -46,15 +40,23 @@ public UserInfo fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("UserInfo fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "UserInfo fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return UserInfo.fromJson(response.getStream(), client.getObjectMapper()); + return UserInfo.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/preview/deployedDevices/Fleet.java b/src/main/java/com/twilio/rest/preview/deployedDevices/Fleet.java index d61d126f54..91132245c8 100644 --- a/src/main/java/com/twilio/rest/preview/deployedDevices/Fleet.java +++ b/src/main/java/com/twilio/rest/preview/deployedDevices/Fleet.java @@ -23,55 +23,54 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Fleet extends Resource { + private static final long serialVersionUID = 162068485825595L; - public static FleetCreator creator(){ + public static FleetCreator creator() { return new FleetCreator(); } - public static FleetDeleter deleter(final String pathSid){ + public static FleetDeleter deleter(final String pathSid) { return new FleetDeleter(pathSid); } - public static FleetFetcher fetcher(final String pathSid){ + public static FleetFetcher fetcher(final String pathSid) { return new FleetFetcher(pathSid); } - public static FleetReader reader(){ + public static FleetReader reader() { return new FleetReader(); } - public static FleetUpdater updater(final String pathSid){ + public static FleetUpdater updater(final String pathSid) { return new FleetUpdater(pathSid); } /** - * Converts a JSON String into a Fleet object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Fleet object represented by the provided JSON - */ - public static Fleet fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Fleet object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Fleet object represented by the provided JSON + */ + public static Fleet fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Fleet.class); @@ -83,14 +82,17 @@ public static Fleet fromJson(final String json, final ObjectMapper objectMapper) } /** - * Converts a JSON InputStream into a Fleet object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Fleet object represented by the provided JSON - */ - public static Fleet fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Fleet object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Fleet object represented by the provided JSON + */ + public static Fleet fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Fleet.class); @@ -113,32 +115,17 @@ public static Fleet fromJson(final InputStream json, final ObjectMapper objectMa @JsonCreator private Fleet( - @JsonProperty("sid") - final String sid, - - @JsonProperty("url") - final URI url, - - @JsonProperty("unique_name") - final String uniqueName, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("default_deployment_sid") - final String defaultDeploymentSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("links") - final Map links + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty( + "default_deployment_sid" + ) final String defaultDeploymentSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("links") final Map links ) { this.sid = sid; this.url = url; @@ -151,37 +138,45 @@ private Fleet( this.links = links; } - public final String getSid() { - return this.sid; - } - public final URI getUrl() { - return this.url; - } - public final String getUniqueName() { - return this.uniqueName; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getDefaultDeploymentSid() { - return this.defaultDeploymentSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final Map getLinks() { - return this.links; - } + public final String getSid() { + return this.sid; + } + + public final URI getUrl() { + return this.url; + } + + public final String getUniqueName() { + return this.uniqueName; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getDefaultDeploymentSid() { + return this.defaultDeploymentSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -191,13 +186,31 @@ public boolean equals(final Object o) { Fleet other = (Fleet) o; - return Objects.equals(sid, other.sid) && Objects.equals(url, other.url) && Objects.equals(uniqueName, other.uniqueName) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(accountSid, other.accountSid) && Objects.equals(defaultDeploymentSid, other.defaultDeploymentSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(links, other.links) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(defaultDeploymentSid, other.defaultDeploymentSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(sid, url, uniqueName, friendlyName, accountSid, defaultDeploymentSid, dateCreated, dateUpdated, links); + return Objects.hash( + sid, + url, + uniqueName, + friendlyName, + accountSid, + defaultDeploymentSid, + dateCreated, + dateUpdated, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/preview/deployedDevices/FleetCreator.java b/src/main/java/com/twilio/rest/preview/deployedDevices/FleetCreator.java index 7db66ed3e2..683f3fa93e 100644 --- a/src/main/java/com/twilio/rest/preview/deployedDevices/FleetCreator.java +++ b/src/main/java/com/twilio/rest/preview/deployedDevices/FleetCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.preview.deployedDevices; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,36 +25,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class FleetCreator extends Creator { - - -public class FleetCreator extends Creator{ private String friendlyName; - public FleetCreator() { - } + public FleetCreator() {} - public FleetCreator setFriendlyName(final String friendlyName){ + public FleetCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } @Override - public Fleet create(final TwilioRestClient client){ + public Fleet create(final TwilioRestClient client) { String path = "/DeployedDevices/Fleets"; - Request request = new Request( HttpMethod.POST, Domains.PREVIEW.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Fleet creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Fleet creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -62,10 +65,10 @@ public Fleet create(final TwilioRestClient client){ return Fleet.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } } } diff --git a/src/main/java/com/twilio/rest/preview/deployedDevices/FleetDeleter.java b/src/main/java/com/twilio/rest/preview/deployedDevices/FleetDeleter.java index 6002fe7a3c..0eb93252c4 100644 --- a/src/main/java/com/twilio/rest/preview/deployedDevices/FleetDeleter.java +++ b/src/main/java/com/twilio/rest/preview/deployedDevices/FleetDeleter.java @@ -24,21 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class FleetDeleter extends Deleter { + private String pathSid; - public FleetDeleter(final String pathSid){ + public FleetDeleter(final String pathSid) { this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/DeployedDevices/Fleets/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -48,9 +46,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Fleet delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Fleet delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/preview/deployedDevices/FleetFetcher.java b/src/main/java/com/twilio/rest/preview/deployedDevices/FleetFetcher.java index 8c99d70bfb..cd5bd46423 100644 --- a/src/main/java/com/twilio/rest/preview/deployedDevices/FleetFetcher.java +++ b/src/main/java/com/twilio/rest/preview/deployedDevices/FleetFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class FleetFetcher extends Fetcher { + private String pathSid; - public FleetFetcher(final String pathSid){ + public FleetFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public Fleet fetch(final TwilioRestClient client) { String path = "/DeployedDevices/Fleets/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,9 +46,14 @@ public Fleet fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Fleet fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Fleet fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/preview/deployedDevices/FleetReader.java b/src/main/java/com/twilio/rest/preview/deployedDevices/FleetReader.java index b9d36a8cd8..6dd6ef616b 100644 --- a/src/main/java/com/twilio/rest/preview/deployedDevices/FleetReader.java +++ b/src/main/java/com/twilio/rest/preview/deployedDevices/FleetReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.preview.deployedDevices; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,17 +25,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class FleetReader extends Reader { + private Integer pageSize; - public FleetReader(){ - } + public FleetReader() {} - public FleetReader setPageSize(final Integer pageSize){ + public FleetReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -57,13 +55,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Fleet read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Fleet read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -79,7 +85,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.PREVIEW.toString()) @@ -87,9 +96,11 @@ public Page previousPage(final Page page, final TwilioRestClient c return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.PREVIEW.toString()) @@ -98,21 +109,21 @@ public Page nextPage(final Page page, final TwilioRestClient clien } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/preview/deployedDevices/FleetUpdater.java b/src/main/java/com/twilio/rest/preview/deployedDevices/FleetUpdater.java index b7b35a6632..22ecbb71a6 100644 --- a/src/main/java/com/twilio/rest/preview/deployedDevices/FleetUpdater.java +++ b/src/main/java/com/twilio/rest/preview/deployedDevices/FleetUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.preview.deployedDevices; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,44 +25,51 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class FleetUpdater extends Updater { - - -public class FleetUpdater extends Updater{ private String pathSid; private String friendlyName; private String defaultDeploymentSid; - public FleetUpdater(final String pathSid){ + public FleetUpdater(final String pathSid) { this.pathSid = pathSid; } - public FleetUpdater setFriendlyName(final String friendlyName){ + public FleetUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public FleetUpdater setDefaultDeploymentSid(final String defaultDeploymentSid){ + + public FleetUpdater setDefaultDeploymentSid( + final String defaultDeploymentSid + ) { this.defaultDeploymentSid = defaultDeploymentSid; return this; } @Override - public Fleet update(final TwilioRestClient client){ + public Fleet update(final TwilioRestClient client) { String path = "/DeployedDevices/Fleets/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.PREVIEW.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Fleet update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Fleet update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -70,14 +78,13 @@ public Fleet update(final TwilioRestClient client){ return Fleet.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (defaultDeploymentSid != null) { request.addPostParam("DefaultDeploymentSid", defaultDeploymentSid); - } } } diff --git a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/Certificate.java b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/Certificate.java index f026465b38..689c209106 100644 --- a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/Certificate.java +++ b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/Certificate.java @@ -23,53 +23,64 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Certificate extends Resource { + private static final long serialVersionUID = 26542571339730L; - public static CertificateCreator creator(final String pathFleetSid, final String certificateData){ + public static CertificateCreator creator( + final String pathFleetSid, + final String certificateData + ) { return new CertificateCreator(pathFleetSid, certificateData); } - public static CertificateDeleter deleter(final String pathFleetSid, final String pathSid){ + public static CertificateDeleter deleter( + final String pathFleetSid, + final String pathSid + ) { return new CertificateDeleter(pathFleetSid, pathSid); } - public static CertificateFetcher fetcher(final String pathFleetSid, final String pathSid){ + public static CertificateFetcher fetcher( + final String pathFleetSid, + final String pathSid + ) { return new CertificateFetcher(pathFleetSid, pathSid); } - public static CertificateReader reader(final String pathFleetSid){ + public static CertificateReader reader(final String pathFleetSid) { return new CertificateReader(pathFleetSid); } - public static CertificateUpdater updater(final String pathFleetSid, final String pathSid){ + public static CertificateUpdater updater( + final String pathFleetSid, + final String pathSid + ) { return new CertificateUpdater(pathFleetSid, pathSid); } /** - * Converts a JSON String into a Certificate object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Certificate object represented by the provided JSON - */ - public static Certificate fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Certificate object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Certificate object represented by the provided JSON + */ + public static Certificate fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Certificate.class); @@ -81,14 +92,17 @@ public static Certificate fromJson(final String json, final ObjectMapper objectM } /** - * Converts a JSON InputStream into a Certificate object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Certificate object represented by the provided JSON - */ - public static Certificate fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Certificate object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Certificate object represented by the provided JSON + */ + public static Certificate fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Certificate.class); @@ -111,32 +125,15 @@ public static Certificate fromJson(final InputStream json, final ObjectMapper ob @JsonCreator private Certificate( - @JsonProperty("sid") - final String sid, - - @JsonProperty("url") - final URI url, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("fleet_sid") - final String fleetSid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("device_sid") - final String deviceSid, - - @JsonProperty("thumbprint") - final String thumbprint, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("fleet_sid") final String fleetSid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("device_sid") final String deviceSid, + @JsonProperty("thumbprint") final String thumbprint, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated ) { this.sid = sid; this.url = url; @@ -149,37 +146,45 @@ private Certificate( this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); } - public final String getSid() { - return this.sid; - } - public final URI getUrl() { - return this.url; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getFleetSid() { - return this.fleetSid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getDeviceSid() { - return this.deviceSid; - } - public final String getThumbprint() { - return this.thumbprint; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } + public final String getSid() { + return this.sid; + } + + public final URI getUrl() { + return this.url; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getFleetSid() { + return this.fleetSid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getDeviceSid() { + return this.deviceSid; + } + + public final String getThumbprint() { + return this.thumbprint; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -189,13 +194,31 @@ public boolean equals(final Object o) { Certificate other = (Certificate) o; - return Objects.equals(sid, other.sid) && Objects.equals(url, other.url) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(fleetSid, other.fleetSid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(deviceSid, other.deviceSid) && Objects.equals(thumbprint, other.thumbprint) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(fleetSid, other.fleetSid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(deviceSid, other.deviceSid) && + Objects.equals(thumbprint, other.thumbprint) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) + ); } @Override public int hashCode() { - return Objects.hash(sid, url, friendlyName, fleetSid, accountSid, deviceSid, thumbprint, dateCreated, dateUpdated); + return Objects.hash( + sid, + url, + friendlyName, + fleetSid, + accountSid, + deviceSid, + thumbprint, + dateCreated, + dateUpdated + ); } - } - diff --git a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/CertificateCreator.java b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/CertificateCreator.java index 1c870aff0c..ace0dc32a6 100644 --- a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/CertificateCreator.java +++ b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/CertificateCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.preview.deployedDevices.fleet; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,71 +25,86 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class CertificateCreator extends Creator { - - -public class CertificateCreator extends Creator{ private String pathFleetSid; private String certificateData; private String friendlyName; private String deviceSid; - public CertificateCreator(final String pathFleetSid, final String certificateData) { + public CertificateCreator( + final String pathFleetSid, + final String certificateData + ) { this.pathFleetSid = pathFleetSid; this.certificateData = certificateData; } - public CertificateCreator setCertificateData(final String certificateData){ + public CertificateCreator setCertificateData(final String certificateData) { this.certificateData = certificateData; return this; } - public CertificateCreator setFriendlyName(final String friendlyName){ + + public CertificateCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public CertificateCreator setDeviceSid(final String deviceSid){ + + public CertificateCreator setDeviceSid(final String deviceSid) { this.deviceSid = deviceSid; return this; } @Override - public Certificate create(final TwilioRestClient client){ + public Certificate create(final TwilioRestClient client) { String path = "/DeployedDevices/Fleets/{FleetSid}/Certificates"; - path = path.replace("{"+"FleetSid"+"}", this.pathFleetSid.toString()); - path = path.replace("{"+"CertificateData"+"}", this.certificateData.toString()); + path = + path.replace("{" + "FleetSid" + "}", this.pathFleetSid.toString()); + path = + path.replace( + "{" + "CertificateData" + "}", + this.certificateData.toString() + ); Request request = new Request( HttpMethod.POST, Domains.PREVIEW.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Certificate creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Certificate creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Certificate.fromJson(response.getStream(), client.getObjectMapper()); + return Certificate.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (certificateData != null) { request.addPostParam("CertificateData", certificateData); - } if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (deviceSid != null) { request.addPostParam("DeviceSid", deviceSid); - } } } diff --git a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/CertificateDeleter.java b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/CertificateDeleter.java index b3fd24bee2..ce0e9ba342 100644 --- a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/CertificateDeleter.java +++ b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/CertificateDeleter.java @@ -24,24 +24,23 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class CertificateDeleter extends Deleter { + private String pathFleetSid; private String pathSid; - public CertificateDeleter(final String pathFleetSid, final String pathSid){ + public CertificateDeleter(final String pathFleetSid, final String pathSid) { this.pathFleetSid = pathFleetSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/DeployedDevices/Fleets/{FleetSid}/Certificates/{Sid}"; - path = path.replace("{"+"FleetSid"+"}", this.pathFleetSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace("{" + "FleetSid" + "}", this.pathFleetSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +50,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Certificate delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Certificate delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/CertificateFetcher.java b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/CertificateFetcher.java index af435f5348..107e971ded 100644 --- a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/CertificateFetcher.java +++ b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/CertificateFetcher.java @@ -24,25 +24,23 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class CertificateFetcher extends Fetcher { + private String pathFleetSid; private String pathSid; - public CertificateFetcher(final String pathFleetSid, final String pathSid){ + public CertificateFetcher(final String pathFleetSid, final String pathSid) { this.pathFleetSid = pathFleetSid; this.pathSid = pathSid; } - @Override public Certificate fetch(final TwilioRestClient client) { String path = "/DeployedDevices/Fleets/{FleetSid}/Certificates/{Sid}"; - path = path.replace("{"+"FleetSid"+"}", this.pathFleetSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace("{" + "FleetSid" + "}", this.pathFleetSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,15 +50,23 @@ public Certificate fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Certificate fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Certificate fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Certificate.fromJson(response.getStream(), client.getObjectMapper()); + return Certificate.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/CertificateReader.java b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/CertificateReader.java index 6f370b1e22..46f66b35d6 100644 --- a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/CertificateReader.java +++ b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/CertificateReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.preview.deployedDevices.fleet; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,24 +25,23 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class CertificateReader extends Reader { + private String pathFleetSid; private String deviceSid; private Integer pageSize; - public CertificateReader(final String pathFleetSid){ + public CertificateReader(final String pathFleetSid) { this.pathFleetSid = pathFleetSid; } - public CertificateReader setDeviceSid(final String deviceSid){ + public CertificateReader setDeviceSid(final String deviceSid) { this.deviceSid = deviceSid; return this; } - public CertificateReader setPageSize(final Integer pageSize){ + + public CertificateReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -53,7 +53,8 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/DeployedDevices/Fleets/{FleetSid}/Certificates"; - path = path.replace("{"+"FleetSid"+"}", this.pathFleetSid.toString()); + path = + path.replace("{" + "FleetSid" + "}", this.pathFleetSid.toString()); Request request = new Request( HttpMethod.GET, @@ -65,13 +66,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Certificate read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Certificate read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -87,7 +96,10 @@ private Page pageForRequest(final TwilioRestClient client, final Re } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.PREVIEW.toString()) @@ -95,9 +107,11 @@ public Page previousPage(final Page page, final Twilio return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.PREVIEW.toString()) @@ -106,25 +120,24 @@ public Page nextPage(final Page page, final TwilioRest } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (deviceSid != null) { - request.addQueryParam("DeviceSid", deviceSid); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/CertificateUpdater.java b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/CertificateUpdater.java index 628240e9f4..ca08cd6518 100644 --- a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/CertificateUpdater.java +++ b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/CertificateUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.preview.deployedDevices.fleet; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,63 +25,71 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class CertificateUpdater extends Updater { - - -public class CertificateUpdater extends Updater{ private String pathFleetSid; private String pathSid; private String friendlyName; private String deviceSid; - public CertificateUpdater(final String pathFleetSid, final String pathSid){ + public CertificateUpdater(final String pathFleetSid, final String pathSid) { this.pathFleetSid = pathFleetSid; this.pathSid = pathSid; } - public CertificateUpdater setFriendlyName(final String friendlyName){ + public CertificateUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public CertificateUpdater setDeviceSid(final String deviceSid){ + + public CertificateUpdater setDeviceSid(final String deviceSid) { this.deviceSid = deviceSid; return this; } @Override - public Certificate update(final TwilioRestClient client){ + public Certificate update(final TwilioRestClient client) { String path = "/DeployedDevices/Fleets/{FleetSid}/Certificates/{Sid}"; - path = path.replace("{"+"FleetSid"+"}", this.pathFleetSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace("{" + "FleetSid" + "}", this.pathFleetSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.PREVIEW.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Certificate update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Certificate update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Certificate.fromJson(response.getStream(), client.getObjectMapper()); + return Certificate.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (deviceSid != null) { request.addPostParam("DeviceSid", deviceSid); - } } } diff --git a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/Deployment.java b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/Deployment.java index 8ef440ae6f..0d5c068f7b 100644 --- a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/Deployment.java +++ b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/Deployment.java @@ -23,53 +23,61 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Deployment extends Resource { + private static final long serialVersionUID = 184203517947226L; - public static DeploymentCreator creator(final String pathFleetSid){ + public static DeploymentCreator creator(final String pathFleetSid) { return new DeploymentCreator(pathFleetSid); } - public static DeploymentDeleter deleter(final String pathFleetSid, final String pathSid){ + public static DeploymentDeleter deleter( + final String pathFleetSid, + final String pathSid + ) { return new DeploymentDeleter(pathFleetSid, pathSid); } - public static DeploymentFetcher fetcher(final String pathFleetSid, final String pathSid){ + public static DeploymentFetcher fetcher( + final String pathFleetSid, + final String pathSid + ) { return new DeploymentFetcher(pathFleetSid, pathSid); } - public static DeploymentReader reader(final String pathFleetSid){ + public static DeploymentReader reader(final String pathFleetSid) { return new DeploymentReader(pathFleetSid); } - public static DeploymentUpdater updater(final String pathFleetSid, final String pathSid){ + public static DeploymentUpdater updater( + final String pathFleetSid, + final String pathSid + ) { return new DeploymentUpdater(pathFleetSid, pathSid); } /** - * Converts a JSON String into a Deployment object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Deployment object represented by the provided JSON - */ - public static Deployment fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Deployment object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Deployment object represented by the provided JSON + */ + public static Deployment fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Deployment.class); @@ -81,14 +89,17 @@ public static Deployment fromJson(final String json, final ObjectMapper objectMa } /** - * Converts a JSON InputStream into a Deployment object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Deployment object represented by the provided JSON - */ - public static Deployment fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Deployment object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Deployment object represented by the provided JSON + */ + public static Deployment fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Deployment.class); @@ -110,29 +121,14 @@ public static Deployment fromJson(final InputStream json, final ObjectMapper obj @JsonCreator private Deployment( - @JsonProperty("sid") - final String sid, - - @JsonProperty("url") - final URI url, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("fleet_sid") - final String fleetSid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("sync_service_sid") - final String syncServiceSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("fleet_sid") final String fleetSid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("sync_service_sid") final String syncServiceSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated ) { this.sid = sid; this.url = url; @@ -144,34 +140,41 @@ private Deployment( this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); } - public final String getSid() { - return this.sid; - } - public final URI getUrl() { - return this.url; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getFleetSid() { - return this.fleetSid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getSyncServiceSid() { - return this.syncServiceSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } + public final String getSid() { + return this.sid; + } + + public final URI getUrl() { + return this.url; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getFleetSid() { + return this.fleetSid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getSyncServiceSid() { + return this.syncServiceSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -181,13 +184,29 @@ public boolean equals(final Object o) { Deployment other = (Deployment) o; - return Objects.equals(sid, other.sid) && Objects.equals(url, other.url) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(fleetSid, other.fleetSid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(syncServiceSid, other.syncServiceSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(fleetSid, other.fleetSid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(syncServiceSid, other.syncServiceSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) + ); } @Override public int hashCode() { - return Objects.hash(sid, url, friendlyName, fleetSid, accountSid, syncServiceSid, dateCreated, dateUpdated); + return Objects.hash( + sid, + url, + friendlyName, + fleetSid, + accountSid, + syncServiceSid, + dateCreated, + dateUpdated + ); } - } - diff --git a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeploymentCreator.java b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeploymentCreator.java index 36002414fb..5442b40875 100644 --- a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeploymentCreator.java +++ b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeploymentCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.preview.deployedDevices.fleet; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class DeploymentCreator extends Creator { - - -public class DeploymentCreator extends Creator{ private String pathFleetSid; private String friendlyName; private String syncServiceSid; @@ -36,48 +35,58 @@ public DeploymentCreator(final String pathFleetSid) { this.pathFleetSid = pathFleetSid; } - public DeploymentCreator setFriendlyName(final String friendlyName){ + public DeploymentCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public DeploymentCreator setSyncServiceSid(final String syncServiceSid){ + + public DeploymentCreator setSyncServiceSid(final String syncServiceSid) { this.syncServiceSid = syncServiceSid; return this; } @Override - public Deployment create(final TwilioRestClient client){ + public Deployment create(final TwilioRestClient client) { String path = "/DeployedDevices/Fleets/{FleetSid}/Deployments"; - path = path.replace("{"+"FleetSid"+"}", this.pathFleetSid.toString()); + path = + path.replace("{" + "FleetSid" + "}", this.pathFleetSid.toString()); Request request = new Request( HttpMethod.POST, Domains.PREVIEW.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Deployment creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Deployment creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Deployment.fromJson(response.getStream(), client.getObjectMapper()); + return Deployment.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (syncServiceSid != null) { request.addPostParam("SyncServiceSid", syncServiceSid); - } } } diff --git a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeploymentDeleter.java b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeploymentDeleter.java index 732fac47c3..020a53b1a2 100644 --- a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeploymentDeleter.java +++ b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeploymentDeleter.java @@ -24,24 +24,23 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class DeploymentDeleter extends Deleter { + private String pathFleetSid; private String pathSid; - public DeploymentDeleter(final String pathFleetSid, final String pathSid){ + public DeploymentDeleter(final String pathFleetSid, final String pathSid) { this.pathFleetSid = pathFleetSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/DeployedDevices/Fleets/{FleetSid}/Deployments/{Sid}"; - path = path.replace("{"+"FleetSid"+"}", this.pathFleetSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace("{" + "FleetSid" + "}", this.pathFleetSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +50,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Deployment delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Deployment delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeploymentFetcher.java b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeploymentFetcher.java index a8c51b5bc4..b3f3eed30b 100644 --- a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeploymentFetcher.java +++ b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeploymentFetcher.java @@ -24,25 +24,23 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class DeploymentFetcher extends Fetcher { + private String pathFleetSid; private String pathSid; - public DeploymentFetcher(final String pathFleetSid, final String pathSid){ + public DeploymentFetcher(final String pathFleetSid, final String pathSid) { this.pathFleetSid = pathFleetSid; this.pathSid = pathSid; } - @Override public Deployment fetch(final TwilioRestClient client) { String path = "/DeployedDevices/Fleets/{FleetSid}/Deployments/{Sid}"; - path = path.replace("{"+"FleetSid"+"}", this.pathFleetSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace("{" + "FleetSid" + "}", this.pathFleetSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,15 +50,23 @@ public Deployment fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Deployment fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Deployment fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Deployment.fromJson(response.getStream(), client.getObjectMapper()); + return Deployment.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeploymentReader.java b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeploymentReader.java index 372600dad5..42a99df447 100644 --- a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeploymentReader.java +++ b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeploymentReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.preview.deployedDevices.fleet; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,19 +25,17 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class DeploymentReader extends Reader { + private String pathFleetSid; private Integer pageSize; - public DeploymentReader(final String pathFleetSid){ + public DeploymentReader(final String pathFleetSid) { this.pathFleetSid = pathFleetSid; } - public DeploymentReader setPageSize(final Integer pageSize){ + public DeploymentReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -48,7 +47,8 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/DeployedDevices/Fleets/{FleetSid}/Deployments"; - path = path.replace("{"+"FleetSid"+"}", this.pathFleetSid.toString()); + path = + path.replace("{" + "FleetSid" + "}", this.pathFleetSid.toString()); Request request = new Request( HttpMethod.GET, @@ -60,13 +60,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Deployment read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Deployment read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +90,10 @@ private Page pageForRequest(final TwilioRestClient client, final Req } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.PREVIEW.toString()) @@ -90,9 +101,11 @@ public Page previousPage(final Page page, final TwilioRe return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.PREVIEW.toString()) @@ -101,21 +114,21 @@ public Page nextPage(final Page page, final TwilioRestCl } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeploymentUpdater.java b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeploymentUpdater.java index d95378e32d..f15da797cb 100644 --- a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeploymentUpdater.java +++ b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeploymentUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.preview.deployedDevices.fleet; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,63 +25,71 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class DeploymentUpdater extends Updater { - - -public class DeploymentUpdater extends Updater{ private String pathFleetSid; private String pathSid; private String friendlyName; private String syncServiceSid; - public DeploymentUpdater(final String pathFleetSid, final String pathSid){ + public DeploymentUpdater(final String pathFleetSid, final String pathSid) { this.pathFleetSid = pathFleetSid; this.pathSid = pathSid; } - public DeploymentUpdater setFriendlyName(final String friendlyName){ + public DeploymentUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public DeploymentUpdater setSyncServiceSid(final String syncServiceSid){ + + public DeploymentUpdater setSyncServiceSid(final String syncServiceSid) { this.syncServiceSid = syncServiceSid; return this; } @Override - public Deployment update(final TwilioRestClient client){ + public Deployment update(final TwilioRestClient client) { String path = "/DeployedDevices/Fleets/{FleetSid}/Deployments/{Sid}"; - path = path.replace("{"+"FleetSid"+"}", this.pathFleetSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace("{" + "FleetSid" + "}", this.pathFleetSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.PREVIEW.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Deployment update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Deployment update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Deployment.fromJson(response.getStream(), client.getObjectMapper()); + return Deployment.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (syncServiceSid != null) { request.addPostParam("SyncServiceSid", syncServiceSid); - } } } diff --git a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/Device.java b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/Device.java index a5e7bd0301..4fc865a180 100644 --- a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/Device.java +++ b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/Device.java @@ -23,53 +23,61 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Device extends Resource { + private static final long serialVersionUID = 204948181343163L; - public static DeviceCreator creator(final String pathFleetSid){ + public static DeviceCreator creator(final String pathFleetSid) { return new DeviceCreator(pathFleetSid); } - public static DeviceDeleter deleter(final String pathFleetSid, final String pathSid){ + public static DeviceDeleter deleter( + final String pathFleetSid, + final String pathSid + ) { return new DeviceDeleter(pathFleetSid, pathSid); } - public static DeviceFetcher fetcher(final String pathFleetSid, final String pathSid){ + public static DeviceFetcher fetcher( + final String pathFleetSid, + final String pathSid + ) { return new DeviceFetcher(pathFleetSid, pathSid); } - public static DeviceReader reader(final String pathFleetSid){ + public static DeviceReader reader(final String pathFleetSid) { return new DeviceReader(pathFleetSid); } - public static DeviceUpdater updater(final String pathFleetSid, final String pathSid){ + public static DeviceUpdater updater( + final String pathFleetSid, + final String pathSid + ) { return new DeviceUpdater(pathFleetSid, pathSid); } /** - * Converts a JSON String into a Device object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Device object represented by the provided JSON - */ - public static Device fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Device object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Device object represented by the provided JSON + */ + public static Device fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Device.class); @@ -81,14 +89,17 @@ public static Device fromJson(final String json, final ObjectMapper objectMapper } /** - * Converts a JSON InputStream into a Device object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Device object represented by the provided JSON - */ - public static Device fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Device object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Device object represented by the provided JSON + */ + public static Device fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Device.class); @@ -114,41 +125,18 @@ public static Device fromJson(final InputStream json, final ObjectMapper objectM @JsonCreator private Device( - @JsonProperty("sid") - final String sid, - - @JsonProperty("url") - final URI url, - - @JsonProperty("unique_name") - final String uniqueName, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("fleet_sid") - final String fleetSid, - - @JsonProperty("enabled") - final Boolean enabled, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("identity") - final String identity, - - @JsonProperty("deployment_sid") - final String deploymentSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("date_authenticated") - final String dateAuthenticated + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("fleet_sid") final String fleetSid, + @JsonProperty("enabled") final Boolean enabled, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("identity") final String identity, + @JsonProperty("deployment_sid") final String deploymentSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("date_authenticated") final String dateAuthenticated ) { this.sid = sid; this.url = url; @@ -161,49 +149,61 @@ private Device( this.deploymentSid = deploymentSid; this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.dateAuthenticated = DateConverter.iso8601DateTimeFromString(dateAuthenticated); + this.dateAuthenticated = + DateConverter.iso8601DateTimeFromString(dateAuthenticated); } - public final String getSid() { - return this.sid; - } - public final URI getUrl() { - return this.url; - } - public final String getUniqueName() { - return this.uniqueName; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getFleetSid() { - return this.fleetSid; - } - public final Boolean getEnabled() { - return this.enabled; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getIdentity() { - return this.identity; - } - public final String getDeploymentSid() { - return this.deploymentSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final ZonedDateTime getDateAuthenticated() { - return this.dateAuthenticated; - } + public final String getSid() { + return this.sid; + } + + public final URI getUrl() { + return this.url; + } + + public final String getUniqueName() { + return this.uniqueName; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getFleetSid() { + return this.fleetSid; + } + + public final Boolean getEnabled() { + return this.enabled; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getIdentity() { + return this.identity; + } + + public final String getDeploymentSid() { + return this.deploymentSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final ZonedDateTime getDateAuthenticated() { + return this.dateAuthenticated; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -213,13 +213,37 @@ public boolean equals(final Object o) { Device other = (Device) o; - return Objects.equals(sid, other.sid) && Objects.equals(url, other.url) && Objects.equals(uniqueName, other.uniqueName) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(fleetSid, other.fleetSid) && Objects.equals(enabled, other.enabled) && Objects.equals(accountSid, other.accountSid) && Objects.equals(identity, other.identity) && Objects.equals(deploymentSid, other.deploymentSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(dateAuthenticated, other.dateAuthenticated) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(fleetSid, other.fleetSid) && + Objects.equals(enabled, other.enabled) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(identity, other.identity) && + Objects.equals(deploymentSid, other.deploymentSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(dateAuthenticated, other.dateAuthenticated) + ); } @Override public int hashCode() { - return Objects.hash(sid, url, uniqueName, friendlyName, fleetSid, enabled, accountSid, identity, deploymentSid, dateCreated, dateUpdated, dateAuthenticated); + return Objects.hash( + sid, + url, + uniqueName, + friendlyName, + fleetSid, + enabled, + accountSid, + identity, + deploymentSid, + dateCreated, + dateUpdated, + dateAuthenticated + ); } - } - diff --git a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeviceCreator.java b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeviceCreator.java index 7e98ec8f94..2dfbe97b06 100644 --- a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeviceCreator.java +++ b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeviceCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.preview.deployedDevices.fleet; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class DeviceCreator extends Creator { - - -public class DeviceCreator extends Creator{ private String pathFleetSid; private String uniqueName; private String friendlyName; @@ -39,44 +38,55 @@ public DeviceCreator(final String pathFleetSid) { this.pathFleetSid = pathFleetSid; } - public DeviceCreator setUniqueName(final String uniqueName){ + public DeviceCreator setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - public DeviceCreator setFriendlyName(final String friendlyName){ + + public DeviceCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public DeviceCreator setIdentity(final String identity){ + + public DeviceCreator setIdentity(final String identity) { this.identity = identity; return this; } - public DeviceCreator setDeploymentSid(final String deploymentSid){ + + public DeviceCreator setDeploymentSid(final String deploymentSid) { this.deploymentSid = deploymentSid; return this; } - public DeviceCreator setEnabled(final Boolean enabled){ + + public DeviceCreator setEnabled(final Boolean enabled) { this.enabled = enabled; return this; } @Override - public Device create(final TwilioRestClient client){ + public Device create(final TwilioRestClient client) { String path = "/DeployedDevices/Fleets/{FleetSid}/Devices"; - path = path.replace("{"+"FleetSid"+"}", this.pathFleetSid.toString()); + path = + path.replace("{" + "FleetSid" + "}", this.pathFleetSid.toString()); Request request = new Request( HttpMethod.POST, Domains.PREVIEW.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Device creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Device creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -85,26 +95,22 @@ public Device create(final TwilioRestClient client){ return Device.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (uniqueName != null) { request.addPostParam("UniqueName", uniqueName); - } if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (identity != null) { request.addPostParam("Identity", identity); - } if (deploymentSid != null) { request.addPostParam("DeploymentSid", deploymentSid); - } if (enabled != null) { request.addPostParam("Enabled", enabled.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeviceDeleter.java b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeviceDeleter.java index be973f3d90..8ab9bbebda 100644 --- a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeviceDeleter.java +++ b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeviceDeleter.java @@ -24,24 +24,23 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class DeviceDeleter extends Deleter { + private String pathFleetSid; private String pathSid; - public DeviceDeleter(final String pathFleetSid, final String pathSid){ + public DeviceDeleter(final String pathFleetSid, final String pathSid) { this.pathFleetSid = pathFleetSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/DeployedDevices/Fleets/{FleetSid}/Devices/{Sid}"; - path = path.replace("{"+"FleetSid"+"}", this.pathFleetSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace("{" + "FleetSid" + "}", this.pathFleetSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +50,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Device delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Device delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeviceFetcher.java b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeviceFetcher.java index 9e2ac43fa0..0272090c46 100644 --- a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeviceFetcher.java +++ b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeviceFetcher.java @@ -24,25 +24,23 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class DeviceFetcher extends Fetcher { + private String pathFleetSid; private String pathSid; - public DeviceFetcher(final String pathFleetSid, final String pathSid){ + public DeviceFetcher(final String pathFleetSid, final String pathSid) { this.pathFleetSid = pathFleetSid; this.pathSid = pathSid; } - @Override public Device fetch(final TwilioRestClient client) { String path = "/DeployedDevices/Fleets/{FleetSid}/Devices/{Sid}"; - path = path.replace("{"+"FleetSid"+"}", this.pathFleetSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace("{" + "FleetSid" + "}", this.pathFleetSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,9 +50,14 @@ public Device fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Device fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Device fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeviceReader.java b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeviceReader.java index df6792544b..1bffac9302 100644 --- a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeviceReader.java +++ b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeviceReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.preview.deployedDevices.fleet; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,24 +25,23 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class DeviceReader extends Reader { + private String pathFleetSid; private String deploymentSid; private Integer pageSize; - public DeviceReader(final String pathFleetSid){ + public DeviceReader(final String pathFleetSid) { this.pathFleetSid = pathFleetSid; } - public DeviceReader setDeploymentSid(final String deploymentSid){ + public DeviceReader setDeploymentSid(final String deploymentSid) { this.deploymentSid = deploymentSid; return this; } - public DeviceReader setPageSize(final Integer pageSize){ + + public DeviceReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -53,7 +53,8 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/DeployedDevices/Fleets/{FleetSid}/Devices"; - path = path.replace("{"+"FleetSid"+"}", this.pathFleetSid.toString()); + path = + path.replace("{" + "FleetSid" + "}", this.pathFleetSid.toString()); Request request = new Request( HttpMethod.GET, @@ -65,13 +66,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Device read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Device read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -87,7 +96,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.PREVIEW.toString()) @@ -95,9 +107,11 @@ public Page previousPage(final Page page, final TwilioRestClient return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.PREVIEW.toString()) @@ -106,25 +120,24 @@ public Page nextPage(final Page page, final TwilioRestClient cli } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (deploymentSid != null) { - request.addQueryParam("DeploymentSid", deploymentSid); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeviceUpdater.java b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeviceUpdater.java index 64284ac8b7..0eee4667e0 100644 --- a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeviceUpdater.java +++ b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeviceUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.preview.deployedDevices.fleet; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class DeviceUpdater extends Updater { - - -public class DeviceUpdater extends Updater{ private String pathFleetSid; private String pathSid; private String friendlyName; @@ -35,46 +34,56 @@ public class DeviceUpdater extends Updater{ private String deploymentSid; private Boolean enabled; - public DeviceUpdater(final String pathFleetSid, final String pathSid){ + public DeviceUpdater(final String pathFleetSid, final String pathSid) { this.pathFleetSid = pathFleetSid; this.pathSid = pathSid; } - public DeviceUpdater setFriendlyName(final String friendlyName){ + public DeviceUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public DeviceUpdater setIdentity(final String identity){ + + public DeviceUpdater setIdentity(final String identity) { this.identity = identity; return this; } - public DeviceUpdater setDeploymentSid(final String deploymentSid){ + + public DeviceUpdater setDeploymentSid(final String deploymentSid) { this.deploymentSid = deploymentSid; return this; } - public DeviceUpdater setEnabled(final Boolean enabled){ + + public DeviceUpdater setEnabled(final Boolean enabled) { this.enabled = enabled; return this; } @Override - public Device update(final TwilioRestClient client){ + public Device update(final TwilioRestClient client) { String path = "/DeployedDevices/Fleets/{FleetSid}/Devices/{Sid}"; - path = path.replace("{"+"FleetSid"+"}", this.pathFleetSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace("{" + "FleetSid" + "}", this.pathFleetSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.PREVIEW.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Device update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Device update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -83,22 +92,19 @@ public Device update(final TwilioRestClient client){ return Device.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (identity != null) { request.addPostParam("Identity", identity); - } if (deploymentSid != null) { request.addPostParam("DeploymentSid", deploymentSid); - } if (enabled != null) { request.addPostParam("Enabled", enabled.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/Key.java b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/Key.java index 4e7afe155b..5b21028730 100644 --- a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/Key.java +++ b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/Key.java @@ -23,53 +23,61 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Key extends Resource { + private static final long serialVersionUID = 158435998679490L; - public static KeyCreator creator(final String pathFleetSid){ + public static KeyCreator creator(final String pathFleetSid) { return new KeyCreator(pathFleetSid); } - public static KeyDeleter deleter(final String pathFleetSid, final String pathSid){ + public static KeyDeleter deleter( + final String pathFleetSid, + final String pathSid + ) { return new KeyDeleter(pathFleetSid, pathSid); } - public static KeyFetcher fetcher(final String pathFleetSid, final String pathSid){ + public static KeyFetcher fetcher( + final String pathFleetSid, + final String pathSid + ) { return new KeyFetcher(pathFleetSid, pathSid); } - public static KeyReader reader(final String pathFleetSid){ + public static KeyReader reader(final String pathFleetSid) { return new KeyReader(pathFleetSid); } - public static KeyUpdater updater(final String pathFleetSid, final String pathSid){ + public static KeyUpdater updater( + final String pathFleetSid, + final String pathSid + ) { return new KeyUpdater(pathFleetSid, pathSid); } /** - * Converts a JSON String into a Key object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Key object represented by the provided JSON - */ - public static Key fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Key object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Key object represented by the provided JSON + */ + public static Key fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Key.class); @@ -81,14 +89,17 @@ public static Key fromJson(final String json, final ObjectMapper objectMapper) { } /** - * Converts a JSON InputStream into a Key object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Key object represented by the provided JSON - */ - public static Key fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Key object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Key object represented by the provided JSON + */ + public static Key fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Key.class); @@ -111,32 +122,15 @@ public static Key fromJson(final InputStream json, final ObjectMapper objectMapp @JsonCreator private Key( - @JsonProperty("sid") - final String sid, - - @JsonProperty("url") - final URI url, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("fleet_sid") - final String fleetSid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("device_sid") - final String deviceSid, - - @JsonProperty("secret") - final String secret, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("fleet_sid") final String fleetSid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("device_sid") final String deviceSid, + @JsonProperty("secret") final String secret, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated ) { this.sid = sid; this.url = url; @@ -149,37 +143,45 @@ private Key( this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); } - public final String getSid() { - return this.sid; - } - public final URI getUrl() { - return this.url; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getFleetSid() { - return this.fleetSid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getDeviceSid() { - return this.deviceSid; - } - public final String getSecret() { - return this.secret; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } + public final String getSid() { + return this.sid; + } + + public final URI getUrl() { + return this.url; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getFleetSid() { + return this.fleetSid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getDeviceSid() { + return this.deviceSid; + } + + public final String getSecret() { + return this.secret; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -189,13 +191,31 @@ public boolean equals(final Object o) { Key other = (Key) o; - return Objects.equals(sid, other.sid) && Objects.equals(url, other.url) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(fleetSid, other.fleetSid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(deviceSid, other.deviceSid) && Objects.equals(secret, other.secret) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(fleetSid, other.fleetSid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(deviceSid, other.deviceSid) && + Objects.equals(secret, other.secret) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) + ); } @Override public int hashCode() { - return Objects.hash(sid, url, friendlyName, fleetSid, accountSid, deviceSid, secret, dateCreated, dateUpdated); + return Objects.hash( + sid, + url, + friendlyName, + fleetSid, + accountSid, + deviceSid, + secret, + dateCreated, + dateUpdated + ); } - } - diff --git a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/KeyCreator.java b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/KeyCreator.java index 7797f28158..7ae6438da5 100644 --- a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/KeyCreator.java +++ b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/KeyCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.preview.deployedDevices.fleet; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class KeyCreator extends Creator { - - -public class KeyCreator extends Creator{ private String pathFleetSid; private String friendlyName; private String deviceSid; @@ -36,32 +35,40 @@ public KeyCreator(final String pathFleetSid) { this.pathFleetSid = pathFleetSid; } - public KeyCreator setFriendlyName(final String friendlyName){ + public KeyCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public KeyCreator setDeviceSid(final String deviceSid){ + + public KeyCreator setDeviceSid(final String deviceSid) { this.deviceSid = deviceSid; return this; } @Override - public Key create(final TwilioRestClient client){ + public Key create(final TwilioRestClient client) { String path = "/DeployedDevices/Fleets/{FleetSid}/Keys"; - path = path.replace("{"+"FleetSid"+"}", this.pathFleetSid.toString()); + path = + path.replace("{" + "FleetSid" + "}", this.pathFleetSid.toString()); Request request = new Request( HttpMethod.POST, Domains.PREVIEW.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Key creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Key creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -70,14 +77,13 @@ public Key create(final TwilioRestClient client){ return Key.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (deviceSid != null) { request.addPostParam("DeviceSid", deviceSid); - } } } diff --git a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/KeyDeleter.java b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/KeyDeleter.java index 4f44c32fa1..22a4121865 100644 --- a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/KeyDeleter.java +++ b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/KeyDeleter.java @@ -24,24 +24,23 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class KeyDeleter extends Deleter { + private String pathFleetSid; private String pathSid; - public KeyDeleter(final String pathFleetSid, final String pathSid){ + public KeyDeleter(final String pathFleetSid, final String pathSid) { this.pathFleetSid = pathFleetSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/DeployedDevices/Fleets/{FleetSid}/Keys/{Sid}"; - path = path.replace("{"+"FleetSid"+"}", this.pathFleetSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace("{" + "FleetSid" + "}", this.pathFleetSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +50,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Key delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Key delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/KeyFetcher.java b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/KeyFetcher.java index 6cf24e7923..1690c7068c 100644 --- a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/KeyFetcher.java +++ b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/KeyFetcher.java @@ -24,25 +24,23 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class KeyFetcher extends Fetcher { + private String pathFleetSid; private String pathSid; - public KeyFetcher(final String pathFleetSid, final String pathSid){ + public KeyFetcher(final String pathFleetSid, final String pathSid) { this.pathFleetSid = pathFleetSid; this.pathSid = pathSid; } - @Override public Key fetch(final TwilioRestClient client) { String path = "/DeployedDevices/Fleets/{FleetSid}/Keys/{Sid}"; - path = path.replace("{"+"FleetSid"+"}", this.pathFleetSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace("{" + "FleetSid" + "}", this.pathFleetSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,9 +50,14 @@ public Key fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Key fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Key fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/KeyReader.java b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/KeyReader.java index 2e89cd1208..409d286675 100644 --- a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/KeyReader.java +++ b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/KeyReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.preview.deployedDevices.fleet; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,24 +25,23 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class KeyReader extends Reader { + private String pathFleetSid; private String deviceSid; private Integer pageSize; - public KeyReader(final String pathFleetSid){ + public KeyReader(final String pathFleetSid) { this.pathFleetSid = pathFleetSid; } - public KeyReader setDeviceSid(final String deviceSid){ + public KeyReader setDeviceSid(final String deviceSid) { this.deviceSid = deviceSid; return this; } - public KeyReader setPageSize(final Integer pageSize){ + + public KeyReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -53,7 +53,8 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/DeployedDevices/Fleets/{FleetSid}/Keys"; - path = path.replace("{"+"FleetSid"+"}", this.pathFleetSid.toString()); + path = + path.replace("{" + "FleetSid" + "}", this.pathFleetSid.toString()); Request request = new Request( HttpMethod.GET, @@ -65,13 +66,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Key read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Key read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -87,7 +96,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request re } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.PREVIEW.toString()) @@ -95,9 +107,11 @@ public Page previousPage(final Page page, final TwilioRestClient clien return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.PREVIEW.toString()) @@ -106,25 +120,24 @@ public Page nextPage(final Page page, final TwilioRestClient client) { } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (deviceSid != null) { - request.addQueryParam("DeviceSid", deviceSid); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/KeyUpdater.java b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/KeyUpdater.java index c12ec6e821..2bbed38cf7 100644 --- a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/KeyUpdater.java +++ b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/KeyUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.preview.deployedDevices.fleet; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,47 +25,53 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class KeyUpdater extends Updater { - - -public class KeyUpdater extends Updater{ private String pathFleetSid; private String pathSid; private String friendlyName; private String deviceSid; - public KeyUpdater(final String pathFleetSid, final String pathSid){ + public KeyUpdater(final String pathFleetSid, final String pathSid) { this.pathFleetSid = pathFleetSid; this.pathSid = pathSid; } - public KeyUpdater setFriendlyName(final String friendlyName){ + public KeyUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public KeyUpdater setDeviceSid(final String deviceSid){ + + public KeyUpdater setDeviceSid(final String deviceSid) { this.deviceSid = deviceSid; return this; } @Override - public Key update(final TwilioRestClient client){ + public Key update(final TwilioRestClient client) { String path = "/DeployedDevices/Fleets/{FleetSid}/Keys/{Sid}"; - path = path.replace("{"+"FleetSid"+"}", this.pathFleetSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace("{" + "FleetSid" + "}", this.pathFleetSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.PREVIEW.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Key update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Key update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -73,14 +80,13 @@ public Key update(final TwilioRestClient client){ return Key.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (deviceSid != null) { request.addPostParam("DeviceSid", deviceSid); - } } } diff --git a/src/main/java/com/twilio/rest/preview/hostedNumbers/AuthorizationDocument.java b/src/main/java/com/twilio/rest/preview/hostedNumbers/AuthorizationDocument.java index 7d5621b1e5..1fe9affcb7 100644 --- a/src/main/java/com/twilio/rest/preview/hostedNumbers/AuthorizationDocument.java +++ b/src/main/java/com/twilio/rest/preview/hostedNumbers/AuthorizationDocument.java @@ -24,52 +24,63 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.List; import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class AuthorizationDocument extends Resource { + private static final long serialVersionUID = 7314983531290L; - public static AuthorizationDocumentCreator creator(final List hostedNumberOrderSids, final String addressSid, final String email, final String contactTitle, final String contactPhoneNumber){ - return new AuthorizationDocumentCreator(hostedNumberOrderSids, addressSid, email, contactTitle, contactPhoneNumber); + public static AuthorizationDocumentCreator creator( + final List hostedNumberOrderSids, + final String addressSid, + final String email, + final String contactTitle, + final String contactPhoneNumber + ) { + return new AuthorizationDocumentCreator( + hostedNumberOrderSids, + addressSid, + email, + contactTitle, + contactPhoneNumber + ); } - public static AuthorizationDocumentFetcher fetcher(final String pathSid){ + public static AuthorizationDocumentFetcher fetcher(final String pathSid) { return new AuthorizationDocumentFetcher(pathSid); } - public static AuthorizationDocumentReader reader(){ + public static AuthorizationDocumentReader reader() { return new AuthorizationDocumentReader(); } - public static AuthorizationDocumentUpdater updater(final String pathSid){ + public static AuthorizationDocumentUpdater updater(final String pathSid) { return new AuthorizationDocumentUpdater(pathSid); } /** - * Converts a JSON String into a AuthorizationDocument object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return AuthorizationDocument object represented by the provided JSON - */ - public static AuthorizationDocument fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a AuthorizationDocument object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return AuthorizationDocument object represented by the provided JSON + */ + public static AuthorizationDocument fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, AuthorizationDocument.class); @@ -81,14 +92,17 @@ public static AuthorizationDocument fromJson(final String json, final ObjectMapp } /** - * Converts a JSON InputStream into a AuthorizationDocument object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return AuthorizationDocument object represented by the provided JSON - */ - public static AuthorizationDocument fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a AuthorizationDocument object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return AuthorizationDocument object represented by the provided JSON + */ + public static AuthorizationDocument fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, AuthorizationDocument.class); @@ -98,6 +112,7 @@ public static AuthorizationDocument fromJson(final InputStream json, final Objec throw new ApiConnectionException(e.getMessage(), e); } } + public enum Status { OPENED("opened"), SIGNING("signing"), @@ -133,32 +148,15 @@ public static Status forValue(final String value) { @JsonCreator private AuthorizationDocument( - @JsonProperty("sid") - final String sid, - - @JsonProperty("address_sid") - final String addressSid, - - @JsonProperty("status") - final AuthorizationDocument.Status status, - - @JsonProperty("email") - final String email, - - @JsonProperty("cc_emails") - final List ccEmails, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("sid") final String sid, + @JsonProperty("address_sid") final String addressSid, + @JsonProperty("status") final AuthorizationDocument.Status status, + @JsonProperty("email") final String email, + @JsonProperty("cc_emails") final List ccEmails, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.sid = sid; this.addressSid = addressSid; @@ -171,37 +169,45 @@ private AuthorizationDocument( this.links = links; } - public final String getSid() { - return this.sid; - } - public final String getAddressSid() { - return this.addressSid; - } - public final AuthorizationDocument.Status getStatus() { - return this.status; - } - public final String getEmail() { - return this.email; - } - public final List getCcEmails() { - return this.ccEmails; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getSid() { + return this.sid; + } + + public final String getAddressSid() { + return this.addressSid; + } + + public final AuthorizationDocument.Status getStatus() { + return this.status; + } + + public final String getEmail() { + return this.email; + } + + public final List getCcEmails() { + return this.ccEmails; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -211,13 +217,31 @@ public boolean equals(final Object o) { AuthorizationDocument other = (AuthorizationDocument) o; - return Objects.equals(sid, other.sid) && Objects.equals(addressSid, other.addressSid) && Objects.equals(status, other.status) && Objects.equals(email, other.email) && Objects.equals(ccEmails, other.ccEmails) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(addressSid, other.addressSid) && + Objects.equals(status, other.status) && + Objects.equals(email, other.email) && + Objects.equals(ccEmails, other.ccEmails) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(sid, addressSid, status, email, ccEmails, dateCreated, dateUpdated, url, links); + return Objects.hash( + sid, + addressSid, + status, + email, + ccEmails, + dateCreated, + dateUpdated, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/preview/hostedNumbers/AuthorizationDocumentCreator.java b/src/main/java/com/twilio/rest/preview/hostedNumbers/AuthorizationDocumentCreator.java index 50927ffdef..2ab5fbe84a 100644 --- a/src/main/java/com/twilio/rest/preview/hostedNumbers/AuthorizationDocumentCreator.java +++ b/src/main/java/com/twilio/rest/preview/hostedNumbers/AuthorizationDocumentCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.preview.hostedNumbers; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -25,12 +26,11 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.util.List; - import java.util.List; +public class AuthorizationDocumentCreator + extends Creator { - -public class AuthorizationDocumentCreator extends Creator{ private List hostedNumberOrderSids; private String addressSid; private String email; @@ -38,7 +38,13 @@ public class AuthorizationDocumentCreator extends Creator private String contactPhoneNumber; private List ccEmails; - public AuthorizationDocumentCreator(final List hostedNumberOrderSids, final String addressSid, final String email, final String contactTitle, final String contactPhoneNumber) { + public AuthorizationDocumentCreator( + final List hostedNumberOrderSids, + final String addressSid, + final String email, + final String contactTitle, + final String contactPhoneNumber + ) { this.hostedNumberOrderSids = hostedNumberOrderSids; this.addressSid = addressSid; this.email = email; @@ -46,94 +52,130 @@ public AuthorizationDocumentCreator(final List hostedNumberOrderSids, fi this.contactPhoneNumber = contactPhoneNumber; } - public AuthorizationDocumentCreator setHostedNumberOrderSids(final List hostedNumberOrderSids){ + public AuthorizationDocumentCreator setHostedNumberOrderSids( + final List hostedNumberOrderSids + ) { this.hostedNumberOrderSids = hostedNumberOrderSids; return this; } - public AuthorizationDocumentCreator setHostedNumberOrderSids(final String hostedNumberOrderSids){ - return setHostedNumberOrderSids(Promoter.listOfOne(hostedNumberOrderSids)); + + public AuthorizationDocumentCreator setHostedNumberOrderSids( + final String hostedNumberOrderSids + ) { + return setHostedNumberOrderSids( + Promoter.listOfOne(hostedNumberOrderSids) + ); } - public AuthorizationDocumentCreator setAddressSid(final String addressSid){ + + public AuthorizationDocumentCreator setAddressSid(final String addressSid) { this.addressSid = addressSid; return this; } - public AuthorizationDocumentCreator setEmail(final String email){ + + public AuthorizationDocumentCreator setEmail(final String email) { this.email = email; return this; } - public AuthorizationDocumentCreator setContactTitle(final String contactTitle){ + + public AuthorizationDocumentCreator setContactTitle( + final String contactTitle + ) { this.contactTitle = contactTitle; return this; } - public AuthorizationDocumentCreator setContactPhoneNumber(final String contactPhoneNumber){ + + public AuthorizationDocumentCreator setContactPhoneNumber( + final String contactPhoneNumber + ) { this.contactPhoneNumber = contactPhoneNumber; return this; } - public AuthorizationDocumentCreator setCcEmails(final List ccEmails){ + + public AuthorizationDocumentCreator setCcEmails( + final List ccEmails + ) { this.ccEmails = ccEmails; return this; } - public AuthorizationDocumentCreator setCcEmails(final String ccEmails){ + + public AuthorizationDocumentCreator setCcEmails(final String ccEmails) { return setCcEmails(Promoter.listOfOne(ccEmails)); } @Override - public AuthorizationDocument create(final TwilioRestClient client){ + public AuthorizationDocument create(final TwilioRestClient client) { String path = "/HostedNumbers/AuthorizationDocuments"; - path = path.replace("{"+"HostedNumberOrderSids"+"}", this.hostedNumberOrderSids.toString()); - path = path.replace("{"+"AddressSid"+"}", this.addressSid.toString()); - path = path.replace("{"+"Email"+"}", this.email.toString()); - path = path.replace("{"+"ContactTitle"+"}", this.contactTitle.toString()); - path = path.replace("{"+"ContactPhoneNumber"+"}", this.contactPhoneNumber.toString()); + path = + path.replace( + "{" + "HostedNumberOrderSids" + "}", + this.hostedNumberOrderSids.toString() + ); + path = + path.replace("{" + "AddressSid" + "}", this.addressSid.toString()); + path = path.replace("{" + "Email" + "}", this.email.toString()); + path = + path.replace( + "{" + "ContactTitle" + "}", + this.contactTitle.toString() + ); + path = + path.replace( + "{" + "ContactPhoneNumber" + "}", + this.contactPhoneNumber.toString() + ); Request request = new Request( HttpMethod.POST, Domains.PREVIEW.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AuthorizationDocument creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "AuthorizationDocument creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return AuthorizationDocument.fromJson(response.getStream(), client.getObjectMapper()); + return AuthorizationDocument.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (hostedNumberOrderSids != null) { for (String prop : hostedNumberOrderSids) { request.addPostParam("HostedNumberOrderSids", prop); } - } if (addressSid != null) { request.addPostParam("AddressSid", addressSid); - } if (email != null) { request.addPostParam("Email", email); - } if (contactTitle != null) { request.addPostParam("ContactTitle", contactTitle); - } if (contactPhoneNumber != null) { request.addPostParam("ContactPhoneNumber", contactPhoneNumber); - } if (ccEmails != null) { for (String prop : ccEmails) { request.addPostParam("CcEmails", prop); } - } } } diff --git a/src/main/java/com/twilio/rest/preview/hostedNumbers/AuthorizationDocumentFetcher.java b/src/main/java/com/twilio/rest/preview/hostedNumbers/AuthorizationDocumentFetcher.java index 1c49f9bd46..2b5c8c61e2 100644 --- a/src/main/java/com/twilio/rest/preview/hostedNumbers/AuthorizationDocumentFetcher.java +++ b/src/main/java/com/twilio/rest/preview/hostedNumbers/AuthorizationDocumentFetcher.java @@ -24,22 +24,20 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class AuthorizationDocumentFetcher + extends Fetcher { - - -public class AuthorizationDocumentFetcher extends Fetcher { private String pathSid; - public AuthorizationDocumentFetcher(final String pathSid){ + public AuthorizationDocumentFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public AuthorizationDocument fetch(final TwilioRestClient client) { String path = "/HostedNumbers/AuthorizationDocuments/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,15 +47,23 @@ public AuthorizationDocument fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AuthorizationDocument fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "AuthorizationDocument fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return AuthorizationDocument.fromJson(response.getStream(), client.getObjectMapper()); + return AuthorizationDocument.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/preview/hostedNumbers/AuthorizationDocumentReader.java b/src/main/java/com/twilio/rest/preview/hostedNumbers/AuthorizationDocumentReader.java index 5d6fd27817..141396d5d5 100644 --- a/src/main/java/com/twilio/rest/preview/hostedNumbers/AuthorizationDocumentReader.java +++ b/src/main/java/com/twilio/rest/preview/hostedNumbers/AuthorizationDocumentReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.preview.hostedNumbers; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,37 +25,42 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class AuthorizationDocumentReader extends Reader { + private String email; private AuthorizationDocument.Status status; private Integer pageSize; - public AuthorizationDocumentReader(){ - } + public AuthorizationDocumentReader() {} - public AuthorizationDocumentReader setEmail(final String email){ + public AuthorizationDocumentReader setEmail(final String email) { this.email = email; return this; } - public AuthorizationDocumentReader setStatus(final AuthorizationDocument.Status status){ + + public AuthorizationDocumentReader setStatus( + final AuthorizationDocument.Status status + ) { this.status = status; return this; } - public AuthorizationDocumentReader setPageSize(final Integer pageSize){ + + public AuthorizationDocumentReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @Override - public ResourceSet read(final TwilioRestClient client) { + public ResourceSet read( + final TwilioRestClient client + ) { return new ResourceSet<>(this, client, firstPage(client)); } - public Page firstPage(final TwilioRestClient client) { + public Page firstPage( + final TwilioRestClient client + ) { String path = "/HostedNumbers/AuthorizationDocuments"; Request request = new Request( @@ -67,13 +73,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AuthorizationDocument read failed: Unable to connect to server"); + throw new ApiConnectionException( + "AuthorizationDocument read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -89,7 +103,10 @@ private Page pageForRequest(final TwilioRestClient client } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.PREVIEW.toString()) @@ -97,9 +114,11 @@ public Page previousPage(final Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.PREVIEW.toString()) @@ -108,29 +127,27 @@ public Page nextPage(final Page pa } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (email != null) { - request.addQueryParam("Email", email); } if (status != null) { - request.addQueryParam("Status", status.toString()); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/preview/hostedNumbers/AuthorizationDocumentUpdater.java b/src/main/java/com/twilio/rest/preview/hostedNumbers/AuthorizationDocumentUpdater.java index 7712fde0a6..d301eb30a3 100644 --- a/src/main/java/com/twilio/rest/preview/hostedNumbers/AuthorizationDocumentUpdater.java +++ b/src/main/java/com/twilio/rest/preview/hostedNumbers/AuthorizationDocumentUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.preview.hostedNumbers; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -24,12 +25,11 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - import java.util.List; +public class AuthorizationDocumentUpdater + extends Updater { -public class AuthorizationDocumentUpdater extends Updater{ private String pathSid; private List hostedNumberOrderSids; private String addressSid; @@ -39,102 +39,127 @@ public class AuthorizationDocumentUpdater extends Updater private String contactTitle; private String contactPhoneNumber; - public AuthorizationDocumentUpdater(final String pathSid){ + public AuthorizationDocumentUpdater(final String pathSid) { this.pathSid = pathSid; } - public AuthorizationDocumentUpdater setHostedNumberOrderSids(final List hostedNumberOrderSids){ + public AuthorizationDocumentUpdater setHostedNumberOrderSids( + final List hostedNumberOrderSids + ) { this.hostedNumberOrderSids = hostedNumberOrderSids; return this; } - public AuthorizationDocumentUpdater setHostedNumberOrderSids(final String hostedNumberOrderSids){ - return setHostedNumberOrderSids(Promoter.listOfOne(hostedNumberOrderSids)); + + public AuthorizationDocumentUpdater setHostedNumberOrderSids( + final String hostedNumberOrderSids + ) { + return setHostedNumberOrderSids( + Promoter.listOfOne(hostedNumberOrderSids) + ); } - public AuthorizationDocumentUpdater setAddressSid(final String addressSid){ + + public AuthorizationDocumentUpdater setAddressSid(final String addressSid) { this.addressSid = addressSid; return this; } - public AuthorizationDocumentUpdater setEmail(final String email){ + + public AuthorizationDocumentUpdater setEmail(final String email) { this.email = email; return this; } - public AuthorizationDocumentUpdater setCcEmails(final List ccEmails){ + + public AuthorizationDocumentUpdater setCcEmails( + final List ccEmails + ) { this.ccEmails = ccEmails; return this; } - public AuthorizationDocumentUpdater setCcEmails(final String ccEmails){ + + public AuthorizationDocumentUpdater setCcEmails(final String ccEmails) { return setCcEmails(Promoter.listOfOne(ccEmails)); } - public AuthorizationDocumentUpdater setStatus(final AuthorizationDocument.Status status){ + + public AuthorizationDocumentUpdater setStatus( + final AuthorizationDocument.Status status + ) { this.status = status; return this; } - public AuthorizationDocumentUpdater setContactTitle(final String contactTitle){ + + public AuthorizationDocumentUpdater setContactTitle( + final String contactTitle + ) { this.contactTitle = contactTitle; return this; } - public AuthorizationDocumentUpdater setContactPhoneNumber(final String contactPhoneNumber){ + + public AuthorizationDocumentUpdater setContactPhoneNumber( + final String contactPhoneNumber + ) { this.contactPhoneNumber = contactPhoneNumber; return this; } @Override - public AuthorizationDocument update(final TwilioRestClient client){ + public AuthorizationDocument update(final TwilioRestClient client) { String path = "/HostedNumbers/AuthorizationDocuments/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.PREVIEW.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AuthorizationDocument update failed: Unable to connect to server"); + throw new ApiConnectionException( + "AuthorizationDocument update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return AuthorizationDocument.fromJson(response.getStream(), client.getObjectMapper()); + return AuthorizationDocument.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (hostedNumberOrderSids != null) { for (String prop : hostedNumberOrderSids) { request.addPostParam("HostedNumberOrderSids", prop); } - } if (addressSid != null) { request.addPostParam("AddressSid", addressSid); - } if (email != null) { request.addPostParam("Email", email); - } if (ccEmails != null) { for (String prop : ccEmails) { request.addPostParam("CcEmails", prop); } - } if (status != null) { request.addPostParam("Status", status.toString()); - } if (contactTitle != null) { request.addPostParam("ContactTitle", contactTitle); - } if (contactPhoneNumber != null) { request.addPostParam("ContactPhoneNumber", contactPhoneNumber); - } } } diff --git a/src/main/java/com/twilio/rest/preview/hostedNumbers/HostedNumberOrder.java b/src/main/java/com/twilio/rest/preview/hostedNumbers/HostedNumberOrder.java index 5966ba09d8..23d24c5102 100644 --- a/src/main/java/com/twilio/rest/preview/hostedNumbers/HostedNumberOrder.java +++ b/src/main/java/com/twilio/rest/preview/hostedNumbers/HostedNumberOrder.java @@ -24,55 +24,57 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - +import com.twilio.type.PhoneNumberCapabilities; import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.List; import java.util.Objects; - - -import com.twilio.type.PhoneNumberCapabilities; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class HostedNumberOrder extends Resource { + private static final long serialVersionUID = 7609372871434L; - public static HostedNumberOrderCreator creator(final com.twilio.type.PhoneNumber phoneNumber, final Boolean smsCapability){ + public static HostedNumberOrderCreator creator( + final com.twilio.type.PhoneNumber phoneNumber, + final Boolean smsCapability + ) { return new HostedNumberOrderCreator(phoneNumber, smsCapability); } - public static HostedNumberOrderDeleter deleter(final String pathSid){ + public static HostedNumberOrderDeleter deleter(final String pathSid) { return new HostedNumberOrderDeleter(pathSid); } - public static HostedNumberOrderFetcher fetcher(final String pathSid){ + public static HostedNumberOrderFetcher fetcher(final String pathSid) { return new HostedNumberOrderFetcher(pathSid); } - public static HostedNumberOrderReader reader(){ + public static HostedNumberOrderReader reader() { return new HostedNumberOrderReader(); } - public static HostedNumberOrderUpdater updater(final String pathSid){ + public static HostedNumberOrderUpdater updater(final String pathSid) { return new HostedNumberOrderUpdater(pathSid); } /** - * Converts a JSON String into a HostedNumberOrder object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return HostedNumberOrder object represented by the provided JSON - */ - public static HostedNumberOrder fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a HostedNumberOrder object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return HostedNumberOrder object represented by the provided JSON + */ + public static HostedNumberOrder fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, HostedNumberOrder.class); @@ -84,14 +86,17 @@ public static HostedNumberOrder fromJson(final String json, final ObjectMapper o } /** - * Converts a JSON InputStream into a HostedNumberOrder object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return HostedNumberOrder object represented by the provided JSON - */ - public static HostedNumberOrder fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a HostedNumberOrder object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return HostedNumberOrder object represented by the provided JSON + */ + public static HostedNumberOrder fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, HostedNumberOrder.class); @@ -101,6 +106,7 @@ public static HostedNumberOrder fromJson(final InputStream json, final ObjectMap throw new ApiConnectionException(e.getMessage(), e); } } + public enum Status { RECEIVED("received"), PENDING_VERIFICATION("pending-verification"), @@ -127,6 +133,7 @@ public static Status forValue(final String value) { return Promoter.enumFromString(value, Status.values()); } } + public enum VerificationType { PHONE_CALL("phone-call"), PHONE_BILL("phone-bill"); @@ -173,74 +180,43 @@ public static VerificationType forValue(final String value) { @JsonCreator private HostedNumberOrder( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("incoming_phone_number_sid") - final String incomingPhoneNumberSid, - - @JsonProperty("address_sid") - final String addressSid, - - @JsonProperty("signing_document_sid") - final String signingDocumentSid, - - @JsonProperty("phone_number") - final com.twilio.type.PhoneNumber phoneNumber, - - @JsonProperty("capabilities") - final PhoneNumberCapabilities capabilities, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("unique_name") - final String uniqueName, - - @JsonProperty("status") - final HostedNumberOrder.Status status, - - @JsonProperty("failure_reason") - final String failureReason, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("verification_attempts") - final Integer verificationAttempts, - - @JsonProperty("email") - final String email, - - @JsonProperty("cc_emails") - final List ccEmails, - - @JsonProperty("url") - final URI url, - - @JsonProperty("verification_type") - final HostedNumberOrder.VerificationType verificationType, - - @JsonProperty("verification_document_sid") - final String verificationDocumentSid, - - @JsonProperty("extension") - final String extension, - - @JsonProperty("call_delay") - final Integer callDelay, - - @JsonProperty("verification_code") - final String verificationCode, - - @JsonProperty("verification_call_sids") - final List verificationCallSids + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty( + "incoming_phone_number_sid" + ) final String incomingPhoneNumberSid, + @JsonProperty("address_sid") final String addressSid, + @JsonProperty("signing_document_sid") final String signingDocumentSid, + @JsonProperty( + "phone_number" + ) final com.twilio.type.PhoneNumber phoneNumber, + @JsonProperty( + "capabilities" + ) final PhoneNumberCapabilities capabilities, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("status") final HostedNumberOrder.Status status, + @JsonProperty("failure_reason") final String failureReason, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty( + "verification_attempts" + ) final Integer verificationAttempts, + @JsonProperty("email") final String email, + @JsonProperty("cc_emails") final List ccEmails, + @JsonProperty("url") final URI url, + @JsonProperty( + "verification_type" + ) final HostedNumberOrder.VerificationType verificationType, + @JsonProperty( + "verification_document_sid" + ) final String verificationDocumentSid, + @JsonProperty("extension") final String extension, + @JsonProperty("call_delay") final Integer callDelay, + @JsonProperty("verification_code") final String verificationCode, + @JsonProperty( + "verification_call_sids" + ) final List verificationCallSids ) { this.sid = sid; this.accountSid = accountSid; @@ -267,79 +243,101 @@ private HostedNumberOrder( this.verificationCallSids = verificationCallSids; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getIncomingPhoneNumberSid() { - return this.incomingPhoneNumberSid; - } - public final String getAddressSid() { - return this.addressSid; - } - public final String getSigningDocumentSid() { - return this.signingDocumentSid; - } - public final com.twilio.type.PhoneNumber getPhoneNumber() { - return this.phoneNumber; - } - public final PhoneNumberCapabilities getCapabilities() { - return this.capabilities; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getUniqueName() { - return this.uniqueName; - } - public final HostedNumberOrder.Status getStatus() { - return this.status; - } - public final String getFailureReason() { - return this.failureReason; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final Integer getVerificationAttempts() { - return this.verificationAttempts; - } - public final String getEmail() { - return this.email; - } - public final List getCcEmails() { - return this.ccEmails; - } - public final URI getUrl() { - return this.url; - } - public final HostedNumberOrder.VerificationType getVerificationType() { - return this.verificationType; - } - public final String getVerificationDocumentSid() { - return this.verificationDocumentSid; - } - public final String getExtension() { - return this.extension; - } - public final Integer getCallDelay() { - return this.callDelay; - } - public final String getVerificationCode() { - return this.verificationCode; - } - public final List getVerificationCallSids() { - return this.verificationCallSids; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getIncomingPhoneNumberSid() { + return this.incomingPhoneNumberSid; + } + + public final String getAddressSid() { + return this.addressSid; + } + + public final String getSigningDocumentSid() { + return this.signingDocumentSid; + } + + public final com.twilio.type.PhoneNumber getPhoneNumber() { + return this.phoneNumber; + } + + public final PhoneNumberCapabilities getCapabilities() { + return this.capabilities; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getUniqueName() { + return this.uniqueName; + } + + public final HostedNumberOrder.Status getStatus() { + return this.status; + } + + public final String getFailureReason() { + return this.failureReason; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final Integer getVerificationAttempts() { + return this.verificationAttempts; + } + + public final String getEmail() { + return this.email; + } + + public final List getCcEmails() { + return this.ccEmails; + } + + public final URI getUrl() { + return this.url; + } + + public final HostedNumberOrder.VerificationType getVerificationType() { + return this.verificationType; + } + + public final String getVerificationDocumentSid() { + return this.verificationDocumentSid; + } + + public final String getExtension() { + return this.extension; + } + + public final Integer getCallDelay() { + return this.callDelay; + } + + public final String getVerificationCode() { + return this.verificationCode; + } + + public final List getVerificationCallSids() { + return this.verificationCallSids; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -349,13 +347,65 @@ public boolean equals(final Object o) { HostedNumberOrder other = (HostedNumberOrder) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(incomingPhoneNumberSid, other.incomingPhoneNumberSid) && Objects.equals(addressSid, other.addressSid) && Objects.equals(signingDocumentSid, other.signingDocumentSid) && Objects.equals(phoneNumber, other.phoneNumber) && Objects.equals(capabilities, other.capabilities) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(uniqueName, other.uniqueName) && Objects.equals(status, other.status) && Objects.equals(failureReason, other.failureReason) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(verificationAttempts, other.verificationAttempts) && Objects.equals(email, other.email) && Objects.equals(ccEmails, other.ccEmails) && Objects.equals(url, other.url) && Objects.equals(verificationType, other.verificationType) && Objects.equals(verificationDocumentSid, other.verificationDocumentSid) && Objects.equals(extension, other.extension) && Objects.equals(callDelay, other.callDelay) && Objects.equals(verificationCode, other.verificationCode) && Objects.equals(verificationCallSids, other.verificationCallSids) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals( + incomingPhoneNumberSid, + other.incomingPhoneNumberSid + ) && + Objects.equals(addressSid, other.addressSid) && + Objects.equals(signingDocumentSid, other.signingDocumentSid) && + Objects.equals(phoneNumber, other.phoneNumber) && + Objects.equals(capabilities, other.capabilities) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(status, other.status) && + Objects.equals(failureReason, other.failureReason) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(verificationAttempts, other.verificationAttempts) && + Objects.equals(email, other.email) && + Objects.equals(ccEmails, other.ccEmails) && + Objects.equals(url, other.url) && + Objects.equals(verificationType, other.verificationType) && + Objects.equals( + verificationDocumentSid, + other.verificationDocumentSid + ) && + Objects.equals(extension, other.extension) && + Objects.equals(callDelay, other.callDelay) && + Objects.equals(verificationCode, other.verificationCode) && + Objects.equals(verificationCallSids, other.verificationCallSids) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, incomingPhoneNumberSid, addressSid, signingDocumentSid, phoneNumber, capabilities, friendlyName, uniqueName, status, failureReason, dateCreated, dateUpdated, verificationAttempts, email, ccEmails, url, verificationType, verificationDocumentSid, extension, callDelay, verificationCode, verificationCallSids); + return Objects.hash( + sid, + accountSid, + incomingPhoneNumberSid, + addressSid, + signingDocumentSid, + phoneNumber, + capabilities, + friendlyName, + uniqueName, + status, + failureReason, + dateCreated, + dateUpdated, + verificationAttempts, + email, + ccEmails, + url, + verificationType, + verificationDocumentSid, + extension, + callDelay, + verificationCode, + verificationCallSids + ); } - } - diff --git a/src/main/java/com/twilio/rest/preview/hostedNumbers/HostedNumberOrderCreator.java b/src/main/java/com/twilio/rest/preview/hostedNumbers/HostedNumberOrderCreator.java index 78a0cb442a..65e1a419ea 100644 --- a/src/main/java/com/twilio/rest/preview/hostedNumbers/HostedNumberOrderCreator.java +++ b/src/main/java/com/twilio/rest/preview/hostedNumbers/HostedNumberOrderCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.preview.hostedNumbers; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -24,15 +25,13 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import java.util.List; import java.net.URI; - +import java.net.URI; +import java.util.List; import java.util.List; +public class HostedNumberOrderCreator extends Creator { -import java.net.URI; - -public class HostedNumberOrderCreator extends Creator{ private com.twilio.type.PhoneNumber phoneNumber; private Boolean smsCapability; private String accountSid; @@ -51,195 +50,253 @@ public class HostedNumberOrderCreator extends Creator{ private HostedNumberOrder.VerificationType verificationType; private String verificationDocumentSid; - public HostedNumberOrderCreator(final com.twilio.type.PhoneNumber phoneNumber, final Boolean smsCapability) { + public HostedNumberOrderCreator( + final com.twilio.type.PhoneNumber phoneNumber, + final Boolean smsCapability + ) { this.phoneNumber = phoneNumber; this.smsCapability = smsCapability; } - public HostedNumberOrderCreator setPhoneNumber(final com.twilio.type.PhoneNumber phoneNumber){ + public HostedNumberOrderCreator setPhoneNumber( + final com.twilio.type.PhoneNumber phoneNumber + ) { this.phoneNumber = phoneNumber; return this; } - public HostedNumberOrderCreator setPhoneNumber(final String phoneNumber){ + public HostedNumberOrderCreator setPhoneNumber(final String phoneNumber) { return setPhoneNumber(Promoter.phoneNumberFromString(phoneNumber)); } - public HostedNumberOrderCreator setSmsCapability(final Boolean smsCapability){ + + public HostedNumberOrderCreator setSmsCapability( + final Boolean smsCapability + ) { this.smsCapability = smsCapability; return this; } - public HostedNumberOrderCreator setAccountSid(final String accountSid){ + + public HostedNumberOrderCreator setAccountSid(final String accountSid) { this.accountSid = accountSid; return this; } - public HostedNumberOrderCreator setFriendlyName(final String friendlyName){ + + public HostedNumberOrderCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public HostedNumberOrderCreator setUniqueName(final String uniqueName){ + + public HostedNumberOrderCreator setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - public HostedNumberOrderCreator setCcEmails(final List ccEmails){ + + public HostedNumberOrderCreator setCcEmails(final List ccEmails) { this.ccEmails = ccEmails; return this; } - public HostedNumberOrderCreator setCcEmails(final String ccEmails){ + + public HostedNumberOrderCreator setCcEmails(final String ccEmails) { return setCcEmails(Promoter.listOfOne(ccEmails)); } - public HostedNumberOrderCreator setSmsUrl(final URI smsUrl){ + + public HostedNumberOrderCreator setSmsUrl(final URI smsUrl) { this.smsUrl = smsUrl; return this; } - public HostedNumberOrderCreator setSmsUrl(final String smsUrl){ + public HostedNumberOrderCreator setSmsUrl(final String smsUrl) { return setSmsUrl(Promoter.uriFromString(smsUrl)); } - public HostedNumberOrderCreator setSmsMethod(final HttpMethod smsMethod){ + + public HostedNumberOrderCreator setSmsMethod(final HttpMethod smsMethod) { this.smsMethod = smsMethod; return this; } - public HostedNumberOrderCreator setSmsFallbackUrl(final URI smsFallbackUrl){ + + public HostedNumberOrderCreator setSmsFallbackUrl( + final URI smsFallbackUrl + ) { this.smsFallbackUrl = smsFallbackUrl; return this; } - public HostedNumberOrderCreator setSmsFallbackUrl(final String smsFallbackUrl){ + public HostedNumberOrderCreator setSmsFallbackUrl( + final String smsFallbackUrl + ) { return setSmsFallbackUrl(Promoter.uriFromString(smsFallbackUrl)); } - public HostedNumberOrderCreator setSmsFallbackMethod(final HttpMethod smsFallbackMethod){ + + public HostedNumberOrderCreator setSmsFallbackMethod( + final HttpMethod smsFallbackMethod + ) { this.smsFallbackMethod = smsFallbackMethod; return this; } - public HostedNumberOrderCreator setStatusCallbackUrl(final URI statusCallbackUrl){ + + public HostedNumberOrderCreator setStatusCallbackUrl( + final URI statusCallbackUrl + ) { this.statusCallbackUrl = statusCallbackUrl; return this; } - public HostedNumberOrderCreator setStatusCallbackUrl(final String statusCallbackUrl){ + public HostedNumberOrderCreator setStatusCallbackUrl( + final String statusCallbackUrl + ) { return setStatusCallbackUrl(Promoter.uriFromString(statusCallbackUrl)); } - public HostedNumberOrderCreator setStatusCallbackMethod(final HttpMethod statusCallbackMethod){ + + public HostedNumberOrderCreator setStatusCallbackMethod( + final HttpMethod statusCallbackMethod + ) { this.statusCallbackMethod = statusCallbackMethod; return this; } - public HostedNumberOrderCreator setSmsApplicationSid(final String smsApplicationSid){ + + public HostedNumberOrderCreator setSmsApplicationSid( + final String smsApplicationSid + ) { this.smsApplicationSid = smsApplicationSid; return this; } - public HostedNumberOrderCreator setAddressSid(final String addressSid){ + + public HostedNumberOrderCreator setAddressSid(final String addressSid) { this.addressSid = addressSid; return this; } - public HostedNumberOrderCreator setEmail(final String email){ + + public HostedNumberOrderCreator setEmail(final String email) { this.email = email; return this; } - public HostedNumberOrderCreator setVerificationType(final HostedNumberOrder.VerificationType verificationType){ + + public HostedNumberOrderCreator setVerificationType( + final HostedNumberOrder.VerificationType verificationType + ) { this.verificationType = verificationType; return this; } - public HostedNumberOrderCreator setVerificationDocumentSid(final String verificationDocumentSid){ + + public HostedNumberOrderCreator setVerificationDocumentSid( + final String verificationDocumentSid + ) { this.verificationDocumentSid = verificationDocumentSid; return this; } @Override - public HostedNumberOrder create(final TwilioRestClient client){ + public HostedNumberOrder create(final TwilioRestClient client) { String path = "/HostedNumbers/HostedNumberOrders"; - path = path.replace("{"+"PhoneNumber"+"}", this.phoneNumber.encode("utf-8")); - path = path.replace("{"+"SmsCapability"+"}", this.smsCapability.toString()); + path = + path.replace( + "{" + "PhoneNumber" + "}", + this.phoneNumber.encode("utf-8") + ); + path = + path.replace( + "{" + "SmsCapability" + "}", + this.smsCapability.toString() + ); Request request = new Request( HttpMethod.POST, Domains.PREVIEW.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("HostedNumberOrder creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "HostedNumberOrder creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return HostedNumberOrder.fromJson(response.getStream(), client.getObjectMapper()); + return HostedNumberOrder.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (phoneNumber != null) { request.addPostParam("PhoneNumber", phoneNumber.toString()); - } if (smsCapability != null) { request.addPostParam("SmsCapability", smsCapability.toString()); - } if (accountSid != null) { request.addPostParam("AccountSid", accountSid); - } if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (uniqueName != null) { request.addPostParam("UniqueName", uniqueName); - } if (ccEmails != null) { for (String prop : ccEmails) { request.addPostParam("CcEmails", prop); } - } if (smsUrl != null) { request.addPostParam("SmsUrl", smsUrl.toString()); - } if (smsMethod != null) { request.addPostParam("SmsMethod", smsMethod.toString()); - } if (smsFallbackUrl != null) { request.addPostParam("SmsFallbackUrl", smsFallbackUrl.toString()); - } if (smsFallbackMethod != null) { - request.addPostParam("SmsFallbackMethod", smsFallbackMethod.toString()); - + request.addPostParam( + "SmsFallbackMethod", + smsFallbackMethod.toString() + ); } if (statusCallbackUrl != null) { - request.addPostParam("StatusCallbackUrl", statusCallbackUrl.toString()); - + request.addPostParam( + "StatusCallbackUrl", + statusCallbackUrl.toString() + ); } if (statusCallbackMethod != null) { - request.addPostParam("StatusCallbackMethod", statusCallbackMethod.toString()); - + request.addPostParam( + "StatusCallbackMethod", + statusCallbackMethod.toString() + ); } if (smsApplicationSid != null) { request.addPostParam("SmsApplicationSid", smsApplicationSid); - } if (addressSid != null) { request.addPostParam("AddressSid", addressSid); - } if (email != null) { request.addPostParam("Email", email); - } if (verificationType != null) { - request.addPostParam("VerificationType", verificationType.toString()); - + request.addPostParam( + "VerificationType", + verificationType.toString() + ); } if (verificationDocumentSid != null) { - request.addPostParam("VerificationDocumentSid", verificationDocumentSid); - + request.addPostParam( + "VerificationDocumentSid", + verificationDocumentSid + ); } } } diff --git a/src/main/java/com/twilio/rest/preview/hostedNumbers/HostedNumberOrderDeleter.java b/src/main/java/com/twilio/rest/preview/hostedNumbers/HostedNumberOrderDeleter.java index fdbfb79545..47f3af0c6c 100644 --- a/src/main/java/com/twilio/rest/preview/hostedNumbers/HostedNumberOrderDeleter.java +++ b/src/main/java/com/twilio/rest/preview/hostedNumbers/HostedNumberOrderDeleter.java @@ -24,21 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class HostedNumberOrderDeleter extends Deleter { + private String pathSid; - public HostedNumberOrderDeleter(final String pathSid){ + public HostedNumberOrderDeleter(final String pathSid) { this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/HostedNumbers/HostedNumberOrders/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -48,9 +46,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("HostedNumberOrder delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "HostedNumberOrder delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/preview/hostedNumbers/HostedNumberOrderFetcher.java b/src/main/java/com/twilio/rest/preview/hostedNumbers/HostedNumberOrderFetcher.java index 2363645a03..b7d07fec2f 100644 --- a/src/main/java/com/twilio/rest/preview/hostedNumbers/HostedNumberOrderFetcher.java +++ b/src/main/java/com/twilio/rest/preview/hostedNumbers/HostedNumberOrderFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class HostedNumberOrderFetcher extends Fetcher { + private String pathSid; - public HostedNumberOrderFetcher(final String pathSid){ + public HostedNumberOrderFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public HostedNumberOrder fetch(final TwilioRestClient client) { String path = "/HostedNumbers/HostedNumberOrders/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,15 +46,23 @@ public HostedNumberOrder fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("HostedNumberOrder fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "HostedNumberOrder fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return HostedNumberOrder.fromJson(response.getStream(), client.getObjectMapper()); + return HostedNumberOrder.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/preview/hostedNumbers/HostedNumberOrderReader.java b/src/main/java/com/twilio/rest/preview/hostedNumbers/HostedNumberOrderReader.java index db951e6012..fe7ebd5615 100644 --- a/src/main/java/com/twilio/rest/preview/hostedNumbers/HostedNumberOrderReader.java +++ b/src/main/java/com/twilio/rest/preview/hostedNumbers/HostedNumberOrderReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.preview.hostedNumbers; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.converter.Promoter; @@ -25,11 +26,9 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class HostedNumberOrderReader extends Reader { + private HostedNumberOrder.Status status; private com.twilio.type.PhoneNumber phoneNumber; private String incomingPhoneNumberSid; @@ -37,34 +36,44 @@ public class HostedNumberOrderReader extends Reader { private String uniqueName; private Integer pageSize; - public HostedNumberOrderReader(){ - } + public HostedNumberOrderReader() {} - public HostedNumberOrderReader setStatus(final HostedNumberOrder.Status status){ + public HostedNumberOrderReader setStatus( + final HostedNumberOrder.Status status + ) { this.status = status; return this; } - public HostedNumberOrderReader setPhoneNumber(final com.twilio.type.PhoneNumber phoneNumber){ + + public HostedNumberOrderReader setPhoneNumber( + final com.twilio.type.PhoneNumber phoneNumber + ) { this.phoneNumber = phoneNumber; return this; } - public HostedNumberOrderReader setPhoneNumber(final String phoneNumber){ + public HostedNumberOrderReader setPhoneNumber(final String phoneNumber) { return setPhoneNumber(Promoter.phoneNumberFromString(phoneNumber)); } - public HostedNumberOrderReader setIncomingPhoneNumberSid(final String incomingPhoneNumberSid){ + + public HostedNumberOrderReader setIncomingPhoneNumberSid( + final String incomingPhoneNumberSid + ) { this.incomingPhoneNumberSid = incomingPhoneNumberSid; return this; } - public HostedNumberOrderReader setFriendlyName(final String friendlyName){ + + public HostedNumberOrderReader setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public HostedNumberOrderReader setUniqueName(final String uniqueName){ + + public HostedNumberOrderReader setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - public HostedNumberOrderReader setPageSize(final Integer pageSize){ + + public HostedNumberOrderReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -87,13 +96,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("HostedNumberOrder read failed: Unable to connect to server"); + throw new ApiConnectionException( + "HostedNumberOrder read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -109,7 +126,10 @@ private Page pageForRequest(final TwilioRestClient client, fi } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.PREVIEW.toString()) @@ -117,9 +137,11 @@ public Page previousPage(final Page page, return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.PREVIEW.toString()) @@ -128,41 +150,39 @@ public Page nextPage(final Page page, fina } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (status != null) { - request.addQueryParam("Status", status.toString()); } if (phoneNumber != null) { - request.addQueryParam("PhoneNumber", phoneNumber.toString()); } if (incomingPhoneNumberSid != null) { - - request.addQueryParam("IncomingPhoneNumberSid", incomingPhoneNumberSid); + request.addQueryParam( + "IncomingPhoneNumberSid", + incomingPhoneNumberSid + ); } if (friendlyName != null) { - request.addQueryParam("FriendlyName", friendlyName); } if (uniqueName != null) { - request.addQueryParam("UniqueName", uniqueName); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/preview/hostedNumbers/HostedNumberOrderUpdater.java b/src/main/java/com/twilio/rest/preview/hostedNumbers/HostedNumberOrderUpdater.java index 1f48e9d651..ea00e76699 100644 --- a/src/main/java/com/twilio/rest/preview/hostedNumbers/HostedNumberOrderUpdater.java +++ b/src/main/java/com/twilio/rest/preview/hostedNumbers/HostedNumberOrderUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.preview.hostedNumbers; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -24,12 +25,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - import java.util.List; +public class HostedNumberOrderUpdater extends Updater { -public class HostedNumberOrderUpdater extends Updater{ private String pathSid; private String friendlyName; private String uniqueName; @@ -42,121 +41,145 @@ public class HostedNumberOrderUpdater extends Updater{ private String extension; private Integer callDelay; - public HostedNumberOrderUpdater(final String pathSid){ + public HostedNumberOrderUpdater(final String pathSid) { this.pathSid = pathSid; } - public HostedNumberOrderUpdater setFriendlyName(final String friendlyName){ + public HostedNumberOrderUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public HostedNumberOrderUpdater setUniqueName(final String uniqueName){ + + public HostedNumberOrderUpdater setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - public HostedNumberOrderUpdater setEmail(final String email){ + + public HostedNumberOrderUpdater setEmail(final String email) { this.email = email; return this; } - public HostedNumberOrderUpdater setCcEmails(final List ccEmails){ + + public HostedNumberOrderUpdater setCcEmails(final List ccEmails) { this.ccEmails = ccEmails; return this; } - public HostedNumberOrderUpdater setCcEmails(final String ccEmails){ + + public HostedNumberOrderUpdater setCcEmails(final String ccEmails) { return setCcEmails(Promoter.listOfOne(ccEmails)); } - public HostedNumberOrderUpdater setStatus(final HostedNumberOrder.Status status){ + + public HostedNumberOrderUpdater setStatus( + final HostedNumberOrder.Status status + ) { this.status = status; return this; } - public HostedNumberOrderUpdater setVerificationCode(final String verificationCode){ + + public HostedNumberOrderUpdater setVerificationCode( + final String verificationCode + ) { this.verificationCode = verificationCode; return this; } - public HostedNumberOrderUpdater setVerificationType(final HostedNumberOrder.VerificationType verificationType){ + + public HostedNumberOrderUpdater setVerificationType( + final HostedNumberOrder.VerificationType verificationType + ) { this.verificationType = verificationType; return this; } - public HostedNumberOrderUpdater setVerificationDocumentSid(final String verificationDocumentSid){ + + public HostedNumberOrderUpdater setVerificationDocumentSid( + final String verificationDocumentSid + ) { this.verificationDocumentSid = verificationDocumentSid; return this; } - public HostedNumberOrderUpdater setExtension(final String extension){ + + public HostedNumberOrderUpdater setExtension(final String extension) { this.extension = extension; return this; } - public HostedNumberOrderUpdater setCallDelay(final Integer callDelay){ + + public HostedNumberOrderUpdater setCallDelay(final Integer callDelay) { this.callDelay = callDelay; return this; } @Override - public HostedNumberOrder update(final TwilioRestClient client){ + public HostedNumberOrder update(final TwilioRestClient client) { String path = "/HostedNumbers/HostedNumberOrders/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.PREVIEW.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("HostedNumberOrder update failed: Unable to connect to server"); + throw new ApiConnectionException( + "HostedNumberOrder update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return HostedNumberOrder.fromJson(response.getStream(), client.getObjectMapper()); + return HostedNumberOrder.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (uniqueName != null) { request.addPostParam("UniqueName", uniqueName); - } if (email != null) { request.addPostParam("Email", email); - } if (ccEmails != null) { for (String prop : ccEmails) { request.addPostParam("CcEmails", prop); } - } if (status != null) { request.addPostParam("Status", status.toString()); - } if (verificationCode != null) { request.addPostParam("VerificationCode", verificationCode); - } if (verificationType != null) { - request.addPostParam("VerificationType", verificationType.toString()); - + request.addPostParam( + "VerificationType", + verificationType.toString() + ); } if (verificationDocumentSid != null) { - request.addPostParam("VerificationDocumentSid", verificationDocumentSid); - + request.addPostParam( + "VerificationDocumentSid", + verificationDocumentSid + ); } if (extension != null) { request.addPostParam("Extension", extension); - } if (callDelay != null) { request.addPostParam("CallDelay", callDelay.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/preview/hostedNumbers/authorizationdocument/DependentHostedNumberOrder.java b/src/main/java/com/twilio/rest/preview/hostedNumbers/authorizationdocument/DependentHostedNumberOrder.java index 65fc3baf3e..825c4a8467 100644 --- a/src/main/java/com/twilio/rest/preview/hostedNumbers/authorizationdocument/DependentHostedNumberOrder.java +++ b/src/main/java/com/twilio/rest/preview/hostedNumbers/authorizationdocument/DependentHostedNumberOrder.java @@ -24,41 +24,45 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - +import com.twilio.type.PhoneNumberCapabilities; import java.io.IOException; import java.io.InputStream; import java.time.ZonedDateTime; - import java.util.List; import java.util.Objects; - - -import com.twilio.type.PhoneNumberCapabilities; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class DependentHostedNumberOrder extends Resource { + private static final long serialVersionUID = 65583991731077L; - public static DependentHostedNumberOrderReader reader(final String pathSigningDocumentSid){ + public static DependentHostedNumberOrderReader reader( + final String pathSigningDocumentSid + ) { return new DependentHostedNumberOrderReader(pathSigningDocumentSid); } /** - * Converts a JSON String into a DependentHostedNumberOrder object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return DependentHostedNumberOrder object represented by the provided JSON - */ - public static DependentHostedNumberOrder fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a DependentHostedNumberOrder object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return DependentHostedNumberOrder object represented by the provided JSON + */ + public static DependentHostedNumberOrder fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, DependentHostedNumberOrder.class); + return objectMapper.readValue( + json, + DependentHostedNumberOrder.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -67,23 +71,30 @@ public static DependentHostedNumberOrder fromJson(final String json, final Objec } /** - * Converts a JSON InputStream into a DependentHostedNumberOrder object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return DependentHostedNumberOrder object represented by the provided JSON - */ - public static DependentHostedNumberOrder fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a DependentHostedNumberOrder object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return DependentHostedNumberOrder object represented by the provided JSON + */ + public static DependentHostedNumberOrder fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, DependentHostedNumberOrder.class); + return objectMapper.readValue( + json, + DependentHostedNumberOrder.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { throw new ApiConnectionException(e.getMessage(), e); } } + public enum Status { RECEIVED("received"), PENDING_VERIFICATION("pending-verification"), @@ -110,6 +121,7 @@ public static Status forValue(final String value) { return Promoter.enumFromString(value, Status.values()); } } + public enum VerificationType { PHONE_CALL("phone-call"), PHONE_BILL("phone-bill"); @@ -155,71 +167,42 @@ public static VerificationType forValue(final String value) { @JsonCreator private DependentHostedNumberOrder( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("incoming_phone_number_sid") - final String incomingPhoneNumberSid, - - @JsonProperty("address_sid") - final String addressSid, - - @JsonProperty("signing_document_sid") - final String signingDocumentSid, - - @JsonProperty("phone_number") - final com.twilio.type.PhoneNumber phoneNumber, - - @JsonProperty("capabilities") - final PhoneNumberCapabilities capabilities, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("unique_name") - final String uniqueName, - - @JsonProperty("status") - final DependentHostedNumberOrder.Status status, - - @JsonProperty("failure_reason") - final String failureReason, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("verification_attempts") - final Integer verificationAttempts, - - @JsonProperty("email") - final String email, - - @JsonProperty("cc_emails") - final List ccEmails, - - @JsonProperty("verification_type") - final DependentHostedNumberOrder.VerificationType verificationType, - - @JsonProperty("verification_document_sid") - final String verificationDocumentSid, - - @JsonProperty("extension") - final String extension, - - @JsonProperty("call_delay") - final Integer callDelay, - - @JsonProperty("verification_code") - final String verificationCode, - - @JsonProperty("verification_call_sids") - final List verificationCallSids + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty( + "incoming_phone_number_sid" + ) final String incomingPhoneNumberSid, + @JsonProperty("address_sid") final String addressSid, + @JsonProperty("signing_document_sid") final String signingDocumentSid, + @JsonProperty( + "phone_number" + ) final com.twilio.type.PhoneNumber phoneNumber, + @JsonProperty( + "capabilities" + ) final PhoneNumberCapabilities capabilities, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("status") final DependentHostedNumberOrder.Status status, + @JsonProperty("failure_reason") final String failureReason, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty( + "verification_attempts" + ) final Integer verificationAttempts, + @JsonProperty("email") final String email, + @JsonProperty("cc_emails") final List ccEmails, + @JsonProperty( + "verification_type" + ) final DependentHostedNumberOrder.VerificationType verificationType, + @JsonProperty( + "verification_document_sid" + ) final String verificationDocumentSid, + @JsonProperty("extension") final String extension, + @JsonProperty("call_delay") final Integer callDelay, + @JsonProperty("verification_code") final String verificationCode, + @JsonProperty( + "verification_call_sids" + ) final List verificationCallSids ) { this.sid = sid; this.accountSid = accountSid; @@ -245,76 +228,97 @@ private DependentHostedNumberOrder( this.verificationCallSids = verificationCallSids; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getIncomingPhoneNumberSid() { - return this.incomingPhoneNumberSid; - } - public final String getAddressSid() { - return this.addressSid; - } - public final String getSigningDocumentSid() { - return this.signingDocumentSid; - } - public final com.twilio.type.PhoneNumber getPhoneNumber() { - return this.phoneNumber; - } - public final PhoneNumberCapabilities getCapabilities() { - return this.capabilities; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getUniqueName() { - return this.uniqueName; - } - public final DependentHostedNumberOrder.Status getStatus() { - return this.status; - } - public final String getFailureReason() { - return this.failureReason; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final Integer getVerificationAttempts() { - return this.verificationAttempts; - } - public final String getEmail() { - return this.email; - } - public final List getCcEmails() { - return this.ccEmails; - } - public final DependentHostedNumberOrder.VerificationType getVerificationType() { - return this.verificationType; - } - public final String getVerificationDocumentSid() { - return this.verificationDocumentSid; - } - public final String getExtension() { - return this.extension; - } - public final Integer getCallDelay() { - return this.callDelay; - } - public final String getVerificationCode() { - return this.verificationCode; - } - public final List getVerificationCallSids() { - return this.verificationCallSids; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getIncomingPhoneNumberSid() { + return this.incomingPhoneNumberSid; + } + + public final String getAddressSid() { + return this.addressSid; + } + + public final String getSigningDocumentSid() { + return this.signingDocumentSid; + } + + public final com.twilio.type.PhoneNumber getPhoneNumber() { + return this.phoneNumber; + } + + public final PhoneNumberCapabilities getCapabilities() { + return this.capabilities; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getUniqueName() { + return this.uniqueName; + } + + public final DependentHostedNumberOrder.Status getStatus() { + return this.status; + } + + public final String getFailureReason() { + return this.failureReason; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final Integer getVerificationAttempts() { + return this.verificationAttempts; + } + + public final String getEmail() { + return this.email; + } + + public final List getCcEmails() { + return this.ccEmails; + } + + public final DependentHostedNumberOrder.VerificationType getVerificationType() { + return this.verificationType; + } + + public final String getVerificationDocumentSid() { + return this.verificationDocumentSid; + } + + public final String getExtension() { + return this.extension; + } + + public final Integer getCallDelay() { + return this.callDelay; + } + + public final String getVerificationCode() { + return this.verificationCode; + } + + public final List getVerificationCallSids() { + return this.verificationCallSids; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -324,13 +328,63 @@ public boolean equals(final Object o) { DependentHostedNumberOrder other = (DependentHostedNumberOrder) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(incomingPhoneNumberSid, other.incomingPhoneNumberSid) && Objects.equals(addressSid, other.addressSid) && Objects.equals(signingDocumentSid, other.signingDocumentSid) && Objects.equals(phoneNumber, other.phoneNumber) && Objects.equals(capabilities, other.capabilities) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(uniqueName, other.uniqueName) && Objects.equals(status, other.status) && Objects.equals(failureReason, other.failureReason) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(verificationAttempts, other.verificationAttempts) && Objects.equals(email, other.email) && Objects.equals(ccEmails, other.ccEmails) && Objects.equals(verificationType, other.verificationType) && Objects.equals(verificationDocumentSid, other.verificationDocumentSid) && Objects.equals(extension, other.extension) && Objects.equals(callDelay, other.callDelay) && Objects.equals(verificationCode, other.verificationCode) && Objects.equals(verificationCallSids, other.verificationCallSids) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals( + incomingPhoneNumberSid, + other.incomingPhoneNumberSid + ) && + Objects.equals(addressSid, other.addressSid) && + Objects.equals(signingDocumentSid, other.signingDocumentSid) && + Objects.equals(phoneNumber, other.phoneNumber) && + Objects.equals(capabilities, other.capabilities) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(status, other.status) && + Objects.equals(failureReason, other.failureReason) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(verificationAttempts, other.verificationAttempts) && + Objects.equals(email, other.email) && + Objects.equals(ccEmails, other.ccEmails) && + Objects.equals(verificationType, other.verificationType) && + Objects.equals( + verificationDocumentSid, + other.verificationDocumentSid + ) && + Objects.equals(extension, other.extension) && + Objects.equals(callDelay, other.callDelay) && + Objects.equals(verificationCode, other.verificationCode) && + Objects.equals(verificationCallSids, other.verificationCallSids) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, incomingPhoneNumberSid, addressSid, signingDocumentSid, phoneNumber, capabilities, friendlyName, uniqueName, status, failureReason, dateCreated, dateUpdated, verificationAttempts, email, ccEmails, verificationType, verificationDocumentSid, extension, callDelay, verificationCode, verificationCallSids); + return Objects.hash( + sid, + accountSid, + incomingPhoneNumberSid, + addressSid, + signingDocumentSid, + phoneNumber, + capabilities, + friendlyName, + uniqueName, + status, + failureReason, + dateCreated, + dateUpdated, + verificationAttempts, + email, + ccEmails, + verificationType, + verificationDocumentSid, + extension, + callDelay, + verificationCode, + verificationCallSids + ); } - } - diff --git a/src/main/java/com/twilio/rest/preview/hostedNumbers/authorizationdocument/DependentHostedNumberOrderReader.java b/src/main/java/com/twilio/rest/preview/hostedNumbers/authorizationdocument/DependentHostedNumberOrderReader.java index 9e69700367..6bcaf9956c 100644 --- a/src/main/java/com/twilio/rest/preview/hostedNumbers/authorizationdocument/DependentHostedNumberOrderReader.java +++ b/src/main/java/com/twilio/rest/preview/hostedNumbers/authorizationdocument/DependentHostedNumberOrderReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.preview.hostedNumbers.authorizationdocument; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.converter.Promoter; @@ -25,11 +26,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; +public class DependentHostedNumberOrderReader + extends Reader { - -public class DependentHostedNumberOrderReader extends Reader { private String pathSigningDocumentSid; private DependentHostedNumberOrder.Status status; private com.twilio.type.PhoneNumber phoneNumber; @@ -38,47 +38,77 @@ public class DependentHostedNumberOrderReader extends Reader read(final TwilioRestClient client) { + public ResourceSet read( + final TwilioRestClient client + ) { return new ResourceSet<>(this, client, firstPage(client)); } - public Page firstPage(final TwilioRestClient client) { - String path = "/HostedNumbers/AuthorizationDocuments/{SigningDocumentSid}/DependentHostedNumberOrders"; - path = path.replace("{"+"SigningDocumentSid"+"}", this.pathSigningDocumentSid.toString()); + public Page firstPage( + final TwilioRestClient client + ) { + String path = + "/HostedNumbers/AuthorizationDocuments/{SigningDocumentSid}/DependentHostedNumberOrders"; + path = + path.replace( + "{" + "SigningDocumentSid" + "}", + this.pathSigningDocumentSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -90,13 +120,21 @@ public Page firstPage(final TwilioRestClient client) return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("DependentHostedNumberOrder read failed: Unable to connect to server"); + throw new ApiConnectionException( + "DependentHostedNumberOrder read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -112,7 +150,10 @@ private Page pageForRequest(final TwilioRestClient c } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.PREVIEW.toString()) @@ -120,9 +161,11 @@ public Page previousPage(final Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.PREVIEW.toString()) @@ -131,41 +174,39 @@ public Page nextPage(final Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (status != null) { - request.addQueryParam("Status", status.toString()); } if (phoneNumber != null) { - request.addQueryParam("PhoneNumber", phoneNumber.toString()); } if (incomingPhoneNumberSid != null) { - - request.addQueryParam("IncomingPhoneNumberSid", incomingPhoneNumberSid); + request.addQueryParam( + "IncomingPhoneNumberSid", + incomingPhoneNumberSid + ); } if (friendlyName != null) { - request.addQueryParam("FriendlyName", friendlyName); } if (uniqueName != null) { - request.addQueryParam("UniqueName", uniqueName); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/preview/marketplace/AvailableAddOn.java b/src/main/java/com/twilio/rest/preview/marketplace/AvailableAddOn.java index 9f25c56f9e..f524b70549 100644 --- a/src/main/java/com/twilio/rest/preview/marketplace/AvailableAddOn.java +++ b/src/main/java/com/twilio/rest/preview/marketplace/AvailableAddOn.java @@ -22,42 +22,41 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class AvailableAddOn extends Resource { + private static final long serialVersionUID = 265387241353044L; - public static AvailableAddOnFetcher fetcher(final String pathSid){ + public static AvailableAddOnFetcher fetcher(final String pathSid) { return new AvailableAddOnFetcher(pathSid); } - public static AvailableAddOnReader reader(){ + public static AvailableAddOnReader reader() { return new AvailableAddOnReader(); } /** - * Converts a JSON String into a AvailableAddOn object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return AvailableAddOn object represented by the provided JSON - */ - public static AvailableAddOn fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a AvailableAddOn object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return AvailableAddOn object represented by the provided JSON + */ + public static AvailableAddOn fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, AvailableAddOn.class); @@ -69,14 +68,17 @@ public static AvailableAddOn fromJson(final String json, final ObjectMapper obje } /** - * Converts a JSON InputStream into a AvailableAddOn object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return AvailableAddOn object represented by the provided JSON - */ - public static AvailableAddOn fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a AvailableAddOn object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return AvailableAddOn object represented by the provided JSON + */ + public static AvailableAddOn fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, AvailableAddOn.class); @@ -97,26 +99,15 @@ public static AvailableAddOn fromJson(final InputStream json, final ObjectMapper @JsonCreator private AvailableAddOn( - @JsonProperty("sid") - final String sid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("description") - final String description, - - @JsonProperty("pricing_type") - final String pricingType, - - @JsonProperty("configuration_schema") - final Map configurationSchema, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("sid") final String sid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("description") final String description, + @JsonProperty("pricing_type") final String pricingType, + @JsonProperty( + "configuration_schema" + ) final Map configurationSchema, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.sid = sid; this.friendlyName = friendlyName; @@ -127,31 +118,37 @@ private AvailableAddOn( this.links = links; } - public final String getSid() { - return this.sid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getDescription() { - return this.description; - } - public final String getPricingType() { - return this.pricingType; - } - public final Map getConfigurationSchema() { - return this.configurationSchema; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getSid() { + return this.sid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getDescription() { + return this.description; + } + + public final String getPricingType() { + return this.pricingType; + } + + public final Map getConfigurationSchema() { + return this.configurationSchema; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -161,13 +158,27 @@ public boolean equals(final Object o) { AvailableAddOn other = (AvailableAddOn) o; - return Objects.equals(sid, other.sid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(description, other.description) && Objects.equals(pricingType, other.pricingType) && Objects.equals(configurationSchema, other.configurationSchema) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(description, other.description) && + Objects.equals(pricingType, other.pricingType) && + Objects.equals(configurationSchema, other.configurationSchema) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(sid, friendlyName, description, pricingType, configurationSchema, url, links); + return Objects.hash( + sid, + friendlyName, + description, + pricingType, + configurationSchema, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/preview/marketplace/AvailableAddOnFetcher.java b/src/main/java/com/twilio/rest/preview/marketplace/AvailableAddOnFetcher.java index 85c583486e..b9e666b0a0 100644 --- a/src/main/java/com/twilio/rest/preview/marketplace/AvailableAddOnFetcher.java +++ b/src/main/java/com/twilio/rest/preview/marketplace/AvailableAddOnFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class AvailableAddOnFetcher extends Fetcher { + private String pathSid; - public AvailableAddOnFetcher(final String pathSid){ + public AvailableAddOnFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public AvailableAddOn fetch(final TwilioRestClient client) { String path = "/marketplace/AvailableAddOns/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,15 +46,23 @@ public AvailableAddOn fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AvailableAddOn fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "AvailableAddOn fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return AvailableAddOn.fromJson(response.getStream(), client.getObjectMapper()); + return AvailableAddOn.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/preview/marketplace/AvailableAddOnReader.java b/src/main/java/com/twilio/rest/preview/marketplace/AvailableAddOnReader.java index 0d7f7d7824..17dd2e1b22 100644 --- a/src/main/java/com/twilio/rest/preview/marketplace/AvailableAddOnReader.java +++ b/src/main/java/com/twilio/rest/preview/marketplace/AvailableAddOnReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.preview.marketplace; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,17 +25,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class AvailableAddOnReader extends Reader { + private Integer pageSize; - public AvailableAddOnReader(){ - } + public AvailableAddOnReader() {} - public AvailableAddOnReader setPageSize(final Integer pageSize){ + public AvailableAddOnReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -57,13 +55,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AvailableAddOn read failed: Unable to connect to server"); + throw new ApiConnectionException( + "AvailableAddOn read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -79,7 +85,10 @@ private Page pageForRequest(final TwilioRestClient client, final } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.PREVIEW.toString()) @@ -87,9 +96,11 @@ public Page previousPage(final Page page, final return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.PREVIEW.toString()) @@ -98,21 +109,21 @@ public Page nextPage(final Page page, final Twil } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/preview/marketplace/InstalledAddOn.java b/src/main/java/com/twilio/rest/preview/marketplace/InstalledAddOn.java index b6ee262513..864a5bec86 100644 --- a/src/main/java/com/twilio/rest/preview/marketplace/InstalledAddOn.java +++ b/src/main/java/com/twilio/rest/preview/marketplace/InstalledAddOn.java @@ -23,55 +23,60 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class InstalledAddOn extends Resource { + private static final long serialVersionUID = 250400645130930L; - public static InstalledAddOnCreator creator(final String availableAddOnSid, final Boolean acceptTermsOfService){ - return new InstalledAddOnCreator(availableAddOnSid, acceptTermsOfService); + public static InstalledAddOnCreator creator( + final String availableAddOnSid, + final Boolean acceptTermsOfService + ) { + return new InstalledAddOnCreator( + availableAddOnSid, + acceptTermsOfService + ); } - public static InstalledAddOnDeleter deleter(final String pathSid){ + public static InstalledAddOnDeleter deleter(final String pathSid) { return new InstalledAddOnDeleter(pathSid); } - public static InstalledAddOnFetcher fetcher(final String pathSid){ + public static InstalledAddOnFetcher fetcher(final String pathSid) { return new InstalledAddOnFetcher(pathSid); } - public static InstalledAddOnReader reader(){ + public static InstalledAddOnReader reader() { return new InstalledAddOnReader(); } - public static InstalledAddOnUpdater updater(final String pathSid){ + public static InstalledAddOnUpdater updater(final String pathSid) { return new InstalledAddOnUpdater(pathSid); } /** - * Converts a JSON String into a InstalledAddOn object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return InstalledAddOn object represented by the provided JSON - */ - public static InstalledAddOn fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a InstalledAddOn object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return InstalledAddOn object represented by the provided JSON + */ + public static InstalledAddOn fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, InstalledAddOn.class); @@ -83,14 +88,17 @@ public static InstalledAddOn fromJson(final String json, final ObjectMapper obje } /** - * Converts a JSON InputStream into a InstalledAddOn object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return InstalledAddOn object represented by the provided JSON - */ - public static InstalledAddOn fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a InstalledAddOn object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return InstalledAddOn object represented by the provided JSON + */ + public static InstalledAddOn fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, InstalledAddOn.class); @@ -114,35 +122,16 @@ public static InstalledAddOn fromJson(final InputStream json, final ObjectMapper @JsonCreator private InstalledAddOn( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("description") - final String description, - - @JsonProperty("configuration") - final Map configuration, - - @JsonProperty("unique_name") - final String uniqueName, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("description") final String description, + @JsonProperty("configuration") final Map configuration, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.sid = sid; this.accountSid = accountSid; @@ -156,40 +145,49 @@ private InstalledAddOn( this.links = links; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getDescription() { - return this.description; - } - public final Map getConfiguration() { - return this.configuration; - } - public final String getUniqueName() { - return this.uniqueName; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getDescription() { + return this.description; + } + + public final Map getConfiguration() { + return this.configuration; + } + + public final String getUniqueName() { + return this.uniqueName; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -199,13 +197,33 @@ public boolean equals(final Object o) { InstalledAddOn other = (InstalledAddOn) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(description, other.description) && Objects.equals(configuration, other.configuration) && Objects.equals(uniqueName, other.uniqueName) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(description, other.description) && + Objects.equals(configuration, other.configuration) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, friendlyName, description, configuration, uniqueName, dateCreated, dateUpdated, url, links); + return Objects.hash( + sid, + accountSid, + friendlyName, + description, + configuration, + uniqueName, + dateCreated, + dateUpdated, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/preview/marketplace/InstalledAddOnCreator.java b/src/main/java/com/twilio/rest/preview/marketplace/InstalledAddOnCreator.java index 4a16f663cd..c41ce727f1 100644 --- a/src/main/java/com/twilio/rest/preview/marketplace/InstalledAddOnCreator.java +++ b/src/main/java/com/twilio/rest/preview/marketplace/InstalledAddOnCreator.java @@ -15,8 +15,10 @@ package com.twilio.rest.preview.marketplace; import com.twilio.base.Creator; -import com.twilio.exception.ApiConnectionException; +import com.twilio.constant.EnumConstants; +import com.twilio.converter.Converter; import com.twilio.converter.Converter; +import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; @@ -25,82 +27,111 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.util.Map; -import com.twilio.converter.Converter; - import java.util.Map; +public class InstalledAddOnCreator extends Creator { - -public class InstalledAddOnCreator extends Creator{ private String availableAddOnSid; private Boolean acceptTermsOfService; private Map configuration; private String uniqueName; - public InstalledAddOnCreator(final String availableAddOnSid, final Boolean acceptTermsOfService) { + public InstalledAddOnCreator( + final String availableAddOnSid, + final Boolean acceptTermsOfService + ) { this.availableAddOnSid = availableAddOnSid; this.acceptTermsOfService = acceptTermsOfService; } - public InstalledAddOnCreator setAvailableAddOnSid(final String availableAddOnSid){ + public InstalledAddOnCreator setAvailableAddOnSid( + final String availableAddOnSid + ) { this.availableAddOnSid = availableAddOnSid; return this; } - public InstalledAddOnCreator setAcceptTermsOfService(final Boolean acceptTermsOfService){ + + public InstalledAddOnCreator setAcceptTermsOfService( + final Boolean acceptTermsOfService + ) { this.acceptTermsOfService = acceptTermsOfService; return this; } - public InstalledAddOnCreator setConfiguration(final Map configuration){ + + public InstalledAddOnCreator setConfiguration( + final Map configuration + ) { this.configuration = configuration; return this; } - public InstalledAddOnCreator setUniqueName(final String uniqueName){ + + public InstalledAddOnCreator setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } @Override - public InstalledAddOn create(final TwilioRestClient client){ + public InstalledAddOn create(final TwilioRestClient client) { String path = "/marketplace/InstalledAddOns"; - path = path.replace("{"+"AvailableAddOnSid"+"}", this.availableAddOnSid.toString()); - path = path.replace("{"+"AcceptTermsOfService"+"}", this.acceptTermsOfService.toString()); + path = + path.replace( + "{" + "AvailableAddOnSid" + "}", + this.availableAddOnSid.toString() + ); + path = + path.replace( + "{" + "AcceptTermsOfService" + "}", + this.acceptTermsOfService.toString() + ); Request request = new Request( HttpMethod.POST, Domains.PREVIEW.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("InstalledAddOn creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "InstalledAddOn creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return InstalledAddOn.fromJson(response.getStream(), client.getObjectMapper()); + return InstalledAddOn.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (availableAddOnSid != null) { request.addPostParam("AvailableAddOnSid", availableAddOnSid); - } if (acceptTermsOfService != null) { - request.addPostParam("AcceptTermsOfService", acceptTermsOfService.toString()); - + request.addPostParam( + "AcceptTermsOfService", + acceptTermsOfService.toString() + ); } if (configuration != null) { - request.addPostParam("Configuration", Converter.mapToJson(configuration)); - + request.addPostParam( + "Configuration", + Converter.mapToJson(configuration) + ); } if (uniqueName != null) { request.addPostParam("UniqueName", uniqueName); - } } } diff --git a/src/main/java/com/twilio/rest/preview/marketplace/InstalledAddOnDeleter.java b/src/main/java/com/twilio/rest/preview/marketplace/InstalledAddOnDeleter.java index 43d33ec280..87e0c5209c 100644 --- a/src/main/java/com/twilio/rest/preview/marketplace/InstalledAddOnDeleter.java +++ b/src/main/java/com/twilio/rest/preview/marketplace/InstalledAddOnDeleter.java @@ -24,21 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class InstalledAddOnDeleter extends Deleter { + private String pathSid; - public InstalledAddOnDeleter(final String pathSid){ + public InstalledAddOnDeleter(final String pathSid) { this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/marketplace/InstalledAddOns/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -48,9 +46,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("InstalledAddOn delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "InstalledAddOn delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/preview/marketplace/InstalledAddOnFetcher.java b/src/main/java/com/twilio/rest/preview/marketplace/InstalledAddOnFetcher.java index d9a0a5b17b..7eceb8980d 100644 --- a/src/main/java/com/twilio/rest/preview/marketplace/InstalledAddOnFetcher.java +++ b/src/main/java/com/twilio/rest/preview/marketplace/InstalledAddOnFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class InstalledAddOnFetcher extends Fetcher { + private String pathSid; - public InstalledAddOnFetcher(final String pathSid){ + public InstalledAddOnFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public InstalledAddOn fetch(final TwilioRestClient client) { String path = "/marketplace/InstalledAddOns/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,15 +46,23 @@ public InstalledAddOn fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("InstalledAddOn fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "InstalledAddOn fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return InstalledAddOn.fromJson(response.getStream(), client.getObjectMapper()); + return InstalledAddOn.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/preview/marketplace/InstalledAddOnReader.java b/src/main/java/com/twilio/rest/preview/marketplace/InstalledAddOnReader.java index 55fd376db9..1e3d369584 100644 --- a/src/main/java/com/twilio/rest/preview/marketplace/InstalledAddOnReader.java +++ b/src/main/java/com/twilio/rest/preview/marketplace/InstalledAddOnReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.preview.marketplace; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,17 +25,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class InstalledAddOnReader extends Reader { + private Integer pageSize; - public InstalledAddOnReader(){ - } + public InstalledAddOnReader() {} - public InstalledAddOnReader setPageSize(final Integer pageSize){ + public InstalledAddOnReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -57,13 +55,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("InstalledAddOn read failed: Unable to connect to server"); + throw new ApiConnectionException( + "InstalledAddOn read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -79,7 +85,10 @@ private Page pageForRequest(final TwilioRestClient client, final } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.PREVIEW.toString()) @@ -87,9 +96,11 @@ public Page previousPage(final Page page, final return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.PREVIEW.toString()) @@ -98,21 +109,21 @@ public Page nextPage(final Page page, final Twil } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/preview/marketplace/InstalledAddOnUpdater.java b/src/main/java/com/twilio/rest/preview/marketplace/InstalledAddOnUpdater.java index 2417e1fe78..27092c0fa4 100644 --- a/src/main/java/com/twilio/rest/preview/marketplace/InstalledAddOnUpdater.java +++ b/src/main/java/com/twilio/rest/preview/marketplace/InstalledAddOnUpdater.java @@ -15,8 +15,9 @@ package com.twilio.rest.preview.marketplace; import com.twilio.base.Updater; -import com.twilio.exception.ApiConnectionException; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Converter; +import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; @@ -24,62 +25,74 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - import java.util.Map; +public class InstalledAddOnUpdater extends Updater { -public class InstalledAddOnUpdater extends Updater{ private String pathSid; private Map configuration; private String uniqueName; - public InstalledAddOnUpdater(final String pathSid){ + public InstalledAddOnUpdater(final String pathSid) { this.pathSid = pathSid; } - public InstalledAddOnUpdater setConfiguration(final Map configuration){ + public InstalledAddOnUpdater setConfiguration( + final Map configuration + ) { this.configuration = configuration; return this; } - public InstalledAddOnUpdater setUniqueName(final String uniqueName){ + + public InstalledAddOnUpdater setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } @Override - public InstalledAddOn update(final TwilioRestClient client){ + public InstalledAddOn update(final TwilioRestClient client) { String path = "/marketplace/InstalledAddOns/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.PREVIEW.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("InstalledAddOn update failed: Unable to connect to server"); + throw new ApiConnectionException( + "InstalledAddOn update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return InstalledAddOn.fromJson(response.getStream(), client.getObjectMapper()); + return InstalledAddOn.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (configuration != null) { - request.addPostParam("Configuration", Converter.mapToJson(configuration)); - + request.addPostParam( + "Configuration", + Converter.mapToJson(configuration) + ); } if (uniqueName != null) { request.addPostParam("UniqueName", uniqueName); - } } } diff --git a/src/main/java/com/twilio/rest/preview/marketplace/availableaddon/AvailableAddOnExtension.java b/src/main/java/com/twilio/rest/preview/marketplace/availableaddon/AvailableAddOnExtension.java index 66244c888d..9e62d2a07d 100644 --- a/src/main/java/com/twilio/rest/preview/marketplace/availableaddon/AvailableAddOnExtension.java +++ b/src/main/java/com/twilio/rest/preview/marketplace/availableaddon/AvailableAddOnExtension.java @@ -22,40 +22,47 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class AvailableAddOnExtension extends Resource { + private static final long serialVersionUID = 15009232316880L; - public static AvailableAddOnExtensionFetcher fetcher(final String pathAvailableAddOnSid, final String pathSid){ - return new AvailableAddOnExtensionFetcher(pathAvailableAddOnSid, pathSid); + public static AvailableAddOnExtensionFetcher fetcher( + final String pathAvailableAddOnSid, + final String pathSid + ) { + return new AvailableAddOnExtensionFetcher( + pathAvailableAddOnSid, + pathSid + ); } - public static AvailableAddOnExtensionReader reader(final String pathAvailableAddOnSid){ + public static AvailableAddOnExtensionReader reader( + final String pathAvailableAddOnSid + ) { return new AvailableAddOnExtensionReader(pathAvailableAddOnSid); } /** - * Converts a JSON String into a AvailableAddOnExtension object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return AvailableAddOnExtension object represented by the provided JSON - */ - public static AvailableAddOnExtension fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a AvailableAddOnExtension object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return AvailableAddOnExtension object represented by the provided JSON + */ + public static AvailableAddOnExtension fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, AvailableAddOnExtension.class); @@ -67,14 +74,17 @@ public static AvailableAddOnExtension fromJson(final String json, final ObjectMa } /** - * Converts a JSON InputStream into a AvailableAddOnExtension object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return AvailableAddOnExtension object represented by the provided JSON - */ - public static AvailableAddOnExtension fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a AvailableAddOnExtension object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return AvailableAddOnExtension object represented by the provided JSON + */ + public static AvailableAddOnExtension fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, AvailableAddOnExtension.class); @@ -94,23 +104,12 @@ public static AvailableAddOnExtension fromJson(final InputStream json, final Obj @JsonCreator private AvailableAddOnExtension( - @JsonProperty("sid") - final String sid, - - @JsonProperty("available_add_on_sid") - final String availableAddOnSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("product_name") - final String productName, - - @JsonProperty("unique_name") - final String uniqueName, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("available_add_on_sid") final String availableAddOnSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("product_name") final String productName, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("url") final URI url ) { this.sid = sid; this.availableAddOnSid = availableAddOnSid; @@ -120,28 +119,33 @@ private AvailableAddOnExtension( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getAvailableAddOnSid() { - return this.availableAddOnSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getProductName() { - return this.productName; - } - public final String getUniqueName() { - return this.uniqueName; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getAvailableAddOnSid() { + return this.availableAddOnSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getProductName() { + return this.productName; + } + + public final String getUniqueName() { + return this.uniqueName; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -151,13 +155,25 @@ public boolean equals(final Object o) { AvailableAddOnExtension other = (AvailableAddOnExtension) o; - return Objects.equals(sid, other.sid) && Objects.equals(availableAddOnSid, other.availableAddOnSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(productName, other.productName) && Objects.equals(uniqueName, other.uniqueName) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(availableAddOnSid, other.availableAddOnSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(productName, other.productName) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, availableAddOnSid, friendlyName, productName, uniqueName, url); + return Objects.hash( + sid, + availableAddOnSid, + friendlyName, + productName, + uniqueName, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/preview/marketplace/availableaddon/AvailableAddOnExtensionFetcher.java b/src/main/java/com/twilio/rest/preview/marketplace/availableaddon/AvailableAddOnExtensionFetcher.java index 66c60eb58a..e39ea13998 100644 --- a/src/main/java/com/twilio/rest/preview/marketplace/availableaddon/AvailableAddOnExtensionFetcher.java +++ b/src/main/java/com/twilio/rest/preview/marketplace/availableaddon/AvailableAddOnExtensionFetcher.java @@ -24,25 +24,31 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class AvailableAddOnExtensionFetcher + extends Fetcher { - - -public class AvailableAddOnExtensionFetcher extends Fetcher { private String pathAvailableAddOnSid; private String pathSid; - public AvailableAddOnExtensionFetcher(final String pathAvailableAddOnSid, final String pathSid){ + public AvailableAddOnExtensionFetcher( + final String pathAvailableAddOnSid, + final String pathSid + ) { this.pathAvailableAddOnSid = pathAvailableAddOnSid; this.pathSid = pathSid; } - @Override public AvailableAddOnExtension fetch(final TwilioRestClient client) { - String path = "/marketplace/AvailableAddOns/{AvailableAddOnSid}/Extensions/{Sid}"; + String path = + "/marketplace/AvailableAddOns/{AvailableAddOnSid}/Extensions/{Sid}"; - path = path.replace("{"+"AvailableAddOnSid"+"}", this.pathAvailableAddOnSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "AvailableAddOnSid" + "}", + this.pathAvailableAddOnSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,15 +58,23 @@ public AvailableAddOnExtension fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AvailableAddOnExtension fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "AvailableAddOnExtension fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return AvailableAddOnExtension.fromJson(response.getStream(), client.getObjectMapper()); + return AvailableAddOnExtension.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/preview/marketplace/availableaddon/AvailableAddOnExtensionReader.java b/src/main/java/com/twilio/rest/preview/marketplace/availableaddon/AvailableAddOnExtensionReader.java index 4abe6566d5..f00996b4ec 100644 --- a/src/main/java/com/twilio/rest/preview/marketplace/availableaddon/AvailableAddOnExtensionReader.java +++ b/src/main/java/com/twilio/rest/preview/marketplace/availableaddon/AvailableAddOnExtensionReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.preview.marketplace.availableaddon; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,31 +25,39 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; +public class AvailableAddOnExtensionReader + extends Reader { - -public class AvailableAddOnExtensionReader extends Reader { private String pathAvailableAddOnSid; private Integer pageSize; - public AvailableAddOnExtensionReader(final String pathAvailableAddOnSid){ + public AvailableAddOnExtensionReader(final String pathAvailableAddOnSid) { this.pathAvailableAddOnSid = pathAvailableAddOnSid; } - public AvailableAddOnExtensionReader setPageSize(final Integer pageSize){ + public AvailableAddOnExtensionReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @Override - public ResourceSet read(final TwilioRestClient client) { + public ResourceSet read( + final TwilioRestClient client + ) { return new ResourceSet<>(this, client, firstPage(client)); } - public Page firstPage(final TwilioRestClient client) { - String path = "/marketplace/AvailableAddOns/{AvailableAddOnSid}/Extensions"; - path = path.replace("{"+"AvailableAddOnSid"+"}", this.pathAvailableAddOnSid.toString()); + public Page firstPage( + final TwilioRestClient client + ) { + String path = + "/marketplace/AvailableAddOns/{AvailableAddOnSid}/Extensions"; + path = + path.replace( + "{" + "AvailableAddOnSid" + "}", + this.pathAvailableAddOnSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -60,13 +69,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AvailableAddOnExtension read failed: Unable to connect to server"); + throw new ApiConnectionException( + "AvailableAddOnExtension read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +99,10 @@ private Page pageForRequest(final TwilioRestClient clie } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.PREVIEW.toString()) @@ -90,9 +110,11 @@ public Page previousPage(final Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.PREVIEW.toString()) @@ -101,21 +123,21 @@ public Page nextPage(final Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/preview/marketplace/installedaddon/InstalledAddOnExtension.java b/src/main/java/com/twilio/rest/preview/marketplace/installedaddon/InstalledAddOnExtension.java index 6ff90cac33..3cca5a44a1 100644 --- a/src/main/java/com/twilio/rest/preview/marketplace/installedaddon/InstalledAddOnExtension.java +++ b/src/main/java/com/twilio/rest/preview/marketplace/installedaddon/InstalledAddOnExtension.java @@ -22,44 +22,59 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class InstalledAddOnExtension extends Resource { + private static final long serialVersionUID = 244872409958696L; - public static InstalledAddOnExtensionFetcher fetcher(final String pathInstalledAddOnSid, final String pathSid){ - return new InstalledAddOnExtensionFetcher(pathInstalledAddOnSid, pathSid); + public static InstalledAddOnExtensionFetcher fetcher( + final String pathInstalledAddOnSid, + final String pathSid + ) { + return new InstalledAddOnExtensionFetcher( + pathInstalledAddOnSid, + pathSid + ); } - public static InstalledAddOnExtensionReader reader(final String pathInstalledAddOnSid){ + public static InstalledAddOnExtensionReader reader( + final String pathInstalledAddOnSid + ) { return new InstalledAddOnExtensionReader(pathInstalledAddOnSid); } - public static InstalledAddOnExtensionUpdater updater(final String pathInstalledAddOnSid, final String pathSid, final Boolean enabled){ - return new InstalledAddOnExtensionUpdater(pathInstalledAddOnSid, pathSid, enabled); + public static InstalledAddOnExtensionUpdater updater( + final String pathInstalledAddOnSid, + final String pathSid, + final Boolean enabled + ) { + return new InstalledAddOnExtensionUpdater( + pathInstalledAddOnSid, + pathSid, + enabled + ); } /** - * Converts a JSON String into a InstalledAddOnExtension object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return InstalledAddOnExtension object represented by the provided JSON - */ - public static InstalledAddOnExtension fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a InstalledAddOnExtension object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return InstalledAddOnExtension object represented by the provided JSON + */ + public static InstalledAddOnExtension fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, InstalledAddOnExtension.class); @@ -71,14 +86,17 @@ public static InstalledAddOnExtension fromJson(final String json, final ObjectMa } /** - * Converts a JSON InputStream into a InstalledAddOnExtension object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return InstalledAddOnExtension object represented by the provided JSON - */ - public static InstalledAddOnExtension fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a InstalledAddOnExtension object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return InstalledAddOnExtension object represented by the provided JSON + */ + public static InstalledAddOnExtension fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, InstalledAddOnExtension.class); @@ -99,26 +117,13 @@ public static InstalledAddOnExtension fromJson(final InputStream json, final Obj @JsonCreator private InstalledAddOnExtension( - @JsonProperty("sid") - final String sid, - - @JsonProperty("installed_add_on_sid") - final String installedAddOnSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("product_name") - final String productName, - - @JsonProperty("unique_name") - final String uniqueName, - - @JsonProperty("enabled") - final Boolean enabled, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("installed_add_on_sid") final String installedAddOnSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("product_name") final String productName, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("enabled") final Boolean enabled, + @JsonProperty("url") final URI url ) { this.sid = sid; this.installedAddOnSid = installedAddOnSid; @@ -129,31 +134,37 @@ private InstalledAddOnExtension( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getInstalledAddOnSid() { - return this.installedAddOnSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getProductName() { - return this.productName; - } - public final String getUniqueName() { - return this.uniqueName; - } - public final Boolean getEnabled() { - return this.enabled; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getInstalledAddOnSid() { + return this.installedAddOnSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getProductName() { + return this.productName; + } + + public final String getUniqueName() { + return this.uniqueName; + } + + public final Boolean getEnabled() { + return this.enabled; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -163,13 +174,27 @@ public boolean equals(final Object o) { InstalledAddOnExtension other = (InstalledAddOnExtension) o; - return Objects.equals(sid, other.sid) && Objects.equals(installedAddOnSid, other.installedAddOnSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(productName, other.productName) && Objects.equals(uniqueName, other.uniqueName) && Objects.equals(enabled, other.enabled) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(installedAddOnSid, other.installedAddOnSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(productName, other.productName) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(enabled, other.enabled) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, installedAddOnSid, friendlyName, productName, uniqueName, enabled, url); + return Objects.hash( + sid, + installedAddOnSid, + friendlyName, + productName, + uniqueName, + enabled, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/preview/marketplace/installedaddon/InstalledAddOnExtensionFetcher.java b/src/main/java/com/twilio/rest/preview/marketplace/installedaddon/InstalledAddOnExtensionFetcher.java index 7677d31e02..38e83bc2c6 100644 --- a/src/main/java/com/twilio/rest/preview/marketplace/installedaddon/InstalledAddOnExtensionFetcher.java +++ b/src/main/java/com/twilio/rest/preview/marketplace/installedaddon/InstalledAddOnExtensionFetcher.java @@ -24,25 +24,31 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class InstalledAddOnExtensionFetcher + extends Fetcher { - - -public class InstalledAddOnExtensionFetcher extends Fetcher { private String pathInstalledAddOnSid; private String pathSid; - public InstalledAddOnExtensionFetcher(final String pathInstalledAddOnSid, final String pathSid){ + public InstalledAddOnExtensionFetcher( + final String pathInstalledAddOnSid, + final String pathSid + ) { this.pathInstalledAddOnSid = pathInstalledAddOnSid; this.pathSid = pathSid; } - @Override public InstalledAddOnExtension fetch(final TwilioRestClient client) { - String path = "/marketplace/InstalledAddOns/{InstalledAddOnSid}/Extensions/{Sid}"; + String path = + "/marketplace/InstalledAddOns/{InstalledAddOnSid}/Extensions/{Sid}"; - path = path.replace("{"+"InstalledAddOnSid"+"}", this.pathInstalledAddOnSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "InstalledAddOnSid" + "}", + this.pathInstalledAddOnSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,15 +58,23 @@ public InstalledAddOnExtension fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("InstalledAddOnExtension fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "InstalledAddOnExtension fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return InstalledAddOnExtension.fromJson(response.getStream(), client.getObjectMapper()); + return InstalledAddOnExtension.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/preview/marketplace/installedaddon/InstalledAddOnExtensionReader.java b/src/main/java/com/twilio/rest/preview/marketplace/installedaddon/InstalledAddOnExtensionReader.java index 13d228fd46..e94de1d1e1 100644 --- a/src/main/java/com/twilio/rest/preview/marketplace/installedaddon/InstalledAddOnExtensionReader.java +++ b/src/main/java/com/twilio/rest/preview/marketplace/installedaddon/InstalledAddOnExtensionReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.preview.marketplace.installedaddon; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,31 +25,39 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; +public class InstalledAddOnExtensionReader + extends Reader { - -public class InstalledAddOnExtensionReader extends Reader { private String pathInstalledAddOnSid; private Integer pageSize; - public InstalledAddOnExtensionReader(final String pathInstalledAddOnSid){ + public InstalledAddOnExtensionReader(final String pathInstalledAddOnSid) { this.pathInstalledAddOnSid = pathInstalledAddOnSid; } - public InstalledAddOnExtensionReader setPageSize(final Integer pageSize){ + public InstalledAddOnExtensionReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @Override - public ResourceSet read(final TwilioRestClient client) { + public ResourceSet read( + final TwilioRestClient client + ) { return new ResourceSet<>(this, client, firstPage(client)); } - public Page firstPage(final TwilioRestClient client) { - String path = "/marketplace/InstalledAddOns/{InstalledAddOnSid}/Extensions"; - path = path.replace("{"+"InstalledAddOnSid"+"}", this.pathInstalledAddOnSid.toString()); + public Page firstPage( + final TwilioRestClient client + ) { + String path = + "/marketplace/InstalledAddOns/{InstalledAddOnSid}/Extensions"; + path = + path.replace( + "{" + "InstalledAddOnSid" + "}", + this.pathInstalledAddOnSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -60,13 +69,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("InstalledAddOnExtension read failed: Unable to connect to server"); + throw new ApiConnectionException( + "InstalledAddOnExtension read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +99,10 @@ private Page pageForRequest(final TwilioRestClient clie } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.PREVIEW.toString()) @@ -90,9 +110,11 @@ public Page previousPage(final Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.PREVIEW.toString()) @@ -101,21 +123,21 @@ public Page nextPage(final Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/preview/marketplace/installedaddon/InstalledAddOnExtensionUpdater.java b/src/main/java/com/twilio/rest/preview/marketplace/installedaddon/InstalledAddOnExtensionUpdater.java index 80507e6de3..fd4366ce88 100644 --- a/src/main/java/com/twilio/rest/preview/marketplace/installedaddon/InstalledAddOnExtensionUpdater.java +++ b/src/main/java/com/twilio/rest/preview/marketplace/installedaddon/InstalledAddOnExtensionUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.preview.marketplace.installedaddon; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,56 +25,73 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class InstalledAddOnExtensionUpdater + extends Updater { - - -public class InstalledAddOnExtensionUpdater extends Updater{ private String pathInstalledAddOnSid; private String pathSid; private Boolean enabled; - public InstalledAddOnExtensionUpdater(final String pathInstalledAddOnSid, final String pathSid, final Boolean enabled){ + public InstalledAddOnExtensionUpdater( + final String pathInstalledAddOnSid, + final String pathSid, + final Boolean enabled + ) { this.pathInstalledAddOnSid = pathInstalledAddOnSid; this.pathSid = pathSid; this.enabled = enabled; } - public InstalledAddOnExtensionUpdater setEnabled(final Boolean enabled){ + public InstalledAddOnExtensionUpdater setEnabled(final Boolean enabled) { this.enabled = enabled; return this; } @Override - public InstalledAddOnExtension update(final TwilioRestClient client){ - String path = "/marketplace/InstalledAddOns/{InstalledAddOnSid}/Extensions/{Sid}"; + public InstalledAddOnExtension update(final TwilioRestClient client) { + String path = + "/marketplace/InstalledAddOns/{InstalledAddOnSid}/Extensions/{Sid}"; - path = path.replace("{"+"InstalledAddOnSid"+"}", this.pathInstalledAddOnSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); - path = path.replace("{"+"Enabled"+"}", this.enabled.toString()); + path = + path.replace( + "{" + "InstalledAddOnSid" + "}", + this.pathInstalledAddOnSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + path = path.replace("{" + "Enabled" + "}", this.enabled.toString()); Request request = new Request( HttpMethod.POST, Domains.PREVIEW.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("InstalledAddOnExtension update failed: Unable to connect to server"); + throw new ApiConnectionException( + "InstalledAddOnExtension update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return InstalledAddOnExtension.fromJson(response.getStream(), client.getObjectMapper()); + return InstalledAddOnExtension.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (enabled != null) { request.addPostParam("Enabled", enabled.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/preview/sync/Service.java b/src/main/java/com/twilio/rest/preview/sync/Service.java index 2cfaf5f938..bfd9848b1a 100644 --- a/src/main/java/com/twilio/rest/preview/sync/Service.java +++ b/src/main/java/com/twilio/rest/preview/sync/Service.java @@ -23,55 +23,54 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Service extends Resource { + private static final long serialVersionUID = 175206360832156L; - public static ServiceCreator creator(){ + public static ServiceCreator creator() { return new ServiceCreator(); } - public static ServiceDeleter deleter(final String pathSid){ + public static ServiceDeleter deleter(final String pathSid) { return new ServiceDeleter(pathSid); } - public static ServiceFetcher fetcher(final String pathSid){ + public static ServiceFetcher fetcher(final String pathSid) { return new ServiceFetcher(pathSid); } - public static ServiceReader reader(){ + public static ServiceReader reader() { return new ServiceReader(); } - public static ServiceUpdater updater(final String pathSid){ + public static ServiceUpdater updater(final String pathSid) { return new ServiceUpdater(pathSid); } /** - * Converts a JSON String into a Service object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Service object represented by the provided JSON - */ - public static Service fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Service object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Service object represented by the provided JSON + */ + public static Service fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Service.class); @@ -83,14 +82,17 @@ public static Service fromJson(final String json, final ObjectMapper objectMappe } /** - * Converts a JSON InputStream into a Service object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Service object represented by the provided JSON - */ - public static Service fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Service object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Service object represented by the provided JSON + */ + public static Service fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Service.class); @@ -114,35 +116,18 @@ public static Service fromJson(final InputStream json, final ObjectMapper object @JsonCreator private Service( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url, - - @JsonProperty("webhook_url") - final URI webhookUrl, - - @JsonProperty("reachability_webhooks_enabled") - final Boolean reachabilityWebhooksEnabled, - - @JsonProperty("acl_enabled") - final Boolean aclEnabled, - - @JsonProperty("links") - final Map links + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url, + @JsonProperty("webhook_url") final URI webhookUrl, + @JsonProperty( + "reachability_webhooks_enabled" + ) final Boolean reachabilityWebhooksEnabled, + @JsonProperty("acl_enabled") final Boolean aclEnabled, + @JsonProperty("links") final Map links ) { this.sid = sid; this.accountSid = accountSid; @@ -156,40 +141,49 @@ private Service( this.links = links; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } - public final URI getWebhookUrl() { - return this.webhookUrl; - } - public final Boolean getReachabilityWebhooksEnabled() { - return this.reachabilityWebhooksEnabled; - } - public final Boolean getAclEnabled() { - return this.aclEnabled; - } - public final Map getLinks() { - return this.links; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } + + public final URI getWebhookUrl() { + return this.webhookUrl; + } + + public final Boolean getReachabilityWebhooksEnabled() { + return this.reachabilityWebhooksEnabled; + } + + public final Boolean getAclEnabled() { + return this.aclEnabled; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -199,13 +193,36 @@ public boolean equals(final Object o) { Service other = (Service) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) && Objects.equals(webhookUrl, other.webhookUrl) && Objects.equals(reachabilityWebhooksEnabled, other.reachabilityWebhooksEnabled) && Objects.equals(aclEnabled, other.aclEnabled) && Objects.equals(links, other.links) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) && + Objects.equals(webhookUrl, other.webhookUrl) && + Objects.equals( + reachabilityWebhooksEnabled, + other.reachabilityWebhooksEnabled + ) && + Objects.equals(aclEnabled, other.aclEnabled) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, friendlyName, dateCreated, dateUpdated, url, webhookUrl, reachabilityWebhooksEnabled, aclEnabled, links); + return Objects.hash( + sid, + accountSid, + friendlyName, + dateCreated, + dateUpdated, + url, + webhookUrl, + reachabilityWebhooksEnabled, + aclEnabled, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/preview/sync/ServiceCreator.java b/src/main/java/com/twilio/rest/preview/sync/ServiceCreator.java index 4365fa9913..b07d4691dd 100644 --- a/src/main/java/com/twilio/rest/preview/sync/ServiceCreator.java +++ b/src/main/java/com/twilio/rest/preview/sync/ServiceCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.preview.sync; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -25,57 +26,64 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.net.URI; - - - import java.net.URI; -public class ServiceCreator extends Creator{ +public class ServiceCreator extends Creator { + private String friendlyName; private URI webhookUrl; private Boolean reachabilityWebhooksEnabled; private Boolean aclEnabled; - public ServiceCreator() { - } + public ServiceCreator() {} - public ServiceCreator setFriendlyName(final String friendlyName){ + public ServiceCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public ServiceCreator setWebhookUrl(final URI webhookUrl){ + + public ServiceCreator setWebhookUrl(final URI webhookUrl) { this.webhookUrl = webhookUrl; return this; } - public ServiceCreator setWebhookUrl(final String webhookUrl){ + public ServiceCreator setWebhookUrl(final String webhookUrl) { return setWebhookUrl(Promoter.uriFromString(webhookUrl)); } - public ServiceCreator setReachabilityWebhooksEnabled(final Boolean reachabilityWebhooksEnabled){ + + public ServiceCreator setReachabilityWebhooksEnabled( + final Boolean reachabilityWebhooksEnabled + ) { this.reachabilityWebhooksEnabled = reachabilityWebhooksEnabled; return this; } - public ServiceCreator setAclEnabled(final Boolean aclEnabled){ + + public ServiceCreator setAclEnabled(final Boolean aclEnabled) { this.aclEnabled = aclEnabled; return this; } @Override - public Service create(final TwilioRestClient client){ + public Service create(final TwilioRestClient client) { String path = "/Sync/Services"; - Request request = new Request( HttpMethod.POST, Domains.PREVIEW.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -84,22 +92,22 @@ public Service create(final TwilioRestClient client){ return Service.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (webhookUrl != null) { request.addPostParam("WebhookUrl", webhookUrl.toString()); - } if (reachabilityWebhooksEnabled != null) { - request.addPostParam("ReachabilityWebhooksEnabled", reachabilityWebhooksEnabled.toString()); - + request.addPostParam( + "ReachabilityWebhooksEnabled", + reachabilityWebhooksEnabled.toString() + ); } if (aclEnabled != null) { request.addPostParam("AclEnabled", aclEnabled.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/preview/sync/ServiceDeleter.java b/src/main/java/com/twilio/rest/preview/sync/ServiceDeleter.java index 9c2d793106..25e9e36e4a 100644 --- a/src/main/java/com/twilio/rest/preview/sync/ServiceDeleter.java +++ b/src/main/java/com/twilio/rest/preview/sync/ServiceDeleter.java @@ -24,21 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class ServiceDeleter extends Deleter { + private String pathSid; - public ServiceDeleter(final String pathSid){ + public ServiceDeleter(final String pathSid) { this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/Sync/Services/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -48,9 +46,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/preview/sync/ServiceFetcher.java b/src/main/java/com/twilio/rest/preview/sync/ServiceFetcher.java index 97073ed9f3..d1f4f84bbe 100644 --- a/src/main/java/com/twilio/rest/preview/sync/ServiceFetcher.java +++ b/src/main/java/com/twilio/rest/preview/sync/ServiceFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class ServiceFetcher extends Fetcher { + private String pathSid; - public ServiceFetcher(final String pathSid){ + public ServiceFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public Service fetch(final TwilioRestClient client) { String path = "/Sync/Services/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,9 +46,14 @@ public Service fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/preview/sync/ServiceReader.java b/src/main/java/com/twilio/rest/preview/sync/ServiceReader.java index d6f87028f8..1b8af27d54 100644 --- a/src/main/java/com/twilio/rest/preview/sync/ServiceReader.java +++ b/src/main/java/com/twilio/rest/preview/sync/ServiceReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.preview.sync; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,17 +25,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class ServiceReader extends Reader { + private Integer pageSize; - public ServiceReader(){ - } + public ServiceReader() {} - public ServiceReader setPageSize(final Integer pageSize){ + public ServiceReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -57,13 +55,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -79,7 +85,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reques } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.PREVIEW.toString()) @@ -87,9 +96,11 @@ public Page previousPage(final Page page, final TwilioRestClie return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.PREVIEW.toString()) @@ -98,21 +109,21 @@ public Page nextPage(final Page page, final TwilioRestClient c } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/preview/sync/ServiceUpdater.java b/src/main/java/com/twilio/rest/preview/sync/ServiceUpdater.java index 209a43c90b..900436028c 100644 --- a/src/main/java/com/twilio/rest/preview/sync/ServiceUpdater.java +++ b/src/main/java/com/twilio/rest/preview/sync/ServiceUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.preview.sync; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -24,60 +25,69 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.net.URI; +public class ServiceUpdater extends Updater { - -public class ServiceUpdater extends Updater{ private String pathSid; private URI webhookUrl; private String friendlyName; private Boolean reachabilityWebhooksEnabled; private Boolean aclEnabled; - public ServiceUpdater(final String pathSid){ + public ServiceUpdater(final String pathSid) { this.pathSid = pathSid; } - public ServiceUpdater setWebhookUrl(final URI webhookUrl){ + public ServiceUpdater setWebhookUrl(final URI webhookUrl) { this.webhookUrl = webhookUrl; return this; } - public ServiceUpdater setWebhookUrl(final String webhookUrl){ + public ServiceUpdater setWebhookUrl(final String webhookUrl) { return setWebhookUrl(Promoter.uriFromString(webhookUrl)); } - public ServiceUpdater setFriendlyName(final String friendlyName){ + + public ServiceUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public ServiceUpdater setReachabilityWebhooksEnabled(final Boolean reachabilityWebhooksEnabled){ + + public ServiceUpdater setReachabilityWebhooksEnabled( + final Boolean reachabilityWebhooksEnabled + ) { this.reachabilityWebhooksEnabled = reachabilityWebhooksEnabled; return this; } - public ServiceUpdater setAclEnabled(final Boolean aclEnabled){ + + public ServiceUpdater setAclEnabled(final Boolean aclEnabled) { this.aclEnabled = aclEnabled; return this; } @Override - public Service update(final TwilioRestClient client){ + public Service update(final TwilioRestClient client) { String path = "/Sync/Services/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.PREVIEW.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -86,22 +96,22 @@ public Service update(final TwilioRestClient client){ return Service.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (webhookUrl != null) { request.addPostParam("WebhookUrl", webhookUrl.toString()); - } if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (reachabilityWebhooksEnabled != null) { - request.addPostParam("ReachabilityWebhooksEnabled", reachabilityWebhooksEnabled.toString()); - + request.addPostParam( + "ReachabilityWebhooksEnabled", + reachabilityWebhooksEnabled.toString() + ); } if (aclEnabled != null) { request.addPostParam("AclEnabled", aclEnabled.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/preview/sync/service/Document.java b/src/main/java/com/twilio/rest/preview/sync/service/Document.java index e441c9a544..38c90de038 100644 --- a/src/main/java/com/twilio/rest/preview/sync/service/Document.java +++ b/src/main/java/com/twilio/rest/preview/sync/service/Document.java @@ -23,55 +23,64 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Document extends Resource { + private static final long serialVersionUID = 115316298329366L; - public static DocumentCreator creator(final String pathServiceSid){ + public static DocumentCreator creator(final String pathServiceSid) { return new DocumentCreator(pathServiceSid); } - public static DocumentDeleter deleter(final String pathServiceSid, final String pathSid){ + public static DocumentDeleter deleter( + final String pathServiceSid, + final String pathSid + ) { return new DocumentDeleter(pathServiceSid, pathSid); } - public static DocumentFetcher fetcher(final String pathServiceSid, final String pathSid){ + public static DocumentFetcher fetcher( + final String pathServiceSid, + final String pathSid + ) { return new DocumentFetcher(pathServiceSid, pathSid); } - public static DocumentReader reader(final String pathServiceSid){ + public static DocumentReader reader(final String pathServiceSid) { return new DocumentReader(pathServiceSid); } - public static DocumentUpdater updater(final String pathServiceSid, final String pathSid, final Map data){ + public static DocumentUpdater updater( + final String pathServiceSid, + final String pathSid, + final Map data + ) { return new DocumentUpdater(pathServiceSid, pathSid, data); } /** - * Converts a JSON String into a Document object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Document object represented by the provided JSON - */ - public static Document fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Document object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Document object represented by the provided JSON + */ + public static Document fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Document.class); @@ -83,14 +92,17 @@ public static Document fromJson(final String json, final ObjectMapper objectMapp } /** - * Converts a JSON InputStream into a Document object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Document object represented by the provided JSON - */ - public static Document fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Document object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Document object represented by the provided JSON + */ + public static Document fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Document.class); @@ -115,38 +127,17 @@ public static Document fromJson(final InputStream json, final ObjectMapper objec @JsonCreator private Document( - @JsonProperty("sid") - final String sid, - - @JsonProperty("unique_name") - final String uniqueName, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links, - - @JsonProperty("revision") - final String revision, - - @JsonProperty("data") - final Map data, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("created_by") - final String createdBy + @JsonProperty("sid") final String sid, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links, + @JsonProperty("revision") final String revision, + @JsonProperty("data") final Map data, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("created_by") final String createdBy ) { this.sid = sid; this.uniqueName = uniqueName; @@ -161,43 +152,53 @@ private Document( this.createdBy = createdBy; } - public final String getSid() { - return this.sid; - } - public final String getUniqueName() { - return this.uniqueName; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } - public final String getRevision() { - return this.revision; - } - public final Map getData() { - return this.data; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getCreatedBy() { - return this.createdBy; - } + public final String getSid() { + return this.sid; + } + + public final String getUniqueName() { + return this.uniqueName; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } + + public final String getRevision() { + return this.revision; + } + + public final Map getData() { + return this.data; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getCreatedBy() { + return this.createdBy; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -207,13 +208,35 @@ public boolean equals(final Object o) { Document other = (Document) o; - return Objects.equals(sid, other.sid) && Objects.equals(uniqueName, other.uniqueName) && Objects.equals(accountSid, other.accountSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(url, other.url) && Objects.equals(links, other.links) && Objects.equals(revision, other.revision) && Objects.equals(data, other.data) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(createdBy, other.createdBy) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) && + Objects.equals(revision, other.revision) && + Objects.equals(data, other.data) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(createdBy, other.createdBy) + ); } @Override public int hashCode() { - return Objects.hash(sid, uniqueName, accountSid, serviceSid, url, links, revision, data, dateCreated, dateUpdated, createdBy); + return Objects.hash( + sid, + uniqueName, + accountSid, + serviceSid, + url, + links, + revision, + data, + dateCreated, + dateUpdated, + createdBy + ); } - } - diff --git a/src/main/java/com/twilio/rest/preview/sync/service/DocumentCreator.java b/src/main/java/com/twilio/rest/preview/sync/service/DocumentCreator.java index 5b6a56e675..66df22ba27 100644 --- a/src/main/java/com/twilio/rest/preview/sync/service/DocumentCreator.java +++ b/src/main/java/com/twilio/rest/preview/sync/service/DocumentCreator.java @@ -15,8 +15,10 @@ package com.twilio.rest.preview.sync.service; import com.twilio.base.Creator; -import com.twilio.exception.ApiConnectionException; +import com.twilio.constant.EnumConstants; +import com.twilio.converter.Converter; import com.twilio.converter.Converter; +import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; @@ -25,13 +27,10 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.util.Map; -import com.twilio.converter.Converter; - import java.util.Map; +public class DocumentCreator extends Creator { - -public class DocumentCreator extends Creator{ private String pathServiceSid; private String uniqueName; private Map data; @@ -40,48 +39,61 @@ public DocumentCreator(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - public DocumentCreator setUniqueName(final String uniqueName){ + public DocumentCreator setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - public DocumentCreator setData(final Map data){ + + public DocumentCreator setData(final Map data) { this.data = data; return this; } @Override - public Document create(final TwilioRestClient client){ + public Document create(final TwilioRestClient client) { String path = "/Sync/Services/{ServiceSid}/Documents"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.PREVIEW.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Document creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Document creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Document.fromJson(response.getStream(), client.getObjectMapper()); + return Document.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (uniqueName != null) { request.addPostParam("UniqueName", uniqueName); - } if (data != null) { - request.addPostParam("Data", Converter.mapToJson(data)); - + request.addPostParam("Data", Converter.mapToJson(data)); } } } diff --git a/src/main/java/com/twilio/rest/preview/sync/service/DocumentDeleter.java b/src/main/java/com/twilio/rest/preview/sync/service/DocumentDeleter.java index 3b98f24912..1674dac5a6 100644 --- a/src/main/java/com/twilio/rest/preview/sync/service/DocumentDeleter.java +++ b/src/main/java/com/twilio/rest/preview/sync/service/DocumentDeleter.java @@ -24,24 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class DocumentDeleter extends Deleter { + private String pathServiceSid; private String pathSid; - public DocumentDeleter(final String pathServiceSid, final String pathSid){ + public DocumentDeleter(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/Sync/Services/{ServiceSid}/Documents/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +53,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Document delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Document delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/preview/sync/service/DocumentFetcher.java b/src/main/java/com/twilio/rest/preview/sync/service/DocumentFetcher.java index b7d20e0f58..fb1f2b1ff6 100644 --- a/src/main/java/com/twilio/rest/preview/sync/service/DocumentFetcher.java +++ b/src/main/java/com/twilio/rest/preview/sync/service/DocumentFetcher.java @@ -24,25 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class DocumentFetcher extends Fetcher { + private String pathServiceSid; private String pathSid; - public DocumentFetcher(final String pathServiceSid, final String pathSid){ + public DocumentFetcher(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - @Override public Document fetch(final TwilioRestClient client) { String path = "/Sync/Services/{ServiceSid}/Documents/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,15 +53,23 @@ public Document fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Document fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Document fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Document.fromJson(response.getStream(), client.getObjectMapper()); + return Document.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/preview/sync/service/DocumentReader.java b/src/main/java/com/twilio/rest/preview/sync/service/DocumentReader.java index 11bd850a9c..cf5fc9ed6f 100644 --- a/src/main/java/com/twilio/rest/preview/sync/service/DocumentReader.java +++ b/src/main/java/com/twilio/rest/preview/sync/service/DocumentReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.preview.sync.service; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,19 +25,17 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class DocumentReader extends Reader { + private String pathServiceSid; private Integer pageSize; - public DocumentReader(final String pathServiceSid){ + public DocumentReader(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - public DocumentReader setPageSize(final Integer pageSize){ + public DocumentReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -48,7 +47,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/Sync/Services/{ServiceSid}/Documents"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -60,13 +63,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Document read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Document read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +93,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reque } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.PREVIEW.toString()) @@ -90,9 +104,11 @@ public Page previousPage(final Page page, final TwilioRestCl return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.PREVIEW.toString()) @@ -101,21 +117,21 @@ public Page nextPage(final Page page, final TwilioRestClient } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/preview/sync/service/DocumentUpdater.java b/src/main/java/com/twilio/rest/preview/sync/service/DocumentUpdater.java index 672278011c..31e45f7061 100644 --- a/src/main/java/com/twilio/rest/preview/sync/service/DocumentUpdater.java +++ b/src/main/java/com/twilio/rest/preview/sync/service/DocumentUpdater.java @@ -15,8 +15,9 @@ package com.twilio.rest.preview.sync.service; import com.twilio.base.Updater; -import com.twilio.exception.ApiConnectionException; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Converter; +import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; @@ -24,70 +25,86 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - import java.util.Map; +public class DocumentUpdater extends Updater { -public class DocumentUpdater extends Updater{ private String pathServiceSid; private String pathSid; private Map data; private String ifMatch; - public DocumentUpdater(final String pathServiceSid, final String pathSid, final Map data){ + public DocumentUpdater( + final String pathServiceSid, + final String pathSid, + final Map data + ) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; this.data = data; } - public DocumentUpdater setData(final Map data){ + public DocumentUpdater setData(final Map data) { this.data = data; return this; } - public DocumentUpdater setIfMatch(final String ifMatch){ + + public DocumentUpdater setIfMatch(final String ifMatch) { this.ifMatch = ifMatch; return this; } @Override - public Document update(final TwilioRestClient client){ + public Document update(final TwilioRestClient client) { String path = "/Sync/Services/{ServiceSid}/Documents/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); - path = path.replace("{"+"Data"+"}", this.data.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + path = path.replace("{" + "Data" + "}", this.data.toString()); Request request = new Request( HttpMethod.POST, Domains.PREVIEW.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); addHeaderParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Document update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Document update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Document.fromJson(response.getStream(), client.getObjectMapper()); + return Document.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (data != null) { - request.addPostParam("Data", Converter.mapToJson(data)); - + request.addPostParam("Data", Converter.mapToJson(data)); } } + private void addHeaderParams(final Request request) { if (ifMatch != null) { request.addHeaderParam("If-Match", ifMatch); - } } } diff --git a/src/main/java/com/twilio/rest/preview/sync/service/SyncList.java b/src/main/java/com/twilio/rest/preview/sync/service/SyncList.java index 682f98f77b..2f42577a80 100644 --- a/src/main/java/com/twilio/rest/preview/sync/service/SyncList.java +++ b/src/main/java/com/twilio/rest/preview/sync/service/SyncList.java @@ -23,51 +23,56 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class SyncList extends Resource { + private static final long serialVersionUID = 90485787612091L; - public static SyncListCreator creator(final String pathServiceSid){ + public static SyncListCreator creator(final String pathServiceSid) { return new SyncListCreator(pathServiceSid); } - public static SyncListDeleter deleter(final String pathServiceSid, final String pathSid){ + public static SyncListDeleter deleter( + final String pathServiceSid, + final String pathSid + ) { return new SyncListDeleter(pathServiceSid, pathSid); } - public static SyncListFetcher fetcher(final String pathServiceSid, final String pathSid){ + public static SyncListFetcher fetcher( + final String pathServiceSid, + final String pathSid + ) { return new SyncListFetcher(pathServiceSid, pathSid); } - public static SyncListReader reader(final String pathServiceSid){ + public static SyncListReader reader(final String pathServiceSid) { return new SyncListReader(pathServiceSid); } /** - * Converts a JSON String into a SyncList object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return SyncList object represented by the provided JSON - */ - public static SyncList fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a SyncList object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return SyncList object represented by the provided JSON + */ + public static SyncList fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SyncList.class); @@ -79,14 +84,17 @@ public static SyncList fromJson(final String json, final ObjectMapper objectMapp } /** - * Converts a JSON InputStream into a SyncList object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return SyncList object represented by the provided JSON - */ - public static SyncList fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a SyncList object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return SyncList object represented by the provided JSON + */ + public static SyncList fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SyncList.class); @@ -110,35 +118,16 @@ public static SyncList fromJson(final InputStream json, final ObjectMapper objec @JsonCreator private SyncList( - @JsonProperty("sid") - final String sid, - - @JsonProperty("unique_name") - final String uniqueName, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links, - - @JsonProperty("revision") - final String revision, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("created_by") - final String createdBy + @JsonProperty("sid") final String sid, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links, + @JsonProperty("revision") final String revision, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("created_by") final String createdBy ) { this.sid = sid; this.uniqueName = uniqueName; @@ -152,40 +141,49 @@ private SyncList( this.createdBy = createdBy; } - public final String getSid() { - return this.sid; - } - public final String getUniqueName() { - return this.uniqueName; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } - public final String getRevision() { - return this.revision; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getCreatedBy() { - return this.createdBy; - } + public final String getSid() { + return this.sid; + } + + public final String getUniqueName() { + return this.uniqueName; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } + + public final String getRevision() { + return this.revision; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getCreatedBy() { + return this.createdBy; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -195,13 +193,33 @@ public boolean equals(final Object o) { SyncList other = (SyncList) o; - return Objects.equals(sid, other.sid) && Objects.equals(uniqueName, other.uniqueName) && Objects.equals(accountSid, other.accountSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(url, other.url) && Objects.equals(links, other.links) && Objects.equals(revision, other.revision) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(createdBy, other.createdBy) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) && + Objects.equals(revision, other.revision) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(createdBy, other.createdBy) + ); } @Override public int hashCode() { - return Objects.hash(sid, uniqueName, accountSid, serviceSid, url, links, revision, dateCreated, dateUpdated, createdBy); + return Objects.hash( + sid, + uniqueName, + accountSid, + serviceSid, + url, + links, + revision, + dateCreated, + dateUpdated, + createdBy + ); } - } - diff --git a/src/main/java/com/twilio/rest/preview/sync/service/SyncListCreator.java b/src/main/java/com/twilio/rest/preview/sync/service/SyncListCreator.java index 2d9a61c62d..304ac2bd2f 100644 --- a/src/main/java/com/twilio/rest/preview/sync/service/SyncListCreator.java +++ b/src/main/java/com/twilio/rest/preview/sync/service/SyncListCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.preview.sync.service; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class SyncListCreator extends Creator { - - -public class SyncListCreator extends Creator{ private String pathServiceSid; private String uniqueName; @@ -35,40 +34,53 @@ public SyncListCreator(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - public SyncListCreator setUniqueName(final String uniqueName){ + public SyncListCreator setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } @Override - public SyncList create(final TwilioRestClient client){ + public SyncList create(final TwilioRestClient client) { String path = "/Sync/Services/{ServiceSid}/Lists"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.PREVIEW.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncList creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "SyncList creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return SyncList.fromJson(response.getStream(), client.getObjectMapper()); + return SyncList.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (uniqueName != null) { request.addPostParam("UniqueName", uniqueName); - } } } diff --git a/src/main/java/com/twilio/rest/preview/sync/service/SyncListDeleter.java b/src/main/java/com/twilio/rest/preview/sync/service/SyncListDeleter.java index 7c65dc9988..e9ec845147 100644 --- a/src/main/java/com/twilio/rest/preview/sync/service/SyncListDeleter.java +++ b/src/main/java/com/twilio/rest/preview/sync/service/SyncListDeleter.java @@ -24,24 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class SyncListDeleter extends Deleter { + private String pathServiceSid; private String pathSid; - public SyncListDeleter(final String pathServiceSid, final String pathSid){ + public SyncListDeleter(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/Sync/Services/{ServiceSid}/Lists/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +53,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncList delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "SyncList delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/preview/sync/service/SyncListFetcher.java b/src/main/java/com/twilio/rest/preview/sync/service/SyncListFetcher.java index e4da33e97a..97fcd20fcd 100644 --- a/src/main/java/com/twilio/rest/preview/sync/service/SyncListFetcher.java +++ b/src/main/java/com/twilio/rest/preview/sync/service/SyncListFetcher.java @@ -24,25 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class SyncListFetcher extends Fetcher { + private String pathServiceSid; private String pathSid; - public SyncListFetcher(final String pathServiceSid, final String pathSid){ + public SyncListFetcher(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - @Override public SyncList fetch(final TwilioRestClient client) { String path = "/Sync/Services/{ServiceSid}/Lists/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,15 +53,23 @@ public SyncList fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncList fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "SyncList fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return SyncList.fromJson(response.getStream(), client.getObjectMapper()); + return SyncList.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/preview/sync/service/SyncListReader.java b/src/main/java/com/twilio/rest/preview/sync/service/SyncListReader.java index 653cc1a72b..63d37407ab 100644 --- a/src/main/java/com/twilio/rest/preview/sync/service/SyncListReader.java +++ b/src/main/java/com/twilio/rest/preview/sync/service/SyncListReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.preview.sync.service; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,19 +25,17 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class SyncListReader extends Reader { + private String pathServiceSid; private Integer pageSize; - public SyncListReader(final String pathServiceSid){ + public SyncListReader(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - public SyncListReader setPageSize(final Integer pageSize){ + public SyncListReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -48,7 +47,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/Sync/Services/{ServiceSid}/Lists"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -60,13 +63,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncList read failed: Unable to connect to server"); + throw new ApiConnectionException( + "SyncList read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +93,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reque } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.PREVIEW.toString()) @@ -90,9 +104,11 @@ public Page previousPage(final Page page, final TwilioRestCl return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.PREVIEW.toString()) @@ -101,21 +117,21 @@ public Page nextPage(final Page page, final TwilioRestClient } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/preview/sync/service/SyncMap.java b/src/main/java/com/twilio/rest/preview/sync/service/SyncMap.java index 350790e86f..9bb7084867 100644 --- a/src/main/java/com/twilio/rest/preview/sync/service/SyncMap.java +++ b/src/main/java/com/twilio/rest/preview/sync/service/SyncMap.java @@ -23,51 +23,56 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class SyncMap extends Resource { + private static final long serialVersionUID = 90485787612091L; - public static SyncMapCreator creator(final String pathServiceSid){ + public static SyncMapCreator creator(final String pathServiceSid) { return new SyncMapCreator(pathServiceSid); } - public static SyncMapDeleter deleter(final String pathServiceSid, final String pathSid){ + public static SyncMapDeleter deleter( + final String pathServiceSid, + final String pathSid + ) { return new SyncMapDeleter(pathServiceSid, pathSid); } - public static SyncMapFetcher fetcher(final String pathServiceSid, final String pathSid){ + public static SyncMapFetcher fetcher( + final String pathServiceSid, + final String pathSid + ) { return new SyncMapFetcher(pathServiceSid, pathSid); } - public static SyncMapReader reader(final String pathServiceSid){ + public static SyncMapReader reader(final String pathServiceSid) { return new SyncMapReader(pathServiceSid); } /** - * Converts a JSON String into a SyncMap object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return SyncMap object represented by the provided JSON - */ - public static SyncMap fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a SyncMap object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return SyncMap object represented by the provided JSON + */ + public static SyncMap fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SyncMap.class); @@ -79,14 +84,17 @@ public static SyncMap fromJson(final String json, final ObjectMapper objectMappe } /** - * Converts a JSON InputStream into a SyncMap object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return SyncMap object represented by the provided JSON - */ - public static SyncMap fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a SyncMap object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return SyncMap object represented by the provided JSON + */ + public static SyncMap fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SyncMap.class); @@ -110,35 +118,16 @@ public static SyncMap fromJson(final InputStream json, final ObjectMapper object @JsonCreator private SyncMap( - @JsonProperty("sid") - final String sid, - - @JsonProperty("unique_name") - final String uniqueName, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links, - - @JsonProperty("revision") - final String revision, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("created_by") - final String createdBy + @JsonProperty("sid") final String sid, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links, + @JsonProperty("revision") final String revision, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("created_by") final String createdBy ) { this.sid = sid; this.uniqueName = uniqueName; @@ -152,40 +141,49 @@ private SyncMap( this.createdBy = createdBy; } - public final String getSid() { - return this.sid; - } - public final String getUniqueName() { - return this.uniqueName; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } - public final String getRevision() { - return this.revision; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getCreatedBy() { - return this.createdBy; - } + public final String getSid() { + return this.sid; + } + + public final String getUniqueName() { + return this.uniqueName; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } + + public final String getRevision() { + return this.revision; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getCreatedBy() { + return this.createdBy; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -195,13 +193,33 @@ public boolean equals(final Object o) { SyncMap other = (SyncMap) o; - return Objects.equals(sid, other.sid) && Objects.equals(uniqueName, other.uniqueName) && Objects.equals(accountSid, other.accountSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(url, other.url) && Objects.equals(links, other.links) && Objects.equals(revision, other.revision) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(createdBy, other.createdBy) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) && + Objects.equals(revision, other.revision) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(createdBy, other.createdBy) + ); } @Override public int hashCode() { - return Objects.hash(sid, uniqueName, accountSid, serviceSid, url, links, revision, dateCreated, dateUpdated, createdBy); + return Objects.hash( + sid, + uniqueName, + accountSid, + serviceSid, + url, + links, + revision, + dateCreated, + dateUpdated, + createdBy + ); } - } - diff --git a/src/main/java/com/twilio/rest/preview/sync/service/SyncMapCreator.java b/src/main/java/com/twilio/rest/preview/sync/service/SyncMapCreator.java index 5b51dfc748..836a62c01a 100644 --- a/src/main/java/com/twilio/rest/preview/sync/service/SyncMapCreator.java +++ b/src/main/java/com/twilio/rest/preview/sync/service/SyncMapCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.preview.sync.service; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class SyncMapCreator extends Creator { - - -public class SyncMapCreator extends Creator{ private String pathServiceSid; private String uniqueName; @@ -35,28 +34,38 @@ public SyncMapCreator(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - public SyncMapCreator setUniqueName(final String uniqueName){ + public SyncMapCreator setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } @Override - public SyncMap create(final TwilioRestClient client){ + public SyncMap create(final TwilioRestClient client) { String path = "/Sync/Services/{ServiceSid}/Maps"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.PREVIEW.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncMap creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "SyncMap creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -65,10 +74,10 @@ public SyncMap create(final TwilioRestClient client){ return SyncMap.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (uniqueName != null) { request.addPostParam("UniqueName", uniqueName); - } } } diff --git a/src/main/java/com/twilio/rest/preview/sync/service/SyncMapDeleter.java b/src/main/java/com/twilio/rest/preview/sync/service/SyncMapDeleter.java index 56d36f486b..083e7ef4b8 100644 --- a/src/main/java/com/twilio/rest/preview/sync/service/SyncMapDeleter.java +++ b/src/main/java/com/twilio/rest/preview/sync/service/SyncMapDeleter.java @@ -24,24 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class SyncMapDeleter extends Deleter { + private String pathServiceSid; private String pathSid; - public SyncMapDeleter(final String pathServiceSid, final String pathSid){ + public SyncMapDeleter(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/Sync/Services/{ServiceSid}/Maps/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +53,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncMap delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "SyncMap delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/preview/sync/service/SyncMapFetcher.java b/src/main/java/com/twilio/rest/preview/sync/service/SyncMapFetcher.java index d73fbb67c3..661d19d586 100644 --- a/src/main/java/com/twilio/rest/preview/sync/service/SyncMapFetcher.java +++ b/src/main/java/com/twilio/rest/preview/sync/service/SyncMapFetcher.java @@ -24,25 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class SyncMapFetcher extends Fetcher { + private String pathServiceSid; private String pathSid; - public SyncMapFetcher(final String pathServiceSid, final String pathSid){ + public SyncMapFetcher(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - @Override public SyncMap fetch(final TwilioRestClient client) { String path = "/Sync/Services/{ServiceSid}/Maps/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,9 +53,14 @@ public SyncMap fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncMap fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "SyncMap fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/preview/sync/service/SyncMapReader.java b/src/main/java/com/twilio/rest/preview/sync/service/SyncMapReader.java index 3788271e27..9cc02619c7 100644 --- a/src/main/java/com/twilio/rest/preview/sync/service/SyncMapReader.java +++ b/src/main/java/com/twilio/rest/preview/sync/service/SyncMapReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.preview.sync.service; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,19 +25,17 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class SyncMapReader extends Reader { + private String pathServiceSid; private Integer pageSize; - public SyncMapReader(final String pathServiceSid){ + public SyncMapReader(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - public SyncMapReader setPageSize(final Integer pageSize){ + public SyncMapReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -48,7 +47,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/Sync/Services/{ServiceSid}/Maps"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -60,13 +63,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncMap read failed: Unable to connect to server"); + throw new ApiConnectionException( + "SyncMap read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +93,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reques } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.PREVIEW.toString()) @@ -90,9 +104,11 @@ public Page previousPage(final Page page, final TwilioRestClie return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.PREVIEW.toString()) @@ -101,21 +117,21 @@ public Page nextPage(final Page page, final TwilioRestClient c } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/preview/sync/service/document/DocumentPermission.java b/src/main/java/com/twilio/rest/preview/sync/service/document/DocumentPermission.java index 5dbde44534..cca948c3b6 100644 --- a/src/main/java/com/twilio/rest/preview/sync/service/document/DocumentPermission.java +++ b/src/main/java/com/twilio/rest/preview/sync/service/document/DocumentPermission.java @@ -22,48 +22,80 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class DocumentPermission extends Resource { + private static final long serialVersionUID = 90173038651529L; - public static DocumentPermissionDeleter deleter(final String pathServiceSid, final String pathDocumentSid, final String pathIdentity){ - return new DocumentPermissionDeleter(pathServiceSid, pathDocumentSid, pathIdentity); + public static DocumentPermissionDeleter deleter( + final String pathServiceSid, + final String pathDocumentSid, + final String pathIdentity + ) { + return new DocumentPermissionDeleter( + pathServiceSid, + pathDocumentSid, + pathIdentity + ); } - public static DocumentPermissionFetcher fetcher(final String pathServiceSid, final String pathDocumentSid, final String pathIdentity){ - return new DocumentPermissionFetcher(pathServiceSid, pathDocumentSid, pathIdentity); + public static DocumentPermissionFetcher fetcher( + final String pathServiceSid, + final String pathDocumentSid, + final String pathIdentity + ) { + return new DocumentPermissionFetcher( + pathServiceSid, + pathDocumentSid, + pathIdentity + ); } - public static DocumentPermissionReader reader(final String pathServiceSid, final String pathDocumentSid){ + public static DocumentPermissionReader reader( + final String pathServiceSid, + final String pathDocumentSid + ) { return new DocumentPermissionReader(pathServiceSid, pathDocumentSid); } - public static DocumentPermissionUpdater updater(final String pathServiceSid, final String pathDocumentSid, final String pathIdentity, final Boolean read, final Boolean write, final Boolean manage){ - return new DocumentPermissionUpdater(pathServiceSid, pathDocumentSid, pathIdentity, read, write, manage); + public static DocumentPermissionUpdater updater( + final String pathServiceSid, + final String pathDocumentSid, + final String pathIdentity, + final Boolean read, + final Boolean write, + final Boolean manage + ) { + return new DocumentPermissionUpdater( + pathServiceSid, + pathDocumentSid, + pathIdentity, + read, + write, + manage + ); } /** - * Converts a JSON String into a DocumentPermission object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return DocumentPermission object represented by the provided JSON - */ - public static DocumentPermission fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a DocumentPermission object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return DocumentPermission object represented by the provided JSON + */ + public static DocumentPermission fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, DocumentPermission.class); @@ -75,14 +107,17 @@ public static DocumentPermission fromJson(final String json, final ObjectMapper } /** - * Converts a JSON InputStream into a DocumentPermission object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return DocumentPermission object represented by the provided JSON - */ - public static DocumentPermission fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a DocumentPermission object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return DocumentPermission object represented by the provided JSON + */ + public static DocumentPermission fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, DocumentPermission.class); @@ -104,29 +139,14 @@ public static DocumentPermission fromJson(final InputStream json, final ObjectMa @JsonCreator private DocumentPermission( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("document_sid") - final String documentSid, - - @JsonProperty("identity") - final String identity, - - @JsonProperty("read") - final Boolean read, - - @JsonProperty("write") - final Boolean write, - - @JsonProperty("manage") - final Boolean manage, - - @JsonProperty("url") - final URI url + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("document_sid") final String documentSid, + @JsonProperty("identity") final String identity, + @JsonProperty("read") final Boolean read, + @JsonProperty("write") final Boolean write, + @JsonProperty("manage") final Boolean manage, + @JsonProperty("url") final URI url ) { this.accountSid = accountSid; this.serviceSid = serviceSid; @@ -138,34 +158,41 @@ private DocumentPermission( this.url = url; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final String getDocumentSid() { - return this.documentSid; - } - public final String getIdentity() { - return this.identity; - } - public final Boolean getRead() { - return this.read; - } - public final Boolean getWrite() { - return this.write; - } - public final Boolean getManage() { - return this.manage; - } - public final URI getUrl() { - return this.url; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final String getDocumentSid() { + return this.documentSid; + } + + public final String getIdentity() { + return this.identity; + } + + public final Boolean getRead() { + return this.read; + } + + public final Boolean getWrite() { + return this.write; + } + + public final Boolean getManage() { + return this.manage; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -175,13 +202,29 @@ public boolean equals(final Object o) { DocumentPermission other = (DocumentPermission) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(documentSid, other.documentSid) && Objects.equals(identity, other.identity) && Objects.equals(read, other.read) && Objects.equals(write, other.write) && Objects.equals(manage, other.manage) && Objects.equals(url, other.url) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(documentSid, other.documentSid) && + Objects.equals(identity, other.identity) && + Objects.equals(read, other.read) && + Objects.equals(write, other.write) && + Objects.equals(manage, other.manage) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, serviceSid, documentSid, identity, read, write, manage, url); + return Objects.hash( + accountSid, + serviceSid, + documentSid, + identity, + read, + write, + manage, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/preview/sync/service/document/DocumentPermissionDeleter.java b/src/main/java/com/twilio/rest/preview/sync/service/document/DocumentPermissionDeleter.java index b34357eadb..56fa213eba 100644 --- a/src/main/java/com/twilio/rest/preview/sync/service/document/DocumentPermissionDeleter.java +++ b/src/main/java/com/twilio/rest/preview/sync/service/document/DocumentPermissionDeleter.java @@ -24,27 +24,39 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class DocumentPermissionDeleter extends Deleter { + private String pathServiceSid; private String pathDocumentSid; private String pathIdentity; - public DocumentPermissionDeleter(final String pathServiceSid, final String pathDocumentSid, final String pathIdentity){ + public DocumentPermissionDeleter( + final String pathServiceSid, + final String pathDocumentSid, + final String pathIdentity + ) { this.pathServiceSid = pathServiceSid; this.pathDocumentSid = pathDocumentSid; this.pathIdentity = pathIdentity; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/Sync/Services/{ServiceSid}/Documents/{DocumentSid}/Permissions/{Identity}"; + String path = + "/Sync/Services/{ServiceSid}/Documents/{DocumentSid}/Permissions/{Identity}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"DocumentSid"+"}", this.pathDocumentSid.toString()); - path = path.replace("{"+"Identity"+"}", this.pathIdentity.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "DocumentSid" + "}", + this.pathDocumentSid.toString() + ); + path = + path.replace("{" + "Identity" + "}", this.pathIdentity.toString()); Request request = new Request( HttpMethod.DELETE, @@ -54,9 +66,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("DocumentPermission delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "DocumentPermission delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/preview/sync/service/document/DocumentPermissionFetcher.java b/src/main/java/com/twilio/rest/preview/sync/service/document/DocumentPermissionFetcher.java index e81f7cd09d..6b7fc4c3c2 100644 --- a/src/main/java/com/twilio/rest/preview/sync/service/document/DocumentPermissionFetcher.java +++ b/src/main/java/com/twilio/rest/preview/sync/service/document/DocumentPermissionFetcher.java @@ -24,28 +24,39 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class DocumentPermissionFetcher extends Fetcher { + private String pathServiceSid; private String pathDocumentSid; private String pathIdentity; - public DocumentPermissionFetcher(final String pathServiceSid, final String pathDocumentSid, final String pathIdentity){ + public DocumentPermissionFetcher( + final String pathServiceSid, + final String pathDocumentSid, + final String pathIdentity + ) { this.pathServiceSid = pathServiceSid; this.pathDocumentSid = pathDocumentSid; this.pathIdentity = pathIdentity; } - @Override public DocumentPermission fetch(final TwilioRestClient client) { - String path = "/Sync/Services/{ServiceSid}/Documents/{DocumentSid}/Permissions/{Identity}"; + String path = + "/Sync/Services/{ServiceSid}/Documents/{DocumentSid}/Permissions/{Identity}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"DocumentSid"+"}", this.pathDocumentSid.toString()); - path = path.replace("{"+"Identity"+"}", this.pathIdentity.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "DocumentSid" + "}", + this.pathDocumentSid.toString() + ); + path = + path.replace("{" + "Identity" + "}", this.pathIdentity.toString()); Request request = new Request( HttpMethod.GET, @@ -55,15 +66,23 @@ public DocumentPermission fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("DocumentPermission fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "DocumentPermission fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return DocumentPermission.fromJson(response.getStream(), client.getObjectMapper()); + return DocumentPermission.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/preview/sync/service/document/DocumentPermissionReader.java b/src/main/java/com/twilio/rest/preview/sync/service/document/DocumentPermissionReader.java index d8d2b74a26..40709b6045 100644 --- a/src/main/java/com/twilio/rest/preview/sync/service/document/DocumentPermissionReader.java +++ b/src/main/java/com/twilio/rest/preview/sync/service/document/DocumentPermissionReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.preview.sync.service.document; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,21 +25,22 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class DocumentPermissionReader extends Reader { + private String pathServiceSid; private String pathDocumentSid; private Integer pageSize; - public DocumentPermissionReader(final String pathServiceSid, final String pathDocumentSid){ + public DocumentPermissionReader( + final String pathServiceSid, + final String pathDocumentSid + ) { this.pathServiceSid = pathServiceSid; this.pathDocumentSid = pathDocumentSid; } - public DocumentPermissionReader setPageSize(final Integer pageSize){ + public DocumentPermissionReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -49,9 +51,18 @@ public ResourceSet read(final TwilioRestClient client) { } public Page firstPage(final TwilioRestClient client) { - String path = "/Sync/Services/{ServiceSid}/Documents/{DocumentSid}/Permissions"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"DocumentSid"+"}", this.pathDocumentSid.toString()); + String path = + "/Sync/Services/{ServiceSid}/Documents/{DocumentSid}/Permissions"; + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "DocumentSid" + "}", + this.pathDocumentSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -63,13 +74,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("DocumentPermission read failed: Unable to connect to server"); + throw new ApiConnectionException( + "DocumentPermission read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -85,7 +104,10 @@ private Page pageForRequest(final TwilioRestClient client, f } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.PREVIEW.toString()) @@ -93,9 +115,11 @@ public Page previousPage(final Page page return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.PREVIEW.toString()) @@ -104,21 +128,21 @@ public Page nextPage(final Page page, fi } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/preview/sync/service/document/DocumentPermissionUpdater.java b/src/main/java/com/twilio/rest/preview/sync/service/document/DocumentPermissionUpdater.java index 9dbb99f736..7bec386b8b 100644 --- a/src/main/java/com/twilio/rest/preview/sync/service/document/DocumentPermissionUpdater.java +++ b/src/main/java/com/twilio/rest/preview/sync/service/document/DocumentPermissionUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.preview.sync.service.document; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class DocumentPermissionUpdater extends Updater { - - -public class DocumentPermissionUpdater extends Updater{ private String pathServiceSid; private String pathDocumentSid; private String pathIdentity; @@ -35,7 +34,14 @@ public class DocumentPermissionUpdater extends Updater{ private Boolean write; private Boolean manage; - public DocumentPermissionUpdater(final String pathServiceSid, final String pathDocumentSid, final String pathIdentity, final Boolean read, final Boolean write, final Boolean manage){ + public DocumentPermissionUpdater( + final String pathServiceSid, + final String pathDocumentSid, + final String pathIdentity, + final Boolean read, + final Boolean write, + final Boolean manage + ) { this.pathServiceSid = pathServiceSid; this.pathDocumentSid = pathDocumentSid; this.pathIdentity = pathIdentity; @@ -44,61 +50,80 @@ public DocumentPermissionUpdater(final String pathServiceSid, final String pathD this.manage = manage; } - public DocumentPermissionUpdater setRead(final Boolean read){ + public DocumentPermissionUpdater setRead(final Boolean read) { this.read = read; return this; } - public DocumentPermissionUpdater setWrite(final Boolean write){ + + public DocumentPermissionUpdater setWrite(final Boolean write) { this.write = write; return this; } - public DocumentPermissionUpdater setManage(final Boolean manage){ + + public DocumentPermissionUpdater setManage(final Boolean manage) { this.manage = manage; return this; } @Override - public DocumentPermission update(final TwilioRestClient client){ - String path = "/Sync/Services/{ServiceSid}/Documents/{DocumentSid}/Permissions/{Identity}"; + public DocumentPermission update(final TwilioRestClient client) { + String path = + "/Sync/Services/{ServiceSid}/Documents/{DocumentSid}/Permissions/{Identity}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"DocumentSid"+"}", this.pathDocumentSid.toString()); - path = path.replace("{"+"Identity"+"}", this.pathIdentity.toString()); - path = path.replace("{"+"Read"+"}", this.read.toString()); - path = path.replace("{"+"Write"+"}", this.write.toString()); - path = path.replace("{"+"Manage"+"}", this.manage.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "DocumentSid" + "}", + this.pathDocumentSid.toString() + ); + path = + path.replace("{" + "Identity" + "}", this.pathIdentity.toString()); + path = path.replace("{" + "Read" + "}", this.read.toString()); + path = path.replace("{" + "Write" + "}", this.write.toString()); + path = path.replace("{" + "Manage" + "}", this.manage.toString()); Request request = new Request( HttpMethod.POST, Domains.PREVIEW.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("DocumentPermission update failed: Unable to connect to server"); + throw new ApiConnectionException( + "DocumentPermission update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return DocumentPermission.fromJson(response.getStream(), client.getObjectMapper()); + return DocumentPermission.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (read != null) { request.addPostParam("Read", read.toString()); - } if (write != null) { request.addPostParam("Write", write.toString()); - } if (manage != null) { request.addPostParam("Manage", manage.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListItem.java b/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListItem.java index 03fc8112b5..20a517aa28 100644 --- a/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListItem.java +++ b/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListItem.java @@ -24,55 +24,79 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class SyncListItem extends Resource { + private static final long serialVersionUID = 44561675896318L; - public static SyncListItemCreator creator(final String pathServiceSid, final String pathListSid, final Map data){ + public static SyncListItemCreator creator( + final String pathServiceSid, + final String pathListSid, + final Map data + ) { return new SyncListItemCreator(pathServiceSid, pathListSid, data); } - public static SyncListItemDeleter deleter(final String pathServiceSid, final String pathListSid, final Integer pathIndex){ + public static SyncListItemDeleter deleter( + final String pathServiceSid, + final String pathListSid, + final Integer pathIndex + ) { return new SyncListItemDeleter(pathServiceSid, pathListSid, pathIndex); } - public static SyncListItemFetcher fetcher(final String pathServiceSid, final String pathListSid, final Integer pathIndex){ + public static SyncListItemFetcher fetcher( + final String pathServiceSid, + final String pathListSid, + final Integer pathIndex + ) { return new SyncListItemFetcher(pathServiceSid, pathListSid, pathIndex); } - public static SyncListItemReader reader(final String pathServiceSid, final String pathListSid){ + public static SyncListItemReader reader( + final String pathServiceSid, + final String pathListSid + ) { return new SyncListItemReader(pathServiceSid, pathListSid); } - public static SyncListItemUpdater updater(final String pathServiceSid, final String pathListSid, final Integer pathIndex, final Map data){ - return new SyncListItemUpdater(pathServiceSid, pathListSid, pathIndex, data); + public static SyncListItemUpdater updater( + final String pathServiceSid, + final String pathListSid, + final Integer pathIndex, + final Map data + ) { + return new SyncListItemUpdater( + pathServiceSid, + pathListSid, + pathIndex, + data + ); } /** - * Converts a JSON String into a SyncListItem object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return SyncListItem object represented by the provided JSON - */ - public static SyncListItem fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a SyncListItem object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return SyncListItem object represented by the provided JSON + */ + public static SyncListItem fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SyncListItem.class); @@ -84,14 +108,17 @@ public static SyncListItem fromJson(final String json, final ObjectMapper object } /** - * Converts a JSON InputStream into a SyncListItem object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return SyncListItem object represented by the provided JSON - */ - public static SyncListItem fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a SyncListItem object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return SyncListItem object represented by the provided JSON + */ + public static SyncListItem fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SyncListItem.class); @@ -101,6 +128,7 @@ public static SyncListItem fromJson(final InputStream json, final ObjectMapper o throw new ApiConnectionException(e.getMessage(), e); } } + public enum QueryFromBoundType { INCLUSIVE("inclusive"), EXCLUSIVE("exclusive"); @@ -120,6 +148,7 @@ public static QueryFromBoundType forValue(final String value) { return Promoter.enumFromString(value, QueryFromBoundType.values()); } } + public enum QueryResultOrder { ASC("asc"), DESC("desc"); @@ -153,35 +182,16 @@ public static QueryResultOrder forValue(final String value) { @JsonCreator private SyncListItem( - @JsonProperty("index") - final Integer index, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("list_sid") - final String listSid, - - @JsonProperty("url") - final URI url, - - @JsonProperty("revision") - final String revision, - - @JsonProperty("data") - final Map data, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("created_by") - final String createdBy + @JsonProperty("index") final Integer index, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("list_sid") final String listSid, + @JsonProperty("url") final URI url, + @JsonProperty("revision") final String revision, + @JsonProperty("data") final Map data, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("created_by") final String createdBy ) { this.index = index; this.accountSid = accountSid; @@ -195,40 +205,49 @@ private SyncListItem( this.createdBy = createdBy; } - public final Integer getIndex() { - return this.index; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final String getListSid() { - return this.listSid; - } - public final URI getUrl() { - return this.url; - } - public final String getRevision() { - return this.revision; - } - public final Map getData() { - return this.data; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getCreatedBy() { - return this.createdBy; - } + public final Integer getIndex() { + return this.index; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final String getListSid() { + return this.listSid; + } + + public final URI getUrl() { + return this.url; + } + + public final String getRevision() { + return this.revision; + } + + public final Map getData() { + return this.data; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getCreatedBy() { + return this.createdBy; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -238,13 +257,33 @@ public boolean equals(final Object o) { SyncListItem other = (SyncListItem) o; - return Objects.equals(index, other.index) && Objects.equals(accountSid, other.accountSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(listSid, other.listSid) && Objects.equals(url, other.url) && Objects.equals(revision, other.revision) && Objects.equals(data, other.data) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(createdBy, other.createdBy) ; + return ( + Objects.equals(index, other.index) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(listSid, other.listSid) && + Objects.equals(url, other.url) && + Objects.equals(revision, other.revision) && + Objects.equals(data, other.data) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(createdBy, other.createdBy) + ); } @Override public int hashCode() { - return Objects.hash(index, accountSid, serviceSid, listSid, url, revision, data, dateCreated, dateUpdated, createdBy); + return Objects.hash( + index, + accountSid, + serviceSid, + listSid, + url, + revision, + data, + dateCreated, + dateUpdated, + createdBy + ); } - } - diff --git a/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListItemCreator.java b/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListItemCreator.java index 7ae895d7a8..0a6a3770c7 100644 --- a/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListItemCreator.java +++ b/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListItemCreator.java @@ -15,8 +15,10 @@ package com.twilio.rest.preview.sync.service.synclist; import com.twilio.base.Creator; -import com.twilio.exception.ApiConnectionException; +import com.twilio.constant.EnumConstants; +import com.twilio.converter.Converter; import com.twilio.converter.Converter; +import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; @@ -25,59 +27,73 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.util.Map; -import com.twilio.converter.Converter; - import java.util.Map; +public class SyncListItemCreator extends Creator { - -public class SyncListItemCreator extends Creator{ private String pathServiceSid; private String pathListSid; private Map data; - public SyncListItemCreator(final String pathServiceSid, final String pathListSid, final Map data) { + public SyncListItemCreator( + final String pathServiceSid, + final String pathListSid, + final Map data + ) { this.pathServiceSid = pathServiceSid; this.pathListSid = pathListSid; this.data = data; } - public SyncListItemCreator setData(final Map data){ + public SyncListItemCreator setData(final Map data) { this.data = data; return this; } @Override - public SyncListItem create(final TwilioRestClient client){ + public SyncListItem create(final TwilioRestClient client) { String path = "/Sync/Services/{ServiceSid}/Lists/{ListSid}/Items"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ListSid"+"}", this.pathListSid.toString()); - path = path.replace("{"+"Data"+"}", this.data.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "ListSid" + "}", this.pathListSid.toString()); + path = path.replace("{" + "Data" + "}", this.data.toString()); Request request = new Request( HttpMethod.POST, Domains.PREVIEW.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncListItem creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "SyncListItem creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return SyncListItem.fromJson(response.getStream(), client.getObjectMapper()); + return SyncListItem.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (data != null) { - request.addPostParam("Data", Converter.mapToJson(data)); - + request.addPostParam("Data", Converter.mapToJson(data)); } } } diff --git a/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListItemDeleter.java b/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListItemDeleter.java index a8de2c1d3c..81b5bf4846 100644 --- a/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListItemDeleter.java +++ b/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListItemDeleter.java @@ -24,32 +24,40 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class SyncListItemDeleter extends Deleter { + private String pathServiceSid; private String pathListSid; private Integer pathIndex; private String ifMatch; - public SyncListItemDeleter(final String pathServiceSid, final String pathListSid, final Integer pathIndex){ + public SyncListItemDeleter( + final String pathServiceSid, + final String pathListSid, + final Integer pathIndex + ) { this.pathServiceSid = pathServiceSid; this.pathListSid = pathListSid; this.pathIndex = pathIndex; } - public SyncListItemDeleter setIfMatch(final String ifMatch){ + public SyncListItemDeleter setIfMatch(final String ifMatch) { this.ifMatch = ifMatch; return this; } @Override public boolean delete(final TwilioRestClient client) { - String path = "/Sync/Services/{ServiceSid}/Lists/{ListSid}/Items/{Index}"; + String path = + "/Sync/Services/{ServiceSid}/Lists/{ListSid}/Items/{Index}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ListSid"+"}", this.pathListSid.toString()); - path = path.replace("{"+"Index"+"}", this.pathIndex.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "ListSid" + "}", this.pathListSid.toString()); + path = path.replace("{" + "Index" + "}", this.pathIndex.toString()); Request request = new Request( HttpMethod.DELETE, @@ -60,9 +68,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncListItem delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "SyncListItem delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -70,10 +83,10 @@ public boolean delete(final TwilioRestClient client) { } return response.getStatusCode() == 204; } + private void addHeaderParams(final Request request) { if (ifMatch != null) { request.addHeaderParam("If-Match", ifMatch); - } } } diff --git a/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListItemFetcher.java b/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListItemFetcher.java index 3ad0307c43..80c1c19d6c 100644 --- a/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListItemFetcher.java +++ b/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListItemFetcher.java @@ -24,28 +24,34 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class SyncListItemFetcher extends Fetcher { + private String pathServiceSid; private String pathListSid; private Integer pathIndex; - public SyncListItemFetcher(final String pathServiceSid, final String pathListSid, final Integer pathIndex){ + public SyncListItemFetcher( + final String pathServiceSid, + final String pathListSid, + final Integer pathIndex + ) { this.pathServiceSid = pathServiceSid; this.pathListSid = pathListSid; this.pathIndex = pathIndex; } - @Override public SyncListItem fetch(final TwilioRestClient client) { - String path = "/Sync/Services/{ServiceSid}/Lists/{ListSid}/Items/{Index}"; + String path = + "/Sync/Services/{ServiceSid}/Lists/{ListSid}/Items/{Index}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ListSid"+"}", this.pathListSid.toString()); - path = path.replace("{"+"Index"+"}", this.pathIndex.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "ListSid" + "}", this.pathListSid.toString()); + path = path.replace("{" + "Index" + "}", this.pathIndex.toString()); Request request = new Request( HttpMethod.GET, @@ -55,15 +61,23 @@ public SyncListItem fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncListItem fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "SyncListItem fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return SyncListItem.fromJson(response.getStream(), client.getObjectMapper()); + return SyncListItem.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListItemReader.java b/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListItemReader.java index 9ec6a9084d..72827c9192 100644 --- a/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListItemReader.java +++ b/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListItemReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.preview.sync.service.synclist; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,11 +25,9 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class SyncListItemReader extends Reader { + private String pathServiceSid; private String pathListSid; private SyncListItem.QueryResultOrder order; @@ -36,24 +35,34 @@ public class SyncListItemReader extends Reader { private SyncListItem.QueryFromBoundType bounds; private Integer pageSize; - public SyncListItemReader(final String pathServiceSid, final String pathListSid){ + public SyncListItemReader( + final String pathServiceSid, + final String pathListSid + ) { this.pathServiceSid = pathServiceSid; this.pathListSid = pathListSid; } - public SyncListItemReader setOrder(final SyncListItem.QueryResultOrder order){ + public SyncListItemReader setOrder( + final SyncListItem.QueryResultOrder order + ) { this.order = order; return this; } - public SyncListItemReader setFrom(final String from){ + + public SyncListItemReader setFrom(final String from) { this.from = from; return this; } - public SyncListItemReader setBounds(final SyncListItem.QueryFromBoundType bounds){ + + public SyncListItemReader setBounds( + final SyncListItem.QueryFromBoundType bounds + ) { this.bounds = bounds; return this; } - public SyncListItemReader setPageSize(final Integer pageSize){ + + public SyncListItemReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -65,8 +74,12 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/Sync/Services/{ServiceSid}/Lists/{ListSid}/Items"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ListSid"+"}", this.pathListSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "ListSid" + "}", this.pathListSid.toString()); Request request = new Request( HttpMethod.GET, @@ -78,13 +91,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncListItem read failed: Unable to connect to server"); + throw new ApiConnectionException( + "SyncListItem read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -100,7 +121,10 @@ private Page pageForRequest(final TwilioRestClient client, final R } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.PREVIEW.toString()) @@ -108,9 +132,11 @@ public Page previousPage(final Page page, final Twil return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.PREVIEW.toString()) @@ -119,33 +145,30 @@ public Page nextPage(final Page page, final TwilioRe } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (order != null) { - request.addQueryParam("Order", order.toString()); } if (from != null) { - request.addQueryParam("From", from); } if (bounds != null) { - request.addQueryParam("Bounds", bounds.toString()); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListItemUpdater.java b/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListItemUpdater.java index 79c3963bc5..50cc908f6f 100644 --- a/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListItemUpdater.java +++ b/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListItemUpdater.java @@ -15,8 +15,9 @@ package com.twilio.rest.preview.sync.service.synclist; import com.twilio.base.Updater; -import com.twilio.exception.ApiConnectionException; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Converter; +import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; @@ -24,73 +25,91 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - import java.util.Map; +public class SyncListItemUpdater extends Updater { -public class SyncListItemUpdater extends Updater{ private String pathServiceSid; private String pathListSid; private Integer pathIndex; private Map data; private String ifMatch; - public SyncListItemUpdater(final String pathServiceSid, final String pathListSid, final Integer pathIndex, final Map data){ + public SyncListItemUpdater( + final String pathServiceSid, + final String pathListSid, + final Integer pathIndex, + final Map data + ) { this.pathServiceSid = pathServiceSid; this.pathListSid = pathListSid; this.pathIndex = pathIndex; this.data = data; } - public SyncListItemUpdater setData(final Map data){ + public SyncListItemUpdater setData(final Map data) { this.data = data; return this; } - public SyncListItemUpdater setIfMatch(final String ifMatch){ + + public SyncListItemUpdater setIfMatch(final String ifMatch) { this.ifMatch = ifMatch; return this; } @Override - public SyncListItem update(final TwilioRestClient client){ - String path = "/Sync/Services/{ServiceSid}/Lists/{ListSid}/Items/{Index}"; + public SyncListItem update(final TwilioRestClient client) { + String path = + "/Sync/Services/{ServiceSid}/Lists/{ListSid}/Items/{Index}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ListSid"+"}", this.pathListSid.toString()); - path = path.replace("{"+"Index"+"}", this.pathIndex.toString()); - path = path.replace("{"+"Data"+"}", this.data.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "ListSid" + "}", this.pathListSid.toString()); + path = path.replace("{" + "Index" + "}", this.pathIndex.toString()); + path = path.replace("{" + "Data" + "}", this.data.toString()); Request request = new Request( HttpMethod.POST, Domains.PREVIEW.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); addHeaderParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncListItem update failed: Unable to connect to server"); + throw new ApiConnectionException( + "SyncListItem update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return SyncListItem.fromJson(response.getStream(), client.getObjectMapper()); + return SyncListItem.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (data != null) { - request.addPostParam("Data", Converter.mapToJson(data)); - + request.addPostParam("Data", Converter.mapToJson(data)); } } + private void addHeaderParams(final Request request) { if (ifMatch != null) { request.addHeaderParam("If-Match", ifMatch); - } } } diff --git a/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListPermission.java b/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListPermission.java index 0298edef06..7aba8fabda 100644 --- a/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListPermission.java +++ b/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListPermission.java @@ -22,48 +22,80 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class SyncListPermission extends Resource { + private static final long serialVersionUID = 225550881347017L; - public static SyncListPermissionDeleter deleter(final String pathServiceSid, final String pathListSid, final String pathIdentity){ - return new SyncListPermissionDeleter(pathServiceSid, pathListSid, pathIdentity); + public static SyncListPermissionDeleter deleter( + final String pathServiceSid, + final String pathListSid, + final String pathIdentity + ) { + return new SyncListPermissionDeleter( + pathServiceSid, + pathListSid, + pathIdentity + ); } - public static SyncListPermissionFetcher fetcher(final String pathServiceSid, final String pathListSid, final String pathIdentity){ - return new SyncListPermissionFetcher(pathServiceSid, pathListSid, pathIdentity); + public static SyncListPermissionFetcher fetcher( + final String pathServiceSid, + final String pathListSid, + final String pathIdentity + ) { + return new SyncListPermissionFetcher( + pathServiceSid, + pathListSid, + pathIdentity + ); } - public static SyncListPermissionReader reader(final String pathServiceSid, final String pathListSid){ + public static SyncListPermissionReader reader( + final String pathServiceSid, + final String pathListSid + ) { return new SyncListPermissionReader(pathServiceSid, pathListSid); } - public static SyncListPermissionUpdater updater(final String pathServiceSid, final String pathListSid, final String pathIdentity, final Boolean read, final Boolean write, final Boolean manage){ - return new SyncListPermissionUpdater(pathServiceSid, pathListSid, pathIdentity, read, write, manage); + public static SyncListPermissionUpdater updater( + final String pathServiceSid, + final String pathListSid, + final String pathIdentity, + final Boolean read, + final Boolean write, + final Boolean manage + ) { + return new SyncListPermissionUpdater( + pathServiceSid, + pathListSid, + pathIdentity, + read, + write, + manage + ); } /** - * Converts a JSON String into a SyncListPermission object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return SyncListPermission object represented by the provided JSON - */ - public static SyncListPermission fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a SyncListPermission object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return SyncListPermission object represented by the provided JSON + */ + public static SyncListPermission fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SyncListPermission.class); @@ -75,14 +107,17 @@ public static SyncListPermission fromJson(final String json, final ObjectMapper } /** - * Converts a JSON InputStream into a SyncListPermission object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return SyncListPermission object represented by the provided JSON - */ - public static SyncListPermission fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a SyncListPermission object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return SyncListPermission object represented by the provided JSON + */ + public static SyncListPermission fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SyncListPermission.class); @@ -104,29 +139,14 @@ public static SyncListPermission fromJson(final InputStream json, final ObjectMa @JsonCreator private SyncListPermission( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("list_sid") - final String listSid, - - @JsonProperty("identity") - final String identity, - - @JsonProperty("read") - final Boolean read, - - @JsonProperty("write") - final Boolean write, - - @JsonProperty("manage") - final Boolean manage, - - @JsonProperty("url") - final URI url + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("list_sid") final String listSid, + @JsonProperty("identity") final String identity, + @JsonProperty("read") final Boolean read, + @JsonProperty("write") final Boolean write, + @JsonProperty("manage") final Boolean manage, + @JsonProperty("url") final URI url ) { this.accountSid = accountSid; this.serviceSid = serviceSid; @@ -138,34 +158,41 @@ private SyncListPermission( this.url = url; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final String getListSid() { - return this.listSid; - } - public final String getIdentity() { - return this.identity; - } - public final Boolean getRead() { - return this.read; - } - public final Boolean getWrite() { - return this.write; - } - public final Boolean getManage() { - return this.manage; - } - public final URI getUrl() { - return this.url; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final String getListSid() { + return this.listSid; + } + + public final String getIdentity() { + return this.identity; + } + + public final Boolean getRead() { + return this.read; + } + + public final Boolean getWrite() { + return this.write; + } + + public final Boolean getManage() { + return this.manage; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -175,13 +202,29 @@ public boolean equals(final Object o) { SyncListPermission other = (SyncListPermission) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(listSid, other.listSid) && Objects.equals(identity, other.identity) && Objects.equals(read, other.read) && Objects.equals(write, other.write) && Objects.equals(manage, other.manage) && Objects.equals(url, other.url) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(listSid, other.listSid) && + Objects.equals(identity, other.identity) && + Objects.equals(read, other.read) && + Objects.equals(write, other.write) && + Objects.equals(manage, other.manage) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, serviceSid, listSid, identity, read, write, manage, url); + return Objects.hash( + accountSid, + serviceSid, + listSid, + identity, + read, + write, + manage, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListPermissionDeleter.java b/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListPermissionDeleter.java index 15284fc09a..7ac4c4182f 100644 --- a/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListPermissionDeleter.java +++ b/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListPermissionDeleter.java @@ -24,27 +24,35 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class SyncListPermissionDeleter extends Deleter { + private String pathServiceSid; private String pathListSid; private String pathIdentity; - public SyncListPermissionDeleter(final String pathServiceSid, final String pathListSid, final String pathIdentity){ + public SyncListPermissionDeleter( + final String pathServiceSid, + final String pathListSid, + final String pathIdentity + ) { this.pathServiceSid = pathServiceSid; this.pathListSid = pathListSid; this.pathIdentity = pathIdentity; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/Sync/Services/{ServiceSid}/Lists/{ListSid}/Permissions/{Identity}"; + String path = + "/Sync/Services/{ServiceSid}/Lists/{ListSid}/Permissions/{Identity}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ListSid"+"}", this.pathListSid.toString()); - path = path.replace("{"+"Identity"+"}", this.pathIdentity.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "ListSid" + "}", this.pathListSid.toString()); + path = + path.replace("{" + "Identity" + "}", this.pathIdentity.toString()); Request request = new Request( HttpMethod.DELETE, @@ -54,9 +62,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncListPermission delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "SyncListPermission delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListPermissionFetcher.java b/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListPermissionFetcher.java index 5a772b7af0..be02a80aa6 100644 --- a/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListPermissionFetcher.java +++ b/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListPermissionFetcher.java @@ -24,28 +24,35 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class SyncListPermissionFetcher extends Fetcher { + private String pathServiceSid; private String pathListSid; private String pathIdentity; - public SyncListPermissionFetcher(final String pathServiceSid, final String pathListSid, final String pathIdentity){ + public SyncListPermissionFetcher( + final String pathServiceSid, + final String pathListSid, + final String pathIdentity + ) { this.pathServiceSid = pathServiceSid; this.pathListSid = pathListSid; this.pathIdentity = pathIdentity; } - @Override public SyncListPermission fetch(final TwilioRestClient client) { - String path = "/Sync/Services/{ServiceSid}/Lists/{ListSid}/Permissions/{Identity}"; + String path = + "/Sync/Services/{ServiceSid}/Lists/{ListSid}/Permissions/{Identity}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ListSid"+"}", this.pathListSid.toString()); - path = path.replace("{"+"Identity"+"}", this.pathIdentity.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "ListSid" + "}", this.pathListSid.toString()); + path = + path.replace("{" + "Identity" + "}", this.pathIdentity.toString()); Request request = new Request( HttpMethod.GET, @@ -55,15 +62,23 @@ public SyncListPermission fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncListPermission fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "SyncListPermission fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return SyncListPermission.fromJson(response.getStream(), client.getObjectMapper()); + return SyncListPermission.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListPermissionReader.java b/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListPermissionReader.java index 6e3843e80b..a86a3e8ccb 100644 --- a/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListPermissionReader.java +++ b/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListPermissionReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.preview.sync.service.synclist; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,21 +25,22 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class SyncListPermissionReader extends Reader { + private String pathServiceSid; private String pathListSid; private Integer pageSize; - public SyncListPermissionReader(final String pathServiceSid, final String pathListSid){ + public SyncListPermissionReader( + final String pathServiceSid, + final String pathListSid + ) { this.pathServiceSid = pathServiceSid; this.pathListSid = pathListSid; } - public SyncListPermissionReader setPageSize(final Integer pageSize){ + public SyncListPermissionReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -50,8 +52,12 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/Sync/Services/{ServiceSid}/Lists/{ListSid}/Permissions"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ListSid"+"}", this.pathListSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "ListSid" + "}", this.pathListSid.toString()); Request request = new Request( HttpMethod.GET, @@ -63,13 +69,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncListPermission read failed: Unable to connect to server"); + throw new ApiConnectionException( + "SyncListPermission read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -85,7 +99,10 @@ private Page pageForRequest(final TwilioRestClient client, f } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.PREVIEW.toString()) @@ -93,9 +110,11 @@ public Page previousPage(final Page page return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.PREVIEW.toString()) @@ -104,21 +123,21 @@ public Page nextPage(final Page page, fi } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListPermissionUpdater.java b/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListPermissionUpdater.java index c52c8f83d4..9bf6b9a68b 100644 --- a/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListPermissionUpdater.java +++ b/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListPermissionUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.preview.sync.service.synclist; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class SyncListPermissionUpdater extends Updater { - - -public class SyncListPermissionUpdater extends Updater{ private String pathServiceSid; private String pathListSid; private String pathIdentity; @@ -35,7 +34,14 @@ public class SyncListPermissionUpdater extends Updater{ private Boolean write; private Boolean manage; - public SyncListPermissionUpdater(final String pathServiceSid, final String pathListSid, final String pathIdentity, final Boolean read, final Boolean write, final Boolean manage){ + public SyncListPermissionUpdater( + final String pathServiceSid, + final String pathListSid, + final String pathIdentity, + final Boolean read, + final Boolean write, + final Boolean manage + ) { this.pathServiceSid = pathServiceSid; this.pathListSid = pathListSid; this.pathIdentity = pathIdentity; @@ -44,61 +50,76 @@ public SyncListPermissionUpdater(final String pathServiceSid, final String pathL this.manage = manage; } - public SyncListPermissionUpdater setRead(final Boolean read){ + public SyncListPermissionUpdater setRead(final Boolean read) { this.read = read; return this; } - public SyncListPermissionUpdater setWrite(final Boolean write){ + + public SyncListPermissionUpdater setWrite(final Boolean write) { this.write = write; return this; } - public SyncListPermissionUpdater setManage(final Boolean manage){ + + public SyncListPermissionUpdater setManage(final Boolean manage) { this.manage = manage; return this; } @Override - public SyncListPermission update(final TwilioRestClient client){ - String path = "/Sync/Services/{ServiceSid}/Lists/{ListSid}/Permissions/{Identity}"; + public SyncListPermission update(final TwilioRestClient client) { + String path = + "/Sync/Services/{ServiceSid}/Lists/{ListSid}/Permissions/{Identity}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ListSid"+"}", this.pathListSid.toString()); - path = path.replace("{"+"Identity"+"}", this.pathIdentity.toString()); - path = path.replace("{"+"Read"+"}", this.read.toString()); - path = path.replace("{"+"Write"+"}", this.write.toString()); - path = path.replace("{"+"Manage"+"}", this.manage.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "ListSid" + "}", this.pathListSid.toString()); + path = + path.replace("{" + "Identity" + "}", this.pathIdentity.toString()); + path = path.replace("{" + "Read" + "}", this.read.toString()); + path = path.replace("{" + "Write" + "}", this.write.toString()); + path = path.replace("{" + "Manage" + "}", this.manage.toString()); Request request = new Request( HttpMethod.POST, Domains.PREVIEW.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncListPermission update failed: Unable to connect to server"); + throw new ApiConnectionException( + "SyncListPermission update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return SyncListPermission.fromJson(response.getStream(), client.getObjectMapper()); + return SyncListPermission.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (read != null) { request.addPostParam("Read", read.toString()); - } if (write != null) { request.addPostParam("Write", write.toString()); - } if (manage != null) { request.addPostParam("Manage", manage.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapItem.java b/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapItem.java index 015f07afbc..8d27d40590 100644 --- a/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapItem.java +++ b/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapItem.java @@ -24,55 +24,80 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class SyncMapItem extends Resource { + private static final long serialVersionUID = 40990956939472L; - public static SyncMapItemCreator creator(final String pathServiceSid, final String pathMapSid, final String key, final Map data){ + public static SyncMapItemCreator creator( + final String pathServiceSid, + final String pathMapSid, + final String key, + final Map data + ) { return new SyncMapItemCreator(pathServiceSid, pathMapSid, key, data); } - public static SyncMapItemDeleter deleter(final String pathServiceSid, final String pathMapSid, final String pathKey){ + public static SyncMapItemDeleter deleter( + final String pathServiceSid, + final String pathMapSid, + final String pathKey + ) { return new SyncMapItemDeleter(pathServiceSid, pathMapSid, pathKey); } - public static SyncMapItemFetcher fetcher(final String pathServiceSid, final String pathMapSid, final String pathKey){ + public static SyncMapItemFetcher fetcher( + final String pathServiceSid, + final String pathMapSid, + final String pathKey + ) { return new SyncMapItemFetcher(pathServiceSid, pathMapSid, pathKey); } - public static SyncMapItemReader reader(final String pathServiceSid, final String pathMapSid){ + public static SyncMapItemReader reader( + final String pathServiceSid, + final String pathMapSid + ) { return new SyncMapItemReader(pathServiceSid, pathMapSid); } - public static SyncMapItemUpdater updater(final String pathServiceSid, final String pathMapSid, final String pathKey, final Map data){ - return new SyncMapItemUpdater(pathServiceSid, pathMapSid, pathKey, data); + public static SyncMapItemUpdater updater( + final String pathServiceSid, + final String pathMapSid, + final String pathKey, + final Map data + ) { + return new SyncMapItemUpdater( + pathServiceSid, + pathMapSid, + pathKey, + data + ); } /** - * Converts a JSON String into a SyncMapItem object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return SyncMapItem object represented by the provided JSON - */ - public static SyncMapItem fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a SyncMapItem object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return SyncMapItem object represented by the provided JSON + */ + public static SyncMapItem fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SyncMapItem.class); @@ -84,14 +109,17 @@ public static SyncMapItem fromJson(final String json, final ObjectMapper objectM } /** - * Converts a JSON InputStream into a SyncMapItem object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return SyncMapItem object represented by the provided JSON - */ - public static SyncMapItem fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a SyncMapItem object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return SyncMapItem object represented by the provided JSON + */ + public static SyncMapItem fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SyncMapItem.class); @@ -101,6 +129,7 @@ public static SyncMapItem fromJson(final InputStream json, final ObjectMapper ob throw new ApiConnectionException(e.getMessage(), e); } } + public enum QueryFromBoundType { INCLUSIVE("inclusive"), EXCLUSIVE("exclusive"); @@ -120,6 +149,7 @@ public static QueryFromBoundType forValue(final String value) { return Promoter.enumFromString(value, QueryFromBoundType.values()); } } + public enum QueryResultOrder { ASC("asc"), DESC("desc"); @@ -153,35 +183,16 @@ public static QueryResultOrder forValue(final String value) { @JsonCreator private SyncMapItem( - @JsonProperty("key") - final String key, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("map_sid") - final String mapSid, - - @JsonProperty("url") - final URI url, - - @JsonProperty("revision") - final String revision, - - @JsonProperty("data") - final Map data, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("created_by") - final String createdBy + @JsonProperty("key") final String key, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("map_sid") final String mapSid, + @JsonProperty("url") final URI url, + @JsonProperty("revision") final String revision, + @JsonProperty("data") final Map data, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("created_by") final String createdBy ) { this.key = key; this.accountSid = accountSid; @@ -195,40 +206,49 @@ private SyncMapItem( this.createdBy = createdBy; } - public final String getKey() { - return this.key; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final String getMapSid() { - return this.mapSid; - } - public final URI getUrl() { - return this.url; - } - public final String getRevision() { - return this.revision; - } - public final Map getData() { - return this.data; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getCreatedBy() { - return this.createdBy; - } + public final String getKey() { + return this.key; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final String getMapSid() { + return this.mapSid; + } + + public final URI getUrl() { + return this.url; + } + + public final String getRevision() { + return this.revision; + } + + public final Map getData() { + return this.data; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getCreatedBy() { + return this.createdBy; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -238,13 +258,33 @@ public boolean equals(final Object o) { SyncMapItem other = (SyncMapItem) o; - return Objects.equals(key, other.key) && Objects.equals(accountSid, other.accountSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(mapSid, other.mapSid) && Objects.equals(url, other.url) && Objects.equals(revision, other.revision) && Objects.equals(data, other.data) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(createdBy, other.createdBy) ; + return ( + Objects.equals(key, other.key) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(mapSid, other.mapSid) && + Objects.equals(url, other.url) && + Objects.equals(revision, other.revision) && + Objects.equals(data, other.data) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(createdBy, other.createdBy) + ); } @Override public int hashCode() { - return Objects.hash(key, accountSid, serviceSid, mapSid, url, revision, data, dateCreated, dateUpdated, createdBy); + return Objects.hash( + key, + accountSid, + serviceSid, + mapSid, + url, + revision, + data, + dateCreated, + dateUpdated, + createdBy + ); } - } - diff --git a/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapItemCreator.java b/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapItemCreator.java index 741dbb0062..c79a1f73c4 100644 --- a/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapItemCreator.java +++ b/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapItemCreator.java @@ -15,8 +15,10 @@ package com.twilio.rest.preview.sync.service.syncmap; import com.twilio.base.Creator; -import com.twilio.exception.ApiConnectionException; +import com.twilio.constant.EnumConstants; +import com.twilio.converter.Converter; import com.twilio.converter.Converter; +import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; @@ -25,70 +27,85 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.util.Map; -import com.twilio.converter.Converter; - import java.util.Map; +public class SyncMapItemCreator extends Creator { - -public class SyncMapItemCreator extends Creator{ private String pathServiceSid; private String pathMapSid; private String key; private Map data; - public SyncMapItemCreator(final String pathServiceSid, final String pathMapSid, final String key, final Map data) { + public SyncMapItemCreator( + final String pathServiceSid, + final String pathMapSid, + final String key, + final Map data + ) { this.pathServiceSid = pathServiceSid; this.pathMapSid = pathMapSid; this.key = key; this.data = data; } - public SyncMapItemCreator setKey(final String key){ + public SyncMapItemCreator setKey(final String key) { this.key = key; return this; } - public SyncMapItemCreator setData(final Map data){ + + public SyncMapItemCreator setData(final Map data) { this.data = data; return this; } @Override - public SyncMapItem create(final TwilioRestClient client){ + public SyncMapItem create(final TwilioRestClient client) { String path = "/Sync/Services/{ServiceSid}/Maps/{MapSid}/Items"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"MapSid"+"}", this.pathMapSid.toString()); - path = path.replace("{"+"Key"+"}", this.key.toString()); - path = path.replace("{"+"Data"+"}", this.data.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "MapSid" + "}", this.pathMapSid.toString()); + path = path.replace("{" + "Key" + "}", this.key.toString()); + path = path.replace("{" + "Data" + "}", this.data.toString()); Request request = new Request( HttpMethod.POST, Domains.PREVIEW.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncMapItem creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "SyncMapItem creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return SyncMapItem.fromJson(response.getStream(), client.getObjectMapper()); + return SyncMapItem.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (key != null) { request.addPostParam("Key", key); - } if (data != null) { - request.addPostParam("Data", Converter.mapToJson(data)); - + request.addPostParam("Data", Converter.mapToJson(data)); } } } diff --git a/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapItemDeleter.java b/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapItemDeleter.java index 9d5c473597..280025c11f 100644 --- a/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapItemDeleter.java +++ b/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapItemDeleter.java @@ -24,21 +24,24 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class SyncMapItemDeleter extends Deleter { + private String pathServiceSid; private String pathMapSid; private String pathKey; private String ifMatch; - public SyncMapItemDeleter(final String pathServiceSid, final String pathMapSid, final String pathKey){ + public SyncMapItemDeleter( + final String pathServiceSid, + final String pathMapSid, + final String pathKey + ) { this.pathServiceSid = pathServiceSid; this.pathMapSid = pathMapSid; this.pathKey = pathKey; } - public SyncMapItemDeleter setIfMatch(final String ifMatch){ + public SyncMapItemDeleter setIfMatch(final String ifMatch) { this.ifMatch = ifMatch; return this; } @@ -47,9 +50,13 @@ public SyncMapItemDeleter setIfMatch(final String ifMatch){ public boolean delete(final TwilioRestClient client) { String path = "/Sync/Services/{ServiceSid}/Maps/{MapSid}/Items/{Key}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"MapSid"+"}", this.pathMapSid.toString()); - path = path.replace("{"+"Key"+"}", this.pathKey.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "MapSid" + "}", this.pathMapSid.toString()); + path = path.replace("{" + "Key" + "}", this.pathKey.toString()); Request request = new Request( HttpMethod.DELETE, @@ -60,9 +67,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncMapItem delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "SyncMapItem delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -70,10 +82,10 @@ public boolean delete(final TwilioRestClient client) { } return response.getStatusCode() == 204; } + private void addHeaderParams(final Request request) { if (ifMatch != null) { request.addHeaderParam("If-Match", ifMatch); - } } } diff --git a/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapItemFetcher.java b/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapItemFetcher.java index aa45c6cd2f..8657422ba8 100644 --- a/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapItemFetcher.java +++ b/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapItemFetcher.java @@ -24,28 +24,33 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class SyncMapItemFetcher extends Fetcher { + private String pathServiceSid; private String pathMapSid; private String pathKey; - public SyncMapItemFetcher(final String pathServiceSid, final String pathMapSid, final String pathKey){ + public SyncMapItemFetcher( + final String pathServiceSid, + final String pathMapSid, + final String pathKey + ) { this.pathServiceSid = pathServiceSid; this.pathMapSid = pathMapSid; this.pathKey = pathKey; } - @Override public SyncMapItem fetch(final TwilioRestClient client) { String path = "/Sync/Services/{ServiceSid}/Maps/{MapSid}/Items/{Key}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"MapSid"+"}", this.pathMapSid.toString()); - path = path.replace("{"+"Key"+"}", this.pathKey.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "MapSid" + "}", this.pathMapSid.toString()); + path = path.replace("{" + "Key" + "}", this.pathKey.toString()); Request request = new Request( HttpMethod.GET, @@ -55,15 +60,23 @@ public SyncMapItem fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncMapItem fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "SyncMapItem fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return SyncMapItem.fromJson(response.getStream(), client.getObjectMapper()); + return SyncMapItem.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapItemReader.java b/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapItemReader.java index b85cdb1cf6..29c9d6b565 100644 --- a/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapItemReader.java +++ b/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapItemReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.preview.sync.service.syncmap; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,11 +25,9 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class SyncMapItemReader extends Reader { + private String pathServiceSid; private String pathMapSid; private SyncMapItem.QueryResultOrder order; @@ -36,24 +35,34 @@ public class SyncMapItemReader extends Reader { private SyncMapItem.QueryFromBoundType bounds; private Integer pageSize; - public SyncMapItemReader(final String pathServiceSid, final String pathMapSid){ + public SyncMapItemReader( + final String pathServiceSid, + final String pathMapSid + ) { this.pathServiceSid = pathServiceSid; this.pathMapSid = pathMapSid; } - public SyncMapItemReader setOrder(final SyncMapItem.QueryResultOrder order){ + public SyncMapItemReader setOrder( + final SyncMapItem.QueryResultOrder order + ) { this.order = order; return this; } - public SyncMapItemReader setFrom(final String from){ + + public SyncMapItemReader setFrom(final String from) { this.from = from; return this; } - public SyncMapItemReader setBounds(final SyncMapItem.QueryFromBoundType bounds){ + + public SyncMapItemReader setBounds( + final SyncMapItem.QueryFromBoundType bounds + ) { this.bounds = bounds; return this; } - public SyncMapItemReader setPageSize(final Integer pageSize){ + + public SyncMapItemReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -65,8 +74,12 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/Sync/Services/{ServiceSid}/Maps/{MapSid}/Items"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"MapSid"+"}", this.pathMapSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "MapSid" + "}", this.pathMapSid.toString()); Request request = new Request( HttpMethod.GET, @@ -78,13 +91,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncMapItem read failed: Unable to connect to server"); + throw new ApiConnectionException( + "SyncMapItem read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -100,7 +121,10 @@ private Page pageForRequest(final TwilioRestClient client, final Re } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.PREVIEW.toString()) @@ -108,9 +132,11 @@ public Page previousPage(final Page page, final Twilio return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.PREVIEW.toString()) @@ -119,33 +145,30 @@ public Page nextPage(final Page page, final TwilioRest } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (order != null) { - request.addQueryParam("Order", order.toString()); } if (from != null) { - request.addQueryParam("From", from); } if (bounds != null) { - request.addQueryParam("Bounds", bounds.toString()); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapItemUpdater.java b/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapItemUpdater.java index 4e7b0d0433..c331a3def4 100644 --- a/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapItemUpdater.java +++ b/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapItemUpdater.java @@ -15,8 +15,9 @@ package com.twilio.rest.preview.sync.service.syncmap; import com.twilio.base.Updater; -import com.twilio.exception.ApiConnectionException; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Converter; +import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; @@ -24,73 +25,90 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - import java.util.Map; +public class SyncMapItemUpdater extends Updater { -public class SyncMapItemUpdater extends Updater{ private String pathServiceSid; private String pathMapSid; private String pathKey; private Map data; private String ifMatch; - public SyncMapItemUpdater(final String pathServiceSid, final String pathMapSid, final String pathKey, final Map data){ + public SyncMapItemUpdater( + final String pathServiceSid, + final String pathMapSid, + final String pathKey, + final Map data + ) { this.pathServiceSid = pathServiceSid; this.pathMapSid = pathMapSid; this.pathKey = pathKey; this.data = data; } - public SyncMapItemUpdater setData(final Map data){ + public SyncMapItemUpdater setData(final Map data) { this.data = data; return this; } - public SyncMapItemUpdater setIfMatch(final String ifMatch){ + + public SyncMapItemUpdater setIfMatch(final String ifMatch) { this.ifMatch = ifMatch; return this; } @Override - public SyncMapItem update(final TwilioRestClient client){ + public SyncMapItem update(final TwilioRestClient client) { String path = "/Sync/Services/{ServiceSid}/Maps/{MapSid}/Items/{Key}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"MapSid"+"}", this.pathMapSid.toString()); - path = path.replace("{"+"Key"+"}", this.pathKey.toString()); - path = path.replace("{"+"Data"+"}", this.data.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "MapSid" + "}", this.pathMapSid.toString()); + path = path.replace("{" + "Key" + "}", this.pathKey.toString()); + path = path.replace("{" + "Data" + "}", this.data.toString()); Request request = new Request( HttpMethod.POST, Domains.PREVIEW.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); addHeaderParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncMapItem update failed: Unable to connect to server"); + throw new ApiConnectionException( + "SyncMapItem update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return SyncMapItem.fromJson(response.getStream(), client.getObjectMapper()); + return SyncMapItem.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (data != null) { - request.addPostParam("Data", Converter.mapToJson(data)); - + request.addPostParam("Data", Converter.mapToJson(data)); } } + private void addHeaderParams(final Request request) { if (ifMatch != null) { request.addHeaderParam("If-Match", ifMatch); - } } } diff --git a/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapPermission.java b/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapPermission.java index 321b9e210d..bbe717a0ee 100644 --- a/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapPermission.java +++ b/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapPermission.java @@ -22,48 +22,80 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class SyncMapPermission extends Resource { + private static final long serialVersionUID = 55149075645678L; - public static SyncMapPermissionDeleter deleter(final String pathServiceSid, final String pathMapSid, final String pathIdentity){ - return new SyncMapPermissionDeleter(pathServiceSid, pathMapSid, pathIdentity); + public static SyncMapPermissionDeleter deleter( + final String pathServiceSid, + final String pathMapSid, + final String pathIdentity + ) { + return new SyncMapPermissionDeleter( + pathServiceSid, + pathMapSid, + pathIdentity + ); } - public static SyncMapPermissionFetcher fetcher(final String pathServiceSid, final String pathMapSid, final String pathIdentity){ - return new SyncMapPermissionFetcher(pathServiceSid, pathMapSid, pathIdentity); + public static SyncMapPermissionFetcher fetcher( + final String pathServiceSid, + final String pathMapSid, + final String pathIdentity + ) { + return new SyncMapPermissionFetcher( + pathServiceSid, + pathMapSid, + pathIdentity + ); } - public static SyncMapPermissionReader reader(final String pathServiceSid, final String pathMapSid){ + public static SyncMapPermissionReader reader( + final String pathServiceSid, + final String pathMapSid + ) { return new SyncMapPermissionReader(pathServiceSid, pathMapSid); } - public static SyncMapPermissionUpdater updater(final String pathServiceSid, final String pathMapSid, final String pathIdentity, final Boolean read, final Boolean write, final Boolean manage){ - return new SyncMapPermissionUpdater(pathServiceSid, pathMapSid, pathIdentity, read, write, manage); + public static SyncMapPermissionUpdater updater( + final String pathServiceSid, + final String pathMapSid, + final String pathIdentity, + final Boolean read, + final Boolean write, + final Boolean manage + ) { + return new SyncMapPermissionUpdater( + pathServiceSid, + pathMapSid, + pathIdentity, + read, + write, + manage + ); } /** - * Converts a JSON String into a SyncMapPermission object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return SyncMapPermission object represented by the provided JSON - */ - public static SyncMapPermission fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a SyncMapPermission object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return SyncMapPermission object represented by the provided JSON + */ + public static SyncMapPermission fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SyncMapPermission.class); @@ -75,14 +107,17 @@ public static SyncMapPermission fromJson(final String json, final ObjectMapper o } /** - * Converts a JSON InputStream into a SyncMapPermission object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return SyncMapPermission object represented by the provided JSON - */ - public static SyncMapPermission fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a SyncMapPermission object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return SyncMapPermission object represented by the provided JSON + */ + public static SyncMapPermission fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SyncMapPermission.class); @@ -104,29 +139,14 @@ public static SyncMapPermission fromJson(final InputStream json, final ObjectMap @JsonCreator private SyncMapPermission( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("map_sid") - final String mapSid, - - @JsonProperty("identity") - final String identity, - - @JsonProperty("read") - final Boolean read, - - @JsonProperty("write") - final Boolean write, - - @JsonProperty("manage") - final Boolean manage, - - @JsonProperty("url") - final URI url + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("map_sid") final String mapSid, + @JsonProperty("identity") final String identity, + @JsonProperty("read") final Boolean read, + @JsonProperty("write") final Boolean write, + @JsonProperty("manage") final Boolean manage, + @JsonProperty("url") final URI url ) { this.accountSid = accountSid; this.serviceSid = serviceSid; @@ -138,34 +158,41 @@ private SyncMapPermission( this.url = url; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final String getMapSid() { - return this.mapSid; - } - public final String getIdentity() { - return this.identity; - } - public final Boolean getRead() { - return this.read; - } - public final Boolean getWrite() { - return this.write; - } - public final Boolean getManage() { - return this.manage; - } - public final URI getUrl() { - return this.url; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final String getMapSid() { + return this.mapSid; + } + + public final String getIdentity() { + return this.identity; + } + + public final Boolean getRead() { + return this.read; + } + + public final Boolean getWrite() { + return this.write; + } + + public final Boolean getManage() { + return this.manage; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -175,13 +202,29 @@ public boolean equals(final Object o) { SyncMapPermission other = (SyncMapPermission) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(mapSid, other.mapSid) && Objects.equals(identity, other.identity) && Objects.equals(read, other.read) && Objects.equals(write, other.write) && Objects.equals(manage, other.manage) && Objects.equals(url, other.url) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(mapSid, other.mapSid) && + Objects.equals(identity, other.identity) && + Objects.equals(read, other.read) && + Objects.equals(write, other.write) && + Objects.equals(manage, other.manage) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, serviceSid, mapSid, identity, read, write, manage, url); + return Objects.hash( + accountSid, + serviceSid, + mapSid, + identity, + read, + write, + manage, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapPermissionDeleter.java b/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapPermissionDeleter.java index 5eac720816..d2a33ce387 100644 --- a/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapPermissionDeleter.java +++ b/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapPermissionDeleter.java @@ -24,27 +24,35 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class SyncMapPermissionDeleter extends Deleter { + private String pathServiceSid; private String pathMapSid; private String pathIdentity; - public SyncMapPermissionDeleter(final String pathServiceSid, final String pathMapSid, final String pathIdentity){ + public SyncMapPermissionDeleter( + final String pathServiceSid, + final String pathMapSid, + final String pathIdentity + ) { this.pathServiceSid = pathServiceSid; this.pathMapSid = pathMapSid; this.pathIdentity = pathIdentity; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/Sync/Services/{ServiceSid}/Maps/{MapSid}/Permissions/{Identity}"; + String path = + "/Sync/Services/{ServiceSid}/Maps/{MapSid}/Permissions/{Identity}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"MapSid"+"}", this.pathMapSid.toString()); - path = path.replace("{"+"Identity"+"}", this.pathIdentity.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "MapSid" + "}", this.pathMapSid.toString()); + path = + path.replace("{" + "Identity" + "}", this.pathIdentity.toString()); Request request = new Request( HttpMethod.DELETE, @@ -54,9 +62,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncMapPermission delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "SyncMapPermission delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapPermissionFetcher.java b/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapPermissionFetcher.java index b4c0c31585..e5612263e3 100644 --- a/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapPermissionFetcher.java +++ b/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapPermissionFetcher.java @@ -24,28 +24,35 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class SyncMapPermissionFetcher extends Fetcher { + private String pathServiceSid; private String pathMapSid; private String pathIdentity; - public SyncMapPermissionFetcher(final String pathServiceSid, final String pathMapSid, final String pathIdentity){ + public SyncMapPermissionFetcher( + final String pathServiceSid, + final String pathMapSid, + final String pathIdentity + ) { this.pathServiceSid = pathServiceSid; this.pathMapSid = pathMapSid; this.pathIdentity = pathIdentity; } - @Override public SyncMapPermission fetch(final TwilioRestClient client) { - String path = "/Sync/Services/{ServiceSid}/Maps/{MapSid}/Permissions/{Identity}"; + String path = + "/Sync/Services/{ServiceSid}/Maps/{MapSid}/Permissions/{Identity}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"MapSid"+"}", this.pathMapSid.toString()); - path = path.replace("{"+"Identity"+"}", this.pathIdentity.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "MapSid" + "}", this.pathMapSid.toString()); + path = + path.replace("{" + "Identity" + "}", this.pathIdentity.toString()); Request request = new Request( HttpMethod.GET, @@ -55,15 +62,23 @@ public SyncMapPermission fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncMapPermission fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "SyncMapPermission fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return SyncMapPermission.fromJson(response.getStream(), client.getObjectMapper()); + return SyncMapPermission.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapPermissionReader.java b/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapPermissionReader.java index e65191275c..b721836bc7 100644 --- a/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapPermissionReader.java +++ b/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapPermissionReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.preview.sync.service.syncmap; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,21 +25,22 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class SyncMapPermissionReader extends Reader { + private String pathServiceSid; private String pathMapSid; private Integer pageSize; - public SyncMapPermissionReader(final String pathServiceSid, final String pathMapSid){ + public SyncMapPermissionReader( + final String pathServiceSid, + final String pathMapSid + ) { this.pathServiceSid = pathServiceSid; this.pathMapSid = pathMapSid; } - public SyncMapPermissionReader setPageSize(final Integer pageSize){ + public SyncMapPermissionReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -50,8 +52,12 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/Sync/Services/{ServiceSid}/Maps/{MapSid}/Permissions"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"MapSid"+"}", this.pathMapSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "MapSid" + "}", this.pathMapSid.toString()); Request request = new Request( HttpMethod.GET, @@ -63,13 +69,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncMapPermission read failed: Unable to connect to server"); + throw new ApiConnectionException( + "SyncMapPermission read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -85,7 +99,10 @@ private Page pageForRequest(final TwilioRestClient client, fi } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.PREVIEW.toString()) @@ -93,9 +110,11 @@ public Page previousPage(final Page page, return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.PREVIEW.toString()) @@ -104,21 +123,21 @@ public Page nextPage(final Page page, fina } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapPermissionUpdater.java b/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapPermissionUpdater.java index 7b496aa278..dfe1024299 100644 --- a/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapPermissionUpdater.java +++ b/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapPermissionUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.preview.sync.service.syncmap; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class SyncMapPermissionUpdater extends Updater { - - -public class SyncMapPermissionUpdater extends Updater{ private String pathServiceSid; private String pathMapSid; private String pathIdentity; @@ -35,7 +34,14 @@ public class SyncMapPermissionUpdater extends Updater{ private Boolean write; private Boolean manage; - public SyncMapPermissionUpdater(final String pathServiceSid, final String pathMapSid, final String pathIdentity, final Boolean read, final Boolean write, final Boolean manage){ + public SyncMapPermissionUpdater( + final String pathServiceSid, + final String pathMapSid, + final String pathIdentity, + final Boolean read, + final Boolean write, + final Boolean manage + ) { this.pathServiceSid = pathServiceSid; this.pathMapSid = pathMapSid; this.pathIdentity = pathIdentity; @@ -44,61 +50,76 @@ public SyncMapPermissionUpdater(final String pathServiceSid, final String pathMa this.manage = manage; } - public SyncMapPermissionUpdater setRead(final Boolean read){ + public SyncMapPermissionUpdater setRead(final Boolean read) { this.read = read; return this; } - public SyncMapPermissionUpdater setWrite(final Boolean write){ + + public SyncMapPermissionUpdater setWrite(final Boolean write) { this.write = write; return this; } - public SyncMapPermissionUpdater setManage(final Boolean manage){ + + public SyncMapPermissionUpdater setManage(final Boolean manage) { this.manage = manage; return this; } @Override - public SyncMapPermission update(final TwilioRestClient client){ - String path = "/Sync/Services/{ServiceSid}/Maps/{MapSid}/Permissions/{Identity}"; + public SyncMapPermission update(final TwilioRestClient client) { + String path = + "/Sync/Services/{ServiceSid}/Maps/{MapSid}/Permissions/{Identity}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"MapSid"+"}", this.pathMapSid.toString()); - path = path.replace("{"+"Identity"+"}", this.pathIdentity.toString()); - path = path.replace("{"+"Read"+"}", this.read.toString()); - path = path.replace("{"+"Write"+"}", this.write.toString()); - path = path.replace("{"+"Manage"+"}", this.manage.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "MapSid" + "}", this.pathMapSid.toString()); + path = + path.replace("{" + "Identity" + "}", this.pathIdentity.toString()); + path = path.replace("{" + "Read" + "}", this.read.toString()); + path = path.replace("{" + "Write" + "}", this.write.toString()); + path = path.replace("{" + "Manage" + "}", this.manage.toString()); Request request = new Request( HttpMethod.POST, Domains.PREVIEW.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncMapPermission update failed: Unable to connect to server"); + throw new ApiConnectionException( + "SyncMapPermission update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return SyncMapPermission.fromJson(response.getStream(), client.getObjectMapper()); + return SyncMapPermission.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (read != null) { request.addPostParam("Read", read.toString()); - } if (write != null) { request.addPostParam("Write", write.toString()); - } if (manage != null) { request.addPostParam("Manage", manage.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/preview/understand/Assistant.java b/src/main/java/com/twilio/rest/preview/understand/Assistant.java index dcadd40901..0fcdf8642f 100644 --- a/src/main/java/com/twilio/rest/preview/understand/Assistant.java +++ b/src/main/java/com/twilio/rest/preview/understand/Assistant.java @@ -23,55 +23,54 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Assistant extends Resource { + private static final long serialVersionUID = 164340193709329L; - public static AssistantCreator creator(){ + public static AssistantCreator creator() { return new AssistantCreator(); } - public static AssistantDeleter deleter(final String pathSid){ + public static AssistantDeleter deleter(final String pathSid) { return new AssistantDeleter(pathSid); } - public static AssistantFetcher fetcher(final String pathSid){ + public static AssistantFetcher fetcher(final String pathSid) { return new AssistantFetcher(pathSid); } - public static AssistantReader reader(){ + public static AssistantReader reader() { return new AssistantReader(); } - public static AssistantUpdater updater(final String pathSid){ + public static AssistantUpdater updater(final String pathSid) { return new AssistantUpdater(pathSid); } /** - * Converts a JSON String into a Assistant object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Assistant object represented by the provided JSON - */ - public static Assistant fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Assistant object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Assistant object represented by the provided JSON + */ + public static Assistant fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Assistant.class); @@ -83,14 +82,17 @@ public static Assistant fromJson(final String json, final ObjectMapper objectMap } /** - * Converts a JSON InputStream into a Assistant object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Assistant object represented by the provided JSON - */ - public static Assistant fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Assistant object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Assistant object represented by the provided JSON + */ + public static Assistant fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Assistant.class); @@ -116,41 +118,20 @@ public static Assistant fromJson(final InputStream json, final ObjectMapper obje @JsonCreator private Assistant( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("latest_model_build_sid") - final String latestModelBuildSid, - - @JsonProperty("links") - final Map links, - - @JsonProperty("log_queries") - final Boolean logQueries, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("unique_name") - final String uniqueName, - - @JsonProperty("url") - final URI url, - - @JsonProperty("callback_url") - final URI callbackUrl, - - @JsonProperty("callback_events") - final String callbackEvents + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty( + "latest_model_build_sid" + ) final String latestModelBuildSid, + @JsonProperty("links") final Map links, + @JsonProperty("log_queries") final Boolean logQueries, + @JsonProperty("sid") final String sid, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("url") final URI url, + @JsonProperty("callback_url") final URI callbackUrl, + @JsonProperty("callback_events") final String callbackEvents ) { this.accountSid = accountSid; this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); @@ -166,46 +147,57 @@ private Assistant( this.callbackEvents = callbackEvents; } - public final String getAccountSid() { - return this.accountSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getLatestModelBuildSid() { - return this.latestModelBuildSid; - } - public final Map getLinks() { - return this.links; - } - public final Boolean getLogQueries() { - return this.logQueries; - } - public final String getSid() { - return this.sid; - } - public final String getUniqueName() { - return this.uniqueName; - } - public final URI getUrl() { - return this.url; - } - public final URI getCallbackUrl() { - return this.callbackUrl; - } - public final String getCallbackEvents() { - return this.callbackEvents; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getLatestModelBuildSid() { + return this.latestModelBuildSid; + } + + public final Map getLinks() { + return this.links; + } + + public final Boolean getLogQueries() { + return this.logQueries; + } + + public final String getSid() { + return this.sid; + } + + public final String getUniqueName() { + return this.uniqueName; + } + + public final URI getUrl() { + return this.url; + } + + public final URI getCallbackUrl() { + return this.callbackUrl; + } + + public final String getCallbackEvents() { + return this.callbackEvents; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -215,13 +207,37 @@ public boolean equals(final Object o) { Assistant other = (Assistant) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(latestModelBuildSid, other.latestModelBuildSid) && Objects.equals(links, other.links) && Objects.equals(logQueries, other.logQueries) && Objects.equals(sid, other.sid) && Objects.equals(uniqueName, other.uniqueName) && Objects.equals(url, other.url) && Objects.equals(callbackUrl, other.callbackUrl) && Objects.equals(callbackEvents, other.callbackEvents) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(latestModelBuildSid, other.latestModelBuildSid) && + Objects.equals(links, other.links) && + Objects.equals(logQueries, other.logQueries) && + Objects.equals(sid, other.sid) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(url, other.url) && + Objects.equals(callbackUrl, other.callbackUrl) && + Objects.equals(callbackEvents, other.callbackEvents) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, dateCreated, dateUpdated, friendlyName, latestModelBuildSid, links, logQueries, sid, uniqueName, url, callbackUrl, callbackEvents); + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + friendlyName, + latestModelBuildSid, + links, + logQueries, + sid, + uniqueName, + url, + callbackUrl, + callbackEvents + ); } - } - diff --git a/src/main/java/com/twilio/rest/preview/understand/AssistantCreator.java b/src/main/java/com/twilio/rest/preview/understand/AssistantCreator.java index 3fc19ff816..fd30266480 100644 --- a/src/main/java/com/twilio/rest/preview/understand/AssistantCreator.java +++ b/src/main/java/com/twilio/rest/preview/understand/AssistantCreator.java @@ -15,9 +15,11 @@ package com.twilio.rest.preview.understand; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; +import com.twilio.converter.Converter; +import com.twilio.converter.Converter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; -import com.twilio.converter.Converter; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; @@ -25,16 +27,13 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import java.util.Map; -import com.twilio.converter.Converter; import java.net.URI; - +import java.net.URI; +import java.util.Map; import java.util.Map; +public class AssistantCreator extends Creator { -import java.net.URI; - -public class AssistantCreator extends Creator{ private String friendlyName; private Boolean logQueries; private String uniqueName; @@ -44,102 +43,121 @@ public class AssistantCreator extends Creator{ private Map initiationActions; private Map styleSheet; - public AssistantCreator() { - } + public AssistantCreator() {} - public AssistantCreator setFriendlyName(final String friendlyName){ + public AssistantCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public AssistantCreator setLogQueries(final Boolean logQueries){ + + public AssistantCreator setLogQueries(final Boolean logQueries) { this.logQueries = logQueries; return this; } - public AssistantCreator setUniqueName(final String uniqueName){ + + public AssistantCreator setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - public AssistantCreator setCallbackUrl(final URI callbackUrl){ + + public AssistantCreator setCallbackUrl(final URI callbackUrl) { this.callbackUrl = callbackUrl; return this; } - public AssistantCreator setCallbackUrl(final String callbackUrl){ + public AssistantCreator setCallbackUrl(final String callbackUrl) { return setCallbackUrl(Promoter.uriFromString(callbackUrl)); } - public AssistantCreator setCallbackEvents(final String callbackEvents){ + + public AssistantCreator setCallbackEvents(final String callbackEvents) { this.callbackEvents = callbackEvents; return this; } - public AssistantCreator setFallbackActions(final Map fallbackActions){ + + public AssistantCreator setFallbackActions( + final Map fallbackActions + ) { this.fallbackActions = fallbackActions; return this; } - public AssistantCreator setInitiationActions(final Map initiationActions){ + + public AssistantCreator setInitiationActions( + final Map initiationActions + ) { this.initiationActions = initiationActions; return this; } - public AssistantCreator setStyleSheet(final Map styleSheet){ + + public AssistantCreator setStyleSheet( + final Map styleSheet + ) { this.styleSheet = styleSheet; return this; } @Override - public Assistant create(final TwilioRestClient client){ + public Assistant create(final TwilioRestClient client) { String path = "/understand/Assistants"; - Request request = new Request( HttpMethod.POST, Domains.PREVIEW.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Assistant creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Assistant creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Assistant.fromJson(response.getStream(), client.getObjectMapper()); + return Assistant.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (logQueries != null) { request.addPostParam("LogQueries", logQueries.toString()); - } if (uniqueName != null) { request.addPostParam("UniqueName", uniqueName); - } if (callbackUrl != null) { request.addPostParam("CallbackUrl", callbackUrl.toString()); - } if (callbackEvents != null) { request.addPostParam("CallbackEvents", callbackEvents); - } if (fallbackActions != null) { - request.addPostParam("FallbackActions", Converter.mapToJson(fallbackActions)); - + request.addPostParam( + "FallbackActions", + Converter.mapToJson(fallbackActions) + ); } if (initiationActions != null) { - request.addPostParam("InitiationActions", Converter.mapToJson(initiationActions)); - + request.addPostParam( + "InitiationActions", + Converter.mapToJson(initiationActions) + ); } if (styleSheet != null) { - request.addPostParam("StyleSheet", Converter.mapToJson(styleSheet)); - + request.addPostParam("StyleSheet", Converter.mapToJson(styleSheet)); } } } diff --git a/src/main/java/com/twilio/rest/preview/understand/AssistantDeleter.java b/src/main/java/com/twilio/rest/preview/understand/AssistantDeleter.java index a977a2fab5..25d67d0610 100644 --- a/src/main/java/com/twilio/rest/preview/understand/AssistantDeleter.java +++ b/src/main/java/com/twilio/rest/preview/understand/AssistantDeleter.java @@ -24,21 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class AssistantDeleter extends Deleter { + private String pathSid; - public AssistantDeleter(final String pathSid){ + public AssistantDeleter(final String pathSid) { this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/understand/Assistants/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -48,9 +46,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Assistant delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Assistant delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/preview/understand/AssistantFetcher.java b/src/main/java/com/twilio/rest/preview/understand/AssistantFetcher.java index 00d45f873a..dcf871f952 100644 --- a/src/main/java/com/twilio/rest/preview/understand/AssistantFetcher.java +++ b/src/main/java/com/twilio/rest/preview/understand/AssistantFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class AssistantFetcher extends Fetcher { + private String pathSid; - public AssistantFetcher(final String pathSid){ + public AssistantFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public Assistant fetch(final TwilioRestClient client) { String path = "/understand/Assistants/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,15 +46,23 @@ public Assistant fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Assistant fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Assistant fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Assistant.fromJson(response.getStream(), client.getObjectMapper()); + return Assistant.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/preview/understand/AssistantReader.java b/src/main/java/com/twilio/rest/preview/understand/AssistantReader.java index 9b46f578f0..57c1e8ce42 100644 --- a/src/main/java/com/twilio/rest/preview/understand/AssistantReader.java +++ b/src/main/java/com/twilio/rest/preview/understand/AssistantReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.preview.understand; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,17 +25,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class AssistantReader extends Reader { + private Integer pageSize; - public AssistantReader(){ - } + public AssistantReader() {} - public AssistantReader setPageSize(final Integer pageSize){ + public AssistantReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -57,13 +55,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Assistant read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Assistant read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -79,7 +85,10 @@ private Page pageForRequest(final TwilioRestClient client, final Requ } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.PREVIEW.toString()) @@ -87,9 +96,11 @@ public Page previousPage(final Page page, final TwilioRest return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.PREVIEW.toString()) @@ -98,21 +109,21 @@ public Page nextPage(final Page page, final TwilioRestClie } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/preview/understand/AssistantUpdater.java b/src/main/java/com/twilio/rest/preview/understand/AssistantUpdater.java index ce443425bc..560f3faef2 100644 --- a/src/main/java/com/twilio/rest/preview/understand/AssistantUpdater.java +++ b/src/main/java/com/twilio/rest/preview/understand/AssistantUpdater.java @@ -15,9 +15,10 @@ package com.twilio.rest.preview.understand; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.converter.Converter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; -import com.twilio.converter.Converter; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; @@ -25,13 +26,11 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.net.URI; - import java.util.Map; +public class AssistantUpdater extends Updater { -public class AssistantUpdater extends Updater{ private String pathSid; private String friendlyName; private Boolean logQueries; @@ -42,104 +41,125 @@ public class AssistantUpdater extends Updater{ private Map initiationActions; private Map styleSheet; - public AssistantUpdater(final String pathSid){ + public AssistantUpdater(final String pathSid) { this.pathSid = pathSid; } - public AssistantUpdater setFriendlyName(final String friendlyName){ + public AssistantUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public AssistantUpdater setLogQueries(final Boolean logQueries){ + + public AssistantUpdater setLogQueries(final Boolean logQueries) { this.logQueries = logQueries; return this; } - public AssistantUpdater setUniqueName(final String uniqueName){ + + public AssistantUpdater setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - public AssistantUpdater setCallbackUrl(final URI callbackUrl){ + + public AssistantUpdater setCallbackUrl(final URI callbackUrl) { this.callbackUrl = callbackUrl; return this; } - public AssistantUpdater setCallbackUrl(final String callbackUrl){ + public AssistantUpdater setCallbackUrl(final String callbackUrl) { return setCallbackUrl(Promoter.uriFromString(callbackUrl)); } - public AssistantUpdater setCallbackEvents(final String callbackEvents){ + + public AssistantUpdater setCallbackEvents(final String callbackEvents) { this.callbackEvents = callbackEvents; return this; } - public AssistantUpdater setFallbackActions(final Map fallbackActions){ + + public AssistantUpdater setFallbackActions( + final Map fallbackActions + ) { this.fallbackActions = fallbackActions; return this; } - public AssistantUpdater setInitiationActions(final Map initiationActions){ + + public AssistantUpdater setInitiationActions( + final Map initiationActions + ) { this.initiationActions = initiationActions; return this; } - public AssistantUpdater setStyleSheet(final Map styleSheet){ + + public AssistantUpdater setStyleSheet( + final Map styleSheet + ) { this.styleSheet = styleSheet; return this; } @Override - public Assistant update(final TwilioRestClient client){ + public Assistant update(final TwilioRestClient client) { String path = "/understand/Assistants/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.PREVIEW.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Assistant update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Assistant update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Assistant.fromJson(response.getStream(), client.getObjectMapper()); + return Assistant.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (logQueries != null) { request.addPostParam("LogQueries", logQueries.toString()); - } if (uniqueName != null) { request.addPostParam("UniqueName", uniqueName); - } if (callbackUrl != null) { request.addPostParam("CallbackUrl", callbackUrl.toString()); - } if (callbackEvents != null) { request.addPostParam("CallbackEvents", callbackEvents); - } if (fallbackActions != null) { - request.addPostParam("FallbackActions", Converter.mapToJson(fallbackActions)); - + request.addPostParam( + "FallbackActions", + Converter.mapToJson(fallbackActions) + ); } if (initiationActions != null) { - request.addPostParam("InitiationActions", Converter.mapToJson(initiationActions)); - + request.addPostParam( + "InitiationActions", + Converter.mapToJson(initiationActions) + ); } if (styleSheet != null) { - request.addPostParam("StyleSheet", Converter.mapToJson(styleSheet)); - + request.addPostParam("StyleSheet", Converter.mapToJson(styleSheet)); } } } diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/AssistantFallbackActions.java b/src/main/java/com/twilio/rest/preview/understand/assistant/AssistantFallbackActions.java index 4ac92bfed2..8e5a5d5091 100644 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/AssistantFallbackActions.java +++ b/src/main/java/com/twilio/rest/preview/understand/assistant/AssistantFallbackActions.java @@ -22,42 +22,45 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class AssistantFallbackActions extends Resource { + private static final long serialVersionUID = 52727905251134L; - public static AssistantFallbackActionsFetcher fetcher(final String pathAssistantSid){ + public static AssistantFallbackActionsFetcher fetcher( + final String pathAssistantSid + ) { return new AssistantFallbackActionsFetcher(pathAssistantSid); } - public static AssistantFallbackActionsUpdater updater(final String pathAssistantSid){ + public static AssistantFallbackActionsUpdater updater( + final String pathAssistantSid + ) { return new AssistantFallbackActionsUpdater(pathAssistantSid); } /** - * Converts a JSON String into a AssistantFallbackActions object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return AssistantFallbackActions object represented by the provided JSON - */ - public static AssistantFallbackActions fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a AssistantFallbackActions object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return AssistantFallbackActions object represented by the provided JSON + */ + public static AssistantFallbackActions fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, AssistantFallbackActions.class); @@ -69,14 +72,17 @@ public static AssistantFallbackActions fromJson(final String json, final ObjectM } /** - * Converts a JSON InputStream into a AssistantFallbackActions object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return AssistantFallbackActions object represented by the provided JSON - */ - public static AssistantFallbackActions fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a AssistantFallbackActions object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return AssistantFallbackActions object represented by the provided JSON + */ + public static AssistantFallbackActions fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, AssistantFallbackActions.class); @@ -94,17 +100,10 @@ public static AssistantFallbackActions fromJson(final InputStream json, final Ob @JsonCreator private AssistantFallbackActions( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("assistant_sid") - final String assistantSid, - - @JsonProperty("url") - final URI url, - - @JsonProperty("data") - final Map data + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("assistant_sid") final String assistantSid, + @JsonProperty("url") final URI url, + @JsonProperty("data") final Map data ) { this.accountSid = accountSid; this.assistantSid = assistantSid; @@ -112,22 +111,25 @@ private AssistantFallbackActions( this.data = data; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getAssistantSid() { - return this.assistantSid; - } - public final URI getUrl() { - return this.url; - } - public final Map getData() { - return this.data; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getAssistantSid() { + return this.assistantSid; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getData() { + return this.data; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -137,13 +139,16 @@ public boolean equals(final Object o) { AssistantFallbackActions other = (AssistantFallbackActions) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(assistantSid, other.assistantSid) && Objects.equals(url, other.url) && Objects.equals(data, other.data) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(assistantSid, other.assistantSid) && + Objects.equals(url, other.url) && + Objects.equals(data, other.data) + ); } @Override public int hashCode() { return Objects.hash(accountSid, assistantSid, url, data); } - } - diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/AssistantFallbackActionsFetcher.java b/src/main/java/com/twilio/rest/preview/understand/assistant/AssistantFallbackActionsFetcher.java index 2784489c20..eaac3b736f 100644 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/AssistantFallbackActionsFetcher.java +++ b/src/main/java/com/twilio/rest/preview/understand/assistant/AssistantFallbackActionsFetcher.java @@ -24,22 +24,24 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class AssistantFallbackActionsFetcher + extends Fetcher { - - -public class AssistantFallbackActionsFetcher extends Fetcher { private String pathAssistantSid; - public AssistantFallbackActionsFetcher(final String pathAssistantSid){ + public AssistantFallbackActionsFetcher(final String pathAssistantSid) { this.pathAssistantSid = pathAssistantSid; } - @Override public AssistantFallbackActions fetch(final TwilioRestClient client) { String path = "/understand/Assistants/{AssistantSid}/FallbackActions"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -49,15 +51,23 @@ public AssistantFallbackActions fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AssistantFallbackActions fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "AssistantFallbackActions fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return AssistantFallbackActions.fromJson(response.getStream(), client.getObjectMapper()); + return AssistantFallbackActions.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/AssistantFallbackActionsUpdater.java b/src/main/java/com/twilio/rest/preview/understand/assistant/AssistantFallbackActionsUpdater.java index bb2905eb01..81eb4863db 100644 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/AssistantFallbackActionsUpdater.java +++ b/src/main/java/com/twilio/rest/preview/understand/assistant/AssistantFallbackActionsUpdater.java @@ -15,8 +15,9 @@ package com.twilio.rest.preview.understand.assistant; import com.twilio.base.Updater; -import com.twilio.exception.ApiConnectionException; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Converter; +import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; @@ -24,53 +25,70 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - import java.util.Map; +public class AssistantFallbackActionsUpdater + extends Updater { -public class AssistantFallbackActionsUpdater extends Updater{ private String pathAssistantSid; private Map fallbackActions; - public AssistantFallbackActionsUpdater(final String pathAssistantSid){ + public AssistantFallbackActionsUpdater(final String pathAssistantSid) { this.pathAssistantSid = pathAssistantSid; } - public AssistantFallbackActionsUpdater setFallbackActions(final Map fallbackActions){ + public AssistantFallbackActionsUpdater setFallbackActions( + final Map fallbackActions + ) { this.fallbackActions = fallbackActions; return this; } @Override - public AssistantFallbackActions update(final TwilioRestClient client){ + public AssistantFallbackActions update(final TwilioRestClient client) { String path = "/understand/Assistants/{AssistantSid}/FallbackActions"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.PREVIEW.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AssistantFallbackActions update failed: Unable to connect to server"); + throw new ApiConnectionException( + "AssistantFallbackActions update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return AssistantFallbackActions.fromJson(response.getStream(), client.getObjectMapper()); + return AssistantFallbackActions.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (fallbackActions != null) { - request.addPostParam("FallbackActions", Converter.mapToJson(fallbackActions)); - + request.addPostParam( + "FallbackActions", + Converter.mapToJson(fallbackActions) + ); } } } diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/AssistantInitiationActions.java b/src/main/java/com/twilio/rest/preview/understand/assistant/AssistantInitiationActions.java index 882545a7f5..9b3f435637 100644 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/AssistantInitiationActions.java +++ b/src/main/java/com/twilio/rest/preview/understand/assistant/AssistantInitiationActions.java @@ -22,45 +22,51 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class AssistantInitiationActions extends Resource { + private static final long serialVersionUID = 52727905251134L; - public static AssistantInitiationActionsFetcher fetcher(final String pathAssistantSid){ + public static AssistantInitiationActionsFetcher fetcher( + final String pathAssistantSid + ) { return new AssistantInitiationActionsFetcher(pathAssistantSid); } - public static AssistantInitiationActionsUpdater updater(final String pathAssistantSid){ + public static AssistantInitiationActionsUpdater updater( + final String pathAssistantSid + ) { return new AssistantInitiationActionsUpdater(pathAssistantSid); } /** - * Converts a JSON String into a AssistantInitiationActions object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return AssistantInitiationActions object represented by the provided JSON - */ - public static AssistantInitiationActions fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a AssistantInitiationActions object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return AssistantInitiationActions object represented by the provided JSON + */ + public static AssistantInitiationActions fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, AssistantInitiationActions.class); + return objectMapper.readValue( + json, + AssistantInitiationActions.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -69,17 +75,23 @@ public static AssistantInitiationActions fromJson(final String json, final Objec } /** - * Converts a JSON InputStream into a AssistantInitiationActions object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return AssistantInitiationActions object represented by the provided JSON - */ - public static AssistantInitiationActions fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a AssistantInitiationActions object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return AssistantInitiationActions object represented by the provided JSON + */ + public static AssistantInitiationActions fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, AssistantInitiationActions.class); + return objectMapper.readValue( + json, + AssistantInitiationActions.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -94,17 +106,10 @@ public static AssistantInitiationActions fromJson(final InputStream json, final @JsonCreator private AssistantInitiationActions( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("assistant_sid") - final String assistantSid, - - @JsonProperty("url") - final URI url, - - @JsonProperty("data") - final Map data + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("assistant_sid") final String assistantSid, + @JsonProperty("url") final URI url, + @JsonProperty("data") final Map data ) { this.accountSid = accountSid; this.assistantSid = assistantSid; @@ -112,22 +117,25 @@ private AssistantInitiationActions( this.data = data; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getAssistantSid() { - return this.assistantSid; - } - public final URI getUrl() { - return this.url; - } - public final Map getData() { - return this.data; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getAssistantSid() { + return this.assistantSid; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getData() { + return this.data; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -137,13 +145,16 @@ public boolean equals(final Object o) { AssistantInitiationActions other = (AssistantInitiationActions) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(assistantSid, other.assistantSid) && Objects.equals(url, other.url) && Objects.equals(data, other.data) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(assistantSid, other.assistantSid) && + Objects.equals(url, other.url) && + Objects.equals(data, other.data) + ); } @Override public int hashCode() { return Objects.hash(accountSid, assistantSid, url, data); } - } - diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/AssistantInitiationActionsFetcher.java b/src/main/java/com/twilio/rest/preview/understand/assistant/AssistantInitiationActionsFetcher.java index d0992820a6..536c01e6a8 100644 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/AssistantInitiationActionsFetcher.java +++ b/src/main/java/com/twilio/rest/preview/understand/assistant/AssistantInitiationActionsFetcher.java @@ -24,22 +24,24 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class AssistantInitiationActionsFetcher + extends Fetcher { - - -public class AssistantInitiationActionsFetcher extends Fetcher { private String pathAssistantSid; - public AssistantInitiationActionsFetcher(final String pathAssistantSid){ + public AssistantInitiationActionsFetcher(final String pathAssistantSid) { this.pathAssistantSid = pathAssistantSid; } - @Override public AssistantInitiationActions fetch(final TwilioRestClient client) { String path = "/understand/Assistants/{AssistantSid}/InitiationActions"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -49,15 +51,23 @@ public AssistantInitiationActions fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AssistantInitiationActions fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "AssistantInitiationActions fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return AssistantInitiationActions.fromJson(response.getStream(), client.getObjectMapper()); + return AssistantInitiationActions.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/AssistantInitiationActionsUpdater.java b/src/main/java/com/twilio/rest/preview/understand/assistant/AssistantInitiationActionsUpdater.java index 296e4003e9..6f23848b06 100644 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/AssistantInitiationActionsUpdater.java +++ b/src/main/java/com/twilio/rest/preview/understand/assistant/AssistantInitiationActionsUpdater.java @@ -15,8 +15,9 @@ package com.twilio.rest.preview.understand.assistant; import com.twilio.base.Updater; -import com.twilio.exception.ApiConnectionException; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Converter; +import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; @@ -24,53 +25,70 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - import java.util.Map; +public class AssistantInitiationActionsUpdater + extends Updater { -public class AssistantInitiationActionsUpdater extends Updater{ private String pathAssistantSid; private Map initiationActions; - public AssistantInitiationActionsUpdater(final String pathAssistantSid){ + public AssistantInitiationActionsUpdater(final String pathAssistantSid) { this.pathAssistantSid = pathAssistantSid; } - public AssistantInitiationActionsUpdater setInitiationActions(final Map initiationActions){ + public AssistantInitiationActionsUpdater setInitiationActions( + final Map initiationActions + ) { this.initiationActions = initiationActions; return this; } @Override - public AssistantInitiationActions update(final TwilioRestClient client){ + public AssistantInitiationActions update(final TwilioRestClient client) { String path = "/understand/Assistants/{AssistantSid}/InitiationActions"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.PREVIEW.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AssistantInitiationActions update failed: Unable to connect to server"); + throw new ApiConnectionException( + "AssistantInitiationActions update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return AssistantInitiationActions.fromJson(response.getStream(), client.getObjectMapper()); + return AssistantInitiationActions.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (initiationActions != null) { - request.addPostParam("InitiationActions", Converter.mapToJson(initiationActions)); - + request.addPostParam( + "InitiationActions", + Converter.mapToJson(initiationActions) + ); } } } diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/Dialogue.java b/src/main/java/com/twilio/rest/preview/understand/assistant/Dialogue.java index 82a14f6290..bec8ac0c07 100644 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/Dialogue.java +++ b/src/main/java/com/twilio/rest/preview/understand/assistant/Dialogue.java @@ -22,38 +22,40 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Dialogue extends Resource { + private static final long serialVersionUID = 270949613735802L; - public static DialogueFetcher fetcher(final String pathAssistantSid, final String pathSid){ + public static DialogueFetcher fetcher( + final String pathAssistantSid, + final String pathSid + ) { return new DialogueFetcher(pathAssistantSid, pathSid); } /** - * Converts a JSON String into a Dialogue object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Dialogue object represented by the provided JSON - */ - public static Dialogue fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Dialogue object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Dialogue object represented by the provided JSON + */ + public static Dialogue fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Dialogue.class); @@ -65,14 +67,17 @@ public static Dialogue fromJson(final String json, final ObjectMapper objectMapp } /** - * Converts a JSON InputStream into a Dialogue object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Dialogue object represented by the provided JSON - */ - public static Dialogue fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Dialogue object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Dialogue object represented by the provided JSON + */ + public static Dialogue fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Dialogue.class); @@ -91,20 +96,11 @@ public static Dialogue fromJson(final InputStream json, final ObjectMapper objec @JsonCreator private Dialogue( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("assistant_sid") - final String assistantSid, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("data") - final Map data, - - @JsonProperty("url") - final URI url + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("assistant_sid") final String assistantSid, + @JsonProperty("sid") final String sid, + @JsonProperty("data") final Map data, + @JsonProperty("url") final URI url ) { this.accountSid = accountSid; this.assistantSid = assistantSid; @@ -113,25 +109,29 @@ private Dialogue( this.url = url; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getAssistantSid() { - return this.assistantSid; - } - public final String getSid() { - return this.sid; - } - public final Map getData() { - return this.data; - } - public final URI getUrl() { - return this.url; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getAssistantSid() { + return this.assistantSid; + } + + public final String getSid() { + return this.sid; + } + + public final Map getData() { + return this.data; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -141,13 +141,17 @@ public boolean equals(final Object o) { Dialogue other = (Dialogue) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(assistantSid, other.assistantSid) && Objects.equals(sid, other.sid) && Objects.equals(data, other.data) && Objects.equals(url, other.url) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(assistantSid, other.assistantSid) && + Objects.equals(sid, other.sid) && + Objects.equals(data, other.data) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { return Objects.hash(accountSid, assistantSid, sid, data, url); } - } - diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/DialogueFetcher.java b/src/main/java/com/twilio/rest/preview/understand/assistant/DialogueFetcher.java index 1499f2c32b..0e66417397 100644 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/DialogueFetcher.java +++ b/src/main/java/com/twilio/rest/preview/understand/assistant/DialogueFetcher.java @@ -24,25 +24,29 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class DialogueFetcher extends Fetcher { + private String pathAssistantSid; private String pathSid; - public DialogueFetcher(final String pathAssistantSid, final String pathSid){ + public DialogueFetcher( + final String pathAssistantSid, + final String pathSid + ) { this.pathAssistantSid = pathAssistantSid; this.pathSid = pathSid; } - @Override public Dialogue fetch(final TwilioRestClient client) { String path = "/understand/Assistants/{AssistantSid}/Dialogues/{Sid}"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,15 +56,23 @@ public Dialogue fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Dialogue fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Dialogue fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Dialogue.fromJson(response.getStream(), client.getObjectMapper()); + return Dialogue.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/FieldType.java b/src/main/java/com/twilio/rest/preview/understand/assistant/FieldType.java index 3f39d01587..75b1de9725 100644 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/FieldType.java +++ b/src/main/java/com/twilio/rest/preview/understand/assistant/FieldType.java @@ -23,55 +23,66 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class FieldType extends Resource { + private static final long serialVersionUID = 124097769891823L; - public static FieldTypeCreator creator(final String pathAssistantSid, final String uniqueName){ + public static FieldTypeCreator creator( + final String pathAssistantSid, + final String uniqueName + ) { return new FieldTypeCreator(pathAssistantSid, uniqueName); } - public static FieldTypeDeleter deleter(final String pathAssistantSid, final String pathSid){ + public static FieldTypeDeleter deleter( + final String pathAssistantSid, + final String pathSid + ) { return new FieldTypeDeleter(pathAssistantSid, pathSid); } - public static FieldTypeFetcher fetcher(final String pathAssistantSid, final String pathSid){ + public static FieldTypeFetcher fetcher( + final String pathAssistantSid, + final String pathSid + ) { return new FieldTypeFetcher(pathAssistantSid, pathSid); } - public static FieldTypeReader reader(final String pathAssistantSid){ + public static FieldTypeReader reader(final String pathAssistantSid) { return new FieldTypeReader(pathAssistantSid); } - public static FieldTypeUpdater updater(final String pathAssistantSid, final String pathSid){ + public static FieldTypeUpdater updater( + final String pathAssistantSid, + final String pathSid + ) { return new FieldTypeUpdater(pathAssistantSid, pathSid); } /** - * Converts a JSON String into a FieldType object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return FieldType object represented by the provided JSON - */ - public static FieldType fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a FieldType object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return FieldType object represented by the provided JSON + */ + public static FieldType fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, FieldType.class); @@ -83,14 +94,17 @@ public static FieldType fromJson(final String json, final ObjectMapper objectMap } /** - * Converts a JSON InputStream into a FieldType object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return FieldType object represented by the provided JSON - */ - public static FieldType fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a FieldType object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return FieldType object represented by the provided JSON + */ + public static FieldType fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, FieldType.class); @@ -113,32 +127,15 @@ public static FieldType fromJson(final InputStream json, final ObjectMapper obje @JsonCreator private FieldType( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("links") - final Map links, - - @JsonProperty("assistant_sid") - final String assistantSid, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("unique_name") - final String uniqueName, - - @JsonProperty("url") - final URI url + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("links") final Map links, + @JsonProperty("assistant_sid") final String assistantSid, + @JsonProperty("sid") final String sid, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("url") final URI url ) { this.accountSid = accountSid; this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); @@ -151,37 +148,45 @@ private FieldType( this.url = url; } - public final String getAccountSid() { - return this.accountSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final Map getLinks() { - return this.links; - } - public final String getAssistantSid() { - return this.assistantSid; - } - public final String getSid() { - return this.sid; - } - public final String getUniqueName() { - return this.uniqueName; - } - public final URI getUrl() { - return this.url; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final Map getLinks() { + return this.links; + } + + public final String getAssistantSid() { + return this.assistantSid; + } + + public final String getSid() { + return this.sid; + } + + public final String getUniqueName() { + return this.uniqueName; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -191,13 +196,31 @@ public boolean equals(final Object o) { FieldType other = (FieldType) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(links, other.links) && Objects.equals(assistantSid, other.assistantSid) && Objects.equals(sid, other.sid) && Objects.equals(uniqueName, other.uniqueName) && Objects.equals(url, other.url) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(links, other.links) && + Objects.equals(assistantSid, other.assistantSid) && + Objects.equals(sid, other.sid) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, dateCreated, dateUpdated, friendlyName, links, assistantSid, sid, uniqueName, url); + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + friendlyName, + links, + assistantSid, + sid, + uniqueName, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/FieldTypeCreator.java b/src/main/java/com/twilio/rest/preview/understand/assistant/FieldTypeCreator.java index c489302277..b0984fe0fe 100644 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/FieldTypeCreator.java +++ b/src/main/java/com/twilio/rest/preview/understand/assistant/FieldTypeCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.preview.understand.assistant; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,62 +25,77 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class FieldTypeCreator extends Creator { - - -public class FieldTypeCreator extends Creator{ private String pathAssistantSid; private String uniqueName; private String friendlyName; - public FieldTypeCreator(final String pathAssistantSid, final String uniqueName) { + public FieldTypeCreator( + final String pathAssistantSid, + final String uniqueName + ) { this.pathAssistantSid = pathAssistantSid; this.uniqueName = uniqueName; } - public FieldTypeCreator setUniqueName(final String uniqueName){ + public FieldTypeCreator setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - public FieldTypeCreator setFriendlyName(final String friendlyName){ + + public FieldTypeCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } @Override - public FieldType create(final TwilioRestClient client){ + public FieldType create(final TwilioRestClient client) { String path = "/understand/Assistants/{AssistantSid}/FieldTypes"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"UniqueName"+"}", this.uniqueName.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = + path.replace("{" + "UniqueName" + "}", this.uniqueName.toString()); Request request = new Request( HttpMethod.POST, Domains.PREVIEW.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("FieldType creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "FieldType creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return FieldType.fromJson(response.getStream(), client.getObjectMapper()); + return FieldType.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (uniqueName != null) { request.addPostParam("UniqueName", uniqueName); - } if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } } } diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/FieldTypeDeleter.java b/src/main/java/com/twilio/rest/preview/understand/assistant/FieldTypeDeleter.java index 3eb0ffd3c8..a0cb4ae271 100644 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/FieldTypeDeleter.java +++ b/src/main/java/com/twilio/rest/preview/understand/assistant/FieldTypeDeleter.java @@ -24,24 +24,29 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class FieldTypeDeleter extends Deleter { + private String pathAssistantSid; private String pathSid; - public FieldTypeDeleter(final String pathAssistantSid, final String pathSid){ + public FieldTypeDeleter( + final String pathAssistantSid, + final String pathSid + ) { this.pathAssistantSid = pathAssistantSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/understand/Assistants/{AssistantSid}/FieldTypes/{Sid}"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +56,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("FieldType delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "FieldType delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/FieldTypeFetcher.java b/src/main/java/com/twilio/rest/preview/understand/assistant/FieldTypeFetcher.java index dcb5f738d0..c4362c542a 100644 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/FieldTypeFetcher.java +++ b/src/main/java/com/twilio/rest/preview/understand/assistant/FieldTypeFetcher.java @@ -24,25 +24,29 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class FieldTypeFetcher extends Fetcher { + private String pathAssistantSid; private String pathSid; - public FieldTypeFetcher(final String pathAssistantSid, final String pathSid){ + public FieldTypeFetcher( + final String pathAssistantSid, + final String pathSid + ) { this.pathAssistantSid = pathAssistantSid; this.pathSid = pathSid; } - @Override public FieldType fetch(final TwilioRestClient client) { String path = "/understand/Assistants/{AssistantSid}/FieldTypes/{Sid}"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,15 +56,23 @@ public FieldType fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("FieldType fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "FieldType fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return FieldType.fromJson(response.getStream(), client.getObjectMapper()); + return FieldType.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/FieldTypeReader.java b/src/main/java/com/twilio/rest/preview/understand/assistant/FieldTypeReader.java index 2ca43e498c..712e06b52c 100644 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/FieldTypeReader.java +++ b/src/main/java/com/twilio/rest/preview/understand/assistant/FieldTypeReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.preview.understand.assistant; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,19 +25,17 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class FieldTypeReader extends Reader { + private String pathAssistantSid; private Integer pageSize; - public FieldTypeReader(final String pathAssistantSid){ + public FieldTypeReader(final String pathAssistantSid) { this.pathAssistantSid = pathAssistantSid; } - public FieldTypeReader setPageSize(final Integer pageSize){ + public FieldTypeReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -48,7 +47,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/understand/Assistants/{AssistantSid}/FieldTypes"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -60,13 +63,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("FieldType read failed: Unable to connect to server"); + throw new ApiConnectionException( + "FieldType read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +93,10 @@ private Page pageForRequest(final TwilioRestClient client, final Requ } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.PREVIEW.toString()) @@ -90,9 +104,11 @@ public Page previousPage(final Page page, final TwilioRest return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.PREVIEW.toString()) @@ -101,21 +117,21 @@ public Page nextPage(final Page page, final TwilioRestClie } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/FieldTypeUpdater.java b/src/main/java/com/twilio/rest/preview/understand/assistant/FieldTypeUpdater.java index 9a8af03298..0beac3f04e 100644 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/FieldTypeUpdater.java +++ b/src/main/java/com/twilio/rest/preview/understand/assistant/FieldTypeUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.preview.understand.assistant; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,63 +25,77 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class FieldTypeUpdater extends Updater { - - -public class FieldTypeUpdater extends Updater{ private String pathAssistantSid; private String pathSid; private String friendlyName; private String uniqueName; - public FieldTypeUpdater(final String pathAssistantSid, final String pathSid){ + public FieldTypeUpdater( + final String pathAssistantSid, + final String pathSid + ) { this.pathAssistantSid = pathAssistantSid; this.pathSid = pathSid; } - public FieldTypeUpdater setFriendlyName(final String friendlyName){ + public FieldTypeUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public FieldTypeUpdater setUniqueName(final String uniqueName){ + + public FieldTypeUpdater setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } @Override - public FieldType update(final TwilioRestClient client){ + public FieldType update(final TwilioRestClient client) { String path = "/understand/Assistants/{AssistantSid}/FieldTypes/{Sid}"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.PREVIEW.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("FieldType update failed: Unable to connect to server"); + throw new ApiConnectionException( + "FieldType update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return FieldType.fromJson(response.getStream(), client.getObjectMapper()); + return FieldType.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (uniqueName != null) { request.addPostParam("UniqueName", uniqueName); - } } } diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/ModelBuild.java b/src/main/java/com/twilio/rest/preview/understand/assistant/ModelBuild.java index 36aac75c82..e27bb2b354 100644 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/ModelBuild.java +++ b/src/main/java/com/twilio/rest/preview/understand/assistant/ModelBuild.java @@ -24,53 +24,61 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class ModelBuild extends Resource { + private static final long serialVersionUID = 226055418389205L; - public static ModelBuildCreator creator(final String pathAssistantSid){ + public static ModelBuildCreator creator(final String pathAssistantSid) { return new ModelBuildCreator(pathAssistantSid); } - public static ModelBuildDeleter deleter(final String pathAssistantSid, final String pathSid){ + public static ModelBuildDeleter deleter( + final String pathAssistantSid, + final String pathSid + ) { return new ModelBuildDeleter(pathAssistantSid, pathSid); } - public static ModelBuildFetcher fetcher(final String pathAssistantSid, final String pathSid){ + public static ModelBuildFetcher fetcher( + final String pathAssistantSid, + final String pathSid + ) { return new ModelBuildFetcher(pathAssistantSid, pathSid); } - public static ModelBuildReader reader(final String pathAssistantSid){ + public static ModelBuildReader reader(final String pathAssistantSid) { return new ModelBuildReader(pathAssistantSid); } - public static ModelBuildUpdater updater(final String pathAssistantSid, final String pathSid){ + public static ModelBuildUpdater updater( + final String pathAssistantSid, + final String pathSid + ) { return new ModelBuildUpdater(pathAssistantSid, pathSid); } /** - * Converts a JSON String into a ModelBuild object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return ModelBuild object represented by the provided JSON - */ - public static ModelBuild fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a ModelBuild object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return ModelBuild object represented by the provided JSON + */ + public static ModelBuild fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, ModelBuild.class); @@ -82,14 +90,17 @@ public static ModelBuild fromJson(final String json, final ObjectMapper objectMa } /** - * Converts a JSON InputStream into a ModelBuild object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return ModelBuild object represented by the provided JSON - */ - public static ModelBuild fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a ModelBuild object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return ModelBuild object represented by the provided JSON + */ + public static ModelBuild fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, ModelBuild.class); @@ -99,6 +110,7 @@ public static ModelBuild fromJson(final InputStream json, final ObjectMapper obj throw new ApiConnectionException(e.getMessage(), e); } } + public enum Status { ENQUEUED("enqueued"), BUILDING("building"), @@ -135,35 +147,16 @@ public static Status forValue(final String value) { @JsonCreator private ModelBuild( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("assistant_sid") - final String assistantSid, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("status") - final ModelBuild.Status status, - - @JsonProperty("unique_name") - final String uniqueName, - - @JsonProperty("url") - final URI url, - - @JsonProperty("build_duration") - final Integer buildDuration, - - @JsonProperty("error_code") - final Integer errorCode + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("assistant_sid") final String assistantSid, + @JsonProperty("sid") final String sid, + @JsonProperty("status") final ModelBuild.Status status, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("url") final URI url, + @JsonProperty("build_duration") final Integer buildDuration, + @JsonProperty("error_code") final Integer errorCode ) { this.accountSid = accountSid; this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); @@ -177,40 +170,49 @@ private ModelBuild( this.errorCode = errorCode; } - public final String getAccountSid() { - return this.accountSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getAssistantSid() { - return this.assistantSid; - } - public final String getSid() { - return this.sid; - } - public final ModelBuild.Status getStatus() { - return this.status; - } - public final String getUniqueName() { - return this.uniqueName; - } - public final URI getUrl() { - return this.url; - } - public final Integer getBuildDuration() { - return this.buildDuration; - } - public final Integer getErrorCode() { - return this.errorCode; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getAssistantSid() { + return this.assistantSid; + } + + public final String getSid() { + return this.sid; + } + + public final ModelBuild.Status getStatus() { + return this.status; + } + + public final String getUniqueName() { + return this.uniqueName; + } + + public final URI getUrl() { + return this.url; + } + + public final Integer getBuildDuration() { + return this.buildDuration; + } + + public final Integer getErrorCode() { + return this.errorCode; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -220,13 +222,33 @@ public boolean equals(final Object o) { ModelBuild other = (ModelBuild) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(assistantSid, other.assistantSid) && Objects.equals(sid, other.sid) && Objects.equals(status, other.status) && Objects.equals(uniqueName, other.uniqueName) && Objects.equals(url, other.url) && Objects.equals(buildDuration, other.buildDuration) && Objects.equals(errorCode, other.errorCode) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(assistantSid, other.assistantSid) && + Objects.equals(sid, other.sid) && + Objects.equals(status, other.status) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(url, other.url) && + Objects.equals(buildDuration, other.buildDuration) && + Objects.equals(errorCode, other.errorCode) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, dateCreated, dateUpdated, assistantSid, sid, status, uniqueName, url, buildDuration, errorCode); + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + assistantSid, + sid, + status, + uniqueName, + url, + buildDuration, + errorCode + ); } - } - diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/ModelBuildCreator.java b/src/main/java/com/twilio/rest/preview/understand/assistant/ModelBuildCreator.java index 0f8cc99741..394069971b 100644 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/ModelBuildCreator.java +++ b/src/main/java/com/twilio/rest/preview/understand/assistant/ModelBuildCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.preview.understand.assistant; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -25,12 +26,10 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.net.URI; - - - import java.net.URI; -public class ModelBuildCreator extends Creator{ +public class ModelBuildCreator extends Creator { + private String pathAssistantSid; private URI statusCallback; private String uniqueName; @@ -39,52 +38,65 @@ public ModelBuildCreator(final String pathAssistantSid) { this.pathAssistantSid = pathAssistantSid; } - public ModelBuildCreator setStatusCallback(final URI statusCallback){ + public ModelBuildCreator setStatusCallback(final URI statusCallback) { this.statusCallback = statusCallback; return this; } - public ModelBuildCreator setStatusCallback(final String statusCallback){ + public ModelBuildCreator setStatusCallback(final String statusCallback) { return setStatusCallback(Promoter.uriFromString(statusCallback)); } - public ModelBuildCreator setUniqueName(final String uniqueName){ + + public ModelBuildCreator setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } @Override - public ModelBuild create(final TwilioRestClient client){ + public ModelBuild create(final TwilioRestClient client) { String path = "/understand/Assistants/{AssistantSid}/ModelBuilds"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.PREVIEW.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("ModelBuild creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "ModelBuild creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return ModelBuild.fromJson(response.getStream(), client.getObjectMapper()); + return ModelBuild.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (statusCallback != null) { request.addPostParam("StatusCallback", statusCallback.toString()); - } if (uniqueName != null) { request.addPostParam("UniqueName", uniqueName); - } } } diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/ModelBuildDeleter.java b/src/main/java/com/twilio/rest/preview/understand/assistant/ModelBuildDeleter.java index 11e5e1ae31..74b07e117e 100644 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/ModelBuildDeleter.java +++ b/src/main/java/com/twilio/rest/preview/understand/assistant/ModelBuildDeleter.java @@ -24,24 +24,29 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class ModelBuildDeleter extends Deleter { + private String pathAssistantSid; private String pathSid; - public ModelBuildDeleter(final String pathAssistantSid, final String pathSid){ + public ModelBuildDeleter( + final String pathAssistantSid, + final String pathSid + ) { this.pathAssistantSid = pathAssistantSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/understand/Assistants/{AssistantSid}/ModelBuilds/{Sid}"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +56,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("ModelBuild delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "ModelBuild delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/ModelBuildFetcher.java b/src/main/java/com/twilio/rest/preview/understand/assistant/ModelBuildFetcher.java index c31b7ffaa0..76b46a422f 100644 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/ModelBuildFetcher.java +++ b/src/main/java/com/twilio/rest/preview/understand/assistant/ModelBuildFetcher.java @@ -24,25 +24,29 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class ModelBuildFetcher extends Fetcher { + private String pathAssistantSid; private String pathSid; - public ModelBuildFetcher(final String pathAssistantSid, final String pathSid){ + public ModelBuildFetcher( + final String pathAssistantSid, + final String pathSid + ) { this.pathAssistantSid = pathAssistantSid; this.pathSid = pathSid; } - @Override public ModelBuild fetch(final TwilioRestClient client) { String path = "/understand/Assistants/{AssistantSid}/ModelBuilds/{Sid}"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,15 +56,23 @@ public ModelBuild fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("ModelBuild fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "ModelBuild fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return ModelBuild.fromJson(response.getStream(), client.getObjectMapper()); + return ModelBuild.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/ModelBuildReader.java b/src/main/java/com/twilio/rest/preview/understand/assistant/ModelBuildReader.java index 0fdaec4ecd..e4e8f71962 100644 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/ModelBuildReader.java +++ b/src/main/java/com/twilio/rest/preview/understand/assistant/ModelBuildReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.preview.understand.assistant; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,19 +25,17 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class ModelBuildReader extends Reader { + private String pathAssistantSid; private Integer pageSize; - public ModelBuildReader(final String pathAssistantSid){ + public ModelBuildReader(final String pathAssistantSid) { this.pathAssistantSid = pathAssistantSid; } - public ModelBuildReader setPageSize(final Integer pageSize){ + public ModelBuildReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -48,7 +47,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/understand/Assistants/{AssistantSid}/ModelBuilds"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -60,13 +63,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("ModelBuild read failed: Unable to connect to server"); + throw new ApiConnectionException( + "ModelBuild read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +93,10 @@ private Page pageForRequest(final TwilioRestClient client, final Req } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.PREVIEW.toString()) @@ -90,9 +104,11 @@ public Page previousPage(final Page page, final TwilioRe return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.PREVIEW.toString()) @@ -101,21 +117,21 @@ public Page nextPage(final Page page, final TwilioRestCl } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/ModelBuildUpdater.java b/src/main/java/com/twilio/rest/preview/understand/assistant/ModelBuildUpdater.java index 84940464ad..db7cb874a7 100644 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/ModelBuildUpdater.java +++ b/src/main/java/com/twilio/rest/preview/understand/assistant/ModelBuildUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.preview.understand.assistant; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,54 +25,68 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class ModelBuildUpdater extends Updater { - - -public class ModelBuildUpdater extends Updater{ private String pathAssistantSid; private String pathSid; private String uniqueName; - public ModelBuildUpdater(final String pathAssistantSid, final String pathSid){ + public ModelBuildUpdater( + final String pathAssistantSid, + final String pathSid + ) { this.pathAssistantSid = pathAssistantSid; this.pathSid = pathSid; } - public ModelBuildUpdater setUniqueName(final String uniqueName){ + public ModelBuildUpdater setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } @Override - public ModelBuild update(final TwilioRestClient client){ + public ModelBuild update(final TwilioRestClient client) { String path = "/understand/Assistants/{AssistantSid}/ModelBuilds/{Sid}"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.PREVIEW.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("ModelBuild update failed: Unable to connect to server"); + throw new ApiConnectionException( + "ModelBuild update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return ModelBuild.fromJson(response.getStream(), client.getObjectMapper()); + return ModelBuild.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (uniqueName != null) { request.addPostParam("UniqueName", uniqueName); - } } } diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/Query.java b/src/main/java/com/twilio/rest/preview/understand/assistant/Query.java index a7515213c9..b0934d9170 100644 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/Query.java +++ b/src/main/java/com/twilio/rest/preview/understand/assistant/Query.java @@ -23,55 +23,67 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Query extends Resource { + private static final long serialVersionUID = 180519234688811L; - public static QueryCreator creator(final String pathAssistantSid, final String language, final String query){ + public static QueryCreator creator( + final String pathAssistantSid, + final String language, + final String query + ) { return new QueryCreator(pathAssistantSid, language, query); } - public static QueryDeleter deleter(final String pathAssistantSid, final String pathSid){ + public static QueryDeleter deleter( + final String pathAssistantSid, + final String pathSid + ) { return new QueryDeleter(pathAssistantSid, pathSid); } - public static QueryFetcher fetcher(final String pathAssistantSid, final String pathSid){ + public static QueryFetcher fetcher( + final String pathAssistantSid, + final String pathSid + ) { return new QueryFetcher(pathAssistantSid, pathSid); } - public static QueryReader reader(final String pathAssistantSid){ + public static QueryReader reader(final String pathAssistantSid) { return new QueryReader(pathAssistantSid); } - public static QueryUpdater updater(final String pathAssistantSid, final String pathSid){ + public static QueryUpdater updater( + final String pathAssistantSid, + final String pathSid + ) { return new QueryUpdater(pathAssistantSid, pathSid); } /** - * Converts a JSON String into a Query object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Query object represented by the provided JSON - */ - public static Query fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Query object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Query object represented by the provided JSON + */ + public static Query fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Query.class); @@ -83,14 +95,17 @@ public static Query fromJson(final String json, final ObjectMapper objectMapper) } /** - * Converts a JSON InputStream into a Query object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Query object represented by the provided JSON - */ - public static Query fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Query object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Query object represented by the provided JSON + */ + public static Query fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Query.class); @@ -117,44 +132,19 @@ public static Query fromJson(final InputStream json, final ObjectMapper objectMa @JsonCreator private Query( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("results") - final Map results, - - @JsonProperty("language") - final String language, - - @JsonProperty("model_build_sid") - final String modelBuildSid, - - @JsonProperty("query") - final String query, - - @JsonProperty("sample_sid") - final String sampleSid, - - @JsonProperty("assistant_sid") - final String assistantSid, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("status") - final String status, - - @JsonProperty("url") - final URI url, - - @JsonProperty("source_channel") - final String sourceChannel + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("results") final Map results, + @JsonProperty("language") final String language, + @JsonProperty("model_build_sid") final String modelBuildSid, + @JsonProperty("query") final String query, + @JsonProperty("sample_sid") final String sampleSid, + @JsonProperty("assistant_sid") final String assistantSid, + @JsonProperty("sid") final String sid, + @JsonProperty("status") final String status, + @JsonProperty("url") final URI url, + @JsonProperty("source_channel") final String sourceChannel ) { this.accountSid = accountSid; this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); @@ -171,49 +161,61 @@ private Query( this.sourceChannel = sourceChannel; } - public final String getAccountSid() { - return this.accountSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final Map getResults() { - return this.results; - } - public final String getLanguage() { - return this.language; - } - public final String getModelBuildSid() { - return this.modelBuildSid; - } - public final String getQuery() { - return this.query; - } - public final String getSampleSid() { - return this.sampleSid; - } - public final String getAssistantSid() { - return this.assistantSid; - } - public final String getSid() { - return this.sid; - } - public final String getStatus() { - return this.status; - } - public final URI getUrl() { - return this.url; - } - public final String getSourceChannel() { - return this.sourceChannel; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final Map getResults() { + return this.results; + } + + public final String getLanguage() { + return this.language; + } + + public final String getModelBuildSid() { + return this.modelBuildSid; + } + + public final String getQuery() { + return this.query; + } + + public final String getSampleSid() { + return this.sampleSid; + } + + public final String getAssistantSid() { + return this.assistantSid; + } + + public final String getSid() { + return this.sid; + } + + public final String getStatus() { + return this.status; + } + + public final URI getUrl() { + return this.url; + } + + public final String getSourceChannel() { + return this.sourceChannel; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -223,13 +225,39 @@ public boolean equals(final Object o) { Query other = (Query) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(results, other.results) && Objects.equals(language, other.language) && Objects.equals(modelBuildSid, other.modelBuildSid) && Objects.equals(query, other.query) && Objects.equals(sampleSid, other.sampleSid) && Objects.equals(assistantSid, other.assistantSid) && Objects.equals(sid, other.sid) && Objects.equals(status, other.status) && Objects.equals(url, other.url) && Objects.equals(sourceChannel, other.sourceChannel) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(results, other.results) && + Objects.equals(language, other.language) && + Objects.equals(modelBuildSid, other.modelBuildSid) && + Objects.equals(query, other.query) && + Objects.equals(sampleSid, other.sampleSid) && + Objects.equals(assistantSid, other.assistantSid) && + Objects.equals(sid, other.sid) && + Objects.equals(status, other.status) && + Objects.equals(url, other.url) && + Objects.equals(sourceChannel, other.sourceChannel) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, dateCreated, dateUpdated, results, language, modelBuildSid, query, sampleSid, assistantSid, sid, status, url, sourceChannel); + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + results, + language, + modelBuildSid, + query, + sampleSid, + assistantSid, + sid, + status, + url, + sourceChannel + ); } - } - diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/QueryCreator.java b/src/main/java/com/twilio/rest/preview/understand/assistant/QueryCreator.java index 7fbcf7a23b..9d28c01619 100644 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/QueryCreator.java +++ b/src/main/java/com/twilio/rest/preview/understand/assistant/QueryCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.preview.understand.assistant; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class QueryCreator extends Creator { - - -public class QueryCreator extends Creator{ private String pathAssistantSid; private String language; private String query; @@ -35,52 +34,70 @@ public class QueryCreator extends Creator{ private String modelBuild; private String field; - public QueryCreator(final String pathAssistantSid, final String language, final String query) { + public QueryCreator( + final String pathAssistantSid, + final String language, + final String query + ) { this.pathAssistantSid = pathAssistantSid; this.language = language; this.query = query; } - public QueryCreator setLanguage(final String language){ + public QueryCreator setLanguage(final String language) { this.language = language; return this; } - public QueryCreator setQuery(final String query){ + + public QueryCreator setQuery(final String query) { this.query = query; return this; } - public QueryCreator setTasks(final String tasks){ + + public QueryCreator setTasks(final String tasks) { this.tasks = tasks; return this; } - public QueryCreator setModelBuild(final String modelBuild){ + + public QueryCreator setModelBuild(final String modelBuild) { this.modelBuild = modelBuild; return this; } - public QueryCreator setField(final String field){ + + public QueryCreator setField(final String field) { this.field = field; return this; } @Override - public Query create(final TwilioRestClient client){ + public Query create(final TwilioRestClient client) { String path = "/understand/Assistants/{AssistantSid}/Queries"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"Language"+"}", this.language.toString()); - path = path.replace("{"+"Query"+"}", this.query.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = path.replace("{" + "Language" + "}", this.language.toString()); + path = path.replace("{" + "Query" + "}", this.query.toString()); Request request = new Request( HttpMethod.POST, Domains.PREVIEW.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Query creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Query creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -89,26 +106,22 @@ public Query create(final TwilioRestClient client){ return Query.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (language != null) { request.addPostParam("Language", language); - } if (query != null) { request.addPostParam("Query", query); - } if (tasks != null) { request.addPostParam("Tasks", tasks); - } if (modelBuild != null) { request.addPostParam("ModelBuild", modelBuild); - } if (field != null) { request.addPostParam("Field", field); - } } } diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/QueryDeleter.java b/src/main/java/com/twilio/rest/preview/understand/assistant/QueryDeleter.java index 39b0026bb6..c212c70285 100644 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/QueryDeleter.java +++ b/src/main/java/com/twilio/rest/preview/understand/assistant/QueryDeleter.java @@ -24,24 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class QueryDeleter extends Deleter { + private String pathAssistantSid; private String pathSid; - public QueryDeleter(final String pathAssistantSid, final String pathSid){ + public QueryDeleter(final String pathAssistantSid, final String pathSid) { this.pathAssistantSid = pathAssistantSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/understand/Assistants/{AssistantSid}/Queries/{Sid}"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +53,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Query delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Query delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/QueryFetcher.java b/src/main/java/com/twilio/rest/preview/understand/assistant/QueryFetcher.java index 0f94185176..0a27769320 100644 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/QueryFetcher.java +++ b/src/main/java/com/twilio/rest/preview/understand/assistant/QueryFetcher.java @@ -24,25 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class QueryFetcher extends Fetcher { + private String pathAssistantSid; private String pathSid; - public QueryFetcher(final String pathAssistantSid, final String pathSid){ + public QueryFetcher(final String pathAssistantSid, final String pathSid) { this.pathAssistantSid = pathAssistantSid; this.pathSid = pathSid; } - @Override public Query fetch(final TwilioRestClient client) { String path = "/understand/Assistants/{AssistantSid}/Queries/{Sid}"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,9 +53,14 @@ public Query fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Query fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Query fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/QueryReader.java b/src/main/java/com/twilio/rest/preview/understand/assistant/QueryReader.java index a38acc0013..48c1c7aba2 100644 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/QueryReader.java +++ b/src/main/java/com/twilio/rest/preview/understand/assistant/QueryReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.preview.understand.assistant; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,34 +25,35 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class QueryReader extends Reader { + private String pathAssistantSid; private String language; private String modelBuild; private String status; private Integer pageSize; - public QueryReader(final String pathAssistantSid){ + public QueryReader(final String pathAssistantSid) { this.pathAssistantSid = pathAssistantSid; } - public QueryReader setLanguage(final String language){ + public QueryReader setLanguage(final String language) { this.language = language; return this; } - public QueryReader setModelBuild(final String modelBuild){ + + public QueryReader setModelBuild(final String modelBuild) { this.modelBuild = modelBuild; return this; } - public QueryReader setStatus(final String status){ + + public QueryReader setStatus(final String status) { this.status = status; return this; } - public QueryReader setPageSize(final Integer pageSize){ + + public QueryReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -63,7 +65,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/understand/Assistants/{AssistantSid}/Queries"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -75,13 +81,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Query read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Query read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -97,7 +111,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.PREVIEW.toString()) @@ -105,9 +122,11 @@ public Page previousPage(final Page page, final TwilioRestClient c return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.PREVIEW.toString()) @@ -116,33 +135,30 @@ public Page nextPage(final Page page, final TwilioRestClient clien } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (language != null) { - request.addQueryParam("Language", language); } if (modelBuild != null) { - request.addQueryParam("ModelBuild", modelBuild); } if (status != null) { - request.addQueryParam("Status", status); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/QueryUpdater.java b/src/main/java/com/twilio/rest/preview/understand/assistant/QueryUpdater.java index a23a3c34c8..e5567abba9 100644 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/QueryUpdater.java +++ b/src/main/java/com/twilio/rest/preview/understand/assistant/QueryUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.preview.understand.assistant; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,47 +25,56 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class QueryUpdater extends Updater { - - -public class QueryUpdater extends Updater{ private String pathAssistantSid; private String pathSid; private String sampleSid; private String status; - public QueryUpdater(final String pathAssistantSid, final String pathSid){ + public QueryUpdater(final String pathAssistantSid, final String pathSid) { this.pathAssistantSid = pathAssistantSid; this.pathSid = pathSid; } - public QueryUpdater setSampleSid(final String sampleSid){ + public QueryUpdater setSampleSid(final String sampleSid) { this.sampleSid = sampleSid; return this; } - public QueryUpdater setStatus(final String status){ + + public QueryUpdater setStatus(final String status) { this.status = status; return this; } @Override - public Query update(final TwilioRestClient client){ + public Query update(final TwilioRestClient client) { String path = "/understand/Assistants/{AssistantSid}/Queries/{Sid}"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.PREVIEW.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Query update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Query update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -73,14 +83,13 @@ public Query update(final TwilioRestClient client){ return Query.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (sampleSid != null) { request.addPostParam("SampleSid", sampleSid); - } if (status != null) { request.addPostParam("Status", status); - } } } diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/StyleSheet.java b/src/main/java/com/twilio/rest/preview/understand/assistant/StyleSheet.java index 8b2aab60d5..6f8ff4aa5d 100644 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/StyleSheet.java +++ b/src/main/java/com/twilio/rest/preview/understand/assistant/StyleSheet.java @@ -22,42 +22,41 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class StyleSheet extends Resource { + private static final long serialVersionUID = 52727905251134L; - public static StyleSheetFetcher fetcher(final String pathAssistantSid){ + public static StyleSheetFetcher fetcher(final String pathAssistantSid) { return new StyleSheetFetcher(pathAssistantSid); } - public static StyleSheetUpdater updater(final String pathAssistantSid){ + public static StyleSheetUpdater updater(final String pathAssistantSid) { return new StyleSheetUpdater(pathAssistantSid); } /** - * Converts a JSON String into a StyleSheet object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return StyleSheet object represented by the provided JSON - */ - public static StyleSheet fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a StyleSheet object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return StyleSheet object represented by the provided JSON + */ + public static StyleSheet fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, StyleSheet.class); @@ -69,14 +68,17 @@ public static StyleSheet fromJson(final String json, final ObjectMapper objectMa } /** - * Converts a JSON InputStream into a StyleSheet object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return StyleSheet object represented by the provided JSON - */ - public static StyleSheet fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a StyleSheet object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return StyleSheet object represented by the provided JSON + */ + public static StyleSheet fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, StyleSheet.class); @@ -94,17 +96,10 @@ public static StyleSheet fromJson(final InputStream json, final ObjectMapper obj @JsonCreator private StyleSheet( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("assistant_sid") - final String assistantSid, - - @JsonProperty("url") - final URI url, - - @JsonProperty("data") - final Map data + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("assistant_sid") final String assistantSid, + @JsonProperty("url") final URI url, + @JsonProperty("data") final Map data ) { this.accountSid = accountSid; this.assistantSid = assistantSid; @@ -112,22 +107,25 @@ private StyleSheet( this.data = data; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getAssistantSid() { - return this.assistantSid; - } - public final URI getUrl() { - return this.url; - } - public final Map getData() { - return this.data; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getAssistantSid() { + return this.assistantSid; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getData() { + return this.data; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -137,13 +135,16 @@ public boolean equals(final Object o) { StyleSheet other = (StyleSheet) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(assistantSid, other.assistantSid) && Objects.equals(url, other.url) && Objects.equals(data, other.data) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(assistantSid, other.assistantSid) && + Objects.equals(url, other.url) && + Objects.equals(data, other.data) + ); } @Override public int hashCode() { return Objects.hash(accountSid, assistantSid, url, data); } - } - diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/StyleSheetFetcher.java b/src/main/java/com/twilio/rest/preview/understand/assistant/StyleSheetFetcher.java index 9721b42e52..74f681b994 100644 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/StyleSheetFetcher.java +++ b/src/main/java/com/twilio/rest/preview/understand/assistant/StyleSheetFetcher.java @@ -24,22 +24,23 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class StyleSheetFetcher extends Fetcher { + private String pathAssistantSid; - public StyleSheetFetcher(final String pathAssistantSid){ + public StyleSheetFetcher(final String pathAssistantSid) { this.pathAssistantSid = pathAssistantSid; } - @Override public StyleSheet fetch(final TwilioRestClient client) { String path = "/understand/Assistants/{AssistantSid}/StyleSheet"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -49,15 +50,23 @@ public StyleSheet fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("StyleSheet fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "StyleSheet fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return StyleSheet.fromJson(response.getStream(), client.getObjectMapper()); + return StyleSheet.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/StyleSheetUpdater.java b/src/main/java/com/twilio/rest/preview/understand/assistant/StyleSheetUpdater.java index 89ebd0b62a..8a4a400bbf 100644 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/StyleSheetUpdater.java +++ b/src/main/java/com/twilio/rest/preview/understand/assistant/StyleSheetUpdater.java @@ -15,8 +15,9 @@ package com.twilio.rest.preview.understand.assistant; import com.twilio.base.Updater; -import com.twilio.exception.ApiConnectionException; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Converter; +import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; @@ -24,53 +25,66 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - import java.util.Map; +public class StyleSheetUpdater extends Updater { -public class StyleSheetUpdater extends Updater{ private String pathAssistantSid; private Map styleSheet; - public StyleSheetUpdater(final String pathAssistantSid){ + public StyleSheetUpdater(final String pathAssistantSid) { this.pathAssistantSid = pathAssistantSid; } - public StyleSheetUpdater setStyleSheet(final Map styleSheet){ + public StyleSheetUpdater setStyleSheet( + final Map styleSheet + ) { this.styleSheet = styleSheet; return this; } @Override - public StyleSheet update(final TwilioRestClient client){ + public StyleSheet update(final TwilioRestClient client) { String path = "/understand/Assistants/{AssistantSid}/StyleSheet"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.PREVIEW.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("StyleSheet update failed: Unable to connect to server"); + throw new ApiConnectionException( + "StyleSheet update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return StyleSheet.fromJson(response.getStream(), client.getObjectMapper()); + return StyleSheet.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (styleSheet != null) { - request.addPostParam("StyleSheet", Converter.mapToJson(styleSheet)); - + request.addPostParam("StyleSheet", Converter.mapToJson(styleSheet)); } } } diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/Task.java b/src/main/java/com/twilio/rest/preview/understand/assistant/Task.java index af8accd3ad..8e09c271d0 100644 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/Task.java +++ b/src/main/java/com/twilio/rest/preview/understand/assistant/Task.java @@ -23,55 +23,66 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Task extends Resource { + private static final long serialVersionUID = 59959992200143L; - public static TaskCreator creator(final String pathAssistantSid, final String uniqueName){ + public static TaskCreator creator( + final String pathAssistantSid, + final String uniqueName + ) { return new TaskCreator(pathAssistantSid, uniqueName); } - public static TaskDeleter deleter(final String pathAssistantSid, final String pathSid){ + public static TaskDeleter deleter( + final String pathAssistantSid, + final String pathSid + ) { return new TaskDeleter(pathAssistantSid, pathSid); } - public static TaskFetcher fetcher(final String pathAssistantSid, final String pathSid){ + public static TaskFetcher fetcher( + final String pathAssistantSid, + final String pathSid + ) { return new TaskFetcher(pathAssistantSid, pathSid); } - public static TaskReader reader(final String pathAssistantSid){ + public static TaskReader reader(final String pathAssistantSid) { return new TaskReader(pathAssistantSid); } - public static TaskUpdater updater(final String pathAssistantSid, final String pathSid){ + public static TaskUpdater updater( + final String pathAssistantSid, + final String pathSid + ) { return new TaskUpdater(pathAssistantSid, pathSid); } /** - * Converts a JSON String into a Task object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Task object represented by the provided JSON - */ - public static Task fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Task object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Task object represented by the provided JSON + */ + public static Task fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Task.class); @@ -83,14 +94,17 @@ public static Task fromJson(final String json, final ObjectMapper objectMapper) } /** - * Converts a JSON InputStream into a Task object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Task object represented by the provided JSON - */ - public static Task fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Task object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Task object represented by the provided JSON + */ + public static Task fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Task.class); @@ -114,35 +128,16 @@ public static Task fromJson(final InputStream json, final ObjectMapper objectMap @JsonCreator private Task( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("links") - final Map links, - - @JsonProperty("assistant_sid") - final String assistantSid, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("unique_name") - final String uniqueName, - - @JsonProperty("actions_url") - final URI actionsUrl, - - @JsonProperty("url") - final URI url + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("links") final Map links, + @JsonProperty("assistant_sid") final String assistantSid, + @JsonProperty("sid") final String sid, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("actions_url") final URI actionsUrl, + @JsonProperty("url") final URI url ) { this.accountSid = accountSid; this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); @@ -156,40 +151,49 @@ private Task( this.url = url; } - public final String getAccountSid() { - return this.accountSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final Map getLinks() { - return this.links; - } - public final String getAssistantSid() { - return this.assistantSid; - } - public final String getSid() { - return this.sid; - } - public final String getUniqueName() { - return this.uniqueName; - } - public final URI getActionsUrl() { - return this.actionsUrl; - } - public final URI getUrl() { - return this.url; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final Map getLinks() { + return this.links; + } + + public final String getAssistantSid() { + return this.assistantSid; + } + + public final String getSid() { + return this.sid; + } + + public final String getUniqueName() { + return this.uniqueName; + } + + public final URI getActionsUrl() { + return this.actionsUrl; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -199,13 +203,33 @@ public boolean equals(final Object o) { Task other = (Task) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(links, other.links) && Objects.equals(assistantSid, other.assistantSid) && Objects.equals(sid, other.sid) && Objects.equals(uniqueName, other.uniqueName) && Objects.equals(actionsUrl, other.actionsUrl) && Objects.equals(url, other.url) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(links, other.links) && + Objects.equals(assistantSid, other.assistantSid) && + Objects.equals(sid, other.sid) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(actionsUrl, other.actionsUrl) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, dateCreated, dateUpdated, friendlyName, links, assistantSid, sid, uniqueName, actionsUrl, url); + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + friendlyName, + links, + assistantSid, + sid, + uniqueName, + actionsUrl, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/TaskCreator.java b/src/main/java/com/twilio/rest/preview/understand/assistant/TaskCreator.java index f7a73958ee..08aa1e1cdb 100644 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/TaskCreator.java +++ b/src/main/java/com/twilio/rest/preview/understand/assistant/TaskCreator.java @@ -15,9 +15,11 @@ package com.twilio.rest.preview.understand.assistant; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; +import com.twilio.converter.Converter; +import com.twilio.converter.Converter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; -import com.twilio.converter.Converter; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; @@ -25,16 +27,13 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import java.util.Map; -import com.twilio.converter.Converter; import java.net.URI; - +import java.net.URI; +import java.util.Map; import java.util.Map; +public class TaskCreator extends Creator { -import java.net.URI; - -public class TaskCreator extends Creator{ private String pathAssistantSid; private String uniqueName; private String friendlyName; @@ -46,45 +45,59 @@ public TaskCreator(final String pathAssistantSid, final String uniqueName) { this.uniqueName = uniqueName; } - public TaskCreator setUniqueName(final String uniqueName){ + public TaskCreator setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - public TaskCreator setFriendlyName(final String friendlyName){ + + public TaskCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public TaskCreator setActions(final Map actions){ + + public TaskCreator setActions(final Map actions) { this.actions = actions; return this; } - public TaskCreator setActionsUrl(final URI actionsUrl){ + + public TaskCreator setActionsUrl(final URI actionsUrl) { this.actionsUrl = actionsUrl; return this; } - public TaskCreator setActionsUrl(final String actionsUrl){ + public TaskCreator setActionsUrl(final String actionsUrl) { return setActionsUrl(Promoter.uriFromString(actionsUrl)); } @Override - public Task create(final TwilioRestClient client){ + public Task create(final TwilioRestClient client) { String path = "/understand/Assistants/{AssistantSid}/Tasks"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"UniqueName"+"}", this.uniqueName.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = + path.replace("{" + "UniqueName" + "}", this.uniqueName.toString()); Request request = new Request( HttpMethod.POST, Domains.PREVIEW.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Task creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Task creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -93,22 +106,19 @@ public Task create(final TwilioRestClient client){ return Task.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (uniqueName != null) { request.addPostParam("UniqueName", uniqueName); - } if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (actions != null) { - request.addPostParam("Actions", Converter.mapToJson(actions)); - + request.addPostParam("Actions", Converter.mapToJson(actions)); } if (actionsUrl != null) { request.addPostParam("ActionsUrl", actionsUrl.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/TaskDeleter.java b/src/main/java/com/twilio/rest/preview/understand/assistant/TaskDeleter.java index 23a6a93776..71a379ac97 100644 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/TaskDeleter.java +++ b/src/main/java/com/twilio/rest/preview/understand/assistant/TaskDeleter.java @@ -24,24 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class TaskDeleter extends Deleter { + private String pathAssistantSid; private String pathSid; - public TaskDeleter(final String pathAssistantSid, final String pathSid){ + public TaskDeleter(final String pathAssistantSid, final String pathSid) { this.pathAssistantSid = pathAssistantSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/understand/Assistants/{AssistantSid}/Tasks/{Sid}"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +53,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Task delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Task delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/TaskFetcher.java b/src/main/java/com/twilio/rest/preview/understand/assistant/TaskFetcher.java index 6b76286334..1b1824809c 100644 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/TaskFetcher.java +++ b/src/main/java/com/twilio/rest/preview/understand/assistant/TaskFetcher.java @@ -24,25 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class TaskFetcher extends Fetcher { + private String pathAssistantSid; private String pathSid; - public TaskFetcher(final String pathAssistantSid, final String pathSid){ + public TaskFetcher(final String pathAssistantSid, final String pathSid) { this.pathAssistantSid = pathAssistantSid; this.pathSid = pathSid; } - @Override public Task fetch(final TwilioRestClient client) { String path = "/understand/Assistants/{AssistantSid}/Tasks/{Sid}"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,9 +53,14 @@ public Task fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Task fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Task fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/TaskReader.java b/src/main/java/com/twilio/rest/preview/understand/assistant/TaskReader.java index 552a52534e..19e9ab5ea3 100644 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/TaskReader.java +++ b/src/main/java/com/twilio/rest/preview/understand/assistant/TaskReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.preview.understand.assistant; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,19 +25,17 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class TaskReader extends Reader { + private String pathAssistantSid; private Integer pageSize; - public TaskReader(final String pathAssistantSid){ + public TaskReader(final String pathAssistantSid) { this.pathAssistantSid = pathAssistantSid; } - public TaskReader setPageSize(final Integer pageSize){ + public TaskReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -48,7 +47,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/understand/Assistants/{AssistantSid}/Tasks"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -60,13 +63,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Task read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Task read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +93,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request r } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.PREVIEW.toString()) @@ -90,9 +104,11 @@ public Page previousPage(final Page page, final TwilioRestClient cli return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.PREVIEW.toString()) @@ -101,21 +117,21 @@ public Page nextPage(final Page page, final TwilioRestClient client) } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/TaskUpdater.java b/src/main/java/com/twilio/rest/preview/understand/assistant/TaskUpdater.java index a68e61cb82..99e58e7a7e 100644 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/TaskUpdater.java +++ b/src/main/java/com/twilio/rest/preview/understand/assistant/TaskUpdater.java @@ -15,9 +15,10 @@ package com.twilio.rest.preview.understand.assistant; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.converter.Converter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; -import com.twilio.converter.Converter; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; @@ -25,13 +26,11 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.net.URI; - import java.util.Map; +public class TaskUpdater extends Updater { -public class TaskUpdater extends Updater{ private String pathAssistantSid; private String pathSid; private String friendlyName; @@ -39,50 +38,63 @@ public class TaskUpdater extends Updater{ private Map actions; private URI actionsUrl; - public TaskUpdater(final String pathAssistantSid, final String pathSid){ + public TaskUpdater(final String pathAssistantSid, final String pathSid) { this.pathAssistantSid = pathAssistantSid; this.pathSid = pathSid; } - public TaskUpdater setFriendlyName(final String friendlyName){ + public TaskUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public TaskUpdater setUniqueName(final String uniqueName){ + + public TaskUpdater setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - public TaskUpdater setActions(final Map actions){ + + public TaskUpdater setActions(final Map actions) { this.actions = actions; return this; } - public TaskUpdater setActionsUrl(final URI actionsUrl){ + + public TaskUpdater setActionsUrl(final URI actionsUrl) { this.actionsUrl = actionsUrl; return this; } - public TaskUpdater setActionsUrl(final String actionsUrl){ + public TaskUpdater setActionsUrl(final String actionsUrl) { return setActionsUrl(Promoter.uriFromString(actionsUrl)); } @Override - public Task update(final TwilioRestClient client){ + public Task update(final TwilioRestClient client) { String path = "/understand/Assistants/{AssistantSid}/Tasks/{Sid}"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.PREVIEW.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Task update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Task update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -91,22 +103,19 @@ public Task update(final TwilioRestClient client){ return Task.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (uniqueName != null) { request.addPostParam("UniqueName", uniqueName); - } if (actions != null) { - request.addPostParam("Actions", Converter.mapToJson(actions)); - + request.addPostParam("Actions", Converter.mapToJson(actions)); } if (actionsUrl != null) { request.addPostParam("ActionsUrl", actionsUrl.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/fieldtype/FieldValue.java b/src/main/java/com/twilio/rest/preview/understand/assistant/fieldtype/FieldValue.java index 6871c1ebbc..9e633257c3 100644 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/fieldtype/FieldValue.java +++ b/src/main/java/com/twilio/rest/preview/understand/assistant/fieldtype/FieldValue.java @@ -23,49 +23,77 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class FieldValue extends Resource { + private static final long serialVersionUID = 181490262234152L; - public static FieldValueCreator creator(final String pathAssistantSid, final String pathFieldTypeSid, final String language, final String value){ - return new FieldValueCreator(pathAssistantSid, pathFieldTypeSid, language, value); + public static FieldValueCreator creator( + final String pathAssistantSid, + final String pathFieldTypeSid, + final String language, + final String value + ) { + return new FieldValueCreator( + pathAssistantSid, + pathFieldTypeSid, + language, + value + ); } - public static FieldValueDeleter deleter(final String pathAssistantSid, final String pathFieldTypeSid, final String pathSid){ - return new FieldValueDeleter(pathAssistantSid, pathFieldTypeSid, pathSid); + public static FieldValueDeleter deleter( + final String pathAssistantSid, + final String pathFieldTypeSid, + final String pathSid + ) { + return new FieldValueDeleter( + pathAssistantSid, + pathFieldTypeSid, + pathSid + ); } - public static FieldValueFetcher fetcher(final String pathAssistantSid, final String pathFieldTypeSid, final String pathSid){ - return new FieldValueFetcher(pathAssistantSid, pathFieldTypeSid, pathSid); + public static FieldValueFetcher fetcher( + final String pathAssistantSid, + final String pathFieldTypeSid, + final String pathSid + ) { + return new FieldValueFetcher( + pathAssistantSid, + pathFieldTypeSid, + pathSid + ); } - public static FieldValueReader reader(final String pathAssistantSid, final String pathFieldTypeSid){ + public static FieldValueReader reader( + final String pathAssistantSid, + final String pathFieldTypeSid + ) { return new FieldValueReader(pathAssistantSid, pathFieldTypeSid); } /** - * Converts a JSON String into a FieldValue object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return FieldValue object represented by the provided JSON - */ - public static FieldValue fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a FieldValue object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return FieldValue object represented by the provided JSON + */ + public static FieldValue fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, FieldValue.class); @@ -77,14 +105,17 @@ public static FieldValue fromJson(final String json, final ObjectMapper objectMa } /** - * Converts a JSON InputStream into a FieldValue object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return FieldValue object represented by the provided JSON - */ - public static FieldValue fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a FieldValue object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return FieldValue object represented by the provided JSON + */ + public static FieldValue fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, FieldValue.class); @@ -108,35 +139,16 @@ public static FieldValue fromJson(final InputStream json, final ObjectMapper obj @JsonCreator private FieldValue( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("field_type_sid") - final String fieldTypeSid, - - @JsonProperty("language") - final String language, - - @JsonProperty("assistant_sid") - final String assistantSid, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("value") - final String value, - - @JsonProperty("url") - final URI url, - - @JsonProperty("synonym_of") - final String synonymOf + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("field_type_sid") final String fieldTypeSid, + @JsonProperty("language") final String language, + @JsonProperty("assistant_sid") final String assistantSid, + @JsonProperty("sid") final String sid, + @JsonProperty("value") final String value, + @JsonProperty("url") final URI url, + @JsonProperty("synonym_of") final String synonymOf ) { this.accountSid = accountSid; this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); @@ -150,40 +162,49 @@ private FieldValue( this.synonymOf = synonymOf; } - public final String getAccountSid() { - return this.accountSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getFieldTypeSid() { - return this.fieldTypeSid; - } - public final String getLanguage() { - return this.language; - } - public final String getAssistantSid() { - return this.assistantSid; - } - public final String getSid() { - return this.sid; - } - public final String getValue() { - return this.value; - } - public final URI getUrl() { - return this.url; - } - public final String getSynonymOf() { - return this.synonymOf; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getFieldTypeSid() { + return this.fieldTypeSid; + } + + public final String getLanguage() { + return this.language; + } + + public final String getAssistantSid() { + return this.assistantSid; + } + + public final String getSid() { + return this.sid; + } + + public final String getValue() { + return this.value; + } + + public final URI getUrl() { + return this.url; + } + + public final String getSynonymOf() { + return this.synonymOf; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -193,13 +214,33 @@ public boolean equals(final Object o) { FieldValue other = (FieldValue) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(fieldTypeSid, other.fieldTypeSid) && Objects.equals(language, other.language) && Objects.equals(assistantSid, other.assistantSid) && Objects.equals(sid, other.sid) && Objects.equals(value, other.value) && Objects.equals(url, other.url) && Objects.equals(synonymOf, other.synonymOf) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(fieldTypeSid, other.fieldTypeSid) && + Objects.equals(language, other.language) && + Objects.equals(assistantSid, other.assistantSid) && + Objects.equals(sid, other.sid) && + Objects.equals(value, other.value) && + Objects.equals(url, other.url) && + Objects.equals(synonymOf, other.synonymOf) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, dateCreated, dateUpdated, fieldTypeSid, language, assistantSid, sid, value, url, synonymOf); + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + fieldTypeSid, + language, + assistantSid, + sid, + value, + url, + synonymOf + ); } - } - diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/fieldtype/FieldValueCreator.java b/src/main/java/com/twilio/rest/preview/understand/assistant/fieldtype/FieldValueCreator.java index 6d86962005..9d2e062869 100644 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/fieldtype/FieldValueCreator.java +++ b/src/main/java/com/twilio/rest/preview/understand/assistant/fieldtype/FieldValueCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.preview.understand.assistant.fieldtype; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,76 +25,97 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class FieldValueCreator extends Creator { - - -public class FieldValueCreator extends Creator{ private String pathAssistantSid; private String pathFieldTypeSid; private String language; private String value; private String synonymOf; - public FieldValueCreator(final String pathAssistantSid, final String pathFieldTypeSid, final String language, final String value) { + public FieldValueCreator( + final String pathAssistantSid, + final String pathFieldTypeSid, + final String language, + final String value + ) { this.pathAssistantSid = pathAssistantSid; this.pathFieldTypeSid = pathFieldTypeSid; this.language = language; this.value = value; } - public FieldValueCreator setLanguage(final String language){ + public FieldValueCreator setLanguage(final String language) { this.language = language; return this; } - public FieldValueCreator setValue(final String value){ + + public FieldValueCreator setValue(final String value) { this.value = value; return this; } - public FieldValueCreator setSynonymOf(final String synonymOf){ + + public FieldValueCreator setSynonymOf(final String synonymOf) { this.synonymOf = synonymOf; return this; } @Override - public FieldValue create(final TwilioRestClient client){ - String path = "/understand/Assistants/{AssistantSid}/FieldTypes/{FieldTypeSid}/FieldValues"; + public FieldValue create(final TwilioRestClient client) { + String path = + "/understand/Assistants/{AssistantSid}/FieldTypes/{FieldTypeSid}/FieldValues"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"FieldTypeSid"+"}", this.pathFieldTypeSid.toString()); - path = path.replace("{"+"Language"+"}", this.language.toString()); - path = path.replace("{"+"Value"+"}", this.value.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = + path.replace( + "{" + "FieldTypeSid" + "}", + this.pathFieldTypeSid.toString() + ); + path = path.replace("{" + "Language" + "}", this.language.toString()); + path = path.replace("{" + "Value" + "}", this.value.toString()); Request request = new Request( HttpMethod.POST, Domains.PREVIEW.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("FieldValue creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "FieldValue creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return FieldValue.fromJson(response.getStream(), client.getObjectMapper()); + return FieldValue.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (language != null) { request.addPostParam("Language", language); - } if (value != null) { request.addPostParam("Value", value); - } if (synonymOf != null) { request.addPostParam("SynonymOf", synonymOf); - } } } diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/fieldtype/FieldValueDeleter.java b/src/main/java/com/twilio/rest/preview/understand/assistant/fieldtype/FieldValueDeleter.java index 78aa1e1765..e3365ff06d 100644 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/fieldtype/FieldValueDeleter.java +++ b/src/main/java/com/twilio/rest/preview/understand/assistant/fieldtype/FieldValueDeleter.java @@ -24,27 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class FieldValueDeleter extends Deleter { + private String pathAssistantSid; private String pathFieldTypeSid; private String pathSid; - public FieldValueDeleter(final String pathAssistantSid, final String pathFieldTypeSid, final String pathSid){ + public FieldValueDeleter( + final String pathAssistantSid, + final String pathFieldTypeSid, + final String pathSid + ) { this.pathAssistantSid = pathAssistantSid; this.pathFieldTypeSid = pathFieldTypeSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/understand/Assistants/{AssistantSid}/FieldTypes/{FieldTypeSid}/FieldValues/{Sid}"; + String path = + "/understand/Assistants/{AssistantSid}/FieldTypes/{FieldTypeSid}/FieldValues/{Sid}"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"FieldTypeSid"+"}", this.pathFieldTypeSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = + path.replace( + "{" + "FieldTypeSid" + "}", + this.pathFieldTypeSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -54,9 +65,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("FieldValue delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "FieldValue delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/fieldtype/FieldValueFetcher.java b/src/main/java/com/twilio/rest/preview/understand/assistant/fieldtype/FieldValueFetcher.java index f4e7448405..4e6cfd8314 100644 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/fieldtype/FieldValueFetcher.java +++ b/src/main/java/com/twilio/rest/preview/understand/assistant/fieldtype/FieldValueFetcher.java @@ -24,28 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class FieldValueFetcher extends Fetcher { + private String pathAssistantSid; private String pathFieldTypeSid; private String pathSid; - public FieldValueFetcher(final String pathAssistantSid, final String pathFieldTypeSid, final String pathSid){ + public FieldValueFetcher( + final String pathAssistantSid, + final String pathFieldTypeSid, + final String pathSid + ) { this.pathAssistantSid = pathAssistantSid; this.pathFieldTypeSid = pathFieldTypeSid; this.pathSid = pathSid; } - @Override public FieldValue fetch(final TwilioRestClient client) { - String path = "/understand/Assistants/{AssistantSid}/FieldTypes/{FieldTypeSid}/FieldValues/{Sid}"; + String path = + "/understand/Assistants/{AssistantSid}/FieldTypes/{FieldTypeSid}/FieldValues/{Sid}"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"FieldTypeSid"+"}", this.pathFieldTypeSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = + path.replace( + "{" + "FieldTypeSid" + "}", + this.pathFieldTypeSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -55,15 +65,23 @@ public FieldValue fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("FieldValue fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "FieldValue fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return FieldValue.fromJson(response.getStream(), client.getObjectMapper()); + return FieldValue.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/fieldtype/FieldValueReader.java b/src/main/java/com/twilio/rest/preview/understand/assistant/fieldtype/FieldValueReader.java index 72ab75a85f..bf3b27b25d 100644 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/fieldtype/FieldValueReader.java +++ b/src/main/java/com/twilio/rest/preview/understand/assistant/fieldtype/FieldValueReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.preview.understand.assistant.fieldtype; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,26 +25,28 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class FieldValueReader extends Reader { + private String pathAssistantSid; private String pathFieldTypeSid; private String language; private Integer pageSize; - public FieldValueReader(final String pathAssistantSid, final String pathFieldTypeSid){ + public FieldValueReader( + final String pathAssistantSid, + final String pathFieldTypeSid + ) { this.pathAssistantSid = pathAssistantSid; this.pathFieldTypeSid = pathFieldTypeSid; } - public FieldValueReader setLanguage(final String language){ + public FieldValueReader setLanguage(final String language) { this.language = language; return this; } - public FieldValueReader setPageSize(final Integer pageSize){ + + public FieldValueReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -54,9 +57,18 @@ public ResourceSet read(final TwilioRestClient client) { } public Page firstPage(final TwilioRestClient client) { - String path = "/understand/Assistants/{AssistantSid}/FieldTypes/{FieldTypeSid}/FieldValues"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"FieldTypeSid"+"}", this.pathFieldTypeSid.toString()); + String path = + "/understand/Assistants/{AssistantSid}/FieldTypes/{FieldTypeSid}/FieldValues"; + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = + path.replace( + "{" + "FieldTypeSid" + "}", + this.pathFieldTypeSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -68,13 +80,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("FieldValue read failed: Unable to connect to server"); + throw new ApiConnectionException( + "FieldValue read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -90,7 +110,10 @@ private Page pageForRequest(final TwilioRestClient client, final Req } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.PREVIEW.toString()) @@ -98,9 +121,11 @@ public Page previousPage(final Page page, final TwilioRe return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.PREVIEW.toString()) @@ -109,25 +134,24 @@ public Page nextPage(final Page page, final TwilioRestCl } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (language != null) { - request.addQueryParam("Language", language); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/task/Field.java b/src/main/java/com/twilio/rest/preview/understand/assistant/task/Field.java index 0ae3eb8fc6..1b6c6c74cd 100644 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/task/Field.java +++ b/src/main/java/com/twilio/rest/preview/understand/assistant/task/Field.java @@ -23,49 +23,69 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Field extends Resource { + private static final long serialVersionUID = 118531839027400L; - public static FieldCreator creator(final String pathAssistantSid, final String pathTaskSid, final String fieldType, final String uniqueName){ - return new FieldCreator(pathAssistantSid, pathTaskSid, fieldType, uniqueName); + public static FieldCreator creator( + final String pathAssistantSid, + final String pathTaskSid, + final String fieldType, + final String uniqueName + ) { + return new FieldCreator( + pathAssistantSid, + pathTaskSid, + fieldType, + uniqueName + ); } - public static FieldDeleter deleter(final String pathAssistantSid, final String pathTaskSid, final String pathSid){ + public static FieldDeleter deleter( + final String pathAssistantSid, + final String pathTaskSid, + final String pathSid + ) { return new FieldDeleter(pathAssistantSid, pathTaskSid, pathSid); } - public static FieldFetcher fetcher(final String pathAssistantSid, final String pathTaskSid, final String pathSid){ + public static FieldFetcher fetcher( + final String pathAssistantSid, + final String pathTaskSid, + final String pathSid + ) { return new FieldFetcher(pathAssistantSid, pathTaskSid, pathSid); } - public static FieldReader reader(final String pathAssistantSid, final String pathTaskSid){ + public static FieldReader reader( + final String pathAssistantSid, + final String pathTaskSid + ) { return new FieldReader(pathAssistantSid, pathTaskSid); } /** - * Converts a JSON String into a Field object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Field object represented by the provided JSON - */ - public static Field fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Field object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Field object represented by the provided JSON + */ + public static Field fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Field.class); @@ -77,14 +97,17 @@ public static Field fromJson(final String json, final ObjectMapper objectMapper) } /** - * Converts a JSON InputStream into a Field object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Field object represented by the provided JSON - */ - public static Field fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Field object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Field object represented by the provided JSON + */ + public static Field fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Field.class); @@ -107,32 +130,15 @@ public static Field fromJson(final InputStream json, final ObjectMapper objectMa @JsonCreator private Field( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("field_type") - final String fieldType, - - @JsonProperty("task_sid") - final String taskSid, - - @JsonProperty("assistant_sid") - final String assistantSid, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("unique_name") - final String uniqueName, - - @JsonProperty("url") - final URI url + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("field_type") final String fieldType, + @JsonProperty("task_sid") final String taskSid, + @JsonProperty("assistant_sid") final String assistantSid, + @JsonProperty("sid") final String sid, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("url") final URI url ) { this.accountSid = accountSid; this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); @@ -145,37 +151,45 @@ private Field( this.url = url; } - public final String getAccountSid() { - return this.accountSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getFieldType() { - return this.fieldType; - } - public final String getTaskSid() { - return this.taskSid; - } - public final String getAssistantSid() { - return this.assistantSid; - } - public final String getSid() { - return this.sid; - } - public final String getUniqueName() { - return this.uniqueName; - } - public final URI getUrl() { - return this.url; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getFieldType() { + return this.fieldType; + } + + public final String getTaskSid() { + return this.taskSid; + } + + public final String getAssistantSid() { + return this.assistantSid; + } + + public final String getSid() { + return this.sid; + } + + public final String getUniqueName() { + return this.uniqueName; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -185,13 +199,31 @@ public boolean equals(final Object o) { Field other = (Field) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(fieldType, other.fieldType) && Objects.equals(taskSid, other.taskSid) && Objects.equals(assistantSid, other.assistantSid) && Objects.equals(sid, other.sid) && Objects.equals(uniqueName, other.uniqueName) && Objects.equals(url, other.url) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(fieldType, other.fieldType) && + Objects.equals(taskSid, other.taskSid) && + Objects.equals(assistantSid, other.assistantSid) && + Objects.equals(sid, other.sid) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, dateCreated, dateUpdated, fieldType, taskSid, assistantSid, sid, uniqueName, url); + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + fieldType, + taskSid, + assistantSid, + sid, + uniqueName, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/task/FieldCreator.java b/src/main/java/com/twilio/rest/preview/understand/assistant/task/FieldCreator.java index 444ba1d740..7ece99f714 100644 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/task/FieldCreator.java +++ b/src/main/java/com/twilio/rest/preview/understand/assistant/task/FieldCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.preview.understand.assistant.task; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,51 +25,67 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class FieldCreator extends Creator { - - -public class FieldCreator extends Creator{ private String pathAssistantSid; private String pathTaskSid; private String fieldType; private String uniqueName; - public FieldCreator(final String pathAssistantSid, final String pathTaskSid, final String fieldType, final String uniqueName) { + public FieldCreator( + final String pathAssistantSid, + final String pathTaskSid, + final String fieldType, + final String uniqueName + ) { this.pathAssistantSid = pathAssistantSid; this.pathTaskSid = pathTaskSid; this.fieldType = fieldType; this.uniqueName = uniqueName; } - public FieldCreator setFieldType(final String fieldType){ + public FieldCreator setFieldType(final String fieldType) { this.fieldType = fieldType; return this; } - public FieldCreator setUniqueName(final String uniqueName){ + + public FieldCreator setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } @Override - public Field create(final TwilioRestClient client){ - String path = "/understand/Assistants/{AssistantSid}/Tasks/{TaskSid}/Fields"; + public Field create(final TwilioRestClient client) { + String path = + "/understand/Assistants/{AssistantSid}/Tasks/{TaskSid}/Fields"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"TaskSid"+"}", this.pathTaskSid.toString()); - path = path.replace("{"+"FieldType"+"}", this.fieldType.toString()); - path = path.replace("{"+"UniqueName"+"}", this.uniqueName.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = path.replace("{" + "TaskSid" + "}", this.pathTaskSid.toString()); + path = path.replace("{" + "FieldType" + "}", this.fieldType.toString()); + path = + path.replace("{" + "UniqueName" + "}", this.uniqueName.toString()); Request request = new Request( HttpMethod.POST, Domains.PREVIEW.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Field creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Field creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -77,14 +94,13 @@ public Field create(final TwilioRestClient client){ return Field.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (fieldType != null) { request.addPostParam("FieldType", fieldType); - } if (uniqueName != null) { request.addPostParam("UniqueName", uniqueName); - } } } diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/task/FieldDeleter.java b/src/main/java/com/twilio/rest/preview/understand/assistant/task/FieldDeleter.java index a860a95814..826e23d302 100644 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/task/FieldDeleter.java +++ b/src/main/java/com/twilio/rest/preview/understand/assistant/task/FieldDeleter.java @@ -24,27 +24,34 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class FieldDeleter extends Deleter { + private String pathAssistantSid; private String pathTaskSid; private String pathSid; - public FieldDeleter(final String pathAssistantSid, final String pathTaskSid, final String pathSid){ + public FieldDeleter( + final String pathAssistantSid, + final String pathTaskSid, + final String pathSid + ) { this.pathAssistantSid = pathAssistantSid; this.pathTaskSid = pathTaskSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/understand/Assistants/{AssistantSid}/Tasks/{TaskSid}/Fields/{Sid}"; + String path = + "/understand/Assistants/{AssistantSid}/Tasks/{TaskSid}/Fields/{Sid}"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"TaskSid"+"}", this.pathTaskSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = path.replace("{" + "TaskSid" + "}", this.pathTaskSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -54,9 +61,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Field delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Field delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/task/FieldFetcher.java b/src/main/java/com/twilio/rest/preview/understand/assistant/task/FieldFetcher.java index 1808548fd5..70a6961933 100644 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/task/FieldFetcher.java +++ b/src/main/java/com/twilio/rest/preview/understand/assistant/task/FieldFetcher.java @@ -24,28 +24,34 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class FieldFetcher extends Fetcher { + private String pathAssistantSid; private String pathTaskSid; private String pathSid; - public FieldFetcher(final String pathAssistantSid, final String pathTaskSid, final String pathSid){ + public FieldFetcher( + final String pathAssistantSid, + final String pathTaskSid, + final String pathSid + ) { this.pathAssistantSid = pathAssistantSid; this.pathTaskSid = pathTaskSid; this.pathSid = pathSid; } - @Override public Field fetch(final TwilioRestClient client) { - String path = "/understand/Assistants/{AssistantSid}/Tasks/{TaskSid}/Fields/{Sid}"; + String path = + "/understand/Assistants/{AssistantSid}/Tasks/{TaskSid}/Fields/{Sid}"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"TaskSid"+"}", this.pathTaskSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = path.replace("{" + "TaskSid" + "}", this.pathTaskSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -55,9 +61,14 @@ public Field fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Field fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Field fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/task/FieldReader.java b/src/main/java/com/twilio/rest/preview/understand/assistant/task/FieldReader.java index f008044b0e..09e83f60ad 100644 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/task/FieldReader.java +++ b/src/main/java/com/twilio/rest/preview/understand/assistant/task/FieldReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.preview.understand.assistant.task; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,21 +25,22 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class FieldReader extends Reader { + private String pathAssistantSid; private String pathTaskSid; private Integer pageSize; - public FieldReader(final String pathAssistantSid, final String pathTaskSid){ + public FieldReader( + final String pathAssistantSid, + final String pathTaskSid + ) { this.pathAssistantSid = pathAssistantSid; this.pathTaskSid = pathTaskSid; } - public FieldReader setPageSize(final Integer pageSize){ + public FieldReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -49,9 +51,14 @@ public ResourceSet read(final TwilioRestClient client) { } public Page firstPage(final TwilioRestClient client) { - String path = "/understand/Assistants/{AssistantSid}/Tasks/{TaskSid}/Fields"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"TaskSid"+"}", this.pathTaskSid.toString()); + String path = + "/understand/Assistants/{AssistantSid}/Tasks/{TaskSid}/Fields"; + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = path.replace("{" + "TaskSid" + "}", this.pathTaskSid.toString()); Request request = new Request( HttpMethod.GET, @@ -63,13 +70,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Field read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Field read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -85,7 +100,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.PREVIEW.toString()) @@ -93,9 +111,11 @@ public Page previousPage(final Page page, final TwilioRestClient c return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.PREVIEW.toString()) @@ -104,21 +124,21 @@ public Page nextPage(final Page page, final TwilioRestClient clien } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/task/Sample.java b/src/main/java/com/twilio/rest/preview/understand/assistant/task/Sample.java index 7b3ac592bc..c249018843 100644 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/task/Sample.java +++ b/src/main/java/com/twilio/rest/preview/understand/assistant/task/Sample.java @@ -23,53 +23,77 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Sample extends Resource { + private static final long serialVersionUID = 197447215274163L; - public static SampleCreator creator(final String pathAssistantSid, final String pathTaskSid, final String language, final String taggedText){ - return new SampleCreator(pathAssistantSid, pathTaskSid, language, taggedText); + public static SampleCreator creator( + final String pathAssistantSid, + final String pathTaskSid, + final String language, + final String taggedText + ) { + return new SampleCreator( + pathAssistantSid, + pathTaskSid, + language, + taggedText + ); } - public static SampleDeleter deleter(final String pathAssistantSid, final String pathTaskSid, final String pathSid){ + public static SampleDeleter deleter( + final String pathAssistantSid, + final String pathTaskSid, + final String pathSid + ) { return new SampleDeleter(pathAssistantSid, pathTaskSid, pathSid); } - public static SampleFetcher fetcher(final String pathAssistantSid, final String pathTaskSid, final String pathSid){ + public static SampleFetcher fetcher( + final String pathAssistantSid, + final String pathTaskSid, + final String pathSid + ) { return new SampleFetcher(pathAssistantSid, pathTaskSid, pathSid); } - public static SampleReader reader(final String pathAssistantSid, final String pathTaskSid){ + public static SampleReader reader( + final String pathAssistantSid, + final String pathTaskSid + ) { return new SampleReader(pathAssistantSid, pathTaskSid); } - public static SampleUpdater updater(final String pathAssistantSid, final String pathTaskSid, final String pathSid){ + public static SampleUpdater updater( + final String pathAssistantSid, + final String pathTaskSid, + final String pathSid + ) { return new SampleUpdater(pathAssistantSid, pathTaskSid, pathSid); } /** - * Converts a JSON String into a Sample object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Sample object represented by the provided JSON - */ - public static Sample fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Sample object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Sample object represented by the provided JSON + */ + public static Sample fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Sample.class); @@ -81,14 +105,17 @@ public static Sample fromJson(final String json, final ObjectMapper objectMapper } /** - * Converts a JSON InputStream into a Sample object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Sample object represented by the provided JSON - */ - public static Sample fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Sample object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Sample object represented by the provided JSON + */ + public static Sample fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Sample.class); @@ -112,35 +139,16 @@ public static Sample fromJson(final InputStream json, final ObjectMapper objectM @JsonCreator private Sample( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("task_sid") - final String taskSid, - - @JsonProperty("language") - final String language, - - @JsonProperty("assistant_sid") - final String assistantSid, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("tagged_text") - final String taggedText, - - @JsonProperty("url") - final URI url, - - @JsonProperty("source_channel") - final String sourceChannel + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("task_sid") final String taskSid, + @JsonProperty("language") final String language, + @JsonProperty("assistant_sid") final String assistantSid, + @JsonProperty("sid") final String sid, + @JsonProperty("tagged_text") final String taggedText, + @JsonProperty("url") final URI url, + @JsonProperty("source_channel") final String sourceChannel ) { this.accountSid = accountSid; this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); @@ -154,40 +162,49 @@ private Sample( this.sourceChannel = sourceChannel; } - public final String getAccountSid() { - return this.accountSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getTaskSid() { - return this.taskSid; - } - public final String getLanguage() { - return this.language; - } - public final String getAssistantSid() { - return this.assistantSid; - } - public final String getSid() { - return this.sid; - } - public final String getTaggedText() { - return this.taggedText; - } - public final URI getUrl() { - return this.url; - } - public final String getSourceChannel() { - return this.sourceChannel; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getTaskSid() { + return this.taskSid; + } + + public final String getLanguage() { + return this.language; + } + + public final String getAssistantSid() { + return this.assistantSid; + } + + public final String getSid() { + return this.sid; + } + + public final String getTaggedText() { + return this.taggedText; + } + + public final URI getUrl() { + return this.url; + } + + public final String getSourceChannel() { + return this.sourceChannel; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -197,13 +214,33 @@ public boolean equals(final Object o) { Sample other = (Sample) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(taskSid, other.taskSid) && Objects.equals(language, other.language) && Objects.equals(assistantSid, other.assistantSid) && Objects.equals(sid, other.sid) && Objects.equals(taggedText, other.taggedText) && Objects.equals(url, other.url) && Objects.equals(sourceChannel, other.sourceChannel) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(taskSid, other.taskSid) && + Objects.equals(language, other.language) && + Objects.equals(assistantSid, other.assistantSid) && + Objects.equals(sid, other.sid) && + Objects.equals(taggedText, other.taggedText) && + Objects.equals(url, other.url) && + Objects.equals(sourceChannel, other.sourceChannel) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, dateCreated, dateUpdated, taskSid, language, assistantSid, sid, taggedText, url, sourceChannel); + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + taskSid, + language, + assistantSid, + sid, + taggedText, + url, + sourceChannel + ); } - } - diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/task/SampleCreator.java b/src/main/java/com/twilio/rest/preview/understand/assistant/task/SampleCreator.java index 7e73ffb596..d684c970e8 100644 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/task/SampleCreator.java +++ b/src/main/java/com/twilio/rest/preview/understand/assistant/task/SampleCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.preview.understand.assistant.task; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,56 +25,73 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class SampleCreator extends Creator { - - -public class SampleCreator extends Creator{ private String pathAssistantSid; private String pathTaskSid; private String language; private String taggedText; private String sourceChannel; - public SampleCreator(final String pathAssistantSid, final String pathTaskSid, final String language, final String taggedText) { + public SampleCreator( + final String pathAssistantSid, + final String pathTaskSid, + final String language, + final String taggedText + ) { this.pathAssistantSid = pathAssistantSid; this.pathTaskSid = pathTaskSid; this.language = language; this.taggedText = taggedText; } - public SampleCreator setLanguage(final String language){ + public SampleCreator setLanguage(final String language) { this.language = language; return this; } - public SampleCreator setTaggedText(final String taggedText){ + + public SampleCreator setTaggedText(final String taggedText) { this.taggedText = taggedText; return this; } - public SampleCreator setSourceChannel(final String sourceChannel){ + + public SampleCreator setSourceChannel(final String sourceChannel) { this.sourceChannel = sourceChannel; return this; } @Override - public Sample create(final TwilioRestClient client){ - String path = "/understand/Assistants/{AssistantSid}/Tasks/{TaskSid}/Samples"; + public Sample create(final TwilioRestClient client) { + String path = + "/understand/Assistants/{AssistantSid}/Tasks/{TaskSid}/Samples"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"TaskSid"+"}", this.pathTaskSid.toString()); - path = path.replace("{"+"Language"+"}", this.language.toString()); - path = path.replace("{"+"TaggedText"+"}", this.taggedText.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = path.replace("{" + "TaskSid" + "}", this.pathTaskSid.toString()); + path = path.replace("{" + "Language" + "}", this.language.toString()); + path = + path.replace("{" + "TaggedText" + "}", this.taggedText.toString()); Request request = new Request( HttpMethod.POST, Domains.PREVIEW.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Sample creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Sample creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,18 +100,16 @@ public Sample create(final TwilioRestClient client){ return Sample.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (language != null) { request.addPostParam("Language", language); - } if (taggedText != null) { request.addPostParam("TaggedText", taggedText); - } if (sourceChannel != null) { request.addPostParam("SourceChannel", sourceChannel); - } } } diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/task/SampleDeleter.java b/src/main/java/com/twilio/rest/preview/understand/assistant/task/SampleDeleter.java index 6c27aa7ecb..011b8a7573 100644 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/task/SampleDeleter.java +++ b/src/main/java/com/twilio/rest/preview/understand/assistant/task/SampleDeleter.java @@ -24,27 +24,34 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class SampleDeleter extends Deleter { + private String pathAssistantSid; private String pathTaskSid; private String pathSid; - public SampleDeleter(final String pathAssistantSid, final String pathTaskSid, final String pathSid){ + public SampleDeleter( + final String pathAssistantSid, + final String pathTaskSid, + final String pathSid + ) { this.pathAssistantSid = pathAssistantSid; this.pathTaskSid = pathTaskSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/understand/Assistants/{AssistantSid}/Tasks/{TaskSid}/Samples/{Sid}"; + String path = + "/understand/Assistants/{AssistantSid}/Tasks/{TaskSid}/Samples/{Sid}"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"TaskSid"+"}", this.pathTaskSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = path.replace("{" + "TaskSid" + "}", this.pathTaskSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -54,9 +61,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Sample delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Sample delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/task/SampleFetcher.java b/src/main/java/com/twilio/rest/preview/understand/assistant/task/SampleFetcher.java index 64ae339ef0..3c1846847e 100644 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/task/SampleFetcher.java +++ b/src/main/java/com/twilio/rest/preview/understand/assistant/task/SampleFetcher.java @@ -24,28 +24,34 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class SampleFetcher extends Fetcher { + private String pathAssistantSid; private String pathTaskSid; private String pathSid; - public SampleFetcher(final String pathAssistantSid, final String pathTaskSid, final String pathSid){ + public SampleFetcher( + final String pathAssistantSid, + final String pathTaskSid, + final String pathSid + ) { this.pathAssistantSid = pathAssistantSid; this.pathTaskSid = pathTaskSid; this.pathSid = pathSid; } - @Override public Sample fetch(final TwilioRestClient client) { - String path = "/understand/Assistants/{AssistantSid}/Tasks/{TaskSid}/Samples/{Sid}"; + String path = + "/understand/Assistants/{AssistantSid}/Tasks/{TaskSid}/Samples/{Sid}"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"TaskSid"+"}", this.pathTaskSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = path.replace("{" + "TaskSid" + "}", this.pathTaskSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -55,9 +61,14 @@ public Sample fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Sample fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Sample fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/task/SampleReader.java b/src/main/java/com/twilio/rest/preview/understand/assistant/task/SampleReader.java index 9b3084c848..6478bfd09d 100644 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/task/SampleReader.java +++ b/src/main/java/com/twilio/rest/preview/understand/assistant/task/SampleReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.preview.understand.assistant.task; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,26 +25,28 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class SampleReader extends Reader { + private String pathAssistantSid; private String pathTaskSid; private String language; private Integer pageSize; - public SampleReader(final String pathAssistantSid, final String pathTaskSid){ + public SampleReader( + final String pathAssistantSid, + final String pathTaskSid + ) { this.pathAssistantSid = pathAssistantSid; this.pathTaskSid = pathTaskSid; } - public SampleReader setLanguage(final String language){ + public SampleReader setLanguage(final String language) { this.language = language; return this; } - public SampleReader setPageSize(final Integer pageSize){ + + public SampleReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -54,9 +57,14 @@ public ResourceSet read(final TwilioRestClient client) { } public Page firstPage(final TwilioRestClient client) { - String path = "/understand/Assistants/{AssistantSid}/Tasks/{TaskSid}/Samples"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"TaskSid"+"}", this.pathTaskSid.toString()); + String path = + "/understand/Assistants/{AssistantSid}/Tasks/{TaskSid}/Samples"; + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = path.replace("{" + "TaskSid" + "}", this.pathTaskSid.toString()); Request request = new Request( HttpMethod.GET, @@ -68,13 +76,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Sample read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Sample read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -90,7 +106,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.PREVIEW.toString()) @@ -98,9 +117,11 @@ public Page previousPage(final Page page, final TwilioRestClient return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.PREVIEW.toString()) @@ -109,25 +130,24 @@ public Page nextPage(final Page page, final TwilioRestClient cli } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (language != null) { - request.addQueryParam("Language", language); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/task/SampleUpdater.java b/src/main/java/com/twilio/rest/preview/understand/assistant/task/SampleUpdater.java index 7183af1eda..404129fc3b 100644 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/task/SampleUpdater.java +++ b/src/main/java/com/twilio/rest/preview/understand/assistant/task/SampleUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.preview.understand.assistant.task; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class SampleUpdater extends Updater { - - -public class SampleUpdater extends Updater{ private String pathAssistantSid; private String pathTaskSid; private String pathSid; @@ -35,44 +34,61 @@ public class SampleUpdater extends Updater{ private String taggedText; private String sourceChannel; - public SampleUpdater(final String pathAssistantSid, final String pathTaskSid, final String pathSid){ + public SampleUpdater( + final String pathAssistantSid, + final String pathTaskSid, + final String pathSid + ) { this.pathAssistantSid = pathAssistantSid; this.pathTaskSid = pathTaskSid; this.pathSid = pathSid; } - public SampleUpdater setLanguage(final String language){ + public SampleUpdater setLanguage(final String language) { this.language = language; return this; } - public SampleUpdater setTaggedText(final String taggedText){ + + public SampleUpdater setTaggedText(final String taggedText) { this.taggedText = taggedText; return this; } - public SampleUpdater setSourceChannel(final String sourceChannel){ + + public SampleUpdater setSourceChannel(final String sourceChannel) { this.sourceChannel = sourceChannel; return this; } @Override - public Sample update(final TwilioRestClient client){ - String path = "/understand/Assistants/{AssistantSid}/Tasks/{TaskSid}/Samples/{Sid}"; + public Sample update(final TwilioRestClient client) { + String path = + "/understand/Assistants/{AssistantSid}/Tasks/{TaskSid}/Samples/{Sid}"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"TaskSid"+"}", this.pathTaskSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = path.replace("{" + "TaskSid" + "}", this.pathTaskSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.PREVIEW.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Sample update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Sample update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -81,18 +97,16 @@ public Sample update(final TwilioRestClient client){ return Sample.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (language != null) { request.addPostParam("Language", language); - } if (taggedText != null) { request.addPostParam("TaggedText", taggedText); - } if (sourceChannel != null) { request.addPostParam("SourceChannel", sourceChannel); - } } } diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/task/TaskActions.java b/src/main/java/com/twilio/rest/preview/understand/assistant/task/TaskActions.java index 94dc4ff4f3..55ba162c50 100644 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/task/TaskActions.java +++ b/src/main/java/com/twilio/rest/preview/understand/assistant/task/TaskActions.java @@ -22,42 +22,47 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class TaskActions extends Resource { + private static final long serialVersionUID = 36530790788418L; - public static TaskActionsFetcher fetcher(final String pathAssistantSid, final String pathTaskSid){ + public static TaskActionsFetcher fetcher( + final String pathAssistantSid, + final String pathTaskSid + ) { return new TaskActionsFetcher(pathAssistantSid, pathTaskSid); } - public static TaskActionsUpdater updater(final String pathAssistantSid, final String pathTaskSid){ + public static TaskActionsUpdater updater( + final String pathAssistantSid, + final String pathTaskSid + ) { return new TaskActionsUpdater(pathAssistantSid, pathTaskSid); } /** - * Converts a JSON String into a TaskActions object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return TaskActions object represented by the provided JSON - */ - public static TaskActions fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a TaskActions object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return TaskActions object represented by the provided JSON + */ + public static TaskActions fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, TaskActions.class); @@ -69,14 +74,17 @@ public static TaskActions fromJson(final String json, final ObjectMapper objectM } /** - * Converts a JSON InputStream into a TaskActions object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return TaskActions object represented by the provided JSON - */ - public static TaskActions fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a TaskActions object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return TaskActions object represented by the provided JSON + */ + public static TaskActions fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, TaskActions.class); @@ -95,20 +103,11 @@ public static TaskActions fromJson(final InputStream json, final ObjectMapper ob @JsonCreator private TaskActions( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("assistant_sid") - final String assistantSid, - - @JsonProperty("task_sid") - final String taskSid, - - @JsonProperty("url") - final URI url, - - @JsonProperty("data") - final Map data + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("assistant_sid") final String assistantSid, + @JsonProperty("task_sid") final String taskSid, + @JsonProperty("url") final URI url, + @JsonProperty("data") final Map data ) { this.accountSid = accountSid; this.assistantSid = assistantSid; @@ -117,25 +116,29 @@ private TaskActions( this.data = data; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getAssistantSid() { - return this.assistantSid; - } - public final String getTaskSid() { - return this.taskSid; - } - public final URI getUrl() { - return this.url; - } - public final Map getData() { - return this.data; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getAssistantSid() { + return this.assistantSid; + } + + public final String getTaskSid() { + return this.taskSid; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getData() { + return this.data; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -145,13 +148,17 @@ public boolean equals(final Object o) { TaskActions other = (TaskActions) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(assistantSid, other.assistantSid) && Objects.equals(taskSid, other.taskSid) && Objects.equals(url, other.url) && Objects.equals(data, other.data) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(assistantSid, other.assistantSid) && + Objects.equals(taskSid, other.taskSid) && + Objects.equals(url, other.url) && + Objects.equals(data, other.data) + ); } @Override public int hashCode() { return Objects.hash(accountSid, assistantSid, taskSid, url, data); } - } - diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/task/TaskActionsFetcher.java b/src/main/java/com/twilio/rest/preview/understand/assistant/task/TaskActionsFetcher.java index 5b3ce511cb..bcdf6ad91e 100644 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/task/TaskActionsFetcher.java +++ b/src/main/java/com/twilio/rest/preview/understand/assistant/task/TaskActionsFetcher.java @@ -24,25 +24,30 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class TaskActionsFetcher extends Fetcher { + private String pathAssistantSid; private String pathTaskSid; - public TaskActionsFetcher(final String pathAssistantSid, final String pathTaskSid){ + public TaskActionsFetcher( + final String pathAssistantSid, + final String pathTaskSid + ) { this.pathAssistantSid = pathAssistantSid; this.pathTaskSid = pathTaskSid; } - @Override public TaskActions fetch(final TwilioRestClient client) { - String path = "/understand/Assistants/{AssistantSid}/Tasks/{TaskSid}/Actions"; + String path = + "/understand/Assistants/{AssistantSid}/Tasks/{TaskSid}/Actions"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"TaskSid"+"}", this.pathTaskSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = path.replace("{" + "TaskSid" + "}", this.pathTaskSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,15 +57,23 @@ public TaskActions fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("TaskActions fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "TaskActions fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return TaskActions.fromJson(response.getStream(), client.getObjectMapper()); + return TaskActions.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/task/TaskActionsUpdater.java b/src/main/java/com/twilio/rest/preview/understand/assistant/task/TaskActionsUpdater.java index b198c4fabd..9fa6ad94b2 100644 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/task/TaskActionsUpdater.java +++ b/src/main/java/com/twilio/rest/preview/understand/assistant/task/TaskActionsUpdater.java @@ -15,8 +15,9 @@ package com.twilio.rest.preview.understand.assistant.task; import com.twilio.base.Updater; -import com.twilio.exception.ApiConnectionException; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Converter; +import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; @@ -24,56 +25,71 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - import java.util.Map; +public class TaskActionsUpdater extends Updater { -public class TaskActionsUpdater extends Updater{ private String pathAssistantSid; private String pathTaskSid; private Map actions; - public TaskActionsUpdater(final String pathAssistantSid, final String pathTaskSid){ + public TaskActionsUpdater( + final String pathAssistantSid, + final String pathTaskSid + ) { this.pathAssistantSid = pathAssistantSid; this.pathTaskSid = pathTaskSid; } - public TaskActionsUpdater setActions(final Map actions){ + public TaskActionsUpdater setActions(final Map actions) { this.actions = actions; return this; } @Override - public TaskActions update(final TwilioRestClient client){ - String path = "/understand/Assistants/{AssistantSid}/Tasks/{TaskSid}/Actions"; + public TaskActions update(final TwilioRestClient client) { + String path = + "/understand/Assistants/{AssistantSid}/Tasks/{TaskSid}/Actions"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"TaskSid"+"}", this.pathTaskSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = path.replace("{" + "TaskSid" + "}", this.pathTaskSid.toString()); Request request = new Request( HttpMethod.POST, Domains.PREVIEW.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("TaskActions update failed: Unable to connect to server"); + throw new ApiConnectionException( + "TaskActions update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return TaskActions.fromJson(response.getStream(), client.getObjectMapper()); + return TaskActions.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (actions != null) { - request.addPostParam("Actions", Converter.mapToJson(actions)); - + request.addPostParam("Actions", Converter.mapToJson(actions)); } } } diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/task/TaskStatistics.java b/src/main/java/com/twilio/rest/preview/understand/assistant/task/TaskStatistics.java index a324117f0f..5df490f2db 100644 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/task/TaskStatistics.java +++ b/src/main/java/com/twilio/rest/preview/understand/assistant/task/TaskStatistics.java @@ -22,36 +22,38 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class TaskStatistics extends Resource { + private static final long serialVersionUID = 99044881135361L; - public static TaskStatisticsFetcher fetcher(final String pathAssistantSid, final String pathTaskSid){ + public static TaskStatisticsFetcher fetcher( + final String pathAssistantSid, + final String pathTaskSid + ) { return new TaskStatisticsFetcher(pathAssistantSid, pathTaskSid); } /** - * Converts a JSON String into a TaskStatistics object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return TaskStatistics object represented by the provided JSON - */ - public static TaskStatistics fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a TaskStatistics object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return TaskStatistics object represented by the provided JSON + */ + public static TaskStatistics fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, TaskStatistics.class); @@ -63,14 +65,17 @@ public static TaskStatistics fromJson(final String json, final ObjectMapper obje } /** - * Converts a JSON InputStream into a TaskStatistics object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return TaskStatistics object represented by the provided JSON - */ - public static TaskStatistics fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a TaskStatistics object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return TaskStatistics object represented by the provided JSON + */ + public static TaskStatistics fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, TaskStatistics.class); @@ -90,23 +95,12 @@ public static TaskStatistics fromJson(final InputStream json, final ObjectMapper @JsonCreator private TaskStatistics( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("assistant_sid") - final String assistantSid, - - @JsonProperty("task_sid") - final String taskSid, - - @JsonProperty("samples_count") - final Integer samplesCount, - - @JsonProperty("fields_count") - final Integer fieldsCount, - - @JsonProperty("url") - final URI url + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("assistant_sid") final String assistantSid, + @JsonProperty("task_sid") final String taskSid, + @JsonProperty("samples_count") final Integer samplesCount, + @JsonProperty("fields_count") final Integer fieldsCount, + @JsonProperty("url") final URI url ) { this.accountSid = accountSid; this.assistantSid = assistantSid; @@ -116,28 +110,33 @@ private TaskStatistics( this.url = url; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getAssistantSid() { - return this.assistantSid; - } - public final String getTaskSid() { - return this.taskSid; - } - public final Integer getSamplesCount() { - return this.samplesCount; - } - public final Integer getFieldsCount() { - return this.fieldsCount; - } - public final URI getUrl() { - return this.url; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getAssistantSid() { + return this.assistantSid; + } + + public final String getTaskSid() { + return this.taskSid; + } + + public final Integer getSamplesCount() { + return this.samplesCount; + } + + public final Integer getFieldsCount() { + return this.fieldsCount; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -147,13 +146,25 @@ public boolean equals(final Object o) { TaskStatistics other = (TaskStatistics) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(assistantSid, other.assistantSid) && Objects.equals(taskSid, other.taskSid) && Objects.equals(samplesCount, other.samplesCount) && Objects.equals(fieldsCount, other.fieldsCount) && Objects.equals(url, other.url) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(assistantSid, other.assistantSid) && + Objects.equals(taskSid, other.taskSid) && + Objects.equals(samplesCount, other.samplesCount) && + Objects.equals(fieldsCount, other.fieldsCount) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, assistantSid, taskSid, samplesCount, fieldsCount, url); + return Objects.hash( + accountSid, + assistantSid, + taskSid, + samplesCount, + fieldsCount, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/task/TaskStatisticsFetcher.java b/src/main/java/com/twilio/rest/preview/understand/assistant/task/TaskStatisticsFetcher.java index 0dc57bb41c..2c6de265e2 100644 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/task/TaskStatisticsFetcher.java +++ b/src/main/java/com/twilio/rest/preview/understand/assistant/task/TaskStatisticsFetcher.java @@ -24,25 +24,30 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class TaskStatisticsFetcher extends Fetcher { + private String pathAssistantSid; private String pathTaskSid; - public TaskStatisticsFetcher(final String pathAssistantSid, final String pathTaskSid){ + public TaskStatisticsFetcher( + final String pathAssistantSid, + final String pathTaskSid + ) { this.pathAssistantSid = pathAssistantSid; this.pathTaskSid = pathTaskSid; } - @Override public TaskStatistics fetch(final TwilioRestClient client) { - String path = "/understand/Assistants/{AssistantSid}/Tasks/{TaskSid}/Statistics"; + String path = + "/understand/Assistants/{AssistantSid}/Tasks/{TaskSid}/Statistics"; - path = path.replace("{"+"AssistantSid"+"}", this.pathAssistantSid.toString()); - path = path.replace("{"+"TaskSid"+"}", this.pathTaskSid.toString()); + path = + path.replace( + "{" + "AssistantSid" + "}", + this.pathAssistantSid.toString() + ); + path = path.replace("{" + "TaskSid" + "}", this.pathTaskSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,15 +57,23 @@ public TaskStatistics fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("TaskStatistics fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "TaskStatistics fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return TaskStatistics.fromJson(response.getStream(), client.getObjectMapper()); + return TaskStatistics.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/preview/wireless/Command.java b/src/main/java/com/twilio/rest/preview/wireless/Command.java index bf739e8aa1..a51ef30e47 100644 --- a/src/main/java/com/twilio/rest/preview/wireless/Command.java +++ b/src/main/java/com/twilio/rest/preview/wireless/Command.java @@ -23,45 +23,44 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Command extends Resource { + private static final long serialVersionUID = 211711437701945L; - public static CommandCreator creator(final String command){ + public static CommandCreator creator(final String command) { return new CommandCreator(command); } - public static CommandFetcher fetcher(final String pathSid){ + public static CommandFetcher fetcher(final String pathSid) { return new CommandFetcher(pathSid); } - public static CommandReader reader(){ + public static CommandReader reader() { return new CommandReader(); } /** - * Converts a JSON String into a Command object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Command object represented by the provided JSON - */ - public static Command fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Command object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Command object represented by the provided JSON + */ + public static Command fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Command.class); @@ -73,14 +72,17 @@ public static Command fromJson(final String json, final ObjectMapper objectMappe } /** - * Converts a JSON InputStream into a Command object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Command object represented by the provided JSON - */ - public static Command fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Command object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Command object represented by the provided JSON + */ + public static Command fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Command.class); @@ -105,38 +107,17 @@ public static Command fromJson(final InputStream json, final ObjectMapper object @JsonCreator private Command( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("device_sid") - final String deviceSid, - - @JsonProperty("sim_sid") - final String simSid, - - @JsonProperty("command") - final String command, - - @JsonProperty("command_mode") - final String commandMode, - - @JsonProperty("status") - final String status, - - @JsonProperty("direction") - final String direction, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("device_sid") final String deviceSid, + @JsonProperty("sim_sid") final String simSid, + @JsonProperty("command") final String command, + @JsonProperty("command_mode") final String commandMode, + @JsonProperty("status") final String status, + @JsonProperty("direction") final String direction, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url ) { this.sid = sid; this.accountSid = accountSid; @@ -151,43 +132,53 @@ private Command( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getDeviceSid() { - return this.deviceSid; - } - public final String getSimSid() { - return this.simSid; - } - public final String getCommand() { - return this.command; - } - public final String getCommandMode() { - return this.commandMode; - } - public final String getStatus() { - return this.status; - } - public final String getDirection() { - return this.direction; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getDeviceSid() { + return this.deviceSid; + } + + public final String getSimSid() { + return this.simSid; + } + + public final String getCommand() { + return this.command; + } + + public final String getCommandMode() { + return this.commandMode; + } + + public final String getStatus() { + return this.status; + } + + public final String getDirection() { + return this.direction; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -197,13 +188,35 @@ public boolean equals(final Object o) { Command other = (Command) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(deviceSid, other.deviceSid) && Objects.equals(simSid, other.simSid) && Objects.equals(command, other.command) && Objects.equals(commandMode, other.commandMode) && Objects.equals(status, other.status) && Objects.equals(direction, other.direction) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(deviceSid, other.deviceSid) && + Objects.equals(simSid, other.simSid) && + Objects.equals(command, other.command) && + Objects.equals(commandMode, other.commandMode) && + Objects.equals(status, other.status) && + Objects.equals(direction, other.direction) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, deviceSid, simSid, command, commandMode, status, direction, dateCreated, dateUpdated, url); + return Objects.hash( + sid, + accountSid, + deviceSid, + simSid, + command, + commandMode, + status, + direction, + dateCreated, + dateUpdated, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/preview/wireless/CommandCreator.java b/src/main/java/com/twilio/rest/preview/wireless/CommandCreator.java index 6a3bc96279..b5a8aaec67 100644 --- a/src/main/java/com/twilio/rest/preview/wireless/CommandCreator.java +++ b/src/main/java/com/twilio/rest/preview/wireless/CommandCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.preview.wireless; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -25,12 +26,10 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.net.URI; - - - import java.net.URI; -public class CommandCreator extends Creator{ +public class CommandCreator extends Creator { + private String command; private String device; private String sim; @@ -43,56 +42,68 @@ public CommandCreator(final String command) { this.command = command; } - public CommandCreator setCommand(final String command){ + public CommandCreator setCommand(final String command) { this.command = command; return this; } - public CommandCreator setDevice(final String device){ + + public CommandCreator setDevice(final String device) { this.device = device; return this; } - public CommandCreator setSim(final String sim){ + + public CommandCreator setSim(final String sim) { this.sim = sim; return this; } - public CommandCreator setCallbackMethod(final String callbackMethod){ + + public CommandCreator setCallbackMethod(final String callbackMethod) { this.callbackMethod = callbackMethod; return this; } - public CommandCreator setCallbackUrl(final URI callbackUrl){ + + public CommandCreator setCallbackUrl(final URI callbackUrl) { this.callbackUrl = callbackUrl; return this; } - public CommandCreator setCallbackUrl(final String callbackUrl){ + public CommandCreator setCallbackUrl(final String callbackUrl) { return setCallbackUrl(Promoter.uriFromString(callbackUrl)); } - public CommandCreator setCommandMode(final String commandMode){ + + public CommandCreator setCommandMode(final String commandMode) { this.commandMode = commandMode; return this; } - public CommandCreator setIncludeSid(final String includeSid){ + + public CommandCreator setIncludeSid(final String includeSid) { this.includeSid = includeSid; return this; } @Override - public Command create(final TwilioRestClient client){ + public Command create(final TwilioRestClient client) { String path = "/wireless/Commands"; - path = path.replace("{"+"Command"+"}", this.command.toString()); + path = path.replace("{" + "Command" + "}", this.command.toString()); Request request = new Request( HttpMethod.POST, Domains.PREVIEW.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Command creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Command creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -101,34 +112,28 @@ public Command create(final TwilioRestClient client){ return Command.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (command != null) { request.addPostParam("Command", command); - } if (device != null) { request.addPostParam("Device", device); - } if (sim != null) { request.addPostParam("Sim", sim); - } if (callbackMethod != null) { request.addPostParam("CallbackMethod", callbackMethod); - } if (callbackUrl != null) { request.addPostParam("CallbackUrl", callbackUrl.toString()); - } if (commandMode != null) { request.addPostParam("CommandMode", commandMode); - } if (includeSid != null) { request.addPostParam("IncludeSid", includeSid); - } } } diff --git a/src/main/java/com/twilio/rest/preview/wireless/CommandFetcher.java b/src/main/java/com/twilio/rest/preview/wireless/CommandFetcher.java index 502093c7f5..606e62308c 100644 --- a/src/main/java/com/twilio/rest/preview/wireless/CommandFetcher.java +++ b/src/main/java/com/twilio/rest/preview/wireless/CommandFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class CommandFetcher extends Fetcher { + private String pathSid; - public CommandFetcher(final String pathSid){ + public CommandFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public Command fetch(final TwilioRestClient client) { String path = "/wireless/Commands/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,9 +46,14 @@ public Command fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Command fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Command fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/preview/wireless/CommandReader.java b/src/main/java/com/twilio/rest/preview/wireless/CommandReader.java index e87122c43b..32d09c67fc 100644 --- a/src/main/java/com/twilio/rest/preview/wireless/CommandReader.java +++ b/src/main/java/com/twilio/rest/preview/wireless/CommandReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.preview.wireless; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,37 +25,38 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class CommandReader extends Reader { + private String device; private String sim; private String status; private String direction; private Integer pageSize; - public CommandReader(){ - } + public CommandReader() {} - public CommandReader setDevice(final String device){ + public CommandReader setDevice(final String device) { this.device = device; return this; } - public CommandReader setSim(final String sim){ + + public CommandReader setSim(final String sim) { this.sim = sim; return this; } - public CommandReader setStatus(final String status){ + + public CommandReader setStatus(final String status) { this.status = status; return this; } - public CommandReader setDirection(final String direction){ + + public CommandReader setDirection(final String direction) { this.direction = direction; return this; } - public CommandReader setPageSize(final Integer pageSize){ + + public CommandReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -77,13 +79,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Command read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Command read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -99,7 +109,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reques } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.PREVIEW.toString()) @@ -107,9 +120,11 @@ public Page previousPage(final Page page, final TwilioRestClie return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.PREVIEW.toString()) @@ -118,37 +133,33 @@ public Page nextPage(final Page page, final TwilioRestClient c } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (device != null) { - request.addQueryParam("Device", device); } if (sim != null) { - request.addQueryParam("Sim", sim); } if (status != null) { - request.addQueryParam("Status", status); } if (direction != null) { - request.addQueryParam("Direction", direction); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/preview/wireless/RatePlan.java b/src/main/java/com/twilio/rest/preview/wireless/RatePlan.java index 041c5e5d4a..5b1af5993f 100644 --- a/src/main/java/com/twilio/rest/preview/wireless/RatePlan.java +++ b/src/main/java/com/twilio/rest/preview/wireless/RatePlan.java @@ -23,54 +23,53 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.List; import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class RatePlan extends Resource { + private static final long serialVersionUID = 138565285894419L; - public static RatePlanCreator creator(){ + public static RatePlanCreator creator() { return new RatePlanCreator(); } - public static RatePlanDeleter deleter(final String pathSid){ + public static RatePlanDeleter deleter(final String pathSid) { return new RatePlanDeleter(pathSid); } - public static RatePlanFetcher fetcher(final String pathSid){ + public static RatePlanFetcher fetcher(final String pathSid) { return new RatePlanFetcher(pathSid); } - public static RatePlanReader reader(){ + public static RatePlanReader reader() { return new RatePlanReader(); } - public static RatePlanUpdater updater(final String pathSid){ + public static RatePlanUpdater updater(final String pathSid) { return new RatePlanUpdater(pathSid); } /** - * Converts a JSON String into a RatePlan object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return RatePlan object represented by the provided JSON - */ - public static RatePlan fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a RatePlan object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return RatePlan object represented by the provided JSON + */ + public static RatePlan fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, RatePlan.class); @@ -82,14 +81,17 @@ public static RatePlan fromJson(final String json, final ObjectMapper objectMapp } /** - * Converts a JSON InputStream into a RatePlan object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return RatePlan object represented by the provided JSON - */ - public static RatePlan fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a RatePlan object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return RatePlan object represented by the provided JSON + */ + public static RatePlan fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, RatePlan.class); @@ -117,47 +119,24 @@ public static RatePlan fromJson(final InputStream json, final ObjectMapper objec @JsonCreator private RatePlan( - @JsonProperty("sid") - final String sid, - - @JsonProperty("unique_name") - final String uniqueName, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("data_enabled") - final Boolean dataEnabled, - - @JsonProperty("data_metering") - final String dataMetering, - - @JsonProperty("data_limit") - final Integer dataLimit, - - @JsonProperty("messaging_enabled") - final Boolean messagingEnabled, - - @JsonProperty("voice_enabled") - final Boolean voiceEnabled, - - @JsonProperty("national_roaming_enabled") - final Boolean nationalRoamingEnabled, - - @JsonProperty("international_roaming") - final List internationalRoaming, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("data_enabled") final Boolean dataEnabled, + @JsonProperty("data_metering") final String dataMetering, + @JsonProperty("data_limit") final Integer dataLimit, + @JsonProperty("messaging_enabled") final Boolean messagingEnabled, + @JsonProperty("voice_enabled") final Boolean voiceEnabled, + @JsonProperty( + "national_roaming_enabled" + ) final Boolean nationalRoamingEnabled, + @JsonProperty( + "international_roaming" + ) final List internationalRoaming, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url ) { this.sid = sid; this.uniqueName = uniqueName; @@ -175,52 +154,65 @@ private RatePlan( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getUniqueName() { - return this.uniqueName; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final Boolean getDataEnabled() { - return this.dataEnabled; - } - public final String getDataMetering() { - return this.dataMetering; - } - public final Integer getDataLimit() { - return this.dataLimit; - } - public final Boolean getMessagingEnabled() { - return this.messagingEnabled; - } - public final Boolean getVoiceEnabled() { - return this.voiceEnabled; - } - public final Boolean getNationalRoamingEnabled() { - return this.nationalRoamingEnabled; - } - public final List getInternationalRoaming() { - return this.internationalRoaming; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getUniqueName() { + return this.uniqueName; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final Boolean getDataEnabled() { + return this.dataEnabled; + } + + public final String getDataMetering() { + return this.dataMetering; + } + + public final Integer getDataLimit() { + return this.dataLimit; + } + + public final Boolean getMessagingEnabled() { + return this.messagingEnabled; + } + + public final Boolean getVoiceEnabled() { + return this.voiceEnabled; + } + + public final Boolean getNationalRoamingEnabled() { + return this.nationalRoamingEnabled; + } + + public final List getInternationalRoaming() { + return this.internationalRoaming; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -230,13 +222,44 @@ public boolean equals(final Object o) { RatePlan other = (RatePlan) o; - return Objects.equals(sid, other.sid) && Objects.equals(uniqueName, other.uniqueName) && Objects.equals(accountSid, other.accountSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(dataEnabled, other.dataEnabled) && Objects.equals(dataMetering, other.dataMetering) && Objects.equals(dataLimit, other.dataLimit) && Objects.equals(messagingEnabled, other.messagingEnabled) && Objects.equals(voiceEnabled, other.voiceEnabled) && Objects.equals(nationalRoamingEnabled, other.nationalRoamingEnabled) && Objects.equals(internationalRoaming, other.internationalRoaming) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(dataEnabled, other.dataEnabled) && + Objects.equals(dataMetering, other.dataMetering) && + Objects.equals(dataLimit, other.dataLimit) && + Objects.equals(messagingEnabled, other.messagingEnabled) && + Objects.equals(voiceEnabled, other.voiceEnabled) && + Objects.equals( + nationalRoamingEnabled, + other.nationalRoamingEnabled + ) && + Objects.equals(internationalRoaming, other.internationalRoaming) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, uniqueName, accountSid, friendlyName, dataEnabled, dataMetering, dataLimit, messagingEnabled, voiceEnabled, nationalRoamingEnabled, internationalRoaming, dateCreated, dateUpdated, url); + return Objects.hash( + sid, + uniqueName, + accountSid, + friendlyName, + dataEnabled, + dataMetering, + dataLimit, + messagingEnabled, + voiceEnabled, + nationalRoamingEnabled, + internationalRoaming, + dateCreated, + dateUpdated, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/preview/wireless/RatePlanCreator.java b/src/main/java/com/twilio/rest/preview/wireless/RatePlanCreator.java index 4223fb6f1e..83ba15e015 100644 --- a/src/main/java/com/twilio/rest/preview/wireless/RatePlanCreator.java +++ b/src/main/java/com/twilio/rest/preview/wireless/RatePlanCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.preview.wireless; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -25,12 +26,10 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.util.List; - import java.util.List; +public class RatePlanCreator extends Creator { - -public class RatePlanCreator extends Creator{ private String uniqueName; private String friendlyName; private Boolean dataEnabled; @@ -42,119 +41,141 @@ public class RatePlanCreator extends Creator{ private Boolean nationalRoamingEnabled; private List internationalRoaming; - public RatePlanCreator() { - } + public RatePlanCreator() {} - public RatePlanCreator setUniqueName(final String uniqueName){ + public RatePlanCreator setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - public RatePlanCreator setFriendlyName(final String friendlyName){ + + public RatePlanCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public RatePlanCreator setDataEnabled(final Boolean dataEnabled){ + + public RatePlanCreator setDataEnabled(final Boolean dataEnabled) { this.dataEnabled = dataEnabled; return this; } - public RatePlanCreator setDataLimit(final Integer dataLimit){ + + public RatePlanCreator setDataLimit(final Integer dataLimit) { this.dataLimit = dataLimit; return this; } - public RatePlanCreator setDataMetering(final String dataMetering){ + + public RatePlanCreator setDataMetering(final String dataMetering) { this.dataMetering = dataMetering; return this; } - public RatePlanCreator setMessagingEnabled(final Boolean messagingEnabled){ + + public RatePlanCreator setMessagingEnabled(final Boolean messagingEnabled) { this.messagingEnabled = messagingEnabled; return this; } - public RatePlanCreator setVoiceEnabled(final Boolean voiceEnabled){ + + public RatePlanCreator setVoiceEnabled(final Boolean voiceEnabled) { this.voiceEnabled = voiceEnabled; return this; } - public RatePlanCreator setCommandsEnabled(final Boolean commandsEnabled){ + + public RatePlanCreator setCommandsEnabled(final Boolean commandsEnabled) { this.commandsEnabled = commandsEnabled; return this; } - public RatePlanCreator setNationalRoamingEnabled(final Boolean nationalRoamingEnabled){ + + public RatePlanCreator setNationalRoamingEnabled( + final Boolean nationalRoamingEnabled + ) { this.nationalRoamingEnabled = nationalRoamingEnabled; return this; } - public RatePlanCreator setInternationalRoaming(final List internationalRoaming){ + + public RatePlanCreator setInternationalRoaming( + final List internationalRoaming + ) { this.internationalRoaming = internationalRoaming; return this; } - public RatePlanCreator setInternationalRoaming(final String internationalRoaming){ - return setInternationalRoaming(Promoter.listOfOne(internationalRoaming)); + + public RatePlanCreator setInternationalRoaming( + final String internationalRoaming + ) { + return setInternationalRoaming( + Promoter.listOfOne(internationalRoaming) + ); } @Override - public RatePlan create(final TwilioRestClient client){ + public RatePlan create(final TwilioRestClient client) { String path = "/wireless/RatePlans"; - Request request = new Request( HttpMethod.POST, Domains.PREVIEW.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("RatePlan creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "RatePlan creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return RatePlan.fromJson(response.getStream(), client.getObjectMapper()); + return RatePlan.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (uniqueName != null) { request.addPostParam("UniqueName", uniqueName); - } if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (dataEnabled != null) { request.addPostParam("DataEnabled", dataEnabled.toString()); - } if (dataLimit != null) { request.addPostParam("DataLimit", dataLimit.toString()); - } if (dataMetering != null) { request.addPostParam("DataMetering", dataMetering); - } if (messagingEnabled != null) { - request.addPostParam("MessagingEnabled", messagingEnabled.toString()); - + request.addPostParam( + "MessagingEnabled", + messagingEnabled.toString() + ); } if (voiceEnabled != null) { request.addPostParam("VoiceEnabled", voiceEnabled.toString()); - } if (commandsEnabled != null) { request.addPostParam("CommandsEnabled", commandsEnabled.toString()); - } if (nationalRoamingEnabled != null) { - request.addPostParam("NationalRoamingEnabled", nationalRoamingEnabled.toString()); - + request.addPostParam( + "NationalRoamingEnabled", + nationalRoamingEnabled.toString() + ); } if (internationalRoaming != null) { for (String prop : internationalRoaming) { request.addPostParam("InternationalRoaming", prop); } - } } } diff --git a/src/main/java/com/twilio/rest/preview/wireless/RatePlanDeleter.java b/src/main/java/com/twilio/rest/preview/wireless/RatePlanDeleter.java index e5ff2e3b1a..2b6c6c7327 100644 --- a/src/main/java/com/twilio/rest/preview/wireless/RatePlanDeleter.java +++ b/src/main/java/com/twilio/rest/preview/wireless/RatePlanDeleter.java @@ -24,21 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class RatePlanDeleter extends Deleter { + private String pathSid; - public RatePlanDeleter(final String pathSid){ + public RatePlanDeleter(final String pathSid) { this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/wireless/RatePlans/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -48,9 +46,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("RatePlan delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "RatePlan delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/preview/wireless/RatePlanFetcher.java b/src/main/java/com/twilio/rest/preview/wireless/RatePlanFetcher.java index 98aed613c7..4de1045747 100644 --- a/src/main/java/com/twilio/rest/preview/wireless/RatePlanFetcher.java +++ b/src/main/java/com/twilio/rest/preview/wireless/RatePlanFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class RatePlanFetcher extends Fetcher { + private String pathSid; - public RatePlanFetcher(final String pathSid){ + public RatePlanFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public RatePlan fetch(final TwilioRestClient client) { String path = "/wireless/RatePlans/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,15 +46,23 @@ public RatePlan fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("RatePlan fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "RatePlan fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return RatePlan.fromJson(response.getStream(), client.getObjectMapper()); + return RatePlan.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/preview/wireless/RatePlanReader.java b/src/main/java/com/twilio/rest/preview/wireless/RatePlanReader.java index aa4149f64c..fef16b059f 100644 --- a/src/main/java/com/twilio/rest/preview/wireless/RatePlanReader.java +++ b/src/main/java/com/twilio/rest/preview/wireless/RatePlanReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.preview.wireless; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,17 +25,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class RatePlanReader extends Reader { + private Integer pageSize; - public RatePlanReader(){ - } + public RatePlanReader() {} - public RatePlanReader setPageSize(final Integer pageSize){ + public RatePlanReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -57,13 +55,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("RatePlan read failed: Unable to connect to server"); + throw new ApiConnectionException( + "RatePlan read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -79,7 +85,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reque } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.PREVIEW.toString()) @@ -87,9 +96,11 @@ public Page previousPage(final Page page, final TwilioRestCl return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.PREVIEW.toString()) @@ -98,21 +109,21 @@ public Page nextPage(final Page page, final TwilioRestClient } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/preview/wireless/RatePlanUpdater.java b/src/main/java/com/twilio/rest/preview/wireless/RatePlanUpdater.java index fed6198c27..9ac79a365f 100644 --- a/src/main/java/com/twilio/rest/preview/wireless/RatePlanUpdater.java +++ b/src/main/java/com/twilio/rest/preview/wireless/RatePlanUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.preview.wireless; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,60 +25,67 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class RatePlanUpdater extends Updater { - - -public class RatePlanUpdater extends Updater{ private String pathSid; private String uniqueName; private String friendlyName; - public RatePlanUpdater(final String pathSid){ + public RatePlanUpdater(final String pathSid) { this.pathSid = pathSid; } - public RatePlanUpdater setUniqueName(final String uniqueName){ + public RatePlanUpdater setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - public RatePlanUpdater setFriendlyName(final String friendlyName){ + + public RatePlanUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } @Override - public RatePlan update(final TwilioRestClient client){ + public RatePlan update(final TwilioRestClient client) { String path = "/wireless/RatePlans/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.PREVIEW.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("RatePlan update failed: Unable to connect to server"); + throw new ApiConnectionException( + "RatePlan update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return RatePlan.fromJson(response.getStream(), client.getObjectMapper()); + return RatePlan.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (uniqueName != null) { request.addPostParam("UniqueName", uniqueName); - } if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } } } diff --git a/src/main/java/com/twilio/rest/preview/wireless/Sim.java b/src/main/java/com/twilio/rest/preview/wireless/Sim.java index 0efc0acd81..0a11ea0d21 100644 --- a/src/main/java/com/twilio/rest/preview/wireless/Sim.java +++ b/src/main/java/com/twilio/rest/preview/wireless/Sim.java @@ -23,48 +23,47 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; import com.twilio.http.HttpMethod; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Sim extends Resource { + private static final long serialVersionUID = 220976187959759L; - public static SimFetcher fetcher(final String pathSid){ + public static SimFetcher fetcher(final String pathSid) { return new SimFetcher(pathSid); } - public static SimReader reader(){ + public static SimReader reader() { return new SimReader(); } - public static SimUpdater updater(final String pathSid){ + public static SimUpdater updater(final String pathSid) { return new SimUpdater(pathSid); } /** - * Converts a JSON String into a Sim object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Sim object represented by the provided JSON - */ - public static Sim fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Sim object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Sim object represented by the provided JSON + */ + public static Sim fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Sim.class); @@ -76,14 +75,17 @@ public static Sim fromJson(final String json, final ObjectMapper objectMapper) { } /** - * Converts a JSON InputStream into a Sim object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Sim object represented by the provided JSON - */ - public static Sim fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Sim object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Sim object represented by the provided JSON + */ + public static Sim fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Sim.class); @@ -119,71 +121,32 @@ public static Sim fromJson(final InputStream json, final ObjectMapper objectMapp @JsonCreator private Sim( - @JsonProperty("sid") - final String sid, - - @JsonProperty("unique_name") - final String uniqueName, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("rate_plan_sid") - final String ratePlanSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("iccid") - final String iccid, - - @JsonProperty("e_id") - final String eId, - - @JsonProperty("status") - final String status, - - @JsonProperty("commands_callback_url") - final URI commandsCallbackUrl, - - @JsonProperty("commands_callback_method") - final String commandsCallbackMethod, - - @JsonProperty("sms_fallback_method") - final HttpMethod smsFallbackMethod, - - @JsonProperty("sms_fallback_url") - final URI smsFallbackUrl, - - @JsonProperty("sms_method") - final HttpMethod smsMethod, - - @JsonProperty("sms_url") - final URI smsUrl, - - @JsonProperty("voice_fallback_method") - final HttpMethod voiceFallbackMethod, - - @JsonProperty("voice_fallback_url") - final URI voiceFallbackUrl, - - @JsonProperty("voice_method") - final HttpMethod voiceMethod, - - @JsonProperty("voice_url") - final URI voiceUrl, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("sid") final String sid, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("rate_plan_sid") final String ratePlanSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("iccid") final String iccid, + @JsonProperty("e_id") final String eId, + @JsonProperty("status") final String status, + @JsonProperty("commands_callback_url") final URI commandsCallbackUrl, + @JsonProperty( + "commands_callback_method" + ) final String commandsCallbackMethod, + @JsonProperty("sms_fallback_method") final HttpMethod smsFallbackMethod, + @JsonProperty("sms_fallback_url") final URI smsFallbackUrl, + @JsonProperty("sms_method") final HttpMethod smsMethod, + @JsonProperty("sms_url") final URI smsUrl, + @JsonProperty( + "voice_fallback_method" + ) final HttpMethod voiceFallbackMethod, + @JsonProperty("voice_fallback_url") final URI voiceFallbackUrl, + @JsonProperty("voice_method") final HttpMethod voiceMethod, + @JsonProperty("voice_url") final URI voiceUrl, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.sid = sid; this.uniqueName = uniqueName; @@ -209,76 +172,97 @@ private Sim( this.links = links; } - public final String getSid() { - return this.sid; - } - public final String getUniqueName() { - return this.uniqueName; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getRatePlanSid() { - return this.ratePlanSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getIccid() { - return this.iccid; - } - public final String getEId() { - return this.eId; - } - public final String getStatus() { - return this.status; - } - public final URI getCommandsCallbackUrl() { - return this.commandsCallbackUrl; - } - public final String getCommandsCallbackMethod() { - return this.commandsCallbackMethod; - } - public final HttpMethod getSmsFallbackMethod() { - return this.smsFallbackMethod; - } - public final URI getSmsFallbackUrl() { - return this.smsFallbackUrl; - } - public final HttpMethod getSmsMethod() { - return this.smsMethod; - } - public final URI getSmsUrl() { - return this.smsUrl; - } - public final HttpMethod getVoiceFallbackMethod() { - return this.voiceFallbackMethod; - } - public final URI getVoiceFallbackUrl() { - return this.voiceFallbackUrl; - } - public final HttpMethod getVoiceMethod() { - return this.voiceMethod; - } - public final URI getVoiceUrl() { - return this.voiceUrl; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getSid() { + return this.sid; + } + + public final String getUniqueName() { + return this.uniqueName; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getRatePlanSid() { + return this.ratePlanSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getIccid() { + return this.iccid; + } + + public final String getEId() { + return this.eId; + } + + public final String getStatus() { + return this.status; + } + + public final URI getCommandsCallbackUrl() { + return this.commandsCallbackUrl; + } + + public final String getCommandsCallbackMethod() { + return this.commandsCallbackMethod; + } + + public final HttpMethod getSmsFallbackMethod() { + return this.smsFallbackMethod; + } + + public final URI getSmsFallbackUrl() { + return this.smsFallbackUrl; + } + + public final HttpMethod getSmsMethod() { + return this.smsMethod; + } + + public final URI getSmsUrl() { + return this.smsUrl; + } + + public final HttpMethod getVoiceFallbackMethod() { + return this.voiceFallbackMethod; + } + + public final URI getVoiceFallbackUrl() { + return this.voiceFallbackUrl; + } + + public final HttpMethod getVoiceMethod() { + return this.voiceMethod; + } + + public final URI getVoiceUrl() { + return this.voiceUrl; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -288,13 +272,60 @@ public boolean equals(final Object o) { Sim other = (Sim) o; - return Objects.equals(sid, other.sid) && Objects.equals(uniqueName, other.uniqueName) && Objects.equals(accountSid, other.accountSid) && Objects.equals(ratePlanSid, other.ratePlanSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(iccid, other.iccid) && Objects.equals(eId, other.eId) && Objects.equals(status, other.status) && Objects.equals(commandsCallbackUrl, other.commandsCallbackUrl) && Objects.equals(commandsCallbackMethod, other.commandsCallbackMethod) && Objects.equals(smsFallbackMethod, other.smsFallbackMethod) && Objects.equals(smsFallbackUrl, other.smsFallbackUrl) && Objects.equals(smsMethod, other.smsMethod) && Objects.equals(smsUrl, other.smsUrl) && Objects.equals(voiceFallbackMethod, other.voiceFallbackMethod) && Objects.equals(voiceFallbackUrl, other.voiceFallbackUrl) && Objects.equals(voiceMethod, other.voiceMethod) && Objects.equals(voiceUrl, other.voiceUrl) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(ratePlanSid, other.ratePlanSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(iccid, other.iccid) && + Objects.equals(eId, other.eId) && + Objects.equals(status, other.status) && + Objects.equals(commandsCallbackUrl, other.commandsCallbackUrl) && + Objects.equals( + commandsCallbackMethod, + other.commandsCallbackMethod + ) && + Objects.equals(smsFallbackMethod, other.smsFallbackMethod) && + Objects.equals(smsFallbackUrl, other.smsFallbackUrl) && + Objects.equals(smsMethod, other.smsMethod) && + Objects.equals(smsUrl, other.smsUrl) && + Objects.equals(voiceFallbackMethod, other.voiceFallbackMethod) && + Objects.equals(voiceFallbackUrl, other.voiceFallbackUrl) && + Objects.equals(voiceMethod, other.voiceMethod) && + Objects.equals(voiceUrl, other.voiceUrl) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(sid, uniqueName, accountSid, ratePlanSid, friendlyName, iccid, eId, status, commandsCallbackUrl, commandsCallbackMethod, smsFallbackMethod, smsFallbackUrl, smsMethod, smsUrl, voiceFallbackMethod, voiceFallbackUrl, voiceMethod, voiceUrl, dateCreated, dateUpdated, url, links); + return Objects.hash( + sid, + uniqueName, + accountSid, + ratePlanSid, + friendlyName, + iccid, + eId, + status, + commandsCallbackUrl, + commandsCallbackMethod, + smsFallbackMethod, + smsFallbackUrl, + smsMethod, + smsUrl, + voiceFallbackMethod, + voiceFallbackUrl, + voiceMethod, + voiceUrl, + dateCreated, + dateUpdated, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/preview/wireless/SimFetcher.java b/src/main/java/com/twilio/rest/preview/wireless/SimFetcher.java index b42e44415b..ec3d21c3f2 100644 --- a/src/main/java/com/twilio/rest/preview/wireless/SimFetcher.java +++ b/src/main/java/com/twilio/rest/preview/wireless/SimFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class SimFetcher extends Fetcher { + private String pathSid; - public SimFetcher(final String pathSid){ + public SimFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public Sim fetch(final TwilioRestClient client) { String path = "/wireless/Sims/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,9 +46,14 @@ public Sim fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Sim fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Sim fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/preview/wireless/SimReader.java b/src/main/java/com/twilio/rest/preview/wireless/SimReader.java index 519c752f77..822ba98cea 100644 --- a/src/main/java/com/twilio/rest/preview/wireless/SimReader.java +++ b/src/main/java/com/twilio/rest/preview/wireless/SimReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.preview.wireless; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,11 +25,9 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class SimReader extends Reader { + private String status; private String iccid; private String ratePlan; @@ -36,30 +35,34 @@ public class SimReader extends Reader { private String simRegistrationCode; private Integer pageSize; - public SimReader(){ - } + public SimReader() {} - public SimReader setStatus(final String status){ + public SimReader setStatus(final String status) { this.status = status; return this; } - public SimReader setIccid(final String iccid){ + + public SimReader setIccid(final String iccid) { this.iccid = iccid; return this; } - public SimReader setRatePlan(final String ratePlan){ + + public SimReader setRatePlan(final String ratePlan) { this.ratePlan = ratePlan; return this; } - public SimReader setEid(final String eid){ + + public SimReader setEid(final String eid) { this.eid = eid; return this; } - public SimReader setSimRegistrationCode(final String simRegistrationCode){ + + public SimReader setSimRegistrationCode(final String simRegistrationCode) { this.simRegistrationCode = simRegistrationCode; return this; } - public SimReader setPageSize(final Integer pageSize){ + + public SimReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -82,13 +85,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Sim read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Sim read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -104,7 +115,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request re } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.PREVIEW.toString()) @@ -112,9 +126,11 @@ public Page previousPage(final Page page, final TwilioRestClient clien return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.PREVIEW.toString()) @@ -123,41 +139,36 @@ public Page nextPage(final Page page, final TwilioRestClient client) { } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (status != null) { - request.addQueryParam("Status", status); } if (iccid != null) { - request.addQueryParam("Iccid", iccid); } if (ratePlan != null) { - request.addQueryParam("RatePlan", ratePlan); } if (eid != null) { - request.addQueryParam("EId", eid); } if (simRegistrationCode != null) { - request.addQueryParam("SimRegistrationCode", simRegistrationCode); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/preview/wireless/SimUpdater.java b/src/main/java/com/twilio/rest/preview/wireless/SimUpdater.java index 2d7a92efb9..678c7c874e 100644 --- a/src/main/java/com/twilio/rest/preview/wireless/SimUpdater.java +++ b/src/main/java/com/twilio/rest/preview/wireless/SimUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.preview.wireless; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -24,12 +25,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.net.URI; +public class SimUpdater extends Updater { - -public class SimUpdater extends Updater{ private String pathSid; private String uniqueName; private String callbackMethod; @@ -48,116 +47,143 @@ public class SimUpdater extends Updater{ private HttpMethod voiceMethod; private URI voiceUrl; - public SimUpdater(final String pathSid){ + public SimUpdater(final String pathSid) { this.pathSid = pathSid; } - public SimUpdater setUniqueName(final String uniqueName){ + public SimUpdater setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - public SimUpdater setCallbackMethod(final String callbackMethod){ + + public SimUpdater setCallbackMethod(final String callbackMethod) { this.callbackMethod = callbackMethod; return this; } - public SimUpdater setCallbackUrl(final URI callbackUrl){ + + public SimUpdater setCallbackUrl(final URI callbackUrl) { this.callbackUrl = callbackUrl; return this; } - public SimUpdater setCallbackUrl(final String callbackUrl){ + public SimUpdater setCallbackUrl(final String callbackUrl) { return setCallbackUrl(Promoter.uriFromString(callbackUrl)); } - public SimUpdater setFriendlyName(final String friendlyName){ + + public SimUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public SimUpdater setRatePlan(final String ratePlan){ + + public SimUpdater setRatePlan(final String ratePlan) { this.ratePlan = ratePlan; return this; } - public SimUpdater setStatus(final String status){ + + public SimUpdater setStatus(final String status) { this.status = status; return this; } - public SimUpdater setCommandsCallbackMethod(final HttpMethod commandsCallbackMethod){ + + public SimUpdater setCommandsCallbackMethod( + final HttpMethod commandsCallbackMethod + ) { this.commandsCallbackMethod = commandsCallbackMethod; return this; } - public SimUpdater setCommandsCallbackUrl(final URI commandsCallbackUrl){ + + public SimUpdater setCommandsCallbackUrl(final URI commandsCallbackUrl) { this.commandsCallbackUrl = commandsCallbackUrl; return this; } - public SimUpdater setCommandsCallbackUrl(final String commandsCallbackUrl){ - return setCommandsCallbackUrl(Promoter.uriFromString(commandsCallbackUrl)); + public SimUpdater setCommandsCallbackUrl(final String commandsCallbackUrl) { + return setCommandsCallbackUrl( + Promoter.uriFromString(commandsCallbackUrl) + ); } - public SimUpdater setSmsFallbackMethod(final HttpMethod smsFallbackMethod){ + + public SimUpdater setSmsFallbackMethod(final HttpMethod smsFallbackMethod) { this.smsFallbackMethod = smsFallbackMethod; return this; } - public SimUpdater setSmsFallbackUrl(final URI smsFallbackUrl){ + + public SimUpdater setSmsFallbackUrl(final URI smsFallbackUrl) { this.smsFallbackUrl = smsFallbackUrl; return this; } - public SimUpdater setSmsFallbackUrl(final String smsFallbackUrl){ + public SimUpdater setSmsFallbackUrl(final String smsFallbackUrl) { return setSmsFallbackUrl(Promoter.uriFromString(smsFallbackUrl)); } - public SimUpdater setSmsMethod(final HttpMethod smsMethod){ + + public SimUpdater setSmsMethod(final HttpMethod smsMethod) { this.smsMethod = smsMethod; return this; } - public SimUpdater setSmsUrl(final URI smsUrl){ + + public SimUpdater setSmsUrl(final URI smsUrl) { this.smsUrl = smsUrl; return this; } - public SimUpdater setSmsUrl(final String smsUrl){ + public SimUpdater setSmsUrl(final String smsUrl) { return setSmsUrl(Promoter.uriFromString(smsUrl)); } - public SimUpdater setVoiceFallbackMethod(final HttpMethod voiceFallbackMethod){ + + public SimUpdater setVoiceFallbackMethod( + final HttpMethod voiceFallbackMethod + ) { this.voiceFallbackMethod = voiceFallbackMethod; return this; } - public SimUpdater setVoiceFallbackUrl(final URI voiceFallbackUrl){ + + public SimUpdater setVoiceFallbackUrl(final URI voiceFallbackUrl) { this.voiceFallbackUrl = voiceFallbackUrl; return this; } - public SimUpdater setVoiceFallbackUrl(final String voiceFallbackUrl){ + public SimUpdater setVoiceFallbackUrl(final String voiceFallbackUrl) { return setVoiceFallbackUrl(Promoter.uriFromString(voiceFallbackUrl)); } - public SimUpdater setVoiceMethod(final HttpMethod voiceMethod){ + + public SimUpdater setVoiceMethod(final HttpMethod voiceMethod) { this.voiceMethod = voiceMethod; return this; } - public SimUpdater setVoiceUrl(final URI voiceUrl){ + + public SimUpdater setVoiceUrl(final URI voiceUrl) { this.voiceUrl = voiceUrl; return this; } - public SimUpdater setVoiceUrl(final String voiceUrl){ + public SimUpdater setVoiceUrl(final String voiceUrl) { return setVoiceUrl(Promoter.uriFromString(voiceUrl)); } @Override - public Sim update(final TwilioRestClient client){ + public Sim update(final TwilioRestClient client) { String path = "/wireless/Sims/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.PREVIEW.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Sim update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Sim update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -166,70 +192,70 @@ public Sim update(final TwilioRestClient client){ return Sim.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (uniqueName != null) { request.addPostParam("UniqueName", uniqueName); - } if (callbackMethod != null) { request.addPostParam("CallbackMethod", callbackMethod); - } if (callbackUrl != null) { request.addPostParam("CallbackUrl", callbackUrl.toString()); - } if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (ratePlan != null) { request.addPostParam("RatePlan", ratePlan); - } if (status != null) { request.addPostParam("Status", status); - } if (commandsCallbackMethod != null) { - request.addPostParam("CommandsCallbackMethod", commandsCallbackMethod.toString()); - + request.addPostParam( + "CommandsCallbackMethod", + commandsCallbackMethod.toString() + ); } if (commandsCallbackUrl != null) { - request.addPostParam("CommandsCallbackUrl", commandsCallbackUrl.toString()); - + request.addPostParam( + "CommandsCallbackUrl", + commandsCallbackUrl.toString() + ); } if (smsFallbackMethod != null) { - request.addPostParam("SmsFallbackMethod", smsFallbackMethod.toString()); - + request.addPostParam( + "SmsFallbackMethod", + smsFallbackMethod.toString() + ); } if (smsFallbackUrl != null) { request.addPostParam("SmsFallbackUrl", smsFallbackUrl.toString()); - } if (smsMethod != null) { request.addPostParam("SmsMethod", smsMethod.toString()); - } if (smsUrl != null) { request.addPostParam("SmsUrl", smsUrl.toString()); - } if (voiceFallbackMethod != null) { - request.addPostParam("VoiceFallbackMethod", voiceFallbackMethod.toString()); - + request.addPostParam( + "VoiceFallbackMethod", + voiceFallbackMethod.toString() + ); } if (voiceFallbackUrl != null) { - request.addPostParam("VoiceFallbackUrl", voiceFallbackUrl.toString()); - + request.addPostParam( + "VoiceFallbackUrl", + voiceFallbackUrl.toString() + ); } if (voiceMethod != null) { request.addPostParam("VoiceMethod", voiceMethod.toString()); - } if (voiceUrl != null) { request.addPostParam("VoiceUrl", voiceUrl.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/preview/wireless/sim/Usage.java b/src/main/java/com/twilio/rest/preview/wireless/sim/Usage.java index 76bb0f9de2..c2683da2c1 100644 --- a/src/main/java/com/twilio/rest/preview/wireless/sim/Usage.java +++ b/src/main/java/com/twilio/rest/preview/wireless/sim/Usage.java @@ -22,38 +22,37 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Usage extends Resource { + private static final long serialVersionUID = 23834274390782L; - public static UsageFetcher fetcher(final String pathSimSid){ + public static UsageFetcher fetcher(final String pathSimSid) { return new UsageFetcher(pathSimSid); } /** - * Converts a JSON String into a Usage object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Usage object represented by the provided JSON - */ - public static Usage fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Usage object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Usage object represented by the provided JSON + */ + public static Usage fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Usage.class); @@ -65,14 +64,17 @@ public static Usage fromJson(final String json, final ObjectMapper objectMapper) } /** - * Converts a JSON InputStream into a Usage object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Usage object represented by the provided JSON - */ - public static Usage fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Usage object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Usage object represented by the provided JSON + */ + public static Usage fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Usage.class); @@ -95,32 +97,15 @@ public static Usage fromJson(final InputStream json, final ObjectMapper objectMa @JsonCreator private Usage( - @JsonProperty("sim_sid") - final String simSid, - - @JsonProperty("sim_unique_name") - final String simUniqueName, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("period") - final Map period, - - @JsonProperty("commands_usage") - final Map commandsUsage, - - @JsonProperty("commands_costs") - final Map commandsCosts, - - @JsonProperty("data_usage") - final Map dataUsage, - - @JsonProperty("data_costs") - final Map dataCosts, - - @JsonProperty("url") - final URI url + @JsonProperty("sim_sid") final String simSid, + @JsonProperty("sim_unique_name") final String simUniqueName, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("period") final Map period, + @JsonProperty("commands_usage") final Map commandsUsage, + @JsonProperty("commands_costs") final Map commandsCosts, + @JsonProperty("data_usage") final Map dataUsage, + @JsonProperty("data_costs") final Map dataCosts, + @JsonProperty("url") final URI url ) { this.simSid = simSid; this.simUniqueName = simUniqueName; @@ -133,37 +118,45 @@ private Usage( this.url = url; } - public final String getSimSid() { - return this.simSid; - } - public final String getSimUniqueName() { - return this.simUniqueName; - } - public final String getAccountSid() { - return this.accountSid; - } - public final Map getPeriod() { - return this.period; - } - public final Map getCommandsUsage() { - return this.commandsUsage; - } - public final Map getCommandsCosts() { - return this.commandsCosts; - } - public final Map getDataUsage() { - return this.dataUsage; - } - public final Map getDataCosts() { - return this.dataCosts; - } - public final URI getUrl() { - return this.url; - } + public final String getSimSid() { + return this.simSid; + } + + public final String getSimUniqueName() { + return this.simUniqueName; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final Map getPeriod() { + return this.period; + } + + public final Map getCommandsUsage() { + return this.commandsUsage; + } + + public final Map getCommandsCosts() { + return this.commandsCosts; + } + + public final Map getDataUsage() { + return this.dataUsage; + } + + public final Map getDataCosts() { + return this.dataCosts; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -173,13 +166,31 @@ public boolean equals(final Object o) { Usage other = (Usage) o; - return Objects.equals(simSid, other.simSid) && Objects.equals(simUniqueName, other.simUniqueName) && Objects.equals(accountSid, other.accountSid) && Objects.equals(period, other.period) && Objects.equals(commandsUsage, other.commandsUsage) && Objects.equals(commandsCosts, other.commandsCosts) && Objects.equals(dataUsage, other.dataUsage) && Objects.equals(dataCosts, other.dataCosts) && Objects.equals(url, other.url) ; + return ( + Objects.equals(simSid, other.simSid) && + Objects.equals(simUniqueName, other.simUniqueName) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(period, other.period) && + Objects.equals(commandsUsage, other.commandsUsage) && + Objects.equals(commandsCosts, other.commandsCosts) && + Objects.equals(dataUsage, other.dataUsage) && + Objects.equals(dataCosts, other.dataCosts) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(simSid, simUniqueName, accountSid, period, commandsUsage, commandsCosts, dataUsage, dataCosts, url); + return Objects.hash( + simSid, + simUniqueName, + accountSid, + period, + commandsUsage, + commandsCosts, + dataUsage, + dataCosts, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/preview/wireless/sim/UsageFetcher.java b/src/main/java/com/twilio/rest/preview/wireless/sim/UsageFetcher.java index 2fbf79f7c7..6bc6bf2cf9 100644 --- a/src/main/java/com/twilio/rest/preview/wireless/sim/UsageFetcher.java +++ b/src/main/java/com/twilio/rest/preview/wireless/sim/UsageFetcher.java @@ -24,23 +24,22 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class UsageFetcher extends Fetcher { + private String pathSimSid; private String end; private String start; - public UsageFetcher(final String pathSimSid){ + public UsageFetcher(final String pathSimSid) { this.pathSimSid = pathSimSid; } - public UsageFetcher setEnd(final String end){ + public UsageFetcher setEnd(final String end) { this.end = end; return this; } - public UsageFetcher setStart(final String start){ + + public UsageFetcher setStart(final String start) { this.start = start; return this; } @@ -49,7 +48,7 @@ public UsageFetcher setStart(final String start){ public Usage fetch(final TwilioRestClient client) { String path = "/wireless/Sims/{SimSid}/Usage"; - path = path.replace("{"+"SimSid"+"}", this.pathSimSid.toString()); + path = path.replace("{" + "SimSid" + "}", this.pathSimSid.toString()); Request request = new Request( HttpMethod.GET, @@ -60,9 +59,14 @@ public Usage fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Usage fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Usage fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -71,13 +75,12 @@ public Usage fetch(final TwilioRestClient client) { return Usage.fromJson(response.getStream(), client.getObjectMapper()); } + private void addQueryParams(final Request request) { if (end != null) { - request.addQueryParam("End", end); } if (start != null) { - request.addQueryParam("Start", start); } } diff --git a/src/main/java/com/twilio/rest/pricing/v1/messaging/Country.java b/src/main/java/com/twilio/rest/pricing/v1/messaging/Country.java index 9bead26091..48f3e4c94d 100644 --- a/src/main/java/com/twilio/rest/pricing/v1/messaging/Country.java +++ b/src/main/java/com/twilio/rest/pricing/v1/messaging/Country.java @@ -20,48 +20,47 @@ import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.twilio.base.Resource; -import java.util.Currency; import com.twilio.converter.CurrencyDeserializer; import com.twilio.exception.ApiConnectionException; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; - import com.twilio.exception.ApiException; - -import lombok.ToString; - +import com.twilio.type.InboundSmsPrice; +import com.twilio.type.OutboundSmsPrice; import java.io.IOException; import java.io.InputStream; import java.net.URI; - +import java.util.Currency; import java.util.List; import java.util.Objects; - - -import com.twilio.type.InboundSmsPrice; -import com.twilio.type.OutboundSmsPrice; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Country extends Resource { + private static final long serialVersionUID = 141644803807942L; - public static CountryFetcher fetcher(final String pathIsoCountry){ + public static CountryFetcher fetcher(final String pathIsoCountry) { return new CountryFetcher(pathIsoCountry); } - public static CountryReader reader(){ + public static CountryReader reader() { return new CountryReader(); } /** - * Converts a JSON String into a Country object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Country object represented by the provided JSON - */ - public static Country fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Country object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Country object represented by the provided JSON + */ + public static Country fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Country.class); @@ -73,14 +72,17 @@ public static Country fromJson(final String json, final ObjectMapper objectMappe } /** - * Converts a JSON InputStream into a Country object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Country object represented by the provided JSON - */ - public static Country fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Country object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Country object represented by the provided JSON + */ + public static Country fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Country.class); @@ -100,24 +102,18 @@ public static Country fromJson(final InputStream json, final ObjectMapper object @JsonCreator private Country( - @JsonProperty("country") - final String country, - - @JsonProperty("iso_country") - final String isoCountry, - - @JsonProperty("outbound_sms_prices") - final List outboundSmsPrices, - - @JsonProperty("inbound_sms_prices") - final List inboundSmsPrices, - - @JsonProperty("price_unit") - @JsonDeserialize(using = com.twilio.converter.CurrencyDeserializer.class) - final Currency priceUnit, - - @JsonProperty("url") - final URI url + @JsonProperty("country") final String country, + @JsonProperty("iso_country") final String isoCountry, + @JsonProperty( + "outbound_sms_prices" + ) final List outboundSmsPrices, + @JsonProperty( + "inbound_sms_prices" + ) final List inboundSmsPrices, + @JsonProperty("price_unit") @JsonDeserialize( + using = com.twilio.converter.CurrencyDeserializer.class + ) final Currency priceUnit, + @JsonProperty("url") final URI url ) { this.country = country; this.isoCountry = isoCountry; @@ -127,28 +123,33 @@ private Country( this.url = url; } - public final String getCountry() { - return this.country; - } - public final String getIsoCountry() { - return this.isoCountry; - } - public final List getOutboundSmsPrices() { - return this.outboundSmsPrices; - } - public final List getInboundSmsPrices() { - return this.inboundSmsPrices; - } - public final Currency getPriceUnit() { - return this.priceUnit; - } - public final URI getUrl() { - return this.url; - } + public final String getCountry() { + return this.country; + } + + public final String getIsoCountry() { + return this.isoCountry; + } + + public final List getOutboundSmsPrices() { + return this.outboundSmsPrices; + } + + public final List getInboundSmsPrices() { + return this.inboundSmsPrices; + } + + public final Currency getPriceUnit() { + return this.priceUnit; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -158,13 +159,25 @@ public boolean equals(final Object o) { Country other = (Country) o; - return Objects.equals(country, other.country) && Objects.equals(isoCountry, other.isoCountry) && Objects.equals(outboundSmsPrices, other.outboundSmsPrices) && Objects.equals(inboundSmsPrices, other.inboundSmsPrices) && Objects.equals(priceUnit, other.priceUnit) && Objects.equals(url, other.url) ; + return ( + Objects.equals(country, other.country) && + Objects.equals(isoCountry, other.isoCountry) && + Objects.equals(outboundSmsPrices, other.outboundSmsPrices) && + Objects.equals(inboundSmsPrices, other.inboundSmsPrices) && + Objects.equals(priceUnit, other.priceUnit) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(country, isoCountry, outboundSmsPrices, inboundSmsPrices, priceUnit, url); + return Objects.hash( + country, + isoCountry, + outboundSmsPrices, + inboundSmsPrices, + priceUnit, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/pricing/v1/messaging/CountryFetcher.java b/src/main/java/com/twilio/rest/pricing/v1/messaging/CountryFetcher.java index 301dc86991..714a21bad0 100644 --- a/src/main/java/com/twilio/rest/pricing/v1/messaging/CountryFetcher.java +++ b/src/main/java/com/twilio/rest/pricing/v1/messaging/CountryFetcher.java @@ -24,22 +24,23 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class CountryFetcher extends Fetcher { + private String pathIsoCountry; - public CountryFetcher(final String pathIsoCountry){ + public CountryFetcher(final String pathIsoCountry) { this.pathIsoCountry = pathIsoCountry; } - @Override public Country fetch(final TwilioRestClient client) { String path = "/v1/Messaging/Countries/{IsoCountry}"; - path = path.replace("{"+"IsoCountry"+"}", this.pathIsoCountry.toString()); + path = + path.replace( + "{" + "IsoCountry" + "}", + this.pathIsoCountry.toString() + ); Request request = new Request( HttpMethod.GET, @@ -49,9 +50,14 @@ public Country fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Country fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Country fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/pricing/v1/messaging/CountryReader.java b/src/main/java/com/twilio/rest/pricing/v1/messaging/CountryReader.java index 4a9f00de0a..3ce2b06cce 100644 --- a/src/main/java/com/twilio/rest/pricing/v1/messaging/CountryReader.java +++ b/src/main/java/com/twilio/rest/pricing/v1/messaging/CountryReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.pricing.v1.messaging; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,17 +25,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class CountryReader extends Reader { + private Integer pageSize; - public CountryReader(){ - } + public CountryReader() {} - public CountryReader setPageSize(final Integer pageSize){ + public CountryReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -57,13 +55,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Country read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Country read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -79,7 +85,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reques } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.PRICING.toString()) @@ -87,9 +96,11 @@ public Page previousPage(final Page page, final TwilioRestClie return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.PRICING.toString()) @@ -98,21 +109,21 @@ public Page nextPage(final Page page, final TwilioRestClient c } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/pricing/v1/phonenumber/Country.java b/src/main/java/com/twilio/rest/pricing/v1/phonenumber/Country.java index 5398f5f60d..7122cc73ae 100644 --- a/src/main/java/com/twilio/rest/pricing/v1/phonenumber/Country.java +++ b/src/main/java/com/twilio/rest/pricing/v1/phonenumber/Country.java @@ -20,47 +20,46 @@ import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.twilio.base.Resource; -import java.util.Currency; import com.twilio.converter.CurrencyDeserializer; import com.twilio.exception.ApiConnectionException; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; - import com.twilio.exception.ApiException; - -import lombok.ToString; - +import com.twilio.type.PhoneNumberPrice; import java.io.IOException; import java.io.InputStream; import java.net.URI; - +import java.util.Currency; import java.util.List; import java.util.Objects; - - -import com.twilio.type.PhoneNumberPrice; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Country extends Resource { + private static final long serialVersionUID = 141644803807942L; - public static CountryFetcher fetcher(final String pathIsoCountry){ + public static CountryFetcher fetcher(final String pathIsoCountry) { return new CountryFetcher(pathIsoCountry); } - public static CountryReader reader(){ + public static CountryReader reader() { return new CountryReader(); } /** - * Converts a JSON String into a Country object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Country object represented by the provided JSON - */ - public static Country fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Country object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Country object represented by the provided JSON + */ + public static Country fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Country.class); @@ -72,14 +71,17 @@ public static Country fromJson(final String json, final ObjectMapper objectMappe } /** - * Converts a JSON InputStream into a Country object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Country object represented by the provided JSON - */ - public static Country fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Country object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Country object represented by the provided JSON + */ + public static Country fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Country.class); @@ -98,21 +100,15 @@ public static Country fromJson(final InputStream json, final ObjectMapper object @JsonCreator private Country( - @JsonProperty("country") - final String country, - - @JsonProperty("iso_country") - final String isoCountry, - - @JsonProperty("phone_number_prices") - final List phoneNumberPrices, - - @JsonProperty("price_unit") - @JsonDeserialize(using = com.twilio.converter.CurrencyDeserializer.class) - final Currency priceUnit, - - @JsonProperty("url") - final URI url + @JsonProperty("country") final String country, + @JsonProperty("iso_country") final String isoCountry, + @JsonProperty( + "phone_number_prices" + ) final List phoneNumberPrices, + @JsonProperty("price_unit") @JsonDeserialize( + using = com.twilio.converter.CurrencyDeserializer.class + ) final Currency priceUnit, + @JsonProperty("url") final URI url ) { this.country = country; this.isoCountry = isoCountry; @@ -121,25 +117,29 @@ private Country( this.url = url; } - public final String getCountry() { - return this.country; - } - public final String getIsoCountry() { - return this.isoCountry; - } - public final List getPhoneNumberPrices() { - return this.phoneNumberPrices; - } - public final Currency getPriceUnit() { - return this.priceUnit; - } - public final URI getUrl() { - return this.url; - } + public final String getCountry() { + return this.country; + } + + public final String getIsoCountry() { + return this.isoCountry; + } + + public final List getPhoneNumberPrices() { + return this.phoneNumberPrices; + } + + public final Currency getPriceUnit() { + return this.priceUnit; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -149,13 +149,23 @@ public boolean equals(final Object o) { Country other = (Country) o; - return Objects.equals(country, other.country) && Objects.equals(isoCountry, other.isoCountry) && Objects.equals(phoneNumberPrices, other.phoneNumberPrices) && Objects.equals(priceUnit, other.priceUnit) && Objects.equals(url, other.url) ; + return ( + Objects.equals(country, other.country) && + Objects.equals(isoCountry, other.isoCountry) && + Objects.equals(phoneNumberPrices, other.phoneNumberPrices) && + Objects.equals(priceUnit, other.priceUnit) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(country, isoCountry, phoneNumberPrices, priceUnit, url); + return Objects.hash( + country, + isoCountry, + phoneNumberPrices, + priceUnit, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/pricing/v1/phonenumber/CountryFetcher.java b/src/main/java/com/twilio/rest/pricing/v1/phonenumber/CountryFetcher.java index 08036482d7..b8716624f0 100644 --- a/src/main/java/com/twilio/rest/pricing/v1/phonenumber/CountryFetcher.java +++ b/src/main/java/com/twilio/rest/pricing/v1/phonenumber/CountryFetcher.java @@ -24,22 +24,23 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class CountryFetcher extends Fetcher { + private String pathIsoCountry; - public CountryFetcher(final String pathIsoCountry){ + public CountryFetcher(final String pathIsoCountry) { this.pathIsoCountry = pathIsoCountry; } - @Override public Country fetch(final TwilioRestClient client) { String path = "/v1/PhoneNumbers/Countries/{IsoCountry}"; - path = path.replace("{"+"IsoCountry"+"}", this.pathIsoCountry.toString()); + path = + path.replace( + "{" + "IsoCountry" + "}", + this.pathIsoCountry.toString() + ); Request request = new Request( HttpMethod.GET, @@ -49,9 +50,14 @@ public Country fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Country fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Country fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/pricing/v1/phonenumber/CountryReader.java b/src/main/java/com/twilio/rest/pricing/v1/phonenumber/CountryReader.java index 6914ad693f..7452c747b2 100644 --- a/src/main/java/com/twilio/rest/pricing/v1/phonenumber/CountryReader.java +++ b/src/main/java/com/twilio/rest/pricing/v1/phonenumber/CountryReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.pricing.v1.phonenumber; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,17 +25,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class CountryReader extends Reader { + private Integer pageSize; - public CountryReader(){ - } + public CountryReader() {} - public CountryReader setPageSize(final Integer pageSize){ + public CountryReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -57,13 +55,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Country read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Country read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -79,7 +85,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reques } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.PRICING.toString()) @@ -87,9 +96,11 @@ public Page previousPage(final Page page, final TwilioRestClie return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.PRICING.toString()) @@ -98,21 +109,21 @@ public Page nextPage(final Page page, final TwilioRestClient c } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/pricing/v1/voice/Country.java b/src/main/java/com/twilio/rest/pricing/v1/voice/Country.java index 5a3200b8e1..9247c4620f 100644 --- a/src/main/java/com/twilio/rest/pricing/v1/voice/Country.java +++ b/src/main/java/com/twilio/rest/pricing/v1/voice/Country.java @@ -20,48 +20,47 @@ import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.twilio.base.Resource; -import java.util.Currency; import com.twilio.converter.CurrencyDeserializer; import com.twilio.exception.ApiConnectionException; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; - import com.twilio.exception.ApiException; - -import lombok.ToString; - +import com.twilio.type.InboundCallPrice; +import com.twilio.type.OutboundPrefixPrice; import java.io.IOException; import java.io.InputStream; import java.net.URI; - +import java.util.Currency; import java.util.List; import java.util.Objects; - - -import com.twilio.type.InboundCallPrice; -import com.twilio.type.OutboundPrefixPrice; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Country extends Resource { + private static final long serialVersionUID = 141644803807942L; - public static CountryFetcher fetcher(final String pathIsoCountry){ + public static CountryFetcher fetcher(final String pathIsoCountry) { return new CountryFetcher(pathIsoCountry); } - public static CountryReader reader(){ + public static CountryReader reader() { return new CountryReader(); } /** - * Converts a JSON String into a Country object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Country object represented by the provided JSON - */ - public static Country fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Country object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Country object represented by the provided JSON + */ + public static Country fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Country.class); @@ -73,14 +72,17 @@ public static Country fromJson(final String json, final ObjectMapper objectMappe } /** - * Converts a JSON InputStream into a Country object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Country object represented by the provided JSON - */ - public static Country fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Country object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Country object represented by the provided JSON + */ + public static Country fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Country.class); @@ -100,24 +102,18 @@ public static Country fromJson(final InputStream json, final ObjectMapper object @JsonCreator private Country( - @JsonProperty("country") - final String country, - - @JsonProperty("iso_country") - final String isoCountry, - - @JsonProperty("outbound_prefix_prices") - final List outboundPrefixPrices, - - @JsonProperty("inbound_call_prices") - final List inboundCallPrices, - - @JsonProperty("price_unit") - @JsonDeserialize(using = com.twilio.converter.CurrencyDeserializer.class) - final Currency priceUnit, - - @JsonProperty("url") - final URI url + @JsonProperty("country") final String country, + @JsonProperty("iso_country") final String isoCountry, + @JsonProperty( + "outbound_prefix_prices" + ) final List outboundPrefixPrices, + @JsonProperty( + "inbound_call_prices" + ) final List inboundCallPrices, + @JsonProperty("price_unit") @JsonDeserialize( + using = com.twilio.converter.CurrencyDeserializer.class + ) final Currency priceUnit, + @JsonProperty("url") final URI url ) { this.country = country; this.isoCountry = isoCountry; @@ -127,28 +123,33 @@ private Country( this.url = url; } - public final String getCountry() { - return this.country; - } - public final String getIsoCountry() { - return this.isoCountry; - } - public final List getOutboundPrefixPrices() { - return this.outboundPrefixPrices; - } - public final List getInboundCallPrices() { - return this.inboundCallPrices; - } - public final Currency getPriceUnit() { - return this.priceUnit; - } - public final URI getUrl() { - return this.url; - } + public final String getCountry() { + return this.country; + } + + public final String getIsoCountry() { + return this.isoCountry; + } + + public final List getOutboundPrefixPrices() { + return this.outboundPrefixPrices; + } + + public final List getInboundCallPrices() { + return this.inboundCallPrices; + } + + public final Currency getPriceUnit() { + return this.priceUnit; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -158,13 +159,25 @@ public boolean equals(final Object o) { Country other = (Country) o; - return Objects.equals(country, other.country) && Objects.equals(isoCountry, other.isoCountry) && Objects.equals(outboundPrefixPrices, other.outboundPrefixPrices) && Objects.equals(inboundCallPrices, other.inboundCallPrices) && Objects.equals(priceUnit, other.priceUnit) && Objects.equals(url, other.url) ; + return ( + Objects.equals(country, other.country) && + Objects.equals(isoCountry, other.isoCountry) && + Objects.equals(outboundPrefixPrices, other.outboundPrefixPrices) && + Objects.equals(inboundCallPrices, other.inboundCallPrices) && + Objects.equals(priceUnit, other.priceUnit) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(country, isoCountry, outboundPrefixPrices, inboundCallPrices, priceUnit, url); + return Objects.hash( + country, + isoCountry, + outboundPrefixPrices, + inboundCallPrices, + priceUnit, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/pricing/v1/voice/CountryFetcher.java b/src/main/java/com/twilio/rest/pricing/v1/voice/CountryFetcher.java index 8687575fa3..1220e78a9a 100644 --- a/src/main/java/com/twilio/rest/pricing/v1/voice/CountryFetcher.java +++ b/src/main/java/com/twilio/rest/pricing/v1/voice/CountryFetcher.java @@ -24,22 +24,23 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class CountryFetcher extends Fetcher { + private String pathIsoCountry; - public CountryFetcher(final String pathIsoCountry){ + public CountryFetcher(final String pathIsoCountry) { this.pathIsoCountry = pathIsoCountry; } - @Override public Country fetch(final TwilioRestClient client) { String path = "/v1/Voice/Countries/{IsoCountry}"; - path = path.replace("{"+"IsoCountry"+"}", this.pathIsoCountry.toString()); + path = + path.replace( + "{" + "IsoCountry" + "}", + this.pathIsoCountry.toString() + ); Request request = new Request( HttpMethod.GET, @@ -49,9 +50,14 @@ public Country fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Country fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Country fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/pricing/v1/voice/CountryReader.java b/src/main/java/com/twilio/rest/pricing/v1/voice/CountryReader.java index 67ee8a8c21..04d8da90d8 100644 --- a/src/main/java/com/twilio/rest/pricing/v1/voice/CountryReader.java +++ b/src/main/java/com/twilio/rest/pricing/v1/voice/CountryReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.pricing.v1.voice; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,17 +25,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class CountryReader extends Reader { + private Integer pageSize; - public CountryReader(){ - } + public CountryReader() {} - public CountryReader setPageSize(final Integer pageSize){ + public CountryReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -57,13 +55,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Country read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Country read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -79,7 +85,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reques } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.PRICING.toString()) @@ -87,9 +96,11 @@ public Page previousPage(final Page page, final TwilioRestClie return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.PRICING.toString()) @@ -98,21 +109,21 @@ public Page nextPage(final Page page, final TwilioRestClient c } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/pricing/v1/voice/Number.java b/src/main/java/com/twilio/rest/pricing/v1/voice/Number.java index 4488510720..84501022ef 100644 --- a/src/main/java/com/twilio/rest/pricing/v1/voice/Number.java +++ b/src/main/java/com/twilio/rest/pricing/v1/voice/Number.java @@ -20,43 +20,44 @@ import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.twilio.base.Resource; -import java.util.Currency; import com.twilio.converter.CurrencyDeserializer; import com.twilio.exception.ApiConnectionException; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; - import com.twilio.exception.ApiException; - -import lombok.ToString; - +import com.twilio.type.InboundCallPrice; +import com.twilio.type.OutboundCallPrice; import java.io.IOException; import java.io.InputStream; import java.net.URI; - +import java.util.Currency; import java.util.Objects; - - -import com.twilio.type.InboundCallPrice; -import com.twilio.type.OutboundCallPrice; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Number extends Resource { + private static final long serialVersionUID = 23882142179085L; - public static NumberFetcher fetcher(final com.twilio.type.PhoneNumber pathNumber){ + public static NumberFetcher fetcher( + final com.twilio.type.PhoneNumber pathNumber + ) { return new NumberFetcher(pathNumber); } /** - * Converts a JSON String into a Number object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Number object represented by the provided JSON - */ - public static Number fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Number object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Number object represented by the provided JSON + */ + public static Number fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Number.class); @@ -68,14 +69,17 @@ public static Number fromJson(final String json, final ObjectMapper objectMapper } /** - * Converts a JSON InputStream into a Number object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Number object represented by the provided JSON - */ - public static Number fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Number object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Number object represented by the provided JSON + */ + public static Number fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Number.class); @@ -96,27 +100,19 @@ public static Number fromJson(final InputStream json, final ObjectMapper objectM @JsonCreator private Number( - @JsonProperty("number") - final com.twilio.type.PhoneNumber number, - - @JsonProperty("country") - final String country, - - @JsonProperty("iso_country") - final String isoCountry, - - @JsonProperty("outbound_call_price") - final OutboundCallPrice outboundCallPrice, - - @JsonProperty("inbound_call_price") - final InboundCallPrice inboundCallPrice, - - @JsonProperty("price_unit") - @JsonDeserialize(using = com.twilio.converter.CurrencyDeserializer.class) - final Currency priceUnit, - - @JsonProperty("url") - final URI url + @JsonProperty("number") final com.twilio.type.PhoneNumber number, + @JsonProperty("country") final String country, + @JsonProperty("iso_country") final String isoCountry, + @JsonProperty( + "outbound_call_price" + ) final OutboundCallPrice outboundCallPrice, + @JsonProperty( + "inbound_call_price" + ) final InboundCallPrice inboundCallPrice, + @JsonProperty("price_unit") @JsonDeserialize( + using = com.twilio.converter.CurrencyDeserializer.class + ) final Currency priceUnit, + @JsonProperty("url") final URI url ) { this.number = number; this.country = country; @@ -127,31 +123,37 @@ private Number( this.url = url; } - public final com.twilio.type.PhoneNumber getNumber() { - return this.number; - } - public final String getCountry() { - return this.country; - } - public final String getIsoCountry() { - return this.isoCountry; - } - public final OutboundCallPrice getOutboundCallPrice() { - return this.outboundCallPrice; - } - public final InboundCallPrice getInboundCallPrice() { - return this.inboundCallPrice; - } - public final Currency getPriceUnit() { - return this.priceUnit; - } - public final URI getUrl() { - return this.url; - } + public final com.twilio.type.PhoneNumber getNumber() { + return this.number; + } + + public final String getCountry() { + return this.country; + } + + public final String getIsoCountry() { + return this.isoCountry; + } + + public final OutboundCallPrice getOutboundCallPrice() { + return this.outboundCallPrice; + } + + public final InboundCallPrice getInboundCallPrice() { + return this.inboundCallPrice; + } + + public final Currency getPriceUnit() { + return this.priceUnit; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -161,13 +163,27 @@ public boolean equals(final Object o) { Number other = (Number) o; - return Objects.equals(number, other.number) && Objects.equals(country, other.country) && Objects.equals(isoCountry, other.isoCountry) && Objects.equals(outboundCallPrice, other.outboundCallPrice) && Objects.equals(inboundCallPrice, other.inboundCallPrice) && Objects.equals(priceUnit, other.priceUnit) && Objects.equals(url, other.url) ; + return ( + Objects.equals(number, other.number) && + Objects.equals(country, other.country) && + Objects.equals(isoCountry, other.isoCountry) && + Objects.equals(outboundCallPrice, other.outboundCallPrice) && + Objects.equals(inboundCallPrice, other.inboundCallPrice) && + Objects.equals(priceUnit, other.priceUnit) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(number, country, isoCountry, outboundCallPrice, inboundCallPrice, priceUnit, url); + return Objects.hash( + number, + country, + isoCountry, + outboundCallPrice, + inboundCallPrice, + priceUnit, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/pricing/v1/voice/NumberFetcher.java b/src/main/java/com/twilio/rest/pricing/v1/voice/NumberFetcher.java index e11144203c..252a690f16 100644 --- a/src/main/java/com/twilio/rest/pricing/v1/voice/NumberFetcher.java +++ b/src/main/java/com/twilio/rest/pricing/v1/voice/NumberFetcher.java @@ -24,22 +24,20 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class NumberFetcher extends Fetcher { + private com.twilio.type.PhoneNumber pathNumber; - public NumberFetcher(final com.twilio.type.PhoneNumber pathNumber){ + public NumberFetcher(final com.twilio.type.PhoneNumber pathNumber) { this.pathNumber = pathNumber; } - @Override public Number fetch(final TwilioRestClient client) { String path = "/v1/Voice/Numbers/{Number}"; - path = path.replace("{"+"Number"+"}", this.pathNumber.encode("utf-8")); + path = + path.replace("{" + "Number" + "}", this.pathNumber.encode("utf-8")); Request request = new Request( HttpMethod.GET, @@ -49,9 +47,14 @@ public Number fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Number fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Number fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/pricing/v2/Country.java b/src/main/java/com/twilio/rest/pricing/v2/Country.java index 8ba0c9d16d..f8626cc830 100644 --- a/src/main/java/com/twilio/rest/pricing/v2/Country.java +++ b/src/main/java/com/twilio/rest/pricing/v2/Country.java @@ -20,48 +20,47 @@ import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.twilio.base.Resource; -import java.util.Currency; import com.twilio.converter.CurrencyDeserializer; import com.twilio.exception.ApiConnectionException; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; - import com.twilio.exception.ApiException; - -import lombok.ToString; - +import com.twilio.type.InboundCallPrice; +import com.twilio.type.OutboundPrefixPriceWithOrigin; import java.io.IOException; import java.io.InputStream; import java.net.URI; - +import java.util.Currency; import java.util.List; import java.util.Objects; - - -import com.twilio.type.InboundCallPrice; -import com.twilio.type.OutboundPrefixPriceWithOrigin; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Country extends Resource { + private static final long serialVersionUID = 141644803807942L; - public static CountryFetcher fetcher(final String pathIsoCountry){ + public static CountryFetcher fetcher(final String pathIsoCountry) { return new CountryFetcher(pathIsoCountry); } - public static CountryReader reader(){ + public static CountryReader reader() { return new CountryReader(); } /** - * Converts a JSON String into a Country object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Country object represented by the provided JSON - */ - public static Country fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Country object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Country object represented by the provided JSON + */ + public static Country fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Country.class); @@ -73,14 +72,17 @@ public static Country fromJson(final String json, final ObjectMapper objectMappe } /** - * Converts a JSON InputStream into a Country object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Country object represented by the provided JSON - */ - public static Country fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Country object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Country object represented by the provided JSON + */ + public static Country fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Country.class); @@ -100,24 +102,18 @@ public static Country fromJson(final InputStream json, final ObjectMapper object @JsonCreator private Country( - @JsonProperty("country") - final String country, - - @JsonProperty("iso_country") - final String isoCountry, - - @JsonProperty("terminating_prefix_prices") - final List terminatingPrefixPrices, - - @JsonProperty("originating_call_prices") - final List originatingCallPrices, - - @JsonProperty("price_unit") - @JsonDeserialize(using = com.twilio.converter.CurrencyDeserializer.class) - final Currency priceUnit, - - @JsonProperty("url") - final URI url + @JsonProperty("country") final String country, + @JsonProperty("iso_country") final String isoCountry, + @JsonProperty( + "terminating_prefix_prices" + ) final List terminatingPrefixPrices, + @JsonProperty( + "originating_call_prices" + ) final List originatingCallPrices, + @JsonProperty("price_unit") @JsonDeserialize( + using = com.twilio.converter.CurrencyDeserializer.class + ) final Currency priceUnit, + @JsonProperty("url") final URI url ) { this.country = country; this.isoCountry = isoCountry; @@ -127,28 +123,33 @@ private Country( this.url = url; } - public final String getCountry() { - return this.country; - } - public final String getIsoCountry() { - return this.isoCountry; - } - public final List getTerminatingPrefixPrices() { - return this.terminatingPrefixPrices; - } - public final List getOriginatingCallPrices() { - return this.originatingCallPrices; - } - public final Currency getPriceUnit() { - return this.priceUnit; - } - public final URI getUrl() { - return this.url; - } + public final String getCountry() { + return this.country; + } + + public final String getIsoCountry() { + return this.isoCountry; + } + + public final List getTerminatingPrefixPrices() { + return this.terminatingPrefixPrices; + } + + public final List getOriginatingCallPrices() { + return this.originatingCallPrices; + } + + public final Currency getPriceUnit() { + return this.priceUnit; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -158,13 +159,31 @@ public boolean equals(final Object o) { Country other = (Country) o; - return Objects.equals(country, other.country) && Objects.equals(isoCountry, other.isoCountry) && Objects.equals(terminatingPrefixPrices, other.terminatingPrefixPrices) && Objects.equals(originatingCallPrices, other.originatingCallPrices) && Objects.equals(priceUnit, other.priceUnit) && Objects.equals(url, other.url) ; + return ( + Objects.equals(country, other.country) && + Objects.equals(isoCountry, other.isoCountry) && + Objects.equals( + terminatingPrefixPrices, + other.terminatingPrefixPrices + ) && + Objects.equals( + originatingCallPrices, + other.originatingCallPrices + ) && + Objects.equals(priceUnit, other.priceUnit) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(country, isoCountry, terminatingPrefixPrices, originatingCallPrices, priceUnit, url); + return Objects.hash( + country, + isoCountry, + terminatingPrefixPrices, + originatingCallPrices, + priceUnit, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/pricing/v2/CountryFetcher.java b/src/main/java/com/twilio/rest/pricing/v2/CountryFetcher.java index 5dcbe51fec..b82ffcdf31 100644 --- a/src/main/java/com/twilio/rest/pricing/v2/CountryFetcher.java +++ b/src/main/java/com/twilio/rest/pricing/v2/CountryFetcher.java @@ -24,22 +24,23 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class CountryFetcher extends Fetcher { + private String pathIsoCountry; - public CountryFetcher(final String pathIsoCountry){ + public CountryFetcher(final String pathIsoCountry) { this.pathIsoCountry = pathIsoCountry; } - @Override public Country fetch(final TwilioRestClient client) { String path = "/v2/Trunking/Countries/{IsoCountry}"; - path = path.replace("{"+"IsoCountry"+"}", this.pathIsoCountry.toString()); + path = + path.replace( + "{" + "IsoCountry" + "}", + this.pathIsoCountry.toString() + ); Request request = new Request( HttpMethod.GET, @@ -49,9 +50,14 @@ public Country fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Country fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Country fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/pricing/v2/CountryReader.java b/src/main/java/com/twilio/rest/pricing/v2/CountryReader.java index e515cd6fb0..4ac34cbb93 100644 --- a/src/main/java/com/twilio/rest/pricing/v2/CountryReader.java +++ b/src/main/java/com/twilio/rest/pricing/v2/CountryReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.pricing.v2; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,17 +25,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class CountryReader extends Reader { + private Integer pageSize; - public CountryReader(){ - } + public CountryReader() {} - public CountryReader setPageSize(final Integer pageSize){ + public CountryReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -57,13 +55,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Country read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Country read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -79,7 +85,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reques } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.PRICING.toString()) @@ -87,9 +96,11 @@ public Page previousPage(final Page page, final TwilioRestClie return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.PRICING.toString()) @@ -98,21 +109,21 @@ public Page nextPage(final Page page, final TwilioRestClient c } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/pricing/v2/Number.java b/src/main/java/com/twilio/rest/pricing/v2/Number.java index 1fb0eff24c..54dadd1914 100644 --- a/src/main/java/com/twilio/rest/pricing/v2/Number.java +++ b/src/main/java/com/twilio/rest/pricing/v2/Number.java @@ -20,44 +20,45 @@ import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.twilio.base.Resource; -import java.util.Currency; import com.twilio.converter.CurrencyDeserializer; import com.twilio.exception.ApiConnectionException; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; - import com.twilio.exception.ApiException; - -import lombok.ToString; - +import com.twilio.type.InboundCallPrice; +import com.twilio.type.OutboundPrefixPriceWithOrigin; import java.io.IOException; import java.io.InputStream; import java.net.URI; - +import java.util.Currency; import java.util.List; import java.util.Objects; - - -import com.twilio.type.InboundCallPrice; -import com.twilio.type.OutboundPrefixPriceWithOrigin; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Number extends Resource { + private static final long serialVersionUID = 12955680623193L; - public static NumberFetcher fetcher(final com.twilio.type.PhoneNumber pathDestinationNumber){ + public static NumberFetcher fetcher( + final com.twilio.type.PhoneNumber pathDestinationNumber + ) { return new NumberFetcher(pathDestinationNumber); } /** - * Converts a JSON String into a Number object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Number object represented by the provided JSON - */ - public static Number fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Number object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Number object represented by the provided JSON + */ + public static Number fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Number.class); @@ -69,14 +70,17 @@ public static Number fromJson(final String json, final ObjectMapper objectMapper } /** - * Converts a JSON InputStream into a Number object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Number object represented by the provided JSON - */ - public static Number fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Number object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Number object represented by the provided JSON + */ + public static Number fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Number.class); @@ -98,30 +102,24 @@ public static Number fromJson(final InputStream json, final ObjectMapper objectM @JsonCreator private Number( - @JsonProperty("destination_number") - final com.twilio.type.PhoneNumber destinationNumber, - - @JsonProperty("origination_number") - final com.twilio.type.PhoneNumber originationNumber, - - @JsonProperty("country") - final String country, - - @JsonProperty("iso_country") - final String isoCountry, - - @JsonProperty("terminating_prefix_prices") - final List terminatingPrefixPrices, - - @JsonProperty("originating_call_price") - final InboundCallPrice originatingCallPrice, - - @JsonProperty("price_unit") - @JsonDeserialize(using = com.twilio.converter.CurrencyDeserializer.class) - final Currency priceUnit, - - @JsonProperty("url") - final URI url + @JsonProperty( + "destination_number" + ) final com.twilio.type.PhoneNumber destinationNumber, + @JsonProperty( + "origination_number" + ) final com.twilio.type.PhoneNumber originationNumber, + @JsonProperty("country") final String country, + @JsonProperty("iso_country") final String isoCountry, + @JsonProperty( + "terminating_prefix_prices" + ) final List terminatingPrefixPrices, + @JsonProperty( + "originating_call_price" + ) final InboundCallPrice originatingCallPrice, + @JsonProperty("price_unit") @JsonDeserialize( + using = com.twilio.converter.CurrencyDeserializer.class + ) final Currency priceUnit, + @JsonProperty("url") final URI url ) { this.destinationNumber = destinationNumber; this.originationNumber = originationNumber; @@ -133,34 +131,41 @@ private Number( this.url = url; } - public final com.twilio.type.PhoneNumber getDestinationNumber() { - return this.destinationNumber; - } - public final com.twilio.type.PhoneNumber getOriginationNumber() { - return this.originationNumber; - } - public final String getCountry() { - return this.country; - } - public final String getIsoCountry() { - return this.isoCountry; - } - public final List getTerminatingPrefixPrices() { - return this.terminatingPrefixPrices; - } - public final InboundCallPrice getOriginatingCallPrice() { - return this.originatingCallPrice; - } - public final Currency getPriceUnit() { - return this.priceUnit; - } - public final URI getUrl() { - return this.url; - } + public final com.twilio.type.PhoneNumber getDestinationNumber() { + return this.destinationNumber; + } + + public final com.twilio.type.PhoneNumber getOriginationNumber() { + return this.originationNumber; + } + + public final String getCountry() { + return this.country; + } + + public final String getIsoCountry() { + return this.isoCountry; + } + + public final List getTerminatingPrefixPrices() { + return this.terminatingPrefixPrices; + } + + public final InboundCallPrice getOriginatingCallPrice() { + return this.originatingCallPrice; + } + + public final Currency getPriceUnit() { + return this.priceUnit; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -170,13 +175,32 @@ public boolean equals(final Object o) { Number other = (Number) o; - return Objects.equals(destinationNumber, other.destinationNumber) && Objects.equals(originationNumber, other.originationNumber) && Objects.equals(country, other.country) && Objects.equals(isoCountry, other.isoCountry) && Objects.equals(terminatingPrefixPrices, other.terminatingPrefixPrices) && Objects.equals(originatingCallPrice, other.originatingCallPrice) && Objects.equals(priceUnit, other.priceUnit) && Objects.equals(url, other.url) ; + return ( + Objects.equals(destinationNumber, other.destinationNumber) && + Objects.equals(originationNumber, other.originationNumber) && + Objects.equals(country, other.country) && + Objects.equals(isoCountry, other.isoCountry) && + Objects.equals( + terminatingPrefixPrices, + other.terminatingPrefixPrices + ) && + Objects.equals(originatingCallPrice, other.originatingCallPrice) && + Objects.equals(priceUnit, other.priceUnit) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(destinationNumber, originationNumber, country, isoCountry, terminatingPrefixPrices, originatingCallPrice, priceUnit, url); + return Objects.hash( + destinationNumber, + originationNumber, + country, + isoCountry, + terminatingPrefixPrices, + originatingCallPrice, + priceUnit, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/pricing/v2/NumberFetcher.java b/src/main/java/com/twilio/rest/pricing/v2/NumberFetcher.java index 254ed04495..4ce19c3014 100644 --- a/src/main/java/com/twilio/rest/pricing/v2/NumberFetcher.java +++ b/src/main/java/com/twilio/rest/pricing/v2/NumberFetcher.java @@ -25,31 +25,39 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class NumberFetcher extends Fetcher { + private com.twilio.type.PhoneNumber pathDestinationNumber; private com.twilio.type.PhoneNumber originationNumber; - public NumberFetcher(final com.twilio.type.PhoneNumber pathDestinationNumber){ + public NumberFetcher( + final com.twilio.type.PhoneNumber pathDestinationNumber + ) { this.pathDestinationNumber = pathDestinationNumber; } - public NumberFetcher setOriginationNumber(final com.twilio.type.PhoneNumber originationNumber){ + public NumberFetcher setOriginationNumber( + final com.twilio.type.PhoneNumber originationNumber + ) { this.originationNumber = originationNumber; return this; } - public NumberFetcher setOriginationNumber(final String originationNumber){ - return setOriginationNumber(Promoter.phoneNumberFromString(originationNumber)); + public NumberFetcher setOriginationNumber(final String originationNumber) { + return setOriginationNumber( + Promoter.phoneNumberFromString(originationNumber) + ); } @Override public Number fetch(final TwilioRestClient client) { String path = "/v2/Trunking/Numbers/{DestinationNumber}"; - path = path.replace("{"+"DestinationNumber"+"}", this.pathDestinationNumber.encode("utf-8")); + path = + path.replace( + "{" + "DestinationNumber" + "}", + this.pathDestinationNumber.encode("utf-8") + ); Request request = new Request( HttpMethod.GET, @@ -60,9 +68,14 @@ public Number fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Number fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Number fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -71,10 +84,13 @@ public Number fetch(final TwilioRestClient client) { return Number.fromJson(response.getStream(), client.getObjectMapper()); } + private void addQueryParams(final Request request) { if (originationNumber != null) { - - request.addQueryParam("OriginationNumber", originationNumber.toString()); + request.addQueryParam( + "OriginationNumber", + originationNumber.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/pricing/v2/voice/Country.java b/src/main/java/com/twilio/rest/pricing/v2/voice/Country.java index d86ec8c375..e7031c188b 100644 --- a/src/main/java/com/twilio/rest/pricing/v2/voice/Country.java +++ b/src/main/java/com/twilio/rest/pricing/v2/voice/Country.java @@ -20,48 +20,47 @@ import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.twilio.base.Resource; -import java.util.Currency; import com.twilio.converter.CurrencyDeserializer; import com.twilio.exception.ApiConnectionException; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; - import com.twilio.exception.ApiException; - -import lombok.ToString; - +import com.twilio.type.InboundCallPrice; +import com.twilio.type.OutboundPrefixPriceWithOrigin; import java.io.IOException; import java.io.InputStream; import java.net.URI; - +import java.util.Currency; import java.util.List; import java.util.Objects; - - -import com.twilio.type.InboundCallPrice; -import com.twilio.type.OutboundPrefixPriceWithOrigin; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Country extends Resource { + private static final long serialVersionUID = 141644803807942L; - public static CountryFetcher fetcher(final String pathIsoCountry){ + public static CountryFetcher fetcher(final String pathIsoCountry) { return new CountryFetcher(pathIsoCountry); } - public static CountryReader reader(){ + public static CountryReader reader() { return new CountryReader(); } /** - * Converts a JSON String into a Country object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Country object represented by the provided JSON - */ - public static Country fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Country object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Country object represented by the provided JSON + */ + public static Country fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Country.class); @@ -73,14 +72,17 @@ public static Country fromJson(final String json, final ObjectMapper objectMappe } /** - * Converts a JSON InputStream into a Country object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Country object represented by the provided JSON - */ - public static Country fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Country object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Country object represented by the provided JSON + */ + public static Country fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Country.class); @@ -100,24 +102,18 @@ public static Country fromJson(final InputStream json, final ObjectMapper object @JsonCreator private Country( - @JsonProperty("country") - final String country, - - @JsonProperty("iso_country") - final String isoCountry, - - @JsonProperty("outbound_prefix_prices") - final List outboundPrefixPrices, - - @JsonProperty("inbound_call_prices") - final List inboundCallPrices, - - @JsonProperty("price_unit") - @JsonDeserialize(using = com.twilio.converter.CurrencyDeserializer.class) - final Currency priceUnit, - - @JsonProperty("url") - final URI url + @JsonProperty("country") final String country, + @JsonProperty("iso_country") final String isoCountry, + @JsonProperty( + "outbound_prefix_prices" + ) final List outboundPrefixPrices, + @JsonProperty( + "inbound_call_prices" + ) final List inboundCallPrices, + @JsonProperty("price_unit") @JsonDeserialize( + using = com.twilio.converter.CurrencyDeserializer.class + ) final Currency priceUnit, + @JsonProperty("url") final URI url ) { this.country = country; this.isoCountry = isoCountry; @@ -127,28 +123,33 @@ private Country( this.url = url; } - public final String getCountry() { - return this.country; - } - public final String getIsoCountry() { - return this.isoCountry; - } - public final List getOutboundPrefixPrices() { - return this.outboundPrefixPrices; - } - public final List getInboundCallPrices() { - return this.inboundCallPrices; - } - public final Currency getPriceUnit() { - return this.priceUnit; - } - public final URI getUrl() { - return this.url; - } + public final String getCountry() { + return this.country; + } + + public final String getIsoCountry() { + return this.isoCountry; + } + + public final List getOutboundPrefixPrices() { + return this.outboundPrefixPrices; + } + + public final List getInboundCallPrices() { + return this.inboundCallPrices; + } + + public final Currency getPriceUnit() { + return this.priceUnit; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -158,13 +159,25 @@ public boolean equals(final Object o) { Country other = (Country) o; - return Objects.equals(country, other.country) && Objects.equals(isoCountry, other.isoCountry) && Objects.equals(outboundPrefixPrices, other.outboundPrefixPrices) && Objects.equals(inboundCallPrices, other.inboundCallPrices) && Objects.equals(priceUnit, other.priceUnit) && Objects.equals(url, other.url) ; + return ( + Objects.equals(country, other.country) && + Objects.equals(isoCountry, other.isoCountry) && + Objects.equals(outboundPrefixPrices, other.outboundPrefixPrices) && + Objects.equals(inboundCallPrices, other.inboundCallPrices) && + Objects.equals(priceUnit, other.priceUnit) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(country, isoCountry, outboundPrefixPrices, inboundCallPrices, priceUnit, url); + return Objects.hash( + country, + isoCountry, + outboundPrefixPrices, + inboundCallPrices, + priceUnit, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/pricing/v2/voice/CountryFetcher.java b/src/main/java/com/twilio/rest/pricing/v2/voice/CountryFetcher.java index a746be94fa..fffe280ea6 100644 --- a/src/main/java/com/twilio/rest/pricing/v2/voice/CountryFetcher.java +++ b/src/main/java/com/twilio/rest/pricing/v2/voice/CountryFetcher.java @@ -24,22 +24,23 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class CountryFetcher extends Fetcher { + private String pathIsoCountry; - public CountryFetcher(final String pathIsoCountry){ + public CountryFetcher(final String pathIsoCountry) { this.pathIsoCountry = pathIsoCountry; } - @Override public Country fetch(final TwilioRestClient client) { String path = "/v2/Voice/Countries/{IsoCountry}"; - path = path.replace("{"+"IsoCountry"+"}", this.pathIsoCountry.toString()); + path = + path.replace( + "{" + "IsoCountry" + "}", + this.pathIsoCountry.toString() + ); Request request = new Request( HttpMethod.GET, @@ -49,9 +50,14 @@ public Country fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Country fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Country fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/pricing/v2/voice/CountryReader.java b/src/main/java/com/twilio/rest/pricing/v2/voice/CountryReader.java index 7ecc99dc54..6c58cca002 100644 --- a/src/main/java/com/twilio/rest/pricing/v2/voice/CountryReader.java +++ b/src/main/java/com/twilio/rest/pricing/v2/voice/CountryReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.pricing.v2.voice; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,17 +25,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class CountryReader extends Reader { + private Integer pageSize; - public CountryReader(){ - } + public CountryReader() {} - public CountryReader setPageSize(final Integer pageSize){ + public CountryReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -57,13 +55,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Country read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Country read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -79,7 +85,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reques } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.PRICING.toString()) @@ -87,9 +96,11 @@ public Page previousPage(final Page page, final TwilioRestClie return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.PRICING.toString()) @@ -98,21 +109,21 @@ public Page nextPage(final Page page, final TwilioRestClient c } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/pricing/v2/voice/Number.java b/src/main/java/com/twilio/rest/pricing/v2/voice/Number.java index cdad42eb72..0126e8d99f 100644 --- a/src/main/java/com/twilio/rest/pricing/v2/voice/Number.java +++ b/src/main/java/com/twilio/rest/pricing/v2/voice/Number.java @@ -20,44 +20,45 @@ import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.twilio.base.Resource; -import java.util.Currency; import com.twilio.converter.CurrencyDeserializer; import com.twilio.exception.ApiConnectionException; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; - import com.twilio.exception.ApiException; - -import lombok.ToString; - +import com.twilio.type.InboundCallPrice; +import com.twilio.type.OutboundCallPriceWithOrigin; import java.io.IOException; import java.io.InputStream; import java.net.URI; - +import java.util.Currency; import java.util.List; import java.util.Objects; - - -import com.twilio.type.InboundCallPrice; -import com.twilio.type.OutboundCallPriceWithOrigin; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Number extends Resource { + private static final long serialVersionUID = 252636644344470L; - public static NumberFetcher fetcher(final com.twilio.type.PhoneNumber pathDestinationNumber){ + public static NumberFetcher fetcher( + final com.twilio.type.PhoneNumber pathDestinationNumber + ) { return new NumberFetcher(pathDestinationNumber); } /** - * Converts a JSON String into a Number object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Number object represented by the provided JSON - */ - public static Number fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Number object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Number object represented by the provided JSON + */ + public static Number fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Number.class); @@ -69,14 +70,17 @@ public static Number fromJson(final String json, final ObjectMapper objectMapper } /** - * Converts a JSON InputStream into a Number object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Number object represented by the provided JSON - */ - public static Number fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Number object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Number object represented by the provided JSON + */ + public static Number fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Number.class); @@ -98,30 +102,24 @@ public static Number fromJson(final InputStream json, final ObjectMapper objectM @JsonCreator private Number( - @JsonProperty("destination_number") - final com.twilio.type.PhoneNumber destinationNumber, - - @JsonProperty("origination_number") - final com.twilio.type.PhoneNumber originationNumber, - - @JsonProperty("country") - final String country, - - @JsonProperty("iso_country") - final String isoCountry, - - @JsonProperty("outbound_call_prices") - final List outboundCallPrices, - - @JsonProperty("inbound_call_price") - final InboundCallPrice inboundCallPrice, - - @JsonProperty("price_unit") - @JsonDeserialize(using = com.twilio.converter.CurrencyDeserializer.class) - final Currency priceUnit, - - @JsonProperty("url") - final URI url + @JsonProperty( + "destination_number" + ) final com.twilio.type.PhoneNumber destinationNumber, + @JsonProperty( + "origination_number" + ) final com.twilio.type.PhoneNumber originationNumber, + @JsonProperty("country") final String country, + @JsonProperty("iso_country") final String isoCountry, + @JsonProperty( + "outbound_call_prices" + ) final List outboundCallPrices, + @JsonProperty( + "inbound_call_price" + ) final InboundCallPrice inboundCallPrice, + @JsonProperty("price_unit") @JsonDeserialize( + using = com.twilio.converter.CurrencyDeserializer.class + ) final Currency priceUnit, + @JsonProperty("url") final URI url ) { this.destinationNumber = destinationNumber; this.originationNumber = originationNumber; @@ -133,34 +131,41 @@ private Number( this.url = url; } - public final com.twilio.type.PhoneNumber getDestinationNumber() { - return this.destinationNumber; - } - public final com.twilio.type.PhoneNumber getOriginationNumber() { - return this.originationNumber; - } - public final String getCountry() { - return this.country; - } - public final String getIsoCountry() { - return this.isoCountry; - } - public final List getOutboundCallPrices() { - return this.outboundCallPrices; - } - public final InboundCallPrice getInboundCallPrice() { - return this.inboundCallPrice; - } - public final Currency getPriceUnit() { - return this.priceUnit; - } - public final URI getUrl() { - return this.url; - } + public final com.twilio.type.PhoneNumber getDestinationNumber() { + return this.destinationNumber; + } + + public final com.twilio.type.PhoneNumber getOriginationNumber() { + return this.originationNumber; + } + + public final String getCountry() { + return this.country; + } + + public final String getIsoCountry() { + return this.isoCountry; + } + + public final List getOutboundCallPrices() { + return this.outboundCallPrices; + } + + public final InboundCallPrice getInboundCallPrice() { + return this.inboundCallPrice; + } + + public final Currency getPriceUnit() { + return this.priceUnit; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -170,13 +175,29 @@ public boolean equals(final Object o) { Number other = (Number) o; - return Objects.equals(destinationNumber, other.destinationNumber) && Objects.equals(originationNumber, other.originationNumber) && Objects.equals(country, other.country) && Objects.equals(isoCountry, other.isoCountry) && Objects.equals(outboundCallPrices, other.outboundCallPrices) && Objects.equals(inboundCallPrice, other.inboundCallPrice) && Objects.equals(priceUnit, other.priceUnit) && Objects.equals(url, other.url) ; + return ( + Objects.equals(destinationNumber, other.destinationNumber) && + Objects.equals(originationNumber, other.originationNumber) && + Objects.equals(country, other.country) && + Objects.equals(isoCountry, other.isoCountry) && + Objects.equals(outboundCallPrices, other.outboundCallPrices) && + Objects.equals(inboundCallPrice, other.inboundCallPrice) && + Objects.equals(priceUnit, other.priceUnit) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(destinationNumber, originationNumber, country, isoCountry, outboundCallPrices, inboundCallPrice, priceUnit, url); + return Objects.hash( + destinationNumber, + originationNumber, + country, + isoCountry, + outboundCallPrices, + inboundCallPrice, + priceUnit, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/pricing/v2/voice/NumberFetcher.java b/src/main/java/com/twilio/rest/pricing/v2/voice/NumberFetcher.java index 0a091772d6..1cefca2ae7 100644 --- a/src/main/java/com/twilio/rest/pricing/v2/voice/NumberFetcher.java +++ b/src/main/java/com/twilio/rest/pricing/v2/voice/NumberFetcher.java @@ -25,31 +25,39 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class NumberFetcher extends Fetcher { + private com.twilio.type.PhoneNumber pathDestinationNumber; private com.twilio.type.PhoneNumber originationNumber; - public NumberFetcher(final com.twilio.type.PhoneNumber pathDestinationNumber){ + public NumberFetcher( + final com.twilio.type.PhoneNumber pathDestinationNumber + ) { this.pathDestinationNumber = pathDestinationNumber; } - public NumberFetcher setOriginationNumber(final com.twilio.type.PhoneNumber originationNumber){ + public NumberFetcher setOriginationNumber( + final com.twilio.type.PhoneNumber originationNumber + ) { this.originationNumber = originationNumber; return this; } - public NumberFetcher setOriginationNumber(final String originationNumber){ - return setOriginationNumber(Promoter.phoneNumberFromString(originationNumber)); + public NumberFetcher setOriginationNumber(final String originationNumber) { + return setOriginationNumber( + Promoter.phoneNumberFromString(originationNumber) + ); } @Override public Number fetch(final TwilioRestClient client) { String path = "/v2/Voice/Numbers/{DestinationNumber}"; - path = path.replace("{"+"DestinationNumber"+"}", this.pathDestinationNumber.encode("utf-8")); + path = + path.replace( + "{" + "DestinationNumber" + "}", + this.pathDestinationNumber.encode("utf-8") + ); Request request = new Request( HttpMethod.GET, @@ -60,9 +68,14 @@ public Number fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Number fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Number fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -71,10 +84,13 @@ public Number fetch(final TwilioRestClient client) { return Number.fromJson(response.getStream(), client.getObjectMapper()); } + private void addQueryParams(final Request request) { if (originationNumber != null) { - - request.addQueryParam("OriginationNumber", originationNumber.toString()); + request.addQueryParam( + "OriginationNumber", + originationNumber.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/proxy/v1/Service.java b/src/main/java/com/twilio/rest/proxy/v1/Service.java index ef561cab4e..c83064e6d9 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/Service.java +++ b/src/main/java/com/twilio/rest/proxy/v1/Service.java @@ -24,55 +24,54 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Service extends Resource { + private static final long serialVersionUID = 120259795390146L; - public static ServiceCreator creator(final String uniqueName){ + public static ServiceCreator creator(final String uniqueName) { return new ServiceCreator(uniqueName); } - public static ServiceDeleter deleter(final String pathSid){ + public static ServiceDeleter deleter(final String pathSid) { return new ServiceDeleter(pathSid); } - public static ServiceFetcher fetcher(final String pathSid){ + public static ServiceFetcher fetcher(final String pathSid) { return new ServiceFetcher(pathSid); } - public static ServiceReader reader(){ + public static ServiceReader reader() { return new ServiceReader(); } - public static ServiceUpdater updater(final String pathSid){ + public static ServiceUpdater updater(final String pathSid) { return new ServiceUpdater(pathSid); } /** - * Converts a JSON String into a Service object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Service object represented by the provided JSON - */ - public static Service fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Service object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Service object represented by the provided JSON + */ + public static Service fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Service.class); @@ -84,14 +83,17 @@ public static Service fromJson(final String json, final ObjectMapper objectMappe } /** - * Converts a JSON InputStream into a Service object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Service object represented by the provided JSON - */ - public static Service fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Service object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Service object represented by the provided JSON + */ + public static Service fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Service.class); @@ -101,6 +103,7 @@ public static Service fromJson(final InputStream json, final ObjectMapper object throw new ApiConnectionException(e.getMessage(), e); } } + public enum GeoMatchLevel { AREA_CODE("area-code"), OVERLAY("overlay"), @@ -122,6 +125,7 @@ public static GeoMatchLevel forValue(final String value) { return Promoter.enumFromString(value, GeoMatchLevel.values()); } } + public enum NumberSelectionBehavior { AVOID_STICKY("avoid-sticky"), PREFER_STICKY("prefer-sticky"); @@ -138,7 +142,10 @@ public String toString() { @JsonCreator public static NumberSelectionBehavior forValue(final String value) { - return Promoter.enumFromString(value, NumberSelectionBehavior.values()); + return Promoter.enumFromString( + value, + NumberSelectionBehavior.values() + ); } } @@ -159,47 +166,26 @@ public static NumberSelectionBehavior forValue(final String value) { @JsonCreator private Service( - @JsonProperty("sid") - final String sid, - - @JsonProperty("unique_name") - final String uniqueName, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("chat_instance_sid") - final String chatInstanceSid, - - @JsonProperty("callback_url") - final URI callbackUrl, - - @JsonProperty("default_ttl") - final Integer defaultTtl, - - @JsonProperty("number_selection_behavior") - final Service.NumberSelectionBehavior numberSelectionBehavior, - - @JsonProperty("geo_match_level") - final Service.GeoMatchLevel geoMatchLevel, - - @JsonProperty("intercept_callback_url") - final URI interceptCallbackUrl, - - @JsonProperty("out_of_session_callback_url") - final URI outOfSessionCallbackUrl, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("sid") final String sid, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("chat_instance_sid") final String chatInstanceSid, + @JsonProperty("callback_url") final URI callbackUrl, + @JsonProperty("default_ttl") final Integer defaultTtl, + @JsonProperty( + "number_selection_behavior" + ) final Service.NumberSelectionBehavior numberSelectionBehavior, + @JsonProperty( + "geo_match_level" + ) final Service.GeoMatchLevel geoMatchLevel, + @JsonProperty("intercept_callback_url") final URI interceptCallbackUrl, + @JsonProperty( + "out_of_session_callback_url" + ) final URI outOfSessionCallbackUrl, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.sid = sid; this.uniqueName = uniqueName; @@ -217,52 +203,65 @@ private Service( this.links = links; } - public final String getSid() { - return this.sid; - } - public final String getUniqueName() { - return this.uniqueName; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getChatInstanceSid() { - return this.chatInstanceSid; - } - public final URI getCallbackUrl() { - return this.callbackUrl; - } - public final Integer getDefaultTtl() { - return this.defaultTtl; - } - public final Service.NumberSelectionBehavior getNumberSelectionBehavior() { - return this.numberSelectionBehavior; - } - public final Service.GeoMatchLevel getGeoMatchLevel() { - return this.geoMatchLevel; - } - public final URI getInterceptCallbackUrl() { - return this.interceptCallbackUrl; - } - public final URI getOutOfSessionCallbackUrl() { - return this.outOfSessionCallbackUrl; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getSid() { + return this.sid; + } + + public final String getUniqueName() { + return this.uniqueName; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getChatInstanceSid() { + return this.chatInstanceSid; + } + + public final URI getCallbackUrl() { + return this.callbackUrl; + } + + public final Integer getDefaultTtl() { + return this.defaultTtl; + } + + public final Service.NumberSelectionBehavior getNumberSelectionBehavior() { + return this.numberSelectionBehavior; + } + + public final Service.GeoMatchLevel getGeoMatchLevel() { + return this.geoMatchLevel; + } + + public final URI getInterceptCallbackUrl() { + return this.interceptCallbackUrl; + } + + public final URI getOutOfSessionCallbackUrl() { + return this.outOfSessionCallbackUrl; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -272,13 +271,47 @@ public boolean equals(final Object o) { Service other = (Service) o; - return Objects.equals(sid, other.sid) && Objects.equals(uniqueName, other.uniqueName) && Objects.equals(accountSid, other.accountSid) && Objects.equals(chatInstanceSid, other.chatInstanceSid) && Objects.equals(callbackUrl, other.callbackUrl) && Objects.equals(defaultTtl, other.defaultTtl) && Objects.equals(numberSelectionBehavior, other.numberSelectionBehavior) && Objects.equals(geoMatchLevel, other.geoMatchLevel) && Objects.equals(interceptCallbackUrl, other.interceptCallbackUrl) && Objects.equals(outOfSessionCallbackUrl, other.outOfSessionCallbackUrl) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(chatInstanceSid, other.chatInstanceSid) && + Objects.equals(callbackUrl, other.callbackUrl) && + Objects.equals(defaultTtl, other.defaultTtl) && + Objects.equals( + numberSelectionBehavior, + other.numberSelectionBehavior + ) && + Objects.equals(geoMatchLevel, other.geoMatchLevel) && + Objects.equals(interceptCallbackUrl, other.interceptCallbackUrl) && + Objects.equals( + outOfSessionCallbackUrl, + other.outOfSessionCallbackUrl + ) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(sid, uniqueName, accountSid, chatInstanceSid, callbackUrl, defaultTtl, numberSelectionBehavior, geoMatchLevel, interceptCallbackUrl, outOfSessionCallbackUrl, dateCreated, dateUpdated, url, links); + return Objects.hash( + sid, + uniqueName, + accountSid, + chatInstanceSid, + callbackUrl, + defaultTtl, + numberSelectionBehavior, + geoMatchLevel, + interceptCallbackUrl, + outOfSessionCallbackUrl, + dateCreated, + dateUpdated, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/proxy/v1/ServiceCreator.java b/src/main/java/com/twilio/rest/proxy/v1/ServiceCreator.java index f4fb172fb2..e5b0549fc1 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/ServiceCreator.java +++ b/src/main/java/com/twilio/rest/proxy/v1/ServiceCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.proxy.v1; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -25,12 +26,10 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.net.URI; - - - import java.net.URI; -public class ServiceCreator extends Creator{ +public class ServiceCreator extends Creator { + private String uniqueName; private Integer defaultTtl; private URI callbackUrl; @@ -44,68 +43,98 @@ public ServiceCreator(final String uniqueName) { this.uniqueName = uniqueName; } - public ServiceCreator setUniqueName(final String uniqueName){ + public ServiceCreator setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - public ServiceCreator setDefaultTtl(final Integer defaultTtl){ + + public ServiceCreator setDefaultTtl(final Integer defaultTtl) { this.defaultTtl = defaultTtl; return this; } - public ServiceCreator setCallbackUrl(final URI callbackUrl){ + + public ServiceCreator setCallbackUrl(final URI callbackUrl) { this.callbackUrl = callbackUrl; return this; } - public ServiceCreator setCallbackUrl(final String callbackUrl){ + public ServiceCreator setCallbackUrl(final String callbackUrl) { return setCallbackUrl(Promoter.uriFromString(callbackUrl)); } - public ServiceCreator setGeoMatchLevel(final Service.GeoMatchLevel geoMatchLevel){ + + public ServiceCreator setGeoMatchLevel( + final Service.GeoMatchLevel geoMatchLevel + ) { this.geoMatchLevel = geoMatchLevel; return this; } - public ServiceCreator setNumberSelectionBehavior(final Service.NumberSelectionBehavior numberSelectionBehavior){ + + public ServiceCreator setNumberSelectionBehavior( + final Service.NumberSelectionBehavior numberSelectionBehavior + ) { this.numberSelectionBehavior = numberSelectionBehavior; return this; } - public ServiceCreator setInterceptCallbackUrl(final URI interceptCallbackUrl){ + + public ServiceCreator setInterceptCallbackUrl( + final URI interceptCallbackUrl + ) { this.interceptCallbackUrl = interceptCallbackUrl; return this; } - public ServiceCreator setInterceptCallbackUrl(final String interceptCallbackUrl){ - return setInterceptCallbackUrl(Promoter.uriFromString(interceptCallbackUrl)); + public ServiceCreator setInterceptCallbackUrl( + final String interceptCallbackUrl + ) { + return setInterceptCallbackUrl( + Promoter.uriFromString(interceptCallbackUrl) + ); } - public ServiceCreator setOutOfSessionCallbackUrl(final URI outOfSessionCallbackUrl){ + + public ServiceCreator setOutOfSessionCallbackUrl( + final URI outOfSessionCallbackUrl + ) { this.outOfSessionCallbackUrl = outOfSessionCallbackUrl; return this; } - public ServiceCreator setOutOfSessionCallbackUrl(final String outOfSessionCallbackUrl){ - return setOutOfSessionCallbackUrl(Promoter.uriFromString(outOfSessionCallbackUrl)); + public ServiceCreator setOutOfSessionCallbackUrl( + final String outOfSessionCallbackUrl + ) { + return setOutOfSessionCallbackUrl( + Promoter.uriFromString(outOfSessionCallbackUrl) + ); } - public ServiceCreator setChatInstanceSid(final String chatInstanceSid){ + + public ServiceCreator setChatInstanceSid(final String chatInstanceSid) { this.chatInstanceSid = chatInstanceSid; return this; } @Override - public Service create(final TwilioRestClient client){ + public Service create(final TwilioRestClient client) { String path = "/v1/Services"; - path = path.replace("{"+"UniqueName"+"}", this.uniqueName.toString()); + path = + path.replace("{" + "UniqueName" + "}", this.uniqueName.toString()); Request request = new Request( HttpMethod.POST, Domains.PROXY.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -114,38 +143,40 @@ public Service create(final TwilioRestClient client){ return Service.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (uniqueName != null) { request.addPostParam("UniqueName", uniqueName); - } if (defaultTtl != null) { request.addPostParam("DefaultTtl", defaultTtl.toString()); - } if (callbackUrl != null) { request.addPostParam("CallbackUrl", callbackUrl.toString()); - } if (geoMatchLevel != null) { request.addPostParam("GeoMatchLevel", geoMatchLevel.toString()); - } if (numberSelectionBehavior != null) { - request.addPostParam("NumberSelectionBehavior", numberSelectionBehavior.toString()); - + request.addPostParam( + "NumberSelectionBehavior", + numberSelectionBehavior.toString() + ); } if (interceptCallbackUrl != null) { - request.addPostParam("InterceptCallbackUrl", interceptCallbackUrl.toString()); - + request.addPostParam( + "InterceptCallbackUrl", + interceptCallbackUrl.toString() + ); } if (outOfSessionCallbackUrl != null) { - request.addPostParam("OutOfSessionCallbackUrl", outOfSessionCallbackUrl.toString()); - + request.addPostParam( + "OutOfSessionCallbackUrl", + outOfSessionCallbackUrl.toString() + ); } if (chatInstanceSid != null) { request.addPostParam("ChatInstanceSid", chatInstanceSid); - } } } diff --git a/src/main/java/com/twilio/rest/proxy/v1/ServiceDeleter.java b/src/main/java/com/twilio/rest/proxy/v1/ServiceDeleter.java index 25a93c7e87..89b21db04f 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/ServiceDeleter.java +++ b/src/main/java/com/twilio/rest/proxy/v1/ServiceDeleter.java @@ -24,21 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class ServiceDeleter extends Deleter { + private String pathSid; - public ServiceDeleter(final String pathSid){ + public ServiceDeleter(final String pathSid) { this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Services/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -48,9 +46,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/proxy/v1/ServiceFetcher.java b/src/main/java/com/twilio/rest/proxy/v1/ServiceFetcher.java index 4ea66bb92f..8e6a5b28b1 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/ServiceFetcher.java +++ b/src/main/java/com/twilio/rest/proxy/v1/ServiceFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class ServiceFetcher extends Fetcher { + private String pathSid; - public ServiceFetcher(final String pathSid){ + public ServiceFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public Service fetch(final TwilioRestClient client) { String path = "/v1/Services/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,9 +46,14 @@ public Service fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/proxy/v1/ServiceReader.java b/src/main/java/com/twilio/rest/proxy/v1/ServiceReader.java index 6de680dfc5..261cd0922f 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/ServiceReader.java +++ b/src/main/java/com/twilio/rest/proxy/v1/ServiceReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.proxy.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,17 +25,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class ServiceReader extends Reader { + private Integer pageSize; - public ServiceReader(){ - } + public ServiceReader() {} - public ServiceReader setPageSize(final Integer pageSize){ + public ServiceReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -57,13 +55,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -79,7 +85,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reques } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.PROXY.toString()) @@ -87,9 +96,11 @@ public Page previousPage(final Page page, final TwilioRestClie return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.PROXY.toString()) @@ -98,21 +109,21 @@ public Page nextPage(final Page page, final TwilioRestClient c } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/proxy/v1/ServiceUpdater.java b/src/main/java/com/twilio/rest/proxy/v1/ServiceUpdater.java index 563e1f22f4..1170f3af93 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/ServiceUpdater.java +++ b/src/main/java/com/twilio/rest/proxy/v1/ServiceUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.proxy.v1; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -24,12 +25,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.net.URI; +public class ServiceUpdater extends Updater { - -public class ServiceUpdater extends Updater{ private String pathSid; private String uniqueName; private Integer defaultTtl; @@ -40,72 +39,101 @@ public class ServiceUpdater extends Updater{ private URI outOfSessionCallbackUrl; private String chatInstanceSid; - public ServiceUpdater(final String pathSid){ + public ServiceUpdater(final String pathSid) { this.pathSid = pathSid; } - public ServiceUpdater setUniqueName(final String uniqueName){ + public ServiceUpdater setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - public ServiceUpdater setDefaultTtl(final Integer defaultTtl){ + + public ServiceUpdater setDefaultTtl(final Integer defaultTtl) { this.defaultTtl = defaultTtl; return this; } - public ServiceUpdater setCallbackUrl(final URI callbackUrl){ + + public ServiceUpdater setCallbackUrl(final URI callbackUrl) { this.callbackUrl = callbackUrl; return this; } - public ServiceUpdater setCallbackUrl(final String callbackUrl){ + public ServiceUpdater setCallbackUrl(final String callbackUrl) { return setCallbackUrl(Promoter.uriFromString(callbackUrl)); } - public ServiceUpdater setGeoMatchLevel(final Service.GeoMatchLevel geoMatchLevel){ + + public ServiceUpdater setGeoMatchLevel( + final Service.GeoMatchLevel geoMatchLevel + ) { this.geoMatchLevel = geoMatchLevel; return this; } - public ServiceUpdater setNumberSelectionBehavior(final Service.NumberSelectionBehavior numberSelectionBehavior){ + + public ServiceUpdater setNumberSelectionBehavior( + final Service.NumberSelectionBehavior numberSelectionBehavior + ) { this.numberSelectionBehavior = numberSelectionBehavior; return this; } - public ServiceUpdater setInterceptCallbackUrl(final URI interceptCallbackUrl){ + + public ServiceUpdater setInterceptCallbackUrl( + final URI interceptCallbackUrl + ) { this.interceptCallbackUrl = interceptCallbackUrl; return this; } - public ServiceUpdater setInterceptCallbackUrl(final String interceptCallbackUrl){ - return setInterceptCallbackUrl(Promoter.uriFromString(interceptCallbackUrl)); + public ServiceUpdater setInterceptCallbackUrl( + final String interceptCallbackUrl + ) { + return setInterceptCallbackUrl( + Promoter.uriFromString(interceptCallbackUrl) + ); } - public ServiceUpdater setOutOfSessionCallbackUrl(final URI outOfSessionCallbackUrl){ + + public ServiceUpdater setOutOfSessionCallbackUrl( + final URI outOfSessionCallbackUrl + ) { this.outOfSessionCallbackUrl = outOfSessionCallbackUrl; return this; } - public ServiceUpdater setOutOfSessionCallbackUrl(final String outOfSessionCallbackUrl){ - return setOutOfSessionCallbackUrl(Promoter.uriFromString(outOfSessionCallbackUrl)); + public ServiceUpdater setOutOfSessionCallbackUrl( + final String outOfSessionCallbackUrl + ) { + return setOutOfSessionCallbackUrl( + Promoter.uriFromString(outOfSessionCallbackUrl) + ); } - public ServiceUpdater setChatInstanceSid(final String chatInstanceSid){ + + public ServiceUpdater setChatInstanceSid(final String chatInstanceSid) { this.chatInstanceSid = chatInstanceSid; return this; } @Override - public Service update(final TwilioRestClient client){ + public Service update(final TwilioRestClient client) { String path = "/v1/Services/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.PROXY.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -114,38 +142,40 @@ public Service update(final TwilioRestClient client){ return Service.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (uniqueName != null) { request.addPostParam("UniqueName", uniqueName); - } if (defaultTtl != null) { request.addPostParam("DefaultTtl", defaultTtl.toString()); - } if (callbackUrl != null) { request.addPostParam("CallbackUrl", callbackUrl.toString()); - } if (geoMatchLevel != null) { request.addPostParam("GeoMatchLevel", geoMatchLevel.toString()); - } if (numberSelectionBehavior != null) { - request.addPostParam("NumberSelectionBehavior", numberSelectionBehavior.toString()); - + request.addPostParam( + "NumberSelectionBehavior", + numberSelectionBehavior.toString() + ); } if (interceptCallbackUrl != null) { - request.addPostParam("InterceptCallbackUrl", interceptCallbackUrl.toString()); - + request.addPostParam( + "InterceptCallbackUrl", + interceptCallbackUrl.toString() + ); } if (outOfSessionCallbackUrl != null) { - request.addPostParam("OutOfSessionCallbackUrl", outOfSessionCallbackUrl.toString()); - + request.addPostParam( + "OutOfSessionCallbackUrl", + outOfSessionCallbackUrl.toString() + ); } if (chatInstanceSid != null) { request.addPostParam("ChatInstanceSid", chatInstanceSid); - } } } diff --git a/src/main/java/com/twilio/rest/proxy/v1/service/PhoneNumber.java b/src/main/java/com/twilio/rest/proxy/v1/service/PhoneNumber.java index 450ef31bbf..714612794f 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/service/PhoneNumber.java +++ b/src/main/java/com/twilio/rest/proxy/v1/service/PhoneNumber.java @@ -23,54 +23,62 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - +import com.twilio.type.PhoneNumberCapabilities; import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - -import com.twilio.type.PhoneNumberCapabilities; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class PhoneNumber extends Resource { + private static final long serialVersionUID = 71034679090032L; - public static PhoneNumberCreator creator(final String pathServiceSid){ + public static PhoneNumberCreator creator(final String pathServiceSid) { return new PhoneNumberCreator(pathServiceSid); } - public static PhoneNumberDeleter deleter(final String pathServiceSid, final String pathSid){ + public static PhoneNumberDeleter deleter( + final String pathServiceSid, + final String pathSid + ) { return new PhoneNumberDeleter(pathServiceSid, pathSid); } - public static PhoneNumberFetcher fetcher(final String pathServiceSid, final String pathSid){ + public static PhoneNumberFetcher fetcher( + final String pathServiceSid, + final String pathSid + ) { return new PhoneNumberFetcher(pathServiceSid, pathSid); } - public static PhoneNumberReader reader(final String pathServiceSid){ + public static PhoneNumberReader reader(final String pathServiceSid) { return new PhoneNumberReader(pathServiceSid); } - public static PhoneNumberUpdater updater(final String pathServiceSid, final String pathSid){ + public static PhoneNumberUpdater updater( + final String pathServiceSid, + final String pathSid + ) { return new PhoneNumberUpdater(pathServiceSid, pathSid); } /** - * Converts a JSON String into a PhoneNumber object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return PhoneNumber object represented by the provided JSON - */ - public static PhoneNumber fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a PhoneNumber object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return PhoneNumber object represented by the provided JSON + */ + public static PhoneNumber fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, PhoneNumber.class); @@ -82,14 +90,17 @@ public static PhoneNumber fromJson(final String json, final ObjectMapper objectM } /** - * Converts a JSON InputStream into a PhoneNumber object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return PhoneNumber object represented by the provided JSON - */ - public static PhoneNumber fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a PhoneNumber object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return PhoneNumber object represented by the provided JSON + */ + public static PhoneNumber fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, PhoneNumber.class); @@ -115,41 +126,22 @@ public static PhoneNumber fromJson(final InputStream json, final ObjectMapper ob @JsonCreator private PhoneNumber( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("phone_number") - final com.twilio.type.PhoneNumber phoneNumber, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("iso_country") - final String isoCountry, - - @JsonProperty("capabilities") - final PhoneNumberCapabilities capabilities, - - @JsonProperty("url") - final URI url, - - @JsonProperty("is_reserved") - final Boolean isReserved, - - @JsonProperty("in_use") - final Integer inUse + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty( + "phone_number" + ) final com.twilio.type.PhoneNumber phoneNumber, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("iso_country") final String isoCountry, + @JsonProperty( + "capabilities" + ) final PhoneNumberCapabilities capabilities, + @JsonProperty("url") final URI url, + @JsonProperty("is_reserved") final Boolean isReserved, + @JsonProperty("in_use") final Integer inUse ) { this.sid = sid; this.accountSid = accountSid; @@ -165,46 +157,57 @@ private PhoneNumber( this.inUse = inUse; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final com.twilio.type.PhoneNumber getPhoneNumber() { - return this.phoneNumber; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getIsoCountry() { - return this.isoCountry; - } - public final PhoneNumberCapabilities getCapabilities() { - return this.capabilities; - } - public final URI getUrl() { - return this.url; - } - public final Boolean getIsReserved() { - return this.isReserved; - } - public final Integer getInUse() { - return this.inUse; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final com.twilio.type.PhoneNumber getPhoneNumber() { + return this.phoneNumber; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getIsoCountry() { + return this.isoCountry; + } + + public final PhoneNumberCapabilities getCapabilities() { + return this.capabilities; + } + + public final URI getUrl() { + return this.url; + } + + public final Boolean getIsReserved() { + return this.isReserved; + } + + public final Integer getInUse() { + return this.inUse; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -214,13 +217,37 @@ public boolean equals(final Object o) { PhoneNumber other = (PhoneNumber) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(phoneNumber, other.phoneNumber) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(isoCountry, other.isoCountry) && Objects.equals(capabilities, other.capabilities) && Objects.equals(url, other.url) && Objects.equals(isReserved, other.isReserved) && Objects.equals(inUse, other.inUse) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(phoneNumber, other.phoneNumber) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(isoCountry, other.isoCountry) && + Objects.equals(capabilities, other.capabilities) && + Objects.equals(url, other.url) && + Objects.equals(isReserved, other.isReserved) && + Objects.equals(inUse, other.inUse) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, serviceSid, dateCreated, dateUpdated, phoneNumber, friendlyName, isoCountry, capabilities, url, isReserved, inUse); + return Objects.hash( + sid, + accountSid, + serviceSid, + dateCreated, + dateUpdated, + phoneNumber, + friendlyName, + isoCountry, + capabilities, + url, + isReserved, + inUse + ); } - } - diff --git a/src/main/java/com/twilio/rest/proxy/v1/service/PhoneNumberCreator.java b/src/main/java/com/twilio/rest/proxy/v1/service/PhoneNumberCreator.java index b4292f5fd9..e615318672 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/service/PhoneNumberCreator.java +++ b/src/main/java/com/twilio/rest/proxy/v1/service/PhoneNumberCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.proxy.v1.service; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -25,10 +26,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class PhoneNumberCreator extends Creator { - - -public class PhoneNumberCreator extends Creator{ private String pathServiceSid; private String sid; private com.twilio.type.PhoneNumber phoneNumber; @@ -38,60 +37,75 @@ public PhoneNumberCreator(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - public PhoneNumberCreator setSid(final String sid){ + public PhoneNumberCreator setSid(final String sid) { this.sid = sid; return this; } - public PhoneNumberCreator setPhoneNumber(final com.twilio.type.PhoneNumber phoneNumber){ + + public PhoneNumberCreator setPhoneNumber( + final com.twilio.type.PhoneNumber phoneNumber + ) { this.phoneNumber = phoneNumber; return this; } - public PhoneNumberCreator setPhoneNumber(final String phoneNumber){ + public PhoneNumberCreator setPhoneNumber(final String phoneNumber) { return setPhoneNumber(Promoter.phoneNumberFromString(phoneNumber)); } - public PhoneNumberCreator setIsReserved(final Boolean isReserved){ + + public PhoneNumberCreator setIsReserved(final Boolean isReserved) { this.isReserved = isReserved; return this; } @Override - public PhoneNumber create(final TwilioRestClient client){ + public PhoneNumber create(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/PhoneNumbers"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.PROXY.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("PhoneNumber creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "PhoneNumber creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return PhoneNumber.fromJson(response.getStream(), client.getObjectMapper()); + return PhoneNumber.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (sid != null) { request.addPostParam("Sid", sid); - } if (phoneNumber != null) { request.addPostParam("PhoneNumber", phoneNumber.toString()); - } if (isReserved != null) { request.addPostParam("IsReserved", isReserved.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/proxy/v1/service/PhoneNumberDeleter.java b/src/main/java/com/twilio/rest/proxy/v1/service/PhoneNumberDeleter.java index bab8feba57..5838330b08 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/service/PhoneNumberDeleter.java +++ b/src/main/java/com/twilio/rest/proxy/v1/service/PhoneNumberDeleter.java @@ -24,24 +24,29 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class PhoneNumberDeleter extends Deleter { + private String pathServiceSid; private String pathSid; - public PhoneNumberDeleter(final String pathServiceSid, final String pathSid){ + public PhoneNumberDeleter( + final String pathServiceSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/PhoneNumbers/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +56,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("PhoneNumber delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "PhoneNumber delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/proxy/v1/service/PhoneNumberFetcher.java b/src/main/java/com/twilio/rest/proxy/v1/service/PhoneNumberFetcher.java index b6c38b27e8..c779723770 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/service/PhoneNumberFetcher.java +++ b/src/main/java/com/twilio/rest/proxy/v1/service/PhoneNumberFetcher.java @@ -24,25 +24,29 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class PhoneNumberFetcher extends Fetcher { + private String pathServiceSid; private String pathSid; - public PhoneNumberFetcher(final String pathServiceSid, final String pathSid){ + public PhoneNumberFetcher( + final String pathServiceSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - @Override public PhoneNumber fetch(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/PhoneNumbers/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,15 +56,23 @@ public PhoneNumber fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("PhoneNumber fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "PhoneNumber fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return PhoneNumber.fromJson(response.getStream(), client.getObjectMapper()); + return PhoneNumber.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/proxy/v1/service/PhoneNumberReader.java b/src/main/java/com/twilio/rest/proxy/v1/service/PhoneNumberReader.java index 2e9d229d9d..6e94fe1721 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/service/PhoneNumberReader.java +++ b/src/main/java/com/twilio/rest/proxy/v1/service/PhoneNumberReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.proxy.v1.service; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,19 +25,17 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class PhoneNumberReader extends Reader { + private String pathServiceSid; private Integer pageSize; - public PhoneNumberReader(final String pathServiceSid){ + public PhoneNumberReader(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - public PhoneNumberReader setPageSize(final Integer pageSize){ + public PhoneNumberReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -48,7 +47,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/PhoneNumbers"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -60,13 +63,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("PhoneNumber read failed: Unable to connect to server"); + throw new ApiConnectionException( + "PhoneNumber read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +93,10 @@ private Page pageForRequest(final TwilioRestClient client, final Re } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.PROXY.toString()) @@ -90,9 +104,11 @@ public Page previousPage(final Page page, final Twilio return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.PROXY.toString()) @@ -101,21 +117,21 @@ public Page nextPage(final Page page, final TwilioRest } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/proxy/v1/service/PhoneNumberUpdater.java b/src/main/java/com/twilio/rest/proxy/v1/service/PhoneNumberUpdater.java index 47c82c869b..95e5ec5bbd 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/service/PhoneNumberUpdater.java +++ b/src/main/java/com/twilio/rest/proxy/v1/service/PhoneNumberUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.proxy.v1.service; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,54 +25,68 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class PhoneNumberUpdater extends Updater { - - -public class PhoneNumberUpdater extends Updater{ private String pathServiceSid; private String pathSid; private Boolean isReserved; - public PhoneNumberUpdater(final String pathServiceSid, final String pathSid){ + public PhoneNumberUpdater( + final String pathServiceSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - public PhoneNumberUpdater setIsReserved(final Boolean isReserved){ + public PhoneNumberUpdater setIsReserved(final Boolean isReserved) { this.isReserved = isReserved; return this; } @Override - public PhoneNumber update(final TwilioRestClient client){ + public PhoneNumber update(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/PhoneNumbers/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.PROXY.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("PhoneNumber update failed: Unable to connect to server"); + throw new ApiConnectionException( + "PhoneNumber update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return PhoneNumber.fromJson(response.getStream(), client.getObjectMapper()); + return PhoneNumber.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (isReserved != null) { request.addPostParam("IsReserved", isReserved.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/proxy/v1/service/Session.java b/src/main/java/com/twilio/rest/proxy/v1/service/Session.java index 7f40b49246..24579d82fb 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/service/Session.java +++ b/src/main/java/com/twilio/rest/proxy/v1/service/Session.java @@ -24,55 +24,63 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Session extends Resource { + private static final long serialVersionUID = 86537474068288L; - public static SessionCreator creator(final String pathServiceSid){ + public static SessionCreator creator(final String pathServiceSid) { return new SessionCreator(pathServiceSid); } - public static SessionDeleter deleter(final String pathServiceSid, final String pathSid){ + public static SessionDeleter deleter( + final String pathServiceSid, + final String pathSid + ) { return new SessionDeleter(pathServiceSid, pathSid); } - public static SessionFetcher fetcher(final String pathServiceSid, final String pathSid){ + public static SessionFetcher fetcher( + final String pathServiceSid, + final String pathSid + ) { return new SessionFetcher(pathServiceSid, pathSid); } - public static SessionReader reader(final String pathServiceSid){ + public static SessionReader reader(final String pathServiceSid) { return new SessionReader(pathServiceSid); } - public static SessionUpdater updater(final String pathServiceSid, final String pathSid){ + public static SessionUpdater updater( + final String pathServiceSid, + final String pathSid + ) { return new SessionUpdater(pathServiceSid, pathSid); } /** - * Converts a JSON String into a Session object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Session object represented by the provided JSON - */ - public static Session fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Session object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Session object represented by the provided JSON + */ + public static Session fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Session.class); @@ -84,14 +92,17 @@ public static Session fromJson(final String json, final ObjectMapper objectMappe } /** - * Converts a JSON InputStream into a Session object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Session object represented by the provided JSON - */ - public static Session fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Session object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Session object represented by the provided JSON + */ + public static Session fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Session.class); @@ -101,6 +112,7 @@ public static Session fromJson(final InputStream json, final ObjectMapper object throw new ApiConnectionException(e.getMessage(), e); } } + public enum Mode { MESSAGE_ONLY("message-only"), VOICE_ONLY("voice-only"), @@ -121,6 +133,7 @@ public static Mode forValue(final String value) { return Promoter.enumFromString(value, Mode.values()); } } + public enum Status { OPEN("open"), IN_PROGRESS("in-progress"), @@ -163,60 +176,30 @@ public static Status forValue(final String value) { @JsonCreator private Session( - @JsonProperty("sid") - final String sid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("date_started") - final String dateStarted, - - @JsonProperty("date_ended") - final String dateEnded, - - @JsonProperty("date_last_interaction") - final String dateLastInteraction, - - @JsonProperty("date_expiry") - final String dateExpiry, - - @JsonProperty("unique_name") - final String uniqueName, - - @JsonProperty("status") - final Session.Status status, - - @JsonProperty("closed_reason") - final String closedReason, - - @JsonProperty("ttl") - final Integer ttl, - - @JsonProperty("mode") - final Session.Mode mode, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("sid") final String sid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_started") final String dateStarted, + @JsonProperty("date_ended") final String dateEnded, + @JsonProperty("date_last_interaction") final String dateLastInteraction, + @JsonProperty("date_expiry") final String dateExpiry, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("status") final Session.Status status, + @JsonProperty("closed_reason") final String closedReason, + @JsonProperty("ttl") final Integer ttl, + @JsonProperty("mode") final Session.Mode mode, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.sid = sid; this.serviceSid = serviceSid; this.accountSid = accountSid; this.dateStarted = DateConverter.iso8601DateTimeFromString(dateStarted); this.dateEnded = DateConverter.iso8601DateTimeFromString(dateEnded); - this.dateLastInteraction = DateConverter.iso8601DateTimeFromString(dateLastInteraction); + this.dateLastInteraction = + DateConverter.iso8601DateTimeFromString(dateLastInteraction); this.dateExpiry = DateConverter.iso8601DateTimeFromString(dateExpiry); this.uniqueName = uniqueName; this.status = status; @@ -229,58 +212,73 @@ private Session( this.links = links; } - public final String getSid() { - return this.sid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final ZonedDateTime getDateStarted() { - return this.dateStarted; - } - public final ZonedDateTime getDateEnded() { - return this.dateEnded; - } - public final ZonedDateTime getDateLastInteraction() { - return this.dateLastInteraction; - } - public final ZonedDateTime getDateExpiry() { - return this.dateExpiry; - } - public final String getUniqueName() { - return this.uniqueName; - } - public final Session.Status getStatus() { - return this.status; - } - public final String getClosedReason() { - return this.closedReason; - } - public final Integer getTtl() { - return this.ttl; - } - public final Session.Mode getMode() { - return this.mode; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getSid() { + return this.sid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final ZonedDateTime getDateStarted() { + return this.dateStarted; + } + + public final ZonedDateTime getDateEnded() { + return this.dateEnded; + } + + public final ZonedDateTime getDateLastInteraction() { + return this.dateLastInteraction; + } + + public final ZonedDateTime getDateExpiry() { + return this.dateExpiry; + } + + public final String getUniqueName() { + return this.uniqueName; + } + + public final Session.Status getStatus() { + return this.status; + } + + public final String getClosedReason() { + return this.closedReason; + } + + public final Integer getTtl() { + return this.ttl; + } + + public final Session.Mode getMode() { + return this.mode; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -290,13 +288,45 @@ public boolean equals(final Object o) { Session other = (Session) o; - return Objects.equals(sid, other.sid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(dateStarted, other.dateStarted) && Objects.equals(dateEnded, other.dateEnded) && Objects.equals(dateLastInteraction, other.dateLastInteraction) && Objects.equals(dateExpiry, other.dateExpiry) && Objects.equals(uniqueName, other.uniqueName) && Objects.equals(status, other.status) && Objects.equals(closedReason, other.closedReason) && Objects.equals(ttl, other.ttl) && Objects.equals(mode, other.mode) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateStarted, other.dateStarted) && + Objects.equals(dateEnded, other.dateEnded) && + Objects.equals(dateLastInteraction, other.dateLastInteraction) && + Objects.equals(dateExpiry, other.dateExpiry) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(status, other.status) && + Objects.equals(closedReason, other.closedReason) && + Objects.equals(ttl, other.ttl) && + Objects.equals(mode, other.mode) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(sid, serviceSid, accountSid, dateStarted, dateEnded, dateLastInteraction, dateExpiry, uniqueName, status, closedReason, ttl, mode, dateCreated, dateUpdated, url, links); + return Objects.hash( + sid, + serviceSid, + accountSid, + dateStarted, + dateEnded, + dateLastInteraction, + dateExpiry, + uniqueName, + status, + closedReason, + ttl, + mode, + dateCreated, + dateUpdated, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/proxy/v1/service/SessionCreator.java b/src/main/java/com/twilio/rest/proxy/v1/service/SessionCreator.java index db27239f5d..ce83350957 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/service/SessionCreator.java +++ b/src/main/java/com/twilio/rest/proxy/v1/service/SessionCreator.java @@ -15,9 +15,11 @@ package com.twilio.rest.proxy.v1.service; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; +import com.twilio.converter.Converter; +import com.twilio.converter.Converter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; -import com.twilio.converter.Converter; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; @@ -25,17 +27,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import java.util.List; -import java.util.Map; -import com.twilio.converter.Converter; import java.time.ZonedDateTime; - +import java.util.List; import java.util.List; import java.util.Map; +import java.util.Map; +public class SessionCreator extends Creator { - -public class SessionCreator extends Creator{ private String pathServiceSid; private String uniqueName; private ZonedDateTime dateExpiry; @@ -48,51 +47,71 @@ public SessionCreator(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - public SessionCreator setUniqueName(final String uniqueName){ + public SessionCreator setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - public SessionCreator setDateExpiry(final ZonedDateTime dateExpiry){ + + public SessionCreator setDateExpiry(final ZonedDateTime dateExpiry) { this.dateExpiry = dateExpiry; return this; } - public SessionCreator setTtl(final Integer ttl){ + + public SessionCreator setTtl(final Integer ttl) { this.ttl = ttl; return this; } - public SessionCreator setMode(final Session.Mode mode){ + + public SessionCreator setMode(final Session.Mode mode) { this.mode = mode; return this; } - public SessionCreator setStatus(final Session.Status status){ + + public SessionCreator setStatus(final Session.Status status) { this.status = status; return this; } - public SessionCreator setParticipants(final List> participants){ + + public SessionCreator setParticipants( + final List> participants + ) { this.participants = participants; return this; } - public SessionCreator setParticipants(final Map participants){ + + public SessionCreator setParticipants( + final Map participants + ) { return setParticipants(Promoter.listOfOne(participants)); } @Override - public Session create(final TwilioRestClient client){ + public Session create(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Sessions"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.PROXY.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Session creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Session creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -101,32 +120,30 @@ public Session create(final TwilioRestClient client){ return Session.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (uniqueName != null) { request.addPostParam("UniqueName", uniqueName); - } if (dateExpiry != null) { - request.addPostParam("DateExpiry", dateExpiry.toInstant().toString()); - + request.addPostParam( + "DateExpiry", + dateExpiry.toInstant().toString() + ); } if (ttl != null) { request.addPostParam("Ttl", ttl.toString()); - } if (mode != null) { request.addPostParam("Mode", mode.toString()); - } if (status != null) { request.addPostParam("Status", status.toString()); - } if (participants != null) { for (Map prop : participants) { request.addPostParam("Participants", Converter.mapToJson(prop)); } - } } } diff --git a/src/main/java/com/twilio/rest/proxy/v1/service/SessionDeleter.java b/src/main/java/com/twilio/rest/proxy/v1/service/SessionDeleter.java index 48e6e2d12c..7ad07ec617 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/service/SessionDeleter.java +++ b/src/main/java/com/twilio/rest/proxy/v1/service/SessionDeleter.java @@ -24,24 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class SessionDeleter extends Deleter { + private String pathServiceSid; private String pathSid; - public SessionDeleter(final String pathServiceSid, final String pathSid){ + public SessionDeleter(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Sessions/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +53,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Session delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Session delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/proxy/v1/service/SessionFetcher.java b/src/main/java/com/twilio/rest/proxy/v1/service/SessionFetcher.java index 62f195cbc2..e41e9006de 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/service/SessionFetcher.java +++ b/src/main/java/com/twilio/rest/proxy/v1/service/SessionFetcher.java @@ -24,25 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class SessionFetcher extends Fetcher { + private String pathServiceSid; private String pathSid; - public SessionFetcher(final String pathServiceSid, final String pathSid){ + public SessionFetcher(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - @Override public Session fetch(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Sessions/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,9 +53,14 @@ public Session fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Session fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Session fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/proxy/v1/service/SessionReader.java b/src/main/java/com/twilio/rest/proxy/v1/service/SessionReader.java index 6532f4a449..b52652ab29 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/service/SessionReader.java +++ b/src/main/java/com/twilio/rest/proxy/v1/service/SessionReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.proxy.v1.service; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,19 +25,17 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class SessionReader extends Reader { + private String pathServiceSid; private Integer pageSize; - public SessionReader(final String pathServiceSid){ + public SessionReader(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - public SessionReader setPageSize(final Integer pageSize){ + public SessionReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -48,7 +47,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Sessions"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -60,13 +63,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Session read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Session read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +93,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reques } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.PROXY.toString()) @@ -90,9 +104,11 @@ public Page previousPage(final Page page, final TwilioRestClie return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.PROXY.toString()) @@ -101,21 +117,21 @@ public Page nextPage(final Page page, final TwilioRestClient c } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/proxy/v1/service/SessionUpdater.java b/src/main/java/com/twilio/rest/proxy/v1/service/SessionUpdater.java index f2ef425b07..23d1e94128 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/service/SessionUpdater.java +++ b/src/main/java/com/twilio/rest/proxy/v1/service/SessionUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.proxy.v1.service; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -23,54 +24,64 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.time.ZonedDateTime; +public class SessionUpdater extends Updater { - -public class SessionUpdater extends Updater{ private String pathServiceSid; private String pathSid; private ZonedDateTime dateExpiry; private Integer ttl; private Session.Status status; - public SessionUpdater(final String pathServiceSid, final String pathSid){ + public SessionUpdater(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - public SessionUpdater setDateExpiry(final ZonedDateTime dateExpiry){ + public SessionUpdater setDateExpiry(final ZonedDateTime dateExpiry) { this.dateExpiry = dateExpiry; return this; } - public SessionUpdater setTtl(final Integer ttl){ + + public SessionUpdater setTtl(final Integer ttl) { this.ttl = ttl; return this; } - public SessionUpdater setStatus(final Session.Status status){ + + public SessionUpdater setStatus(final Session.Status status) { this.status = status; return this; } @Override - public Session update(final TwilioRestClient client){ + public Session update(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Sessions/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.PROXY.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Session update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Session update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -79,18 +90,19 @@ public Session update(final TwilioRestClient client){ return Session.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (dateExpiry != null) { - request.addPostParam("DateExpiry", dateExpiry.toInstant().toString()); - + request.addPostParam( + "DateExpiry", + dateExpiry.toInstant().toString() + ); } if (ttl != null) { request.addPostParam("Ttl", ttl.toString()); - } if (status != null) { request.addPostParam("Status", status.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/proxy/v1/service/ShortCode.java b/src/main/java/com/twilio/rest/proxy/v1/service/ShortCode.java index cdb9896210..f329ccddf9 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/service/ShortCode.java +++ b/src/main/java/com/twilio/rest/proxy/v1/service/ShortCode.java @@ -23,54 +23,65 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - +import com.twilio.type.PhoneNumberCapabilities; import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - -import com.twilio.type.PhoneNumberCapabilities; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class ShortCode extends Resource { + private static final long serialVersionUID = 222849980654127L; - public static ShortCodeCreator creator(final String pathServiceSid, final String sid){ + public static ShortCodeCreator creator( + final String pathServiceSid, + final String sid + ) { return new ShortCodeCreator(pathServiceSid, sid); } - public static ShortCodeDeleter deleter(final String pathServiceSid, final String pathSid){ + public static ShortCodeDeleter deleter( + final String pathServiceSid, + final String pathSid + ) { return new ShortCodeDeleter(pathServiceSid, pathSid); } - public static ShortCodeFetcher fetcher(final String pathServiceSid, final String pathSid){ + public static ShortCodeFetcher fetcher( + final String pathServiceSid, + final String pathSid + ) { return new ShortCodeFetcher(pathServiceSid, pathSid); } - public static ShortCodeReader reader(final String pathServiceSid){ + public static ShortCodeReader reader(final String pathServiceSid) { return new ShortCodeReader(pathServiceSid); } - public static ShortCodeUpdater updater(final String pathServiceSid, final String pathSid){ + public static ShortCodeUpdater updater( + final String pathServiceSid, + final String pathSid + ) { return new ShortCodeUpdater(pathServiceSid, pathSid); } /** - * Converts a JSON String into a ShortCode object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return ShortCode object represented by the provided JSON - */ - public static ShortCode fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a ShortCode object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return ShortCode object represented by the provided JSON + */ + public static ShortCode fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, ShortCode.class); @@ -82,14 +93,17 @@ public static ShortCode fromJson(final String json, final ObjectMapper objectMap } /** - * Converts a JSON InputStream into a ShortCode object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return ShortCode object represented by the provided JSON - */ - public static ShortCode fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a ShortCode object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return ShortCode object represented by the provided JSON + */ + public static ShortCode fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, ShortCode.class); @@ -113,35 +127,18 @@ public static ShortCode fromJson(final InputStream json, final ObjectMapper obje @JsonCreator private ShortCode( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("short_code") - final String shortCode, - - @JsonProperty("iso_country") - final String isoCountry, - - @JsonProperty("capabilities") - final PhoneNumberCapabilities capabilities, - - @JsonProperty("url") - final URI url, - - @JsonProperty("is_reserved") - final Boolean isReserved + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("short_code") final String shortCode, + @JsonProperty("iso_country") final String isoCountry, + @JsonProperty( + "capabilities" + ) final PhoneNumberCapabilities capabilities, + @JsonProperty("url") final URI url, + @JsonProperty("is_reserved") final Boolean isReserved ) { this.sid = sid; this.accountSid = accountSid; @@ -155,40 +152,49 @@ private ShortCode( this.isReserved = isReserved; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getShortCode() { - return this.shortCode; - } - public final String getIsoCountry() { - return this.isoCountry; - } - public final PhoneNumberCapabilities getCapabilities() { - return this.capabilities; - } - public final URI getUrl() { - return this.url; - } - public final Boolean getIsReserved() { - return this.isReserved; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getShortCode() { + return this.shortCode; + } + + public final String getIsoCountry() { + return this.isoCountry; + } + + public final PhoneNumberCapabilities getCapabilities() { + return this.capabilities; + } + + public final URI getUrl() { + return this.url; + } + + public final Boolean getIsReserved() { + return this.isReserved; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -198,13 +204,33 @@ public boolean equals(final Object o) { ShortCode other = (ShortCode) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(shortCode, other.shortCode) && Objects.equals(isoCountry, other.isoCountry) && Objects.equals(capabilities, other.capabilities) && Objects.equals(url, other.url) && Objects.equals(isReserved, other.isReserved) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(shortCode, other.shortCode) && + Objects.equals(isoCountry, other.isoCountry) && + Objects.equals(capabilities, other.capabilities) && + Objects.equals(url, other.url) && + Objects.equals(isReserved, other.isReserved) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, serviceSid, dateCreated, dateUpdated, shortCode, isoCountry, capabilities, url, isReserved); + return Objects.hash( + sid, + accountSid, + serviceSid, + dateCreated, + dateUpdated, + shortCode, + isoCountry, + capabilities, + url, + isReserved + ); } - } - diff --git a/src/main/java/com/twilio/rest/proxy/v1/service/ShortCodeCreator.java b/src/main/java/com/twilio/rest/proxy/v1/service/ShortCodeCreator.java index c2ef7b5d92..b33f5d9707 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/service/ShortCodeCreator.java +++ b/src/main/java/com/twilio/rest/proxy/v1/service/ShortCodeCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.proxy.v1.service; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class ShortCodeCreator extends Creator { - - -public class ShortCodeCreator extends Creator{ private String pathServiceSid; private String sid; @@ -36,41 +35,54 @@ public ShortCodeCreator(final String pathServiceSid, final String sid) { this.sid = sid; } - public ShortCodeCreator setSid(final String sid){ + public ShortCodeCreator setSid(final String sid) { this.sid = sid; return this; } @Override - public ShortCode create(final TwilioRestClient client){ + public ShortCode create(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/ShortCodes"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.sid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.sid.toString()); Request request = new Request( HttpMethod.POST, Domains.PROXY.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("ShortCode creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "ShortCode creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return ShortCode.fromJson(response.getStream(), client.getObjectMapper()); + return ShortCode.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (sid != null) { request.addPostParam("Sid", sid); - } } } diff --git a/src/main/java/com/twilio/rest/proxy/v1/service/ShortCodeDeleter.java b/src/main/java/com/twilio/rest/proxy/v1/service/ShortCodeDeleter.java index 2572c68024..a96ba191ff 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/service/ShortCodeDeleter.java +++ b/src/main/java/com/twilio/rest/proxy/v1/service/ShortCodeDeleter.java @@ -24,24 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class ShortCodeDeleter extends Deleter { + private String pathServiceSid; private String pathSid; - public ShortCodeDeleter(final String pathServiceSid, final String pathSid){ + public ShortCodeDeleter(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/ShortCodes/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +53,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("ShortCode delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "ShortCode delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/proxy/v1/service/ShortCodeFetcher.java b/src/main/java/com/twilio/rest/proxy/v1/service/ShortCodeFetcher.java index d7a3ba1905..21a5290e6d 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/service/ShortCodeFetcher.java +++ b/src/main/java/com/twilio/rest/proxy/v1/service/ShortCodeFetcher.java @@ -24,25 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class ShortCodeFetcher extends Fetcher { + private String pathServiceSid; private String pathSid; - public ShortCodeFetcher(final String pathServiceSid, final String pathSid){ + public ShortCodeFetcher(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - @Override public ShortCode fetch(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/ShortCodes/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,15 +53,23 @@ public ShortCode fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("ShortCode fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "ShortCode fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return ShortCode.fromJson(response.getStream(), client.getObjectMapper()); + return ShortCode.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/proxy/v1/service/ShortCodeReader.java b/src/main/java/com/twilio/rest/proxy/v1/service/ShortCodeReader.java index 01e0f8a08f..73f2c000c3 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/service/ShortCodeReader.java +++ b/src/main/java/com/twilio/rest/proxy/v1/service/ShortCodeReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.proxy.v1.service; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,19 +25,17 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class ShortCodeReader extends Reader { + private String pathServiceSid; private Integer pageSize; - public ShortCodeReader(final String pathServiceSid){ + public ShortCodeReader(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - public ShortCodeReader setPageSize(final Integer pageSize){ + public ShortCodeReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -48,7 +47,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/ShortCodes"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -60,13 +63,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("ShortCode read failed: Unable to connect to server"); + throw new ApiConnectionException( + "ShortCode read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +93,10 @@ private Page pageForRequest(final TwilioRestClient client, final Requ } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.PROXY.toString()) @@ -90,9 +104,11 @@ public Page previousPage(final Page page, final TwilioRest return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.PROXY.toString()) @@ -101,21 +117,21 @@ public Page nextPage(final Page page, final TwilioRestClie } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/proxy/v1/service/ShortCodeUpdater.java b/src/main/java/com/twilio/rest/proxy/v1/service/ShortCodeUpdater.java index 5f7d8ce7dc..a44945dca2 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/service/ShortCodeUpdater.java +++ b/src/main/java/com/twilio/rest/proxy/v1/service/ShortCodeUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.proxy.v1.service; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,54 +25,65 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class ShortCodeUpdater extends Updater { - - -public class ShortCodeUpdater extends Updater{ private String pathServiceSid; private String pathSid; private Boolean isReserved; - public ShortCodeUpdater(final String pathServiceSid, final String pathSid){ + public ShortCodeUpdater(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - public ShortCodeUpdater setIsReserved(final Boolean isReserved){ + public ShortCodeUpdater setIsReserved(final Boolean isReserved) { this.isReserved = isReserved; return this; } @Override - public ShortCode update(final TwilioRestClient client){ + public ShortCode update(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/ShortCodes/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.PROXY.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("ShortCode update failed: Unable to connect to server"); + throw new ApiConnectionException( + "ShortCode update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return ShortCode.fromJson(response.getStream(), client.getObjectMapper()); + return ShortCode.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (isReserved != null) { request.addPostParam("IsReserved", isReserved.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/proxy/v1/service/session/Interaction.java b/src/main/java/com/twilio/rest/proxy/v1/service/session/Interaction.java index eae6a42b64..b2f2cee78b 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/service/session/Interaction.java +++ b/src/main/java/com/twilio/rest/proxy/v1/service/session/Interaction.java @@ -24,45 +24,55 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Interaction extends Resource { + private static final long serialVersionUID = 104550389018086L; - public static InteractionDeleter deleter(final String pathServiceSid, final String pathSessionSid, final String pathSid){ + public static InteractionDeleter deleter( + final String pathServiceSid, + final String pathSessionSid, + final String pathSid + ) { return new InteractionDeleter(pathServiceSid, pathSessionSid, pathSid); } - public static InteractionFetcher fetcher(final String pathServiceSid, final String pathSessionSid, final String pathSid){ + public static InteractionFetcher fetcher( + final String pathServiceSid, + final String pathSessionSid, + final String pathSid + ) { return new InteractionFetcher(pathServiceSid, pathSessionSid, pathSid); } - public static InteractionReader reader(final String pathServiceSid, final String pathSessionSid){ + public static InteractionReader reader( + final String pathServiceSid, + final String pathSessionSid + ) { return new InteractionReader(pathServiceSid, pathSessionSid); } /** - * Converts a JSON String into a Interaction object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Interaction object represented by the provided JSON - */ - public static Interaction fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Interaction object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Interaction object represented by the provided JSON + */ + public static Interaction fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Interaction.class); @@ -74,14 +84,17 @@ public static Interaction fromJson(final String json, final ObjectMapper objectM } /** - * Converts a JSON InputStream into a Interaction object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Interaction object represented by the provided JSON - */ - public static Interaction fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Interaction object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Interaction object represented by the provided JSON + */ + public static Interaction fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Interaction.class); @@ -91,6 +104,7 @@ public static Interaction fromJson(final InputStream json, final ObjectMapper ob throw new ApiConnectionException(e.getMessage(), e); } } + public enum ResourceStatus { ACCEPTED("accepted"), ANSWERED("answered"), @@ -129,6 +143,7 @@ public static ResourceStatus forValue(final String value) { return Promoter.enumFromString(value, ResourceStatus.values()); } } + public enum Type { MESSAGE("message"), VOICE("voice"), @@ -172,62 +187,35 @@ public static Type forValue(final String value) { @JsonCreator private Interaction( - @JsonProperty("sid") - final String sid, - - @JsonProperty("session_sid") - final String sessionSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("data") - final String data, - - @JsonProperty("type") - final Interaction.Type type, - - @JsonProperty("inbound_participant_sid") - final String inboundParticipantSid, - - @JsonProperty("inbound_resource_sid") - final String inboundResourceSid, - - @JsonProperty("inbound_resource_status") - final Interaction.ResourceStatus inboundResourceStatus, - - @JsonProperty("inbound_resource_type") - final String inboundResourceType, - - @JsonProperty("inbound_resource_url") - final URI inboundResourceUrl, - - @JsonProperty("outbound_participant_sid") - final String outboundParticipantSid, - - @JsonProperty("outbound_resource_sid") - final String outboundResourceSid, - - @JsonProperty("outbound_resource_status") - final Interaction.ResourceStatus outboundResourceStatus, - - @JsonProperty("outbound_resource_type") - final String outboundResourceType, - - @JsonProperty("outbound_resource_url") - final URI outboundResourceUrl, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("session_sid") final String sessionSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("data") final String data, + @JsonProperty("type") final Interaction.Type type, + @JsonProperty( + "inbound_participant_sid" + ) final String inboundParticipantSid, + @JsonProperty("inbound_resource_sid") final String inboundResourceSid, + @JsonProperty( + "inbound_resource_status" + ) final Interaction.ResourceStatus inboundResourceStatus, + @JsonProperty("inbound_resource_type") final String inboundResourceType, + @JsonProperty("inbound_resource_url") final URI inboundResourceUrl, + @JsonProperty( + "outbound_participant_sid" + ) final String outboundParticipantSid, + @JsonProperty("outbound_resource_sid") final String outboundResourceSid, + @JsonProperty( + "outbound_resource_status" + ) final Interaction.ResourceStatus outboundResourceStatus, + @JsonProperty( + "outbound_resource_type" + ) final String outboundResourceType, + @JsonProperty("outbound_resource_url") final URI outboundResourceUrl, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url ) { this.sid = sid; this.sessionSid = sessionSid; @@ -250,67 +238,85 @@ private Interaction( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getSessionSid() { - return this.sessionSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getData() { - return this.data; - } - public final Interaction.Type getType() { - return this.type; - } - public final String getInboundParticipantSid() { - return this.inboundParticipantSid; - } - public final String getInboundResourceSid() { - return this.inboundResourceSid; - } - public final Interaction.ResourceStatus getInboundResourceStatus() { - return this.inboundResourceStatus; - } - public final String getInboundResourceType() { - return this.inboundResourceType; - } - public final URI getInboundResourceUrl() { - return this.inboundResourceUrl; - } - public final String getOutboundParticipantSid() { - return this.outboundParticipantSid; - } - public final String getOutboundResourceSid() { - return this.outboundResourceSid; - } - public final Interaction.ResourceStatus getOutboundResourceStatus() { - return this.outboundResourceStatus; - } - public final String getOutboundResourceType() { - return this.outboundResourceType; - } - public final URI getOutboundResourceUrl() { - return this.outboundResourceUrl; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getSessionSid() { + return this.sessionSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getData() { + return this.data; + } + + public final Interaction.Type getType() { + return this.type; + } + + public final String getInboundParticipantSid() { + return this.inboundParticipantSid; + } + + public final String getInboundResourceSid() { + return this.inboundResourceSid; + } + + public final Interaction.ResourceStatus getInboundResourceStatus() { + return this.inboundResourceStatus; + } + + public final String getInboundResourceType() { + return this.inboundResourceType; + } + + public final URI getInboundResourceUrl() { + return this.inboundResourceUrl; + } + + public final String getOutboundParticipantSid() { + return this.outboundParticipantSid; + } + + public final String getOutboundResourceSid() { + return this.outboundResourceSid; + } + + public final Interaction.ResourceStatus getOutboundResourceStatus() { + return this.outboundResourceStatus; + } + + public final String getOutboundResourceType() { + return this.outboundResourceType; + } + + public final URI getOutboundResourceUrl() { + return this.outboundResourceUrl; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -320,13 +326,63 @@ public boolean equals(final Object o) { Interaction other = (Interaction) o; - return Objects.equals(sid, other.sid) && Objects.equals(sessionSid, other.sessionSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(data, other.data) && Objects.equals(type, other.type) && Objects.equals(inboundParticipantSid, other.inboundParticipantSid) && Objects.equals(inboundResourceSid, other.inboundResourceSid) && Objects.equals(inboundResourceStatus, other.inboundResourceStatus) && Objects.equals(inboundResourceType, other.inboundResourceType) && Objects.equals(inboundResourceUrl, other.inboundResourceUrl) && Objects.equals(outboundParticipantSid, other.outboundParticipantSid) && Objects.equals(outboundResourceSid, other.outboundResourceSid) && Objects.equals(outboundResourceStatus, other.outboundResourceStatus) && Objects.equals(outboundResourceType, other.outboundResourceType) && Objects.equals(outboundResourceUrl, other.outboundResourceUrl) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(sessionSid, other.sessionSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(data, other.data) && + Objects.equals(type, other.type) && + Objects.equals( + inboundParticipantSid, + other.inboundParticipantSid + ) && + Objects.equals(inboundResourceSid, other.inboundResourceSid) && + Objects.equals( + inboundResourceStatus, + other.inboundResourceStatus + ) && + Objects.equals(inboundResourceType, other.inboundResourceType) && + Objects.equals(inboundResourceUrl, other.inboundResourceUrl) && + Objects.equals( + outboundParticipantSid, + other.outboundParticipantSid + ) && + Objects.equals(outboundResourceSid, other.outboundResourceSid) && + Objects.equals( + outboundResourceStatus, + other.outboundResourceStatus + ) && + Objects.equals(outboundResourceType, other.outboundResourceType) && + Objects.equals(outboundResourceUrl, other.outboundResourceUrl) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, sessionSid, serviceSid, accountSid, data, type, inboundParticipantSid, inboundResourceSid, inboundResourceStatus, inboundResourceType, inboundResourceUrl, outboundParticipantSid, outboundResourceSid, outboundResourceStatus, outboundResourceType, outboundResourceUrl, dateCreated, dateUpdated, url); + return Objects.hash( + sid, + sessionSid, + serviceSid, + accountSid, + data, + type, + inboundParticipantSid, + inboundResourceSid, + inboundResourceStatus, + inboundResourceType, + inboundResourceUrl, + outboundParticipantSid, + outboundResourceSid, + outboundResourceStatus, + outboundResourceType, + outboundResourceUrl, + dateCreated, + dateUpdated, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/proxy/v1/service/session/InteractionDeleter.java b/src/main/java/com/twilio/rest/proxy/v1/service/session/InteractionDeleter.java index 00e2c811b2..f4f6afa16c 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/service/session/InteractionDeleter.java +++ b/src/main/java/com/twilio/rest/proxy/v1/service/session/InteractionDeleter.java @@ -24,27 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class InteractionDeleter extends Deleter { + private String pathServiceSid; private String pathSessionSid; private String pathSid; - public InteractionDeleter(final String pathServiceSid, final String pathSessionSid, final String pathSid){ + public InteractionDeleter( + final String pathServiceSid, + final String pathSessionSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathSessionSid = pathSessionSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/v1/Services/{ServiceSid}/Sessions/{SessionSid}/Interactions/{Sid}"; + String path = + "/v1/Services/{ServiceSid}/Sessions/{SessionSid}/Interactions/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"SessionSid"+"}", this.pathSessionSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "SessionSid" + "}", + this.pathSessionSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -54,9 +65,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Interaction delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Interaction delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/proxy/v1/service/session/InteractionFetcher.java b/src/main/java/com/twilio/rest/proxy/v1/service/session/InteractionFetcher.java index ea06e83c47..bfbc8a076d 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/service/session/InteractionFetcher.java +++ b/src/main/java/com/twilio/rest/proxy/v1/service/session/InteractionFetcher.java @@ -24,28 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class InteractionFetcher extends Fetcher { + private String pathServiceSid; private String pathSessionSid; private String pathSid; - public InteractionFetcher(final String pathServiceSid, final String pathSessionSid, final String pathSid){ + public InteractionFetcher( + final String pathServiceSid, + final String pathSessionSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathSessionSid = pathSessionSid; this.pathSid = pathSid; } - @Override public Interaction fetch(final TwilioRestClient client) { - String path = "/v1/Services/{ServiceSid}/Sessions/{SessionSid}/Interactions/{Sid}"; + String path = + "/v1/Services/{ServiceSid}/Sessions/{SessionSid}/Interactions/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"SessionSid"+"}", this.pathSessionSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "SessionSid" + "}", + this.pathSessionSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -55,15 +65,23 @@ public Interaction fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Interaction fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Interaction fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Interaction.fromJson(response.getStream(), client.getObjectMapper()); + return Interaction.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/proxy/v1/service/session/InteractionReader.java b/src/main/java/com/twilio/rest/proxy/v1/service/session/InteractionReader.java index 61f1d9c86a..757be47ff4 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/service/session/InteractionReader.java +++ b/src/main/java/com/twilio/rest/proxy/v1/service/session/InteractionReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.proxy.v1.service.session; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,21 +25,22 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class InteractionReader extends Reader { + private String pathServiceSid; private String pathSessionSid; private Integer pageSize; - public InteractionReader(final String pathServiceSid, final String pathSessionSid){ + public InteractionReader( + final String pathServiceSid, + final String pathSessionSid + ) { this.pathServiceSid = pathServiceSid; this.pathSessionSid = pathSessionSid; } - public InteractionReader setPageSize(final Integer pageSize){ + public InteractionReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -49,9 +51,18 @@ public ResourceSet read(final TwilioRestClient client) { } public Page firstPage(final TwilioRestClient client) { - String path = "/v1/Services/{ServiceSid}/Sessions/{SessionSid}/Interactions"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"SessionSid"+"}", this.pathSessionSid.toString()); + String path = + "/v1/Services/{ServiceSid}/Sessions/{SessionSid}/Interactions"; + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "SessionSid" + "}", + this.pathSessionSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -63,13 +74,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Interaction read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Interaction read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -85,7 +104,10 @@ private Page pageForRequest(final TwilioRestClient client, final Re } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.PROXY.toString()) @@ -93,9 +115,11 @@ public Page previousPage(final Page page, final Twilio return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.PROXY.toString()) @@ -104,21 +128,21 @@ public Page nextPage(final Page page, final TwilioRest } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/proxy/v1/service/session/Participant.java b/src/main/java/com/twilio/rest/proxy/v1/service/session/Participant.java index 0dc4789182..dc56bc5c04 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/service/session/Participant.java +++ b/src/main/java/com/twilio/rest/proxy/v1/service/session/Participant.java @@ -23,51 +23,69 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Participant extends Resource { + private static final long serialVersionUID = 85413043665121L; - public static ParticipantCreator creator(final String pathServiceSid, final String pathSessionSid, final String identifier){ - return new ParticipantCreator(pathServiceSid, pathSessionSid, identifier); + public static ParticipantCreator creator( + final String pathServiceSid, + final String pathSessionSid, + final String identifier + ) { + return new ParticipantCreator( + pathServiceSid, + pathSessionSid, + identifier + ); } - public static ParticipantDeleter deleter(final String pathServiceSid, final String pathSessionSid, final String pathSid){ + public static ParticipantDeleter deleter( + final String pathServiceSid, + final String pathSessionSid, + final String pathSid + ) { return new ParticipantDeleter(pathServiceSid, pathSessionSid, pathSid); } - public static ParticipantFetcher fetcher(final String pathServiceSid, final String pathSessionSid, final String pathSid){ + public static ParticipantFetcher fetcher( + final String pathServiceSid, + final String pathSessionSid, + final String pathSid + ) { return new ParticipantFetcher(pathServiceSid, pathSessionSid, pathSid); } - public static ParticipantReader reader(final String pathServiceSid, final String pathSessionSid){ + public static ParticipantReader reader( + final String pathServiceSid, + final String pathSessionSid + ) { return new ParticipantReader(pathServiceSid, pathSessionSid); } /** - * Converts a JSON String into a Participant object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Participant object represented by the provided JSON - */ - public static Participant fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Participant object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Participant object represented by the provided JSON + */ + public static Participant fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Participant.class); @@ -79,14 +97,17 @@ public static Participant fromJson(final String json, final ObjectMapper objectM } /** - * Converts a JSON InputStream into a Participant object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Participant object represented by the provided JSON - */ - public static Participant fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Participant object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Participant object represented by the provided JSON + */ + public static Participant fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Participant.class); @@ -113,44 +134,19 @@ public static Participant fromJson(final InputStream json, final ObjectMapper ob @JsonCreator private Participant( - @JsonProperty("sid") - final String sid, - - @JsonProperty("session_sid") - final String sessionSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("identifier") - final String identifier, - - @JsonProperty("proxy_identifier") - final String proxyIdentifier, - - @JsonProperty("proxy_identifier_sid") - final String proxyIdentifierSid, - - @JsonProperty("date_deleted") - final String dateDeleted, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("sid") final String sid, + @JsonProperty("session_sid") final String sessionSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("identifier") final String identifier, + @JsonProperty("proxy_identifier") final String proxyIdentifier, + @JsonProperty("proxy_identifier_sid") final String proxyIdentifierSid, + @JsonProperty("date_deleted") final String dateDeleted, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.sid = sid; this.sessionSid = sessionSid; @@ -167,49 +163,61 @@ private Participant( this.links = links; } - public final String getSid() { - return this.sid; - } - public final String getSessionSid() { - return this.sessionSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getIdentifier() { - return this.identifier; - } - public final String getProxyIdentifier() { - return this.proxyIdentifier; - } - public final String getProxyIdentifierSid() { - return this.proxyIdentifierSid; - } - public final ZonedDateTime getDateDeleted() { - return this.dateDeleted; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getSid() { + return this.sid; + } + + public final String getSessionSid() { + return this.sessionSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getIdentifier() { + return this.identifier; + } + + public final String getProxyIdentifier() { + return this.proxyIdentifier; + } + + public final String getProxyIdentifierSid() { + return this.proxyIdentifierSid; + } + + public final ZonedDateTime getDateDeleted() { + return this.dateDeleted; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -219,13 +227,39 @@ public boolean equals(final Object o) { Participant other = (Participant) o; - return Objects.equals(sid, other.sid) && Objects.equals(sessionSid, other.sessionSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(identifier, other.identifier) && Objects.equals(proxyIdentifier, other.proxyIdentifier) && Objects.equals(proxyIdentifierSid, other.proxyIdentifierSid) && Objects.equals(dateDeleted, other.dateDeleted) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(sessionSid, other.sessionSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(identifier, other.identifier) && + Objects.equals(proxyIdentifier, other.proxyIdentifier) && + Objects.equals(proxyIdentifierSid, other.proxyIdentifierSid) && + Objects.equals(dateDeleted, other.dateDeleted) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(sid, sessionSid, serviceSid, accountSid, friendlyName, identifier, proxyIdentifier, proxyIdentifierSid, dateDeleted, dateCreated, dateUpdated, url, links); + return Objects.hash( + sid, + sessionSid, + serviceSid, + accountSid, + friendlyName, + identifier, + proxyIdentifier, + proxyIdentifierSid, + dateDeleted, + dateCreated, + dateUpdated, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/proxy/v1/service/session/ParticipantCreator.java b/src/main/java/com/twilio/rest/proxy/v1/service/session/ParticipantCreator.java index a225b08791..6cc6f97a44 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/service/session/ParticipantCreator.java +++ b/src/main/java/com/twilio/rest/proxy/v1/service/session/ParticipantCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.proxy.v1.service.session; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class ParticipantCreator extends Creator { - - -public class ParticipantCreator extends Creator{ private String pathServiceSid; private String pathSessionSid; private String identifier; @@ -35,72 +34,97 @@ public class ParticipantCreator extends Creator{ private String proxyIdentifier; private String proxyIdentifierSid; - public ParticipantCreator(final String pathServiceSid, final String pathSessionSid, final String identifier) { + public ParticipantCreator( + final String pathServiceSid, + final String pathSessionSid, + final String identifier + ) { this.pathServiceSid = pathServiceSid; this.pathSessionSid = pathSessionSid; this.identifier = identifier; } - public ParticipantCreator setIdentifier(final String identifier){ + public ParticipantCreator setIdentifier(final String identifier) { this.identifier = identifier; return this; } - public ParticipantCreator setFriendlyName(final String friendlyName){ + + public ParticipantCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public ParticipantCreator setProxyIdentifier(final String proxyIdentifier){ + + public ParticipantCreator setProxyIdentifier(final String proxyIdentifier) { this.proxyIdentifier = proxyIdentifier; return this; } - public ParticipantCreator setProxyIdentifierSid(final String proxyIdentifierSid){ + + public ParticipantCreator setProxyIdentifierSid( + final String proxyIdentifierSid + ) { this.proxyIdentifierSid = proxyIdentifierSid; return this; } @Override - public Participant create(final TwilioRestClient client){ - String path = "/v1/Services/{ServiceSid}/Sessions/{SessionSid}/Participants"; + public Participant create(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Sessions/{SessionSid}/Participants"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"SessionSid"+"}", this.pathSessionSid.toString()); - path = path.replace("{"+"Identifier"+"}", this.identifier.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "SessionSid" + "}", + this.pathSessionSid.toString() + ); + path = + path.replace("{" + "Identifier" + "}", this.identifier.toString()); Request request = new Request( HttpMethod.POST, Domains.PROXY.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Participant creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Participant creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Participant.fromJson(response.getStream(), client.getObjectMapper()); + return Participant.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (identifier != null) { request.addPostParam("Identifier", identifier); - } if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (proxyIdentifier != null) { request.addPostParam("ProxyIdentifier", proxyIdentifier); - } if (proxyIdentifierSid != null) { request.addPostParam("ProxyIdentifierSid", proxyIdentifierSid); - } } } diff --git a/src/main/java/com/twilio/rest/proxy/v1/service/session/ParticipantDeleter.java b/src/main/java/com/twilio/rest/proxy/v1/service/session/ParticipantDeleter.java index 287bb3840f..1af9e60850 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/service/session/ParticipantDeleter.java +++ b/src/main/java/com/twilio/rest/proxy/v1/service/session/ParticipantDeleter.java @@ -24,27 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class ParticipantDeleter extends Deleter { + private String pathServiceSid; private String pathSessionSid; private String pathSid; - public ParticipantDeleter(final String pathServiceSid, final String pathSessionSid, final String pathSid){ + public ParticipantDeleter( + final String pathServiceSid, + final String pathSessionSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathSessionSid = pathSessionSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/v1/Services/{ServiceSid}/Sessions/{SessionSid}/Participants/{Sid}"; + String path = + "/v1/Services/{ServiceSid}/Sessions/{SessionSid}/Participants/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"SessionSid"+"}", this.pathSessionSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "SessionSid" + "}", + this.pathSessionSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -54,9 +65,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Participant delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Participant delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/proxy/v1/service/session/ParticipantFetcher.java b/src/main/java/com/twilio/rest/proxy/v1/service/session/ParticipantFetcher.java index bb5a2b58ad..2f55a92998 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/service/session/ParticipantFetcher.java +++ b/src/main/java/com/twilio/rest/proxy/v1/service/session/ParticipantFetcher.java @@ -24,28 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class ParticipantFetcher extends Fetcher { + private String pathServiceSid; private String pathSessionSid; private String pathSid; - public ParticipantFetcher(final String pathServiceSid, final String pathSessionSid, final String pathSid){ + public ParticipantFetcher( + final String pathServiceSid, + final String pathSessionSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathSessionSid = pathSessionSid; this.pathSid = pathSid; } - @Override public Participant fetch(final TwilioRestClient client) { - String path = "/v1/Services/{ServiceSid}/Sessions/{SessionSid}/Participants/{Sid}"; + String path = + "/v1/Services/{ServiceSid}/Sessions/{SessionSid}/Participants/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"SessionSid"+"}", this.pathSessionSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "SessionSid" + "}", + this.pathSessionSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -55,15 +65,23 @@ public Participant fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Participant fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Participant fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Participant.fromJson(response.getStream(), client.getObjectMapper()); + return Participant.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/proxy/v1/service/session/ParticipantReader.java b/src/main/java/com/twilio/rest/proxy/v1/service/session/ParticipantReader.java index 4bf0ceffc0..676b88cb54 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/service/session/ParticipantReader.java +++ b/src/main/java/com/twilio/rest/proxy/v1/service/session/ParticipantReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.proxy.v1.service.session; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,21 +25,22 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class ParticipantReader extends Reader { + private String pathServiceSid; private String pathSessionSid; private Integer pageSize; - public ParticipantReader(final String pathServiceSid, final String pathSessionSid){ + public ParticipantReader( + final String pathServiceSid, + final String pathSessionSid + ) { this.pathServiceSid = pathServiceSid; this.pathSessionSid = pathSessionSid; } - public ParticipantReader setPageSize(final Integer pageSize){ + public ParticipantReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -49,9 +51,18 @@ public ResourceSet read(final TwilioRestClient client) { } public Page firstPage(final TwilioRestClient client) { - String path = "/v1/Services/{ServiceSid}/Sessions/{SessionSid}/Participants"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"SessionSid"+"}", this.pathSessionSid.toString()); + String path = + "/v1/Services/{ServiceSid}/Sessions/{SessionSid}/Participants"; + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "SessionSid" + "}", + this.pathSessionSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -63,13 +74,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Participant read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Participant read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -85,7 +104,10 @@ private Page pageForRequest(final TwilioRestClient client, final Re } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.PROXY.toString()) @@ -93,9 +115,11 @@ public Page previousPage(final Page page, final Twilio return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.PROXY.toString()) @@ -104,21 +128,21 @@ public Page nextPage(final Page page, final TwilioRest } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/proxy/v1/service/session/participant/MessageInteraction.java b/src/main/java/com/twilio/rest/proxy/v1/service/session/participant/MessageInteraction.java index 52bee5cfce..ef345800cf 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/service/session/participant/MessageInteraction.java +++ b/src/main/java/com/twilio/rest/proxy/v1/service/session/participant/MessageInteraction.java @@ -24,49 +24,87 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.List; import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class MessageInteraction extends Resource { + private static final long serialVersionUID = 183572948894378L; - public static MessageInteractionCreator creator(final String pathServiceSid, final String pathSessionSid, final String pathParticipantSid, final String body){ - return new MessageInteractionCreator(pathServiceSid, pathSessionSid, pathParticipantSid, body); + public static MessageInteractionCreator creator( + final String pathServiceSid, + final String pathSessionSid, + final String pathParticipantSid, + final String body + ) { + return new MessageInteractionCreator( + pathServiceSid, + pathSessionSid, + pathParticipantSid, + body + ); } - public static MessageInteractionCreator creator(final String pathServiceSid, final String pathSessionSid, final String pathParticipantSid, final List mediaUrl){ - return new MessageInteractionCreator(pathServiceSid, pathSessionSid, pathParticipantSid, mediaUrl); + + public static MessageInteractionCreator creator( + final String pathServiceSid, + final String pathSessionSid, + final String pathParticipantSid, + final List mediaUrl + ) { + return new MessageInteractionCreator( + pathServiceSid, + pathSessionSid, + pathParticipantSid, + mediaUrl + ); } - public static MessageInteractionFetcher fetcher(final String pathServiceSid, final String pathSessionSid, final String pathParticipantSid, final String pathSid){ - return new MessageInteractionFetcher(pathServiceSid, pathSessionSid, pathParticipantSid, pathSid); + public static MessageInteractionFetcher fetcher( + final String pathServiceSid, + final String pathSessionSid, + final String pathParticipantSid, + final String pathSid + ) { + return new MessageInteractionFetcher( + pathServiceSid, + pathSessionSid, + pathParticipantSid, + pathSid + ); } - public static MessageInteractionReader reader(final String pathServiceSid, final String pathSessionSid, final String pathParticipantSid){ - return new MessageInteractionReader(pathServiceSid, pathSessionSid, pathParticipantSid); + public static MessageInteractionReader reader( + final String pathServiceSid, + final String pathSessionSid, + final String pathParticipantSid + ) { + return new MessageInteractionReader( + pathServiceSid, + pathSessionSid, + pathParticipantSid + ); } /** - * Converts a JSON String into a MessageInteraction object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return MessageInteraction object represented by the provided JSON - */ - public static MessageInteraction fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a MessageInteraction object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return MessageInteraction object represented by the provided JSON + */ + public static MessageInteraction fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, MessageInteraction.class); @@ -78,14 +116,17 @@ public static MessageInteraction fromJson(final String json, final ObjectMapper } /** - * Converts a JSON InputStream into a MessageInteraction object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return MessageInteraction object represented by the provided JSON - */ - public static MessageInteraction fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a MessageInteraction object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return MessageInteraction object represented by the provided JSON + */ + public static MessageInteraction fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, MessageInteraction.class); @@ -95,6 +136,7 @@ public static MessageInteraction fromJson(final InputStream json, final ObjectMa throw new ApiConnectionException(e.getMessage(), e); } } + public enum ResourceStatus { ACCEPTED("accepted"), ANSWERED("answered"), @@ -133,6 +175,7 @@ public static ResourceStatus forValue(final String value) { return Promoter.enumFromString(value, ResourceStatus.values()); } } + public enum Type { MESSAGE("message"), VOICE("voice"), @@ -177,65 +220,36 @@ public static Type forValue(final String value) { @JsonCreator private MessageInteraction( - @JsonProperty("sid") - final String sid, - - @JsonProperty("session_sid") - final String sessionSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("data") - final String data, - - @JsonProperty("type") - final MessageInteraction.Type type, - - @JsonProperty("participant_sid") - final String participantSid, - - @JsonProperty("inbound_participant_sid") - final String inboundParticipantSid, - - @JsonProperty("inbound_resource_sid") - final String inboundResourceSid, - - @JsonProperty("inbound_resource_status") - final MessageInteraction.ResourceStatus inboundResourceStatus, - - @JsonProperty("inbound_resource_type") - final String inboundResourceType, - - @JsonProperty("inbound_resource_url") - final URI inboundResourceUrl, - - @JsonProperty("outbound_participant_sid") - final String outboundParticipantSid, - - @JsonProperty("outbound_resource_sid") - final String outboundResourceSid, - - @JsonProperty("outbound_resource_status") - final MessageInteraction.ResourceStatus outboundResourceStatus, - - @JsonProperty("outbound_resource_type") - final String outboundResourceType, - - @JsonProperty("outbound_resource_url") - final URI outboundResourceUrl, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("session_sid") final String sessionSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("data") final String data, + @JsonProperty("type") final MessageInteraction.Type type, + @JsonProperty("participant_sid") final String participantSid, + @JsonProperty( + "inbound_participant_sid" + ) final String inboundParticipantSid, + @JsonProperty("inbound_resource_sid") final String inboundResourceSid, + @JsonProperty( + "inbound_resource_status" + ) final MessageInteraction.ResourceStatus inboundResourceStatus, + @JsonProperty("inbound_resource_type") final String inboundResourceType, + @JsonProperty("inbound_resource_url") final URI inboundResourceUrl, + @JsonProperty( + "outbound_participant_sid" + ) final String outboundParticipantSid, + @JsonProperty("outbound_resource_sid") final String outboundResourceSid, + @JsonProperty( + "outbound_resource_status" + ) final MessageInteraction.ResourceStatus outboundResourceStatus, + @JsonProperty( + "outbound_resource_type" + ) final String outboundResourceType, + @JsonProperty("outbound_resource_url") final URI outboundResourceUrl, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url ) { this.sid = sid; this.sessionSid = sessionSid; @@ -259,70 +273,89 @@ private MessageInteraction( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getSessionSid() { - return this.sessionSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getData() { - return this.data; - } - public final MessageInteraction.Type getType() { - return this.type; - } - public final String getParticipantSid() { - return this.participantSid; - } - public final String getInboundParticipantSid() { - return this.inboundParticipantSid; - } - public final String getInboundResourceSid() { - return this.inboundResourceSid; - } - public final MessageInteraction.ResourceStatus getInboundResourceStatus() { - return this.inboundResourceStatus; - } - public final String getInboundResourceType() { - return this.inboundResourceType; - } - public final URI getInboundResourceUrl() { - return this.inboundResourceUrl; - } - public final String getOutboundParticipantSid() { - return this.outboundParticipantSid; - } - public final String getOutboundResourceSid() { - return this.outboundResourceSid; - } - public final MessageInteraction.ResourceStatus getOutboundResourceStatus() { - return this.outboundResourceStatus; - } - public final String getOutboundResourceType() { - return this.outboundResourceType; - } - public final URI getOutboundResourceUrl() { - return this.outboundResourceUrl; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getSessionSid() { + return this.sessionSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getData() { + return this.data; + } + + public final MessageInteraction.Type getType() { + return this.type; + } + + public final String getParticipantSid() { + return this.participantSid; + } + + public final String getInboundParticipantSid() { + return this.inboundParticipantSid; + } + + public final String getInboundResourceSid() { + return this.inboundResourceSid; + } + + public final MessageInteraction.ResourceStatus getInboundResourceStatus() { + return this.inboundResourceStatus; + } + + public final String getInboundResourceType() { + return this.inboundResourceType; + } + + public final URI getInboundResourceUrl() { + return this.inboundResourceUrl; + } + + public final String getOutboundParticipantSid() { + return this.outboundParticipantSid; + } + + public final String getOutboundResourceSid() { + return this.outboundResourceSid; + } + + public final MessageInteraction.ResourceStatus getOutboundResourceStatus() { + return this.outboundResourceStatus; + } + + public final String getOutboundResourceType() { + return this.outboundResourceType; + } + + public final URI getOutboundResourceUrl() { + return this.outboundResourceUrl; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -332,13 +365,65 @@ public boolean equals(final Object o) { MessageInteraction other = (MessageInteraction) o; - return Objects.equals(sid, other.sid) && Objects.equals(sessionSid, other.sessionSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(data, other.data) && Objects.equals(type, other.type) && Objects.equals(participantSid, other.participantSid) && Objects.equals(inboundParticipantSid, other.inboundParticipantSid) && Objects.equals(inboundResourceSid, other.inboundResourceSid) && Objects.equals(inboundResourceStatus, other.inboundResourceStatus) && Objects.equals(inboundResourceType, other.inboundResourceType) && Objects.equals(inboundResourceUrl, other.inboundResourceUrl) && Objects.equals(outboundParticipantSid, other.outboundParticipantSid) && Objects.equals(outboundResourceSid, other.outboundResourceSid) && Objects.equals(outboundResourceStatus, other.outboundResourceStatus) && Objects.equals(outboundResourceType, other.outboundResourceType) && Objects.equals(outboundResourceUrl, other.outboundResourceUrl) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(sessionSid, other.sessionSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(data, other.data) && + Objects.equals(type, other.type) && + Objects.equals(participantSid, other.participantSid) && + Objects.equals( + inboundParticipantSid, + other.inboundParticipantSid + ) && + Objects.equals(inboundResourceSid, other.inboundResourceSid) && + Objects.equals( + inboundResourceStatus, + other.inboundResourceStatus + ) && + Objects.equals(inboundResourceType, other.inboundResourceType) && + Objects.equals(inboundResourceUrl, other.inboundResourceUrl) && + Objects.equals( + outboundParticipantSid, + other.outboundParticipantSid + ) && + Objects.equals(outboundResourceSid, other.outboundResourceSid) && + Objects.equals( + outboundResourceStatus, + other.outboundResourceStatus + ) && + Objects.equals(outboundResourceType, other.outboundResourceType) && + Objects.equals(outboundResourceUrl, other.outboundResourceUrl) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, sessionSid, serviceSid, accountSid, data, type, participantSid, inboundParticipantSid, inboundResourceSid, inboundResourceStatus, inboundResourceType, inboundResourceUrl, outboundParticipantSid, outboundResourceSid, outboundResourceStatus, outboundResourceType, outboundResourceUrl, dateCreated, dateUpdated, url); + return Objects.hash( + sid, + sessionSid, + serviceSid, + accountSid, + data, + type, + participantSid, + inboundParticipantSid, + inboundResourceSid, + inboundResourceStatus, + inboundResourceType, + inboundResourceUrl, + outboundParticipantSid, + outboundResourceSid, + outboundResourceStatus, + outboundResourceType, + outboundResourceUrl, + dateCreated, + dateUpdated, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/proxy/v1/service/session/participant/MessageInteractionCreator.java b/src/main/java/com/twilio/rest/proxy/v1/service/session/participant/MessageInteractionCreator.java index e18a99ec37..cd1f531c39 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/service/session/participant/MessageInteractionCreator.java +++ b/src/main/java/com/twilio/rest/proxy/v1/service/session/participant/MessageInteractionCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.proxy.v1.service.session.participant; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -24,87 +25,119 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import java.util.List; import java.net.URI; - +import java.net.URI; +import java.util.List; import java.util.List; +public class MessageInteractionCreator extends Creator { -import java.net.URI; - -public class MessageInteractionCreator extends Creator{ private String pathServiceSid; private String pathSessionSid; private String pathParticipantSid; private String body; private List mediaUrl; - public MessageInteractionCreator(final String pathServiceSid, final String pathSessionSid, final String pathParticipantSid, final String body) { + public MessageInteractionCreator( + final String pathServiceSid, + final String pathSessionSid, + final String pathParticipantSid, + final String body + ) { this.pathServiceSid = pathServiceSid; this.pathSessionSid = pathSessionSid; this.pathParticipantSid = pathParticipantSid; this.body = body; } - public MessageInteractionCreator(final String pathServiceSid, final String pathSessionSid, final String pathParticipantSid, final List mediaUrl) { + + public MessageInteractionCreator( + final String pathServiceSid, + final String pathSessionSid, + final String pathParticipantSid, + final List mediaUrl + ) { this.pathServiceSid = pathServiceSid; this.pathSessionSid = pathSessionSid; this.pathParticipantSid = pathParticipantSid; this.mediaUrl = mediaUrl; } - public MessageInteractionCreator setBody(final String body){ + public MessageInteractionCreator setBody(final String body) { this.body = body; return this; } - public MessageInteractionCreator setMediaUrl(final List mediaUrl){ + + public MessageInteractionCreator setMediaUrl(final List mediaUrl) { this.mediaUrl = mediaUrl; return this; } - public MessageInteractionCreator setMediaUrl(final URI mediaUrl){ + + public MessageInteractionCreator setMediaUrl(final URI mediaUrl) { return setMediaUrl(Promoter.listOfOne(mediaUrl)); } - public MessageInteractionCreator setMediaUrl(final String mediaUrl){ + public MessageInteractionCreator setMediaUrl(final String mediaUrl) { return setMediaUrl(Promoter.uriFromString(mediaUrl)); } @Override - public MessageInteraction create(final TwilioRestClient client){ - String path = "/v1/Services/{ServiceSid}/Sessions/{SessionSid}/Participants/{ParticipantSid}/MessageInteractions"; + public MessageInteraction create(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Sessions/{SessionSid}/Participants/{ParticipantSid}/MessageInteractions"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"SessionSid"+"}", this.pathSessionSid.toString()); - path = path.replace("{"+"ParticipantSid"+"}", this.pathParticipantSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "SessionSid" + "}", + this.pathSessionSid.toString() + ); + path = + path.replace( + "{" + "ParticipantSid" + "}", + this.pathParticipantSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.PROXY.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("MessageInteraction creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "MessageInteraction creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return MessageInteraction.fromJson(response.getStream(), client.getObjectMapper()); + return MessageInteraction.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (body != null) { request.addPostParam("Body", body); - } if (mediaUrl != null) { for (URI prop : mediaUrl) { request.addPostParam("MediaUrl", prop.toString()); } - } } } diff --git a/src/main/java/com/twilio/rest/proxy/v1/service/session/participant/MessageInteractionFetcher.java b/src/main/java/com/twilio/rest/proxy/v1/service/session/participant/MessageInteractionFetcher.java index ca99ef1e36..8c8d8e5949 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/service/session/participant/MessageInteractionFetcher.java +++ b/src/main/java/com/twilio/rest/proxy/v1/service/session/participant/MessageInteractionFetcher.java @@ -24,31 +24,46 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class MessageInteractionFetcher extends Fetcher { + private String pathServiceSid; private String pathSessionSid; private String pathParticipantSid; private String pathSid; - public MessageInteractionFetcher(final String pathServiceSid, final String pathSessionSid, final String pathParticipantSid, final String pathSid){ + public MessageInteractionFetcher( + final String pathServiceSid, + final String pathSessionSid, + final String pathParticipantSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathSessionSid = pathSessionSid; this.pathParticipantSid = pathParticipantSid; this.pathSid = pathSid; } - @Override public MessageInteraction fetch(final TwilioRestClient client) { - String path = "/v1/Services/{ServiceSid}/Sessions/{SessionSid}/Participants/{ParticipantSid}/MessageInteractions/{Sid}"; + String path = + "/v1/Services/{ServiceSid}/Sessions/{SessionSid}/Participants/{ParticipantSid}/MessageInteractions/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"SessionSid"+"}", this.pathSessionSid.toString()); - path = path.replace("{"+"ParticipantSid"+"}", this.pathParticipantSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "SessionSid" + "}", + this.pathSessionSid.toString() + ); + path = + path.replace( + "{" + "ParticipantSid" + "}", + this.pathParticipantSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -58,15 +73,23 @@ public MessageInteraction fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("MessageInteraction fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "MessageInteraction fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return MessageInteraction.fromJson(response.getStream(), client.getObjectMapper()); + return MessageInteraction.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/proxy/v1/service/session/participant/MessageInteractionReader.java b/src/main/java/com/twilio/rest/proxy/v1/service/session/participant/MessageInteractionReader.java index 167a7ddec1..101e0507e6 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/service/session/participant/MessageInteractionReader.java +++ b/src/main/java/com/twilio/rest/proxy/v1/service/session/participant/MessageInteractionReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.proxy.v1.service.session.participant; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,23 +25,25 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class MessageInteractionReader extends Reader { + private String pathServiceSid; private String pathSessionSid; private String pathParticipantSid; private Integer pageSize; - public MessageInteractionReader(final String pathServiceSid, final String pathSessionSid, final String pathParticipantSid){ + public MessageInteractionReader( + final String pathServiceSid, + final String pathSessionSid, + final String pathParticipantSid + ) { this.pathServiceSid = pathServiceSid; this.pathSessionSid = pathSessionSid; this.pathParticipantSid = pathParticipantSid; } - public MessageInteractionReader setPageSize(final Integer pageSize){ + public MessageInteractionReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -51,10 +54,23 @@ public ResourceSet read(final TwilioRestClient client) { } public Page firstPage(final TwilioRestClient client) { - String path = "/v1/Services/{ServiceSid}/Sessions/{SessionSid}/Participants/{ParticipantSid}/MessageInteractions"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"SessionSid"+"}", this.pathSessionSid.toString()); - path = path.replace("{"+"ParticipantSid"+"}", this.pathParticipantSid.toString()); + String path = + "/v1/Services/{ServiceSid}/Sessions/{SessionSid}/Participants/{ParticipantSid}/MessageInteractions"; + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "SessionSid" + "}", + this.pathSessionSid.toString() + ); + path = + path.replace( + "{" + "ParticipantSid" + "}", + this.pathParticipantSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -66,13 +82,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("MessageInteraction read failed: Unable to connect to server"); + throw new ApiConnectionException( + "MessageInteraction read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -88,7 +112,10 @@ private Page pageForRequest(final TwilioRestClient client, f } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.PROXY.toString()) @@ -96,9 +123,11 @@ public Page previousPage(final Page page return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.PROXY.toString()) @@ -107,21 +136,21 @@ public Page nextPage(final Page page, fi } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/routes/v2/PhoneNumber.java b/src/main/java/com/twilio/rest/routes/v2/PhoneNumber.java index b293fc0e4b..66aacca932 100644 --- a/src/main/java/com/twilio/rest/routes/v2/PhoneNumber.java +++ b/src/main/java/com/twilio/rest/routes/v2/PhoneNumber.java @@ -23,41 +23,40 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class PhoneNumber extends Resource { + private static final long serialVersionUID = 213320512216415L; - public static PhoneNumberFetcher fetcher(final String pathPhoneNumber){ + public static PhoneNumberFetcher fetcher(final String pathPhoneNumber) { return new PhoneNumberFetcher(pathPhoneNumber); } - public static PhoneNumberUpdater updater(final String pathPhoneNumber){ + public static PhoneNumberUpdater updater(final String pathPhoneNumber) { return new PhoneNumberUpdater(pathPhoneNumber); } /** - * Converts a JSON String into a PhoneNumber object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return PhoneNumber object represented by the provided JSON - */ - public static PhoneNumber fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a PhoneNumber object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return PhoneNumber object represented by the provided JSON + */ + public static PhoneNumber fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, PhoneNumber.class); @@ -69,14 +68,17 @@ public static PhoneNumber fromJson(final String json, final ObjectMapper objectM } /** - * Converts a JSON InputStream into a PhoneNumber object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return PhoneNumber object represented by the provided JSON - */ - public static PhoneNumber fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a PhoneNumber object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return PhoneNumber object represented by the provided JSON + */ + public static PhoneNumber fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, PhoneNumber.class); @@ -98,29 +100,14 @@ public static PhoneNumber fromJson(final InputStream json, final ObjectMapper ob @JsonCreator private PhoneNumber( - @JsonProperty("phone_number") - final String phoneNumber, - - @JsonProperty("url") - final URI url, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("voice_region") - final String voiceRegion, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated + @JsonProperty("phone_number") final String phoneNumber, + @JsonProperty("url") final URI url, + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("voice_region") final String voiceRegion, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated ) { this.phoneNumber = phoneNumber; this.url = url; @@ -132,34 +119,41 @@ private PhoneNumber( this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); } - public final String getPhoneNumber() { - return this.phoneNumber; - } - public final URI getUrl() { - return this.url; - } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getVoiceRegion() { - return this.voiceRegion; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } + public final String getPhoneNumber() { + return this.phoneNumber; + } + + public final URI getUrl() { + return this.url; + } + + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getVoiceRegion() { + return this.voiceRegion; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -169,13 +163,29 @@ public boolean equals(final Object o) { PhoneNumber other = (PhoneNumber) o; - return Objects.equals(phoneNumber, other.phoneNumber) && Objects.equals(url, other.url) && Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(voiceRegion, other.voiceRegion) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) ; + return ( + Objects.equals(phoneNumber, other.phoneNumber) && + Objects.equals(url, other.url) && + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(voiceRegion, other.voiceRegion) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) + ); } @Override public int hashCode() { - return Objects.hash(phoneNumber, url, sid, accountSid, friendlyName, voiceRegion, dateCreated, dateUpdated); + return Objects.hash( + phoneNumber, + url, + sid, + accountSid, + friendlyName, + voiceRegion, + dateCreated, + dateUpdated + ); } - } - diff --git a/src/main/java/com/twilio/rest/routes/v2/PhoneNumberFetcher.java b/src/main/java/com/twilio/rest/routes/v2/PhoneNumberFetcher.java index d7c1fb9017..df73b8caa4 100644 --- a/src/main/java/com/twilio/rest/routes/v2/PhoneNumberFetcher.java +++ b/src/main/java/com/twilio/rest/routes/v2/PhoneNumberFetcher.java @@ -24,22 +24,23 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class PhoneNumberFetcher extends Fetcher { + private String pathPhoneNumber; - public PhoneNumberFetcher(final String pathPhoneNumber){ + public PhoneNumberFetcher(final String pathPhoneNumber) { this.pathPhoneNumber = pathPhoneNumber; } - @Override public PhoneNumber fetch(final TwilioRestClient client) { String path = "/v2/PhoneNumbers/{PhoneNumber}"; - path = path.replace("{"+"PhoneNumber"+"}", this.pathPhoneNumber.toString()); + path = + path.replace( + "{" + "PhoneNumber" + "}", + this.pathPhoneNumber.toString() + ); Request request = new Request( HttpMethod.GET, @@ -49,15 +50,23 @@ public PhoneNumber fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("PhoneNumber fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "PhoneNumber fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return PhoneNumber.fromJson(response.getStream(), client.getObjectMapper()); + return PhoneNumber.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/routes/v2/PhoneNumberUpdater.java b/src/main/java/com/twilio/rest/routes/v2/PhoneNumberUpdater.java index 8801a5c0a6..cf982bec2b 100644 --- a/src/main/java/com/twilio/rest/routes/v2/PhoneNumberUpdater.java +++ b/src/main/java/com/twilio/rest/routes/v2/PhoneNumberUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.routes.v2; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,60 +25,71 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class PhoneNumberUpdater extends Updater { - - -public class PhoneNumberUpdater extends Updater{ private String pathPhoneNumber; private String voiceRegion; private String friendlyName; - public PhoneNumberUpdater(final String pathPhoneNumber){ + public PhoneNumberUpdater(final String pathPhoneNumber) { this.pathPhoneNumber = pathPhoneNumber; } - public PhoneNumberUpdater setVoiceRegion(final String voiceRegion){ + public PhoneNumberUpdater setVoiceRegion(final String voiceRegion) { this.voiceRegion = voiceRegion; return this; } - public PhoneNumberUpdater setFriendlyName(final String friendlyName){ + + public PhoneNumberUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } @Override - public PhoneNumber update(final TwilioRestClient client){ + public PhoneNumber update(final TwilioRestClient client) { String path = "/v2/PhoneNumbers/{PhoneNumber}"; - path = path.replace("{"+"PhoneNumber"+"}", this.pathPhoneNumber.toString()); + path = + path.replace( + "{" + "PhoneNumber" + "}", + this.pathPhoneNumber.toString() + ); Request request = new Request( HttpMethod.POST, Domains.ROUTES.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("PhoneNumber update failed: Unable to connect to server"); + throw new ApiConnectionException( + "PhoneNumber update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return PhoneNumber.fromJson(response.getStream(), client.getObjectMapper()); + return PhoneNumber.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (voiceRegion != null) { request.addPostParam("VoiceRegion", voiceRegion); - } if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } } } diff --git a/src/main/java/com/twilio/rest/routes/v2/SipDomain.java b/src/main/java/com/twilio/rest/routes/v2/SipDomain.java index b4b545f6a5..c1f8dd1129 100644 --- a/src/main/java/com/twilio/rest/routes/v2/SipDomain.java +++ b/src/main/java/com/twilio/rest/routes/v2/SipDomain.java @@ -23,41 +23,40 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class SipDomain extends Resource { + private static final long serialVersionUID = 81903226613345L; - public static SipDomainFetcher fetcher(final String pathSipDomain){ + public static SipDomainFetcher fetcher(final String pathSipDomain) { return new SipDomainFetcher(pathSipDomain); } - public static SipDomainUpdater updater(final String pathSipDomain){ + public static SipDomainUpdater updater(final String pathSipDomain) { return new SipDomainUpdater(pathSipDomain); } /** - * Converts a JSON String into a SipDomain object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return SipDomain object represented by the provided JSON - */ - public static SipDomain fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a SipDomain object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return SipDomain object represented by the provided JSON + */ + public static SipDomain fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SipDomain.class); @@ -69,14 +68,17 @@ public static SipDomain fromJson(final String json, final ObjectMapper objectMap } /** - * Converts a JSON InputStream into a SipDomain object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return SipDomain object represented by the provided JSON - */ - public static SipDomain fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a SipDomain object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return SipDomain object represented by the provided JSON + */ + public static SipDomain fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SipDomain.class); @@ -98,29 +100,14 @@ public static SipDomain fromJson(final InputStream json, final ObjectMapper obje @JsonCreator private SipDomain( - @JsonProperty("sip_domain") - final String sipDomain, - - @JsonProperty("url") - final URI url, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("voice_region") - final String voiceRegion, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated + @JsonProperty("sip_domain") final String sipDomain, + @JsonProperty("url") final URI url, + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("voice_region") final String voiceRegion, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated ) { this.sipDomain = sipDomain; this.url = url; @@ -132,34 +119,41 @@ private SipDomain( this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); } - public final String getSipDomain() { - return this.sipDomain; - } - public final URI getUrl() { - return this.url; - } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getVoiceRegion() { - return this.voiceRegion; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } + public final String getSipDomain() { + return this.sipDomain; + } + + public final URI getUrl() { + return this.url; + } + + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getVoiceRegion() { + return this.voiceRegion; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -169,13 +163,29 @@ public boolean equals(final Object o) { SipDomain other = (SipDomain) o; - return Objects.equals(sipDomain, other.sipDomain) && Objects.equals(url, other.url) && Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(voiceRegion, other.voiceRegion) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) ; + return ( + Objects.equals(sipDomain, other.sipDomain) && + Objects.equals(url, other.url) && + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(voiceRegion, other.voiceRegion) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) + ); } @Override public int hashCode() { - return Objects.hash(sipDomain, url, sid, accountSid, friendlyName, voiceRegion, dateCreated, dateUpdated); + return Objects.hash( + sipDomain, + url, + sid, + accountSid, + friendlyName, + voiceRegion, + dateCreated, + dateUpdated + ); } - } - diff --git a/src/main/java/com/twilio/rest/routes/v2/SipDomainFetcher.java b/src/main/java/com/twilio/rest/routes/v2/SipDomainFetcher.java index 36d043061f..0a94f307c5 100644 --- a/src/main/java/com/twilio/rest/routes/v2/SipDomainFetcher.java +++ b/src/main/java/com/twilio/rest/routes/v2/SipDomainFetcher.java @@ -24,22 +24,23 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class SipDomainFetcher extends Fetcher { + private String pathSipDomain; - public SipDomainFetcher(final String pathSipDomain){ + public SipDomainFetcher(final String pathSipDomain) { this.pathSipDomain = pathSipDomain; } - @Override public SipDomain fetch(final TwilioRestClient client) { String path = "/v2/SipDomains/{SipDomain}"; - path = path.replace("{"+"SipDomain"+"}", this.pathSipDomain.toString()); + path = + path.replace( + "{" + "SipDomain" + "}", + this.pathSipDomain.toString() + ); Request request = new Request( HttpMethod.GET, @@ -49,15 +50,23 @@ public SipDomain fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SipDomain fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "SipDomain fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return SipDomain.fromJson(response.getStream(), client.getObjectMapper()); + return SipDomain.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/routes/v2/SipDomainUpdater.java b/src/main/java/com/twilio/rest/routes/v2/SipDomainUpdater.java index 620d17ccb7..a1079b826d 100644 --- a/src/main/java/com/twilio/rest/routes/v2/SipDomainUpdater.java +++ b/src/main/java/com/twilio/rest/routes/v2/SipDomainUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.routes.v2; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,60 +25,71 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class SipDomainUpdater extends Updater { - - -public class SipDomainUpdater extends Updater{ private String pathSipDomain; private String voiceRegion; private String friendlyName; - public SipDomainUpdater(final String pathSipDomain){ + public SipDomainUpdater(final String pathSipDomain) { this.pathSipDomain = pathSipDomain; } - public SipDomainUpdater setVoiceRegion(final String voiceRegion){ + public SipDomainUpdater setVoiceRegion(final String voiceRegion) { this.voiceRegion = voiceRegion; return this; } - public SipDomainUpdater setFriendlyName(final String friendlyName){ + + public SipDomainUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } @Override - public SipDomain update(final TwilioRestClient client){ + public SipDomain update(final TwilioRestClient client) { String path = "/v2/SipDomains/{SipDomain}"; - path = path.replace("{"+"SipDomain"+"}", this.pathSipDomain.toString()); + path = + path.replace( + "{" + "SipDomain" + "}", + this.pathSipDomain.toString() + ); Request request = new Request( HttpMethod.POST, Domains.ROUTES.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SipDomain update failed: Unable to connect to server"); + throw new ApiConnectionException( + "SipDomain update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return SipDomain.fromJson(response.getStream(), client.getObjectMapper()); + return SipDomain.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (voiceRegion != null) { request.addPostParam("VoiceRegion", voiceRegion); - } if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } } } diff --git a/src/main/java/com/twilio/rest/routes/v2/Trunk.java b/src/main/java/com/twilio/rest/routes/v2/Trunk.java index ad6c11857c..590a1494bf 100644 --- a/src/main/java/com/twilio/rest/routes/v2/Trunk.java +++ b/src/main/java/com/twilio/rest/routes/v2/Trunk.java @@ -23,41 +23,40 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Trunk extends Resource { + private static final long serialVersionUID = 71100118275281L; - public static TrunkFetcher fetcher(final String pathSipTrunkDomain){ + public static TrunkFetcher fetcher(final String pathSipTrunkDomain) { return new TrunkFetcher(pathSipTrunkDomain); } - public static TrunkUpdater updater(final String pathSipTrunkDomain){ + public static TrunkUpdater updater(final String pathSipTrunkDomain) { return new TrunkUpdater(pathSipTrunkDomain); } /** - * Converts a JSON String into a Trunk object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Trunk object represented by the provided JSON - */ - public static Trunk fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Trunk object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Trunk object represented by the provided JSON + */ + public static Trunk fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Trunk.class); @@ -69,14 +68,17 @@ public static Trunk fromJson(final String json, final ObjectMapper objectMapper) } /** - * Converts a JSON InputStream into a Trunk object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Trunk object represented by the provided JSON - */ - public static Trunk fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Trunk object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Trunk object represented by the provided JSON + */ + public static Trunk fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Trunk.class); @@ -98,29 +100,14 @@ public static Trunk fromJson(final InputStream json, final ObjectMapper objectMa @JsonCreator private Trunk( - @JsonProperty("sip_trunk_domain") - final String sipTrunkDomain, - - @JsonProperty("url") - final URI url, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("voice_region") - final String voiceRegion, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated + @JsonProperty("sip_trunk_domain") final String sipTrunkDomain, + @JsonProperty("url") final URI url, + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("voice_region") final String voiceRegion, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated ) { this.sipTrunkDomain = sipTrunkDomain; this.url = url; @@ -132,34 +119,41 @@ private Trunk( this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); } - public final String getSipTrunkDomain() { - return this.sipTrunkDomain; - } - public final URI getUrl() { - return this.url; - } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getVoiceRegion() { - return this.voiceRegion; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } + public final String getSipTrunkDomain() { + return this.sipTrunkDomain; + } + + public final URI getUrl() { + return this.url; + } + + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getVoiceRegion() { + return this.voiceRegion; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -169,13 +163,29 @@ public boolean equals(final Object o) { Trunk other = (Trunk) o; - return Objects.equals(sipTrunkDomain, other.sipTrunkDomain) && Objects.equals(url, other.url) && Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(voiceRegion, other.voiceRegion) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) ; + return ( + Objects.equals(sipTrunkDomain, other.sipTrunkDomain) && + Objects.equals(url, other.url) && + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(voiceRegion, other.voiceRegion) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) + ); } @Override public int hashCode() { - return Objects.hash(sipTrunkDomain, url, sid, accountSid, friendlyName, voiceRegion, dateCreated, dateUpdated); + return Objects.hash( + sipTrunkDomain, + url, + sid, + accountSid, + friendlyName, + voiceRegion, + dateCreated, + dateUpdated + ); } - } - diff --git a/src/main/java/com/twilio/rest/routes/v2/TrunkFetcher.java b/src/main/java/com/twilio/rest/routes/v2/TrunkFetcher.java index 3ba7935183..1902f7ad4e 100644 --- a/src/main/java/com/twilio/rest/routes/v2/TrunkFetcher.java +++ b/src/main/java/com/twilio/rest/routes/v2/TrunkFetcher.java @@ -24,22 +24,23 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class TrunkFetcher extends Fetcher { + private String pathSipTrunkDomain; - public TrunkFetcher(final String pathSipTrunkDomain){ + public TrunkFetcher(final String pathSipTrunkDomain) { this.pathSipTrunkDomain = pathSipTrunkDomain; } - @Override public Trunk fetch(final TwilioRestClient client) { String path = "/v2/Trunks/{SipTrunkDomain}"; - path = path.replace("{"+"SipTrunkDomain"+"}", this.pathSipTrunkDomain.toString()); + path = + path.replace( + "{" + "SipTrunkDomain" + "}", + this.pathSipTrunkDomain.toString() + ); Request request = new Request( HttpMethod.GET, @@ -49,9 +50,14 @@ public Trunk fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Trunk fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Trunk fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/routes/v2/TrunkUpdater.java b/src/main/java/com/twilio/rest/routes/v2/TrunkUpdater.java index da2c86ac73..14afe4e7af 100644 --- a/src/main/java/com/twilio/rest/routes/v2/TrunkUpdater.java +++ b/src/main/java/com/twilio/rest/routes/v2/TrunkUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.routes.v2; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,44 +25,53 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class TrunkUpdater extends Updater { - - -public class TrunkUpdater extends Updater{ private String pathSipTrunkDomain; private String voiceRegion; private String friendlyName; - public TrunkUpdater(final String pathSipTrunkDomain){ + public TrunkUpdater(final String pathSipTrunkDomain) { this.pathSipTrunkDomain = pathSipTrunkDomain; } - public TrunkUpdater setVoiceRegion(final String voiceRegion){ + public TrunkUpdater setVoiceRegion(final String voiceRegion) { this.voiceRegion = voiceRegion; return this; } - public TrunkUpdater setFriendlyName(final String friendlyName){ + + public TrunkUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } @Override - public Trunk update(final TwilioRestClient client){ + public Trunk update(final TwilioRestClient client) { String path = "/v2/Trunks/{SipTrunkDomain}"; - path = path.replace("{"+"SipTrunkDomain"+"}", this.pathSipTrunkDomain.toString()); + path = + path.replace( + "{" + "SipTrunkDomain" + "}", + this.pathSipTrunkDomain.toString() + ); Request request = new Request( HttpMethod.POST, Domains.ROUTES.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Trunk update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Trunk update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -70,14 +80,13 @@ public Trunk update(final TwilioRestClient client){ return Trunk.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (voiceRegion != null) { request.addPostParam("VoiceRegion", voiceRegion); - } if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } } } diff --git a/src/main/java/com/twilio/rest/serverless/v1/Service.java b/src/main/java/com/twilio/rest/serverless/v1/Service.java index 239272ec23..4ecb0ac584 100644 --- a/src/main/java/com/twilio/rest/serverless/v1/Service.java +++ b/src/main/java/com/twilio/rest/serverless/v1/Service.java @@ -23,55 +23,57 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Service extends Resource { + private static final long serialVersionUID = 60847550969739L; - public static ServiceCreator creator(final String uniqueName, final String friendlyName){ + public static ServiceCreator creator( + final String uniqueName, + final String friendlyName + ) { return new ServiceCreator(uniqueName, friendlyName); } - public static ServiceDeleter deleter(final String pathSid){ + public static ServiceDeleter deleter(final String pathSid) { return new ServiceDeleter(pathSid); } - public static ServiceFetcher fetcher(final String pathSid){ + public static ServiceFetcher fetcher(final String pathSid) { return new ServiceFetcher(pathSid); } - public static ServiceReader reader(){ + public static ServiceReader reader() { return new ServiceReader(); } - public static ServiceUpdater updater(final String pathSid){ + public static ServiceUpdater updater(final String pathSid) { return new ServiceUpdater(pathSid); } /** - * Converts a JSON String into a Service object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Service object represented by the provided JSON - */ - public static Service fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Service object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Service object represented by the provided JSON + */ + public static Service fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Service.class); @@ -83,14 +85,17 @@ public static Service fromJson(final String json, final ObjectMapper objectMappe } /** - * Converts a JSON InputStream into a Service object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Service object represented by the provided JSON - */ - public static Service fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Service object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Service object represented by the provided JSON + */ + public static Service fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Service.class); @@ -115,38 +120,17 @@ public static Service fromJson(final InputStream json, final ObjectMapper object @JsonCreator private Service( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("unique_name") - final String uniqueName, - - @JsonProperty("include_credentials") - final Boolean includeCredentials, - - @JsonProperty("ui_editable") - final Boolean uiEditable, - - @JsonProperty("domain_base") - final String domainBase, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("include_credentials") final Boolean includeCredentials, + @JsonProperty("ui_editable") final Boolean uiEditable, + @JsonProperty("domain_base") final String domainBase, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.sid = sid; this.accountSid = accountSid; @@ -161,43 +145,53 @@ private Service( this.links = links; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getUniqueName() { - return this.uniqueName; - } - public final Boolean getIncludeCredentials() { - return this.includeCredentials; - } - public final Boolean getUiEditable() { - return this.uiEditable; - } - public final String getDomainBase() { - return this.domainBase; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getUniqueName() { + return this.uniqueName; + } + + public final Boolean getIncludeCredentials() { + return this.includeCredentials; + } + + public final Boolean getUiEditable() { + return this.uiEditable; + } + + public final String getDomainBase() { + return this.domainBase; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -207,13 +201,35 @@ public boolean equals(final Object o) { Service other = (Service) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(uniqueName, other.uniqueName) && Objects.equals(includeCredentials, other.includeCredentials) && Objects.equals(uiEditable, other.uiEditable) && Objects.equals(domainBase, other.domainBase) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(includeCredentials, other.includeCredentials) && + Objects.equals(uiEditable, other.uiEditable) && + Objects.equals(domainBase, other.domainBase) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, friendlyName, uniqueName, includeCredentials, uiEditable, domainBase, dateCreated, dateUpdated, url, links); + return Objects.hash( + sid, + accountSid, + friendlyName, + uniqueName, + includeCredentials, + uiEditable, + domainBase, + dateCreated, + dateUpdated, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/serverless/v1/ServiceCreator.java b/src/main/java/com/twilio/rest/serverless/v1/ServiceCreator.java index afd77703ee..14cd3220d8 100644 --- a/src/main/java/com/twilio/rest/serverless/v1/ServiceCreator.java +++ b/src/main/java/com/twilio/rest/serverless/v1/ServiceCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.serverless.v1; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class ServiceCreator extends Creator { - - -public class ServiceCreator extends Creator{ private String uniqueName; private String friendlyName; private Boolean includeCredentials; @@ -38,41 +37,57 @@ public ServiceCreator(final String uniqueName, final String friendlyName) { this.friendlyName = friendlyName; } - public ServiceCreator setUniqueName(final String uniqueName){ + public ServiceCreator setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - public ServiceCreator setFriendlyName(final String friendlyName){ + + public ServiceCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public ServiceCreator setIncludeCredentials(final Boolean includeCredentials){ + + public ServiceCreator setIncludeCredentials( + final Boolean includeCredentials + ) { this.includeCredentials = includeCredentials; return this; } - public ServiceCreator setUiEditable(final Boolean uiEditable){ + + public ServiceCreator setUiEditable(final Boolean uiEditable) { this.uiEditable = uiEditable; return this; } @Override - public Service create(final TwilioRestClient client){ + public Service create(final TwilioRestClient client) { String path = "/v1/Services"; - path = path.replace("{"+"UniqueName"+"}", this.uniqueName.toString()); - path = path.replace("{"+"FriendlyName"+"}", this.friendlyName.toString()); + path = + path.replace("{" + "UniqueName" + "}", this.uniqueName.toString()); + path = + path.replace( + "{" + "FriendlyName" + "}", + this.friendlyName.toString() + ); Request request = new Request( HttpMethod.POST, Domains.SERVERLESS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -81,22 +96,22 @@ public Service create(final TwilioRestClient client){ return Service.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (uniqueName != null) { request.addPostParam("UniqueName", uniqueName); - } if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (includeCredentials != null) { - request.addPostParam("IncludeCredentials", includeCredentials.toString()); - + request.addPostParam( + "IncludeCredentials", + includeCredentials.toString() + ); } if (uiEditable != null) { request.addPostParam("UiEditable", uiEditable.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/serverless/v1/ServiceDeleter.java b/src/main/java/com/twilio/rest/serverless/v1/ServiceDeleter.java index 36cb4ebff7..dcdfd992c2 100644 --- a/src/main/java/com/twilio/rest/serverless/v1/ServiceDeleter.java +++ b/src/main/java/com/twilio/rest/serverless/v1/ServiceDeleter.java @@ -24,21 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class ServiceDeleter extends Deleter { + private String pathSid; - public ServiceDeleter(final String pathSid){ + public ServiceDeleter(final String pathSid) { this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Services/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -48,9 +46,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/serverless/v1/ServiceFetcher.java b/src/main/java/com/twilio/rest/serverless/v1/ServiceFetcher.java index d53d99c998..87b5e2504b 100644 --- a/src/main/java/com/twilio/rest/serverless/v1/ServiceFetcher.java +++ b/src/main/java/com/twilio/rest/serverless/v1/ServiceFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class ServiceFetcher extends Fetcher { + private String pathSid; - public ServiceFetcher(final String pathSid){ + public ServiceFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public Service fetch(final TwilioRestClient client) { String path = "/v1/Services/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,9 +46,14 @@ public Service fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/serverless/v1/ServiceReader.java b/src/main/java/com/twilio/rest/serverless/v1/ServiceReader.java index 4317e96686..39f7d42431 100644 --- a/src/main/java/com/twilio/rest/serverless/v1/ServiceReader.java +++ b/src/main/java/com/twilio/rest/serverless/v1/ServiceReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.serverless.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,17 +25,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class ServiceReader extends Reader { + private Integer pageSize; - public ServiceReader(){ - } + public ServiceReader() {} - public ServiceReader setPageSize(final Integer pageSize){ + public ServiceReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -57,13 +55,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -79,7 +85,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reques } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.SERVERLESS.toString()) @@ -87,9 +96,11 @@ public Page previousPage(final Page page, final TwilioRestClie return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.SERVERLESS.toString()) @@ -98,21 +109,21 @@ public Page nextPage(final Page page, final TwilioRestClient c } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/serverless/v1/ServiceUpdater.java b/src/main/java/com/twilio/rest/serverless/v1/ServiceUpdater.java index 36227c99c7..bde33acf62 100644 --- a/src/main/java/com/twilio/rest/serverless/v1/ServiceUpdater.java +++ b/src/main/java/com/twilio/rest/serverless/v1/ServiceUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.serverless.v1; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,49 +25,57 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class ServiceUpdater extends Updater { - - -public class ServiceUpdater extends Updater{ private String pathSid; private Boolean includeCredentials; private String friendlyName; private Boolean uiEditable; - public ServiceUpdater(final String pathSid){ + public ServiceUpdater(final String pathSid) { this.pathSid = pathSid; } - public ServiceUpdater setIncludeCredentials(final Boolean includeCredentials){ + public ServiceUpdater setIncludeCredentials( + final Boolean includeCredentials + ) { this.includeCredentials = includeCredentials; return this; } - public ServiceUpdater setFriendlyName(final String friendlyName){ + + public ServiceUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public ServiceUpdater setUiEditable(final Boolean uiEditable){ + + public ServiceUpdater setUiEditable(final Boolean uiEditable) { this.uiEditable = uiEditable; return this; } @Override - public Service update(final TwilioRestClient client){ + public Service update(final TwilioRestClient client) { String path = "/v1/Services/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.SERVERLESS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -75,18 +84,19 @@ public Service update(final TwilioRestClient client){ return Service.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (includeCredentials != null) { - request.addPostParam("IncludeCredentials", includeCredentials.toString()); - + request.addPostParam( + "IncludeCredentials", + includeCredentials.toString() + ); } if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (uiEditable != null) { request.addPostParam("UiEditable", uiEditable.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/Asset.java b/src/main/java/com/twilio/rest/serverless/v1/service/Asset.java index 0bad5a526e..0778553bf6 100644 --- a/src/main/java/com/twilio/rest/serverless/v1/service/Asset.java +++ b/src/main/java/com/twilio/rest/serverless/v1/service/Asset.java @@ -23,55 +23,67 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Asset extends Resource { + private static final long serialVersionUID = 60673471687127L; - public static AssetCreator creator(final String pathServiceSid, final String friendlyName){ + public static AssetCreator creator( + final String pathServiceSid, + final String friendlyName + ) { return new AssetCreator(pathServiceSid, friendlyName); } - public static AssetDeleter deleter(final String pathServiceSid, final String pathSid){ + public static AssetDeleter deleter( + final String pathServiceSid, + final String pathSid + ) { return new AssetDeleter(pathServiceSid, pathSid); } - public static AssetFetcher fetcher(final String pathServiceSid, final String pathSid){ + public static AssetFetcher fetcher( + final String pathServiceSid, + final String pathSid + ) { return new AssetFetcher(pathServiceSid, pathSid); } - public static AssetReader reader(final String pathServiceSid){ + public static AssetReader reader(final String pathServiceSid) { return new AssetReader(pathServiceSid); } - public static AssetUpdater updater(final String pathServiceSid, final String pathSid, final String friendlyName){ + public static AssetUpdater updater( + final String pathServiceSid, + final String pathSid, + final String friendlyName + ) { return new AssetUpdater(pathServiceSid, pathSid, friendlyName); } /** - * Converts a JSON String into a Asset object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Asset object represented by the provided JSON - */ - public static Asset fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Asset object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Asset object represented by the provided JSON + */ + public static Asset fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Asset.class); @@ -83,14 +95,17 @@ public static Asset fromJson(final String json, final ObjectMapper objectMapper) } /** - * Converts a JSON InputStream into a Asset object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Asset object represented by the provided JSON - */ - public static Asset fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Asset object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Asset object represented by the provided JSON + */ + public static Asset fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Asset.class); @@ -112,29 +127,14 @@ public static Asset fromJson(final InputStream json, final ObjectMapper objectMa @JsonCreator private Asset( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.sid = sid; this.accountSid = accountSid; @@ -146,34 +146,41 @@ private Asset( this.links = links; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -183,13 +190,29 @@ public boolean equals(final Object o) { Asset other = (Asset) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, serviceSid, friendlyName, dateCreated, dateUpdated, url, links); + return Objects.hash( + sid, + accountSid, + serviceSid, + friendlyName, + dateCreated, + dateUpdated, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/AssetCreator.java b/src/main/java/com/twilio/rest/serverless/v1/service/AssetCreator.java index e7e290fe67..22b08ea062 100644 --- a/src/main/java/com/twilio/rest/serverless/v1/service/AssetCreator.java +++ b/src/main/java/com/twilio/rest/serverless/v1/service/AssetCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.serverless.v1.service; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,41 +25,56 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class AssetCreator extends Creator { - - -public class AssetCreator extends Creator{ private String pathServiceSid; private String friendlyName; - public AssetCreator(final String pathServiceSid, final String friendlyName) { + public AssetCreator( + final String pathServiceSid, + final String friendlyName + ) { this.pathServiceSid = pathServiceSid; this.friendlyName = friendlyName; } - public AssetCreator setFriendlyName(final String friendlyName){ + public AssetCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } @Override - public Asset create(final TwilioRestClient client){ + public Asset create(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Assets"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"FriendlyName"+"}", this.friendlyName.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "FriendlyName" + "}", + this.friendlyName.toString() + ); Request request = new Request( HttpMethod.POST, Domains.SERVERLESS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Asset creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Asset creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -67,10 +83,10 @@ public Asset create(final TwilioRestClient client){ return Asset.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } } } diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/AssetDeleter.java b/src/main/java/com/twilio/rest/serverless/v1/service/AssetDeleter.java index 21fd6b8853..18cf016a88 100644 --- a/src/main/java/com/twilio/rest/serverless/v1/service/AssetDeleter.java +++ b/src/main/java/com/twilio/rest/serverless/v1/service/AssetDeleter.java @@ -24,24 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class AssetDeleter extends Deleter { + private String pathServiceSid; private String pathSid; - public AssetDeleter(final String pathServiceSid, final String pathSid){ + public AssetDeleter(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Assets/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +53,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Asset delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Asset delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/AssetFetcher.java b/src/main/java/com/twilio/rest/serverless/v1/service/AssetFetcher.java index 6e9e3e6367..c3fe33e618 100644 --- a/src/main/java/com/twilio/rest/serverless/v1/service/AssetFetcher.java +++ b/src/main/java/com/twilio/rest/serverless/v1/service/AssetFetcher.java @@ -24,25 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class AssetFetcher extends Fetcher { + private String pathServiceSid; private String pathSid; - public AssetFetcher(final String pathServiceSid, final String pathSid){ + public AssetFetcher(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - @Override public Asset fetch(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Assets/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,9 +53,14 @@ public Asset fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Asset fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Asset fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/AssetReader.java b/src/main/java/com/twilio/rest/serverless/v1/service/AssetReader.java index 100af1181b..216d589b21 100644 --- a/src/main/java/com/twilio/rest/serverless/v1/service/AssetReader.java +++ b/src/main/java/com/twilio/rest/serverless/v1/service/AssetReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.serverless.v1.service; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,19 +25,17 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class AssetReader extends Reader { + private String pathServiceSid; private Integer pageSize; - public AssetReader(final String pathServiceSid){ + public AssetReader(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - public AssetReader setPageSize(final Integer pageSize){ + public AssetReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -48,7 +47,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Assets"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -60,13 +63,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Asset read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Asset read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +93,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.SERVERLESS.toString()) @@ -90,9 +104,11 @@ public Page previousPage(final Page page, final TwilioRestClient c return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.SERVERLESS.toString()) @@ -101,21 +117,21 @@ public Page nextPage(final Page page, final TwilioRestClient clien } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/AssetUpdater.java b/src/main/java/com/twilio/rest/serverless/v1/service/AssetUpdater.java index b1a646d4ee..ada608178e 100644 --- a/src/main/java/com/twilio/rest/serverless/v1/service/AssetUpdater.java +++ b/src/main/java/com/twilio/rest/serverless/v1/service/AssetUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.serverless.v1.service; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,44 +25,60 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class AssetUpdater extends Updater { - - -public class AssetUpdater extends Updater{ private String pathServiceSid; private String pathSid; private String friendlyName; - public AssetUpdater(final String pathServiceSid, final String pathSid, final String friendlyName){ + public AssetUpdater( + final String pathServiceSid, + final String pathSid, + final String friendlyName + ) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; this.friendlyName = friendlyName; } - public AssetUpdater setFriendlyName(final String friendlyName){ + public AssetUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } @Override - public Asset update(final TwilioRestClient client){ + public Asset update(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Assets/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); - path = path.replace("{"+"FriendlyName"+"}", this.friendlyName.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + path = + path.replace( + "{" + "FriendlyName" + "}", + this.friendlyName.toString() + ); Request request = new Request( HttpMethod.POST, Domains.SERVERLESS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Asset update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Asset update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -70,10 +87,10 @@ public Asset update(final TwilioRestClient client){ return Asset.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } } } diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/Build.java b/src/main/java/com/twilio/rest/serverless/v1/service/Build.java index ca195c71b9..af81ffcc69 100644 --- a/src/main/java/com/twilio/rest/serverless/v1/service/Build.java +++ b/src/main/java/com/twilio/rest/serverless/v1/service/Build.java @@ -24,52 +24,57 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.List; import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Build extends Resource { + private static final long serialVersionUID = 76818411121781L; - public static BuildCreator creator(final String pathServiceSid){ + public static BuildCreator creator(final String pathServiceSid) { return new BuildCreator(pathServiceSid); } - public static BuildDeleter deleter(final String pathServiceSid, final String pathSid){ + public static BuildDeleter deleter( + final String pathServiceSid, + final String pathSid + ) { return new BuildDeleter(pathServiceSid, pathSid); } - public static BuildFetcher fetcher(final String pathServiceSid, final String pathSid){ + public static BuildFetcher fetcher( + final String pathServiceSid, + final String pathSid + ) { return new BuildFetcher(pathServiceSid, pathSid); } - public static BuildReader reader(final String pathServiceSid){ + public static BuildReader reader(final String pathServiceSid) { return new BuildReader(pathServiceSid); } /** - * Converts a JSON String into a Build object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Build object represented by the provided JSON - */ - public static Build fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Build object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Build object represented by the provided JSON + */ + public static Build fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Build.class); @@ -81,14 +86,17 @@ public static Build fromJson(final String json, final ObjectMapper objectMapper) } /** - * Converts a JSON InputStream into a Build object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Build object represented by the provided JSON - */ - public static Build fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Build object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Build object represented by the provided JSON + */ + public static Build fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Build.class); @@ -98,6 +106,7 @@ public static Build fromJson(final InputStream json, final ObjectMapper objectMa throw new ApiConnectionException(e.getMessage(), e); } } + public enum Runtime { NODE8("node8"), NODE10("node10"), @@ -120,6 +129,7 @@ public static Runtime forValue(final String value) { return Promoter.enumFromString(value, Runtime.values()); } } + public enum Status { BUILDING("building"), COMPLETED("completed"), @@ -156,41 +166,24 @@ public static Status forValue(final String value) { @JsonCreator private Build( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("status") - final Build.Status status, - - @JsonProperty("asset_versions") - final List> assetVersions, - - @JsonProperty("function_versions") - final List> functionVersions, - - @JsonProperty("dependencies") - final List> dependencies, - - @JsonProperty("runtime") - final Build.Runtime runtime, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("status") final Build.Status status, + @JsonProperty( + "asset_versions" + ) final List> assetVersions, + @JsonProperty( + "function_versions" + ) final List> functionVersions, + @JsonProperty( + "dependencies" + ) final List> dependencies, + @JsonProperty("runtime") final Build.Runtime runtime, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.sid = sid; this.accountSid = accountSid; @@ -206,46 +199,57 @@ private Build( this.links = links; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final Build.Status getStatus() { - return this.status; - } - public final List> getAssetVersions() { - return this.assetVersions; - } - public final List> getFunctionVersions() { - return this.functionVersions; - } - public final List> getDependencies() { - return this.dependencies; - } - public final Build.Runtime getRuntime() { - return this.runtime; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final Build.Status getStatus() { + return this.status; + } + + public final List> getAssetVersions() { + return this.assetVersions; + } + + public final List> getFunctionVersions() { + return this.functionVersions; + } + + public final List> getDependencies() { + return this.dependencies; + } + + public final Build.Runtime getRuntime() { + return this.runtime; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -255,13 +259,37 @@ public boolean equals(final Object o) { Build other = (Build) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(status, other.status) && Objects.equals(assetVersions, other.assetVersions) && Objects.equals(functionVersions, other.functionVersions) && Objects.equals(dependencies, other.dependencies) && Objects.equals(runtime, other.runtime) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(status, other.status) && + Objects.equals(assetVersions, other.assetVersions) && + Objects.equals(functionVersions, other.functionVersions) && + Objects.equals(dependencies, other.dependencies) && + Objects.equals(runtime, other.runtime) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, serviceSid, status, assetVersions, functionVersions, dependencies, runtime, dateCreated, dateUpdated, url, links); + return Objects.hash( + sid, + accountSid, + serviceSid, + status, + assetVersions, + functionVersions, + dependencies, + runtime, + dateCreated, + dateUpdated, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/BuildCreator.java b/src/main/java/com/twilio/rest/serverless/v1/service/BuildCreator.java index 9610a5c58d..e325659f30 100644 --- a/src/main/java/com/twilio/rest/serverless/v1/service/BuildCreator.java +++ b/src/main/java/com/twilio/rest/serverless/v1/service/BuildCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.serverless.v1.service; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -25,12 +26,10 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.util.List; - import java.util.List; +public class BuildCreator extends Creator { - -public class BuildCreator extends Creator{ private String pathServiceSid; private List assetVersions; private List functionVersions; @@ -41,46 +40,63 @@ public BuildCreator(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - public BuildCreator setAssetVersions(final List assetVersions){ + public BuildCreator setAssetVersions(final List assetVersions) { this.assetVersions = assetVersions; return this; } - public BuildCreator setAssetVersions(final String assetVersions){ + + public BuildCreator setAssetVersions(final String assetVersions) { return setAssetVersions(Promoter.listOfOne(assetVersions)); } - public BuildCreator setFunctionVersions(final List functionVersions){ + + public BuildCreator setFunctionVersions( + final List functionVersions + ) { this.functionVersions = functionVersions; return this; } - public BuildCreator setFunctionVersions(final String functionVersions){ + + public BuildCreator setFunctionVersions(final String functionVersions) { return setFunctionVersions(Promoter.listOfOne(functionVersions)); } - public BuildCreator setDependencies(final String dependencies){ + + public BuildCreator setDependencies(final String dependencies) { this.dependencies = dependencies; return this; } - public BuildCreator setRuntime(final String runtime){ + + public BuildCreator setRuntime(final String runtime) { this.runtime = runtime; return this; } @Override - public Build create(final TwilioRestClient client){ + public Build create(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Builds"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.SERVERLESS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Build creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Build creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -89,26 +105,23 @@ public Build create(final TwilioRestClient client){ return Build.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (assetVersions != null) { for (String prop : assetVersions) { request.addPostParam("AssetVersions", prop); } - } if (functionVersions != null) { for (String prop : functionVersions) { request.addPostParam("FunctionVersions", prop); } - } if (dependencies != null) { request.addPostParam("Dependencies", dependencies); - } if (runtime != null) { request.addPostParam("Runtime", runtime); - } } } diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/BuildDeleter.java b/src/main/java/com/twilio/rest/serverless/v1/service/BuildDeleter.java index d0b091bce7..8b619dece9 100644 --- a/src/main/java/com/twilio/rest/serverless/v1/service/BuildDeleter.java +++ b/src/main/java/com/twilio/rest/serverless/v1/service/BuildDeleter.java @@ -24,24 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class BuildDeleter extends Deleter { + private String pathServiceSid; private String pathSid; - public BuildDeleter(final String pathServiceSid, final String pathSid){ + public BuildDeleter(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Builds/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +53,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Build delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Build delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/BuildFetcher.java b/src/main/java/com/twilio/rest/serverless/v1/service/BuildFetcher.java index a82a1730b9..6ef58cf2e9 100644 --- a/src/main/java/com/twilio/rest/serverless/v1/service/BuildFetcher.java +++ b/src/main/java/com/twilio/rest/serverless/v1/service/BuildFetcher.java @@ -24,25 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class BuildFetcher extends Fetcher { + private String pathServiceSid; private String pathSid; - public BuildFetcher(final String pathServiceSid, final String pathSid){ + public BuildFetcher(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - @Override public Build fetch(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Builds/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,9 +53,14 @@ public Build fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Build fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Build fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/BuildReader.java b/src/main/java/com/twilio/rest/serverless/v1/service/BuildReader.java index 3edb151650..8a9a859565 100644 --- a/src/main/java/com/twilio/rest/serverless/v1/service/BuildReader.java +++ b/src/main/java/com/twilio/rest/serverless/v1/service/BuildReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.serverless.v1.service; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,19 +25,17 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class BuildReader extends Reader { + private String pathServiceSid; private Integer pageSize; - public BuildReader(final String pathServiceSid){ + public BuildReader(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - public BuildReader setPageSize(final Integer pageSize){ + public BuildReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -48,7 +47,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Builds"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -60,13 +63,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Build read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Build read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +93,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.SERVERLESS.toString()) @@ -90,9 +104,11 @@ public Page previousPage(final Page page, final TwilioRestClient c return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.SERVERLESS.toString()) @@ -101,21 +117,21 @@ public Page nextPage(final Page page, final TwilioRestClient clien } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/Environment.java b/src/main/java/com/twilio/rest/serverless/v1/service/Environment.java index 72be6b3d4d..19463d800c 100644 --- a/src/main/java/com/twilio/rest/serverless/v1/service/Environment.java +++ b/src/main/java/com/twilio/rest/serverless/v1/service/Environment.java @@ -23,51 +23,59 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Environment extends Resource { + private static final long serialVersionUID = 36784486672291L; - public static EnvironmentCreator creator(final String pathServiceSid, final String uniqueName){ + public static EnvironmentCreator creator( + final String pathServiceSid, + final String uniqueName + ) { return new EnvironmentCreator(pathServiceSid, uniqueName); } - public static EnvironmentDeleter deleter(final String pathServiceSid, final String pathSid){ + public static EnvironmentDeleter deleter( + final String pathServiceSid, + final String pathSid + ) { return new EnvironmentDeleter(pathServiceSid, pathSid); } - public static EnvironmentFetcher fetcher(final String pathServiceSid, final String pathSid){ + public static EnvironmentFetcher fetcher( + final String pathServiceSid, + final String pathSid + ) { return new EnvironmentFetcher(pathServiceSid, pathSid); } - public static EnvironmentReader reader(final String pathServiceSid){ + public static EnvironmentReader reader(final String pathServiceSid) { return new EnvironmentReader(pathServiceSid); } /** - * Converts a JSON String into a Environment object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Environment object represented by the provided JSON - */ - public static Environment fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Environment object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Environment object represented by the provided JSON + */ + public static Environment fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Environment.class); @@ -79,14 +87,17 @@ public static Environment fromJson(final String json, final ObjectMapper objectM } /** - * Converts a JSON InputStream into a Environment object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Environment object represented by the provided JSON - */ - public static Environment fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Environment object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Environment object represented by the provided JSON + */ + public static Environment fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Environment.class); @@ -111,38 +122,17 @@ public static Environment fromJson(final InputStream json, final ObjectMapper ob @JsonCreator private Environment( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("build_sid") - final String buildSid, - - @JsonProperty("unique_name") - final String uniqueName, - - @JsonProperty("domain_suffix") - final String domainSuffix, - - @JsonProperty("domain_name") - final String domainName, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("build_sid") final String buildSid, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("domain_suffix") final String domainSuffix, + @JsonProperty("domain_name") final String domainName, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.sid = sid; this.accountSid = accountSid; @@ -157,43 +147,53 @@ private Environment( this.links = links; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final String getBuildSid() { - return this.buildSid; - } - public final String getUniqueName() { - return this.uniqueName; - } - public final String getDomainSuffix() { - return this.domainSuffix; - } - public final String getDomainName() { - return this.domainName; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final String getBuildSid() { + return this.buildSid; + } + + public final String getUniqueName() { + return this.uniqueName; + } + + public final String getDomainSuffix() { + return this.domainSuffix; + } + + public final String getDomainName() { + return this.domainName; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -203,13 +203,35 @@ public boolean equals(final Object o) { Environment other = (Environment) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(buildSid, other.buildSid) && Objects.equals(uniqueName, other.uniqueName) && Objects.equals(domainSuffix, other.domainSuffix) && Objects.equals(domainName, other.domainName) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(buildSid, other.buildSid) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(domainSuffix, other.domainSuffix) && + Objects.equals(domainName, other.domainName) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, serviceSid, buildSid, uniqueName, domainSuffix, domainName, dateCreated, dateUpdated, url, links); + return Objects.hash( + sid, + accountSid, + serviceSid, + buildSid, + uniqueName, + domainSuffix, + domainName, + dateCreated, + dateUpdated, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/EnvironmentCreator.java b/src/main/java/com/twilio/rest/serverless/v1/service/EnvironmentCreator.java index f5d18be8ad..cd58b3187a 100644 --- a/src/main/java/com/twilio/rest/serverless/v1/service/EnvironmentCreator.java +++ b/src/main/java/com/twilio/rest/serverless/v1/service/EnvironmentCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.serverless.v1.service; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,62 +25,77 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class EnvironmentCreator extends Creator { - - -public class EnvironmentCreator extends Creator{ private String pathServiceSid; private String uniqueName; private String domainSuffix; - public EnvironmentCreator(final String pathServiceSid, final String uniqueName) { + public EnvironmentCreator( + final String pathServiceSid, + final String uniqueName + ) { this.pathServiceSid = pathServiceSid; this.uniqueName = uniqueName; } - public EnvironmentCreator setUniqueName(final String uniqueName){ + public EnvironmentCreator setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - public EnvironmentCreator setDomainSuffix(final String domainSuffix){ + + public EnvironmentCreator setDomainSuffix(final String domainSuffix) { this.domainSuffix = domainSuffix; return this; } @Override - public Environment create(final TwilioRestClient client){ + public Environment create(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Environments"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"UniqueName"+"}", this.uniqueName.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace("{" + "UniqueName" + "}", this.uniqueName.toString()); Request request = new Request( HttpMethod.POST, Domains.SERVERLESS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Environment creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Environment creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Environment.fromJson(response.getStream(), client.getObjectMapper()); + return Environment.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (uniqueName != null) { request.addPostParam("UniqueName", uniqueName); - } if (domainSuffix != null) { request.addPostParam("DomainSuffix", domainSuffix); - } } } diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/EnvironmentDeleter.java b/src/main/java/com/twilio/rest/serverless/v1/service/EnvironmentDeleter.java index 1c4b253709..85a2ea63f1 100644 --- a/src/main/java/com/twilio/rest/serverless/v1/service/EnvironmentDeleter.java +++ b/src/main/java/com/twilio/rest/serverless/v1/service/EnvironmentDeleter.java @@ -24,24 +24,29 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class EnvironmentDeleter extends Deleter { + private String pathServiceSid; private String pathSid; - public EnvironmentDeleter(final String pathServiceSid, final String pathSid){ + public EnvironmentDeleter( + final String pathServiceSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Environments/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +56,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Environment delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Environment delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/EnvironmentFetcher.java b/src/main/java/com/twilio/rest/serverless/v1/service/EnvironmentFetcher.java index 5667fdcdbb..7c03911a16 100644 --- a/src/main/java/com/twilio/rest/serverless/v1/service/EnvironmentFetcher.java +++ b/src/main/java/com/twilio/rest/serverless/v1/service/EnvironmentFetcher.java @@ -24,25 +24,29 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class EnvironmentFetcher extends Fetcher { + private String pathServiceSid; private String pathSid; - public EnvironmentFetcher(final String pathServiceSid, final String pathSid){ + public EnvironmentFetcher( + final String pathServiceSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - @Override public Environment fetch(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Environments/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,15 +56,23 @@ public Environment fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Environment fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Environment fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Environment.fromJson(response.getStream(), client.getObjectMapper()); + return Environment.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/EnvironmentReader.java b/src/main/java/com/twilio/rest/serverless/v1/service/EnvironmentReader.java index 05aa7b9f94..195984d00e 100644 --- a/src/main/java/com/twilio/rest/serverless/v1/service/EnvironmentReader.java +++ b/src/main/java/com/twilio/rest/serverless/v1/service/EnvironmentReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.serverless.v1.service; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,19 +25,17 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class EnvironmentReader extends Reader { + private String pathServiceSid; private Integer pageSize; - public EnvironmentReader(final String pathServiceSid){ + public EnvironmentReader(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - public EnvironmentReader setPageSize(final Integer pageSize){ + public EnvironmentReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -48,7 +47,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Environments"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -60,13 +63,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Environment read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Environment read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +93,10 @@ private Page pageForRequest(final TwilioRestClient client, final Re } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.SERVERLESS.toString()) @@ -90,9 +104,11 @@ public Page previousPage(final Page page, final Twilio return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.SERVERLESS.toString()) @@ -101,21 +117,21 @@ public Page nextPage(final Page page, final TwilioRest } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/Function.java b/src/main/java/com/twilio/rest/serverless/v1/service/Function.java index be1c9a00af..c5180634d8 100644 --- a/src/main/java/com/twilio/rest/serverless/v1/service/Function.java +++ b/src/main/java/com/twilio/rest/serverless/v1/service/Function.java @@ -23,55 +23,67 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Function extends Resource { + private static final long serialVersionUID = 60673471687127L; - public static FunctionCreator creator(final String pathServiceSid, final String friendlyName){ + public static FunctionCreator creator( + final String pathServiceSid, + final String friendlyName + ) { return new FunctionCreator(pathServiceSid, friendlyName); } - public static FunctionDeleter deleter(final String pathServiceSid, final String pathSid){ + public static FunctionDeleter deleter( + final String pathServiceSid, + final String pathSid + ) { return new FunctionDeleter(pathServiceSid, pathSid); } - public static FunctionFetcher fetcher(final String pathServiceSid, final String pathSid){ + public static FunctionFetcher fetcher( + final String pathServiceSid, + final String pathSid + ) { return new FunctionFetcher(pathServiceSid, pathSid); } - public static FunctionReader reader(final String pathServiceSid){ + public static FunctionReader reader(final String pathServiceSid) { return new FunctionReader(pathServiceSid); } - public static FunctionUpdater updater(final String pathServiceSid, final String pathSid, final String friendlyName){ + public static FunctionUpdater updater( + final String pathServiceSid, + final String pathSid, + final String friendlyName + ) { return new FunctionUpdater(pathServiceSid, pathSid, friendlyName); } /** - * Converts a JSON String into a Function object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Function object represented by the provided JSON - */ - public static Function fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Function object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Function object represented by the provided JSON + */ + public static Function fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Function.class); @@ -83,14 +95,17 @@ public static Function fromJson(final String json, final ObjectMapper objectMapp } /** - * Converts a JSON InputStream into a Function object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Function object represented by the provided JSON - */ - public static Function fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Function object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Function object represented by the provided JSON + */ + public static Function fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Function.class); @@ -112,29 +127,14 @@ public static Function fromJson(final InputStream json, final ObjectMapper objec @JsonCreator private Function( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.sid = sid; this.accountSid = accountSid; @@ -146,34 +146,41 @@ private Function( this.links = links; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -183,13 +190,29 @@ public boolean equals(final Object o) { Function other = (Function) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, serviceSid, friendlyName, dateCreated, dateUpdated, url, links); + return Objects.hash( + sid, + accountSid, + serviceSid, + friendlyName, + dateCreated, + dateUpdated, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/FunctionCreator.java b/src/main/java/com/twilio/rest/serverless/v1/service/FunctionCreator.java index d3ad93e33c..061319e188 100644 --- a/src/main/java/com/twilio/rest/serverless/v1/service/FunctionCreator.java +++ b/src/main/java/com/twilio/rest/serverless/v1/service/FunctionCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.serverless.v1.service; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,53 +25,71 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class FunctionCreator extends Creator { - - -public class FunctionCreator extends Creator{ private String pathServiceSid; private String friendlyName; - public FunctionCreator(final String pathServiceSid, final String friendlyName) { + public FunctionCreator( + final String pathServiceSid, + final String friendlyName + ) { this.pathServiceSid = pathServiceSid; this.friendlyName = friendlyName; } - public FunctionCreator setFriendlyName(final String friendlyName){ + public FunctionCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } @Override - public Function create(final TwilioRestClient client){ + public Function create(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Functions"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"FriendlyName"+"}", this.friendlyName.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "FriendlyName" + "}", + this.friendlyName.toString() + ); Request request = new Request( HttpMethod.POST, Domains.SERVERLESS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Function creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Function creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Function.fromJson(response.getStream(), client.getObjectMapper()); + return Function.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } } } diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/FunctionDeleter.java b/src/main/java/com/twilio/rest/serverless/v1/service/FunctionDeleter.java index 3fd530dfe8..d2687464ae 100644 --- a/src/main/java/com/twilio/rest/serverless/v1/service/FunctionDeleter.java +++ b/src/main/java/com/twilio/rest/serverless/v1/service/FunctionDeleter.java @@ -24,24 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class FunctionDeleter extends Deleter { + private String pathServiceSid; private String pathSid; - public FunctionDeleter(final String pathServiceSid, final String pathSid){ + public FunctionDeleter(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Functions/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +53,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Function delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Function delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/FunctionFetcher.java b/src/main/java/com/twilio/rest/serverless/v1/service/FunctionFetcher.java index cee295865b..80c4d7dd58 100644 --- a/src/main/java/com/twilio/rest/serverless/v1/service/FunctionFetcher.java +++ b/src/main/java/com/twilio/rest/serverless/v1/service/FunctionFetcher.java @@ -24,25 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class FunctionFetcher extends Fetcher { + private String pathServiceSid; private String pathSid; - public FunctionFetcher(final String pathServiceSid, final String pathSid){ + public FunctionFetcher(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - @Override public Function fetch(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Functions/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,15 +53,23 @@ public Function fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Function fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Function fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Function.fromJson(response.getStream(), client.getObjectMapper()); + return Function.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/FunctionReader.java b/src/main/java/com/twilio/rest/serverless/v1/service/FunctionReader.java index 241506f19a..e8de2a3163 100644 --- a/src/main/java/com/twilio/rest/serverless/v1/service/FunctionReader.java +++ b/src/main/java/com/twilio/rest/serverless/v1/service/FunctionReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.serverless.v1.service; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,19 +25,17 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class FunctionReader extends Reader { + private String pathServiceSid; private Integer pageSize; - public FunctionReader(final String pathServiceSid){ + public FunctionReader(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - public FunctionReader setPageSize(final Integer pageSize){ + public FunctionReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -48,7 +47,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Functions"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -60,13 +63,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Function read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Function read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +93,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reque } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.SERVERLESS.toString()) @@ -90,9 +104,11 @@ public Page previousPage(final Page page, final TwilioRestCl return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.SERVERLESS.toString()) @@ -101,21 +117,21 @@ public Page nextPage(final Page page, final TwilioRestClient } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/FunctionUpdater.java b/src/main/java/com/twilio/rest/serverless/v1/service/FunctionUpdater.java index 6471f2ac22..8dfbfaaa50 100644 --- a/src/main/java/com/twilio/rest/serverless/v1/service/FunctionUpdater.java +++ b/src/main/java/com/twilio/rest/serverless/v1/service/FunctionUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.serverless.v1.service; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,56 +25,75 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class FunctionUpdater extends Updater { - - -public class FunctionUpdater extends Updater{ private String pathServiceSid; private String pathSid; private String friendlyName; - public FunctionUpdater(final String pathServiceSid, final String pathSid, final String friendlyName){ + public FunctionUpdater( + final String pathServiceSid, + final String pathSid, + final String friendlyName + ) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; this.friendlyName = friendlyName; } - public FunctionUpdater setFriendlyName(final String friendlyName){ + public FunctionUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } @Override - public Function update(final TwilioRestClient client){ + public Function update(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Functions/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); - path = path.replace("{"+"FriendlyName"+"}", this.friendlyName.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + path = + path.replace( + "{" + "FriendlyName" + "}", + this.friendlyName.toString() + ); Request request = new Request( HttpMethod.POST, Domains.SERVERLESS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Function update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Function update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Function.fromJson(response.getStream(), client.getObjectMapper()); + return Function.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } } } diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/asset/AssetVersion.java b/src/main/java/com/twilio/rest/serverless/v1/service/asset/AssetVersion.java index 617d2199d5..c02277543c 100644 --- a/src/main/java/com/twilio/rest/serverless/v1/service/asset/AssetVersion.java +++ b/src/main/java/com/twilio/rest/serverless/v1/service/asset/AssetVersion.java @@ -24,41 +24,47 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class AssetVersion extends Resource { + private static final long serialVersionUID = 215359401104297L; - public static AssetVersionFetcher fetcher(final String pathServiceSid, final String pathAssetSid, final String pathSid){ + public static AssetVersionFetcher fetcher( + final String pathServiceSid, + final String pathAssetSid, + final String pathSid + ) { return new AssetVersionFetcher(pathServiceSid, pathAssetSid, pathSid); } - public static AssetVersionReader reader(final String pathServiceSid, final String pathAssetSid){ + public static AssetVersionReader reader( + final String pathServiceSid, + final String pathAssetSid + ) { return new AssetVersionReader(pathServiceSid, pathAssetSid); } /** - * Converts a JSON String into a AssetVersion object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return AssetVersion object represented by the provided JSON - */ - public static AssetVersion fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a AssetVersion object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return AssetVersion object represented by the provided JSON + */ + public static AssetVersion fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, AssetVersion.class); @@ -70,14 +76,17 @@ public static AssetVersion fromJson(final String json, final ObjectMapper object } /** - * Converts a JSON InputStream into a AssetVersion object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return AssetVersion object represented by the provided JSON - */ - public static AssetVersion fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a AssetVersion object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return AssetVersion object represented by the provided JSON + */ + public static AssetVersion fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, AssetVersion.class); @@ -87,6 +96,7 @@ public static AssetVersion fromJson(final InputStream json, final ObjectMapper o throw new ApiConnectionException(e.getMessage(), e); } } + public enum Visibility { PUBLIC("public"), PRIVATE("private"), @@ -119,29 +129,14 @@ public static Visibility forValue(final String value) { @JsonCreator private AssetVersion( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("asset_sid") - final String assetSid, - - @JsonProperty("path") - final String path, - - @JsonProperty("visibility") - final AssetVersion.Visibility visibility, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("asset_sid") final String assetSid, + @JsonProperty("path") final String path, + @JsonProperty("visibility") final AssetVersion.Visibility visibility, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("url") final URI url ) { this.sid = sid; this.accountSid = accountSid; @@ -153,34 +148,41 @@ private AssetVersion( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final String getAssetSid() { - return this.assetSid; - } - public final String getPath() { - return this.path; - } - public final AssetVersion.Visibility getVisibility() { - return this.visibility; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final String getAssetSid() { + return this.assetSid; + } + + public final String getPath() { + return this.path; + } + + public final AssetVersion.Visibility getVisibility() { + return this.visibility; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -190,13 +192,29 @@ public boolean equals(final Object o) { AssetVersion other = (AssetVersion) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(assetSid, other.assetSid) && Objects.equals(path, other.path) && Objects.equals(visibility, other.visibility) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(assetSid, other.assetSid) && + Objects.equals(path, other.path) && + Objects.equals(visibility, other.visibility) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, serviceSid, assetSid, path, visibility, dateCreated, url); + return Objects.hash( + sid, + accountSid, + serviceSid, + assetSid, + path, + visibility, + dateCreated, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/asset/AssetVersionFetcher.java b/src/main/java/com/twilio/rest/serverless/v1/service/asset/AssetVersionFetcher.java index 52716b44e8..5df44d0583 100644 --- a/src/main/java/com/twilio/rest/serverless/v1/service/asset/AssetVersionFetcher.java +++ b/src/main/java/com/twilio/rest/serverless/v1/service/asset/AssetVersionFetcher.java @@ -24,28 +24,35 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class AssetVersionFetcher extends Fetcher { + private String pathServiceSid; private String pathAssetSid; private String pathSid; - public AssetVersionFetcher(final String pathServiceSid, final String pathAssetSid, final String pathSid){ + public AssetVersionFetcher( + final String pathServiceSid, + final String pathAssetSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathAssetSid = pathAssetSid; this.pathSid = pathSid; } - @Override public AssetVersion fetch(final TwilioRestClient client) { - String path = "/v1/Services/{ServiceSid}/Assets/{AssetSid}/Versions/{Sid}"; + String path = + "/v1/Services/{ServiceSid}/Assets/{AssetSid}/Versions/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"AssetSid"+"}", this.pathAssetSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace("{" + "AssetSid" + "}", this.pathAssetSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -55,15 +62,23 @@ public AssetVersion fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AssetVersion fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "AssetVersion fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return AssetVersion.fromJson(response.getStream(), client.getObjectMapper()); + return AssetVersion.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/asset/AssetVersionReader.java b/src/main/java/com/twilio/rest/serverless/v1/service/asset/AssetVersionReader.java index 0cd27d10e9..9a9409e76b 100644 --- a/src/main/java/com/twilio/rest/serverless/v1/service/asset/AssetVersionReader.java +++ b/src/main/java/com/twilio/rest/serverless/v1/service/asset/AssetVersionReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.serverless.v1.service.asset; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,21 +25,22 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class AssetVersionReader extends Reader { + private String pathServiceSid; private String pathAssetSid; private Integer pageSize; - public AssetVersionReader(final String pathServiceSid, final String pathAssetSid){ + public AssetVersionReader( + final String pathServiceSid, + final String pathAssetSid + ) { this.pathServiceSid = pathServiceSid; this.pathAssetSid = pathAssetSid; } - public AssetVersionReader setPageSize(final Integer pageSize){ + public AssetVersionReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -50,8 +52,13 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Assets/{AssetSid}/Versions"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"AssetSid"+"}", this.pathAssetSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace("{" + "AssetSid" + "}", this.pathAssetSid.toString()); Request request = new Request( HttpMethod.GET, @@ -63,13 +70,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AssetVersion read failed: Unable to connect to server"); + throw new ApiConnectionException( + "AssetVersion read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -85,7 +100,10 @@ private Page pageForRequest(final TwilioRestClient client, final R } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.SERVERLESS.toString()) @@ -93,9 +111,11 @@ public Page previousPage(final Page page, final Twil return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.SERVERLESS.toString()) @@ -104,21 +124,21 @@ public Page nextPage(final Page page, final TwilioRe } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/build/BuildStatus.java b/src/main/java/com/twilio/rest/serverless/v1/service/build/BuildStatus.java index 8127f8b257..b4f7f96b6c 100644 --- a/src/main/java/com/twilio/rest/serverless/v1/service/build/BuildStatus.java +++ b/src/main/java/com/twilio/rest/serverless/v1/service/build/BuildStatus.java @@ -23,36 +23,38 @@ import com.twilio.base.Resource; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class BuildStatus extends Resource { + private static final long serialVersionUID = 256582650740181L; - public static BuildStatusFetcher fetcher(final String pathServiceSid, final String pathSid){ + public static BuildStatusFetcher fetcher( + final String pathServiceSid, + final String pathSid + ) { return new BuildStatusFetcher(pathServiceSid, pathSid); } /** - * Converts a JSON String into a BuildStatus object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return BuildStatus object represented by the provided JSON - */ - public static BuildStatus fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a BuildStatus object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return BuildStatus object represented by the provided JSON + */ + public static BuildStatus fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, BuildStatus.class); @@ -64,14 +66,17 @@ public static BuildStatus fromJson(final String json, final ObjectMapper objectM } /** - * Converts a JSON InputStream into a BuildStatus object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return BuildStatus object represented by the provided JSON - */ - public static BuildStatus fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a BuildStatus object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return BuildStatus object represented by the provided JSON + */ + public static BuildStatus fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, BuildStatus.class); @@ -81,6 +86,7 @@ public static BuildStatus fromJson(final InputStream json, final ObjectMapper ob throw new ApiConnectionException(e.getMessage(), e); } } + public enum Status { BUILDING("building"), COMPLETED("completed"), @@ -110,20 +116,11 @@ public static Status forValue(final String value) { @JsonCreator private BuildStatus( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("status") - final BuildStatus.Status status, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("status") final BuildStatus.Status status, + @JsonProperty("url") final URI url ) { this.sid = sid; this.accountSid = accountSid; @@ -132,25 +129,29 @@ private BuildStatus( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final BuildStatus.Status getStatus() { - return this.status; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final BuildStatus.Status getStatus() { + return this.status; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -160,13 +161,17 @@ public boolean equals(final Object o) { BuildStatus other = (BuildStatus) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(status, other.status) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(status, other.status) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { return Objects.hash(sid, accountSid, serviceSid, status, url); } - } - diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/build/BuildStatusFetcher.java b/src/main/java/com/twilio/rest/serverless/v1/service/build/BuildStatusFetcher.java index 300a4f2f82..8e684ae1fd 100644 --- a/src/main/java/com/twilio/rest/serverless/v1/service/build/BuildStatusFetcher.java +++ b/src/main/java/com/twilio/rest/serverless/v1/service/build/BuildStatusFetcher.java @@ -24,25 +24,29 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class BuildStatusFetcher extends Fetcher { + private String pathServiceSid; private String pathSid; - public BuildStatusFetcher(final String pathServiceSid, final String pathSid){ + public BuildStatusFetcher( + final String pathServiceSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - @Override public BuildStatus fetch(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Builds/{Sid}/Status"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,15 +56,23 @@ public BuildStatus fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("BuildStatus fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "BuildStatus fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return BuildStatus.fromJson(response.getStream(), client.getObjectMapper()); + return BuildStatus.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/environment/Deployment.java b/src/main/java/com/twilio/rest/serverless/v1/service/environment/Deployment.java index 65f513e52c..d65cc5bbf8 100644 --- a/src/main/java/com/twilio/rest/serverless/v1/service/environment/Deployment.java +++ b/src/main/java/com/twilio/rest/serverless/v1/service/environment/Deployment.java @@ -23,45 +23,58 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Deployment extends Resource { + private static final long serialVersionUID = 53350837896565L; - public static DeploymentCreator creator(final String pathServiceSid, final String pathEnvironmentSid){ + public static DeploymentCreator creator( + final String pathServiceSid, + final String pathEnvironmentSid + ) { return new DeploymentCreator(pathServiceSid, pathEnvironmentSid); } - public static DeploymentFetcher fetcher(final String pathServiceSid, final String pathEnvironmentSid, final String pathSid){ - return new DeploymentFetcher(pathServiceSid, pathEnvironmentSid, pathSid); + public static DeploymentFetcher fetcher( + final String pathServiceSid, + final String pathEnvironmentSid, + final String pathSid + ) { + return new DeploymentFetcher( + pathServiceSid, + pathEnvironmentSid, + pathSid + ); } - public static DeploymentReader reader(final String pathServiceSid, final String pathEnvironmentSid){ + public static DeploymentReader reader( + final String pathServiceSid, + final String pathEnvironmentSid + ) { return new DeploymentReader(pathServiceSid, pathEnvironmentSid); } /** - * Converts a JSON String into a Deployment object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Deployment object represented by the provided JSON - */ - public static Deployment fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Deployment object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Deployment object represented by the provided JSON + */ + public static Deployment fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Deployment.class); @@ -73,14 +86,17 @@ public static Deployment fromJson(final String json, final ObjectMapper objectMa } /** - * Converts a JSON InputStream into a Deployment object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Deployment object represented by the provided JSON - */ - public static Deployment fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Deployment object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Deployment object represented by the provided JSON + */ + public static Deployment fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Deployment.class); @@ -102,29 +118,14 @@ public static Deployment fromJson(final InputStream json, final ObjectMapper obj @JsonCreator private Deployment( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("environment_sid") - final String environmentSid, - - @JsonProperty("build_sid") - final String buildSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("environment_sid") final String environmentSid, + @JsonProperty("build_sid") final String buildSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url ) { this.sid = sid; this.accountSid = accountSid; @@ -136,34 +137,41 @@ private Deployment( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final String getEnvironmentSid() { - return this.environmentSid; - } - public final String getBuildSid() { - return this.buildSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final String getEnvironmentSid() { + return this.environmentSid; + } + + public final String getBuildSid() { + return this.buildSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -173,13 +181,29 @@ public boolean equals(final Object o) { Deployment other = (Deployment) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(environmentSid, other.environmentSid) && Objects.equals(buildSid, other.buildSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(environmentSid, other.environmentSid) && + Objects.equals(buildSid, other.buildSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, serviceSid, environmentSid, buildSid, dateCreated, dateUpdated, url); + return Objects.hash( + sid, + accountSid, + serviceSid, + environmentSid, + buildSid, + dateCreated, + dateUpdated, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/environment/DeploymentCreator.java b/src/main/java/com/twilio/rest/serverless/v1/service/environment/DeploymentCreator.java index 36b8a65464..989ef23702 100644 --- a/src/main/java/com/twilio/rest/serverless/v1/service/environment/DeploymentCreator.java +++ b/src/main/java/com/twilio/rest/serverless/v1/service/environment/DeploymentCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.serverless.v1.service.environment; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,54 +25,73 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class DeploymentCreator extends Creator { - - -public class DeploymentCreator extends Creator{ private String pathServiceSid; private String pathEnvironmentSid; private String buildSid; - public DeploymentCreator(final String pathServiceSid, final String pathEnvironmentSid) { + public DeploymentCreator( + final String pathServiceSid, + final String pathEnvironmentSid + ) { this.pathServiceSid = pathServiceSid; this.pathEnvironmentSid = pathEnvironmentSid; } - public DeploymentCreator setBuildSid(final String buildSid){ + public DeploymentCreator setBuildSid(final String buildSid) { this.buildSid = buildSid; return this; } @Override - public Deployment create(final TwilioRestClient client){ - String path = "/v1/Services/{ServiceSid}/Environments/{EnvironmentSid}/Deployments"; + public Deployment create(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Environments/{EnvironmentSid}/Deployments"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"EnvironmentSid"+"}", this.pathEnvironmentSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "EnvironmentSid" + "}", + this.pathEnvironmentSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.SERVERLESS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Deployment creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Deployment creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Deployment.fromJson(response.getStream(), client.getObjectMapper()); + return Deployment.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (buildSid != null) { request.addPostParam("BuildSid", buildSid); - } } } diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/environment/DeploymentFetcher.java b/src/main/java/com/twilio/rest/serverless/v1/service/environment/DeploymentFetcher.java index a9bfc44cb8..17a6233e76 100644 --- a/src/main/java/com/twilio/rest/serverless/v1/service/environment/DeploymentFetcher.java +++ b/src/main/java/com/twilio/rest/serverless/v1/service/environment/DeploymentFetcher.java @@ -24,28 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class DeploymentFetcher extends Fetcher { + private String pathServiceSid; private String pathEnvironmentSid; private String pathSid; - public DeploymentFetcher(final String pathServiceSid, final String pathEnvironmentSid, final String pathSid){ + public DeploymentFetcher( + final String pathServiceSid, + final String pathEnvironmentSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathEnvironmentSid = pathEnvironmentSid; this.pathSid = pathSid; } - @Override public Deployment fetch(final TwilioRestClient client) { - String path = "/v1/Services/{ServiceSid}/Environments/{EnvironmentSid}/Deployments/{Sid}"; + String path = + "/v1/Services/{ServiceSid}/Environments/{EnvironmentSid}/Deployments/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"EnvironmentSid"+"}", this.pathEnvironmentSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "EnvironmentSid" + "}", + this.pathEnvironmentSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -55,15 +65,23 @@ public Deployment fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Deployment fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Deployment fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Deployment.fromJson(response.getStream(), client.getObjectMapper()); + return Deployment.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/environment/DeploymentReader.java b/src/main/java/com/twilio/rest/serverless/v1/service/environment/DeploymentReader.java index 9a7ecc0920..ae66517fbf 100644 --- a/src/main/java/com/twilio/rest/serverless/v1/service/environment/DeploymentReader.java +++ b/src/main/java/com/twilio/rest/serverless/v1/service/environment/DeploymentReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.serverless.v1.service.environment; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,21 +25,22 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class DeploymentReader extends Reader { + private String pathServiceSid; private String pathEnvironmentSid; private Integer pageSize; - public DeploymentReader(final String pathServiceSid, final String pathEnvironmentSid){ + public DeploymentReader( + final String pathServiceSid, + final String pathEnvironmentSid + ) { this.pathServiceSid = pathServiceSid; this.pathEnvironmentSid = pathEnvironmentSid; } - public DeploymentReader setPageSize(final Integer pageSize){ + public DeploymentReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -49,9 +51,18 @@ public ResourceSet read(final TwilioRestClient client) { } public Page firstPage(final TwilioRestClient client) { - String path = "/v1/Services/{ServiceSid}/Environments/{EnvironmentSid}/Deployments"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"EnvironmentSid"+"}", this.pathEnvironmentSid.toString()); + String path = + "/v1/Services/{ServiceSid}/Environments/{EnvironmentSid}/Deployments"; + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "EnvironmentSid" + "}", + this.pathEnvironmentSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -63,13 +74,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Deployment read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Deployment read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -85,7 +104,10 @@ private Page pageForRequest(final TwilioRestClient client, final Req } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.SERVERLESS.toString()) @@ -93,9 +115,11 @@ public Page previousPage(final Page page, final TwilioRe return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.SERVERLESS.toString()) @@ -104,21 +128,21 @@ public Page nextPage(final Page page, final TwilioRestCl } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/environment/Log.java b/src/main/java/com/twilio/rest/serverless/v1/service/environment/Log.java index 183d4be74c..165a40fde5 100644 --- a/src/main/java/com/twilio/rest/serverless/v1/service/environment/Log.java +++ b/src/main/java/com/twilio/rest/serverless/v1/service/environment/Log.java @@ -24,41 +24,47 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Log extends Resource { + private static final long serialVersionUID = 129897058125132L; - public static LogFetcher fetcher(final String pathServiceSid, final String pathEnvironmentSid, final String pathSid){ + public static LogFetcher fetcher( + final String pathServiceSid, + final String pathEnvironmentSid, + final String pathSid + ) { return new LogFetcher(pathServiceSid, pathEnvironmentSid, pathSid); } - public static LogReader reader(final String pathServiceSid, final String pathEnvironmentSid){ + public static LogReader reader( + final String pathServiceSid, + final String pathEnvironmentSid + ) { return new LogReader(pathServiceSid, pathEnvironmentSid); } /** - * Converts a JSON String into a Log object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Log object represented by the provided JSON - */ - public static Log fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Log object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Log object represented by the provided JSON + */ + public static Log fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Log.class); @@ -70,14 +76,17 @@ public static Log fromJson(final String json, final ObjectMapper objectMapper) { } /** - * Converts a JSON InputStream into a Log object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Log object represented by the provided JSON - */ - public static Log fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Log object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Log object represented by the provided JSON + */ + public static Log fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Log.class); @@ -87,6 +96,7 @@ public static Log fromJson(final InputStream json, final ObjectMapper objectMapp throw new ApiConnectionException(e.getMessage(), e); } } + public enum Level { INFO("info"), WARN("warn"), @@ -123,41 +133,18 @@ public static Level forValue(final String value) { @JsonCreator private Log( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("environment_sid") - final String environmentSid, - - @JsonProperty("build_sid") - final String buildSid, - - @JsonProperty("deployment_sid") - final String deploymentSid, - - @JsonProperty("function_sid") - final String functionSid, - - @JsonProperty("request_sid") - final String requestSid, - - @JsonProperty("level") - final Log.Level level, - - @JsonProperty("message") - final String message, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("environment_sid") final String environmentSid, + @JsonProperty("build_sid") final String buildSid, + @JsonProperty("deployment_sid") final String deploymentSid, + @JsonProperty("function_sid") final String functionSid, + @JsonProperty("request_sid") final String requestSid, + @JsonProperty("level") final Log.Level level, + @JsonProperty("message") final String message, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("url") final URI url ) { this.sid = sid; this.accountSid = accountSid; @@ -173,46 +160,57 @@ private Log( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final String getEnvironmentSid() { - return this.environmentSid; - } - public final String getBuildSid() { - return this.buildSid; - } - public final String getDeploymentSid() { - return this.deploymentSid; - } - public final String getFunctionSid() { - return this.functionSid; - } - public final String getRequestSid() { - return this.requestSid; - } - public final Log.Level getLevel() { - return this.level; - } - public final String getMessage() { - return this.message; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final String getEnvironmentSid() { + return this.environmentSid; + } + + public final String getBuildSid() { + return this.buildSid; + } + + public final String getDeploymentSid() { + return this.deploymentSid; + } + + public final String getFunctionSid() { + return this.functionSid; + } + + public final String getRequestSid() { + return this.requestSid; + } + + public final Log.Level getLevel() { + return this.level; + } + + public final String getMessage() { + return this.message; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -222,13 +220,37 @@ public boolean equals(final Object o) { Log other = (Log) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(environmentSid, other.environmentSid) && Objects.equals(buildSid, other.buildSid) && Objects.equals(deploymentSid, other.deploymentSid) && Objects.equals(functionSid, other.functionSid) && Objects.equals(requestSid, other.requestSid) && Objects.equals(level, other.level) && Objects.equals(message, other.message) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(environmentSid, other.environmentSid) && + Objects.equals(buildSid, other.buildSid) && + Objects.equals(deploymentSid, other.deploymentSid) && + Objects.equals(functionSid, other.functionSid) && + Objects.equals(requestSid, other.requestSid) && + Objects.equals(level, other.level) && + Objects.equals(message, other.message) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, serviceSid, environmentSid, buildSid, deploymentSid, functionSid, requestSid, level, message, dateCreated, url); + return Objects.hash( + sid, + accountSid, + serviceSid, + environmentSid, + buildSid, + deploymentSid, + functionSid, + requestSid, + level, + message, + dateCreated, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/environment/LogFetcher.java b/src/main/java/com/twilio/rest/serverless/v1/service/environment/LogFetcher.java index 1b84c6850d..7f7723a11a 100644 --- a/src/main/java/com/twilio/rest/serverless/v1/service/environment/LogFetcher.java +++ b/src/main/java/com/twilio/rest/serverless/v1/service/environment/LogFetcher.java @@ -24,28 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class LogFetcher extends Fetcher { + private String pathServiceSid; private String pathEnvironmentSid; private String pathSid; - public LogFetcher(final String pathServiceSid, final String pathEnvironmentSid, final String pathSid){ + public LogFetcher( + final String pathServiceSid, + final String pathEnvironmentSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathEnvironmentSid = pathEnvironmentSid; this.pathSid = pathSid; } - @Override public Log fetch(final TwilioRestClient client) { - String path = "/v1/Services/{ServiceSid}/Environments/{EnvironmentSid}/Logs/{Sid}"; + String path = + "/v1/Services/{ServiceSid}/Environments/{EnvironmentSid}/Logs/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"EnvironmentSid"+"}", this.pathEnvironmentSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "EnvironmentSid" + "}", + this.pathEnvironmentSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -55,9 +65,14 @@ public Log fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Log fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Log fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/environment/LogReader.java b/src/main/java/com/twilio/rest/serverless/v1/service/environment/LogReader.java index 2b6a88aa9e..f6dfde6d18 100644 --- a/src/main/java/com/twilio/rest/serverless/v1/service/environment/LogReader.java +++ b/src/main/java/com/twilio/rest/serverless/v1/service/environment/LogReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.serverless.v1.service.environment; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,12 +25,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; import java.time.ZonedDateTime; - - public class LogReader extends Reader { + private String pathServiceSid; private String pathEnvironmentSid; private String functionSid; @@ -37,24 +36,30 @@ public class LogReader extends Reader { private ZonedDateTime endDate; private Integer pageSize; - public LogReader(final String pathServiceSid, final String pathEnvironmentSid){ + public LogReader( + final String pathServiceSid, + final String pathEnvironmentSid + ) { this.pathServiceSid = pathServiceSid; this.pathEnvironmentSid = pathEnvironmentSid; } - public LogReader setFunctionSid(final String functionSid){ + public LogReader setFunctionSid(final String functionSid) { this.functionSid = functionSid; return this; } - public LogReader setStartDate(final ZonedDateTime startDate){ + + public LogReader setStartDate(final ZonedDateTime startDate) { this.startDate = startDate; return this; } - public LogReader setEndDate(final ZonedDateTime endDate){ + + public LogReader setEndDate(final ZonedDateTime endDate) { this.endDate = endDate; return this; } - public LogReader setPageSize(final Integer pageSize){ + + public LogReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -65,9 +70,18 @@ public ResourceSet read(final TwilioRestClient client) { } public Page firstPage(final TwilioRestClient client) { - String path = "/v1/Services/{ServiceSid}/Environments/{EnvironmentSid}/Logs"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"EnvironmentSid"+"}", this.pathEnvironmentSid.toString()); + String path = + "/v1/Services/{ServiceSid}/Environments/{EnvironmentSid}/Logs"; + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "EnvironmentSid" + "}", + this.pathEnvironmentSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -79,13 +93,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Log read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Log read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -101,7 +123,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request re } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.SERVERLESS.toString()) @@ -109,9 +134,11 @@ public Page previousPage(final Page page, final TwilioRestClient clien return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.SERVERLESS.toString()) @@ -120,21 +147,24 @@ public Page nextPage(final Page page, final TwilioRestClient client) { } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (functionSid != null) { - request.addQueryParam("FunctionSid", functionSid); } if (startDate != null) { - request.addQueryParam("StartDate", startDate.toInstant().toString()); + request.addQueryParam( + "StartDate", + startDate.toInstant().toString() + ); } if (endDate != null) { @@ -142,11 +172,10 @@ private void addQueryParams(final Request request) { } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/environment/Variable.java b/src/main/java/com/twilio/rest/serverless/v1/service/environment/Variable.java index 4a4c21ae32..2c5f45dec3 100644 --- a/src/main/java/com/twilio/rest/serverless/v1/service/environment/Variable.java +++ b/src/main/java/com/twilio/rest/serverless/v1/service/environment/Variable.java @@ -23,53 +23,77 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Variable extends Resource { + private static final long serialVersionUID = 240706939520174L; - public static VariableCreator creator(final String pathServiceSid, final String pathEnvironmentSid, final String key, final String value){ - return new VariableCreator(pathServiceSid, pathEnvironmentSid, key, value); + public static VariableCreator creator( + final String pathServiceSid, + final String pathEnvironmentSid, + final String key, + final String value + ) { + return new VariableCreator( + pathServiceSid, + pathEnvironmentSid, + key, + value + ); } - public static VariableDeleter deleter(final String pathServiceSid, final String pathEnvironmentSid, final String pathSid){ + public static VariableDeleter deleter( + final String pathServiceSid, + final String pathEnvironmentSid, + final String pathSid + ) { return new VariableDeleter(pathServiceSid, pathEnvironmentSid, pathSid); } - public static VariableFetcher fetcher(final String pathServiceSid, final String pathEnvironmentSid, final String pathSid){ + public static VariableFetcher fetcher( + final String pathServiceSid, + final String pathEnvironmentSid, + final String pathSid + ) { return new VariableFetcher(pathServiceSid, pathEnvironmentSid, pathSid); } - public static VariableReader reader(final String pathServiceSid, final String pathEnvironmentSid){ + public static VariableReader reader( + final String pathServiceSid, + final String pathEnvironmentSid + ) { return new VariableReader(pathServiceSid, pathEnvironmentSid); } - public static VariableUpdater updater(final String pathServiceSid, final String pathEnvironmentSid, final String pathSid){ + public static VariableUpdater updater( + final String pathServiceSid, + final String pathEnvironmentSid, + final String pathSid + ) { return new VariableUpdater(pathServiceSid, pathEnvironmentSid, pathSid); } /** - * Converts a JSON String into a Variable object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Variable object represented by the provided JSON - */ - public static Variable fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Variable object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Variable object represented by the provided JSON + */ + public static Variable fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Variable.class); @@ -81,14 +105,17 @@ public static Variable fromJson(final String json, final ObjectMapper objectMapp } /** - * Converts a JSON InputStream into a Variable object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Variable object represented by the provided JSON - */ - public static Variable fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Variable object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Variable object represented by the provided JSON + */ + public static Variable fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Variable.class); @@ -111,32 +138,15 @@ public static Variable fromJson(final InputStream json, final ObjectMapper objec @JsonCreator private Variable( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("environment_sid") - final String environmentSid, - - @JsonProperty("key") - final String key, - - @JsonProperty("value") - final String value, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("environment_sid") final String environmentSid, + @JsonProperty("key") final String key, + @JsonProperty("value") final String value, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url ) { this.sid = sid; this.accountSid = accountSid; @@ -149,37 +159,45 @@ private Variable( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final String getEnvironmentSid() { - return this.environmentSid; - } - public final String getKey() { - return this.key; - } - public final String getValue() { - return this.value; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final String getEnvironmentSid() { + return this.environmentSid; + } + + public final String getKey() { + return this.key; + } + + public final String getValue() { + return this.value; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -189,13 +207,31 @@ public boolean equals(final Object o) { Variable other = (Variable) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(environmentSid, other.environmentSid) && Objects.equals(key, other.key) && Objects.equals(value, other.value) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(environmentSid, other.environmentSid) && + Objects.equals(key, other.key) && + Objects.equals(value, other.value) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, serviceSid, environmentSid, key, value, dateCreated, dateUpdated, url); + return Objects.hash( + sid, + accountSid, + serviceSid, + environmentSid, + key, + value, + dateCreated, + dateUpdated, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/environment/VariableCreator.java b/src/main/java/com/twilio/rest/serverless/v1/service/environment/VariableCreator.java index b6f91a5158..afe8e5c30b 100644 --- a/src/main/java/com/twilio/rest/serverless/v1/service/environment/VariableCreator.java +++ b/src/main/java/com/twilio/rest/serverless/v1/service/environment/VariableCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.serverless.v1.service.environment; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,67 +25,88 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class VariableCreator extends Creator { - - -public class VariableCreator extends Creator{ private String pathServiceSid; private String pathEnvironmentSid; private String key; private String value; - public VariableCreator(final String pathServiceSid, final String pathEnvironmentSid, final String key, final String value) { + public VariableCreator( + final String pathServiceSid, + final String pathEnvironmentSid, + final String key, + final String value + ) { this.pathServiceSid = pathServiceSid; this.pathEnvironmentSid = pathEnvironmentSid; this.key = key; this.value = value; } - public VariableCreator setKey(final String key){ + public VariableCreator setKey(final String key) { this.key = key; return this; } - public VariableCreator setValue(final String value){ + + public VariableCreator setValue(final String value) { this.value = value; return this; } @Override - public Variable create(final TwilioRestClient client){ - String path = "/v1/Services/{ServiceSid}/Environments/{EnvironmentSid}/Variables"; + public Variable create(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Environments/{EnvironmentSid}/Variables"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"EnvironmentSid"+"}", this.pathEnvironmentSid.toString()); - path = path.replace("{"+"Key"+"}", this.key.toString()); - path = path.replace("{"+"Value"+"}", this.value.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "EnvironmentSid" + "}", + this.pathEnvironmentSid.toString() + ); + path = path.replace("{" + "Key" + "}", this.key.toString()); + path = path.replace("{" + "Value" + "}", this.value.toString()); Request request = new Request( HttpMethod.POST, Domains.SERVERLESS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Variable creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Variable creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Variable.fromJson(response.getStream(), client.getObjectMapper()); + return Variable.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (key != null) { request.addPostParam("Key", key); - } if (value != null) { request.addPostParam("Value", value); - } } } diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/environment/VariableDeleter.java b/src/main/java/com/twilio/rest/serverless/v1/service/environment/VariableDeleter.java index a905b4b9e4..cb86ce1610 100644 --- a/src/main/java/com/twilio/rest/serverless/v1/service/environment/VariableDeleter.java +++ b/src/main/java/com/twilio/rest/serverless/v1/service/environment/VariableDeleter.java @@ -24,27 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class VariableDeleter extends Deleter { + private String pathServiceSid; private String pathEnvironmentSid; private String pathSid; - public VariableDeleter(final String pathServiceSid, final String pathEnvironmentSid, final String pathSid){ + public VariableDeleter( + final String pathServiceSid, + final String pathEnvironmentSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathEnvironmentSid = pathEnvironmentSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/v1/Services/{ServiceSid}/Environments/{EnvironmentSid}/Variables/{Sid}"; + String path = + "/v1/Services/{ServiceSid}/Environments/{EnvironmentSid}/Variables/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"EnvironmentSid"+"}", this.pathEnvironmentSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "EnvironmentSid" + "}", + this.pathEnvironmentSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -54,9 +65,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Variable delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Variable delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/environment/VariableFetcher.java b/src/main/java/com/twilio/rest/serverless/v1/service/environment/VariableFetcher.java index 1857c08ab7..c2e36885cd 100644 --- a/src/main/java/com/twilio/rest/serverless/v1/service/environment/VariableFetcher.java +++ b/src/main/java/com/twilio/rest/serverless/v1/service/environment/VariableFetcher.java @@ -24,28 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class VariableFetcher extends Fetcher { + private String pathServiceSid; private String pathEnvironmentSid; private String pathSid; - public VariableFetcher(final String pathServiceSid, final String pathEnvironmentSid, final String pathSid){ + public VariableFetcher( + final String pathServiceSid, + final String pathEnvironmentSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathEnvironmentSid = pathEnvironmentSid; this.pathSid = pathSid; } - @Override public Variable fetch(final TwilioRestClient client) { - String path = "/v1/Services/{ServiceSid}/Environments/{EnvironmentSid}/Variables/{Sid}"; + String path = + "/v1/Services/{ServiceSid}/Environments/{EnvironmentSid}/Variables/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"EnvironmentSid"+"}", this.pathEnvironmentSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "EnvironmentSid" + "}", + this.pathEnvironmentSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -55,15 +65,23 @@ public Variable fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Variable fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Variable fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Variable.fromJson(response.getStream(), client.getObjectMapper()); + return Variable.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/environment/VariableReader.java b/src/main/java/com/twilio/rest/serverless/v1/service/environment/VariableReader.java index 0b5c6ffb73..da4513e9c9 100644 --- a/src/main/java/com/twilio/rest/serverless/v1/service/environment/VariableReader.java +++ b/src/main/java/com/twilio/rest/serverless/v1/service/environment/VariableReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.serverless.v1.service.environment; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,21 +25,22 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class VariableReader extends Reader { + private String pathServiceSid; private String pathEnvironmentSid; private Integer pageSize; - public VariableReader(final String pathServiceSid, final String pathEnvironmentSid){ + public VariableReader( + final String pathServiceSid, + final String pathEnvironmentSid + ) { this.pathServiceSid = pathServiceSid; this.pathEnvironmentSid = pathEnvironmentSid; } - public VariableReader setPageSize(final Integer pageSize){ + public VariableReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -49,9 +51,18 @@ public ResourceSet read(final TwilioRestClient client) { } public Page firstPage(final TwilioRestClient client) { - String path = "/v1/Services/{ServiceSid}/Environments/{EnvironmentSid}/Variables"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"EnvironmentSid"+"}", this.pathEnvironmentSid.toString()); + String path = + "/v1/Services/{ServiceSid}/Environments/{EnvironmentSid}/Variables"; + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "EnvironmentSid" + "}", + this.pathEnvironmentSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -63,13 +74,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Variable read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Variable read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -85,7 +104,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reque } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.SERVERLESS.toString()) @@ -93,9 +115,11 @@ public Page previousPage(final Page page, final TwilioRestCl return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.SERVERLESS.toString()) @@ -104,21 +128,21 @@ public Page nextPage(final Page page, final TwilioRestClient } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/environment/VariableUpdater.java b/src/main/java/com/twilio/rest/serverless/v1/service/environment/VariableUpdater.java index 1d212da414..ee93d8b21d 100644 --- a/src/main/java/com/twilio/rest/serverless/v1/service/environment/VariableUpdater.java +++ b/src/main/java/com/twilio/rest/serverless/v1/service/environment/VariableUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.serverless.v1.service.environment; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,66 +25,86 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class VariableUpdater extends Updater { - - -public class VariableUpdater extends Updater{ private String pathServiceSid; private String pathEnvironmentSid; private String pathSid; private String key; private String value; - public VariableUpdater(final String pathServiceSid, final String pathEnvironmentSid, final String pathSid){ + public VariableUpdater( + final String pathServiceSid, + final String pathEnvironmentSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathEnvironmentSid = pathEnvironmentSid; this.pathSid = pathSid; } - public VariableUpdater setKey(final String key){ + public VariableUpdater setKey(final String key) { this.key = key; return this; } - public VariableUpdater setValue(final String value){ + + public VariableUpdater setValue(final String value) { this.value = value; return this; } @Override - public Variable update(final TwilioRestClient client){ - String path = "/v1/Services/{ServiceSid}/Environments/{EnvironmentSid}/Variables/{Sid}"; + public Variable update(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Environments/{EnvironmentSid}/Variables/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"EnvironmentSid"+"}", this.pathEnvironmentSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "EnvironmentSid" + "}", + this.pathEnvironmentSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.SERVERLESS.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Variable update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Variable update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Variable.fromJson(response.getStream(), client.getObjectMapper()); + return Variable.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (key != null) { request.addPostParam("Key", key); - } if (value != null) { request.addPostParam("Value", value); - } } } diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/function/FunctionVersion.java b/src/main/java/com/twilio/rest/serverless/v1/service/function/FunctionVersion.java index 7713aee908..67aa2519b5 100644 --- a/src/main/java/com/twilio/rest/serverless/v1/service/function/FunctionVersion.java +++ b/src/main/java/com/twilio/rest/serverless/v1/service/function/FunctionVersion.java @@ -24,43 +24,53 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class FunctionVersion extends Resource { + private static final long serialVersionUID = 85534066966494L; - public static FunctionVersionFetcher fetcher(final String pathServiceSid, final String pathFunctionSid, final String pathSid){ - return new FunctionVersionFetcher(pathServiceSid, pathFunctionSid, pathSid); + public static FunctionVersionFetcher fetcher( + final String pathServiceSid, + final String pathFunctionSid, + final String pathSid + ) { + return new FunctionVersionFetcher( + pathServiceSid, + pathFunctionSid, + pathSid + ); } - public static FunctionVersionReader reader(final String pathServiceSid, final String pathFunctionSid){ + public static FunctionVersionReader reader( + final String pathServiceSid, + final String pathFunctionSid + ) { return new FunctionVersionReader(pathServiceSid, pathFunctionSid); } /** - * Converts a JSON String into a FunctionVersion object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return FunctionVersion object represented by the provided JSON - */ - public static FunctionVersion fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a FunctionVersion object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return FunctionVersion object represented by the provided JSON + */ + public static FunctionVersion fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, FunctionVersion.class); @@ -72,14 +82,17 @@ public static FunctionVersion fromJson(final String json, final ObjectMapper obj } /** - * Converts a JSON InputStream into a FunctionVersion object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return FunctionVersion object represented by the provided JSON - */ - public static FunctionVersion fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a FunctionVersion object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return FunctionVersion object represented by the provided JSON + */ + public static FunctionVersion fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, FunctionVersion.class); @@ -89,6 +102,7 @@ public static FunctionVersion fromJson(final InputStream json, final ObjectMappe throw new ApiConnectionException(e.getMessage(), e); } } + public enum Visibility { PUBLIC("public"), PRIVATE("private"), @@ -122,32 +136,15 @@ public static Visibility forValue(final String value) { @JsonCreator private FunctionVersion( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("function_sid") - final String functionSid, - - @JsonProperty("path") - final String path, - - @JsonProperty("visibility") - final FunctionVersion.Visibility visibility, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("function_sid") final String functionSid, + @JsonProperty("path") final String path, + @JsonProperty("visibility") final FunctionVersion.Visibility visibility, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.sid = sid; this.accountSid = accountSid; @@ -160,37 +157,45 @@ private FunctionVersion( this.links = links; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final String getFunctionSid() { - return this.functionSid; - } - public final String getPath() { - return this.path; - } - public final FunctionVersion.Visibility getVisibility() { - return this.visibility; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final String getFunctionSid() { + return this.functionSid; + } + + public final String getPath() { + return this.path; + } + + public final FunctionVersion.Visibility getVisibility() { + return this.visibility; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -200,13 +205,31 @@ public boolean equals(final Object o) { FunctionVersion other = (FunctionVersion) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(functionSid, other.functionSid) && Objects.equals(path, other.path) && Objects.equals(visibility, other.visibility) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(functionSid, other.functionSid) && + Objects.equals(path, other.path) && + Objects.equals(visibility, other.visibility) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, serviceSid, functionSid, path, visibility, dateCreated, url, links); + return Objects.hash( + sid, + accountSid, + serviceSid, + functionSid, + path, + visibility, + dateCreated, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/function/FunctionVersionFetcher.java b/src/main/java/com/twilio/rest/serverless/v1/service/function/FunctionVersionFetcher.java index 0bc3e23597..5d50d5aa03 100644 --- a/src/main/java/com/twilio/rest/serverless/v1/service/function/FunctionVersionFetcher.java +++ b/src/main/java/com/twilio/rest/serverless/v1/service/function/FunctionVersionFetcher.java @@ -24,28 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class FunctionVersionFetcher extends Fetcher { + private String pathServiceSid; private String pathFunctionSid; private String pathSid; - public FunctionVersionFetcher(final String pathServiceSid, final String pathFunctionSid, final String pathSid){ + public FunctionVersionFetcher( + final String pathServiceSid, + final String pathFunctionSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathFunctionSid = pathFunctionSid; this.pathSid = pathSid; } - @Override public FunctionVersion fetch(final TwilioRestClient client) { - String path = "/v1/Services/{ServiceSid}/Functions/{FunctionSid}/Versions/{Sid}"; + String path = + "/v1/Services/{ServiceSid}/Functions/{FunctionSid}/Versions/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"FunctionSid"+"}", this.pathFunctionSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "FunctionSid" + "}", + this.pathFunctionSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -55,15 +65,23 @@ public FunctionVersion fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("FunctionVersion fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "FunctionVersion fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return FunctionVersion.fromJson(response.getStream(), client.getObjectMapper()); + return FunctionVersion.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/function/FunctionVersionReader.java b/src/main/java/com/twilio/rest/serverless/v1/service/function/FunctionVersionReader.java index ac08104d33..fcc0ef2358 100644 --- a/src/main/java/com/twilio/rest/serverless/v1/service/function/FunctionVersionReader.java +++ b/src/main/java/com/twilio/rest/serverless/v1/service/function/FunctionVersionReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.serverless.v1.service.function; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,21 +25,22 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class FunctionVersionReader extends Reader { + private String pathServiceSid; private String pathFunctionSid; private Integer pageSize; - public FunctionVersionReader(final String pathServiceSid, final String pathFunctionSid){ + public FunctionVersionReader( + final String pathServiceSid, + final String pathFunctionSid + ) { this.pathServiceSid = pathServiceSid; this.pathFunctionSid = pathFunctionSid; } - public FunctionVersionReader setPageSize(final Integer pageSize){ + public FunctionVersionReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -49,9 +51,18 @@ public ResourceSet read(final TwilioRestClient client) { } public Page firstPage(final TwilioRestClient client) { - String path = "/v1/Services/{ServiceSid}/Functions/{FunctionSid}/Versions"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"FunctionSid"+"}", this.pathFunctionSid.toString()); + String path = + "/v1/Services/{ServiceSid}/Functions/{FunctionSid}/Versions"; + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "FunctionSid" + "}", + this.pathFunctionSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -63,13 +74,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("FunctionVersion read failed: Unable to connect to server"); + throw new ApiConnectionException( + "FunctionVersion read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -85,7 +104,10 @@ private Page pageForRequest(final TwilioRestClient client, fina } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.SERVERLESS.toString()) @@ -93,9 +115,11 @@ public Page previousPage(final Page page, fina return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.SERVERLESS.toString()) @@ -104,21 +128,21 @@ public Page nextPage(final Page page, final Tw } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/function/functionversion/FunctionVersionContent.java b/src/main/java/com/twilio/rest/serverless/v1/service/function/functionversion/FunctionVersionContent.java index 7ca2b49cde..c668e1abcc 100644 --- a/src/main/java/com/twilio/rest/serverless/v1/service/function/functionversion/FunctionVersionContent.java +++ b/src/main/java/com/twilio/rest/serverless/v1/service/function/functionversion/FunctionVersionContent.java @@ -22,36 +22,43 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class FunctionVersionContent extends Resource { + private static final long serialVersionUID = 208000590885959L; - public static FunctionVersionContentFetcher fetcher(final String pathServiceSid, final String pathFunctionSid, final String pathSid){ - return new FunctionVersionContentFetcher(pathServiceSid, pathFunctionSid, pathSid); + public static FunctionVersionContentFetcher fetcher( + final String pathServiceSid, + final String pathFunctionSid, + final String pathSid + ) { + return new FunctionVersionContentFetcher( + pathServiceSid, + pathFunctionSid, + pathSid + ); } /** - * Converts a JSON String into a FunctionVersionContent object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return FunctionVersionContent object represented by the provided JSON - */ - public static FunctionVersionContent fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a FunctionVersionContent object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return FunctionVersionContent object represented by the provided JSON + */ + public static FunctionVersionContent fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, FunctionVersionContent.class); @@ -63,14 +70,17 @@ public static FunctionVersionContent fromJson(final String json, final ObjectMap } /** - * Converts a JSON InputStream into a FunctionVersionContent object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return FunctionVersionContent object represented by the provided JSON - */ - public static FunctionVersionContent fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a FunctionVersionContent object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return FunctionVersionContent object represented by the provided JSON + */ + public static FunctionVersionContent fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, FunctionVersionContent.class); @@ -90,23 +100,12 @@ public static FunctionVersionContent fromJson(final InputStream json, final Obje @JsonCreator private FunctionVersionContent( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("function_sid") - final String functionSid, - - @JsonProperty("content") - final String content, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("function_sid") final String functionSid, + @JsonProperty("content") final String content, + @JsonProperty("url") final URI url ) { this.sid = sid; this.accountSid = accountSid; @@ -116,28 +115,33 @@ private FunctionVersionContent( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final String getFunctionSid() { - return this.functionSid; - } - public final String getContent() { - return this.content; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final String getFunctionSid() { + return this.functionSid; + } + + public final String getContent() { + return this.content; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -147,13 +151,25 @@ public boolean equals(final Object o) { FunctionVersionContent other = (FunctionVersionContent) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(functionSid, other.functionSid) && Objects.equals(content, other.content) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(functionSid, other.functionSid) && + Objects.equals(content, other.content) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, serviceSid, functionSid, content, url); + return Objects.hash( + sid, + accountSid, + serviceSid, + functionSid, + content, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/function/functionversion/FunctionVersionContentFetcher.java b/src/main/java/com/twilio/rest/serverless/v1/service/function/functionversion/FunctionVersionContentFetcher.java index c49db99300..39ac27f867 100644 --- a/src/main/java/com/twilio/rest/serverless/v1/service/function/functionversion/FunctionVersionContentFetcher.java +++ b/src/main/java/com/twilio/rest/serverless/v1/service/function/functionversion/FunctionVersionContentFetcher.java @@ -24,28 +24,39 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class FunctionVersionContentFetcher + extends Fetcher { - - -public class FunctionVersionContentFetcher extends Fetcher { private String pathServiceSid; private String pathFunctionSid; private String pathSid; - public FunctionVersionContentFetcher(final String pathServiceSid, final String pathFunctionSid, final String pathSid){ + public FunctionVersionContentFetcher( + final String pathServiceSid, + final String pathFunctionSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathFunctionSid = pathFunctionSid; this.pathSid = pathSid; } - @Override public FunctionVersionContent fetch(final TwilioRestClient client) { - String path = "/v1/Services/{ServiceSid}/Functions/{FunctionSid}/Versions/{Sid}/Content"; + String path = + "/v1/Services/{ServiceSid}/Functions/{FunctionSid}/Versions/{Sid}/Content"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"FunctionSid"+"}", this.pathFunctionSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "FunctionSid" + "}", + this.pathFunctionSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -55,15 +66,23 @@ public FunctionVersionContent fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("FunctionVersionContent fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "FunctionVersionContent fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return FunctionVersionContent.fromJson(response.getStream(), client.getObjectMapper()); + return FunctionVersionContent.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/studio/v1/Flow.java b/src/main/java/com/twilio/rest/studio/v1/Flow.java index 1e6eb76dc3..36bcf71508 100644 --- a/src/main/java/com/twilio/rest/studio/v1/Flow.java +++ b/src/main/java/com/twilio/rest/studio/v1/Flow.java @@ -24,47 +24,46 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Flow extends Resource { + private static final long serialVersionUID = 8879052558661L; - public static FlowDeleter deleter(final String pathSid){ + public static FlowDeleter deleter(final String pathSid) { return new FlowDeleter(pathSid); } - public static FlowFetcher fetcher(final String pathSid){ + public static FlowFetcher fetcher(final String pathSid) { return new FlowFetcher(pathSid); } - public static FlowReader reader(){ + public static FlowReader reader() { return new FlowReader(); } /** - * Converts a JSON String into a Flow object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Flow object represented by the provided JSON - */ - public static Flow fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Flow object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Flow object represented by the provided JSON + */ + public static Flow fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Flow.class); @@ -76,14 +75,17 @@ public static Flow fromJson(final String json, final ObjectMapper objectMapper) } /** - * Converts a JSON InputStream into a Flow object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Flow object represented by the provided JSON - */ - public static Flow fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Flow object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Flow object represented by the provided JSON + */ + public static Flow fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Flow.class); @@ -93,6 +95,7 @@ public static Flow fromJson(final InputStream json, final ObjectMapper objectMap throw new ApiConnectionException(e.getMessage(), e); } } + public enum Status { DRAFT("draft"), PUBLISHED("published"); @@ -125,32 +128,15 @@ public static Status forValue(final String value) { @JsonCreator private Flow( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("status") - final Flow.Status status, - - @JsonProperty("version") - final Integer version, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("status") final Flow.Status status, + @JsonProperty("version") final Integer version, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.sid = sid; this.accountSid = accountSid; @@ -163,37 +149,45 @@ private Flow( this.links = links; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final Flow.Status getStatus() { - return this.status; - } - public final Integer getVersion() { - return this.version; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final Flow.Status getStatus() { + return this.status; + } + + public final Integer getVersion() { + return this.version; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -203,13 +197,31 @@ public boolean equals(final Object o) { Flow other = (Flow) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(status, other.status) && Objects.equals(version, other.version) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(status, other.status) && + Objects.equals(version, other.version) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, friendlyName, status, version, dateCreated, dateUpdated, url, links); + return Objects.hash( + sid, + accountSid, + friendlyName, + status, + version, + dateCreated, + dateUpdated, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/studio/v1/FlowDeleter.java b/src/main/java/com/twilio/rest/studio/v1/FlowDeleter.java index 808b5edd2c..f3c9a6bc77 100644 --- a/src/main/java/com/twilio/rest/studio/v1/FlowDeleter.java +++ b/src/main/java/com/twilio/rest/studio/v1/FlowDeleter.java @@ -24,21 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class FlowDeleter extends Deleter { + private String pathSid; - public FlowDeleter(final String pathSid){ + public FlowDeleter(final String pathSid) { this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Flows/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -48,9 +46,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Flow delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Flow delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/studio/v1/FlowFetcher.java b/src/main/java/com/twilio/rest/studio/v1/FlowFetcher.java index 380708b633..d0deb1fd31 100644 --- a/src/main/java/com/twilio/rest/studio/v1/FlowFetcher.java +++ b/src/main/java/com/twilio/rest/studio/v1/FlowFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class FlowFetcher extends Fetcher { + private String pathSid; - public FlowFetcher(final String pathSid){ + public FlowFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public Flow fetch(final TwilioRestClient client) { String path = "/v1/Flows/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,9 +46,14 @@ public Flow fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Flow fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Flow fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/studio/v1/FlowReader.java b/src/main/java/com/twilio/rest/studio/v1/FlowReader.java index 2ed25e0009..a125da3481 100644 --- a/src/main/java/com/twilio/rest/studio/v1/FlowReader.java +++ b/src/main/java/com/twilio/rest/studio/v1/FlowReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.studio.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,17 +25,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class FlowReader extends Reader { + private Integer pageSize; - public FlowReader(){ - } + public FlowReader() {} - public FlowReader setPageSize(final Integer pageSize){ + public FlowReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -57,13 +55,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Flow read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Flow read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -79,7 +85,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request r } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.STUDIO.toString()) @@ -87,9 +96,11 @@ public Page previousPage(final Page page, final TwilioRestClient cli return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.STUDIO.toString()) @@ -98,21 +109,21 @@ public Page nextPage(final Page page, final TwilioRestClient client) } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/studio/v1/flow/Engagement.java b/src/main/java/com/twilio/rest/studio/v1/flow/Engagement.java index f5604ec9bd..ec7cef6a4c 100644 --- a/src/main/java/com/twilio/rest/studio/v1/flow/Engagement.java +++ b/src/main/java/com/twilio/rest/studio/v1/flow/Engagement.java @@ -24,51 +24,60 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Engagement extends Resource { + private static final long serialVersionUID = 71723617578664L; - public static EngagementCreator creator(final String pathFlowSid, final com.twilio.type.PhoneNumber to, final com.twilio.type.PhoneNumber from){ + public static EngagementCreator creator( + final String pathFlowSid, + final com.twilio.type.PhoneNumber to, + final com.twilio.type.PhoneNumber from + ) { return new EngagementCreator(pathFlowSid, to, from); } - public static EngagementDeleter deleter(final String pathFlowSid, final String pathSid){ + public static EngagementDeleter deleter( + final String pathFlowSid, + final String pathSid + ) { return new EngagementDeleter(pathFlowSid, pathSid); } - public static EngagementFetcher fetcher(final String pathFlowSid, final String pathSid){ + public static EngagementFetcher fetcher( + final String pathFlowSid, + final String pathSid + ) { return new EngagementFetcher(pathFlowSid, pathSid); } - public static EngagementReader reader(final String pathFlowSid){ + public static EngagementReader reader(final String pathFlowSid) { return new EngagementReader(pathFlowSid); } /** - * Converts a JSON String into a Engagement object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Engagement object represented by the provided JSON - */ - public static Engagement fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Engagement object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Engagement object represented by the provided JSON + */ + public static Engagement fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Engagement.class); @@ -80,14 +89,17 @@ public static Engagement fromJson(final String json, final ObjectMapper objectMa } /** - * Converts a JSON InputStream into a Engagement object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Engagement object represented by the provided JSON - */ - public static Engagement fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Engagement object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Engagement object represented by the provided JSON + */ + public static Engagement fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Engagement.class); @@ -97,6 +109,7 @@ public static Engagement fromJson(final InputStream json, final ObjectMapper obj throw new ApiConnectionException(e.getMessage(), e); } } + public enum Status { ACTIVE("active"), ENDED("ended"); @@ -131,38 +144,19 @@ public static Status forValue(final String value) { @JsonCreator private Engagement( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("flow_sid") - final String flowSid, - - @JsonProperty("contact_sid") - final String contactSid, - - @JsonProperty("contact_channel_address") - final String contactChannelAddress, - - @JsonProperty("context") - final Map context, - - @JsonProperty("status") - final Engagement.Status status, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("flow_sid") final String flowSid, + @JsonProperty("contact_sid") final String contactSid, + @JsonProperty( + "contact_channel_address" + ) final String contactChannelAddress, + @JsonProperty("context") final Map context, + @JsonProperty("status") final Engagement.Status status, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.sid = sid; this.accountSid = accountSid; @@ -177,43 +171,53 @@ private Engagement( this.links = links; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getFlowSid() { - return this.flowSid; - } - public final String getContactSid() { - return this.contactSid; - } - public final String getContactChannelAddress() { - return this.contactChannelAddress; - } - public final Map getContext() { - return this.context; - } - public final Engagement.Status getStatus() { - return this.status; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getFlowSid() { + return this.flowSid; + } + + public final String getContactSid() { + return this.contactSid; + } + + public final String getContactChannelAddress() { + return this.contactChannelAddress; + } + + public final Map getContext() { + return this.context; + } + + public final Engagement.Status getStatus() { + return this.status; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -223,13 +227,38 @@ public boolean equals(final Object o) { Engagement other = (Engagement) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(flowSid, other.flowSid) && Objects.equals(contactSid, other.contactSid) && Objects.equals(contactChannelAddress, other.contactChannelAddress) && Objects.equals(context, other.context) && Objects.equals(status, other.status) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(flowSid, other.flowSid) && + Objects.equals(contactSid, other.contactSid) && + Objects.equals( + contactChannelAddress, + other.contactChannelAddress + ) && + Objects.equals(context, other.context) && + Objects.equals(status, other.status) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, flowSid, contactSid, contactChannelAddress, context, status, dateCreated, dateUpdated, url, links); + return Objects.hash( + sid, + accountSid, + flowSid, + contactSid, + contactChannelAddress, + context, + status, + dateCreated, + dateUpdated, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/studio/v1/flow/EngagementCreator.java b/src/main/java/com/twilio/rest/studio/v1/flow/EngagementCreator.java index ba0a873785..4172725f56 100644 --- a/src/main/java/com/twilio/rest/studio/v1/flow/EngagementCreator.java +++ b/src/main/java/com/twilio/rest/studio/v1/flow/EngagementCreator.java @@ -15,9 +15,11 @@ package com.twilio.rest.studio.v1.flow; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; +import com.twilio.converter.Converter; +import com.twilio.converter.Converter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; -import com.twilio.converter.Converter; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; @@ -26,84 +28,96 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.util.Map; -import com.twilio.converter.Converter; - import java.util.Map; +public class EngagementCreator extends Creator { - -public class EngagementCreator extends Creator{ private String pathFlowSid; private com.twilio.type.PhoneNumber to; private com.twilio.type.PhoneNumber from; private Map parameters; - public EngagementCreator(final String pathFlowSid, final com.twilio.type.PhoneNumber to, final com.twilio.type.PhoneNumber from) { + public EngagementCreator( + final String pathFlowSid, + final com.twilio.type.PhoneNumber to, + final com.twilio.type.PhoneNumber from + ) { this.pathFlowSid = pathFlowSid; this.to = to; this.from = from; } - public EngagementCreator setTo(final com.twilio.type.PhoneNumber to){ + public EngagementCreator setTo(final com.twilio.type.PhoneNumber to) { this.to = to; return this; } - public EngagementCreator setTo(final String to){ + public EngagementCreator setTo(final String to) { return setTo(Promoter.phoneNumberFromString(to)); } - public EngagementCreator setFrom(final com.twilio.type.PhoneNumber from){ + + public EngagementCreator setFrom(final com.twilio.type.PhoneNumber from) { this.from = from; return this; } - public EngagementCreator setFrom(final String from){ + public EngagementCreator setFrom(final String from) { return setFrom(Promoter.phoneNumberFromString(from)); } - public EngagementCreator setParameters(final Map parameters){ + + public EngagementCreator setParameters( + final Map parameters + ) { this.parameters = parameters; return this; } @Override - public Engagement create(final TwilioRestClient client){ + public Engagement create(final TwilioRestClient client) { String path = "/v1/Flows/{FlowSid}/Engagements"; - path = path.replace("{"+"FlowSid"+"}", this.pathFlowSid.toString()); - path = path.replace("{"+"To"+"}", this.to.encode("utf-8")); - path = path.replace("{"+"From"+"}", this.from.encode("utf-8")); + path = path.replace("{" + "FlowSid" + "}", this.pathFlowSid.toString()); + path = path.replace("{" + "To" + "}", this.to.encode("utf-8")); + path = path.replace("{" + "From" + "}", this.from.encode("utf-8")); Request request = new Request( HttpMethod.POST, Domains.STUDIO.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Engagement creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Engagement creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Engagement.fromJson(response.getStream(), client.getObjectMapper()); + return Engagement.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (to != null) { request.addPostParam("To", to.toString()); - } if (from != null) { request.addPostParam("From", from.toString()); - } if (parameters != null) { - request.addPostParam("Parameters", Converter.mapToJson(parameters)); - + request.addPostParam("Parameters", Converter.mapToJson(parameters)); } } } diff --git a/src/main/java/com/twilio/rest/studio/v1/flow/EngagementDeleter.java b/src/main/java/com/twilio/rest/studio/v1/flow/EngagementDeleter.java index fcc0c2ff26..e85b0846f6 100644 --- a/src/main/java/com/twilio/rest/studio/v1/flow/EngagementDeleter.java +++ b/src/main/java/com/twilio/rest/studio/v1/flow/EngagementDeleter.java @@ -24,24 +24,22 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class EngagementDeleter extends Deleter { + private String pathFlowSid; private String pathSid; - public EngagementDeleter(final String pathFlowSid, final String pathSid){ + public EngagementDeleter(final String pathFlowSid, final String pathSid) { this.pathFlowSid = pathFlowSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Flows/{FlowSid}/Engagements/{Sid}"; - path = path.replace("{"+"FlowSid"+"}", this.pathFlowSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "FlowSid" + "}", this.pathFlowSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +49,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Engagement delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Engagement delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/studio/v1/flow/EngagementFetcher.java b/src/main/java/com/twilio/rest/studio/v1/flow/EngagementFetcher.java index 3a8935dc74..e069ae7172 100644 --- a/src/main/java/com/twilio/rest/studio/v1/flow/EngagementFetcher.java +++ b/src/main/java/com/twilio/rest/studio/v1/flow/EngagementFetcher.java @@ -24,25 +24,22 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class EngagementFetcher extends Fetcher { + private String pathFlowSid; private String pathSid; - public EngagementFetcher(final String pathFlowSid, final String pathSid){ + public EngagementFetcher(final String pathFlowSid, final String pathSid) { this.pathFlowSid = pathFlowSid; this.pathSid = pathSid; } - @Override public Engagement fetch(final TwilioRestClient client) { String path = "/v1/Flows/{FlowSid}/Engagements/{Sid}"; - path = path.replace("{"+"FlowSid"+"}", this.pathFlowSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "FlowSid" + "}", this.pathFlowSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,15 +49,23 @@ public Engagement fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Engagement fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Engagement fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Engagement.fromJson(response.getStream(), client.getObjectMapper()); + return Engagement.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/studio/v1/flow/EngagementReader.java b/src/main/java/com/twilio/rest/studio/v1/flow/EngagementReader.java index eb7e7ed7cc..de12269520 100644 --- a/src/main/java/com/twilio/rest/studio/v1/flow/EngagementReader.java +++ b/src/main/java/com/twilio/rest/studio/v1/flow/EngagementReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.studio.v1.flow; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,19 +25,17 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class EngagementReader extends Reader { + private String pathFlowSid; private Integer pageSize; - public EngagementReader(final String pathFlowSid){ + public EngagementReader(final String pathFlowSid) { this.pathFlowSid = pathFlowSid; } - public EngagementReader setPageSize(final Integer pageSize){ + public EngagementReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -48,7 +47,7 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Flows/{FlowSid}/Engagements"; - path = path.replace("{"+"FlowSid"+"}", this.pathFlowSid.toString()); + path = path.replace("{" + "FlowSid" + "}", this.pathFlowSid.toString()); Request request = new Request( HttpMethod.GET, @@ -60,13 +59,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Engagement read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Engagement read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +89,10 @@ private Page pageForRequest(final TwilioRestClient client, final Req } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.STUDIO.toString()) @@ -90,9 +100,11 @@ public Page previousPage(final Page page, final TwilioRe return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.STUDIO.toString()) @@ -101,21 +113,21 @@ public Page nextPage(final Page page, final TwilioRestCl } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/studio/v1/flow/Execution.java b/src/main/java/com/twilio/rest/studio/v1/flow/Execution.java index 0af3aa4205..0d6a180648 100644 --- a/src/main/java/com/twilio/rest/studio/v1/flow/Execution.java +++ b/src/main/java/com/twilio/rest/studio/v1/flow/Execution.java @@ -24,55 +24,68 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Execution extends Resource { + private static final long serialVersionUID = 221370387280625L; - public static ExecutionCreator creator(final String pathFlowSid, final com.twilio.type.PhoneNumber to, final com.twilio.type.PhoneNumber from){ + public static ExecutionCreator creator( + final String pathFlowSid, + final com.twilio.type.PhoneNumber to, + final com.twilio.type.PhoneNumber from + ) { return new ExecutionCreator(pathFlowSid, to, from); } - public static ExecutionDeleter deleter(final String pathFlowSid, final String pathSid){ + public static ExecutionDeleter deleter( + final String pathFlowSid, + final String pathSid + ) { return new ExecutionDeleter(pathFlowSid, pathSid); } - public static ExecutionFetcher fetcher(final String pathFlowSid, final String pathSid){ + public static ExecutionFetcher fetcher( + final String pathFlowSid, + final String pathSid + ) { return new ExecutionFetcher(pathFlowSid, pathSid); } - public static ExecutionReader reader(final String pathFlowSid){ + public static ExecutionReader reader(final String pathFlowSid) { return new ExecutionReader(pathFlowSid); } - public static ExecutionUpdater updater(final String pathFlowSid, final String pathSid, final Execution.Status status){ + public static ExecutionUpdater updater( + final String pathFlowSid, + final String pathSid, + final Execution.Status status + ) { return new ExecutionUpdater(pathFlowSid, pathSid, status); } /** - * Converts a JSON String into a Execution object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Execution object represented by the provided JSON - */ - public static Execution fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Execution object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Execution object represented by the provided JSON + */ + public static Execution fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Execution.class); @@ -84,14 +97,17 @@ public static Execution fromJson(final String json, final ObjectMapper objectMap } /** - * Converts a JSON InputStream into a Execution object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Execution object represented by the provided JSON - */ - public static Execution fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Execution object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Execution object represented by the provided JSON + */ + public static Execution fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Execution.class); @@ -101,6 +117,7 @@ public static Execution fromJson(final InputStream json, final ObjectMapper obje throw new ApiConnectionException(e.getMessage(), e); } } + public enum Status { ACTIVE("active"), ENDED("ended"); @@ -135,38 +152,19 @@ public static Status forValue(final String value) { @JsonCreator private Execution( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("flow_sid") - final String flowSid, - - @JsonProperty("contact_sid") - final String contactSid, - - @JsonProperty("contact_channel_address") - final String contactChannelAddress, - - @JsonProperty("context") - final Map context, - - @JsonProperty("status") - final Execution.Status status, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("flow_sid") final String flowSid, + @JsonProperty("contact_sid") final String contactSid, + @JsonProperty( + "contact_channel_address" + ) final String contactChannelAddress, + @JsonProperty("context") final Map context, + @JsonProperty("status") final Execution.Status status, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.sid = sid; this.accountSid = accountSid; @@ -181,43 +179,53 @@ private Execution( this.links = links; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getFlowSid() { - return this.flowSid; - } - public final String getContactSid() { - return this.contactSid; - } - public final String getContactChannelAddress() { - return this.contactChannelAddress; - } - public final Map getContext() { - return this.context; - } - public final Execution.Status getStatus() { - return this.status; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getFlowSid() { + return this.flowSid; + } + + public final String getContactSid() { + return this.contactSid; + } + + public final String getContactChannelAddress() { + return this.contactChannelAddress; + } + + public final Map getContext() { + return this.context; + } + + public final Execution.Status getStatus() { + return this.status; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -227,13 +235,38 @@ public boolean equals(final Object o) { Execution other = (Execution) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(flowSid, other.flowSid) && Objects.equals(contactSid, other.contactSid) && Objects.equals(contactChannelAddress, other.contactChannelAddress) && Objects.equals(context, other.context) && Objects.equals(status, other.status) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(flowSid, other.flowSid) && + Objects.equals(contactSid, other.contactSid) && + Objects.equals( + contactChannelAddress, + other.contactChannelAddress + ) && + Objects.equals(context, other.context) && + Objects.equals(status, other.status) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, flowSid, contactSid, contactChannelAddress, context, status, dateCreated, dateUpdated, url, links); + return Objects.hash( + sid, + accountSid, + flowSid, + contactSid, + contactChannelAddress, + context, + status, + dateCreated, + dateUpdated, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/studio/v1/flow/ExecutionCreator.java b/src/main/java/com/twilio/rest/studio/v1/flow/ExecutionCreator.java index 304c411783..c5ac70dbec 100644 --- a/src/main/java/com/twilio/rest/studio/v1/flow/ExecutionCreator.java +++ b/src/main/java/com/twilio/rest/studio/v1/flow/ExecutionCreator.java @@ -15,9 +15,11 @@ package com.twilio.rest.studio.v1.flow; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; +import com.twilio.converter.Converter; +import com.twilio.converter.Converter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; -import com.twilio.converter.Converter; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; @@ -26,84 +28,96 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.util.Map; -import com.twilio.converter.Converter; - import java.util.Map; +public class ExecutionCreator extends Creator { - -public class ExecutionCreator extends Creator{ private String pathFlowSid; private com.twilio.type.PhoneNumber to; private com.twilio.type.PhoneNumber from; private Map parameters; - public ExecutionCreator(final String pathFlowSid, final com.twilio.type.PhoneNumber to, final com.twilio.type.PhoneNumber from) { + public ExecutionCreator( + final String pathFlowSid, + final com.twilio.type.PhoneNumber to, + final com.twilio.type.PhoneNumber from + ) { this.pathFlowSid = pathFlowSid; this.to = to; this.from = from; } - public ExecutionCreator setTo(final com.twilio.type.PhoneNumber to){ + public ExecutionCreator setTo(final com.twilio.type.PhoneNumber to) { this.to = to; return this; } - public ExecutionCreator setTo(final String to){ + public ExecutionCreator setTo(final String to) { return setTo(Promoter.phoneNumberFromString(to)); } - public ExecutionCreator setFrom(final com.twilio.type.PhoneNumber from){ + + public ExecutionCreator setFrom(final com.twilio.type.PhoneNumber from) { this.from = from; return this; } - public ExecutionCreator setFrom(final String from){ + public ExecutionCreator setFrom(final String from) { return setFrom(Promoter.phoneNumberFromString(from)); } - public ExecutionCreator setParameters(final Map parameters){ + + public ExecutionCreator setParameters( + final Map parameters + ) { this.parameters = parameters; return this; } @Override - public Execution create(final TwilioRestClient client){ + public Execution create(final TwilioRestClient client) { String path = "/v1/Flows/{FlowSid}/Executions"; - path = path.replace("{"+"FlowSid"+"}", this.pathFlowSid.toString()); - path = path.replace("{"+"To"+"}", this.to.encode("utf-8")); - path = path.replace("{"+"From"+"}", this.from.encode("utf-8")); + path = path.replace("{" + "FlowSid" + "}", this.pathFlowSid.toString()); + path = path.replace("{" + "To" + "}", this.to.encode("utf-8")); + path = path.replace("{" + "From" + "}", this.from.encode("utf-8")); Request request = new Request( HttpMethod.POST, Domains.STUDIO.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Execution creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Execution creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Execution.fromJson(response.getStream(), client.getObjectMapper()); + return Execution.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (to != null) { request.addPostParam("To", to.toString()); - } if (from != null) { request.addPostParam("From", from.toString()); - } if (parameters != null) { - request.addPostParam("Parameters", Converter.mapToJson(parameters)); - + request.addPostParam("Parameters", Converter.mapToJson(parameters)); } } } diff --git a/src/main/java/com/twilio/rest/studio/v1/flow/ExecutionDeleter.java b/src/main/java/com/twilio/rest/studio/v1/flow/ExecutionDeleter.java index 78a2e22f65..92d76697da 100644 --- a/src/main/java/com/twilio/rest/studio/v1/flow/ExecutionDeleter.java +++ b/src/main/java/com/twilio/rest/studio/v1/flow/ExecutionDeleter.java @@ -24,24 +24,22 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class ExecutionDeleter extends Deleter { + private String pathFlowSid; private String pathSid; - public ExecutionDeleter(final String pathFlowSid, final String pathSid){ + public ExecutionDeleter(final String pathFlowSid, final String pathSid) { this.pathFlowSid = pathFlowSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Flows/{FlowSid}/Executions/{Sid}"; - path = path.replace("{"+"FlowSid"+"}", this.pathFlowSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "FlowSid" + "}", this.pathFlowSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +49,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Execution delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Execution delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/studio/v1/flow/ExecutionFetcher.java b/src/main/java/com/twilio/rest/studio/v1/flow/ExecutionFetcher.java index 604daeb774..4fe732283a 100644 --- a/src/main/java/com/twilio/rest/studio/v1/flow/ExecutionFetcher.java +++ b/src/main/java/com/twilio/rest/studio/v1/flow/ExecutionFetcher.java @@ -24,25 +24,22 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class ExecutionFetcher extends Fetcher { + private String pathFlowSid; private String pathSid; - public ExecutionFetcher(final String pathFlowSid, final String pathSid){ + public ExecutionFetcher(final String pathFlowSid, final String pathSid) { this.pathFlowSid = pathFlowSid; this.pathSid = pathSid; } - @Override public Execution fetch(final TwilioRestClient client) { String path = "/v1/Flows/{FlowSid}/Executions/{Sid}"; - path = path.replace("{"+"FlowSid"+"}", this.pathFlowSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "FlowSid" + "}", this.pathFlowSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,15 +49,23 @@ public Execution fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Execution fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Execution fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Execution.fromJson(response.getStream(), client.getObjectMapper()); + return Execution.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/studio/v1/flow/ExecutionReader.java b/src/main/java/com/twilio/rest/studio/v1/flow/ExecutionReader.java index 7510353987..6e8d2092a2 100644 --- a/src/main/java/com/twilio/rest/studio/v1/flow/ExecutionReader.java +++ b/src/main/java/com/twilio/rest/studio/v1/flow/ExecutionReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.studio.v1.flow; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,30 +25,32 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; import java.time.ZonedDateTime; - - public class ExecutionReader extends Reader { + private String pathFlowSid; private ZonedDateTime dateCreatedFrom; private ZonedDateTime dateCreatedTo; private Integer pageSize; - public ExecutionReader(final String pathFlowSid){ + public ExecutionReader(final String pathFlowSid) { this.pathFlowSid = pathFlowSid; } - public ExecutionReader setDateCreatedFrom(final ZonedDateTime dateCreatedFrom){ + public ExecutionReader setDateCreatedFrom( + final ZonedDateTime dateCreatedFrom + ) { this.dateCreatedFrom = dateCreatedFrom; return this; } - public ExecutionReader setDateCreatedTo(final ZonedDateTime dateCreatedTo){ + + public ExecutionReader setDateCreatedTo(final ZonedDateTime dateCreatedTo) { this.dateCreatedTo = dateCreatedTo; return this; } - public ExecutionReader setPageSize(final Integer pageSize){ + + public ExecutionReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -59,7 +62,7 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Flows/{FlowSid}/Executions"; - path = path.replace("{"+"FlowSid"+"}", this.pathFlowSid.toString()); + path = path.replace("{" + "FlowSid" + "}", this.pathFlowSid.toString()); Request request = new Request( HttpMethod.GET, @@ -71,13 +74,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Execution read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Execution read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -93,7 +104,10 @@ private Page pageForRequest(final TwilioRestClient client, final Requ } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.STUDIO.toString()) @@ -101,9 +115,11 @@ public Page previousPage(final Page page, final TwilioRest return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.STUDIO.toString()) @@ -112,29 +128,35 @@ public Page nextPage(final Page page, final TwilioRestClie } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (dateCreatedFrom != null) { - request.addQueryParam("DateCreatedFrom", dateCreatedFrom.toInstant().toString()); + request.addQueryParam( + "DateCreatedFrom", + dateCreatedFrom.toInstant().toString() + ); } if (dateCreatedTo != null) { - request.addQueryParam("DateCreatedTo", dateCreatedTo.toInstant().toString()); + request.addQueryParam( + "DateCreatedTo", + dateCreatedTo.toInstant().toString() + ); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/studio/v1/flow/ExecutionUpdater.java b/src/main/java/com/twilio/rest/studio/v1/flow/ExecutionUpdater.java index 10fc71f380..b7c9754ef6 100644 --- a/src/main/java/com/twilio/rest/studio/v1/flow/ExecutionUpdater.java +++ b/src/main/java/com/twilio/rest/studio/v1/flow/ExecutionUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.studio.v1.flow; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,56 +25,67 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class ExecutionUpdater extends Updater { - - -public class ExecutionUpdater extends Updater{ private String pathFlowSid; private String pathSid; private Execution.Status status; - public ExecutionUpdater(final String pathFlowSid, final String pathSid, final Execution.Status status){ + public ExecutionUpdater( + final String pathFlowSid, + final String pathSid, + final Execution.Status status + ) { this.pathFlowSid = pathFlowSid; this.pathSid = pathSid; this.status = status; } - public ExecutionUpdater setStatus(final Execution.Status status){ + public ExecutionUpdater setStatus(final Execution.Status status) { this.status = status; return this; } @Override - public Execution update(final TwilioRestClient client){ + public Execution update(final TwilioRestClient client) { String path = "/v1/Flows/{FlowSid}/Executions/{Sid}"; - path = path.replace("{"+"FlowSid"+"}", this.pathFlowSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); - path = path.replace("{"+"Status"+"}", this.status.toString()); + path = path.replace("{" + "FlowSid" + "}", this.pathFlowSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + path = path.replace("{" + "Status" + "}", this.status.toString()); Request request = new Request( HttpMethod.POST, Domains.STUDIO.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Execution update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Execution update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Execution.fromJson(response.getStream(), client.getObjectMapper()); + return Execution.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (status != null) { request.addPostParam("Status", status.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/studio/v1/flow/engagement/EngagementContext.java b/src/main/java/com/twilio/rest/studio/v1/flow/engagement/EngagementContext.java index fdf970d389..45ed628e3b 100644 --- a/src/main/java/com/twilio/rest/studio/v1/flow/engagement/EngagementContext.java +++ b/src/main/java/com/twilio/rest/studio/v1/flow/engagement/EngagementContext.java @@ -22,38 +22,40 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class EngagementContext extends Resource { + private static final long serialVersionUID = 182363461244967L; - public static EngagementContextFetcher fetcher(final String pathFlowSid, final String pathEngagementSid){ + public static EngagementContextFetcher fetcher( + final String pathFlowSid, + final String pathEngagementSid + ) { return new EngagementContextFetcher(pathFlowSid, pathEngagementSid); } /** - * Converts a JSON String into a EngagementContext object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return EngagementContext object represented by the provided JSON - */ - public static EngagementContext fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a EngagementContext object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return EngagementContext object represented by the provided JSON + */ + public static EngagementContext fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, EngagementContext.class); @@ -65,14 +67,17 @@ public static EngagementContext fromJson(final String json, final ObjectMapper o } /** - * Converts a JSON InputStream into a EngagementContext object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return EngagementContext object represented by the provided JSON - */ - public static EngagementContext fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a EngagementContext object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return EngagementContext object represented by the provided JSON + */ + public static EngagementContext fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, EngagementContext.class); @@ -91,20 +96,11 @@ public static EngagementContext fromJson(final InputStream json, final ObjectMap @JsonCreator private EngagementContext( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("context") - final Map context, - - @JsonProperty("engagement_sid") - final String engagementSid, - - @JsonProperty("flow_sid") - final String flowSid, - - @JsonProperty("url") - final URI url + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("context") final Map context, + @JsonProperty("engagement_sid") final String engagementSid, + @JsonProperty("flow_sid") final String flowSid, + @JsonProperty("url") final URI url ) { this.accountSid = accountSid; this.context = context; @@ -113,25 +109,29 @@ private EngagementContext( this.url = url; } - public final String getAccountSid() { - return this.accountSid; - } - public final Map getContext() { - return this.context; - } - public final String getEngagementSid() { - return this.engagementSid; - } - public final String getFlowSid() { - return this.flowSid; - } - public final URI getUrl() { - return this.url; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final Map getContext() { + return this.context; + } + + public final String getEngagementSid() { + return this.engagementSid; + } + + public final String getFlowSid() { + return this.flowSid; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -141,13 +141,17 @@ public boolean equals(final Object o) { EngagementContext other = (EngagementContext) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(context, other.context) && Objects.equals(engagementSid, other.engagementSid) && Objects.equals(flowSid, other.flowSid) && Objects.equals(url, other.url) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(context, other.context) && + Objects.equals(engagementSid, other.engagementSid) && + Objects.equals(flowSid, other.flowSid) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { return Objects.hash(accountSid, context, engagementSid, flowSid, url); } - } - diff --git a/src/main/java/com/twilio/rest/studio/v1/flow/engagement/EngagementContextFetcher.java b/src/main/java/com/twilio/rest/studio/v1/flow/engagement/EngagementContextFetcher.java index f585cb8845..6e097de476 100644 --- a/src/main/java/com/twilio/rest/studio/v1/flow/engagement/EngagementContextFetcher.java +++ b/src/main/java/com/twilio/rest/studio/v1/flow/engagement/EngagementContextFetcher.java @@ -24,25 +24,29 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class EngagementContextFetcher extends Fetcher { + private String pathFlowSid; private String pathEngagementSid; - public EngagementContextFetcher(final String pathFlowSid, final String pathEngagementSid){ + public EngagementContextFetcher( + final String pathFlowSid, + final String pathEngagementSid + ) { this.pathFlowSid = pathFlowSid; this.pathEngagementSid = pathEngagementSid; } - @Override public EngagementContext fetch(final TwilioRestClient client) { String path = "/v1/Flows/{FlowSid}/Engagements/{EngagementSid}/Context"; - path = path.replace("{"+"FlowSid"+"}", this.pathFlowSid.toString()); - path = path.replace("{"+"EngagementSid"+"}", this.pathEngagementSid.toString()); + path = path.replace("{" + "FlowSid" + "}", this.pathFlowSid.toString()); + path = + path.replace( + "{" + "EngagementSid" + "}", + this.pathEngagementSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -52,15 +56,23 @@ public EngagementContext fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("EngagementContext fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "EngagementContext fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return EngagementContext.fromJson(response.getStream(), client.getObjectMapper()); + return EngagementContext.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/studio/v1/flow/engagement/Step.java b/src/main/java/com/twilio/rest/studio/v1/flow/engagement/Step.java index df3ee0cfc4..9a8f158131 100644 --- a/src/main/java/com/twilio/rest/studio/v1/flow/engagement/Step.java +++ b/src/main/java/com/twilio/rest/studio/v1/flow/engagement/Step.java @@ -23,43 +23,49 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Step extends Resource { + private static final long serialVersionUID = 7112234025465L; - public static StepFetcher fetcher(final String pathFlowSid, final String pathEngagementSid, final String pathSid){ + public static StepFetcher fetcher( + final String pathFlowSid, + final String pathEngagementSid, + final String pathSid + ) { return new StepFetcher(pathFlowSid, pathEngagementSid, pathSid); } - public static StepReader reader(final String pathFlowSid, final String pathEngagementSid){ + public static StepReader reader( + final String pathFlowSid, + final String pathEngagementSid + ) { return new StepReader(pathFlowSid, pathEngagementSid); } /** - * Converts a JSON String into a Step object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Step object represented by the provided JSON - */ - public static Step fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Step object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Step object represented by the provided JSON + */ + public static Step fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Step.class); @@ -71,14 +77,17 @@ public static Step fromJson(final String json, final ObjectMapper objectMapper) } /** - * Converts a JSON InputStream into a Step object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Step object represented by the provided JSON - */ - public static Step fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Step object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Step object represented by the provided JSON + */ + public static Step fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Step.class); @@ -104,41 +113,18 @@ public static Step fromJson(final InputStream json, final ObjectMapper objectMap @JsonCreator private Step( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("flow_sid") - final String flowSid, - - @JsonProperty("engagement_sid") - final String engagementSid, - - @JsonProperty("name") - final String name, - - @JsonProperty("context") - final Map context, - - @JsonProperty("transitioned_from") - final String transitionedFrom, - - @JsonProperty("transitioned_to") - final String transitionedTo, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("flow_sid") final String flowSid, + @JsonProperty("engagement_sid") final String engagementSid, + @JsonProperty("name") final String name, + @JsonProperty("context") final Map context, + @JsonProperty("transitioned_from") final String transitionedFrom, + @JsonProperty("transitioned_to") final String transitionedTo, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.sid = sid; this.accountSid = accountSid; @@ -154,46 +140,57 @@ private Step( this.links = links; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getFlowSid() { - return this.flowSid; - } - public final String getEngagementSid() { - return this.engagementSid; - } - public final String getName() { - return this.name; - } - public final Map getContext() { - return this.context; - } - public final String getTransitionedFrom() { - return this.transitionedFrom; - } - public final String getTransitionedTo() { - return this.transitionedTo; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getFlowSid() { + return this.flowSid; + } + + public final String getEngagementSid() { + return this.engagementSid; + } + + public final String getName() { + return this.name; + } + + public final Map getContext() { + return this.context; + } + + public final String getTransitionedFrom() { + return this.transitionedFrom; + } + + public final String getTransitionedTo() { + return this.transitionedTo; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -203,13 +200,37 @@ public boolean equals(final Object o) { Step other = (Step) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(flowSid, other.flowSid) && Objects.equals(engagementSid, other.engagementSid) && Objects.equals(name, other.name) && Objects.equals(context, other.context) && Objects.equals(transitionedFrom, other.transitionedFrom) && Objects.equals(transitionedTo, other.transitionedTo) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(flowSid, other.flowSid) && + Objects.equals(engagementSid, other.engagementSid) && + Objects.equals(name, other.name) && + Objects.equals(context, other.context) && + Objects.equals(transitionedFrom, other.transitionedFrom) && + Objects.equals(transitionedTo, other.transitionedTo) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, flowSid, engagementSid, name, context, transitionedFrom, transitionedTo, dateCreated, dateUpdated, url, links); + return Objects.hash( + sid, + accountSid, + flowSid, + engagementSid, + name, + context, + transitionedFrom, + transitionedTo, + dateCreated, + dateUpdated, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/studio/v1/flow/engagement/StepFetcher.java b/src/main/java/com/twilio/rest/studio/v1/flow/engagement/StepFetcher.java index e793738c23..06be445396 100644 --- a/src/main/java/com/twilio/rest/studio/v1/flow/engagement/StepFetcher.java +++ b/src/main/java/com/twilio/rest/studio/v1/flow/engagement/StepFetcher.java @@ -24,28 +24,34 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class StepFetcher extends Fetcher { + private String pathFlowSid; private String pathEngagementSid; private String pathSid; - public StepFetcher(final String pathFlowSid, final String pathEngagementSid, final String pathSid){ + public StepFetcher( + final String pathFlowSid, + final String pathEngagementSid, + final String pathSid + ) { this.pathFlowSid = pathFlowSid; this.pathEngagementSid = pathEngagementSid; this.pathSid = pathSid; } - @Override public Step fetch(final TwilioRestClient client) { - String path = "/v1/Flows/{FlowSid}/Engagements/{EngagementSid}/Steps/{Sid}"; + String path = + "/v1/Flows/{FlowSid}/Engagements/{EngagementSid}/Steps/{Sid}"; - path = path.replace("{"+"FlowSid"+"}", this.pathFlowSid.toString()); - path = path.replace("{"+"EngagementSid"+"}", this.pathEngagementSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "FlowSid" + "}", this.pathFlowSid.toString()); + path = + path.replace( + "{" + "EngagementSid" + "}", + this.pathEngagementSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -55,9 +61,14 @@ public Step fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Step fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Step fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/studio/v1/flow/engagement/StepReader.java b/src/main/java/com/twilio/rest/studio/v1/flow/engagement/StepReader.java index 19c36da4ec..5d5db609c9 100644 --- a/src/main/java/com/twilio/rest/studio/v1/flow/engagement/StepReader.java +++ b/src/main/java/com/twilio/rest/studio/v1/flow/engagement/StepReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.studio.v1.flow.engagement; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,21 +25,22 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class StepReader extends Reader { + private String pathFlowSid; private String pathEngagementSid; private Integer pageSize; - public StepReader(final String pathFlowSid, final String pathEngagementSid){ + public StepReader( + final String pathFlowSid, + final String pathEngagementSid + ) { this.pathFlowSid = pathFlowSid; this.pathEngagementSid = pathEngagementSid; } - public StepReader setPageSize(final Integer pageSize){ + public StepReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -50,8 +52,12 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Flows/{FlowSid}/Engagements/{EngagementSid}/Steps"; - path = path.replace("{"+"FlowSid"+"}", this.pathFlowSid.toString()); - path = path.replace("{"+"EngagementSid"+"}", this.pathEngagementSid.toString()); + path = path.replace("{" + "FlowSid" + "}", this.pathFlowSid.toString()); + path = + path.replace( + "{" + "EngagementSid" + "}", + this.pathEngagementSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -63,13 +69,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Step read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Step read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -85,7 +99,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request r } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.STUDIO.toString()) @@ -93,9 +110,11 @@ public Page previousPage(final Page page, final TwilioRestClient cli return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.STUDIO.toString()) @@ -104,21 +123,21 @@ public Page nextPage(final Page page, final TwilioRestClient client) } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/studio/v1/flow/engagement/step/StepContext.java b/src/main/java/com/twilio/rest/studio/v1/flow/engagement/step/StepContext.java index fec1ff5034..b3f8a40bf4 100644 --- a/src/main/java/com/twilio/rest/studio/v1/flow/engagement/step/StepContext.java +++ b/src/main/java/com/twilio/rest/studio/v1/flow/engagement/step/StepContext.java @@ -22,38 +22,45 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class StepContext extends Resource { + private static final long serialVersionUID = 81685274380880L; - public static StepContextFetcher fetcher(final String pathFlowSid, final String pathEngagementSid, final String pathStepSid){ - return new StepContextFetcher(pathFlowSid, pathEngagementSid, pathStepSid); + public static StepContextFetcher fetcher( + final String pathFlowSid, + final String pathEngagementSid, + final String pathStepSid + ) { + return new StepContextFetcher( + pathFlowSid, + pathEngagementSid, + pathStepSid + ); } /** - * Converts a JSON String into a StepContext object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return StepContext object represented by the provided JSON - */ - public static StepContext fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a StepContext object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return StepContext object represented by the provided JSON + */ + public static StepContext fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, StepContext.class); @@ -65,14 +72,17 @@ public static StepContext fromJson(final String json, final ObjectMapper objectM } /** - * Converts a JSON InputStream into a StepContext object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return StepContext object represented by the provided JSON - */ - public static StepContext fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a StepContext object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return StepContext object represented by the provided JSON + */ + public static StepContext fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, StepContext.class); @@ -92,23 +102,12 @@ public static StepContext fromJson(final InputStream json, final ObjectMapper ob @JsonCreator private StepContext( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("context") - final Map context, - - @JsonProperty("engagement_sid") - final String engagementSid, - - @JsonProperty("flow_sid") - final String flowSid, - - @JsonProperty("step_sid") - final String stepSid, - - @JsonProperty("url") - final URI url + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("context") final Map context, + @JsonProperty("engagement_sid") final String engagementSid, + @JsonProperty("flow_sid") final String flowSid, + @JsonProperty("step_sid") final String stepSid, + @JsonProperty("url") final URI url ) { this.accountSid = accountSid; this.context = context; @@ -118,28 +117,33 @@ private StepContext( this.url = url; } - public final String getAccountSid() { - return this.accountSid; - } - public final Map getContext() { - return this.context; - } - public final String getEngagementSid() { - return this.engagementSid; - } - public final String getFlowSid() { - return this.flowSid; - } - public final String getStepSid() { - return this.stepSid; - } - public final URI getUrl() { - return this.url; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final Map getContext() { + return this.context; + } + + public final String getEngagementSid() { + return this.engagementSid; + } + + public final String getFlowSid() { + return this.flowSid; + } + + public final String getStepSid() { + return this.stepSid; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -149,13 +153,25 @@ public boolean equals(final Object o) { StepContext other = (StepContext) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(context, other.context) && Objects.equals(engagementSid, other.engagementSid) && Objects.equals(flowSid, other.flowSid) && Objects.equals(stepSid, other.stepSid) && Objects.equals(url, other.url) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(context, other.context) && + Objects.equals(engagementSid, other.engagementSid) && + Objects.equals(flowSid, other.flowSid) && + Objects.equals(stepSid, other.stepSid) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, context, engagementSid, flowSid, stepSid, url); + return Objects.hash( + accountSid, + context, + engagementSid, + flowSid, + stepSid, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/studio/v1/flow/engagement/step/StepContextFetcher.java b/src/main/java/com/twilio/rest/studio/v1/flow/engagement/step/StepContextFetcher.java index 9c6d685635..fde2e90c41 100644 --- a/src/main/java/com/twilio/rest/studio/v1/flow/engagement/step/StepContextFetcher.java +++ b/src/main/java/com/twilio/rest/studio/v1/flow/engagement/step/StepContextFetcher.java @@ -24,28 +24,34 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class StepContextFetcher extends Fetcher { + private String pathFlowSid; private String pathEngagementSid; private String pathStepSid; - public StepContextFetcher(final String pathFlowSid, final String pathEngagementSid, final String pathStepSid){ + public StepContextFetcher( + final String pathFlowSid, + final String pathEngagementSid, + final String pathStepSid + ) { this.pathFlowSid = pathFlowSid; this.pathEngagementSid = pathEngagementSid; this.pathStepSid = pathStepSid; } - @Override public StepContext fetch(final TwilioRestClient client) { - String path = "/v1/Flows/{FlowSid}/Engagements/{EngagementSid}/Steps/{StepSid}/Context"; + String path = + "/v1/Flows/{FlowSid}/Engagements/{EngagementSid}/Steps/{StepSid}/Context"; - path = path.replace("{"+"FlowSid"+"}", this.pathFlowSid.toString()); - path = path.replace("{"+"EngagementSid"+"}", this.pathEngagementSid.toString()); - path = path.replace("{"+"StepSid"+"}", this.pathStepSid.toString()); + path = path.replace("{" + "FlowSid" + "}", this.pathFlowSid.toString()); + path = + path.replace( + "{" + "EngagementSid" + "}", + this.pathEngagementSid.toString() + ); + path = path.replace("{" + "StepSid" + "}", this.pathStepSid.toString()); Request request = new Request( HttpMethod.GET, @@ -55,15 +61,23 @@ public StepContext fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("StepContext fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "StepContext fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return StepContext.fromJson(response.getStream(), client.getObjectMapper()); + return StepContext.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/studio/v1/flow/execution/ExecutionContext.java b/src/main/java/com/twilio/rest/studio/v1/flow/execution/ExecutionContext.java index d33f2a033c..74e99241f0 100644 --- a/src/main/java/com/twilio/rest/studio/v1/flow/execution/ExecutionContext.java +++ b/src/main/java/com/twilio/rest/studio/v1/flow/execution/ExecutionContext.java @@ -22,38 +22,40 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class ExecutionContext extends Resource { + private static final long serialVersionUID = 48761390116247L; - public static ExecutionContextFetcher fetcher(final String pathFlowSid, final String pathExecutionSid){ + public static ExecutionContextFetcher fetcher( + final String pathFlowSid, + final String pathExecutionSid + ) { return new ExecutionContextFetcher(pathFlowSid, pathExecutionSid); } /** - * Converts a JSON String into a ExecutionContext object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return ExecutionContext object represented by the provided JSON - */ - public static ExecutionContext fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a ExecutionContext object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return ExecutionContext object represented by the provided JSON + */ + public static ExecutionContext fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, ExecutionContext.class); @@ -65,14 +67,17 @@ public static ExecutionContext fromJson(final String json, final ObjectMapper ob } /** - * Converts a JSON InputStream into a ExecutionContext object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return ExecutionContext object represented by the provided JSON - */ - public static ExecutionContext fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a ExecutionContext object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return ExecutionContext object represented by the provided JSON + */ + public static ExecutionContext fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, ExecutionContext.class); @@ -91,20 +96,11 @@ public static ExecutionContext fromJson(final InputStream json, final ObjectMapp @JsonCreator private ExecutionContext( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("context") - final Map context, - - @JsonProperty("flow_sid") - final String flowSid, - - @JsonProperty("execution_sid") - final String executionSid, - - @JsonProperty("url") - final URI url + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("context") final Map context, + @JsonProperty("flow_sid") final String flowSid, + @JsonProperty("execution_sid") final String executionSid, + @JsonProperty("url") final URI url ) { this.accountSid = accountSid; this.context = context; @@ -113,25 +109,29 @@ private ExecutionContext( this.url = url; } - public final String getAccountSid() { - return this.accountSid; - } - public final Map getContext() { - return this.context; - } - public final String getFlowSid() { - return this.flowSid; - } - public final String getExecutionSid() { - return this.executionSid; - } - public final URI getUrl() { - return this.url; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final Map getContext() { + return this.context; + } + + public final String getFlowSid() { + return this.flowSid; + } + + public final String getExecutionSid() { + return this.executionSid; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -141,13 +141,17 @@ public boolean equals(final Object o) { ExecutionContext other = (ExecutionContext) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(context, other.context) && Objects.equals(flowSid, other.flowSid) && Objects.equals(executionSid, other.executionSid) && Objects.equals(url, other.url) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(context, other.context) && + Objects.equals(flowSid, other.flowSid) && + Objects.equals(executionSid, other.executionSid) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { return Objects.hash(accountSid, context, flowSid, executionSid, url); } - } - diff --git a/src/main/java/com/twilio/rest/studio/v1/flow/execution/ExecutionContextFetcher.java b/src/main/java/com/twilio/rest/studio/v1/flow/execution/ExecutionContextFetcher.java index 1d1d55317e..1100396e30 100644 --- a/src/main/java/com/twilio/rest/studio/v1/flow/execution/ExecutionContextFetcher.java +++ b/src/main/java/com/twilio/rest/studio/v1/flow/execution/ExecutionContextFetcher.java @@ -24,25 +24,29 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class ExecutionContextFetcher extends Fetcher { + private String pathFlowSid; private String pathExecutionSid; - public ExecutionContextFetcher(final String pathFlowSid, final String pathExecutionSid){ + public ExecutionContextFetcher( + final String pathFlowSid, + final String pathExecutionSid + ) { this.pathFlowSid = pathFlowSid; this.pathExecutionSid = pathExecutionSid; } - @Override public ExecutionContext fetch(final TwilioRestClient client) { String path = "/v1/Flows/{FlowSid}/Executions/{ExecutionSid}/Context"; - path = path.replace("{"+"FlowSid"+"}", this.pathFlowSid.toString()); - path = path.replace("{"+"ExecutionSid"+"}", this.pathExecutionSid.toString()); + path = path.replace("{" + "FlowSid" + "}", this.pathFlowSid.toString()); + path = + path.replace( + "{" + "ExecutionSid" + "}", + this.pathExecutionSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -52,15 +56,23 @@ public ExecutionContext fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("ExecutionContext fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "ExecutionContext fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return ExecutionContext.fromJson(response.getStream(), client.getObjectMapper()); + return ExecutionContext.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/studio/v1/flow/execution/ExecutionStep.java b/src/main/java/com/twilio/rest/studio/v1/flow/execution/ExecutionStep.java index 8746388b89..9b69e0f303 100644 --- a/src/main/java/com/twilio/rest/studio/v1/flow/execution/ExecutionStep.java +++ b/src/main/java/com/twilio/rest/studio/v1/flow/execution/ExecutionStep.java @@ -23,43 +23,49 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class ExecutionStep extends Resource { + private static final long serialVersionUID = 271983635262130L; - public static ExecutionStepFetcher fetcher(final String pathFlowSid, final String pathExecutionSid, final String pathSid){ + public static ExecutionStepFetcher fetcher( + final String pathFlowSid, + final String pathExecutionSid, + final String pathSid + ) { return new ExecutionStepFetcher(pathFlowSid, pathExecutionSid, pathSid); } - public static ExecutionStepReader reader(final String pathFlowSid, final String pathExecutionSid){ + public static ExecutionStepReader reader( + final String pathFlowSid, + final String pathExecutionSid + ) { return new ExecutionStepReader(pathFlowSid, pathExecutionSid); } /** - * Converts a JSON String into a ExecutionStep object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return ExecutionStep object represented by the provided JSON - */ - public static ExecutionStep fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a ExecutionStep object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return ExecutionStep object represented by the provided JSON + */ + public static ExecutionStep fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, ExecutionStep.class); @@ -71,14 +77,17 @@ public static ExecutionStep fromJson(final String json, final ObjectMapper objec } /** - * Converts a JSON InputStream into a ExecutionStep object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return ExecutionStep object represented by the provided JSON - */ - public static ExecutionStep fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a ExecutionStep object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return ExecutionStep object represented by the provided JSON + */ + public static ExecutionStep fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, ExecutionStep.class); @@ -104,41 +113,18 @@ public static ExecutionStep fromJson(final InputStream json, final ObjectMapper @JsonCreator private ExecutionStep( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("flow_sid") - final String flowSid, - - @JsonProperty("execution_sid") - final String executionSid, - - @JsonProperty("name") - final String name, - - @JsonProperty("context") - final Map context, - - @JsonProperty("transitioned_from") - final String transitionedFrom, - - @JsonProperty("transitioned_to") - final String transitionedTo, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("flow_sid") final String flowSid, + @JsonProperty("execution_sid") final String executionSid, + @JsonProperty("name") final String name, + @JsonProperty("context") final Map context, + @JsonProperty("transitioned_from") final String transitionedFrom, + @JsonProperty("transitioned_to") final String transitionedTo, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.sid = sid; this.accountSid = accountSid; @@ -154,46 +140,57 @@ private ExecutionStep( this.links = links; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getFlowSid() { - return this.flowSid; - } - public final String getExecutionSid() { - return this.executionSid; - } - public final String getName() { - return this.name; - } - public final Map getContext() { - return this.context; - } - public final String getTransitionedFrom() { - return this.transitionedFrom; - } - public final String getTransitionedTo() { - return this.transitionedTo; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getFlowSid() { + return this.flowSid; + } + + public final String getExecutionSid() { + return this.executionSid; + } + + public final String getName() { + return this.name; + } + + public final Map getContext() { + return this.context; + } + + public final String getTransitionedFrom() { + return this.transitionedFrom; + } + + public final String getTransitionedTo() { + return this.transitionedTo; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -203,13 +200,37 @@ public boolean equals(final Object o) { ExecutionStep other = (ExecutionStep) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(flowSid, other.flowSid) && Objects.equals(executionSid, other.executionSid) && Objects.equals(name, other.name) && Objects.equals(context, other.context) && Objects.equals(transitionedFrom, other.transitionedFrom) && Objects.equals(transitionedTo, other.transitionedTo) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(flowSid, other.flowSid) && + Objects.equals(executionSid, other.executionSid) && + Objects.equals(name, other.name) && + Objects.equals(context, other.context) && + Objects.equals(transitionedFrom, other.transitionedFrom) && + Objects.equals(transitionedTo, other.transitionedTo) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, flowSid, executionSid, name, context, transitionedFrom, transitionedTo, dateCreated, dateUpdated, url, links); + return Objects.hash( + sid, + accountSid, + flowSid, + executionSid, + name, + context, + transitionedFrom, + transitionedTo, + dateCreated, + dateUpdated, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/studio/v1/flow/execution/ExecutionStepFetcher.java b/src/main/java/com/twilio/rest/studio/v1/flow/execution/ExecutionStepFetcher.java index 087adf763d..6fa4ef54cc 100644 --- a/src/main/java/com/twilio/rest/studio/v1/flow/execution/ExecutionStepFetcher.java +++ b/src/main/java/com/twilio/rest/studio/v1/flow/execution/ExecutionStepFetcher.java @@ -24,28 +24,34 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class ExecutionStepFetcher extends Fetcher { + private String pathFlowSid; private String pathExecutionSid; private String pathSid; - public ExecutionStepFetcher(final String pathFlowSid, final String pathExecutionSid, final String pathSid){ + public ExecutionStepFetcher( + final String pathFlowSid, + final String pathExecutionSid, + final String pathSid + ) { this.pathFlowSid = pathFlowSid; this.pathExecutionSid = pathExecutionSid; this.pathSid = pathSid; } - @Override public ExecutionStep fetch(final TwilioRestClient client) { - String path = "/v1/Flows/{FlowSid}/Executions/{ExecutionSid}/Steps/{Sid}"; + String path = + "/v1/Flows/{FlowSid}/Executions/{ExecutionSid}/Steps/{Sid}"; - path = path.replace("{"+"FlowSid"+"}", this.pathFlowSid.toString()); - path = path.replace("{"+"ExecutionSid"+"}", this.pathExecutionSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "FlowSid" + "}", this.pathFlowSid.toString()); + path = + path.replace( + "{" + "ExecutionSid" + "}", + this.pathExecutionSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -55,15 +61,23 @@ public ExecutionStep fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("ExecutionStep fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "ExecutionStep fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return ExecutionStep.fromJson(response.getStream(), client.getObjectMapper()); + return ExecutionStep.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/studio/v1/flow/execution/ExecutionStepReader.java b/src/main/java/com/twilio/rest/studio/v1/flow/execution/ExecutionStepReader.java index f9bb0c75a9..bbc558abac 100644 --- a/src/main/java/com/twilio/rest/studio/v1/flow/execution/ExecutionStepReader.java +++ b/src/main/java/com/twilio/rest/studio/v1/flow/execution/ExecutionStepReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.studio.v1.flow.execution; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,21 +25,22 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class ExecutionStepReader extends Reader { + private String pathFlowSid; private String pathExecutionSid; private Integer pageSize; - public ExecutionStepReader(final String pathFlowSid, final String pathExecutionSid){ + public ExecutionStepReader( + final String pathFlowSid, + final String pathExecutionSid + ) { this.pathFlowSid = pathFlowSid; this.pathExecutionSid = pathExecutionSid; } - public ExecutionStepReader setPageSize(final Integer pageSize){ + public ExecutionStepReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -50,8 +52,12 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Flows/{FlowSid}/Executions/{ExecutionSid}/Steps"; - path = path.replace("{"+"FlowSid"+"}", this.pathFlowSid.toString()); - path = path.replace("{"+"ExecutionSid"+"}", this.pathExecutionSid.toString()); + path = path.replace("{" + "FlowSid" + "}", this.pathFlowSid.toString()); + path = + path.replace( + "{" + "ExecutionSid" + "}", + this.pathExecutionSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -63,13 +69,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("ExecutionStep read failed: Unable to connect to server"); + throw new ApiConnectionException( + "ExecutionStep read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -85,7 +99,10 @@ private Page pageForRequest(final TwilioRestClient client, final } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.STUDIO.toString()) @@ -93,9 +110,11 @@ public Page previousPage(final Page page, final Tw return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.STUDIO.toString()) @@ -104,21 +123,21 @@ public Page nextPage(final Page page, final Twilio } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/studio/v1/flow/execution/executionstep/ExecutionStepContext.java b/src/main/java/com/twilio/rest/studio/v1/flow/execution/executionstep/ExecutionStepContext.java index e94246b67b..487d379a2f 100644 --- a/src/main/java/com/twilio/rest/studio/v1/flow/execution/executionstep/ExecutionStepContext.java +++ b/src/main/java/com/twilio/rest/studio/v1/flow/execution/executionstep/ExecutionStepContext.java @@ -22,38 +22,45 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class ExecutionStepContext extends Resource { + private static final long serialVersionUID = 28705359719021L; - public static ExecutionStepContextFetcher fetcher(final String pathFlowSid, final String pathExecutionSid, final String pathStepSid){ - return new ExecutionStepContextFetcher(pathFlowSid, pathExecutionSid, pathStepSid); + public static ExecutionStepContextFetcher fetcher( + final String pathFlowSid, + final String pathExecutionSid, + final String pathStepSid + ) { + return new ExecutionStepContextFetcher( + pathFlowSid, + pathExecutionSid, + pathStepSid + ); } /** - * Converts a JSON String into a ExecutionStepContext object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return ExecutionStepContext object represented by the provided JSON - */ - public static ExecutionStepContext fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a ExecutionStepContext object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return ExecutionStepContext object represented by the provided JSON + */ + public static ExecutionStepContext fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, ExecutionStepContext.class); @@ -65,14 +72,17 @@ public static ExecutionStepContext fromJson(final String json, final ObjectMappe } /** - * Converts a JSON InputStream into a ExecutionStepContext object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return ExecutionStepContext object represented by the provided JSON - */ - public static ExecutionStepContext fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a ExecutionStepContext object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return ExecutionStepContext object represented by the provided JSON + */ + public static ExecutionStepContext fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, ExecutionStepContext.class); @@ -92,23 +102,12 @@ public static ExecutionStepContext fromJson(final InputStream json, final Object @JsonCreator private ExecutionStepContext( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("context") - final Map context, - - @JsonProperty("execution_sid") - final String executionSid, - - @JsonProperty("flow_sid") - final String flowSid, - - @JsonProperty("step_sid") - final String stepSid, - - @JsonProperty("url") - final URI url + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("context") final Map context, + @JsonProperty("execution_sid") final String executionSid, + @JsonProperty("flow_sid") final String flowSid, + @JsonProperty("step_sid") final String stepSid, + @JsonProperty("url") final URI url ) { this.accountSid = accountSid; this.context = context; @@ -118,28 +117,33 @@ private ExecutionStepContext( this.url = url; } - public final String getAccountSid() { - return this.accountSid; - } - public final Map getContext() { - return this.context; - } - public final String getExecutionSid() { - return this.executionSid; - } - public final String getFlowSid() { - return this.flowSid; - } - public final String getStepSid() { - return this.stepSid; - } - public final URI getUrl() { - return this.url; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final Map getContext() { + return this.context; + } + + public final String getExecutionSid() { + return this.executionSid; + } + + public final String getFlowSid() { + return this.flowSid; + } + + public final String getStepSid() { + return this.stepSid; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -149,13 +153,25 @@ public boolean equals(final Object o) { ExecutionStepContext other = (ExecutionStepContext) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(context, other.context) && Objects.equals(executionSid, other.executionSid) && Objects.equals(flowSid, other.flowSid) && Objects.equals(stepSid, other.stepSid) && Objects.equals(url, other.url) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(context, other.context) && + Objects.equals(executionSid, other.executionSid) && + Objects.equals(flowSid, other.flowSid) && + Objects.equals(stepSid, other.stepSid) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, context, executionSid, flowSid, stepSid, url); + return Objects.hash( + accountSid, + context, + executionSid, + flowSid, + stepSid, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/studio/v1/flow/execution/executionstep/ExecutionStepContextFetcher.java b/src/main/java/com/twilio/rest/studio/v1/flow/execution/executionstep/ExecutionStepContextFetcher.java index 48492bc9ea..dc78668895 100644 --- a/src/main/java/com/twilio/rest/studio/v1/flow/execution/executionstep/ExecutionStepContextFetcher.java +++ b/src/main/java/com/twilio/rest/studio/v1/flow/execution/executionstep/ExecutionStepContextFetcher.java @@ -24,28 +24,34 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class ExecutionStepContextFetcher extends Fetcher { + private String pathFlowSid; private String pathExecutionSid; private String pathStepSid; - public ExecutionStepContextFetcher(final String pathFlowSid, final String pathExecutionSid, final String pathStepSid){ + public ExecutionStepContextFetcher( + final String pathFlowSid, + final String pathExecutionSid, + final String pathStepSid + ) { this.pathFlowSid = pathFlowSid; this.pathExecutionSid = pathExecutionSid; this.pathStepSid = pathStepSid; } - @Override public ExecutionStepContext fetch(final TwilioRestClient client) { - String path = "/v1/Flows/{FlowSid}/Executions/{ExecutionSid}/Steps/{StepSid}/Context"; + String path = + "/v1/Flows/{FlowSid}/Executions/{ExecutionSid}/Steps/{StepSid}/Context"; - path = path.replace("{"+"FlowSid"+"}", this.pathFlowSid.toString()); - path = path.replace("{"+"ExecutionSid"+"}", this.pathExecutionSid.toString()); - path = path.replace("{"+"StepSid"+"}", this.pathStepSid.toString()); + path = path.replace("{" + "FlowSid" + "}", this.pathFlowSid.toString()); + path = + path.replace( + "{" + "ExecutionSid" + "}", + this.pathExecutionSid.toString() + ); + path = path.replace("{" + "StepSid" + "}", this.pathStepSid.toString()); Request request = new Request( HttpMethod.GET, @@ -55,15 +61,23 @@ public ExecutionStepContext fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("ExecutionStepContext fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "ExecutionStepContext fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return ExecutionStepContext.fromJson(response.getStream(), client.getObjectMapper()); + return ExecutionStepContext.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/studio/v2/Flow.java b/src/main/java/com/twilio/rest/studio/v2/Flow.java index b2c9e0b0f8..1ce7576a64 100644 --- a/src/main/java/com/twilio/rest/studio/v2/Flow.java +++ b/src/main/java/com/twilio/rest/studio/v2/Flow.java @@ -24,56 +24,62 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.List; import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Flow extends Resource { + private static final long serialVersionUID = 951890745581L; - public static FlowCreator creator(final String friendlyName, final Flow.Status status, final Map definition){ + public static FlowCreator creator( + final String friendlyName, + final Flow.Status status, + final Map definition + ) { return new FlowCreator(friendlyName, status, definition); } - public static FlowDeleter deleter(final String pathSid){ + public static FlowDeleter deleter(final String pathSid) { return new FlowDeleter(pathSid); } - public static FlowFetcher fetcher(final String pathSid){ + public static FlowFetcher fetcher(final String pathSid) { return new FlowFetcher(pathSid); } - public static FlowReader reader(){ + public static FlowReader reader() { return new FlowReader(); } - public static FlowUpdater updater(final String pathSid, final Flow.Status status){ + public static FlowUpdater updater( + final String pathSid, + final Flow.Status status + ) { return new FlowUpdater(pathSid, status); } /** - * Converts a JSON String into a Flow object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Flow object represented by the provided JSON - */ - public static Flow fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Flow object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Flow object represented by the provided JSON + */ + public static Flow fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Flow.class); @@ -85,14 +91,17 @@ public static Flow fromJson(final String json, final ObjectMapper objectMapper) } /** - * Converts a JSON InputStream into a Flow object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Flow object represented by the provided JSON - */ - public static Flow fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Flow object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Flow object represented by the provided JSON + */ + public static Flow fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Flow.class); @@ -102,6 +111,7 @@ public static Flow fromJson(final InputStream json, final ObjectMapper objectMap throw new ApiConnectionException(e.getMessage(), e); } } + public enum Status { DRAFT("draft"), PUBLISHED("published"); @@ -140,50 +150,21 @@ public static Status forValue(final String value) { @JsonCreator private Flow( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("definition") - final Map definition, - - @JsonProperty("status") - final Flow.Status status, - - @JsonProperty("revision") - final Integer revision, - - @JsonProperty("commit_message") - final String commitMessage, - - @JsonProperty("valid") - final Boolean valid, - - @JsonProperty("errors") - final List> errors, - - @JsonProperty("warnings") - final List> warnings, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("webhook_url") - final URI webhookUrl, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("definition") final Map definition, + @JsonProperty("status") final Flow.Status status, + @JsonProperty("revision") final Integer revision, + @JsonProperty("commit_message") final String commitMessage, + @JsonProperty("valid") final Boolean valid, + @JsonProperty("errors") final List> errors, + @JsonProperty("warnings") final List> warnings, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("webhook_url") final URI webhookUrl, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.sid = sid; this.accountSid = accountSid; @@ -202,55 +183,69 @@ private Flow( this.links = links; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final Map getDefinition() { - return this.definition; - } - public final Flow.Status getStatus() { - return this.status; - } - public final Integer getRevision() { - return this.revision; - } - public final String getCommitMessage() { - return this.commitMessage; - } - public final Boolean getValid() { - return this.valid; - } - public final List> getErrors() { - return this.errors; - } - public final List> getWarnings() { - return this.warnings; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getWebhookUrl() { - return this.webhookUrl; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final Map getDefinition() { + return this.definition; + } + + public final Flow.Status getStatus() { + return this.status; + } + + public final Integer getRevision() { + return this.revision; + } + + public final String getCommitMessage() { + return this.commitMessage; + } + + public final Boolean getValid() { + return this.valid; + } + + public final List> getErrors() { + return this.errors; + } + + public final List> getWarnings() { + return this.warnings; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getWebhookUrl() { + return this.webhookUrl; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -260,13 +255,43 @@ public boolean equals(final Object o) { Flow other = (Flow) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(definition, other.definition) && Objects.equals(status, other.status) && Objects.equals(revision, other.revision) && Objects.equals(commitMessage, other.commitMessage) && Objects.equals(valid, other.valid) && Objects.equals(errors, other.errors) && Objects.equals(warnings, other.warnings) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(webhookUrl, other.webhookUrl) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(definition, other.definition) && + Objects.equals(status, other.status) && + Objects.equals(revision, other.revision) && + Objects.equals(commitMessage, other.commitMessage) && + Objects.equals(valid, other.valid) && + Objects.equals(errors, other.errors) && + Objects.equals(warnings, other.warnings) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(webhookUrl, other.webhookUrl) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, friendlyName, definition, status, revision, commitMessage, valid, errors, warnings, dateCreated, dateUpdated, webhookUrl, url, links); + return Objects.hash( + sid, + accountSid, + friendlyName, + definition, + status, + revision, + commitMessage, + valid, + errors, + warnings, + dateCreated, + dateUpdated, + webhookUrl, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/studio/v2/FlowCreator.java b/src/main/java/com/twilio/rest/studio/v2/FlowCreator.java index 23a54cc4c5..be169bd54f 100644 --- a/src/main/java/com/twilio/rest/studio/v2/FlowCreator.java +++ b/src/main/java/com/twilio/rest/studio/v2/FlowCreator.java @@ -15,8 +15,10 @@ package com.twilio.rest.studio.v2; import com.twilio.base.Creator; -import com.twilio.exception.ApiConnectionException; +import com.twilio.constant.EnumConstants; +import com.twilio.converter.Converter; import com.twilio.converter.Converter; +import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; @@ -25,60 +27,75 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.util.Map; -import com.twilio.converter.Converter; - import java.util.Map; +public class FlowCreator extends Creator { - -public class FlowCreator extends Creator{ private String friendlyName; private Flow.Status status; private Map definition; private String commitMessage; - public FlowCreator(final String friendlyName, final Flow.Status status, final Map definition) { + public FlowCreator( + final String friendlyName, + final Flow.Status status, + final Map definition + ) { this.friendlyName = friendlyName; this.status = status; this.definition = definition; } - public FlowCreator setFriendlyName(final String friendlyName){ + public FlowCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public FlowCreator setStatus(final Flow.Status status){ + + public FlowCreator setStatus(final Flow.Status status) { this.status = status; return this; } - public FlowCreator setDefinition(final Map definition){ + + public FlowCreator setDefinition(final Map definition) { this.definition = definition; return this; } - public FlowCreator setCommitMessage(final String commitMessage){ + + public FlowCreator setCommitMessage(final String commitMessage) { this.commitMessage = commitMessage; return this; } @Override - public Flow create(final TwilioRestClient client){ + public Flow create(final TwilioRestClient client) { String path = "/v2/Flows"; - path = path.replace("{"+"FriendlyName"+"}", this.friendlyName.toString()); - path = path.replace("{"+"Status"+"}", this.status.toString()); - path = path.replace("{"+"Definition"+"}", this.definition.toString()); + path = + path.replace( + "{" + "FriendlyName" + "}", + this.friendlyName.toString() + ); + path = path.replace("{" + "Status" + "}", this.status.toString()); + path = + path.replace("{" + "Definition" + "}", this.definition.toString()); Request request = new Request( HttpMethod.POST, Domains.STUDIO.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Flow creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Flow creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -87,22 +104,19 @@ public Flow create(final TwilioRestClient client){ return Flow.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (status != null) { request.addPostParam("Status", status.toString()); - } if (definition != null) { - request.addPostParam("Definition", Converter.mapToJson(definition)); - + request.addPostParam("Definition", Converter.mapToJson(definition)); } if (commitMessage != null) { request.addPostParam("CommitMessage", commitMessage); - } } } diff --git a/src/main/java/com/twilio/rest/studio/v2/FlowDeleter.java b/src/main/java/com/twilio/rest/studio/v2/FlowDeleter.java index a9681c546f..14d22ac536 100644 --- a/src/main/java/com/twilio/rest/studio/v2/FlowDeleter.java +++ b/src/main/java/com/twilio/rest/studio/v2/FlowDeleter.java @@ -24,21 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class FlowDeleter extends Deleter { + private String pathSid; - public FlowDeleter(final String pathSid){ + public FlowDeleter(final String pathSid) { this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v2/Flows/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -48,9 +46,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Flow delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Flow delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/studio/v2/FlowFetcher.java b/src/main/java/com/twilio/rest/studio/v2/FlowFetcher.java index aeb8e60e5d..d5f829a0f7 100644 --- a/src/main/java/com/twilio/rest/studio/v2/FlowFetcher.java +++ b/src/main/java/com/twilio/rest/studio/v2/FlowFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class FlowFetcher extends Fetcher { + private String pathSid; - public FlowFetcher(final String pathSid){ + public FlowFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public Flow fetch(final TwilioRestClient client) { String path = "/v2/Flows/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,9 +46,14 @@ public Flow fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Flow fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Flow fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/studio/v2/FlowReader.java b/src/main/java/com/twilio/rest/studio/v2/FlowReader.java index bea6de1e89..ee0dda7d60 100644 --- a/src/main/java/com/twilio/rest/studio/v2/FlowReader.java +++ b/src/main/java/com/twilio/rest/studio/v2/FlowReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.studio.v2; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,17 +25,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class FlowReader extends Reader { + private Integer pageSize; - public FlowReader(){ - } + public FlowReader() {} - public FlowReader setPageSize(final Integer pageSize){ + public FlowReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -57,13 +55,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Flow read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Flow read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -79,7 +85,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request r } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.STUDIO.toString()) @@ -87,9 +96,11 @@ public Page previousPage(final Page page, final TwilioRestClient cli return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.STUDIO.toString()) @@ -98,21 +109,21 @@ public Page nextPage(final Page page, final TwilioRestClient client) } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/studio/v2/FlowUpdater.java b/src/main/java/com/twilio/rest/studio/v2/FlowUpdater.java index 5a7ef0549f..4b550516d6 100644 --- a/src/main/java/com/twilio/rest/studio/v2/FlowUpdater.java +++ b/src/main/java/com/twilio/rest/studio/v2/FlowUpdater.java @@ -15,8 +15,9 @@ package com.twilio.rest.studio.v2; import com.twilio.base.Updater; -import com.twilio.exception.ApiConnectionException; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Converter; +import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; @@ -24,58 +25,65 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - import java.util.Map; +public class FlowUpdater extends Updater { -public class FlowUpdater extends Updater{ private String pathSid; private Flow.Status status; private String friendlyName; private Map definition; private String commitMessage; - public FlowUpdater(final String pathSid, final Flow.Status status){ + public FlowUpdater(final String pathSid, final Flow.Status status) { this.pathSid = pathSid; this.status = status; } - public FlowUpdater setStatus(final Flow.Status status){ + public FlowUpdater setStatus(final Flow.Status status) { this.status = status; return this; } - public FlowUpdater setFriendlyName(final String friendlyName){ + + public FlowUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public FlowUpdater setDefinition(final Map definition){ + + public FlowUpdater setDefinition(final Map definition) { this.definition = definition; return this; } - public FlowUpdater setCommitMessage(final String commitMessage){ + + public FlowUpdater setCommitMessage(final String commitMessage) { this.commitMessage = commitMessage; return this; } @Override - public Flow update(final TwilioRestClient client){ + public Flow update(final TwilioRestClient client) { String path = "/v2/Flows/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); - path = path.replace("{"+"Status"+"}", this.status.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + path = path.replace("{" + "Status" + "}", this.status.toString()); Request request = new Request( HttpMethod.POST, Domains.STUDIO.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Flow update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Flow update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -84,22 +92,19 @@ public Flow update(final TwilioRestClient client){ return Flow.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (status != null) { request.addPostParam("Status", status.toString()); - } if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (definition != null) { - request.addPostParam("Definition", Converter.mapToJson(definition)); - + request.addPostParam("Definition", Converter.mapToJson(definition)); } if (commitMessage != null) { request.addPostParam("CommitMessage", commitMessage); - } } } diff --git a/src/main/java/com/twilio/rest/studio/v2/FlowValidate.java b/src/main/java/com/twilio/rest/studio/v2/FlowValidate.java index c3d6132f7d..3b1ceb0541 100644 --- a/src/main/java/com/twilio/rest/studio/v2/FlowValidate.java +++ b/src/main/java/com/twilio/rest/studio/v2/FlowValidate.java @@ -23,37 +23,40 @@ import com.twilio.base.Resource; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class FlowValidate extends Resource { + private static final long serialVersionUID = 128242236604078L; - public static FlowValidateUpdater updater(final String friendlyName, final FlowValidate.Status status, final Map definition){ + public static FlowValidateUpdater updater( + final String friendlyName, + final FlowValidate.Status status, + final Map definition + ) { return new FlowValidateUpdater(friendlyName, status, definition); } /** - * Converts a JSON String into a FlowValidate object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return FlowValidate object represented by the provided JSON - */ - public static FlowValidate fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a FlowValidate object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return FlowValidate object represented by the provided JSON + */ + public static FlowValidate fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, FlowValidate.class); @@ -65,14 +68,17 @@ public static FlowValidate fromJson(final String json, final ObjectMapper object } /** - * Converts a JSON InputStream into a FlowValidate object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return FlowValidate object represented by the provided JSON - */ - public static FlowValidate fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a FlowValidate object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return FlowValidate object represented by the provided JSON + */ + public static FlowValidate fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, FlowValidate.class); @@ -82,6 +88,7 @@ public static FlowValidate fromJson(final InputStream json, final ObjectMapper o throw new ApiConnectionException(e.getMessage(), e); } } + public enum Status { DRAFT("draft"), PUBLISHED("published"); @@ -105,20 +112,17 @@ public static Status forValue(final String value) { private final Boolean valid; @JsonCreator - private FlowValidate( - @JsonProperty("valid") - final Boolean valid - ) { + private FlowValidate(@JsonProperty("valid") final Boolean valid) { this.valid = valid; } - public final Boolean getValid() { - return this.valid; - } + public final Boolean getValid() { + return this.valid; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -128,13 +132,11 @@ public boolean equals(final Object o) { FlowValidate other = (FlowValidate) o; - return Objects.equals(valid, other.valid) ; + return Objects.equals(valid, other.valid); } @Override public int hashCode() { return Objects.hash(valid); } - } - diff --git a/src/main/java/com/twilio/rest/studio/v2/FlowValidateUpdater.java b/src/main/java/com/twilio/rest/studio/v2/FlowValidateUpdater.java index b2e6f159e9..e1ee4059d9 100644 --- a/src/main/java/com/twilio/rest/studio/v2/FlowValidateUpdater.java +++ b/src/main/java/com/twilio/rest/studio/v2/FlowValidateUpdater.java @@ -15,8 +15,9 @@ package com.twilio.rest.studio.v2; import com.twilio.base.Updater; -import com.twilio.exception.ApiConnectionException; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Converter; +import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; @@ -24,83 +25,101 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - import java.util.Map; +public class FlowValidateUpdater extends Updater { -public class FlowValidateUpdater extends Updater{ private String friendlyName; private FlowValidate.Status status; private Map definition; private String commitMessage; - public FlowValidateUpdater(final String friendlyName, final FlowValidate.Status status, final Map definition){ + public FlowValidateUpdater( + final String friendlyName, + final FlowValidate.Status status, + final Map definition + ) { this.friendlyName = friendlyName; this.status = status; this.definition = definition; } - public FlowValidateUpdater setFriendlyName(final String friendlyName){ + public FlowValidateUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public FlowValidateUpdater setStatus(final FlowValidate.Status status){ + + public FlowValidateUpdater setStatus(final FlowValidate.Status status) { this.status = status; return this; } - public FlowValidateUpdater setDefinition(final Map definition){ + + public FlowValidateUpdater setDefinition( + final Map definition + ) { this.definition = definition; return this; } - public FlowValidateUpdater setCommitMessage(final String commitMessage){ + + public FlowValidateUpdater setCommitMessage(final String commitMessage) { this.commitMessage = commitMessage; return this; } @Override - public FlowValidate update(final TwilioRestClient client){ + public FlowValidate update(final TwilioRestClient client) { String path = "/v2/Flows/Validate"; - path = path.replace("{"+"FriendlyName"+"}", this.friendlyName.toString()); - path = path.replace("{"+"Status"+"}", this.status.toString()); - path = path.replace("{"+"Definition"+"}", this.definition.toString()); + path = + path.replace( + "{" + "FriendlyName" + "}", + this.friendlyName.toString() + ); + path = path.replace("{" + "Status" + "}", this.status.toString()); + path = + path.replace("{" + "Definition" + "}", this.definition.toString()); Request request = new Request( HttpMethod.POST, Domains.STUDIO.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("FlowValidate update failed: Unable to connect to server"); + throw new ApiConnectionException( + "FlowValidate update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return FlowValidate.fromJson(response.getStream(), client.getObjectMapper()); + return FlowValidate.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (status != null) { request.addPostParam("Status", status.toString()); - } if (definition != null) { - request.addPostParam("Definition", Converter.mapToJson(definition)); - + request.addPostParam("Definition", Converter.mapToJson(definition)); } if (commitMessage != null) { request.addPostParam("CommitMessage", commitMessage); - } } } diff --git a/src/main/java/com/twilio/rest/studio/v2/flow/Execution.java b/src/main/java/com/twilio/rest/studio/v2/flow/Execution.java index 55b5bd2cb6..8f644499f1 100644 --- a/src/main/java/com/twilio/rest/studio/v2/flow/Execution.java +++ b/src/main/java/com/twilio/rest/studio/v2/flow/Execution.java @@ -24,55 +24,68 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Execution extends Resource { + private static final long serialVersionUID = 276284150060496L; - public static ExecutionCreator creator(final String pathFlowSid, final com.twilio.type.PhoneNumber to, final com.twilio.type.PhoneNumber from){ + public static ExecutionCreator creator( + final String pathFlowSid, + final com.twilio.type.PhoneNumber to, + final com.twilio.type.PhoneNumber from + ) { return new ExecutionCreator(pathFlowSid, to, from); } - public static ExecutionDeleter deleter(final String pathFlowSid, final String pathSid){ + public static ExecutionDeleter deleter( + final String pathFlowSid, + final String pathSid + ) { return new ExecutionDeleter(pathFlowSid, pathSid); } - public static ExecutionFetcher fetcher(final String pathFlowSid, final String pathSid){ + public static ExecutionFetcher fetcher( + final String pathFlowSid, + final String pathSid + ) { return new ExecutionFetcher(pathFlowSid, pathSid); } - public static ExecutionReader reader(final String pathFlowSid){ + public static ExecutionReader reader(final String pathFlowSid) { return new ExecutionReader(pathFlowSid); } - public static ExecutionUpdater updater(final String pathFlowSid, final String pathSid, final Execution.Status status){ + public static ExecutionUpdater updater( + final String pathFlowSid, + final String pathSid, + final Execution.Status status + ) { return new ExecutionUpdater(pathFlowSid, pathSid, status); } /** - * Converts a JSON String into a Execution object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Execution object represented by the provided JSON - */ - public static Execution fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Execution object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Execution object represented by the provided JSON + */ + public static Execution fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Execution.class); @@ -84,14 +97,17 @@ public static Execution fromJson(final String json, final ObjectMapper objectMap } /** - * Converts a JSON InputStream into a Execution object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Execution object represented by the provided JSON - */ - public static Execution fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Execution object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Execution object represented by the provided JSON + */ + public static Execution fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Execution.class); @@ -101,6 +117,7 @@ public static Execution fromJson(final InputStream json, final ObjectMapper obje throw new ApiConnectionException(e.getMessage(), e); } } + public enum Status { ACTIVE("active"), ENDED("ended"); @@ -134,35 +151,18 @@ public static Status forValue(final String value) { @JsonCreator private Execution( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("flow_sid") - final String flowSid, - - @JsonProperty("contact_channel_address") - final String contactChannelAddress, - - @JsonProperty("context") - final Map context, - - @JsonProperty("status") - final Execution.Status status, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("flow_sid") final String flowSid, + @JsonProperty( + "contact_channel_address" + ) final String contactChannelAddress, + @JsonProperty("context") final Map context, + @JsonProperty("status") final Execution.Status status, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.sid = sid; this.accountSid = accountSid; @@ -176,40 +176,49 @@ private Execution( this.links = links; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getFlowSid() { - return this.flowSid; - } - public final String getContactChannelAddress() { - return this.contactChannelAddress; - } - public final Map getContext() { - return this.context; - } - public final Execution.Status getStatus() { - return this.status; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getFlowSid() { + return this.flowSid; + } + + public final String getContactChannelAddress() { + return this.contactChannelAddress; + } + + public final Map getContext() { + return this.context; + } + + public final Execution.Status getStatus() { + return this.status; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -219,13 +228,36 @@ public boolean equals(final Object o) { Execution other = (Execution) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(flowSid, other.flowSid) && Objects.equals(contactChannelAddress, other.contactChannelAddress) && Objects.equals(context, other.context) && Objects.equals(status, other.status) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(flowSid, other.flowSid) && + Objects.equals( + contactChannelAddress, + other.contactChannelAddress + ) && + Objects.equals(context, other.context) && + Objects.equals(status, other.status) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, flowSid, contactChannelAddress, context, status, dateCreated, dateUpdated, url, links); + return Objects.hash( + sid, + accountSid, + flowSid, + contactChannelAddress, + context, + status, + dateCreated, + dateUpdated, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/studio/v2/flow/ExecutionCreator.java b/src/main/java/com/twilio/rest/studio/v2/flow/ExecutionCreator.java index 294465746e..0239e96ef2 100644 --- a/src/main/java/com/twilio/rest/studio/v2/flow/ExecutionCreator.java +++ b/src/main/java/com/twilio/rest/studio/v2/flow/ExecutionCreator.java @@ -15,9 +15,11 @@ package com.twilio.rest.studio.v2.flow; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; +import com.twilio.converter.Converter; +import com.twilio.converter.Converter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; -import com.twilio.converter.Converter; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; @@ -26,84 +28,96 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.util.Map; -import com.twilio.converter.Converter; - import java.util.Map; +public class ExecutionCreator extends Creator { - -public class ExecutionCreator extends Creator{ private String pathFlowSid; private com.twilio.type.PhoneNumber to; private com.twilio.type.PhoneNumber from; private Map parameters; - public ExecutionCreator(final String pathFlowSid, final com.twilio.type.PhoneNumber to, final com.twilio.type.PhoneNumber from) { + public ExecutionCreator( + final String pathFlowSid, + final com.twilio.type.PhoneNumber to, + final com.twilio.type.PhoneNumber from + ) { this.pathFlowSid = pathFlowSid; this.to = to; this.from = from; } - public ExecutionCreator setTo(final com.twilio.type.PhoneNumber to){ + public ExecutionCreator setTo(final com.twilio.type.PhoneNumber to) { this.to = to; return this; } - public ExecutionCreator setTo(final String to){ + public ExecutionCreator setTo(final String to) { return setTo(Promoter.phoneNumberFromString(to)); } - public ExecutionCreator setFrom(final com.twilio.type.PhoneNumber from){ + + public ExecutionCreator setFrom(final com.twilio.type.PhoneNumber from) { this.from = from; return this; } - public ExecutionCreator setFrom(final String from){ + public ExecutionCreator setFrom(final String from) { return setFrom(Promoter.phoneNumberFromString(from)); } - public ExecutionCreator setParameters(final Map parameters){ + + public ExecutionCreator setParameters( + final Map parameters + ) { this.parameters = parameters; return this; } @Override - public Execution create(final TwilioRestClient client){ + public Execution create(final TwilioRestClient client) { String path = "/v2/Flows/{FlowSid}/Executions"; - path = path.replace("{"+"FlowSid"+"}", this.pathFlowSid.toString()); - path = path.replace("{"+"To"+"}", this.to.encode("utf-8")); - path = path.replace("{"+"From"+"}", this.from.encode("utf-8")); + path = path.replace("{" + "FlowSid" + "}", this.pathFlowSid.toString()); + path = path.replace("{" + "To" + "}", this.to.encode("utf-8")); + path = path.replace("{" + "From" + "}", this.from.encode("utf-8")); Request request = new Request( HttpMethod.POST, Domains.STUDIO.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Execution creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Execution creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Execution.fromJson(response.getStream(), client.getObjectMapper()); + return Execution.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (to != null) { request.addPostParam("To", to.toString()); - } if (from != null) { request.addPostParam("From", from.toString()); - } if (parameters != null) { - request.addPostParam("Parameters", Converter.mapToJson(parameters)); - + request.addPostParam("Parameters", Converter.mapToJson(parameters)); } } } diff --git a/src/main/java/com/twilio/rest/studio/v2/flow/ExecutionDeleter.java b/src/main/java/com/twilio/rest/studio/v2/flow/ExecutionDeleter.java index 43025d8f77..9e67fcb95a 100644 --- a/src/main/java/com/twilio/rest/studio/v2/flow/ExecutionDeleter.java +++ b/src/main/java/com/twilio/rest/studio/v2/flow/ExecutionDeleter.java @@ -24,24 +24,22 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class ExecutionDeleter extends Deleter { + private String pathFlowSid; private String pathSid; - public ExecutionDeleter(final String pathFlowSid, final String pathSid){ + public ExecutionDeleter(final String pathFlowSid, final String pathSid) { this.pathFlowSid = pathFlowSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v2/Flows/{FlowSid}/Executions/{Sid}"; - path = path.replace("{"+"FlowSid"+"}", this.pathFlowSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "FlowSid" + "}", this.pathFlowSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +49,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Execution delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Execution delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/studio/v2/flow/ExecutionFetcher.java b/src/main/java/com/twilio/rest/studio/v2/flow/ExecutionFetcher.java index 656bdfbbef..d4ce384dd2 100644 --- a/src/main/java/com/twilio/rest/studio/v2/flow/ExecutionFetcher.java +++ b/src/main/java/com/twilio/rest/studio/v2/flow/ExecutionFetcher.java @@ -24,25 +24,22 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class ExecutionFetcher extends Fetcher { + private String pathFlowSid; private String pathSid; - public ExecutionFetcher(final String pathFlowSid, final String pathSid){ + public ExecutionFetcher(final String pathFlowSid, final String pathSid) { this.pathFlowSid = pathFlowSid; this.pathSid = pathSid; } - @Override public Execution fetch(final TwilioRestClient client) { String path = "/v2/Flows/{FlowSid}/Executions/{Sid}"; - path = path.replace("{"+"FlowSid"+"}", this.pathFlowSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "FlowSid" + "}", this.pathFlowSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,15 +49,23 @@ public Execution fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Execution fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Execution fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Execution.fromJson(response.getStream(), client.getObjectMapper()); + return Execution.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/studio/v2/flow/ExecutionReader.java b/src/main/java/com/twilio/rest/studio/v2/flow/ExecutionReader.java index 380aabe8be..cc680f8596 100644 --- a/src/main/java/com/twilio/rest/studio/v2/flow/ExecutionReader.java +++ b/src/main/java/com/twilio/rest/studio/v2/flow/ExecutionReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.studio.v2.flow; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,30 +25,32 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; import java.time.ZonedDateTime; - - public class ExecutionReader extends Reader { + private String pathFlowSid; private ZonedDateTime dateCreatedFrom; private ZonedDateTime dateCreatedTo; private Integer pageSize; - public ExecutionReader(final String pathFlowSid){ + public ExecutionReader(final String pathFlowSid) { this.pathFlowSid = pathFlowSid; } - public ExecutionReader setDateCreatedFrom(final ZonedDateTime dateCreatedFrom){ + public ExecutionReader setDateCreatedFrom( + final ZonedDateTime dateCreatedFrom + ) { this.dateCreatedFrom = dateCreatedFrom; return this; } - public ExecutionReader setDateCreatedTo(final ZonedDateTime dateCreatedTo){ + + public ExecutionReader setDateCreatedTo(final ZonedDateTime dateCreatedTo) { this.dateCreatedTo = dateCreatedTo; return this; } - public ExecutionReader setPageSize(final Integer pageSize){ + + public ExecutionReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -59,7 +62,7 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v2/Flows/{FlowSid}/Executions"; - path = path.replace("{"+"FlowSid"+"}", this.pathFlowSid.toString()); + path = path.replace("{" + "FlowSid" + "}", this.pathFlowSid.toString()); Request request = new Request( HttpMethod.GET, @@ -71,13 +74,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Execution read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Execution read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -93,7 +104,10 @@ private Page pageForRequest(final TwilioRestClient client, final Requ } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.STUDIO.toString()) @@ -101,9 +115,11 @@ public Page previousPage(final Page page, final TwilioRest return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.STUDIO.toString()) @@ -112,29 +128,35 @@ public Page nextPage(final Page page, final TwilioRestClie } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (dateCreatedFrom != null) { - request.addQueryParam("DateCreatedFrom", dateCreatedFrom.toInstant().toString()); + request.addQueryParam( + "DateCreatedFrom", + dateCreatedFrom.toInstant().toString() + ); } if (dateCreatedTo != null) { - request.addQueryParam("DateCreatedTo", dateCreatedTo.toInstant().toString()); + request.addQueryParam( + "DateCreatedTo", + dateCreatedTo.toInstant().toString() + ); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/studio/v2/flow/ExecutionUpdater.java b/src/main/java/com/twilio/rest/studio/v2/flow/ExecutionUpdater.java index 04876aa86f..8f584e077c 100644 --- a/src/main/java/com/twilio/rest/studio/v2/flow/ExecutionUpdater.java +++ b/src/main/java/com/twilio/rest/studio/v2/flow/ExecutionUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.studio.v2.flow; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,56 +25,67 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class ExecutionUpdater extends Updater { - - -public class ExecutionUpdater extends Updater{ private String pathFlowSid; private String pathSid; private Execution.Status status; - public ExecutionUpdater(final String pathFlowSid, final String pathSid, final Execution.Status status){ + public ExecutionUpdater( + final String pathFlowSid, + final String pathSid, + final Execution.Status status + ) { this.pathFlowSid = pathFlowSid; this.pathSid = pathSid; this.status = status; } - public ExecutionUpdater setStatus(final Execution.Status status){ + public ExecutionUpdater setStatus(final Execution.Status status) { this.status = status; return this; } @Override - public Execution update(final TwilioRestClient client){ + public Execution update(final TwilioRestClient client) { String path = "/v2/Flows/{FlowSid}/Executions/{Sid}"; - path = path.replace("{"+"FlowSid"+"}", this.pathFlowSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); - path = path.replace("{"+"Status"+"}", this.status.toString()); + path = path.replace("{" + "FlowSid" + "}", this.pathFlowSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + path = path.replace("{" + "Status" + "}", this.status.toString()); Request request = new Request( HttpMethod.POST, Domains.STUDIO.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Execution update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Execution update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Execution.fromJson(response.getStream(), client.getObjectMapper()); + return Execution.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (status != null) { request.addPostParam("Status", status.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/studio/v2/flow/FlowRevision.java b/src/main/java/com/twilio/rest/studio/v2/flow/FlowRevision.java index dbbdcb3733..eff2723c05 100644 --- a/src/main/java/com/twilio/rest/studio/v2/flow/FlowRevision.java +++ b/src/main/java/com/twilio/rest/studio/v2/flow/FlowRevision.java @@ -24,44 +24,46 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.List; import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class FlowRevision extends Resource { + private static final long serialVersionUID = 84648223923809L; - public static FlowRevisionFetcher fetcher(final String pathSid, final String pathRevision){ + public static FlowRevisionFetcher fetcher( + final String pathSid, + final String pathRevision + ) { return new FlowRevisionFetcher(pathSid, pathRevision); } - public static FlowRevisionReader reader(final String pathSid){ + public static FlowRevisionReader reader(final String pathSid) { return new FlowRevisionReader(pathSid); } /** - * Converts a JSON String into a FlowRevision object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return FlowRevision object represented by the provided JSON - */ - public static FlowRevision fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a FlowRevision object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return FlowRevision object represented by the provided JSON + */ + public static FlowRevision fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, FlowRevision.class); @@ -73,14 +75,17 @@ public static FlowRevision fromJson(final String json, final ObjectMapper object } /** - * Converts a JSON InputStream into a FlowRevision object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return FlowRevision object represented by the provided JSON - */ - public static FlowRevision fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a FlowRevision object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return FlowRevision object represented by the provided JSON + */ + public static FlowRevision fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, FlowRevision.class); @@ -90,6 +95,7 @@ public static FlowRevision fromJson(final InputStream json, final ObjectMapper o throw new ApiConnectionException(e.getMessage(), e); } } + public enum Status { DRAFT("draft"), PUBLISHED("published"); @@ -125,41 +131,18 @@ public static Status forValue(final String value) { @JsonCreator private FlowRevision( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("definition") - final Map definition, - - @JsonProperty("status") - final FlowRevision.Status status, - - @JsonProperty("revision") - final Integer revision, - - @JsonProperty("commit_message") - final String commitMessage, - - @JsonProperty("valid") - final Boolean valid, - - @JsonProperty("errors") - final List> errors, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("definition") final Map definition, + @JsonProperty("status") final FlowRevision.Status status, + @JsonProperty("revision") final Integer revision, + @JsonProperty("commit_message") final String commitMessage, + @JsonProperty("valid") final Boolean valid, + @JsonProperty("errors") final List> errors, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url ) { this.sid = sid; this.accountSid = accountSid; @@ -175,46 +158,57 @@ private FlowRevision( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final Map getDefinition() { - return this.definition; - } - public final FlowRevision.Status getStatus() { - return this.status; - } - public final Integer getRevision() { - return this.revision; - } - public final String getCommitMessage() { - return this.commitMessage; - } - public final Boolean getValid() { - return this.valid; - } - public final List> getErrors() { - return this.errors; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final Map getDefinition() { + return this.definition; + } + + public final FlowRevision.Status getStatus() { + return this.status; + } + + public final Integer getRevision() { + return this.revision; + } + + public final String getCommitMessage() { + return this.commitMessage; + } + + public final Boolean getValid() { + return this.valid; + } + + public final List> getErrors() { + return this.errors; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -224,13 +218,37 @@ public boolean equals(final Object o) { FlowRevision other = (FlowRevision) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(definition, other.definition) && Objects.equals(status, other.status) && Objects.equals(revision, other.revision) && Objects.equals(commitMessage, other.commitMessage) && Objects.equals(valid, other.valid) && Objects.equals(errors, other.errors) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(definition, other.definition) && + Objects.equals(status, other.status) && + Objects.equals(revision, other.revision) && + Objects.equals(commitMessage, other.commitMessage) && + Objects.equals(valid, other.valid) && + Objects.equals(errors, other.errors) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, friendlyName, definition, status, revision, commitMessage, valid, errors, dateCreated, dateUpdated, url); + return Objects.hash( + sid, + accountSid, + friendlyName, + definition, + status, + revision, + commitMessage, + valid, + errors, + dateCreated, + dateUpdated, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/studio/v2/flow/FlowRevisionFetcher.java b/src/main/java/com/twilio/rest/studio/v2/flow/FlowRevisionFetcher.java index 249b216107..3734dfffbb 100644 --- a/src/main/java/com/twilio/rest/studio/v2/flow/FlowRevisionFetcher.java +++ b/src/main/java/com/twilio/rest/studio/v2/flow/FlowRevisionFetcher.java @@ -24,25 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class FlowRevisionFetcher extends Fetcher { + private String pathSid; private String pathRevision; - public FlowRevisionFetcher(final String pathSid, final String pathRevision){ + public FlowRevisionFetcher( + final String pathSid, + final String pathRevision + ) { this.pathSid = pathSid; this.pathRevision = pathRevision; } - @Override public FlowRevision fetch(final TwilioRestClient client) { String path = "/v2/Flows/{Sid}/Revisions/{Revision}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); - path = path.replace("{"+"Revision"+"}", this.pathRevision.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + path = + path.replace("{" + "Revision" + "}", this.pathRevision.toString()); Request request = new Request( HttpMethod.GET, @@ -52,15 +53,23 @@ public FlowRevision fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("FlowRevision fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "FlowRevision fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return FlowRevision.fromJson(response.getStream(), client.getObjectMapper()); + return FlowRevision.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/studio/v2/flow/FlowRevisionReader.java b/src/main/java/com/twilio/rest/studio/v2/flow/FlowRevisionReader.java index c0232a73da..1b7df0a8ef 100644 --- a/src/main/java/com/twilio/rest/studio/v2/flow/FlowRevisionReader.java +++ b/src/main/java/com/twilio/rest/studio/v2/flow/FlowRevisionReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.studio.v2.flow; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,19 +25,17 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class FlowRevisionReader extends Reader { + private String pathSid; private Integer pageSize; - public FlowRevisionReader(final String pathSid){ + public FlowRevisionReader(final String pathSid) { this.pathSid = pathSid; } - public FlowRevisionReader setPageSize(final Integer pageSize){ + public FlowRevisionReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -48,7 +47,7 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v2/Flows/{Sid}/Revisions"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -60,13 +59,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("FlowRevision read failed: Unable to connect to server"); + throw new ApiConnectionException( + "FlowRevision read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +89,10 @@ private Page pageForRequest(final TwilioRestClient client, final R } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.STUDIO.toString()) @@ -90,9 +100,11 @@ public Page previousPage(final Page page, final Twil return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.STUDIO.toString()) @@ -101,21 +113,21 @@ public Page nextPage(final Page page, final TwilioRe } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/studio/v2/flow/FlowTestUser.java b/src/main/java/com/twilio/rest/studio/v2/flow/FlowTestUser.java index bd389036ff..ebd2459378 100644 --- a/src/main/java/com/twilio/rest/studio/v2/flow/FlowTestUser.java +++ b/src/main/java/com/twilio/rest/studio/v2/flow/FlowTestUser.java @@ -22,41 +22,43 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.List; import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class FlowTestUser extends Resource { + private static final long serialVersionUID = 221844198208701L; - public static FlowTestUserFetcher fetcher(final String pathSid){ + public static FlowTestUserFetcher fetcher(final String pathSid) { return new FlowTestUserFetcher(pathSid); } - public static FlowTestUserUpdater updater(final String pathSid, final List testUsers){ + public static FlowTestUserUpdater updater( + final String pathSid, + final List testUsers + ) { return new FlowTestUserUpdater(pathSid, testUsers); } /** - * Converts a JSON String into a FlowTestUser object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return FlowTestUser object represented by the provided JSON - */ - public static FlowTestUser fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a FlowTestUser object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return FlowTestUser object represented by the provided JSON + */ + public static FlowTestUser fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, FlowTestUser.class); @@ -68,14 +70,17 @@ public static FlowTestUser fromJson(final String json, final ObjectMapper object } /** - * Converts a JSON InputStream into a FlowTestUser object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return FlowTestUser object represented by the provided JSON - */ - public static FlowTestUser fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a FlowTestUser object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return FlowTestUser object represented by the provided JSON + */ + public static FlowTestUser fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, FlowTestUser.class); @@ -92,33 +97,30 @@ public static FlowTestUser fromJson(final InputStream json, final ObjectMapper o @JsonCreator private FlowTestUser( - @JsonProperty("sid") - final String sid, - - @JsonProperty("test_users") - final List testUsers, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("test_users") final List testUsers, + @JsonProperty("url") final URI url ) { this.sid = sid; this.testUsers = testUsers; this.url = url; } - public final String getSid() { - return this.sid; - } - public final List getTestUsers() { - return this.testUsers; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final List getTestUsers() { + return this.testUsers; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -128,13 +130,15 @@ public boolean equals(final Object o) { FlowTestUser other = (FlowTestUser) o; - return Objects.equals(sid, other.sid) && Objects.equals(testUsers, other.testUsers) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(testUsers, other.testUsers) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { return Objects.hash(sid, testUsers, url); } - } - diff --git a/src/main/java/com/twilio/rest/studio/v2/flow/FlowTestUserFetcher.java b/src/main/java/com/twilio/rest/studio/v2/flow/FlowTestUserFetcher.java index a460f10e06..31edbc653c 100644 --- a/src/main/java/com/twilio/rest/studio/v2/flow/FlowTestUserFetcher.java +++ b/src/main/java/com/twilio/rest/studio/v2/flow/FlowTestUserFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class FlowTestUserFetcher extends Fetcher { + private String pathSid; - public FlowTestUserFetcher(final String pathSid){ + public FlowTestUserFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public FlowTestUser fetch(final TwilioRestClient client) { String path = "/v2/Flows/{Sid}/TestUsers"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,15 +46,23 @@ public FlowTestUser fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("FlowTestUser fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "FlowTestUser fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return FlowTestUser.fromJson(response.getStream(), client.getObjectMapper()); + return FlowTestUser.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/studio/v2/flow/FlowTestUserUpdater.java b/src/main/java/com/twilio/rest/studio/v2/flow/FlowTestUserUpdater.java index 35c53079dd..0242d34c3f 100644 --- a/src/main/java/com/twilio/rest/studio/v2/flow/FlowTestUserUpdater.java +++ b/src/main/java/com/twilio/rest/studio/v2/flow/FlowTestUserUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.studio.v2.flow; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -24,60 +25,71 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - import java.util.List; +public class FlowTestUserUpdater extends Updater { -public class FlowTestUserUpdater extends Updater{ private String pathSid; private List testUsers; - public FlowTestUserUpdater(final String pathSid, final List testUsers){ + public FlowTestUserUpdater( + final String pathSid, + final List testUsers + ) { this.pathSid = pathSid; this.testUsers = testUsers; } - public FlowTestUserUpdater setTestUsers(final List testUsers){ + public FlowTestUserUpdater setTestUsers(final List testUsers) { this.testUsers = testUsers; return this; } - public FlowTestUserUpdater setTestUsers(final String testUsers){ + + public FlowTestUserUpdater setTestUsers(final String testUsers) { return setTestUsers(Promoter.listOfOne(testUsers)); } @Override - public FlowTestUser update(final TwilioRestClient client){ + public FlowTestUser update(final TwilioRestClient client) { String path = "/v2/Flows/{Sid}/TestUsers"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); - path = path.replace("{"+"TestUsers"+"}", this.testUsers.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + path = path.replace("{" + "TestUsers" + "}", this.testUsers.toString()); Request request = new Request( HttpMethod.POST, Domains.STUDIO.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("FlowTestUser update failed: Unable to connect to server"); + throw new ApiConnectionException( + "FlowTestUser update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return FlowTestUser.fromJson(response.getStream(), client.getObjectMapper()); + return FlowTestUser.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (testUsers != null) { for (String prop : testUsers) { request.addPostParam("TestUsers", prop); } - } } } diff --git a/src/main/java/com/twilio/rest/studio/v2/flow/execution/ExecutionContext.java b/src/main/java/com/twilio/rest/studio/v2/flow/execution/ExecutionContext.java index 4ba261cfbb..1e48c85839 100644 --- a/src/main/java/com/twilio/rest/studio/v2/flow/execution/ExecutionContext.java +++ b/src/main/java/com/twilio/rest/studio/v2/flow/execution/ExecutionContext.java @@ -22,38 +22,40 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class ExecutionContext extends Resource { + private static final long serialVersionUID = 48761390116247L; - public static ExecutionContextFetcher fetcher(final String pathFlowSid, final String pathExecutionSid){ + public static ExecutionContextFetcher fetcher( + final String pathFlowSid, + final String pathExecutionSid + ) { return new ExecutionContextFetcher(pathFlowSid, pathExecutionSid); } /** - * Converts a JSON String into a ExecutionContext object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return ExecutionContext object represented by the provided JSON - */ - public static ExecutionContext fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a ExecutionContext object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return ExecutionContext object represented by the provided JSON + */ + public static ExecutionContext fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, ExecutionContext.class); @@ -65,14 +67,17 @@ public static ExecutionContext fromJson(final String json, final ObjectMapper ob } /** - * Converts a JSON InputStream into a ExecutionContext object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return ExecutionContext object represented by the provided JSON - */ - public static ExecutionContext fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a ExecutionContext object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return ExecutionContext object represented by the provided JSON + */ + public static ExecutionContext fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, ExecutionContext.class); @@ -91,20 +96,11 @@ public static ExecutionContext fromJson(final InputStream json, final ObjectMapp @JsonCreator private ExecutionContext( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("context") - final Map context, - - @JsonProperty("flow_sid") - final String flowSid, - - @JsonProperty("execution_sid") - final String executionSid, - - @JsonProperty("url") - final URI url + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("context") final Map context, + @JsonProperty("flow_sid") final String flowSid, + @JsonProperty("execution_sid") final String executionSid, + @JsonProperty("url") final URI url ) { this.accountSid = accountSid; this.context = context; @@ -113,25 +109,29 @@ private ExecutionContext( this.url = url; } - public final String getAccountSid() { - return this.accountSid; - } - public final Map getContext() { - return this.context; - } - public final String getFlowSid() { - return this.flowSid; - } - public final String getExecutionSid() { - return this.executionSid; - } - public final URI getUrl() { - return this.url; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final Map getContext() { + return this.context; + } + + public final String getFlowSid() { + return this.flowSid; + } + + public final String getExecutionSid() { + return this.executionSid; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -141,13 +141,17 @@ public boolean equals(final Object o) { ExecutionContext other = (ExecutionContext) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(context, other.context) && Objects.equals(flowSid, other.flowSid) && Objects.equals(executionSid, other.executionSid) && Objects.equals(url, other.url) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(context, other.context) && + Objects.equals(flowSid, other.flowSid) && + Objects.equals(executionSid, other.executionSid) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { return Objects.hash(accountSid, context, flowSid, executionSid, url); } - } - diff --git a/src/main/java/com/twilio/rest/studio/v2/flow/execution/ExecutionContextFetcher.java b/src/main/java/com/twilio/rest/studio/v2/flow/execution/ExecutionContextFetcher.java index 2d952f2784..16aec87441 100644 --- a/src/main/java/com/twilio/rest/studio/v2/flow/execution/ExecutionContextFetcher.java +++ b/src/main/java/com/twilio/rest/studio/v2/flow/execution/ExecutionContextFetcher.java @@ -24,25 +24,29 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class ExecutionContextFetcher extends Fetcher { + private String pathFlowSid; private String pathExecutionSid; - public ExecutionContextFetcher(final String pathFlowSid, final String pathExecutionSid){ + public ExecutionContextFetcher( + final String pathFlowSid, + final String pathExecutionSid + ) { this.pathFlowSid = pathFlowSid; this.pathExecutionSid = pathExecutionSid; } - @Override public ExecutionContext fetch(final TwilioRestClient client) { String path = "/v2/Flows/{FlowSid}/Executions/{ExecutionSid}/Context"; - path = path.replace("{"+"FlowSid"+"}", this.pathFlowSid.toString()); - path = path.replace("{"+"ExecutionSid"+"}", this.pathExecutionSid.toString()); + path = path.replace("{" + "FlowSid" + "}", this.pathFlowSid.toString()); + path = + path.replace( + "{" + "ExecutionSid" + "}", + this.pathExecutionSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -52,15 +56,23 @@ public ExecutionContext fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("ExecutionContext fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "ExecutionContext fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return ExecutionContext.fromJson(response.getStream(), client.getObjectMapper()); + return ExecutionContext.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/studio/v2/flow/execution/ExecutionStep.java b/src/main/java/com/twilio/rest/studio/v2/flow/execution/ExecutionStep.java index e223e2cdab..d3a7801bbd 100644 --- a/src/main/java/com/twilio/rest/studio/v2/flow/execution/ExecutionStep.java +++ b/src/main/java/com/twilio/rest/studio/v2/flow/execution/ExecutionStep.java @@ -23,43 +23,49 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class ExecutionStep extends Resource { + private static final long serialVersionUID = 271983635262130L; - public static ExecutionStepFetcher fetcher(final String pathFlowSid, final String pathExecutionSid, final String pathSid){ + public static ExecutionStepFetcher fetcher( + final String pathFlowSid, + final String pathExecutionSid, + final String pathSid + ) { return new ExecutionStepFetcher(pathFlowSid, pathExecutionSid, pathSid); } - public static ExecutionStepReader reader(final String pathFlowSid, final String pathExecutionSid){ + public static ExecutionStepReader reader( + final String pathFlowSid, + final String pathExecutionSid + ) { return new ExecutionStepReader(pathFlowSid, pathExecutionSid); } /** - * Converts a JSON String into a ExecutionStep object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return ExecutionStep object represented by the provided JSON - */ - public static ExecutionStep fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a ExecutionStep object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return ExecutionStep object represented by the provided JSON + */ + public static ExecutionStep fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, ExecutionStep.class); @@ -71,14 +77,17 @@ public static ExecutionStep fromJson(final String json, final ObjectMapper objec } /** - * Converts a JSON InputStream into a ExecutionStep object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return ExecutionStep object represented by the provided JSON - */ - public static ExecutionStep fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a ExecutionStep object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return ExecutionStep object represented by the provided JSON + */ + public static ExecutionStep fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, ExecutionStep.class); @@ -104,41 +113,18 @@ public static ExecutionStep fromJson(final InputStream json, final ObjectMapper @JsonCreator private ExecutionStep( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("flow_sid") - final String flowSid, - - @JsonProperty("execution_sid") - final String executionSid, - - @JsonProperty("name") - final String name, - - @JsonProperty("context") - final Map context, - - @JsonProperty("transitioned_from") - final String transitionedFrom, - - @JsonProperty("transitioned_to") - final String transitionedTo, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("flow_sid") final String flowSid, + @JsonProperty("execution_sid") final String executionSid, + @JsonProperty("name") final String name, + @JsonProperty("context") final Map context, + @JsonProperty("transitioned_from") final String transitionedFrom, + @JsonProperty("transitioned_to") final String transitionedTo, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.sid = sid; this.accountSid = accountSid; @@ -154,46 +140,57 @@ private ExecutionStep( this.links = links; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getFlowSid() { - return this.flowSid; - } - public final String getExecutionSid() { - return this.executionSid; - } - public final String getName() { - return this.name; - } - public final Map getContext() { - return this.context; - } - public final String getTransitionedFrom() { - return this.transitionedFrom; - } - public final String getTransitionedTo() { - return this.transitionedTo; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getFlowSid() { + return this.flowSid; + } + + public final String getExecutionSid() { + return this.executionSid; + } + + public final String getName() { + return this.name; + } + + public final Map getContext() { + return this.context; + } + + public final String getTransitionedFrom() { + return this.transitionedFrom; + } + + public final String getTransitionedTo() { + return this.transitionedTo; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -203,13 +200,37 @@ public boolean equals(final Object o) { ExecutionStep other = (ExecutionStep) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(flowSid, other.flowSid) && Objects.equals(executionSid, other.executionSid) && Objects.equals(name, other.name) && Objects.equals(context, other.context) && Objects.equals(transitionedFrom, other.transitionedFrom) && Objects.equals(transitionedTo, other.transitionedTo) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(flowSid, other.flowSid) && + Objects.equals(executionSid, other.executionSid) && + Objects.equals(name, other.name) && + Objects.equals(context, other.context) && + Objects.equals(transitionedFrom, other.transitionedFrom) && + Objects.equals(transitionedTo, other.transitionedTo) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, flowSid, executionSid, name, context, transitionedFrom, transitionedTo, dateCreated, dateUpdated, url, links); + return Objects.hash( + sid, + accountSid, + flowSid, + executionSid, + name, + context, + transitionedFrom, + transitionedTo, + dateCreated, + dateUpdated, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/studio/v2/flow/execution/ExecutionStepFetcher.java b/src/main/java/com/twilio/rest/studio/v2/flow/execution/ExecutionStepFetcher.java index 838f5dacd3..6822acac38 100644 --- a/src/main/java/com/twilio/rest/studio/v2/flow/execution/ExecutionStepFetcher.java +++ b/src/main/java/com/twilio/rest/studio/v2/flow/execution/ExecutionStepFetcher.java @@ -24,28 +24,34 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class ExecutionStepFetcher extends Fetcher { + private String pathFlowSid; private String pathExecutionSid; private String pathSid; - public ExecutionStepFetcher(final String pathFlowSid, final String pathExecutionSid, final String pathSid){ + public ExecutionStepFetcher( + final String pathFlowSid, + final String pathExecutionSid, + final String pathSid + ) { this.pathFlowSid = pathFlowSid; this.pathExecutionSid = pathExecutionSid; this.pathSid = pathSid; } - @Override public ExecutionStep fetch(final TwilioRestClient client) { - String path = "/v2/Flows/{FlowSid}/Executions/{ExecutionSid}/Steps/{Sid}"; + String path = + "/v2/Flows/{FlowSid}/Executions/{ExecutionSid}/Steps/{Sid}"; - path = path.replace("{"+"FlowSid"+"}", this.pathFlowSid.toString()); - path = path.replace("{"+"ExecutionSid"+"}", this.pathExecutionSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "FlowSid" + "}", this.pathFlowSid.toString()); + path = + path.replace( + "{" + "ExecutionSid" + "}", + this.pathExecutionSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -55,15 +61,23 @@ public ExecutionStep fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("ExecutionStep fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "ExecutionStep fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return ExecutionStep.fromJson(response.getStream(), client.getObjectMapper()); + return ExecutionStep.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/studio/v2/flow/execution/ExecutionStepReader.java b/src/main/java/com/twilio/rest/studio/v2/flow/execution/ExecutionStepReader.java index 6bc51a6269..2a0ecce569 100644 --- a/src/main/java/com/twilio/rest/studio/v2/flow/execution/ExecutionStepReader.java +++ b/src/main/java/com/twilio/rest/studio/v2/flow/execution/ExecutionStepReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.studio.v2.flow.execution; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,21 +25,22 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class ExecutionStepReader extends Reader { + private String pathFlowSid; private String pathExecutionSid; private Integer pageSize; - public ExecutionStepReader(final String pathFlowSid, final String pathExecutionSid){ + public ExecutionStepReader( + final String pathFlowSid, + final String pathExecutionSid + ) { this.pathFlowSid = pathFlowSid; this.pathExecutionSid = pathExecutionSid; } - public ExecutionStepReader setPageSize(final Integer pageSize){ + public ExecutionStepReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -50,8 +52,12 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v2/Flows/{FlowSid}/Executions/{ExecutionSid}/Steps"; - path = path.replace("{"+"FlowSid"+"}", this.pathFlowSid.toString()); - path = path.replace("{"+"ExecutionSid"+"}", this.pathExecutionSid.toString()); + path = path.replace("{" + "FlowSid" + "}", this.pathFlowSid.toString()); + path = + path.replace( + "{" + "ExecutionSid" + "}", + this.pathExecutionSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -63,13 +69,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("ExecutionStep read failed: Unable to connect to server"); + throw new ApiConnectionException( + "ExecutionStep read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -85,7 +99,10 @@ private Page pageForRequest(final TwilioRestClient client, final } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.STUDIO.toString()) @@ -93,9 +110,11 @@ public Page previousPage(final Page page, final Tw return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.STUDIO.toString()) @@ -104,21 +123,21 @@ public Page nextPage(final Page page, final Twilio } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/studio/v2/flow/execution/executionstep/ExecutionStepContext.java b/src/main/java/com/twilio/rest/studio/v2/flow/execution/executionstep/ExecutionStepContext.java index 15ffa92e0e..384675effe 100644 --- a/src/main/java/com/twilio/rest/studio/v2/flow/execution/executionstep/ExecutionStepContext.java +++ b/src/main/java/com/twilio/rest/studio/v2/flow/execution/executionstep/ExecutionStepContext.java @@ -22,38 +22,45 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class ExecutionStepContext extends Resource { + private static final long serialVersionUID = 28705359719021L; - public static ExecutionStepContextFetcher fetcher(final String pathFlowSid, final String pathExecutionSid, final String pathStepSid){ - return new ExecutionStepContextFetcher(pathFlowSid, pathExecutionSid, pathStepSid); + public static ExecutionStepContextFetcher fetcher( + final String pathFlowSid, + final String pathExecutionSid, + final String pathStepSid + ) { + return new ExecutionStepContextFetcher( + pathFlowSid, + pathExecutionSid, + pathStepSid + ); } /** - * Converts a JSON String into a ExecutionStepContext object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return ExecutionStepContext object represented by the provided JSON - */ - public static ExecutionStepContext fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a ExecutionStepContext object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return ExecutionStepContext object represented by the provided JSON + */ + public static ExecutionStepContext fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, ExecutionStepContext.class); @@ -65,14 +72,17 @@ public static ExecutionStepContext fromJson(final String json, final ObjectMappe } /** - * Converts a JSON InputStream into a ExecutionStepContext object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return ExecutionStepContext object represented by the provided JSON - */ - public static ExecutionStepContext fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a ExecutionStepContext object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return ExecutionStepContext object represented by the provided JSON + */ + public static ExecutionStepContext fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, ExecutionStepContext.class); @@ -92,23 +102,12 @@ public static ExecutionStepContext fromJson(final InputStream json, final Object @JsonCreator private ExecutionStepContext( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("context") - final Map context, - - @JsonProperty("execution_sid") - final String executionSid, - - @JsonProperty("flow_sid") - final String flowSid, - - @JsonProperty("step_sid") - final String stepSid, - - @JsonProperty("url") - final URI url + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("context") final Map context, + @JsonProperty("execution_sid") final String executionSid, + @JsonProperty("flow_sid") final String flowSid, + @JsonProperty("step_sid") final String stepSid, + @JsonProperty("url") final URI url ) { this.accountSid = accountSid; this.context = context; @@ -118,28 +117,33 @@ private ExecutionStepContext( this.url = url; } - public final String getAccountSid() { - return this.accountSid; - } - public final Map getContext() { - return this.context; - } - public final String getExecutionSid() { - return this.executionSid; - } - public final String getFlowSid() { - return this.flowSid; - } - public final String getStepSid() { - return this.stepSid; - } - public final URI getUrl() { - return this.url; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final Map getContext() { + return this.context; + } + + public final String getExecutionSid() { + return this.executionSid; + } + + public final String getFlowSid() { + return this.flowSid; + } + + public final String getStepSid() { + return this.stepSid; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -149,13 +153,25 @@ public boolean equals(final Object o) { ExecutionStepContext other = (ExecutionStepContext) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(context, other.context) && Objects.equals(executionSid, other.executionSid) && Objects.equals(flowSid, other.flowSid) && Objects.equals(stepSid, other.stepSid) && Objects.equals(url, other.url) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(context, other.context) && + Objects.equals(executionSid, other.executionSid) && + Objects.equals(flowSid, other.flowSid) && + Objects.equals(stepSid, other.stepSid) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, context, executionSid, flowSid, stepSid, url); + return Objects.hash( + accountSid, + context, + executionSid, + flowSid, + stepSid, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/studio/v2/flow/execution/executionstep/ExecutionStepContextFetcher.java b/src/main/java/com/twilio/rest/studio/v2/flow/execution/executionstep/ExecutionStepContextFetcher.java index cf46b42b9d..9a4b8b6c88 100644 --- a/src/main/java/com/twilio/rest/studio/v2/flow/execution/executionstep/ExecutionStepContextFetcher.java +++ b/src/main/java/com/twilio/rest/studio/v2/flow/execution/executionstep/ExecutionStepContextFetcher.java @@ -24,28 +24,34 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class ExecutionStepContextFetcher extends Fetcher { + private String pathFlowSid; private String pathExecutionSid; private String pathStepSid; - public ExecutionStepContextFetcher(final String pathFlowSid, final String pathExecutionSid, final String pathStepSid){ + public ExecutionStepContextFetcher( + final String pathFlowSid, + final String pathExecutionSid, + final String pathStepSid + ) { this.pathFlowSid = pathFlowSid; this.pathExecutionSid = pathExecutionSid; this.pathStepSid = pathStepSid; } - @Override public ExecutionStepContext fetch(final TwilioRestClient client) { - String path = "/v2/Flows/{FlowSid}/Executions/{ExecutionSid}/Steps/{StepSid}/Context"; + String path = + "/v2/Flows/{FlowSid}/Executions/{ExecutionSid}/Steps/{StepSid}/Context"; - path = path.replace("{"+"FlowSid"+"}", this.pathFlowSid.toString()); - path = path.replace("{"+"ExecutionSid"+"}", this.pathExecutionSid.toString()); - path = path.replace("{"+"StepSid"+"}", this.pathStepSid.toString()); + path = path.replace("{" + "FlowSid" + "}", this.pathFlowSid.toString()); + path = + path.replace( + "{" + "ExecutionSid" + "}", + this.pathExecutionSid.toString() + ); + path = path.replace("{" + "StepSid" + "}", this.pathStepSid.toString()); Request request = new Request( HttpMethod.GET, @@ -55,15 +61,23 @@ public ExecutionStepContext fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("ExecutionStepContext fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "ExecutionStepContext fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return ExecutionStepContext.fromJson(response.getStream(), client.getObjectMapper()); + return ExecutionStepContext.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/supersim/v1/EsimProfile.java b/src/main/java/com/twilio/rest/supersim/v1/EsimProfile.java index bc57221de8..ca26959322 100644 --- a/src/main/java/com/twilio/rest/supersim/v1/EsimProfile.java +++ b/src/main/java/com/twilio/rest/supersim/v1/EsimProfile.java @@ -24,45 +24,44 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class EsimProfile extends Resource { + private static final long serialVersionUID = 165735118410901L; - public static EsimProfileCreator creator(){ + public static EsimProfileCreator creator() { return new EsimProfileCreator(); } - public static EsimProfileFetcher fetcher(final String pathSid){ + public static EsimProfileFetcher fetcher(final String pathSid) { return new EsimProfileFetcher(pathSid); } - public static EsimProfileReader reader(){ + public static EsimProfileReader reader() { return new EsimProfileReader(); } /** - * Converts a JSON String into a EsimProfile object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return EsimProfile object represented by the provided JSON - */ - public static EsimProfile fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a EsimProfile object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return EsimProfile object represented by the provided JSON + */ + public static EsimProfile fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, EsimProfile.class); @@ -74,14 +73,17 @@ public static EsimProfile fromJson(final String json, final ObjectMapper objectM } /** - * Converts a JSON InputStream into a EsimProfile object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return EsimProfile object represented by the provided JSON - */ - public static EsimProfile fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a EsimProfile object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return EsimProfile object represented by the provided JSON + */ + public static EsimProfile fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, EsimProfile.class); @@ -91,6 +93,7 @@ public static EsimProfile fromJson(final InputStream json, final ObjectMapper ob throw new ApiConnectionException(e.getMessage(), e); } } + public enum Status { NEW("new"), RESERVING("reserving"), @@ -132,47 +135,20 @@ public static Status forValue(final String value) { @JsonCreator private EsimProfile( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("iccid") - final String iccid, - - @JsonProperty("sim_sid") - final String simSid, - - @JsonProperty("status") - final EsimProfile.Status status, - - @JsonProperty("eid") - final String eid, - - @JsonProperty("smdp_plus_address") - final URI smdpPlusAddress, - - @JsonProperty("matching_id") - final String matchingId, - - @JsonProperty("activation_code") - final String activationCode, - - @JsonProperty("error_code") - final String errorCode, - - @JsonProperty("error_message") - final String errorMessage, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("iccid") final String iccid, + @JsonProperty("sim_sid") final String simSid, + @JsonProperty("status") final EsimProfile.Status status, + @JsonProperty("eid") final String eid, + @JsonProperty("smdp_plus_address") final URI smdpPlusAddress, + @JsonProperty("matching_id") final String matchingId, + @JsonProperty("activation_code") final String activationCode, + @JsonProperty("error_code") final String errorCode, + @JsonProperty("error_message") final String errorMessage, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url ) { this.sid = sid; this.accountSid = accountSid; @@ -190,52 +166,65 @@ private EsimProfile( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getIccid() { - return this.iccid; - } - public final String getSimSid() { - return this.simSid; - } - public final EsimProfile.Status getStatus() { - return this.status; - } - public final String getEid() { - return this.eid; - } - public final URI getSmdpPlusAddress() { - return this.smdpPlusAddress; - } - public final String getMatchingId() { - return this.matchingId; - } - public final String getActivationCode() { - return this.activationCode; - } - public final String getErrorCode() { - return this.errorCode; - } - public final String getErrorMessage() { - return this.errorMessage; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getIccid() { + return this.iccid; + } + + public final String getSimSid() { + return this.simSid; + } + + public final EsimProfile.Status getStatus() { + return this.status; + } + + public final String getEid() { + return this.eid; + } + + public final URI getSmdpPlusAddress() { + return this.smdpPlusAddress; + } + + public final String getMatchingId() { + return this.matchingId; + } + + public final String getActivationCode() { + return this.activationCode; + } + + public final String getErrorCode() { + return this.errorCode; + } + + public final String getErrorMessage() { + return this.errorMessage; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -245,13 +234,41 @@ public boolean equals(final Object o) { EsimProfile other = (EsimProfile) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(iccid, other.iccid) && Objects.equals(simSid, other.simSid) && Objects.equals(status, other.status) && Objects.equals(eid, other.eid) && Objects.equals(smdpPlusAddress, other.smdpPlusAddress) && Objects.equals(matchingId, other.matchingId) && Objects.equals(activationCode, other.activationCode) && Objects.equals(errorCode, other.errorCode) && Objects.equals(errorMessage, other.errorMessage) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(iccid, other.iccid) && + Objects.equals(simSid, other.simSid) && + Objects.equals(status, other.status) && + Objects.equals(eid, other.eid) && + Objects.equals(smdpPlusAddress, other.smdpPlusAddress) && + Objects.equals(matchingId, other.matchingId) && + Objects.equals(activationCode, other.activationCode) && + Objects.equals(errorCode, other.errorCode) && + Objects.equals(errorMessage, other.errorMessage) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, iccid, simSid, status, eid, smdpPlusAddress, matchingId, activationCode, errorCode, errorMessage, dateCreated, dateUpdated, url); + return Objects.hash( + sid, + accountSid, + iccid, + simSid, + status, + eid, + smdpPlusAddress, + matchingId, + activationCode, + errorCode, + errorMessage, + dateCreated, + dateUpdated, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/supersim/v1/EsimProfileCreator.java b/src/main/java/com/twilio/rest/supersim/v1/EsimProfileCreator.java index f3e2edb3f4..7fc575fb6c 100644 --- a/src/main/java/com/twilio/rest/supersim/v1/EsimProfileCreator.java +++ b/src/main/java/com/twilio/rest/supersim/v1/EsimProfileCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.supersim.v1; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,75 +25,87 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class EsimProfileCreator extends Creator { - - -public class EsimProfileCreator extends Creator{ private String callbackUrl; private HttpMethod callbackMethod; private Boolean generateMatchingId; private String eid; - public EsimProfileCreator() { - } + public EsimProfileCreator() {} - public EsimProfileCreator setCallbackUrl(final String callbackUrl){ + public EsimProfileCreator setCallbackUrl(final String callbackUrl) { this.callbackUrl = callbackUrl; return this; } - public EsimProfileCreator setCallbackMethod(final HttpMethod callbackMethod){ + + public EsimProfileCreator setCallbackMethod( + final HttpMethod callbackMethod + ) { this.callbackMethod = callbackMethod; return this; } - public EsimProfileCreator setGenerateMatchingId(final Boolean generateMatchingId){ + + public EsimProfileCreator setGenerateMatchingId( + final Boolean generateMatchingId + ) { this.generateMatchingId = generateMatchingId; return this; } - public EsimProfileCreator setEid(final String eid){ + + public EsimProfileCreator setEid(final String eid) { this.eid = eid; return this; } @Override - public EsimProfile create(final TwilioRestClient client){ + public EsimProfile create(final TwilioRestClient client) { String path = "/v1/ESimProfiles"; - Request request = new Request( HttpMethod.POST, Domains.SUPERSIM.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("EsimProfile creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "EsimProfile creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return EsimProfile.fromJson(response.getStream(), client.getObjectMapper()); + return EsimProfile.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (callbackUrl != null) { request.addPostParam("CallbackUrl", callbackUrl); - } if (callbackMethod != null) { request.addPostParam("CallbackMethod", callbackMethod.toString()); - } if (generateMatchingId != null) { - request.addPostParam("GenerateMatchingId", generateMatchingId.toString()); - + request.addPostParam( + "GenerateMatchingId", + generateMatchingId.toString() + ); } if (eid != null) { request.addPostParam("Eid", eid); - } } } diff --git a/src/main/java/com/twilio/rest/supersim/v1/EsimProfileFetcher.java b/src/main/java/com/twilio/rest/supersim/v1/EsimProfileFetcher.java index fb0f1cc1c0..43ae503f16 100644 --- a/src/main/java/com/twilio/rest/supersim/v1/EsimProfileFetcher.java +++ b/src/main/java/com/twilio/rest/supersim/v1/EsimProfileFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class EsimProfileFetcher extends Fetcher { + private String pathSid; - public EsimProfileFetcher(final String pathSid){ + public EsimProfileFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public EsimProfile fetch(final TwilioRestClient client) { String path = "/v1/ESimProfiles/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,15 +46,23 @@ public EsimProfile fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("EsimProfile fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "EsimProfile fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return EsimProfile.fromJson(response.getStream(), client.getObjectMapper()); + return EsimProfile.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/supersim/v1/EsimProfileReader.java b/src/main/java/com/twilio/rest/supersim/v1/EsimProfileReader.java index cf0e2a578f..ad08691c0e 100644 --- a/src/main/java/com/twilio/rest/supersim/v1/EsimProfileReader.java +++ b/src/main/java/com/twilio/rest/supersim/v1/EsimProfileReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.supersim.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,32 +25,32 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class EsimProfileReader extends Reader { + private String eid; private String simSid; private EsimProfile.Status status; private Integer pageSize; - public EsimProfileReader(){ - } + public EsimProfileReader() {} - public EsimProfileReader setEid(final String eid){ + public EsimProfileReader setEid(final String eid) { this.eid = eid; return this; } - public EsimProfileReader setSimSid(final String simSid){ + + public EsimProfileReader setSimSid(final String simSid) { this.simSid = simSid; return this; } - public EsimProfileReader setStatus(final EsimProfile.Status status){ + + public EsimProfileReader setStatus(final EsimProfile.Status status) { this.status = status; return this; } - public EsimProfileReader setPageSize(final Integer pageSize){ + + public EsimProfileReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -72,13 +73,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("EsimProfile read failed: Unable to connect to server"); + throw new ApiConnectionException( + "EsimProfile read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -94,7 +103,10 @@ private Page pageForRequest(final TwilioRestClient client, final Re } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.SUPERSIM.toString()) @@ -102,9 +114,11 @@ public Page previousPage(final Page page, final Twilio return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.SUPERSIM.toString()) @@ -113,33 +127,30 @@ public Page nextPage(final Page page, final TwilioRest } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (eid != null) { - request.addQueryParam("Eid", eid); } if (simSid != null) { - request.addQueryParam("SimSid", simSid); } if (status != null) { - request.addQueryParam("Status", status.toString()); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/supersim/v1/Fleet.java b/src/main/java/com/twilio/rest/supersim/v1/Fleet.java index 7b767f1321..702b4b94c6 100644 --- a/src/main/java/com/twilio/rest/supersim/v1/Fleet.java +++ b/src/main/java/com/twilio/rest/supersim/v1/Fleet.java @@ -24,50 +24,49 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; import com.twilio.http.HttpMethod; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Fleet extends Resource { + private static final long serialVersionUID = 74063802547191L; - public static FleetCreator creator(final String networkAccessProfile){ + public static FleetCreator creator(final String networkAccessProfile) { return new FleetCreator(networkAccessProfile); } - public static FleetFetcher fetcher(final String pathSid){ + public static FleetFetcher fetcher(final String pathSid) { return new FleetFetcher(pathSid); } - public static FleetReader reader(){ + public static FleetReader reader() { return new FleetReader(); } - public static FleetUpdater updater(final String pathSid){ + public static FleetUpdater updater(final String pathSid) { return new FleetUpdater(pathSid); } /** - * Converts a JSON String into a Fleet object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Fleet object represented by the provided JSON - */ - public static Fleet fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Fleet object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Fleet object represented by the provided JSON + */ + public static Fleet fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Fleet.class); @@ -79,14 +78,17 @@ public static Fleet fromJson(final String json, final ObjectMapper objectMapper) } /** - * Converts a JSON InputStream into a Fleet object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Fleet object represented by the provided JSON - */ - public static Fleet fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Fleet object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Fleet object represented by the provided JSON + */ + public static Fleet fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Fleet.class); @@ -96,6 +98,7 @@ public static Fleet fromJson(final InputStream json, final ObjectMapper objectMa throw new ApiConnectionException(e.getMessage(), e); } } + public enum DataMetering { PAYG("payg"); @@ -133,50 +136,23 @@ public static DataMetering forValue(final String value) { @JsonCreator private Fleet( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("unique_name") - final String uniqueName, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url, - - @JsonProperty("data_enabled") - final Boolean dataEnabled, - - @JsonProperty("data_limit") - final Integer dataLimit, - - @JsonProperty("data_metering") - final Fleet.DataMetering dataMetering, - - @JsonProperty("sms_commands_enabled") - final Boolean smsCommandsEnabled, - - @JsonProperty("sms_commands_url") - final URI smsCommandsUrl, - - @JsonProperty("sms_commands_method") - final HttpMethod smsCommandsMethod, - - @JsonProperty("network_access_profile_sid") - final String networkAccessProfileSid, - - @JsonProperty("ip_commands_url") - final URI ipCommandsUrl, - - @JsonProperty("ip_commands_method") - final HttpMethod ipCommandsMethod + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("sid") final String sid, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url, + @JsonProperty("data_enabled") final Boolean dataEnabled, + @JsonProperty("data_limit") final Integer dataLimit, + @JsonProperty("data_metering") final Fleet.DataMetering dataMetering, + @JsonProperty("sms_commands_enabled") final Boolean smsCommandsEnabled, + @JsonProperty("sms_commands_url") final URI smsCommandsUrl, + @JsonProperty("sms_commands_method") final HttpMethod smsCommandsMethod, + @JsonProperty( + "network_access_profile_sid" + ) final String networkAccessProfileSid, + @JsonProperty("ip_commands_url") final URI ipCommandsUrl, + @JsonProperty("ip_commands_method") final HttpMethod ipCommandsMethod ) { this.accountSid = accountSid; this.sid = sid; @@ -195,55 +171,69 @@ private Fleet( this.ipCommandsMethod = ipCommandsMethod; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getSid() { - return this.sid; - } - public final String getUniqueName() { - return this.uniqueName; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } - public final Boolean getDataEnabled() { - return this.dataEnabled; - } - public final Integer getDataLimit() { - return this.dataLimit; - } - public final Fleet.DataMetering getDataMetering() { - return this.dataMetering; - } - public final Boolean getSmsCommandsEnabled() { - return this.smsCommandsEnabled; - } - public final URI getSmsCommandsUrl() { - return this.smsCommandsUrl; - } - public final HttpMethod getSmsCommandsMethod() { - return this.smsCommandsMethod; - } - public final String getNetworkAccessProfileSid() { - return this.networkAccessProfileSid; - } - public final URI getIpCommandsUrl() { - return this.ipCommandsUrl; - } - public final HttpMethod getIpCommandsMethod() { - return this.ipCommandsMethod; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getSid() { + return this.sid; + } + + public final String getUniqueName() { + return this.uniqueName; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } + + public final Boolean getDataEnabled() { + return this.dataEnabled; + } + + public final Integer getDataLimit() { + return this.dataLimit; + } + + public final Fleet.DataMetering getDataMetering() { + return this.dataMetering; + } + + public final Boolean getSmsCommandsEnabled() { + return this.smsCommandsEnabled; + } + + public final URI getSmsCommandsUrl() { + return this.smsCommandsUrl; + } + + public final HttpMethod getSmsCommandsMethod() { + return this.smsCommandsMethod; + } + + public final String getNetworkAccessProfileSid() { + return this.networkAccessProfileSid; + } + + public final URI getIpCommandsUrl() { + return this.ipCommandsUrl; + } + + public final HttpMethod getIpCommandsMethod() { + return this.ipCommandsMethod; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -253,13 +243,46 @@ public boolean equals(final Object o) { Fleet other = (Fleet) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(sid, other.sid) && Objects.equals(uniqueName, other.uniqueName) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) && Objects.equals(dataEnabled, other.dataEnabled) && Objects.equals(dataLimit, other.dataLimit) && Objects.equals(dataMetering, other.dataMetering) && Objects.equals(smsCommandsEnabled, other.smsCommandsEnabled) && Objects.equals(smsCommandsUrl, other.smsCommandsUrl) && Objects.equals(smsCommandsMethod, other.smsCommandsMethod) && Objects.equals(networkAccessProfileSid, other.networkAccessProfileSid) && Objects.equals(ipCommandsUrl, other.ipCommandsUrl) && Objects.equals(ipCommandsMethod, other.ipCommandsMethod) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(sid, other.sid) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) && + Objects.equals(dataEnabled, other.dataEnabled) && + Objects.equals(dataLimit, other.dataLimit) && + Objects.equals(dataMetering, other.dataMetering) && + Objects.equals(smsCommandsEnabled, other.smsCommandsEnabled) && + Objects.equals(smsCommandsUrl, other.smsCommandsUrl) && + Objects.equals(smsCommandsMethod, other.smsCommandsMethod) && + Objects.equals( + networkAccessProfileSid, + other.networkAccessProfileSid + ) && + Objects.equals(ipCommandsUrl, other.ipCommandsUrl) && + Objects.equals(ipCommandsMethod, other.ipCommandsMethod) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, sid, uniqueName, dateCreated, dateUpdated, url, dataEnabled, dataLimit, dataMetering, smsCommandsEnabled, smsCommandsUrl, smsCommandsMethod, networkAccessProfileSid, ipCommandsUrl, ipCommandsMethod); + return Objects.hash( + accountSid, + sid, + uniqueName, + dateCreated, + dateUpdated, + url, + dataEnabled, + dataLimit, + dataMetering, + smsCommandsEnabled, + smsCommandsUrl, + smsCommandsMethod, + networkAccessProfileSid, + ipCommandsUrl, + ipCommandsMethod + ); } - } - diff --git a/src/main/java/com/twilio/rest/supersim/v1/FleetCreator.java b/src/main/java/com/twilio/rest/supersim/v1/FleetCreator.java index 75f30d2de9..21444ac021 100644 --- a/src/main/java/com/twilio/rest/supersim/v1/FleetCreator.java +++ b/src/main/java/com/twilio/rest/supersim/v1/FleetCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.supersim.v1; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -25,12 +26,10 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.net.URI; - - - import java.net.URI; -public class FleetCreator extends Creator{ +public class FleetCreator extends Creator { + private String networkAccessProfile; private String uniqueName; private Boolean dataEnabled; @@ -45,68 +44,92 @@ public FleetCreator(final String networkAccessProfile) { this.networkAccessProfile = networkAccessProfile; } - public FleetCreator setNetworkAccessProfile(final String networkAccessProfile){ + public FleetCreator setNetworkAccessProfile( + final String networkAccessProfile + ) { this.networkAccessProfile = networkAccessProfile; return this; } - public FleetCreator setUniqueName(final String uniqueName){ + + public FleetCreator setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - public FleetCreator setDataEnabled(final Boolean dataEnabled){ + + public FleetCreator setDataEnabled(final Boolean dataEnabled) { this.dataEnabled = dataEnabled; return this; } - public FleetCreator setDataLimit(final Integer dataLimit){ + + public FleetCreator setDataLimit(final Integer dataLimit) { this.dataLimit = dataLimit; return this; } - public FleetCreator setIpCommandsUrl(final URI ipCommandsUrl){ + + public FleetCreator setIpCommandsUrl(final URI ipCommandsUrl) { this.ipCommandsUrl = ipCommandsUrl; return this; } - public FleetCreator setIpCommandsUrl(final String ipCommandsUrl){ + public FleetCreator setIpCommandsUrl(final String ipCommandsUrl) { return setIpCommandsUrl(Promoter.uriFromString(ipCommandsUrl)); } - public FleetCreator setIpCommandsMethod(final HttpMethod ipCommandsMethod){ + + public FleetCreator setIpCommandsMethod(final HttpMethod ipCommandsMethod) { this.ipCommandsMethod = ipCommandsMethod; return this; } - public FleetCreator setSmsCommandsEnabled(final Boolean smsCommandsEnabled){ + + public FleetCreator setSmsCommandsEnabled( + final Boolean smsCommandsEnabled + ) { this.smsCommandsEnabled = smsCommandsEnabled; return this; } - public FleetCreator setSmsCommandsUrl(final URI smsCommandsUrl){ + + public FleetCreator setSmsCommandsUrl(final URI smsCommandsUrl) { this.smsCommandsUrl = smsCommandsUrl; return this; } - public FleetCreator setSmsCommandsUrl(final String smsCommandsUrl){ + public FleetCreator setSmsCommandsUrl(final String smsCommandsUrl) { return setSmsCommandsUrl(Promoter.uriFromString(smsCommandsUrl)); } - public FleetCreator setSmsCommandsMethod(final HttpMethod smsCommandsMethod){ + + public FleetCreator setSmsCommandsMethod( + final HttpMethod smsCommandsMethod + ) { this.smsCommandsMethod = smsCommandsMethod; return this; } @Override - public Fleet create(final TwilioRestClient client){ + public Fleet create(final TwilioRestClient client) { String path = "/v1/Fleets"; - path = path.replace("{"+"NetworkAccessProfile"+"}", this.networkAccessProfile.toString()); + path = + path.replace( + "{" + "NetworkAccessProfile" + "}", + this.networkAccessProfile.toString() + ); Request request = new Request( HttpMethod.POST, Domains.SUPERSIM.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Fleet creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Fleet creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -115,42 +138,43 @@ public Fleet create(final TwilioRestClient client){ return Fleet.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (networkAccessProfile != null) { request.addPostParam("NetworkAccessProfile", networkAccessProfile); - } if (uniqueName != null) { request.addPostParam("UniqueName", uniqueName); - } if (dataEnabled != null) { request.addPostParam("DataEnabled", dataEnabled.toString()); - } if (dataLimit != null) { request.addPostParam("DataLimit", dataLimit.toString()); - } if (ipCommandsUrl != null) { request.addPostParam("IpCommandsUrl", ipCommandsUrl.toString()); - } if (ipCommandsMethod != null) { - request.addPostParam("IpCommandsMethod", ipCommandsMethod.toString()); - + request.addPostParam( + "IpCommandsMethod", + ipCommandsMethod.toString() + ); } if (smsCommandsEnabled != null) { - request.addPostParam("SmsCommandsEnabled", smsCommandsEnabled.toString()); - + request.addPostParam( + "SmsCommandsEnabled", + smsCommandsEnabled.toString() + ); } if (smsCommandsUrl != null) { request.addPostParam("SmsCommandsUrl", smsCommandsUrl.toString()); - } if (smsCommandsMethod != null) { - request.addPostParam("SmsCommandsMethod", smsCommandsMethod.toString()); - + request.addPostParam( + "SmsCommandsMethod", + smsCommandsMethod.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/supersim/v1/FleetFetcher.java b/src/main/java/com/twilio/rest/supersim/v1/FleetFetcher.java index 91ed25997d..e7ad434d95 100644 --- a/src/main/java/com/twilio/rest/supersim/v1/FleetFetcher.java +++ b/src/main/java/com/twilio/rest/supersim/v1/FleetFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class FleetFetcher extends Fetcher { + private String pathSid; - public FleetFetcher(final String pathSid){ + public FleetFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public Fleet fetch(final TwilioRestClient client) { String path = "/v1/Fleets/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,9 +46,14 @@ public Fleet fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Fleet fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Fleet fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/supersim/v1/FleetReader.java b/src/main/java/com/twilio/rest/supersim/v1/FleetReader.java index 6fc3640507..0b070fb6af 100644 --- a/src/main/java/com/twilio/rest/supersim/v1/FleetReader.java +++ b/src/main/java/com/twilio/rest/supersim/v1/FleetReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.supersim.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,22 +25,22 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class FleetReader extends Reader { + private String networkAccessProfile; private Integer pageSize; - public FleetReader(){ - } + public FleetReader() {} - public FleetReader setNetworkAccessProfile(final String networkAccessProfile){ + public FleetReader setNetworkAccessProfile( + final String networkAccessProfile + ) { this.networkAccessProfile = networkAccessProfile; return this; } - public FleetReader setPageSize(final Integer pageSize){ + + public FleetReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -62,13 +63,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Fleet read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Fleet read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -84,7 +93,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.SUPERSIM.toString()) @@ -92,9 +104,11 @@ public Page previousPage(final Page page, final TwilioRestClient c return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.SUPERSIM.toString()) @@ -103,25 +117,24 @@ public Page nextPage(final Page page, final TwilioRestClient clien } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (networkAccessProfile != null) { - request.addQueryParam("NetworkAccessProfile", networkAccessProfile); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/supersim/v1/FleetUpdater.java b/src/main/java/com/twilio/rest/supersim/v1/FleetUpdater.java index ddae52e9a3..dd8167a9a3 100644 --- a/src/main/java/com/twilio/rest/supersim/v1/FleetUpdater.java +++ b/src/main/java/com/twilio/rest/supersim/v1/FleetUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.supersim.v1; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -24,12 +25,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.net.URI; +public class FleetUpdater extends Updater { - -public class FleetUpdater extends Updater{ private String pathSid; private String uniqueName; private String networkAccessProfile; @@ -39,64 +38,80 @@ public class FleetUpdater extends Updater{ private HttpMethod smsCommandsMethod; private Integer dataLimit; - public FleetUpdater(final String pathSid){ + public FleetUpdater(final String pathSid) { this.pathSid = pathSid; } - public FleetUpdater setUniqueName(final String uniqueName){ + public FleetUpdater setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - public FleetUpdater setNetworkAccessProfile(final String networkAccessProfile){ + + public FleetUpdater setNetworkAccessProfile( + final String networkAccessProfile + ) { this.networkAccessProfile = networkAccessProfile; return this; } - public FleetUpdater setIpCommandsUrl(final URI ipCommandsUrl){ + + public FleetUpdater setIpCommandsUrl(final URI ipCommandsUrl) { this.ipCommandsUrl = ipCommandsUrl; return this; } - public FleetUpdater setIpCommandsUrl(final String ipCommandsUrl){ + public FleetUpdater setIpCommandsUrl(final String ipCommandsUrl) { return setIpCommandsUrl(Promoter.uriFromString(ipCommandsUrl)); } - public FleetUpdater setIpCommandsMethod(final HttpMethod ipCommandsMethod){ + + public FleetUpdater setIpCommandsMethod(final HttpMethod ipCommandsMethod) { this.ipCommandsMethod = ipCommandsMethod; return this; } - public FleetUpdater setSmsCommandsUrl(final URI smsCommandsUrl){ + + public FleetUpdater setSmsCommandsUrl(final URI smsCommandsUrl) { this.smsCommandsUrl = smsCommandsUrl; return this; } - public FleetUpdater setSmsCommandsUrl(final String smsCommandsUrl){ + public FleetUpdater setSmsCommandsUrl(final String smsCommandsUrl) { return setSmsCommandsUrl(Promoter.uriFromString(smsCommandsUrl)); } - public FleetUpdater setSmsCommandsMethod(final HttpMethod smsCommandsMethod){ + + public FleetUpdater setSmsCommandsMethod( + final HttpMethod smsCommandsMethod + ) { this.smsCommandsMethod = smsCommandsMethod; return this; } - public FleetUpdater setDataLimit(final Integer dataLimit){ + + public FleetUpdater setDataLimit(final Integer dataLimit) { this.dataLimit = dataLimit; return this; } @Override - public Fleet update(final TwilioRestClient client){ + public Fleet update(final TwilioRestClient client) { String path = "/v1/Fleets/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.SUPERSIM.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Fleet update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Fleet update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -105,34 +120,34 @@ public Fleet update(final TwilioRestClient client){ return Fleet.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (uniqueName != null) { request.addPostParam("UniqueName", uniqueName); - } if (networkAccessProfile != null) { request.addPostParam("NetworkAccessProfile", networkAccessProfile); - } if (ipCommandsUrl != null) { request.addPostParam("IpCommandsUrl", ipCommandsUrl.toString()); - } if (ipCommandsMethod != null) { - request.addPostParam("IpCommandsMethod", ipCommandsMethod.toString()); - + request.addPostParam( + "IpCommandsMethod", + ipCommandsMethod.toString() + ); } if (smsCommandsUrl != null) { request.addPostParam("SmsCommandsUrl", smsCommandsUrl.toString()); - } if (smsCommandsMethod != null) { - request.addPostParam("SmsCommandsMethod", smsCommandsMethod.toString()); - + request.addPostParam( + "SmsCommandsMethod", + smsCommandsMethod.toString() + ); } if (dataLimit != null) { request.addPostParam("DataLimit", dataLimit.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/supersim/v1/IpCommand.java b/src/main/java/com/twilio/rest/supersim/v1/IpCommand.java index 8a45366dde..b419666fd3 100644 --- a/src/main/java/com/twilio/rest/supersim/v1/IpCommand.java +++ b/src/main/java/com/twilio/rest/supersim/v1/IpCommand.java @@ -24,45 +24,48 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class IpCommand extends Resource { + private static final long serialVersionUID = 232445526954174L; - public static IpCommandCreator creator(final String sim, final String payload, final Integer devicePort){ + public static IpCommandCreator creator( + final String sim, + final String payload, + final Integer devicePort + ) { return new IpCommandCreator(sim, payload, devicePort); } - public static IpCommandFetcher fetcher(final String pathSid){ + public static IpCommandFetcher fetcher(final String pathSid) { return new IpCommandFetcher(pathSid); } - public static IpCommandReader reader(){ + public static IpCommandReader reader() { return new IpCommandReader(); } /** - * Converts a JSON String into a IpCommand object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return IpCommand object represented by the provided JSON - */ - public static IpCommand fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a IpCommand object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return IpCommand object represented by the provided JSON + */ + public static IpCommand fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, IpCommand.class); @@ -74,14 +77,17 @@ public static IpCommand fromJson(final String json, final ObjectMapper objectMap } /** - * Converts a JSON InputStream into a IpCommand object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return IpCommand object represented by the provided JSON - */ - public static IpCommand fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a IpCommand object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return IpCommand object represented by the provided JSON + */ + public static IpCommand fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, IpCommand.class); @@ -91,6 +97,7 @@ public static IpCommand fromJson(final InputStream json, final ObjectMapper obje throw new ApiConnectionException(e.getMessage(), e); } } + public enum Direction { TO_SIM("to_sim"), FROM_SIM("from_sim"); @@ -110,6 +117,7 @@ public static Direction forValue(final String value) { return Promoter.enumFromString(value, Direction.values()); } } + public enum PayloadType { TEXT("text"), BINARY("binary"); @@ -129,6 +137,7 @@ public static PayloadType forValue(final String value) { return Promoter.enumFromString(value, PayloadType.values()); } } + public enum Status { QUEUED("queued"), SENT("sent"), @@ -167,44 +176,19 @@ public static Status forValue(final String value) { @JsonCreator private IpCommand( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("sim_sid") - final String simSid, - - @JsonProperty("sim_iccid") - final String simIccid, - - @JsonProperty("status") - final IpCommand.Status status, - - @JsonProperty("direction") - final IpCommand.Direction direction, - - @JsonProperty("device_ip") - final String deviceIp, - - @JsonProperty("device_port") - final Integer devicePort, - - @JsonProperty("payload_type") - final IpCommand.PayloadType payloadType, - - @JsonProperty("payload") - final String payload, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("sim_sid") final String simSid, + @JsonProperty("sim_iccid") final String simIccid, + @JsonProperty("status") final IpCommand.Status status, + @JsonProperty("direction") final IpCommand.Direction direction, + @JsonProperty("device_ip") final String deviceIp, + @JsonProperty("device_port") final Integer devicePort, + @JsonProperty("payload_type") final IpCommand.PayloadType payloadType, + @JsonProperty("payload") final String payload, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url ) { this.sid = sid; this.accountSid = accountSid; @@ -221,49 +205,61 @@ private IpCommand( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getSimSid() { - return this.simSid; - } - public final String getSimIccid() { - return this.simIccid; - } - public final IpCommand.Status getStatus() { - return this.status; - } - public final IpCommand.Direction getDirection() { - return this.direction; - } - public final String getDeviceIp() { - return this.deviceIp; - } - public final Integer getDevicePort() { - return this.devicePort; - } - public final IpCommand.PayloadType getPayloadType() { - return this.payloadType; - } - public final String getPayload() { - return this.payload; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getSimSid() { + return this.simSid; + } + + public final String getSimIccid() { + return this.simIccid; + } + + public final IpCommand.Status getStatus() { + return this.status; + } + + public final IpCommand.Direction getDirection() { + return this.direction; + } + + public final String getDeviceIp() { + return this.deviceIp; + } + + public final Integer getDevicePort() { + return this.devicePort; + } + + public final IpCommand.PayloadType getPayloadType() { + return this.payloadType; + } + + public final String getPayload() { + return this.payload; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -273,13 +269,39 @@ public boolean equals(final Object o) { IpCommand other = (IpCommand) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(simSid, other.simSid) && Objects.equals(simIccid, other.simIccid) && Objects.equals(status, other.status) && Objects.equals(direction, other.direction) && Objects.equals(deviceIp, other.deviceIp) && Objects.equals(devicePort, other.devicePort) && Objects.equals(payloadType, other.payloadType) && Objects.equals(payload, other.payload) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(simSid, other.simSid) && + Objects.equals(simIccid, other.simIccid) && + Objects.equals(status, other.status) && + Objects.equals(direction, other.direction) && + Objects.equals(deviceIp, other.deviceIp) && + Objects.equals(devicePort, other.devicePort) && + Objects.equals(payloadType, other.payloadType) && + Objects.equals(payload, other.payload) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, simSid, simIccid, status, direction, deviceIp, devicePort, payloadType, payload, dateCreated, dateUpdated, url); + return Objects.hash( + sid, + accountSid, + simSid, + simIccid, + status, + direction, + deviceIp, + devicePort, + payloadType, + payload, + dateCreated, + dateUpdated, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/supersim/v1/IpCommandCreator.java b/src/main/java/com/twilio/rest/supersim/v1/IpCommandCreator.java index e54dc28e9b..36c7ba0bce 100644 --- a/src/main/java/com/twilio/rest/supersim/v1/IpCommandCreator.java +++ b/src/main/java/com/twilio/rest/supersim/v1/IpCommandCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.supersim.v1; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -25,12 +26,10 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.net.URI; - - - import java.net.URI; -public class IpCommandCreator extends Creator{ +public class IpCommandCreator extends Creator { + private String sim; private String payload; private Integer devicePort; @@ -38,92 +37,108 @@ public class IpCommandCreator extends Creator{ private URI callbackUrl; private HttpMethod callbackMethod; - public IpCommandCreator(final String sim, final String payload, final Integer devicePort) { + public IpCommandCreator( + final String sim, + final String payload, + final Integer devicePort + ) { this.sim = sim; this.payload = payload; this.devicePort = devicePort; } - public IpCommandCreator setSim(final String sim){ + public IpCommandCreator setSim(final String sim) { this.sim = sim; return this; } - public IpCommandCreator setPayload(final String payload){ + + public IpCommandCreator setPayload(final String payload) { this.payload = payload; return this; } - public IpCommandCreator setDevicePort(final Integer devicePort){ + + public IpCommandCreator setDevicePort(final Integer devicePort) { this.devicePort = devicePort; return this; } - public IpCommandCreator setPayloadType(final IpCommand.PayloadType payloadType){ + + public IpCommandCreator setPayloadType( + final IpCommand.PayloadType payloadType + ) { this.payloadType = payloadType; return this; } - public IpCommandCreator setCallbackUrl(final URI callbackUrl){ + + public IpCommandCreator setCallbackUrl(final URI callbackUrl) { this.callbackUrl = callbackUrl; return this; } - public IpCommandCreator setCallbackUrl(final String callbackUrl){ + public IpCommandCreator setCallbackUrl(final String callbackUrl) { return setCallbackUrl(Promoter.uriFromString(callbackUrl)); } - public IpCommandCreator setCallbackMethod(final HttpMethod callbackMethod){ + + public IpCommandCreator setCallbackMethod(final HttpMethod callbackMethod) { this.callbackMethod = callbackMethod; return this; } @Override - public IpCommand create(final TwilioRestClient client){ + public IpCommand create(final TwilioRestClient client) { String path = "/v1/IpCommands"; - path = path.replace("{"+"Sim"+"}", this.sim.toString()); - path = path.replace("{"+"Payload"+"}", this.payload.toString()); - path = path.replace("{"+"DevicePort"+"}", this.devicePort.toString()); + path = path.replace("{" + "Sim" + "}", this.sim.toString()); + path = path.replace("{" + "Payload" + "}", this.payload.toString()); + path = + path.replace("{" + "DevicePort" + "}", this.devicePort.toString()); Request request = new Request( HttpMethod.POST, Domains.SUPERSIM.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("IpCommand creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "IpCommand creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return IpCommand.fromJson(response.getStream(), client.getObjectMapper()); + return IpCommand.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (sim != null) { request.addPostParam("Sim", sim); - } if (payload != null) { request.addPostParam("Payload", payload); - } if (devicePort != null) { request.addPostParam("DevicePort", devicePort.toString()); - } if (payloadType != null) { request.addPostParam("PayloadType", payloadType.toString()); - } if (callbackUrl != null) { request.addPostParam("CallbackUrl", callbackUrl.toString()); - } if (callbackMethod != null) { request.addPostParam("CallbackMethod", callbackMethod.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/supersim/v1/IpCommandFetcher.java b/src/main/java/com/twilio/rest/supersim/v1/IpCommandFetcher.java index 0383533bcf..628005f15d 100644 --- a/src/main/java/com/twilio/rest/supersim/v1/IpCommandFetcher.java +++ b/src/main/java/com/twilio/rest/supersim/v1/IpCommandFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class IpCommandFetcher extends Fetcher { + private String pathSid; - public IpCommandFetcher(final String pathSid){ + public IpCommandFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public IpCommand fetch(final TwilioRestClient client) { String path = "/v1/IpCommands/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,15 +46,23 @@ public IpCommand fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("IpCommand fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "IpCommand fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return IpCommand.fromJson(response.getStream(), client.getObjectMapper()); + return IpCommand.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/supersim/v1/IpCommandReader.java b/src/main/java/com/twilio/rest/supersim/v1/IpCommandReader.java index 6702edc6ec..9b866768f2 100644 --- a/src/main/java/com/twilio/rest/supersim/v1/IpCommandReader.java +++ b/src/main/java/com/twilio/rest/supersim/v1/IpCommandReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.supersim.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,37 +25,38 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class IpCommandReader extends Reader { + private String sim; private String simIccid; private IpCommand.Status status; private IpCommand.Direction direction; private Integer pageSize; - public IpCommandReader(){ - } + public IpCommandReader() {} - public IpCommandReader setSim(final String sim){ + public IpCommandReader setSim(final String sim) { this.sim = sim; return this; } - public IpCommandReader setSimIccid(final String simIccid){ + + public IpCommandReader setSimIccid(final String simIccid) { this.simIccid = simIccid; return this; } - public IpCommandReader setStatus(final IpCommand.Status status){ + + public IpCommandReader setStatus(final IpCommand.Status status) { this.status = status; return this; } - public IpCommandReader setDirection(final IpCommand.Direction direction){ + + public IpCommandReader setDirection(final IpCommand.Direction direction) { this.direction = direction; return this; } - public IpCommandReader setPageSize(final Integer pageSize){ + + public IpCommandReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -77,13 +79,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("IpCommand read failed: Unable to connect to server"); + throw new ApiConnectionException( + "IpCommand read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -99,7 +109,10 @@ private Page pageForRequest(final TwilioRestClient client, final Requ } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.SUPERSIM.toString()) @@ -107,9 +120,11 @@ public Page previousPage(final Page page, final TwilioRest return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.SUPERSIM.toString()) @@ -118,37 +133,33 @@ public Page nextPage(final Page page, final TwilioRestClie } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (sim != null) { - request.addQueryParam("Sim", sim); } if (simIccid != null) { - request.addQueryParam("SimIccid", simIccid); } if (status != null) { - request.addQueryParam("Status", status.toString()); } if (direction != null) { - request.addQueryParam("Direction", direction.toString()); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/supersim/v1/Network.java b/src/main/java/com/twilio/rest/supersim/v1/Network.java index 80d73e69d7..3b01f564d8 100644 --- a/src/main/java/com/twilio/rest/supersim/v1/Network.java +++ b/src/main/java/com/twilio/rest/supersim/v1/Network.java @@ -22,43 +22,42 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.List; import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Network extends Resource { + private static final long serialVersionUID = 225839080791216L; - public static NetworkFetcher fetcher(final String pathSid){ + public static NetworkFetcher fetcher(final String pathSid) { return new NetworkFetcher(pathSid); } - public static NetworkReader reader(){ + public static NetworkReader reader() { return new NetworkReader(); } /** - * Converts a JSON String into a Network object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Network object represented by the provided JSON - */ - public static Network fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Network object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Network object represented by the provided JSON + */ + public static Network fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Network.class); @@ -70,14 +69,17 @@ public static Network fromJson(final String json, final ObjectMapper objectMappe } /** - * Converts a JSON InputStream into a Network object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Network object represented by the provided JSON - */ - public static Network fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Network object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Network object represented by the provided JSON + */ + public static Network fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Network.class); @@ -96,20 +98,11 @@ public static Network fromJson(final InputStream json, final ObjectMapper object @JsonCreator private Network( - @JsonProperty("sid") - final String sid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("url") - final URI url, - - @JsonProperty("iso_country") - final String isoCountry, - - @JsonProperty("identifiers") - final List> identifiers + @JsonProperty("sid") final String sid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("url") final URI url, + @JsonProperty("iso_country") final String isoCountry, + @JsonProperty("identifiers") final List> identifiers ) { this.sid = sid; this.friendlyName = friendlyName; @@ -118,25 +111,29 @@ private Network( this.identifiers = identifiers; } - public final String getSid() { - return this.sid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final URI getUrl() { - return this.url; - } - public final String getIsoCountry() { - return this.isoCountry; - } - public final List> getIdentifiers() { - return this.identifiers; - } + public final String getSid() { + return this.sid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final URI getUrl() { + return this.url; + } + + public final String getIsoCountry() { + return this.isoCountry; + } + + public final List> getIdentifiers() { + return this.identifiers; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -146,13 +143,17 @@ public boolean equals(final Object o) { Network other = (Network) o; - return Objects.equals(sid, other.sid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(url, other.url) && Objects.equals(isoCountry, other.isoCountry) && Objects.equals(identifiers, other.identifiers) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(url, other.url) && + Objects.equals(isoCountry, other.isoCountry) && + Objects.equals(identifiers, other.identifiers) + ); } @Override public int hashCode() { return Objects.hash(sid, friendlyName, url, isoCountry, identifiers); } - } - diff --git a/src/main/java/com/twilio/rest/supersim/v1/NetworkAccessProfile.java b/src/main/java/com/twilio/rest/supersim/v1/NetworkAccessProfile.java index 5053a9bb92..75ea177302 100644 --- a/src/main/java/com/twilio/rest/supersim/v1/NetworkAccessProfile.java +++ b/src/main/java/com/twilio/rest/supersim/v1/NetworkAccessProfile.java @@ -23,51 +23,50 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class NetworkAccessProfile extends Resource { + private static final long serialVersionUID = 19374980019913L; - public static NetworkAccessProfileCreator creator(){ + public static NetworkAccessProfileCreator creator() { return new NetworkAccessProfileCreator(); } - public static NetworkAccessProfileFetcher fetcher(final String pathSid){ + public static NetworkAccessProfileFetcher fetcher(final String pathSid) { return new NetworkAccessProfileFetcher(pathSid); } - public static NetworkAccessProfileReader reader(){ + public static NetworkAccessProfileReader reader() { return new NetworkAccessProfileReader(); } - public static NetworkAccessProfileUpdater updater(final String pathSid){ + public static NetworkAccessProfileUpdater updater(final String pathSid) { return new NetworkAccessProfileUpdater(pathSid); } /** - * Converts a JSON String into a NetworkAccessProfile object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return NetworkAccessProfile object represented by the provided JSON - */ - public static NetworkAccessProfile fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a NetworkAccessProfile object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return NetworkAccessProfile object represented by the provided JSON + */ + public static NetworkAccessProfile fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, NetworkAccessProfile.class); @@ -79,14 +78,17 @@ public static NetworkAccessProfile fromJson(final String json, final ObjectMappe } /** - * Converts a JSON InputStream into a NetworkAccessProfile object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return NetworkAccessProfile object represented by the provided JSON - */ - public static NetworkAccessProfile fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a NetworkAccessProfile object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return NetworkAccessProfile object represented by the provided JSON + */ + public static NetworkAccessProfile fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, NetworkAccessProfile.class); @@ -107,26 +109,13 @@ public static NetworkAccessProfile fromJson(final InputStream json, final Object @JsonCreator private NetworkAccessProfile( - @JsonProperty("sid") - final String sid, - - @JsonProperty("unique_name") - final String uniqueName, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("sid") final String sid, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.sid = sid; this.uniqueName = uniqueName; @@ -137,31 +126,37 @@ private NetworkAccessProfile( this.links = links; } - public final String getSid() { - return this.sid; - } - public final String getUniqueName() { - return this.uniqueName; - } - public final String getAccountSid() { - return this.accountSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getSid() { + return this.sid; + } + + public final String getUniqueName() { + return this.uniqueName; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -171,13 +166,27 @@ public boolean equals(final Object o) { NetworkAccessProfile other = (NetworkAccessProfile) o; - return Objects.equals(sid, other.sid) && Objects.equals(uniqueName, other.uniqueName) && Objects.equals(accountSid, other.accountSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(sid, uniqueName, accountSid, dateCreated, dateUpdated, url, links); + return Objects.hash( + sid, + uniqueName, + accountSid, + dateCreated, + dateUpdated, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/supersim/v1/NetworkAccessProfileCreator.java b/src/main/java/com/twilio/rest/supersim/v1/NetworkAccessProfileCreator.java index f0b200b037..95699a4468 100644 --- a/src/main/java/com/twilio/rest/supersim/v1/NetworkAccessProfileCreator.java +++ b/src/main/java/com/twilio/rest/supersim/v1/NetworkAccessProfileCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.supersim.v1; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -25,64 +26,72 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.util.List; - import java.util.List; +public class NetworkAccessProfileCreator extends Creator { - -public class NetworkAccessProfileCreator extends Creator{ private String uniqueName; private List networks; - public NetworkAccessProfileCreator() { - } + public NetworkAccessProfileCreator() {} - public NetworkAccessProfileCreator setUniqueName(final String uniqueName){ + public NetworkAccessProfileCreator setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - public NetworkAccessProfileCreator setNetworks(final List networks){ + + public NetworkAccessProfileCreator setNetworks( + final List networks + ) { this.networks = networks; return this; } - public NetworkAccessProfileCreator setNetworks(final String networks){ + + public NetworkAccessProfileCreator setNetworks(final String networks) { return setNetworks(Promoter.listOfOne(networks)); } @Override - public NetworkAccessProfile create(final TwilioRestClient client){ + public NetworkAccessProfile create(final TwilioRestClient client) { String path = "/v1/NetworkAccessProfiles"; - Request request = new Request( HttpMethod.POST, Domains.SUPERSIM.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("NetworkAccessProfile creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "NetworkAccessProfile creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return NetworkAccessProfile.fromJson(response.getStream(), client.getObjectMapper()); + return NetworkAccessProfile.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (uniqueName != null) { request.addPostParam("UniqueName", uniqueName); - } if (networks != null) { for (String prop : networks) { request.addPostParam("Networks", prop); } - } } } diff --git a/src/main/java/com/twilio/rest/supersim/v1/NetworkAccessProfileFetcher.java b/src/main/java/com/twilio/rest/supersim/v1/NetworkAccessProfileFetcher.java index 87e4e24329..f8c7fa559e 100644 --- a/src/main/java/com/twilio/rest/supersim/v1/NetworkAccessProfileFetcher.java +++ b/src/main/java/com/twilio/rest/supersim/v1/NetworkAccessProfileFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class NetworkAccessProfileFetcher extends Fetcher { + private String pathSid; - public NetworkAccessProfileFetcher(final String pathSid){ + public NetworkAccessProfileFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public NetworkAccessProfile fetch(final TwilioRestClient client) { String path = "/v1/NetworkAccessProfiles/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,15 +46,23 @@ public NetworkAccessProfile fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("NetworkAccessProfile fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "NetworkAccessProfile fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return NetworkAccessProfile.fromJson(response.getStream(), client.getObjectMapper()); + return NetworkAccessProfile.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/supersim/v1/NetworkAccessProfileReader.java b/src/main/java/com/twilio/rest/supersim/v1/NetworkAccessProfileReader.java index 15111170f5..037031752e 100644 --- a/src/main/java/com/twilio/rest/supersim/v1/NetworkAccessProfileReader.java +++ b/src/main/java/com/twilio/rest/supersim/v1/NetworkAccessProfileReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.supersim.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,23 +25,22 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class NetworkAccessProfileReader extends Reader { + private Integer pageSize; - public NetworkAccessProfileReader(){ - } + public NetworkAccessProfileReader() {} - public NetworkAccessProfileReader setPageSize(final Integer pageSize){ + public NetworkAccessProfileReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @Override - public ResourceSet read(final TwilioRestClient client) { + public ResourceSet read( + final TwilioRestClient client + ) { return new ResourceSet<>(this, client, firstPage(client)); } @@ -57,13 +57,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("NetworkAccessProfile read failed: Unable to connect to server"); + throw new ApiConnectionException( + "NetworkAccessProfile read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -79,7 +87,10 @@ private Page pageForRequest(final TwilioRestClient client, } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.SUPERSIM.toString()) @@ -87,9 +98,11 @@ public Page previousPage(final Page return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.SUPERSIM.toString()) @@ -98,21 +111,21 @@ public Page nextPage(final Page page } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/supersim/v1/NetworkAccessProfileUpdater.java b/src/main/java/com/twilio/rest/supersim/v1/NetworkAccessProfileUpdater.java index 82d6bed880..eed489a622 100644 --- a/src/main/java/com/twilio/rest/supersim/v1/NetworkAccessProfileUpdater.java +++ b/src/main/java/com/twilio/rest/supersim/v1/NetworkAccessProfileUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.supersim.v1; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,51 +25,58 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class NetworkAccessProfileUpdater extends Updater { - - -public class NetworkAccessProfileUpdater extends Updater{ private String pathSid; private String uniqueName; - public NetworkAccessProfileUpdater(final String pathSid){ + public NetworkAccessProfileUpdater(final String pathSid) { this.pathSid = pathSid; } - public NetworkAccessProfileUpdater setUniqueName(final String uniqueName){ + public NetworkAccessProfileUpdater setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } @Override - public NetworkAccessProfile update(final TwilioRestClient client){ + public NetworkAccessProfile update(final TwilioRestClient client) { String path = "/v1/NetworkAccessProfiles/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.SUPERSIM.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("NetworkAccessProfile update failed: Unable to connect to server"); + throw new ApiConnectionException( + "NetworkAccessProfile update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return NetworkAccessProfile.fromJson(response.getStream(), client.getObjectMapper()); + return NetworkAccessProfile.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (uniqueName != null) { request.addPostParam("UniqueName", uniqueName); - } } } diff --git a/src/main/java/com/twilio/rest/supersim/v1/NetworkFetcher.java b/src/main/java/com/twilio/rest/supersim/v1/NetworkFetcher.java index b1e5be475e..5cd0b4610e 100644 --- a/src/main/java/com/twilio/rest/supersim/v1/NetworkFetcher.java +++ b/src/main/java/com/twilio/rest/supersim/v1/NetworkFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class NetworkFetcher extends Fetcher { + private String pathSid; - public NetworkFetcher(final String pathSid){ + public NetworkFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public Network fetch(final TwilioRestClient client) { String path = "/v1/Networks/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,9 +46,14 @@ public Network fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Network fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Network fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/supersim/v1/NetworkReader.java b/src/main/java/com/twilio/rest/supersim/v1/NetworkReader.java index dea37a05b3..459458ae38 100644 --- a/src/main/java/com/twilio/rest/supersim/v1/NetworkReader.java +++ b/src/main/java/com/twilio/rest/supersim/v1/NetworkReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.supersim.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,32 +25,32 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class NetworkReader extends Reader { + private String isoCountry; private String mcc; private String mnc; private Integer pageSize; - public NetworkReader(){ - } + public NetworkReader() {} - public NetworkReader setIsoCountry(final String isoCountry){ + public NetworkReader setIsoCountry(final String isoCountry) { this.isoCountry = isoCountry; return this; } - public NetworkReader setMcc(final String mcc){ + + public NetworkReader setMcc(final String mcc) { this.mcc = mcc; return this; } - public NetworkReader setMnc(final String mnc){ + + public NetworkReader setMnc(final String mnc) { this.mnc = mnc; return this; } - public NetworkReader setPageSize(final Integer pageSize){ + + public NetworkReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -72,13 +73,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Network read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Network read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -94,7 +103,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reques } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.SUPERSIM.toString()) @@ -102,9 +114,11 @@ public Page previousPage(final Page page, final TwilioRestClie return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.SUPERSIM.toString()) @@ -113,33 +127,30 @@ public Page nextPage(final Page page, final TwilioRestClient c } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (isoCountry != null) { - request.addQueryParam("IsoCountry", isoCountry); } if (mcc != null) { - request.addQueryParam("Mcc", mcc); } if (mnc != null) { - request.addQueryParam("Mnc", mnc); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/supersim/v1/SettingsUpdate.java b/src/main/java/com/twilio/rest/supersim/v1/SettingsUpdate.java index 2a6dce4633..02175c2157 100644 --- a/src/main/java/com/twilio/rest/supersim/v1/SettingsUpdate.java +++ b/src/main/java/com/twilio/rest/supersim/v1/SettingsUpdate.java @@ -24,39 +24,38 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.time.ZonedDateTime; - import java.util.List; import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class SettingsUpdate extends Resource { + private static final long serialVersionUID = 126256874693410L; - public static SettingsUpdateReader reader(){ + public static SettingsUpdateReader reader() { return new SettingsUpdateReader(); } /** - * Converts a JSON String into a SettingsUpdate object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return SettingsUpdate object represented by the provided JSON - */ - public static SettingsUpdate fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a SettingsUpdate object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return SettingsUpdate object represented by the provided JSON + */ + public static SettingsUpdate fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SettingsUpdate.class); @@ -68,14 +67,17 @@ public static SettingsUpdate fromJson(final String json, final ObjectMapper obje } /** - * Converts a JSON InputStream into a SettingsUpdate object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return SettingsUpdate object represented by the provided JSON - */ - public static SettingsUpdate fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a SettingsUpdate object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return SettingsUpdate object represented by the provided JSON + */ + public static SettingsUpdate fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SettingsUpdate.class); @@ -85,6 +87,7 @@ public static SettingsUpdate fromJson(final InputStream json, final ObjectMapper throw new ApiConnectionException(e.getMessage(), e); } } + public enum Status { SCHEDULED("scheduled"), IN_PROGRESS("in-progress"), @@ -118,68 +121,61 @@ public static Status forValue(final String value) { @JsonCreator private SettingsUpdate( - @JsonProperty("sid") - final String sid, - - @JsonProperty("iccid") - final String iccid, - - @JsonProperty("sim_sid") - final String simSid, - - @JsonProperty("status") - final SettingsUpdate.Status status, - - @JsonProperty("packages") - final List> packages, - - @JsonProperty("date_completed") - final String dateCompleted, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated + @JsonProperty("sid") final String sid, + @JsonProperty("iccid") final String iccid, + @JsonProperty("sim_sid") final String simSid, + @JsonProperty("status") final SettingsUpdate.Status status, + @JsonProperty("packages") final List> packages, + @JsonProperty("date_completed") final String dateCompleted, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated ) { this.sid = sid; this.iccid = iccid; this.simSid = simSid; this.status = status; this.packages = packages; - this.dateCompleted = DateConverter.iso8601DateTimeFromString(dateCompleted); + this.dateCompleted = + DateConverter.iso8601DateTimeFromString(dateCompleted); this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); } - public final String getSid() { - return this.sid; - } - public final String getIccid() { - return this.iccid; - } - public final String getSimSid() { - return this.simSid; - } - public final SettingsUpdate.Status getStatus() { - return this.status; - } - public final List> getPackages() { - return this.packages; - } - public final ZonedDateTime getDateCompleted() { - return this.dateCompleted; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } + public final String getSid() { + return this.sid; + } + + public final String getIccid() { + return this.iccid; + } + + public final String getSimSid() { + return this.simSid; + } + + public final SettingsUpdate.Status getStatus() { + return this.status; + } + + public final List> getPackages() { + return this.packages; + } + + public final ZonedDateTime getDateCompleted() { + return this.dateCompleted; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -189,13 +185,29 @@ public boolean equals(final Object o) { SettingsUpdate other = (SettingsUpdate) o; - return Objects.equals(sid, other.sid) && Objects.equals(iccid, other.iccid) && Objects.equals(simSid, other.simSid) && Objects.equals(status, other.status) && Objects.equals(packages, other.packages) && Objects.equals(dateCompleted, other.dateCompleted) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(iccid, other.iccid) && + Objects.equals(simSid, other.simSid) && + Objects.equals(status, other.status) && + Objects.equals(packages, other.packages) && + Objects.equals(dateCompleted, other.dateCompleted) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) + ); } @Override public int hashCode() { - return Objects.hash(sid, iccid, simSid, status, packages, dateCompleted, dateCreated, dateUpdated); + return Objects.hash( + sid, + iccid, + simSid, + status, + packages, + dateCompleted, + dateCreated, + dateUpdated + ); } - } - diff --git a/src/main/java/com/twilio/rest/supersim/v1/SettingsUpdateReader.java b/src/main/java/com/twilio/rest/supersim/v1/SettingsUpdateReader.java index 174de0f1ba..243e98d1ce 100644 --- a/src/main/java/com/twilio/rest/supersim/v1/SettingsUpdateReader.java +++ b/src/main/java/com/twilio/rest/supersim/v1/SettingsUpdateReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.supersim.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,27 +25,26 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class SettingsUpdateReader extends Reader { + private String sim; private SettingsUpdate.Status status; private Integer pageSize; - public SettingsUpdateReader(){ - } + public SettingsUpdateReader() {} - public SettingsUpdateReader setSim(final String sim){ + public SettingsUpdateReader setSim(final String sim) { this.sim = sim; return this; } - public SettingsUpdateReader setStatus(final SettingsUpdate.Status status){ + + public SettingsUpdateReader setStatus(final SettingsUpdate.Status status) { this.status = status; return this; } - public SettingsUpdateReader setPageSize(final Integer pageSize){ + + public SettingsUpdateReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -67,13 +67,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SettingsUpdate read failed: Unable to connect to server"); + throw new ApiConnectionException( + "SettingsUpdate read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -89,7 +97,10 @@ private Page pageForRequest(final TwilioRestClient client, final } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.SUPERSIM.toString()) @@ -97,9 +108,11 @@ public Page previousPage(final Page page, final return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.SUPERSIM.toString()) @@ -108,29 +121,27 @@ public Page nextPage(final Page page, final Twil } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (sim != null) { - request.addQueryParam("Sim", sim); } if (status != null) { - request.addQueryParam("Status", status.toString()); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/supersim/v1/Sim.java b/src/main/java/com/twilio/rest/supersim/v1/Sim.java index 6e6ea32136..cee62e5167 100644 --- a/src/main/java/com/twilio/rest/supersim/v1/Sim.java +++ b/src/main/java/com/twilio/rest/supersim/v1/Sim.java @@ -24,51 +24,53 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Sim extends Resource { + private static final long serialVersionUID = 28875728882839L; - public static SimCreator creator(final String iccid, final String registrationCode){ + public static SimCreator creator( + final String iccid, + final String registrationCode + ) { return new SimCreator(iccid, registrationCode); } - public static SimFetcher fetcher(final String pathSid){ + public static SimFetcher fetcher(final String pathSid) { return new SimFetcher(pathSid); } - public static SimReader reader(){ + public static SimReader reader() { return new SimReader(); } - public static SimUpdater updater(final String pathSid){ + public static SimUpdater updater(final String pathSid) { return new SimUpdater(pathSid); } /** - * Converts a JSON String into a Sim object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Sim object represented by the provided JSON - */ - public static Sim fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Sim object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Sim object represented by the provided JSON + */ + public static Sim fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Sim.class); @@ -80,14 +82,17 @@ public static Sim fromJson(final String json, final ObjectMapper objectMapper) { } /** - * Converts a JSON InputStream into a Sim object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Sim object represented by the provided JSON - */ - public static Sim fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Sim object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Sim object represented by the provided JSON + */ + public static Sim fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Sim.class); @@ -97,6 +102,7 @@ public static Sim fromJson(final InputStream json, final ObjectMapper objectMapp throw new ApiConnectionException(e.getMessage(), e); } } + public enum Status { NEW("new"), READY("ready"), @@ -119,6 +125,7 @@ public static Status forValue(final String value) { return Promoter.enumFromString(value, Status.values()); } } + public enum StatusUpdate { READY("ready"), ACTIVE("active"), @@ -153,35 +160,16 @@ public static StatusUpdate forValue(final String value) { @JsonCreator private Sim( - @JsonProperty("sid") - final String sid, - - @JsonProperty("unique_name") - final String uniqueName, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("iccid") - final String iccid, - - @JsonProperty("status") - final Sim.Status status, - - @JsonProperty("fleet_sid") - final String fleetSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("sid") final String sid, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("iccid") final String iccid, + @JsonProperty("status") final Sim.Status status, + @JsonProperty("fleet_sid") final String fleetSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.sid = sid; this.uniqueName = uniqueName; @@ -195,40 +183,49 @@ private Sim( this.links = links; } - public final String getSid() { - return this.sid; - } - public final String getUniqueName() { - return this.uniqueName; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getIccid() { - return this.iccid; - } - public final Sim.Status getStatus() { - return this.status; - } - public final String getFleetSid() { - return this.fleetSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getSid() { + return this.sid; + } + + public final String getUniqueName() { + return this.uniqueName; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getIccid() { + return this.iccid; + } + + public final Sim.Status getStatus() { + return this.status; + } + + public final String getFleetSid() { + return this.fleetSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -238,13 +235,33 @@ public boolean equals(final Object o) { Sim other = (Sim) o; - return Objects.equals(sid, other.sid) && Objects.equals(uniqueName, other.uniqueName) && Objects.equals(accountSid, other.accountSid) && Objects.equals(iccid, other.iccid) && Objects.equals(status, other.status) && Objects.equals(fleetSid, other.fleetSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(iccid, other.iccid) && + Objects.equals(status, other.status) && + Objects.equals(fleetSid, other.fleetSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(sid, uniqueName, accountSid, iccid, status, fleetSid, dateCreated, dateUpdated, url, links); + return Objects.hash( + sid, + uniqueName, + accountSid, + iccid, + status, + fleetSid, + dateCreated, + dateUpdated, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/supersim/v1/SimCreator.java b/src/main/java/com/twilio/rest/supersim/v1/SimCreator.java index 5c122382fe..dcff6c0f82 100644 --- a/src/main/java/com/twilio/rest/supersim/v1/SimCreator.java +++ b/src/main/java/com/twilio/rest/supersim/v1/SimCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.supersim.v1; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class SimCreator extends Creator { - - -public class SimCreator extends Creator{ private String iccid; private String registrationCode; @@ -36,33 +35,44 @@ public SimCreator(final String iccid, final String registrationCode) { this.registrationCode = registrationCode; } - public SimCreator setIccid(final String iccid){ + public SimCreator setIccid(final String iccid) { this.iccid = iccid; return this; } - public SimCreator setRegistrationCode(final String registrationCode){ + + public SimCreator setRegistrationCode(final String registrationCode) { this.registrationCode = registrationCode; return this; } @Override - public Sim create(final TwilioRestClient client){ + public Sim create(final TwilioRestClient client) { String path = "/v1/Sims"; - path = path.replace("{"+"Iccid"+"}", this.iccid.toString()); - path = path.replace("{"+"RegistrationCode"+"}", this.registrationCode.toString()); + path = path.replace("{" + "Iccid" + "}", this.iccid.toString()); + path = + path.replace( + "{" + "RegistrationCode" + "}", + this.registrationCode.toString() + ); Request request = new Request( HttpMethod.POST, Domains.SUPERSIM.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Sim creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Sim creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -71,14 +81,13 @@ public Sim create(final TwilioRestClient client){ return Sim.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (iccid != null) { request.addPostParam("Iccid", iccid); - } if (registrationCode != null) { request.addPostParam("RegistrationCode", registrationCode); - } } } diff --git a/src/main/java/com/twilio/rest/supersim/v1/SimFetcher.java b/src/main/java/com/twilio/rest/supersim/v1/SimFetcher.java index da0f2c4458..ece68185f7 100644 --- a/src/main/java/com/twilio/rest/supersim/v1/SimFetcher.java +++ b/src/main/java/com/twilio/rest/supersim/v1/SimFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class SimFetcher extends Fetcher { + private String pathSid; - public SimFetcher(final String pathSid){ + public SimFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public Sim fetch(final TwilioRestClient client) { String path = "/v1/Sims/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,9 +46,14 @@ public Sim fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Sim fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Sim fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/supersim/v1/SimReader.java b/src/main/java/com/twilio/rest/supersim/v1/SimReader.java index b149c08dc5..bab3cc31f8 100644 --- a/src/main/java/com/twilio/rest/supersim/v1/SimReader.java +++ b/src/main/java/com/twilio/rest/supersim/v1/SimReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.supersim.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,32 +25,32 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class SimReader extends Reader { + private Sim.Status status; private String fleet; private String iccid; private Integer pageSize; - public SimReader(){ - } + public SimReader() {} - public SimReader setStatus(final Sim.Status status){ + public SimReader setStatus(final Sim.Status status) { this.status = status; return this; } - public SimReader setFleet(final String fleet){ + + public SimReader setFleet(final String fleet) { this.fleet = fleet; return this; } - public SimReader setIccid(final String iccid){ + + public SimReader setIccid(final String iccid) { this.iccid = iccid; return this; } - public SimReader setPageSize(final Integer pageSize){ + + public SimReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -72,13 +73,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Sim read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Sim read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -94,7 +103,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request re } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.SUPERSIM.toString()) @@ -102,9 +114,11 @@ public Page previousPage(final Page page, final TwilioRestClient clien return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.SUPERSIM.toString()) @@ -113,33 +127,30 @@ public Page nextPage(final Page page, final TwilioRestClient client) { } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (status != null) { - request.addQueryParam("Status", status.toString()); } if (fleet != null) { - request.addQueryParam("Fleet", fleet); } if (iccid != null) { - request.addQueryParam("Iccid", iccid); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/supersim/v1/SimUpdater.java b/src/main/java/com/twilio/rest/supersim/v1/SimUpdater.java index b98d6557bc..8b20c689b0 100644 --- a/src/main/java/com/twilio/rest/supersim/v1/SimUpdater.java +++ b/src/main/java/com/twilio/rest/supersim/v1/SimUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.supersim.v1; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -24,12 +25,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.net.URI; +public class SimUpdater extends Updater { - -public class SimUpdater extends Updater{ private String pathSid; private String uniqueName; private Sim.StatusUpdate status; @@ -38,56 +37,67 @@ public class SimUpdater extends Updater{ private HttpMethod callbackMethod; private String accountSid; - public SimUpdater(final String pathSid){ + public SimUpdater(final String pathSid) { this.pathSid = pathSid; } - public SimUpdater setUniqueName(final String uniqueName){ + public SimUpdater setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - public SimUpdater setStatus(final Sim.StatusUpdate status){ + + public SimUpdater setStatus(final Sim.StatusUpdate status) { this.status = status; return this; } - public SimUpdater setFleet(final String fleet){ + + public SimUpdater setFleet(final String fleet) { this.fleet = fleet; return this; } - public SimUpdater setCallbackUrl(final URI callbackUrl){ + + public SimUpdater setCallbackUrl(final URI callbackUrl) { this.callbackUrl = callbackUrl; return this; } - public SimUpdater setCallbackUrl(final String callbackUrl){ + public SimUpdater setCallbackUrl(final String callbackUrl) { return setCallbackUrl(Promoter.uriFromString(callbackUrl)); } - public SimUpdater setCallbackMethod(final HttpMethod callbackMethod){ + + public SimUpdater setCallbackMethod(final HttpMethod callbackMethod) { this.callbackMethod = callbackMethod; return this; } - public SimUpdater setAccountSid(final String accountSid){ + + public SimUpdater setAccountSid(final String accountSid) { this.accountSid = accountSid; return this; } @Override - public Sim update(final TwilioRestClient client){ + public Sim update(final TwilioRestClient client) { String path = "/v1/Sims/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.SUPERSIM.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Sim update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Sim update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -96,30 +106,25 @@ public Sim update(final TwilioRestClient client){ return Sim.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (uniqueName != null) { request.addPostParam("UniqueName", uniqueName); - } if (status != null) { request.addPostParam("Status", status.toString()); - } if (fleet != null) { request.addPostParam("Fleet", fleet); - } if (callbackUrl != null) { request.addPostParam("CallbackUrl", callbackUrl.toString()); - } if (callbackMethod != null) { request.addPostParam("CallbackMethod", callbackMethod.toString()); - } if (accountSid != null) { request.addPostParam("AccountSid", accountSid); - } } } diff --git a/src/main/java/com/twilio/rest/supersim/v1/SmsCommand.java b/src/main/java/com/twilio/rest/supersim/v1/SmsCommand.java index 019d03ec54..2e42b6119b 100644 --- a/src/main/java/com/twilio/rest/supersim/v1/SmsCommand.java +++ b/src/main/java/com/twilio/rest/supersim/v1/SmsCommand.java @@ -24,45 +24,47 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class SmsCommand extends Resource { + private static final long serialVersionUID = 38007963555299L; - public static SmsCommandCreator creator(final String sim, final String payload){ + public static SmsCommandCreator creator( + final String sim, + final String payload + ) { return new SmsCommandCreator(sim, payload); } - public static SmsCommandFetcher fetcher(final String pathSid){ + public static SmsCommandFetcher fetcher(final String pathSid) { return new SmsCommandFetcher(pathSid); } - public static SmsCommandReader reader(){ + public static SmsCommandReader reader() { return new SmsCommandReader(); } /** - * Converts a JSON String into a SmsCommand object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return SmsCommand object represented by the provided JSON - */ - public static SmsCommand fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a SmsCommand object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return SmsCommand object represented by the provided JSON + */ + public static SmsCommand fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SmsCommand.class); @@ -74,14 +76,17 @@ public static SmsCommand fromJson(final String json, final ObjectMapper objectMa } /** - * Converts a JSON InputStream into a SmsCommand object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return SmsCommand object represented by the provided JSON - */ - public static SmsCommand fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a SmsCommand object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return SmsCommand object represented by the provided JSON + */ + public static SmsCommand fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SmsCommand.class); @@ -91,6 +96,7 @@ public static SmsCommand fromJson(final InputStream json, final ObjectMapper obj throw new ApiConnectionException(e.getMessage(), e); } } + public enum Direction { TO_SIM("to_sim"), FROM_SIM("from_sim"); @@ -110,6 +116,7 @@ public static Direction forValue(final String value) { return Promoter.enumFromString(value, Direction.values()); } } + public enum Status { QUEUED("queued"), SENT("sent"), @@ -145,32 +152,15 @@ public static Status forValue(final String value) { @JsonCreator private SmsCommand( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("sim_sid") - final String simSid, - - @JsonProperty("payload") - final String payload, - - @JsonProperty("status") - final SmsCommand.Status status, - - @JsonProperty("direction") - final SmsCommand.Direction direction, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("sim_sid") final String simSid, + @JsonProperty("payload") final String payload, + @JsonProperty("status") final SmsCommand.Status status, + @JsonProperty("direction") final SmsCommand.Direction direction, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url ) { this.sid = sid; this.accountSid = accountSid; @@ -183,37 +173,45 @@ private SmsCommand( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getSimSid() { - return this.simSid; - } - public final String getPayload() { - return this.payload; - } - public final SmsCommand.Status getStatus() { - return this.status; - } - public final SmsCommand.Direction getDirection() { - return this.direction; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getSimSid() { + return this.simSid; + } + + public final String getPayload() { + return this.payload; + } + + public final SmsCommand.Status getStatus() { + return this.status; + } + + public final SmsCommand.Direction getDirection() { + return this.direction; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -223,13 +221,31 @@ public boolean equals(final Object o) { SmsCommand other = (SmsCommand) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(simSid, other.simSid) && Objects.equals(payload, other.payload) && Objects.equals(status, other.status) && Objects.equals(direction, other.direction) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(simSid, other.simSid) && + Objects.equals(payload, other.payload) && + Objects.equals(status, other.status) && + Objects.equals(direction, other.direction) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, simSid, payload, status, direction, dateCreated, dateUpdated, url); + return Objects.hash( + sid, + accountSid, + simSid, + payload, + status, + direction, + dateCreated, + dateUpdated, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/supersim/v1/SmsCommandCreator.java b/src/main/java/com/twilio/rest/supersim/v1/SmsCommandCreator.java index ac14540159..4a2fecc793 100644 --- a/src/main/java/com/twilio/rest/supersim/v1/SmsCommandCreator.java +++ b/src/main/java/com/twilio/rest/supersim/v1/SmsCommandCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.supersim.v1; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -25,12 +26,10 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.net.URI; - - - import java.net.URI; -public class SmsCommandCreator extends Creator{ +public class SmsCommandCreator extends Creator { + private String sim; private String payload; private HttpMethod callbackMethod; @@ -41,69 +40,80 @@ public SmsCommandCreator(final String sim, final String payload) { this.payload = payload; } - public SmsCommandCreator setSim(final String sim){ + public SmsCommandCreator setSim(final String sim) { this.sim = sim; return this; } - public SmsCommandCreator setPayload(final String payload){ + + public SmsCommandCreator setPayload(final String payload) { this.payload = payload; return this; } - public SmsCommandCreator setCallbackMethod(final HttpMethod callbackMethod){ + + public SmsCommandCreator setCallbackMethod( + final HttpMethod callbackMethod + ) { this.callbackMethod = callbackMethod; return this; } - public SmsCommandCreator setCallbackUrl(final URI callbackUrl){ + + public SmsCommandCreator setCallbackUrl(final URI callbackUrl) { this.callbackUrl = callbackUrl; return this; } - public SmsCommandCreator setCallbackUrl(final String callbackUrl){ + public SmsCommandCreator setCallbackUrl(final String callbackUrl) { return setCallbackUrl(Promoter.uriFromString(callbackUrl)); } @Override - public SmsCommand create(final TwilioRestClient client){ + public SmsCommand create(final TwilioRestClient client) { String path = "/v1/SmsCommands"; - path = path.replace("{"+"Sim"+"}", this.sim.toString()); - path = path.replace("{"+"Payload"+"}", this.payload.toString()); + path = path.replace("{" + "Sim" + "}", this.sim.toString()); + path = path.replace("{" + "Payload" + "}", this.payload.toString()); Request request = new Request( HttpMethod.POST, Domains.SUPERSIM.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SmsCommand creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "SmsCommand creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return SmsCommand.fromJson(response.getStream(), client.getObjectMapper()); + return SmsCommand.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (sim != null) { request.addPostParam("Sim", sim); - } if (payload != null) { request.addPostParam("Payload", payload); - } if (callbackMethod != null) { request.addPostParam("CallbackMethod", callbackMethod.toString()); - } if (callbackUrl != null) { request.addPostParam("CallbackUrl", callbackUrl.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/supersim/v1/SmsCommandFetcher.java b/src/main/java/com/twilio/rest/supersim/v1/SmsCommandFetcher.java index c18170c907..c40d9fd4d8 100644 --- a/src/main/java/com/twilio/rest/supersim/v1/SmsCommandFetcher.java +++ b/src/main/java/com/twilio/rest/supersim/v1/SmsCommandFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class SmsCommandFetcher extends Fetcher { + private String pathSid; - public SmsCommandFetcher(final String pathSid){ + public SmsCommandFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public SmsCommand fetch(final TwilioRestClient client) { String path = "/v1/SmsCommands/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,15 +46,23 @@ public SmsCommand fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SmsCommand fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "SmsCommand fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return SmsCommand.fromJson(response.getStream(), client.getObjectMapper()); + return SmsCommand.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/supersim/v1/SmsCommandReader.java b/src/main/java/com/twilio/rest/supersim/v1/SmsCommandReader.java index 88f2d47362..92fd3ac9c4 100644 --- a/src/main/java/com/twilio/rest/supersim/v1/SmsCommandReader.java +++ b/src/main/java/com/twilio/rest/supersim/v1/SmsCommandReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.supersim.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,32 +25,32 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class SmsCommandReader extends Reader { + private String sim; private SmsCommand.Status status; private SmsCommand.Direction direction; private Integer pageSize; - public SmsCommandReader(){ - } + public SmsCommandReader() {} - public SmsCommandReader setSim(final String sim){ + public SmsCommandReader setSim(final String sim) { this.sim = sim; return this; } - public SmsCommandReader setStatus(final SmsCommand.Status status){ + + public SmsCommandReader setStatus(final SmsCommand.Status status) { this.status = status; return this; } - public SmsCommandReader setDirection(final SmsCommand.Direction direction){ + + public SmsCommandReader setDirection(final SmsCommand.Direction direction) { this.direction = direction; return this; } - public SmsCommandReader setPageSize(final Integer pageSize){ + + public SmsCommandReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -72,13 +73,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SmsCommand read failed: Unable to connect to server"); + throw new ApiConnectionException( + "SmsCommand read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -94,7 +103,10 @@ private Page pageForRequest(final TwilioRestClient client, final Req } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.SUPERSIM.toString()) @@ -102,9 +114,11 @@ public Page previousPage(final Page page, final TwilioRe return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.SUPERSIM.toString()) @@ -113,33 +127,30 @@ public Page nextPage(final Page page, final TwilioRestCl } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (sim != null) { - request.addQueryParam("Sim", sim); } if (status != null) { - request.addQueryParam("Status", status.toString()); } if (direction != null) { - request.addQueryParam("Direction", direction.toString()); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/supersim/v1/UsageRecord.java b/src/main/java/com/twilio/rest/supersim/v1/UsageRecord.java index 11e21d8025..49baaa2456 100644 --- a/src/main/java/com/twilio/rest/supersim/v1/UsageRecord.java +++ b/src/main/java/com/twilio/rest/supersim/v1/UsageRecord.java @@ -20,44 +20,43 @@ import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.twilio.base.Resource; -import java.util.Currency; -import com.twilio.converter.Promoter; import com.twilio.converter.CurrencyDeserializer; +import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; - +import java.math.BigDecimal; +import java.util.Currency; import java.util.Map; -import java.util.Objects; - - import java.util.Map; -import java.math.BigDecimal; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class UsageRecord extends Resource { + private static final long serialVersionUID = 269766941607639L; - public static UsageRecordReader reader(){ + public static UsageRecordReader reader() { return new UsageRecordReader(); } /** - * Converts a JSON String into a UsageRecord object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return UsageRecord object represented by the provided JSON - */ - public static UsageRecord fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a UsageRecord object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return UsageRecord object represented by the provided JSON + */ + public static UsageRecord fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, UsageRecord.class); @@ -69,14 +68,17 @@ public static UsageRecord fromJson(final String json, final ObjectMapper objectM } /** - * Converts a JSON InputStream into a UsageRecord object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return UsageRecord object represented by the provided JSON - */ - public static UsageRecord fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a UsageRecord object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return UsageRecord object represented by the provided JSON + */ + public static UsageRecord fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, UsageRecord.class); @@ -86,6 +88,7 @@ public static UsageRecord fromJson(final InputStream json, final ObjectMapper ob throw new ApiConnectionException(e.getMessage(), e); } } + public enum Granularity { HOUR("hour"), DAY("day"), @@ -106,6 +109,7 @@ public static Granularity forValue(final String value) { return Promoter.enumFromString(value, Granularity.values()); } } + public enum Group { SIM("sim"), FLEET("fleet"), @@ -142,39 +146,19 @@ public static Group forValue(final String value) { @JsonCreator private UsageRecord( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("sim_sid") - final String simSid, - - @JsonProperty("network_sid") - final String networkSid, - - @JsonProperty("fleet_sid") - final String fleetSid, - - @JsonProperty("iso_country") - final String isoCountry, - - @JsonProperty("period") - final Map period, - - @JsonProperty("data_upload") - final Long dataUpload, - - @JsonProperty("data_download") - final Long dataDownload, - - @JsonProperty("data_total") - final Long dataTotal, - - @JsonProperty("data_total_billed") - final BigDecimal dataTotalBilled, - - @JsonProperty("billed_unit") - @JsonDeserialize(using = com.twilio.converter.CurrencyDeserializer.class) - final Currency billedUnit + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("sim_sid") final String simSid, + @JsonProperty("network_sid") final String networkSid, + @JsonProperty("fleet_sid") final String fleetSid, + @JsonProperty("iso_country") final String isoCountry, + @JsonProperty("period") final Map period, + @JsonProperty("data_upload") final Long dataUpload, + @JsonProperty("data_download") final Long dataDownload, + @JsonProperty("data_total") final Long dataTotal, + @JsonProperty("data_total_billed") final BigDecimal dataTotalBilled, + @JsonProperty("billed_unit") @JsonDeserialize( + using = com.twilio.converter.CurrencyDeserializer.class + ) final Currency billedUnit ) { this.accountSid = accountSid; this.simSid = simSid; @@ -189,43 +173,53 @@ private UsageRecord( this.billedUnit = billedUnit; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getSimSid() { - return this.simSid; - } - public final String getNetworkSid() { - return this.networkSid; - } - public final String getFleetSid() { - return this.fleetSid; - } - public final String getIsoCountry() { - return this.isoCountry; - } - public final Map getPeriod() { - return this.period; - } - public final Long getDataUpload() { - return this.dataUpload; - } - public final Long getDataDownload() { - return this.dataDownload; - } - public final Long getDataTotal() { - return this.dataTotal; - } - public final BigDecimal getDataTotalBilled() { - return this.dataTotalBilled; - } - public final Currency getBilledUnit() { - return this.billedUnit; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getSimSid() { + return this.simSid; + } + + public final String getNetworkSid() { + return this.networkSid; + } + + public final String getFleetSid() { + return this.fleetSid; + } + + public final String getIsoCountry() { + return this.isoCountry; + } + + public final Map getPeriod() { + return this.period; + } + + public final Long getDataUpload() { + return this.dataUpload; + } + + public final Long getDataDownload() { + return this.dataDownload; + } + + public final Long getDataTotal() { + return this.dataTotal; + } + + public final BigDecimal getDataTotalBilled() { + return this.dataTotalBilled; + } + + public final Currency getBilledUnit() { + return this.billedUnit; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -235,13 +229,35 @@ public boolean equals(final Object o) { UsageRecord other = (UsageRecord) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(simSid, other.simSid) && Objects.equals(networkSid, other.networkSid) && Objects.equals(fleetSid, other.fleetSid) && Objects.equals(isoCountry, other.isoCountry) && Objects.equals(period, other.period) && Objects.equals(dataUpload, other.dataUpload) && Objects.equals(dataDownload, other.dataDownload) && Objects.equals(dataTotal, other.dataTotal) && Objects.equals(dataTotalBilled, other.dataTotalBilled) && Objects.equals(billedUnit, other.billedUnit) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(simSid, other.simSid) && + Objects.equals(networkSid, other.networkSid) && + Objects.equals(fleetSid, other.fleetSid) && + Objects.equals(isoCountry, other.isoCountry) && + Objects.equals(period, other.period) && + Objects.equals(dataUpload, other.dataUpload) && + Objects.equals(dataDownload, other.dataDownload) && + Objects.equals(dataTotal, other.dataTotal) && + Objects.equals(dataTotalBilled, other.dataTotalBilled) && + Objects.equals(billedUnit, other.billedUnit) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, simSid, networkSid, fleetSid, isoCountry, period, dataUpload, dataDownload, dataTotal, dataTotalBilled, billedUnit); + return Objects.hash( + accountSid, + simSid, + networkSid, + fleetSid, + isoCountry, + period, + dataUpload, + dataDownload, + dataTotal, + dataTotalBilled, + billedUnit + ); } - } - diff --git a/src/main/java/com/twilio/rest/supersim/v1/UsageRecordReader.java b/src/main/java/com/twilio/rest/supersim/v1/UsageRecordReader.java index 379cd7df97..458efbfddc 100644 --- a/src/main/java/com/twilio/rest/supersim/v1/UsageRecordReader.java +++ b/src/main/java/com/twilio/rest/supersim/v1/UsageRecordReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.supersim.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,12 +25,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; import java.time.ZonedDateTime; - - public class UsageRecordReader extends Reader { + private String sim; private String fleet; private String network; @@ -40,42 +39,51 @@ public class UsageRecordReader extends Reader { private ZonedDateTime endTime; private Integer pageSize; - public UsageRecordReader(){ - } + public UsageRecordReader() {} - public UsageRecordReader setSim(final String sim){ + public UsageRecordReader setSim(final String sim) { this.sim = sim; return this; } - public UsageRecordReader setFleet(final String fleet){ + + public UsageRecordReader setFleet(final String fleet) { this.fleet = fleet; return this; } - public UsageRecordReader setNetwork(final String network){ + + public UsageRecordReader setNetwork(final String network) { this.network = network; return this; } - public UsageRecordReader setIsoCountry(final String isoCountry){ + + public UsageRecordReader setIsoCountry(final String isoCountry) { this.isoCountry = isoCountry; return this; } - public UsageRecordReader setGroup(final UsageRecord.Group group){ + + public UsageRecordReader setGroup(final UsageRecord.Group group) { this.group = group; return this; } - public UsageRecordReader setGranularity(final UsageRecord.Granularity granularity){ + + public UsageRecordReader setGranularity( + final UsageRecord.Granularity granularity + ) { this.granularity = granularity; return this; } - public UsageRecordReader setStartTime(final ZonedDateTime startTime){ + + public UsageRecordReader setStartTime(final ZonedDateTime startTime) { this.startTime = startTime; return this; } - public UsageRecordReader setEndTime(final ZonedDateTime endTime){ + + public UsageRecordReader setEndTime(final ZonedDateTime endTime) { this.endTime = endTime; return this; } - public UsageRecordReader setPageSize(final Integer pageSize){ + + public UsageRecordReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -98,13 +106,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("UsageRecord read failed: Unable to connect to server"); + throw new ApiConnectionException( + "UsageRecord read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -120,7 +136,10 @@ private Page pageForRequest(final TwilioRestClient client, final Re } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.SUPERSIM.toString()) @@ -128,9 +147,11 @@ public Page previousPage(final Page page, final Twilio return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.SUPERSIM.toString()) @@ -139,41 +160,39 @@ public Page nextPage(final Page page, final TwilioRest } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (sim != null) { - request.addQueryParam("Sim", sim); } if (fleet != null) { - request.addQueryParam("Fleet", fleet); } if (network != null) { - request.addQueryParam("Network", network); } if (isoCountry != null) { - request.addQueryParam("IsoCountry", isoCountry); } if (group != null) { - request.addQueryParam("Group", group.toString()); } if (granularity != null) { - request.addQueryParam("Granularity", granularity.toString()); } if (startTime != null) { - request.addQueryParam("StartTime", startTime.toInstant().toString()); + request.addQueryParam( + "StartTime", + startTime.toInstant().toString() + ); } if (endTime != null) { @@ -181,11 +200,10 @@ private void addQueryParams(final Request request) { } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/supersim/v1/networkaccessprofile/NetworkAccessProfileNetwork.java b/src/main/java/com/twilio/rest/supersim/v1/networkaccessprofile/NetworkAccessProfileNetwork.java index b96133d50a..26d4ab9ad4 100644 --- a/src/main/java/com/twilio/rest/supersim/v1/networkaccessprofile/NetworkAccessProfileNetwork.java +++ b/src/main/java/com/twilio/rest/supersim/v1/networkaccessprofile/NetworkAccessProfileNetwork.java @@ -22,54 +22,78 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.List; import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class NetworkAccessProfileNetwork extends Resource { + private static final long serialVersionUID = 187162547019967L; - public static NetworkAccessProfileNetworkCreator creator(final String pathNetworkAccessProfileSid, final String network){ - return new NetworkAccessProfileNetworkCreator(pathNetworkAccessProfileSid, network); + public static NetworkAccessProfileNetworkCreator creator( + final String pathNetworkAccessProfileSid, + final String network + ) { + return new NetworkAccessProfileNetworkCreator( + pathNetworkAccessProfileSid, + network + ); } - public static NetworkAccessProfileNetworkDeleter deleter(final String pathNetworkAccessProfileSid, final String pathSid){ - return new NetworkAccessProfileNetworkDeleter(pathNetworkAccessProfileSid, pathSid); + public static NetworkAccessProfileNetworkDeleter deleter( + final String pathNetworkAccessProfileSid, + final String pathSid + ) { + return new NetworkAccessProfileNetworkDeleter( + pathNetworkAccessProfileSid, + pathSid + ); } - public static NetworkAccessProfileNetworkFetcher fetcher(final String pathNetworkAccessProfileSid, final String pathSid){ - return new NetworkAccessProfileNetworkFetcher(pathNetworkAccessProfileSid, pathSid); + public static NetworkAccessProfileNetworkFetcher fetcher( + final String pathNetworkAccessProfileSid, + final String pathSid + ) { + return new NetworkAccessProfileNetworkFetcher( + pathNetworkAccessProfileSid, + pathSid + ); } - public static NetworkAccessProfileNetworkReader reader(final String pathNetworkAccessProfileSid){ - return new NetworkAccessProfileNetworkReader(pathNetworkAccessProfileSid); + public static NetworkAccessProfileNetworkReader reader( + final String pathNetworkAccessProfileSid + ) { + return new NetworkAccessProfileNetworkReader( + pathNetworkAccessProfileSid + ); } /** - * Converts a JSON String into a NetworkAccessProfileNetwork object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return NetworkAccessProfileNetwork object represented by the provided JSON - */ - public static NetworkAccessProfileNetwork fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a NetworkAccessProfileNetwork object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return NetworkAccessProfileNetwork object represented by the provided JSON + */ + public static NetworkAccessProfileNetwork fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, NetworkAccessProfileNetwork.class); + return objectMapper.readValue( + json, + NetworkAccessProfileNetwork.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -78,17 +102,23 @@ public static NetworkAccessProfileNetwork fromJson(final String json, final Obje } /** - * Converts a JSON InputStream into a NetworkAccessProfileNetwork object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return NetworkAccessProfileNetwork object represented by the provided JSON - */ - public static NetworkAccessProfileNetwork fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a NetworkAccessProfileNetwork object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return NetworkAccessProfileNetwork object represented by the provided JSON + */ + public static NetworkAccessProfileNetwork fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, NetworkAccessProfileNetwork.class); + return objectMapper.readValue( + json, + NetworkAccessProfileNetwork.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -105,23 +135,16 @@ public static NetworkAccessProfileNetwork fromJson(final InputStream json, final @JsonCreator private NetworkAccessProfileNetwork( - @JsonProperty("sid") - final String sid, - - @JsonProperty("network_access_profile_sid") - final String networkAccessProfileSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("iso_country") - final String isoCountry, - - @JsonProperty("identifiers") - final List> identifiers, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty( + "network_access_profile_sid" + ) final String networkAccessProfileSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("iso_country") final String isoCountry, + @JsonProperty( + "identifiers" + ) final List> identifiers, + @JsonProperty("url") final URI url ) { this.sid = sid; this.networkAccessProfileSid = networkAccessProfileSid; @@ -131,28 +154,33 @@ private NetworkAccessProfileNetwork( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getNetworkAccessProfileSid() { - return this.networkAccessProfileSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getIsoCountry() { - return this.isoCountry; - } - public final List> getIdentifiers() { - return this.identifiers; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getNetworkAccessProfileSid() { + return this.networkAccessProfileSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getIsoCountry() { + return this.isoCountry; + } + + public final List> getIdentifiers() { + return this.identifiers; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -162,13 +190,28 @@ public boolean equals(final Object o) { NetworkAccessProfileNetwork other = (NetworkAccessProfileNetwork) o; - return Objects.equals(sid, other.sid) && Objects.equals(networkAccessProfileSid, other.networkAccessProfileSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(isoCountry, other.isoCountry) && Objects.equals(identifiers, other.identifiers) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals( + networkAccessProfileSid, + other.networkAccessProfileSid + ) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(isoCountry, other.isoCountry) && + Objects.equals(identifiers, other.identifiers) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, networkAccessProfileSid, friendlyName, isoCountry, identifiers, url); + return Objects.hash( + sid, + networkAccessProfileSid, + friendlyName, + isoCountry, + identifiers, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/supersim/v1/networkaccessprofile/NetworkAccessProfileNetworkCreator.java b/src/main/java/com/twilio/rest/supersim/v1/networkaccessprofile/NetworkAccessProfileNetworkCreator.java index 7fddb8d951..e9e1732107 100644 --- a/src/main/java/com/twilio/rest/supersim/v1/networkaccessprofile/NetworkAccessProfileNetworkCreator.java +++ b/src/main/java/com/twilio/rest/supersim/v1/networkaccessprofile/NetworkAccessProfileNetworkCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.supersim.v1.networkaccessprofile; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,53 +25,69 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class NetworkAccessProfileNetworkCreator + extends Creator { - - -public class NetworkAccessProfileNetworkCreator extends Creator{ private String pathNetworkAccessProfileSid; private String network; - public NetworkAccessProfileNetworkCreator(final String pathNetworkAccessProfileSid, final String network) { + public NetworkAccessProfileNetworkCreator( + final String pathNetworkAccessProfileSid, + final String network + ) { this.pathNetworkAccessProfileSid = pathNetworkAccessProfileSid; this.network = network; } - public NetworkAccessProfileNetworkCreator setNetwork(final String network){ + public NetworkAccessProfileNetworkCreator setNetwork(final String network) { this.network = network; return this; } @Override - public NetworkAccessProfileNetwork create(final TwilioRestClient client){ - String path = "/v1/NetworkAccessProfiles/{NetworkAccessProfileSid}/Networks"; + public NetworkAccessProfileNetwork create(final TwilioRestClient client) { + String path = + "/v1/NetworkAccessProfiles/{NetworkAccessProfileSid}/Networks"; - path = path.replace("{"+"NetworkAccessProfileSid"+"}", this.pathNetworkAccessProfileSid.toString()); - path = path.replace("{"+"Network"+"}", this.network.toString()); + path = + path.replace( + "{" + "NetworkAccessProfileSid" + "}", + this.pathNetworkAccessProfileSid.toString() + ); + path = path.replace("{" + "Network" + "}", this.network.toString()); Request request = new Request( HttpMethod.POST, Domains.SUPERSIM.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("NetworkAccessProfileNetwork creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "NetworkAccessProfileNetwork creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return NetworkAccessProfileNetwork.fromJson(response.getStream(), client.getObjectMapper()); + return NetworkAccessProfileNetwork.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (network != null) { request.addPostParam("Network", network); - } } } diff --git a/src/main/java/com/twilio/rest/supersim/v1/networkaccessprofile/NetworkAccessProfileNetworkDeleter.java b/src/main/java/com/twilio/rest/supersim/v1/networkaccessprofile/NetworkAccessProfileNetworkDeleter.java index 1b166d9d74..f11d85ca98 100644 --- a/src/main/java/com/twilio/rest/supersim/v1/networkaccessprofile/NetworkAccessProfileNetworkDeleter.java +++ b/src/main/java/com/twilio/rest/supersim/v1/networkaccessprofile/NetworkAccessProfileNetworkDeleter.java @@ -24,24 +24,31 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class NetworkAccessProfileNetworkDeleter + extends Deleter { - -public class NetworkAccessProfileNetworkDeleter extends Deleter { private String pathNetworkAccessProfileSid; private String pathSid; - public NetworkAccessProfileNetworkDeleter(final String pathNetworkAccessProfileSid, final String pathSid){ + public NetworkAccessProfileNetworkDeleter( + final String pathNetworkAccessProfileSid, + final String pathSid + ) { this.pathNetworkAccessProfileSid = pathNetworkAccessProfileSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/v1/NetworkAccessProfiles/{NetworkAccessProfileSid}/Networks/{Sid}"; + String path = + "/v1/NetworkAccessProfiles/{NetworkAccessProfileSid}/Networks/{Sid}"; - path = path.replace("{"+"NetworkAccessProfileSid"+"}", this.pathNetworkAccessProfileSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "NetworkAccessProfileSid" + "}", + this.pathNetworkAccessProfileSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +58,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("NetworkAccessProfileNetwork delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "NetworkAccessProfileNetwork delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/supersim/v1/networkaccessprofile/NetworkAccessProfileNetworkFetcher.java b/src/main/java/com/twilio/rest/supersim/v1/networkaccessprofile/NetworkAccessProfileNetworkFetcher.java index 8f14be8d93..3e50ee41fb 100644 --- a/src/main/java/com/twilio/rest/supersim/v1/networkaccessprofile/NetworkAccessProfileNetworkFetcher.java +++ b/src/main/java/com/twilio/rest/supersim/v1/networkaccessprofile/NetworkAccessProfileNetworkFetcher.java @@ -24,25 +24,31 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class NetworkAccessProfileNetworkFetcher + extends Fetcher { - - -public class NetworkAccessProfileNetworkFetcher extends Fetcher { private String pathNetworkAccessProfileSid; private String pathSid; - public NetworkAccessProfileNetworkFetcher(final String pathNetworkAccessProfileSid, final String pathSid){ + public NetworkAccessProfileNetworkFetcher( + final String pathNetworkAccessProfileSid, + final String pathSid + ) { this.pathNetworkAccessProfileSid = pathNetworkAccessProfileSid; this.pathSid = pathSid; } - @Override public NetworkAccessProfileNetwork fetch(final TwilioRestClient client) { - String path = "/v1/NetworkAccessProfiles/{NetworkAccessProfileSid}/Networks/{Sid}"; + String path = + "/v1/NetworkAccessProfiles/{NetworkAccessProfileSid}/Networks/{Sid}"; - path = path.replace("{"+"NetworkAccessProfileSid"+"}", this.pathNetworkAccessProfileSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "NetworkAccessProfileSid" + "}", + this.pathNetworkAccessProfileSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,15 +58,23 @@ public NetworkAccessProfileNetwork fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("NetworkAccessProfileNetwork fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "NetworkAccessProfileNetwork fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return NetworkAccessProfileNetwork.fromJson(response.getStream(), client.getObjectMapper()); + return NetworkAccessProfileNetwork.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/supersim/v1/networkaccessprofile/NetworkAccessProfileNetworkReader.java b/src/main/java/com/twilio/rest/supersim/v1/networkaccessprofile/NetworkAccessProfileNetworkReader.java index aabdafd40e..7a6ff82bdc 100644 --- a/src/main/java/com/twilio/rest/supersim/v1/networkaccessprofile/NetworkAccessProfileNetworkReader.java +++ b/src/main/java/com/twilio/rest/supersim/v1/networkaccessprofile/NetworkAccessProfileNetworkReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.supersim.v1.networkaccessprofile; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,31 +25,43 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; +public class NetworkAccessProfileNetworkReader + extends Reader { - -public class NetworkAccessProfileNetworkReader extends Reader { private String pathNetworkAccessProfileSid; private Integer pageSize; - public NetworkAccessProfileNetworkReader(final String pathNetworkAccessProfileSid){ + public NetworkAccessProfileNetworkReader( + final String pathNetworkAccessProfileSid + ) { this.pathNetworkAccessProfileSid = pathNetworkAccessProfileSid; } - public NetworkAccessProfileNetworkReader setPageSize(final Integer pageSize){ + public NetworkAccessProfileNetworkReader setPageSize( + final Integer pageSize + ) { this.pageSize = pageSize; return this; } @Override - public ResourceSet read(final TwilioRestClient client) { + public ResourceSet read( + final TwilioRestClient client + ) { return new ResourceSet<>(this, client, firstPage(client)); } - public Page firstPage(final TwilioRestClient client) { - String path = "/v1/NetworkAccessProfiles/{NetworkAccessProfileSid}/Networks"; - path = path.replace("{"+"NetworkAccessProfileSid"+"}", this.pathNetworkAccessProfileSid.toString()); + public Page firstPage( + final TwilioRestClient client + ) { + String path = + "/v1/NetworkAccessProfiles/{NetworkAccessProfileSid}/Networks"; + path = + path.replace( + "{" + "NetworkAccessProfileSid" + "}", + this.pathNetworkAccessProfileSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -60,13 +73,21 @@ public Page firstPage(final TwilioRestClient client return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("NetworkAccessProfileNetwork read failed: Unable to connect to server"); + throw new ApiConnectionException( + "NetworkAccessProfileNetwork read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +103,10 @@ private Page pageForRequest(final TwilioRestClient } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.SUPERSIM.toString()) @@ -90,9 +114,11 @@ public Page previousPage(final Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.SUPERSIM.toString()) @@ -101,21 +127,21 @@ public Page nextPage(final Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/supersim/v1/sim/BillingPeriod.java b/src/main/java/com/twilio/rest/supersim/v1/sim/BillingPeriod.java index 69d4b10a0c..3d853da1b7 100644 --- a/src/main/java/com/twilio/rest/supersim/v1/sim/BillingPeriod.java +++ b/src/main/java/com/twilio/rest/supersim/v1/sim/BillingPeriod.java @@ -24,36 +24,35 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class BillingPeriod extends Resource { + private static final long serialVersionUID = 154829037650501L; - public static BillingPeriodReader reader(final String pathSimSid){ + public static BillingPeriodReader reader(final String pathSimSid) { return new BillingPeriodReader(pathSimSid); } /** - * Converts a JSON String into a BillingPeriod object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return BillingPeriod object represented by the provided JSON - */ - public static BillingPeriod fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a BillingPeriod object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return BillingPeriod object represented by the provided JSON + */ + public static BillingPeriod fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, BillingPeriod.class); @@ -65,14 +64,17 @@ public static BillingPeriod fromJson(final String json, final ObjectMapper objec } /** - * Converts a JSON InputStream into a BillingPeriod object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return BillingPeriod object represented by the provided JSON - */ - public static BillingPeriod fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a BillingPeriod object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return BillingPeriod object represented by the provided JSON + */ + public static BillingPeriod fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, BillingPeriod.class); @@ -82,6 +84,7 @@ public static BillingPeriod fromJson(final InputStream json, final ObjectMapper throw new ApiConnectionException(e.getMessage(), e); } } + public enum BpType { READY("ready"), ACTIVE("active"); @@ -113,29 +116,14 @@ public static BpType forValue(final String value) { @JsonCreator private BillingPeriod( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("sim_sid") - final String simSid, - - @JsonProperty("start_time") - final String startTime, - - @JsonProperty("end_time") - final String endTime, - - @JsonProperty("period_type") - final BillingPeriod.BpType periodType, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("sim_sid") final String simSid, + @JsonProperty("start_time") final String startTime, + @JsonProperty("end_time") final String endTime, + @JsonProperty("period_type") final BillingPeriod.BpType periodType, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated ) { this.sid = sid; this.accountSid = accountSid; @@ -147,34 +135,41 @@ private BillingPeriod( this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getSimSid() { - return this.simSid; - } - public final ZonedDateTime getStartTime() { - return this.startTime; - } - public final ZonedDateTime getEndTime() { - return this.endTime; - } - public final BillingPeriod.BpType getPeriodType() { - return this.periodType; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getSimSid() { + return this.simSid; + } + + public final ZonedDateTime getStartTime() { + return this.startTime; + } + + public final ZonedDateTime getEndTime() { + return this.endTime; + } + + public final BillingPeriod.BpType getPeriodType() { + return this.periodType; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -184,13 +179,29 @@ public boolean equals(final Object o) { BillingPeriod other = (BillingPeriod) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(simSid, other.simSid) && Objects.equals(startTime, other.startTime) && Objects.equals(endTime, other.endTime) && Objects.equals(periodType, other.periodType) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(simSid, other.simSid) && + Objects.equals(startTime, other.startTime) && + Objects.equals(endTime, other.endTime) && + Objects.equals(periodType, other.periodType) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, simSid, startTime, endTime, periodType, dateCreated, dateUpdated); + return Objects.hash( + sid, + accountSid, + simSid, + startTime, + endTime, + periodType, + dateCreated, + dateUpdated + ); } - } - diff --git a/src/main/java/com/twilio/rest/supersim/v1/sim/BillingPeriodReader.java b/src/main/java/com/twilio/rest/supersim/v1/sim/BillingPeriodReader.java index ed5c88693e..ecaf8518e8 100644 --- a/src/main/java/com/twilio/rest/supersim/v1/sim/BillingPeriodReader.java +++ b/src/main/java/com/twilio/rest/supersim/v1/sim/BillingPeriodReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.supersim.v1.sim; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,19 +25,17 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class BillingPeriodReader extends Reader { + private String pathSimSid; private Integer pageSize; - public BillingPeriodReader(final String pathSimSid){ + public BillingPeriodReader(final String pathSimSid) { this.pathSimSid = pathSimSid; } - public BillingPeriodReader setPageSize(final Integer pageSize){ + public BillingPeriodReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -48,7 +47,7 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Sims/{SimSid}/BillingPeriods"; - path = path.replace("{"+"SimSid"+"}", this.pathSimSid.toString()); + path = path.replace("{" + "SimSid" + "}", this.pathSimSid.toString()); Request request = new Request( HttpMethod.GET, @@ -60,13 +59,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("BillingPeriod read failed: Unable to connect to server"); + throw new ApiConnectionException( + "BillingPeriod read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +89,10 @@ private Page pageForRequest(final TwilioRestClient client, final } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.SUPERSIM.toString()) @@ -90,9 +100,11 @@ public Page previousPage(final Page page, final Tw return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.SUPERSIM.toString()) @@ -101,21 +113,21 @@ public Page nextPage(final Page page, final Twilio } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/supersim/v1/sim/SimIpAddress.java b/src/main/java/com/twilio/rest/supersim/v1/sim/SimIpAddress.java index 0cc4808b09..0dae8cfdc5 100644 --- a/src/main/java/com/twilio/rest/supersim/v1/sim/SimIpAddress.java +++ b/src/main/java/com/twilio/rest/supersim/v1/sim/SimIpAddress.java @@ -23,35 +23,34 @@ import com.twilio.base.Resource; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class SimIpAddress extends Resource { + private static final long serialVersionUID = 180616107351268L; - public static SimIpAddressReader reader(final String pathSimSid){ + public static SimIpAddressReader reader(final String pathSimSid) { return new SimIpAddressReader(pathSimSid); } /** - * Converts a JSON String into a SimIpAddress object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return SimIpAddress object represented by the provided JSON - */ - public static SimIpAddress fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a SimIpAddress object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return SimIpAddress object represented by the provided JSON + */ + public static SimIpAddress fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SimIpAddress.class); @@ -63,14 +62,17 @@ public static SimIpAddress fromJson(final String json, final ObjectMapper object } /** - * Converts a JSON InputStream into a SimIpAddress object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return SimIpAddress object represented by the provided JSON - */ - public static SimIpAddress fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a SimIpAddress object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return SimIpAddress object represented by the provided JSON + */ + public static SimIpAddress fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SimIpAddress.class); @@ -80,6 +82,7 @@ public static SimIpAddress fromJson(final InputStream json, final ObjectMapper o throw new ApiConnectionException(e.getMessage(), e); } } + public enum IpAddressVersion { IPV4("IPv4"), IPV6("IPv6"); @@ -105,26 +108,26 @@ public static IpAddressVersion forValue(final String value) { @JsonCreator private SimIpAddress( - @JsonProperty("ip_address") - final String ipAddress, - - @JsonProperty("ip_address_version") - final SimIpAddress.IpAddressVersion ipAddressVersion + @JsonProperty("ip_address") final String ipAddress, + @JsonProperty( + "ip_address_version" + ) final SimIpAddress.IpAddressVersion ipAddressVersion ) { this.ipAddress = ipAddress; this.ipAddressVersion = ipAddressVersion; } - public final String getIpAddress() { - return this.ipAddress; - } - public final SimIpAddress.IpAddressVersion getIpAddressVersion() { - return this.ipAddressVersion; - } + public final String getIpAddress() { + return this.ipAddress; + } + + public final SimIpAddress.IpAddressVersion getIpAddressVersion() { + return this.ipAddressVersion; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -134,13 +137,14 @@ public boolean equals(final Object o) { SimIpAddress other = (SimIpAddress) o; - return Objects.equals(ipAddress, other.ipAddress) && Objects.equals(ipAddressVersion, other.ipAddressVersion) ; + return ( + Objects.equals(ipAddress, other.ipAddress) && + Objects.equals(ipAddressVersion, other.ipAddressVersion) + ); } @Override public int hashCode() { return Objects.hash(ipAddress, ipAddressVersion); } - } - diff --git a/src/main/java/com/twilio/rest/supersim/v1/sim/SimIpAddressReader.java b/src/main/java/com/twilio/rest/supersim/v1/sim/SimIpAddressReader.java index 14f3cbcd20..fe8e9e8eb2 100644 --- a/src/main/java/com/twilio/rest/supersim/v1/sim/SimIpAddressReader.java +++ b/src/main/java/com/twilio/rest/supersim/v1/sim/SimIpAddressReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.supersim.v1.sim; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,19 +25,17 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class SimIpAddressReader extends Reader { + private String pathSimSid; private Integer pageSize; - public SimIpAddressReader(final String pathSimSid){ + public SimIpAddressReader(final String pathSimSid) { this.pathSimSid = pathSimSid; } - public SimIpAddressReader setPageSize(final Integer pageSize){ + public SimIpAddressReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -48,7 +47,7 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Sims/{SimSid}/IpAddresses"; - path = path.replace("{"+"SimSid"+"}", this.pathSimSid.toString()); + path = path.replace("{" + "SimSid" + "}", this.pathSimSid.toString()); Request request = new Request( HttpMethod.GET, @@ -60,13 +59,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SimIpAddress read failed: Unable to connect to server"); + throw new ApiConnectionException( + "SimIpAddress read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +89,10 @@ private Page pageForRequest(final TwilioRestClient client, final R } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.SUPERSIM.toString()) @@ -90,9 +100,11 @@ public Page previousPage(final Page page, final Twil return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.SUPERSIM.toString()) @@ -101,21 +113,21 @@ public Page nextPage(final Page page, final TwilioRe } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/sync/v1/Service.java b/src/main/java/com/twilio/rest/sync/v1/Service.java index 79bb35e820..e18c5dccdc 100644 --- a/src/main/java/com/twilio/rest/sync/v1/Service.java +++ b/src/main/java/com/twilio/rest/sync/v1/Service.java @@ -23,55 +23,54 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Service extends Resource { + private static final long serialVersionUID = 61347848648189L; - public static ServiceCreator creator(){ + public static ServiceCreator creator() { return new ServiceCreator(); } - public static ServiceDeleter deleter(final String pathSid){ + public static ServiceDeleter deleter(final String pathSid) { return new ServiceDeleter(pathSid); } - public static ServiceFetcher fetcher(final String pathSid){ + public static ServiceFetcher fetcher(final String pathSid) { return new ServiceFetcher(pathSid); } - public static ServiceReader reader(){ + public static ServiceReader reader() { return new ServiceReader(); } - public static ServiceUpdater updater(final String pathSid){ + public static ServiceUpdater updater(final String pathSid) { return new ServiceUpdater(pathSid); } /** - * Converts a JSON String into a Service object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Service object represented by the provided JSON - */ - public static Service fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Service object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Service object represented by the provided JSON + */ + public static Service fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Service.class); @@ -83,14 +82,17 @@ public static Service fromJson(final String json, final ObjectMapper objectMappe } /** - * Converts a JSON InputStream into a Service object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Service object represented by the provided JSON - */ - public static Service fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Service object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Service object represented by the provided JSON + */ + public static Service fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Service.class); @@ -118,47 +120,28 @@ public static Service fromJson(final InputStream json, final ObjectMapper object @JsonCreator private Service( - @JsonProperty("sid") - final String sid, - - @JsonProperty("unique_name") - final String uniqueName, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url, - - @JsonProperty("webhook_url") - final URI webhookUrl, - - @JsonProperty("webhooks_from_rest_enabled") - final Boolean webhooksFromRestEnabled, - - @JsonProperty("reachability_webhooks_enabled") - final Boolean reachabilityWebhooksEnabled, - - @JsonProperty("acl_enabled") - final Boolean aclEnabled, - - @JsonProperty("reachability_debouncing_enabled") - final Boolean reachabilityDebouncingEnabled, - - @JsonProperty("reachability_debouncing_window") - final Integer reachabilityDebouncingWindow, - - @JsonProperty("links") - final Map links + @JsonProperty("sid") final String sid, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url, + @JsonProperty("webhook_url") final URI webhookUrl, + @JsonProperty( + "webhooks_from_rest_enabled" + ) final Boolean webhooksFromRestEnabled, + @JsonProperty( + "reachability_webhooks_enabled" + ) final Boolean reachabilityWebhooksEnabled, + @JsonProperty("acl_enabled") final Boolean aclEnabled, + @JsonProperty( + "reachability_debouncing_enabled" + ) final Boolean reachabilityDebouncingEnabled, + @JsonProperty( + "reachability_debouncing_window" + ) final Integer reachabilityDebouncingWindow, + @JsonProperty("links") final Map links ) { this.sid = sid; this.uniqueName = uniqueName; @@ -176,52 +159,65 @@ private Service( this.links = links; } - public final String getSid() { - return this.sid; - } - public final String getUniqueName() { - return this.uniqueName; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } - public final URI getWebhookUrl() { - return this.webhookUrl; - } - public final Boolean getWebhooksFromRestEnabled() { - return this.webhooksFromRestEnabled; - } - public final Boolean getReachabilityWebhooksEnabled() { - return this.reachabilityWebhooksEnabled; - } - public final Boolean getAclEnabled() { - return this.aclEnabled; - } - public final Boolean getReachabilityDebouncingEnabled() { - return this.reachabilityDebouncingEnabled; - } - public final Integer getReachabilityDebouncingWindow() { - return this.reachabilityDebouncingWindow; - } - public final Map getLinks() { - return this.links; - } + public final String getSid() { + return this.sid; + } + + public final String getUniqueName() { + return this.uniqueName; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } + + public final URI getWebhookUrl() { + return this.webhookUrl; + } + + public final Boolean getWebhooksFromRestEnabled() { + return this.webhooksFromRestEnabled; + } + + public final Boolean getReachabilityWebhooksEnabled() { + return this.reachabilityWebhooksEnabled; + } + + public final Boolean getAclEnabled() { + return this.aclEnabled; + } + + public final Boolean getReachabilityDebouncingEnabled() { + return this.reachabilityDebouncingEnabled; + } + + public final Integer getReachabilityDebouncingWindow() { + return this.reachabilityDebouncingWindow; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -231,13 +227,53 @@ public boolean equals(final Object o) { Service other = (Service) o; - return Objects.equals(sid, other.sid) && Objects.equals(uniqueName, other.uniqueName) && Objects.equals(accountSid, other.accountSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) && Objects.equals(webhookUrl, other.webhookUrl) && Objects.equals(webhooksFromRestEnabled, other.webhooksFromRestEnabled) && Objects.equals(reachabilityWebhooksEnabled, other.reachabilityWebhooksEnabled) && Objects.equals(aclEnabled, other.aclEnabled) && Objects.equals(reachabilityDebouncingEnabled, other.reachabilityDebouncingEnabled) && Objects.equals(reachabilityDebouncingWindow, other.reachabilityDebouncingWindow) && Objects.equals(links, other.links) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) && + Objects.equals(webhookUrl, other.webhookUrl) && + Objects.equals( + webhooksFromRestEnabled, + other.webhooksFromRestEnabled + ) && + Objects.equals( + reachabilityWebhooksEnabled, + other.reachabilityWebhooksEnabled + ) && + Objects.equals(aclEnabled, other.aclEnabled) && + Objects.equals( + reachabilityDebouncingEnabled, + other.reachabilityDebouncingEnabled + ) && + Objects.equals( + reachabilityDebouncingWindow, + other.reachabilityDebouncingWindow + ) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(sid, uniqueName, accountSid, friendlyName, dateCreated, dateUpdated, url, webhookUrl, webhooksFromRestEnabled, reachabilityWebhooksEnabled, aclEnabled, reachabilityDebouncingEnabled, reachabilityDebouncingWindow, links); + return Objects.hash( + sid, + uniqueName, + accountSid, + friendlyName, + dateCreated, + dateUpdated, + url, + webhookUrl, + webhooksFromRestEnabled, + reachabilityWebhooksEnabled, + aclEnabled, + reachabilityDebouncingEnabled, + reachabilityDebouncingWindow, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/sync/v1/ServiceCreator.java b/src/main/java/com/twilio/rest/sync/v1/ServiceCreator.java index be49455449..f851b98bb1 100644 --- a/src/main/java/com/twilio/rest/sync/v1/ServiceCreator.java +++ b/src/main/java/com/twilio/rest/sync/v1/ServiceCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.sync.v1; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -25,12 +26,10 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.net.URI; - - - import java.net.URI; -public class ServiceCreator extends Creator{ +public class ServiceCreator extends Creator { + private String friendlyName; private URI webhookUrl; private Boolean reachabilityWebhooksEnabled; @@ -39,58 +38,76 @@ public class ServiceCreator extends Creator{ private Integer reachabilityDebouncingWindow; private Boolean webhooksFromRestEnabled; - public ServiceCreator() { - } + public ServiceCreator() {} - public ServiceCreator setFriendlyName(final String friendlyName){ + public ServiceCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public ServiceCreator setWebhookUrl(final URI webhookUrl){ + + public ServiceCreator setWebhookUrl(final URI webhookUrl) { this.webhookUrl = webhookUrl; return this; } - public ServiceCreator setWebhookUrl(final String webhookUrl){ + public ServiceCreator setWebhookUrl(final String webhookUrl) { return setWebhookUrl(Promoter.uriFromString(webhookUrl)); } - public ServiceCreator setReachabilityWebhooksEnabled(final Boolean reachabilityWebhooksEnabled){ + + public ServiceCreator setReachabilityWebhooksEnabled( + final Boolean reachabilityWebhooksEnabled + ) { this.reachabilityWebhooksEnabled = reachabilityWebhooksEnabled; return this; } - public ServiceCreator setAclEnabled(final Boolean aclEnabled){ + + public ServiceCreator setAclEnabled(final Boolean aclEnabled) { this.aclEnabled = aclEnabled; return this; } - public ServiceCreator setReachabilityDebouncingEnabled(final Boolean reachabilityDebouncingEnabled){ + + public ServiceCreator setReachabilityDebouncingEnabled( + final Boolean reachabilityDebouncingEnabled + ) { this.reachabilityDebouncingEnabled = reachabilityDebouncingEnabled; return this; } - public ServiceCreator setReachabilityDebouncingWindow(final Integer reachabilityDebouncingWindow){ + + public ServiceCreator setReachabilityDebouncingWindow( + final Integer reachabilityDebouncingWindow + ) { this.reachabilityDebouncingWindow = reachabilityDebouncingWindow; return this; } - public ServiceCreator setWebhooksFromRestEnabled(final Boolean webhooksFromRestEnabled){ + + public ServiceCreator setWebhooksFromRestEnabled( + final Boolean webhooksFromRestEnabled + ) { this.webhooksFromRestEnabled = webhooksFromRestEnabled; return this; } @Override - public Service create(final TwilioRestClient client){ + public Service create(final TwilioRestClient client) { String path = "/v1/Services"; - Request request = new Request( HttpMethod.POST, Domains.SYNC.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -99,34 +116,40 @@ public Service create(final TwilioRestClient client){ return Service.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (webhookUrl != null) { request.addPostParam("WebhookUrl", webhookUrl.toString()); - } if (reachabilityWebhooksEnabled != null) { - request.addPostParam("ReachabilityWebhooksEnabled", reachabilityWebhooksEnabled.toString()); - + request.addPostParam( + "ReachabilityWebhooksEnabled", + reachabilityWebhooksEnabled.toString() + ); } if (aclEnabled != null) { request.addPostParam("AclEnabled", aclEnabled.toString()); - } if (reachabilityDebouncingEnabled != null) { - request.addPostParam("ReachabilityDebouncingEnabled", reachabilityDebouncingEnabled.toString()); - + request.addPostParam( + "ReachabilityDebouncingEnabled", + reachabilityDebouncingEnabled.toString() + ); } if (reachabilityDebouncingWindow != null) { - request.addPostParam("ReachabilityDebouncingWindow", reachabilityDebouncingWindow.toString()); - + request.addPostParam( + "ReachabilityDebouncingWindow", + reachabilityDebouncingWindow.toString() + ); } if (webhooksFromRestEnabled != null) { - request.addPostParam("WebhooksFromRestEnabled", webhooksFromRestEnabled.toString()); - + request.addPostParam( + "WebhooksFromRestEnabled", + webhooksFromRestEnabled.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/sync/v1/ServiceDeleter.java b/src/main/java/com/twilio/rest/sync/v1/ServiceDeleter.java index 5e851770a9..7f931cc929 100644 --- a/src/main/java/com/twilio/rest/sync/v1/ServiceDeleter.java +++ b/src/main/java/com/twilio/rest/sync/v1/ServiceDeleter.java @@ -24,21 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class ServiceDeleter extends Deleter { + private String pathSid; - public ServiceDeleter(final String pathSid){ + public ServiceDeleter(final String pathSid) { this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Services/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -48,9 +46,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/sync/v1/ServiceFetcher.java b/src/main/java/com/twilio/rest/sync/v1/ServiceFetcher.java index 4bc9dbec44..3029d03a7b 100644 --- a/src/main/java/com/twilio/rest/sync/v1/ServiceFetcher.java +++ b/src/main/java/com/twilio/rest/sync/v1/ServiceFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class ServiceFetcher extends Fetcher { + private String pathSid; - public ServiceFetcher(final String pathSid){ + public ServiceFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public Service fetch(final TwilioRestClient client) { String path = "/v1/Services/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,9 +46,14 @@ public Service fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/sync/v1/ServiceReader.java b/src/main/java/com/twilio/rest/sync/v1/ServiceReader.java index 835e3c3a43..bbca2641a2 100644 --- a/src/main/java/com/twilio/rest/sync/v1/ServiceReader.java +++ b/src/main/java/com/twilio/rest/sync/v1/ServiceReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.sync.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,17 +25,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class ServiceReader extends Reader { + private Integer pageSize; - public ServiceReader(){ - } + public ServiceReader() {} - public ServiceReader setPageSize(final Integer pageSize){ + public ServiceReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -57,13 +55,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -79,7 +85,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reques } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.SYNC.toString()) @@ -87,9 +96,11 @@ public Page previousPage(final Page page, final TwilioRestClie return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.SYNC.toString()) @@ -98,21 +109,21 @@ public Page nextPage(final Page page, final TwilioRestClient c } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/sync/v1/ServiceUpdater.java b/src/main/java/com/twilio/rest/sync/v1/ServiceUpdater.java index 6318a3e433..2640f42d4e 100644 --- a/src/main/java/com/twilio/rest/sync/v1/ServiceUpdater.java +++ b/src/main/java/com/twilio/rest/sync/v1/ServiceUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.sync.v1; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -24,12 +25,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.net.URI; +public class ServiceUpdater extends Updater { - -public class ServiceUpdater extends Updater{ private String pathSid; private URI webhookUrl; private String friendlyName; @@ -39,60 +38,80 @@ public class ServiceUpdater extends Updater{ private Integer reachabilityDebouncingWindow; private Boolean webhooksFromRestEnabled; - public ServiceUpdater(final String pathSid){ + public ServiceUpdater(final String pathSid) { this.pathSid = pathSid; } - public ServiceUpdater setWebhookUrl(final URI webhookUrl){ + public ServiceUpdater setWebhookUrl(final URI webhookUrl) { this.webhookUrl = webhookUrl; return this; } - public ServiceUpdater setWebhookUrl(final String webhookUrl){ + public ServiceUpdater setWebhookUrl(final String webhookUrl) { return setWebhookUrl(Promoter.uriFromString(webhookUrl)); } - public ServiceUpdater setFriendlyName(final String friendlyName){ + + public ServiceUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public ServiceUpdater setReachabilityWebhooksEnabled(final Boolean reachabilityWebhooksEnabled){ + + public ServiceUpdater setReachabilityWebhooksEnabled( + final Boolean reachabilityWebhooksEnabled + ) { this.reachabilityWebhooksEnabled = reachabilityWebhooksEnabled; return this; } - public ServiceUpdater setAclEnabled(final Boolean aclEnabled){ + + public ServiceUpdater setAclEnabled(final Boolean aclEnabled) { this.aclEnabled = aclEnabled; return this; } - public ServiceUpdater setReachabilityDebouncingEnabled(final Boolean reachabilityDebouncingEnabled){ + + public ServiceUpdater setReachabilityDebouncingEnabled( + final Boolean reachabilityDebouncingEnabled + ) { this.reachabilityDebouncingEnabled = reachabilityDebouncingEnabled; return this; } - public ServiceUpdater setReachabilityDebouncingWindow(final Integer reachabilityDebouncingWindow){ + + public ServiceUpdater setReachabilityDebouncingWindow( + final Integer reachabilityDebouncingWindow + ) { this.reachabilityDebouncingWindow = reachabilityDebouncingWindow; return this; } - public ServiceUpdater setWebhooksFromRestEnabled(final Boolean webhooksFromRestEnabled){ + + public ServiceUpdater setWebhooksFromRestEnabled( + final Boolean webhooksFromRestEnabled + ) { this.webhooksFromRestEnabled = webhooksFromRestEnabled; return this; } @Override - public Service update(final TwilioRestClient client){ + public Service update(final TwilioRestClient client) { String path = "/v1/Services/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.SYNC.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -101,34 +120,40 @@ public Service update(final TwilioRestClient client){ return Service.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (webhookUrl != null) { request.addPostParam("WebhookUrl", webhookUrl.toString()); - } if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (reachabilityWebhooksEnabled != null) { - request.addPostParam("ReachabilityWebhooksEnabled", reachabilityWebhooksEnabled.toString()); - + request.addPostParam( + "ReachabilityWebhooksEnabled", + reachabilityWebhooksEnabled.toString() + ); } if (aclEnabled != null) { request.addPostParam("AclEnabled", aclEnabled.toString()); - } if (reachabilityDebouncingEnabled != null) { - request.addPostParam("ReachabilityDebouncingEnabled", reachabilityDebouncingEnabled.toString()); - + request.addPostParam( + "ReachabilityDebouncingEnabled", + reachabilityDebouncingEnabled.toString() + ); } if (reachabilityDebouncingWindow != null) { - request.addPostParam("ReachabilityDebouncingWindow", reachabilityDebouncingWindow.toString()); - + request.addPostParam( + "ReachabilityDebouncingWindow", + reachabilityDebouncingWindow.toString() + ); } if (webhooksFromRestEnabled != null) { - request.addPostParam("WebhooksFromRestEnabled", webhooksFromRestEnabled.toString()); - + request.addPostParam( + "WebhooksFromRestEnabled", + webhooksFromRestEnabled.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/sync/v1/service/Document.java b/src/main/java/com/twilio/rest/sync/v1/service/Document.java index 970751bd5e..e6b087729b 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/Document.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/Document.java @@ -23,55 +23,63 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Document extends Resource { + private static final long serialVersionUID = 221157207950751L; - public static DocumentCreator creator(final String pathServiceSid){ + public static DocumentCreator creator(final String pathServiceSid) { return new DocumentCreator(pathServiceSid); } - public static DocumentDeleter deleter(final String pathServiceSid, final String pathSid){ + public static DocumentDeleter deleter( + final String pathServiceSid, + final String pathSid + ) { return new DocumentDeleter(pathServiceSid, pathSid); } - public static DocumentFetcher fetcher(final String pathServiceSid, final String pathSid){ + public static DocumentFetcher fetcher( + final String pathServiceSid, + final String pathSid + ) { return new DocumentFetcher(pathServiceSid, pathSid); } - public static DocumentReader reader(final String pathServiceSid){ + public static DocumentReader reader(final String pathServiceSid) { return new DocumentReader(pathServiceSid); } - public static DocumentUpdater updater(final String pathServiceSid, final String pathSid){ + public static DocumentUpdater updater( + final String pathServiceSid, + final String pathSid + ) { return new DocumentUpdater(pathServiceSid, pathSid); } /** - * Converts a JSON String into a Document object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Document object represented by the provided JSON - */ - public static Document fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Document object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Document object represented by the provided JSON + */ + public static Document fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Document.class); @@ -83,14 +91,17 @@ public static Document fromJson(final String json, final ObjectMapper objectMapp } /** - * Converts a JSON InputStream into a Document object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Document object represented by the provided JSON - */ - public static Document fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Document object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Document object represented by the provided JSON + */ + public static Document fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Document.class); @@ -116,41 +127,18 @@ public static Document fromJson(final InputStream json, final ObjectMapper objec @JsonCreator private Document( - @JsonProperty("sid") - final String sid, - - @JsonProperty("unique_name") - final String uniqueName, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links, - - @JsonProperty("revision") - final String revision, - - @JsonProperty("data") - final Map data, - - @JsonProperty("date_expires") - final String dateExpires, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("created_by") - final String createdBy + @JsonProperty("sid") final String sid, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links, + @JsonProperty("revision") final String revision, + @JsonProperty("data") final Map data, + @JsonProperty("date_expires") final String dateExpires, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("created_by") final String createdBy ) { this.sid = sid; this.uniqueName = uniqueName; @@ -166,46 +154,57 @@ private Document( this.createdBy = createdBy; } - public final String getSid() { - return this.sid; - } - public final String getUniqueName() { - return this.uniqueName; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } - public final String getRevision() { - return this.revision; - } - public final Map getData() { - return this.data; - } - public final ZonedDateTime getDateExpires() { - return this.dateExpires; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getCreatedBy() { - return this.createdBy; - } + public final String getSid() { + return this.sid; + } + + public final String getUniqueName() { + return this.uniqueName; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } + + public final String getRevision() { + return this.revision; + } + + public final Map getData() { + return this.data; + } + + public final ZonedDateTime getDateExpires() { + return this.dateExpires; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getCreatedBy() { + return this.createdBy; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -215,13 +214,37 @@ public boolean equals(final Object o) { Document other = (Document) o; - return Objects.equals(sid, other.sid) && Objects.equals(uniqueName, other.uniqueName) && Objects.equals(accountSid, other.accountSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(url, other.url) && Objects.equals(links, other.links) && Objects.equals(revision, other.revision) && Objects.equals(data, other.data) && Objects.equals(dateExpires, other.dateExpires) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(createdBy, other.createdBy) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) && + Objects.equals(revision, other.revision) && + Objects.equals(data, other.data) && + Objects.equals(dateExpires, other.dateExpires) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(createdBy, other.createdBy) + ); } @Override public int hashCode() { - return Objects.hash(sid, uniqueName, accountSid, serviceSid, url, links, revision, data, dateExpires, dateCreated, dateUpdated, createdBy); + return Objects.hash( + sid, + uniqueName, + accountSid, + serviceSid, + url, + links, + revision, + data, + dateExpires, + dateCreated, + dateUpdated, + createdBy + ); } - } - diff --git a/src/main/java/com/twilio/rest/sync/v1/service/DocumentCreator.java b/src/main/java/com/twilio/rest/sync/v1/service/DocumentCreator.java index b6c9b6cf44..98ed959328 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/DocumentCreator.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/DocumentCreator.java @@ -15,8 +15,10 @@ package com.twilio.rest.sync.v1.service; import com.twilio.base.Creator; -import com.twilio.exception.ApiConnectionException; +import com.twilio.constant.EnumConstants; +import com.twilio.converter.Converter; import com.twilio.converter.Converter; +import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; @@ -25,13 +27,10 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.util.Map; -import com.twilio.converter.Converter; - import java.util.Map; +public class DocumentCreator extends Creator { - -public class DocumentCreator extends Creator{ private String pathServiceSid; private String uniqueName; private Map data; @@ -41,56 +40,69 @@ public DocumentCreator(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - public DocumentCreator setUniqueName(final String uniqueName){ + public DocumentCreator setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - public DocumentCreator setData(final Map data){ + + public DocumentCreator setData(final Map data) { this.data = data; return this; } - public DocumentCreator setTtl(final Integer ttl){ + + public DocumentCreator setTtl(final Integer ttl) { this.ttl = ttl; return this; } @Override - public Document create(final TwilioRestClient client){ + public Document create(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Documents"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.SYNC.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Document creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Document creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Document.fromJson(response.getStream(), client.getObjectMapper()); + return Document.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (uniqueName != null) { request.addPostParam("UniqueName", uniqueName); - } if (data != null) { - request.addPostParam("Data", Converter.mapToJson(data)); - + request.addPostParam("Data", Converter.mapToJson(data)); } if (ttl != null) { request.addPostParam("Ttl", ttl.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/sync/v1/service/DocumentDeleter.java b/src/main/java/com/twilio/rest/sync/v1/service/DocumentDeleter.java index d9a7290568..493130345c 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/DocumentDeleter.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/DocumentDeleter.java @@ -24,24 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class DocumentDeleter extends Deleter { + private String pathServiceSid; private String pathSid; - public DocumentDeleter(final String pathServiceSid, final String pathSid){ + public DocumentDeleter(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Documents/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +53,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Document delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Document delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/sync/v1/service/DocumentFetcher.java b/src/main/java/com/twilio/rest/sync/v1/service/DocumentFetcher.java index 3853a2bea8..89078a908e 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/DocumentFetcher.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/DocumentFetcher.java @@ -24,25 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class DocumentFetcher extends Fetcher { + private String pathServiceSid; private String pathSid; - public DocumentFetcher(final String pathServiceSid, final String pathSid){ + public DocumentFetcher(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - @Override public Document fetch(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Documents/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,15 +53,23 @@ public Document fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Document fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Document fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Document.fromJson(response.getStream(), client.getObjectMapper()); + return Document.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/sync/v1/service/DocumentReader.java b/src/main/java/com/twilio/rest/sync/v1/service/DocumentReader.java index e769c1b78e..664ac70637 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/DocumentReader.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/DocumentReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.sync.v1.service; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,19 +25,17 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class DocumentReader extends Reader { + private String pathServiceSid; private Integer pageSize; - public DocumentReader(final String pathServiceSid){ + public DocumentReader(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - public DocumentReader setPageSize(final Integer pageSize){ + public DocumentReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -48,7 +47,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Documents"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -60,13 +63,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Document read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Document read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +93,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reque } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.SYNC.toString()) @@ -90,9 +104,11 @@ public Page previousPage(final Page page, final TwilioRestCl return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.SYNC.toString()) @@ -101,21 +117,21 @@ public Page nextPage(final Page page, final TwilioRestClient } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/sync/v1/service/DocumentUpdater.java b/src/main/java/com/twilio/rest/sync/v1/service/DocumentUpdater.java index f72141140a..27c75df830 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/DocumentUpdater.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/DocumentUpdater.java @@ -15,8 +15,9 @@ package com.twilio.rest.sync.v1.service; import com.twilio.base.Updater; -import com.twilio.exception.ApiConnectionException; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Converter; +import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; @@ -24,77 +25,89 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - import java.util.Map; +public class DocumentUpdater extends Updater { -public class DocumentUpdater extends Updater{ private String pathServiceSid; private String pathSid; private String ifMatch; private Map data; private Integer ttl; - public DocumentUpdater(final String pathServiceSid, final String pathSid){ + public DocumentUpdater(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - public DocumentUpdater setIfMatch(final String ifMatch){ + public DocumentUpdater setIfMatch(final String ifMatch) { this.ifMatch = ifMatch; return this; } - public DocumentUpdater setData(final Map data){ + + public DocumentUpdater setData(final Map data) { this.data = data; return this; } - public DocumentUpdater setTtl(final Integer ttl){ + + public DocumentUpdater setTtl(final Integer ttl) { this.ttl = ttl; return this; } @Override - public Document update(final TwilioRestClient client){ + public Document update(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Documents/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.SYNC.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); addHeaderParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Document update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Document update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Document.fromJson(response.getStream(), client.getObjectMapper()); + return Document.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (data != null) { - request.addPostParam("Data", Converter.mapToJson(data)); - + request.addPostParam("Data", Converter.mapToJson(data)); } if (ttl != null) { request.addPostParam("Ttl", ttl.toString()); - } } + private void addHeaderParams(final Request request) { if (ifMatch != null) { request.addHeaderParam("If-Match", ifMatch); - } } } diff --git a/src/main/java/com/twilio/rest/sync/v1/service/SyncList.java b/src/main/java/com/twilio/rest/sync/v1/service/SyncList.java index a11ce4530d..33c65b1a69 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/SyncList.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/SyncList.java @@ -23,55 +23,63 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class SyncList extends Resource { + private static final long serialVersionUID = 91785924752769L; - public static SyncListCreator creator(final String pathServiceSid){ + public static SyncListCreator creator(final String pathServiceSid) { return new SyncListCreator(pathServiceSid); } - public static SyncListDeleter deleter(final String pathServiceSid, final String pathSid){ + public static SyncListDeleter deleter( + final String pathServiceSid, + final String pathSid + ) { return new SyncListDeleter(pathServiceSid, pathSid); } - public static SyncListFetcher fetcher(final String pathServiceSid, final String pathSid){ + public static SyncListFetcher fetcher( + final String pathServiceSid, + final String pathSid + ) { return new SyncListFetcher(pathServiceSid, pathSid); } - public static SyncListReader reader(final String pathServiceSid){ + public static SyncListReader reader(final String pathServiceSid) { return new SyncListReader(pathServiceSid); } - public static SyncListUpdater updater(final String pathServiceSid, final String pathSid){ + public static SyncListUpdater updater( + final String pathServiceSid, + final String pathSid + ) { return new SyncListUpdater(pathServiceSid, pathSid); } /** - * Converts a JSON String into a SyncList object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return SyncList object represented by the provided JSON - */ - public static SyncList fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a SyncList object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return SyncList object represented by the provided JSON + */ + public static SyncList fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SyncList.class); @@ -83,14 +91,17 @@ public static SyncList fromJson(final String json, final ObjectMapper objectMapp } /** - * Converts a JSON InputStream into a SyncList object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return SyncList object represented by the provided JSON - */ - public static SyncList fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a SyncList object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return SyncList object represented by the provided JSON + */ + public static SyncList fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SyncList.class); @@ -115,38 +126,17 @@ public static SyncList fromJson(final InputStream json, final ObjectMapper objec @JsonCreator private SyncList( - @JsonProperty("sid") - final String sid, - - @JsonProperty("unique_name") - final String uniqueName, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links, - - @JsonProperty("revision") - final String revision, - - @JsonProperty("date_expires") - final String dateExpires, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("created_by") - final String createdBy + @JsonProperty("sid") final String sid, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links, + @JsonProperty("revision") final String revision, + @JsonProperty("date_expires") final String dateExpires, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("created_by") final String createdBy ) { this.sid = sid; this.uniqueName = uniqueName; @@ -161,43 +151,53 @@ private SyncList( this.createdBy = createdBy; } - public final String getSid() { - return this.sid; - } - public final String getUniqueName() { - return this.uniqueName; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } - public final String getRevision() { - return this.revision; - } - public final ZonedDateTime getDateExpires() { - return this.dateExpires; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getCreatedBy() { - return this.createdBy; - } + public final String getSid() { + return this.sid; + } + + public final String getUniqueName() { + return this.uniqueName; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } + + public final String getRevision() { + return this.revision; + } + + public final ZonedDateTime getDateExpires() { + return this.dateExpires; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getCreatedBy() { + return this.createdBy; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -207,13 +207,35 @@ public boolean equals(final Object o) { SyncList other = (SyncList) o; - return Objects.equals(sid, other.sid) && Objects.equals(uniqueName, other.uniqueName) && Objects.equals(accountSid, other.accountSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(url, other.url) && Objects.equals(links, other.links) && Objects.equals(revision, other.revision) && Objects.equals(dateExpires, other.dateExpires) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(createdBy, other.createdBy) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) && + Objects.equals(revision, other.revision) && + Objects.equals(dateExpires, other.dateExpires) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(createdBy, other.createdBy) + ); } @Override public int hashCode() { - return Objects.hash(sid, uniqueName, accountSid, serviceSid, url, links, revision, dateExpires, dateCreated, dateUpdated, createdBy); + return Objects.hash( + sid, + uniqueName, + accountSid, + serviceSid, + url, + links, + revision, + dateExpires, + dateCreated, + dateUpdated, + createdBy + ); } - } - diff --git a/src/main/java/com/twilio/rest/sync/v1/service/SyncListCreator.java b/src/main/java/com/twilio/rest/sync/v1/service/SyncListCreator.java index c87486f5b2..3a180ae6a2 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/SyncListCreator.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/SyncListCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.sync.v1.service; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class SyncListCreator extends Creator { - - -public class SyncListCreator extends Creator{ private String pathServiceSid; private String uniqueName; private Integer ttl; @@ -37,56 +36,69 @@ public SyncListCreator(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - public SyncListCreator setUniqueName(final String uniqueName){ + public SyncListCreator setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - public SyncListCreator setTtl(final Integer ttl){ + + public SyncListCreator setTtl(final Integer ttl) { this.ttl = ttl; return this; } - public SyncListCreator setCollectionTtl(final Integer collectionTtl){ + + public SyncListCreator setCollectionTtl(final Integer collectionTtl) { this.collectionTtl = collectionTtl; return this; } @Override - public SyncList create(final TwilioRestClient client){ + public SyncList create(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Lists"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.SYNC.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncList creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "SyncList creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return SyncList.fromJson(response.getStream(), client.getObjectMapper()); + return SyncList.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (uniqueName != null) { request.addPostParam("UniqueName", uniqueName); - } if (ttl != null) { request.addPostParam("Ttl", ttl.toString()); - } if (collectionTtl != null) { request.addPostParam("CollectionTtl", collectionTtl.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/sync/v1/service/SyncListDeleter.java b/src/main/java/com/twilio/rest/sync/v1/service/SyncListDeleter.java index 6775843f07..309fb8c635 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/SyncListDeleter.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/SyncListDeleter.java @@ -24,24 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class SyncListDeleter extends Deleter { + private String pathServiceSid; private String pathSid; - public SyncListDeleter(final String pathServiceSid, final String pathSid){ + public SyncListDeleter(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Lists/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +53,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncList delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "SyncList delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/sync/v1/service/SyncListFetcher.java b/src/main/java/com/twilio/rest/sync/v1/service/SyncListFetcher.java index 6e3640dcc9..378f8ec5cb 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/SyncListFetcher.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/SyncListFetcher.java @@ -24,25 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class SyncListFetcher extends Fetcher { + private String pathServiceSid; private String pathSid; - public SyncListFetcher(final String pathServiceSid, final String pathSid){ + public SyncListFetcher(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - @Override public SyncList fetch(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Lists/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,15 +53,23 @@ public SyncList fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncList fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "SyncList fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return SyncList.fromJson(response.getStream(), client.getObjectMapper()); + return SyncList.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/sync/v1/service/SyncListReader.java b/src/main/java/com/twilio/rest/sync/v1/service/SyncListReader.java index e9ecc0e997..321d41d47b 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/SyncListReader.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/SyncListReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.sync.v1.service; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,19 +25,17 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class SyncListReader extends Reader { + private String pathServiceSid; private Integer pageSize; - public SyncListReader(final String pathServiceSid){ + public SyncListReader(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - public SyncListReader setPageSize(final Integer pageSize){ + public SyncListReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -48,7 +47,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Lists"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -60,13 +63,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncList read failed: Unable to connect to server"); + throw new ApiConnectionException( + "SyncList read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +93,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reque } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.SYNC.toString()) @@ -90,9 +104,11 @@ public Page previousPage(final Page page, final TwilioRestCl return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.SYNC.toString()) @@ -101,21 +117,21 @@ public Page nextPage(final Page page, final TwilioRestClient } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/sync/v1/service/SyncListUpdater.java b/src/main/java/com/twilio/rest/sync/v1/service/SyncListUpdater.java index 6308d3a401..29e4610e05 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/SyncListUpdater.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/SyncListUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.sync.v1.service; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,63 +25,74 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class SyncListUpdater extends Updater { - - -public class SyncListUpdater extends Updater{ private String pathServiceSid; private String pathSid; private Integer ttl; private Integer collectionTtl; - public SyncListUpdater(final String pathServiceSid, final String pathSid){ + public SyncListUpdater(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - public SyncListUpdater setTtl(final Integer ttl){ + public SyncListUpdater setTtl(final Integer ttl) { this.ttl = ttl; return this; } - public SyncListUpdater setCollectionTtl(final Integer collectionTtl){ + + public SyncListUpdater setCollectionTtl(final Integer collectionTtl) { this.collectionTtl = collectionTtl; return this; } @Override - public SyncList update(final TwilioRestClient client){ + public SyncList update(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Lists/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.SYNC.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncList update failed: Unable to connect to server"); + throw new ApiConnectionException( + "SyncList update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return SyncList.fromJson(response.getStream(), client.getObjectMapper()); + return SyncList.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (ttl != null) { request.addPostParam("Ttl", ttl.toString()); - } if (collectionTtl != null) { request.addPostParam("CollectionTtl", collectionTtl.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/sync/v1/service/SyncMap.java b/src/main/java/com/twilio/rest/sync/v1/service/SyncMap.java index 5a8603cf92..03df2a049f 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/SyncMap.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/SyncMap.java @@ -23,55 +23,63 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class SyncMap extends Resource { + private static final long serialVersionUID = 91785924752769L; - public static SyncMapCreator creator(final String pathServiceSid){ + public static SyncMapCreator creator(final String pathServiceSid) { return new SyncMapCreator(pathServiceSid); } - public static SyncMapDeleter deleter(final String pathServiceSid, final String pathSid){ + public static SyncMapDeleter deleter( + final String pathServiceSid, + final String pathSid + ) { return new SyncMapDeleter(pathServiceSid, pathSid); } - public static SyncMapFetcher fetcher(final String pathServiceSid, final String pathSid){ + public static SyncMapFetcher fetcher( + final String pathServiceSid, + final String pathSid + ) { return new SyncMapFetcher(pathServiceSid, pathSid); } - public static SyncMapReader reader(final String pathServiceSid){ + public static SyncMapReader reader(final String pathServiceSid) { return new SyncMapReader(pathServiceSid); } - public static SyncMapUpdater updater(final String pathServiceSid, final String pathSid){ + public static SyncMapUpdater updater( + final String pathServiceSid, + final String pathSid + ) { return new SyncMapUpdater(pathServiceSid, pathSid); } /** - * Converts a JSON String into a SyncMap object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return SyncMap object represented by the provided JSON - */ - public static SyncMap fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a SyncMap object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return SyncMap object represented by the provided JSON + */ + public static SyncMap fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SyncMap.class); @@ -83,14 +91,17 @@ public static SyncMap fromJson(final String json, final ObjectMapper objectMappe } /** - * Converts a JSON InputStream into a SyncMap object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return SyncMap object represented by the provided JSON - */ - public static SyncMap fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a SyncMap object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return SyncMap object represented by the provided JSON + */ + public static SyncMap fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SyncMap.class); @@ -115,38 +126,17 @@ public static SyncMap fromJson(final InputStream json, final ObjectMapper object @JsonCreator private SyncMap( - @JsonProperty("sid") - final String sid, - - @JsonProperty("unique_name") - final String uniqueName, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links, - - @JsonProperty("revision") - final String revision, - - @JsonProperty("date_expires") - final String dateExpires, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("created_by") - final String createdBy + @JsonProperty("sid") final String sid, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links, + @JsonProperty("revision") final String revision, + @JsonProperty("date_expires") final String dateExpires, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("created_by") final String createdBy ) { this.sid = sid; this.uniqueName = uniqueName; @@ -161,43 +151,53 @@ private SyncMap( this.createdBy = createdBy; } - public final String getSid() { - return this.sid; - } - public final String getUniqueName() { - return this.uniqueName; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } - public final String getRevision() { - return this.revision; - } - public final ZonedDateTime getDateExpires() { - return this.dateExpires; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getCreatedBy() { - return this.createdBy; - } + public final String getSid() { + return this.sid; + } + + public final String getUniqueName() { + return this.uniqueName; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } + + public final String getRevision() { + return this.revision; + } + + public final ZonedDateTime getDateExpires() { + return this.dateExpires; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getCreatedBy() { + return this.createdBy; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -207,13 +207,35 @@ public boolean equals(final Object o) { SyncMap other = (SyncMap) o; - return Objects.equals(sid, other.sid) && Objects.equals(uniqueName, other.uniqueName) && Objects.equals(accountSid, other.accountSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(url, other.url) && Objects.equals(links, other.links) && Objects.equals(revision, other.revision) && Objects.equals(dateExpires, other.dateExpires) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(createdBy, other.createdBy) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) && + Objects.equals(revision, other.revision) && + Objects.equals(dateExpires, other.dateExpires) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(createdBy, other.createdBy) + ); } @Override public int hashCode() { - return Objects.hash(sid, uniqueName, accountSid, serviceSid, url, links, revision, dateExpires, dateCreated, dateUpdated, createdBy); + return Objects.hash( + sid, + uniqueName, + accountSid, + serviceSid, + url, + links, + revision, + dateExpires, + dateCreated, + dateUpdated, + createdBy + ); } - } - diff --git a/src/main/java/com/twilio/rest/sync/v1/service/SyncMapCreator.java b/src/main/java/com/twilio/rest/sync/v1/service/SyncMapCreator.java index 8ad2a2f41f..046ed796e2 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/SyncMapCreator.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/SyncMapCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.sync.v1.service; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class SyncMapCreator extends Creator { - - -public class SyncMapCreator extends Creator{ private String pathServiceSid; private String uniqueName; private Integer ttl; @@ -37,36 +36,48 @@ public SyncMapCreator(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - public SyncMapCreator setUniqueName(final String uniqueName){ + public SyncMapCreator setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - public SyncMapCreator setTtl(final Integer ttl){ + + public SyncMapCreator setTtl(final Integer ttl) { this.ttl = ttl; return this; } - public SyncMapCreator setCollectionTtl(final Integer collectionTtl){ + + public SyncMapCreator setCollectionTtl(final Integer collectionTtl) { this.collectionTtl = collectionTtl; return this; } @Override - public SyncMap create(final TwilioRestClient client){ + public SyncMap create(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Maps"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.SYNC.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncMap creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "SyncMap creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -75,18 +86,16 @@ public SyncMap create(final TwilioRestClient client){ return SyncMap.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (uniqueName != null) { request.addPostParam("UniqueName", uniqueName); - } if (ttl != null) { request.addPostParam("Ttl", ttl.toString()); - } if (collectionTtl != null) { request.addPostParam("CollectionTtl", collectionTtl.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/sync/v1/service/SyncMapDeleter.java b/src/main/java/com/twilio/rest/sync/v1/service/SyncMapDeleter.java index 0d19851f04..0b399e98e6 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/SyncMapDeleter.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/SyncMapDeleter.java @@ -24,24 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class SyncMapDeleter extends Deleter { + private String pathServiceSid; private String pathSid; - public SyncMapDeleter(final String pathServiceSid, final String pathSid){ + public SyncMapDeleter(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Maps/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +53,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncMap delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "SyncMap delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/sync/v1/service/SyncMapFetcher.java b/src/main/java/com/twilio/rest/sync/v1/service/SyncMapFetcher.java index e16fab916e..fe98c57edd 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/SyncMapFetcher.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/SyncMapFetcher.java @@ -24,25 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class SyncMapFetcher extends Fetcher { + private String pathServiceSid; private String pathSid; - public SyncMapFetcher(final String pathServiceSid, final String pathSid){ + public SyncMapFetcher(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - @Override public SyncMap fetch(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Maps/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,9 +53,14 @@ public SyncMap fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncMap fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "SyncMap fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/sync/v1/service/SyncMapReader.java b/src/main/java/com/twilio/rest/sync/v1/service/SyncMapReader.java index aa5d305b30..20e4f77f2e 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/SyncMapReader.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/SyncMapReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.sync.v1.service; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,19 +25,17 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class SyncMapReader extends Reader { + private String pathServiceSid; private Integer pageSize; - public SyncMapReader(final String pathServiceSid){ + public SyncMapReader(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - public SyncMapReader setPageSize(final Integer pageSize){ + public SyncMapReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -48,7 +47,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Maps"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -60,13 +63,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncMap read failed: Unable to connect to server"); + throw new ApiConnectionException( + "SyncMap read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +93,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reques } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.SYNC.toString()) @@ -90,9 +104,11 @@ public Page previousPage(final Page page, final TwilioRestClie return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.SYNC.toString()) @@ -101,21 +117,21 @@ public Page nextPage(final Page page, final TwilioRestClient c } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/sync/v1/service/SyncMapUpdater.java b/src/main/java/com/twilio/rest/sync/v1/service/SyncMapUpdater.java index f40a9df919..19c925b33f 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/SyncMapUpdater.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/SyncMapUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.sync.v1.service; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,47 +25,56 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class SyncMapUpdater extends Updater { - - -public class SyncMapUpdater extends Updater{ private String pathServiceSid; private String pathSid; private Integer ttl; private Integer collectionTtl; - public SyncMapUpdater(final String pathServiceSid, final String pathSid){ + public SyncMapUpdater(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - public SyncMapUpdater setTtl(final Integer ttl){ + public SyncMapUpdater setTtl(final Integer ttl) { this.ttl = ttl; return this; } - public SyncMapUpdater setCollectionTtl(final Integer collectionTtl){ + + public SyncMapUpdater setCollectionTtl(final Integer collectionTtl) { this.collectionTtl = collectionTtl; return this; } @Override - public SyncMap update(final TwilioRestClient client){ + public SyncMap update(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Maps/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.SYNC.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncMap update failed: Unable to connect to server"); + throw new ApiConnectionException( + "SyncMap update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -73,14 +83,13 @@ public SyncMap update(final TwilioRestClient client){ return SyncMap.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (ttl != null) { request.addPostParam("Ttl", ttl.toString()); - } if (collectionTtl != null) { request.addPostParam("CollectionTtl", collectionTtl.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/sync/v1/service/SyncStream.java b/src/main/java/com/twilio/rest/sync/v1/service/SyncStream.java index eb65877be5..3a7c914b96 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/SyncStream.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/SyncStream.java @@ -23,55 +23,63 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class SyncStream extends Resource { + private static final long serialVersionUID = 122709874652370L; - public static SyncStreamCreator creator(final String pathServiceSid){ + public static SyncStreamCreator creator(final String pathServiceSid) { return new SyncStreamCreator(pathServiceSid); } - public static SyncStreamDeleter deleter(final String pathServiceSid, final String pathSid){ + public static SyncStreamDeleter deleter( + final String pathServiceSid, + final String pathSid + ) { return new SyncStreamDeleter(pathServiceSid, pathSid); } - public static SyncStreamFetcher fetcher(final String pathServiceSid, final String pathSid){ + public static SyncStreamFetcher fetcher( + final String pathServiceSid, + final String pathSid + ) { return new SyncStreamFetcher(pathServiceSid, pathSid); } - public static SyncStreamReader reader(final String pathServiceSid){ + public static SyncStreamReader reader(final String pathServiceSid) { return new SyncStreamReader(pathServiceSid); } - public static SyncStreamUpdater updater(final String pathServiceSid, final String pathSid){ + public static SyncStreamUpdater updater( + final String pathServiceSid, + final String pathSid + ) { return new SyncStreamUpdater(pathServiceSid, pathSid); } /** - * Converts a JSON String into a SyncStream object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return SyncStream object represented by the provided JSON - */ - public static SyncStream fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a SyncStream object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return SyncStream object represented by the provided JSON + */ + public static SyncStream fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SyncStream.class); @@ -83,14 +91,17 @@ public static SyncStream fromJson(final String json, final ObjectMapper objectMa } /** - * Converts a JSON InputStream into a SyncStream object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return SyncStream object represented by the provided JSON - */ - public static SyncStream fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a SyncStream object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return SyncStream object represented by the provided JSON + */ + public static SyncStream fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SyncStream.class); @@ -114,35 +125,16 @@ public static SyncStream fromJson(final InputStream json, final ObjectMapper obj @JsonCreator private SyncStream( - @JsonProperty("sid") - final String sid, - - @JsonProperty("unique_name") - final String uniqueName, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links, - - @JsonProperty("date_expires") - final String dateExpires, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("created_by") - final String createdBy + @JsonProperty("sid") final String sid, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links, + @JsonProperty("date_expires") final String dateExpires, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("created_by") final String createdBy ) { this.sid = sid; this.uniqueName = uniqueName; @@ -156,40 +148,49 @@ private SyncStream( this.createdBy = createdBy; } - public final String getSid() { - return this.sid; - } - public final String getUniqueName() { - return this.uniqueName; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } - public final ZonedDateTime getDateExpires() { - return this.dateExpires; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getCreatedBy() { - return this.createdBy; - } + public final String getSid() { + return this.sid; + } + + public final String getUniqueName() { + return this.uniqueName; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } + + public final ZonedDateTime getDateExpires() { + return this.dateExpires; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getCreatedBy() { + return this.createdBy; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -199,13 +200,33 @@ public boolean equals(final Object o) { SyncStream other = (SyncStream) o; - return Objects.equals(sid, other.sid) && Objects.equals(uniqueName, other.uniqueName) && Objects.equals(accountSid, other.accountSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(url, other.url) && Objects.equals(links, other.links) && Objects.equals(dateExpires, other.dateExpires) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(createdBy, other.createdBy) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) && + Objects.equals(dateExpires, other.dateExpires) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(createdBy, other.createdBy) + ); } @Override public int hashCode() { - return Objects.hash(sid, uniqueName, accountSid, serviceSid, url, links, dateExpires, dateCreated, dateUpdated, createdBy); + return Objects.hash( + sid, + uniqueName, + accountSid, + serviceSid, + url, + links, + dateExpires, + dateCreated, + dateUpdated, + createdBy + ); } - } - diff --git a/src/main/java/com/twilio/rest/sync/v1/service/SyncStreamCreator.java b/src/main/java/com/twilio/rest/sync/v1/service/SyncStreamCreator.java index b483ae5aba..c7269ad6ee 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/SyncStreamCreator.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/SyncStreamCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.sync.v1.service; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class SyncStreamCreator extends Creator { - - -public class SyncStreamCreator extends Creator{ private String pathServiceSid; private String uniqueName; private Integer ttl; @@ -36,48 +35,61 @@ public SyncStreamCreator(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - public SyncStreamCreator setUniqueName(final String uniqueName){ + public SyncStreamCreator setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - public SyncStreamCreator setTtl(final Integer ttl){ + + public SyncStreamCreator setTtl(final Integer ttl) { this.ttl = ttl; return this; } @Override - public SyncStream create(final TwilioRestClient client){ + public SyncStream create(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Streams"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.SYNC.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncStream creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "SyncStream creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return SyncStream.fromJson(response.getStream(), client.getObjectMapper()); + return SyncStream.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (uniqueName != null) { request.addPostParam("UniqueName", uniqueName); - } if (ttl != null) { request.addPostParam("Ttl", ttl.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/sync/v1/service/SyncStreamDeleter.java b/src/main/java/com/twilio/rest/sync/v1/service/SyncStreamDeleter.java index 23a66494a8..56f77f1eb7 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/SyncStreamDeleter.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/SyncStreamDeleter.java @@ -24,24 +24,29 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class SyncStreamDeleter extends Deleter { + private String pathServiceSid; private String pathSid; - public SyncStreamDeleter(final String pathServiceSid, final String pathSid){ + public SyncStreamDeleter( + final String pathServiceSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Streams/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +56,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncStream delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "SyncStream delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/sync/v1/service/SyncStreamFetcher.java b/src/main/java/com/twilio/rest/sync/v1/service/SyncStreamFetcher.java index 0a853b4071..7c9013a8c3 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/SyncStreamFetcher.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/SyncStreamFetcher.java @@ -24,25 +24,29 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class SyncStreamFetcher extends Fetcher { + private String pathServiceSid; private String pathSid; - public SyncStreamFetcher(final String pathServiceSid, final String pathSid){ + public SyncStreamFetcher( + final String pathServiceSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - @Override public SyncStream fetch(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Streams/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,15 +56,23 @@ public SyncStream fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncStream fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "SyncStream fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return SyncStream.fromJson(response.getStream(), client.getObjectMapper()); + return SyncStream.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/sync/v1/service/SyncStreamReader.java b/src/main/java/com/twilio/rest/sync/v1/service/SyncStreamReader.java index bc0dcbe326..1c89785ccb 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/SyncStreamReader.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/SyncStreamReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.sync.v1.service; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,19 +25,17 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class SyncStreamReader extends Reader { + private String pathServiceSid; private Integer pageSize; - public SyncStreamReader(final String pathServiceSid){ + public SyncStreamReader(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - public SyncStreamReader setPageSize(final Integer pageSize){ + public SyncStreamReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -48,7 +47,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Streams"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -60,13 +63,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncStream read failed: Unable to connect to server"); + throw new ApiConnectionException( + "SyncStream read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +93,10 @@ private Page pageForRequest(final TwilioRestClient client, final Req } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.SYNC.toString()) @@ -90,9 +104,11 @@ public Page previousPage(final Page page, final TwilioRe return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.SYNC.toString()) @@ -101,21 +117,21 @@ public Page nextPage(final Page page, final TwilioRestCl } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/sync/v1/service/SyncStreamUpdater.java b/src/main/java/com/twilio/rest/sync/v1/service/SyncStreamUpdater.java index 8a2a26374a..3f73eab44d 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/SyncStreamUpdater.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/SyncStreamUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.sync.v1.service; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,54 +25,68 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class SyncStreamUpdater extends Updater { - - -public class SyncStreamUpdater extends Updater{ private String pathServiceSid; private String pathSid; private Integer ttl; - public SyncStreamUpdater(final String pathServiceSid, final String pathSid){ + public SyncStreamUpdater( + final String pathServiceSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - public SyncStreamUpdater setTtl(final Integer ttl){ + public SyncStreamUpdater setTtl(final Integer ttl) { this.ttl = ttl; return this; } @Override - public SyncStream update(final TwilioRestClient client){ + public SyncStream update(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Streams/{Sid}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.SYNC.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncStream update failed: Unable to connect to server"); + throw new ApiConnectionException( + "SyncStream update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return SyncStream.fromJson(response.getStream(), client.getObjectMapper()); + return SyncStream.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (ttl != null) { request.addPostParam("Ttl", ttl.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/sync/v1/service/document/DocumentPermission.java b/src/main/java/com/twilio/rest/sync/v1/service/document/DocumentPermission.java index e4ca46e7fb..a54ffa47b6 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/document/DocumentPermission.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/document/DocumentPermission.java @@ -22,48 +22,80 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class DocumentPermission extends Resource { + private static final long serialVersionUID = 90173038651529L; - public static DocumentPermissionDeleter deleter(final String pathServiceSid, final String pathDocumentSid, final String pathIdentity){ - return new DocumentPermissionDeleter(pathServiceSid, pathDocumentSid, pathIdentity); + public static DocumentPermissionDeleter deleter( + final String pathServiceSid, + final String pathDocumentSid, + final String pathIdentity + ) { + return new DocumentPermissionDeleter( + pathServiceSid, + pathDocumentSid, + pathIdentity + ); } - public static DocumentPermissionFetcher fetcher(final String pathServiceSid, final String pathDocumentSid, final String pathIdentity){ - return new DocumentPermissionFetcher(pathServiceSid, pathDocumentSid, pathIdentity); + public static DocumentPermissionFetcher fetcher( + final String pathServiceSid, + final String pathDocumentSid, + final String pathIdentity + ) { + return new DocumentPermissionFetcher( + pathServiceSid, + pathDocumentSid, + pathIdentity + ); } - public static DocumentPermissionReader reader(final String pathServiceSid, final String pathDocumentSid){ + public static DocumentPermissionReader reader( + final String pathServiceSid, + final String pathDocumentSid + ) { return new DocumentPermissionReader(pathServiceSid, pathDocumentSid); } - public static DocumentPermissionUpdater updater(final String pathServiceSid, final String pathDocumentSid, final String pathIdentity, final Boolean read, final Boolean write, final Boolean manage){ - return new DocumentPermissionUpdater(pathServiceSid, pathDocumentSid, pathIdentity, read, write, manage); + public static DocumentPermissionUpdater updater( + final String pathServiceSid, + final String pathDocumentSid, + final String pathIdentity, + final Boolean read, + final Boolean write, + final Boolean manage + ) { + return new DocumentPermissionUpdater( + pathServiceSid, + pathDocumentSid, + pathIdentity, + read, + write, + manage + ); } /** - * Converts a JSON String into a DocumentPermission object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return DocumentPermission object represented by the provided JSON - */ - public static DocumentPermission fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a DocumentPermission object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return DocumentPermission object represented by the provided JSON + */ + public static DocumentPermission fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, DocumentPermission.class); @@ -75,14 +107,17 @@ public static DocumentPermission fromJson(final String json, final ObjectMapper } /** - * Converts a JSON InputStream into a DocumentPermission object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return DocumentPermission object represented by the provided JSON - */ - public static DocumentPermission fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a DocumentPermission object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return DocumentPermission object represented by the provided JSON + */ + public static DocumentPermission fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, DocumentPermission.class); @@ -104,29 +139,14 @@ public static DocumentPermission fromJson(final InputStream json, final ObjectMa @JsonCreator private DocumentPermission( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("document_sid") - final String documentSid, - - @JsonProperty("identity") - final String identity, - - @JsonProperty("read") - final Boolean read, - - @JsonProperty("write") - final Boolean write, - - @JsonProperty("manage") - final Boolean manage, - - @JsonProperty("url") - final URI url + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("document_sid") final String documentSid, + @JsonProperty("identity") final String identity, + @JsonProperty("read") final Boolean read, + @JsonProperty("write") final Boolean write, + @JsonProperty("manage") final Boolean manage, + @JsonProperty("url") final URI url ) { this.accountSid = accountSid; this.serviceSid = serviceSid; @@ -138,34 +158,41 @@ private DocumentPermission( this.url = url; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final String getDocumentSid() { - return this.documentSid; - } - public final String getIdentity() { - return this.identity; - } - public final Boolean getRead() { - return this.read; - } - public final Boolean getWrite() { - return this.write; - } - public final Boolean getManage() { - return this.manage; - } - public final URI getUrl() { - return this.url; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final String getDocumentSid() { + return this.documentSid; + } + + public final String getIdentity() { + return this.identity; + } + + public final Boolean getRead() { + return this.read; + } + + public final Boolean getWrite() { + return this.write; + } + + public final Boolean getManage() { + return this.manage; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -175,13 +202,29 @@ public boolean equals(final Object o) { DocumentPermission other = (DocumentPermission) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(documentSid, other.documentSid) && Objects.equals(identity, other.identity) && Objects.equals(read, other.read) && Objects.equals(write, other.write) && Objects.equals(manage, other.manage) && Objects.equals(url, other.url) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(documentSid, other.documentSid) && + Objects.equals(identity, other.identity) && + Objects.equals(read, other.read) && + Objects.equals(write, other.write) && + Objects.equals(manage, other.manage) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, serviceSid, documentSid, identity, read, write, manage, url); + return Objects.hash( + accountSid, + serviceSid, + documentSid, + identity, + read, + write, + manage, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/sync/v1/service/document/DocumentPermissionDeleter.java b/src/main/java/com/twilio/rest/sync/v1/service/document/DocumentPermissionDeleter.java index ad091193b1..b091eb58fc 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/document/DocumentPermissionDeleter.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/document/DocumentPermissionDeleter.java @@ -24,27 +24,39 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class DocumentPermissionDeleter extends Deleter { + private String pathServiceSid; private String pathDocumentSid; private String pathIdentity; - public DocumentPermissionDeleter(final String pathServiceSid, final String pathDocumentSid, final String pathIdentity){ + public DocumentPermissionDeleter( + final String pathServiceSid, + final String pathDocumentSid, + final String pathIdentity + ) { this.pathServiceSid = pathServiceSid; this.pathDocumentSid = pathDocumentSid; this.pathIdentity = pathIdentity; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/v1/Services/{ServiceSid}/Documents/{DocumentSid}/Permissions/{Identity}"; + String path = + "/v1/Services/{ServiceSid}/Documents/{DocumentSid}/Permissions/{Identity}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"DocumentSid"+"}", this.pathDocumentSid.toString()); - path = path.replace("{"+"Identity"+"}", this.pathIdentity.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "DocumentSid" + "}", + this.pathDocumentSid.toString() + ); + path = + path.replace("{" + "Identity" + "}", this.pathIdentity.toString()); Request request = new Request( HttpMethod.DELETE, @@ -54,9 +66,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("DocumentPermission delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "DocumentPermission delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/sync/v1/service/document/DocumentPermissionFetcher.java b/src/main/java/com/twilio/rest/sync/v1/service/document/DocumentPermissionFetcher.java index 344c13db6d..f56faeaf39 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/document/DocumentPermissionFetcher.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/document/DocumentPermissionFetcher.java @@ -24,28 +24,39 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class DocumentPermissionFetcher extends Fetcher { + private String pathServiceSid; private String pathDocumentSid; private String pathIdentity; - public DocumentPermissionFetcher(final String pathServiceSid, final String pathDocumentSid, final String pathIdentity){ + public DocumentPermissionFetcher( + final String pathServiceSid, + final String pathDocumentSid, + final String pathIdentity + ) { this.pathServiceSid = pathServiceSid; this.pathDocumentSid = pathDocumentSid; this.pathIdentity = pathIdentity; } - @Override public DocumentPermission fetch(final TwilioRestClient client) { - String path = "/v1/Services/{ServiceSid}/Documents/{DocumentSid}/Permissions/{Identity}"; + String path = + "/v1/Services/{ServiceSid}/Documents/{DocumentSid}/Permissions/{Identity}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"DocumentSid"+"}", this.pathDocumentSid.toString()); - path = path.replace("{"+"Identity"+"}", this.pathIdentity.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "DocumentSid" + "}", + this.pathDocumentSid.toString() + ); + path = + path.replace("{" + "Identity" + "}", this.pathIdentity.toString()); Request request = new Request( HttpMethod.GET, @@ -55,15 +66,23 @@ public DocumentPermission fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("DocumentPermission fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "DocumentPermission fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return DocumentPermission.fromJson(response.getStream(), client.getObjectMapper()); + return DocumentPermission.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/sync/v1/service/document/DocumentPermissionReader.java b/src/main/java/com/twilio/rest/sync/v1/service/document/DocumentPermissionReader.java index 50889511ee..219a7eaf20 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/document/DocumentPermissionReader.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/document/DocumentPermissionReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.sync.v1.service.document; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,21 +25,22 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class DocumentPermissionReader extends Reader { + private String pathServiceSid; private String pathDocumentSid; private Integer pageSize; - public DocumentPermissionReader(final String pathServiceSid, final String pathDocumentSid){ + public DocumentPermissionReader( + final String pathServiceSid, + final String pathDocumentSid + ) { this.pathServiceSid = pathServiceSid; this.pathDocumentSid = pathDocumentSid; } - public DocumentPermissionReader setPageSize(final Integer pageSize){ + public DocumentPermissionReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -49,9 +51,18 @@ public ResourceSet read(final TwilioRestClient client) { } public Page firstPage(final TwilioRestClient client) { - String path = "/v1/Services/{ServiceSid}/Documents/{DocumentSid}/Permissions"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"DocumentSid"+"}", this.pathDocumentSid.toString()); + String path = + "/v1/Services/{ServiceSid}/Documents/{DocumentSid}/Permissions"; + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "DocumentSid" + "}", + this.pathDocumentSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -63,13 +74,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("DocumentPermission read failed: Unable to connect to server"); + throw new ApiConnectionException( + "DocumentPermission read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -85,7 +104,10 @@ private Page pageForRequest(final TwilioRestClient client, f } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.SYNC.toString()) @@ -93,9 +115,11 @@ public Page previousPage(final Page page return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.SYNC.toString()) @@ -104,21 +128,21 @@ public Page nextPage(final Page page, fi } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/sync/v1/service/document/DocumentPermissionUpdater.java b/src/main/java/com/twilio/rest/sync/v1/service/document/DocumentPermissionUpdater.java index c5d273a0f8..189ad4daa2 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/document/DocumentPermissionUpdater.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/document/DocumentPermissionUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.sync.v1.service.document; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class DocumentPermissionUpdater extends Updater { - - -public class DocumentPermissionUpdater extends Updater{ private String pathServiceSid; private String pathDocumentSid; private String pathIdentity; @@ -35,7 +34,14 @@ public class DocumentPermissionUpdater extends Updater{ private Boolean write; private Boolean manage; - public DocumentPermissionUpdater(final String pathServiceSid, final String pathDocumentSid, final String pathIdentity, final Boolean read, final Boolean write, final Boolean manage){ + public DocumentPermissionUpdater( + final String pathServiceSid, + final String pathDocumentSid, + final String pathIdentity, + final Boolean read, + final Boolean write, + final Boolean manage + ) { this.pathServiceSid = pathServiceSid; this.pathDocumentSid = pathDocumentSid; this.pathIdentity = pathIdentity; @@ -44,61 +50,80 @@ public DocumentPermissionUpdater(final String pathServiceSid, final String pathD this.manage = manage; } - public DocumentPermissionUpdater setRead(final Boolean read){ + public DocumentPermissionUpdater setRead(final Boolean read) { this.read = read; return this; } - public DocumentPermissionUpdater setWrite(final Boolean write){ + + public DocumentPermissionUpdater setWrite(final Boolean write) { this.write = write; return this; } - public DocumentPermissionUpdater setManage(final Boolean manage){ + + public DocumentPermissionUpdater setManage(final Boolean manage) { this.manage = manage; return this; } @Override - public DocumentPermission update(final TwilioRestClient client){ - String path = "/v1/Services/{ServiceSid}/Documents/{DocumentSid}/Permissions/{Identity}"; + public DocumentPermission update(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Documents/{DocumentSid}/Permissions/{Identity}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"DocumentSid"+"}", this.pathDocumentSid.toString()); - path = path.replace("{"+"Identity"+"}", this.pathIdentity.toString()); - path = path.replace("{"+"Read"+"}", this.read.toString()); - path = path.replace("{"+"Write"+"}", this.write.toString()); - path = path.replace("{"+"Manage"+"}", this.manage.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "DocumentSid" + "}", + this.pathDocumentSid.toString() + ); + path = + path.replace("{" + "Identity" + "}", this.pathIdentity.toString()); + path = path.replace("{" + "Read" + "}", this.read.toString()); + path = path.replace("{" + "Write" + "}", this.write.toString()); + path = path.replace("{" + "Manage" + "}", this.manage.toString()); Request request = new Request( HttpMethod.POST, Domains.SYNC.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("DocumentPermission update failed: Unable to connect to server"); + throw new ApiConnectionException( + "DocumentPermission update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return DocumentPermission.fromJson(response.getStream(), client.getObjectMapper()); + return DocumentPermission.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (read != null) { request.addPostParam("Read", read.toString()); - } if (write != null) { request.addPostParam("Write", write.toString()); - } if (manage != null) { request.addPostParam("Manage", manage.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListItem.java b/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListItem.java index a4578ed9c2..5300c06515 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListItem.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListItem.java @@ -24,55 +24,73 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class SyncListItem extends Resource { + private static final long serialVersionUID = 92711713432732L; - public static SyncListItemCreator creator(final String pathServiceSid, final String pathListSid, final Map data){ + public static SyncListItemCreator creator( + final String pathServiceSid, + final String pathListSid, + final Map data + ) { return new SyncListItemCreator(pathServiceSid, pathListSid, data); } - public static SyncListItemDeleter deleter(final String pathServiceSid, final String pathListSid, final Integer pathIndex){ + public static SyncListItemDeleter deleter( + final String pathServiceSid, + final String pathListSid, + final Integer pathIndex + ) { return new SyncListItemDeleter(pathServiceSid, pathListSid, pathIndex); } - public static SyncListItemFetcher fetcher(final String pathServiceSid, final String pathListSid, final Integer pathIndex){ + public static SyncListItemFetcher fetcher( + final String pathServiceSid, + final String pathListSid, + final Integer pathIndex + ) { return new SyncListItemFetcher(pathServiceSid, pathListSid, pathIndex); } - public static SyncListItemReader reader(final String pathServiceSid, final String pathListSid){ + public static SyncListItemReader reader( + final String pathServiceSid, + final String pathListSid + ) { return new SyncListItemReader(pathServiceSid, pathListSid); } - public static SyncListItemUpdater updater(final String pathServiceSid, final String pathListSid, final Integer pathIndex){ + public static SyncListItemUpdater updater( + final String pathServiceSid, + final String pathListSid, + final Integer pathIndex + ) { return new SyncListItemUpdater(pathServiceSid, pathListSid, pathIndex); } /** - * Converts a JSON String into a SyncListItem object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return SyncListItem object represented by the provided JSON - */ - public static SyncListItem fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a SyncListItem object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return SyncListItem object represented by the provided JSON + */ + public static SyncListItem fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SyncListItem.class); @@ -84,14 +102,17 @@ public static SyncListItem fromJson(final String json, final ObjectMapper object } /** - * Converts a JSON InputStream into a SyncListItem object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return SyncListItem object represented by the provided JSON - */ - public static SyncListItem fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a SyncListItem object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return SyncListItem object represented by the provided JSON + */ + public static SyncListItem fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SyncListItem.class); @@ -101,6 +122,7 @@ public static SyncListItem fromJson(final InputStream json, final ObjectMapper o throw new ApiConnectionException(e.getMessage(), e); } } + public enum QueryFromBoundType { INCLUSIVE("inclusive"), EXCLUSIVE("exclusive"); @@ -120,6 +142,7 @@ public static QueryFromBoundType forValue(final String value) { return Promoter.enumFromString(value, QueryFromBoundType.values()); } } + public enum QueryResultOrder { ASC("asc"), DESC("desc"); @@ -154,38 +177,17 @@ public static QueryResultOrder forValue(final String value) { @JsonCreator private SyncListItem( - @JsonProperty("index") - final Integer index, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("list_sid") - final String listSid, - - @JsonProperty("url") - final URI url, - - @JsonProperty("revision") - final String revision, - - @JsonProperty("data") - final Map data, - - @JsonProperty("date_expires") - final String dateExpires, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("created_by") - final String createdBy + @JsonProperty("index") final Integer index, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("list_sid") final String listSid, + @JsonProperty("url") final URI url, + @JsonProperty("revision") final String revision, + @JsonProperty("data") final Map data, + @JsonProperty("date_expires") final String dateExpires, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("created_by") final String createdBy ) { this.index = index; this.accountSid = accountSid; @@ -200,43 +202,53 @@ private SyncListItem( this.createdBy = createdBy; } - public final Integer getIndex() { - return this.index; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final String getListSid() { - return this.listSid; - } - public final URI getUrl() { - return this.url; - } - public final String getRevision() { - return this.revision; - } - public final Map getData() { - return this.data; - } - public final ZonedDateTime getDateExpires() { - return this.dateExpires; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getCreatedBy() { - return this.createdBy; - } + public final Integer getIndex() { + return this.index; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final String getListSid() { + return this.listSid; + } + + public final URI getUrl() { + return this.url; + } + + public final String getRevision() { + return this.revision; + } + + public final Map getData() { + return this.data; + } + + public final ZonedDateTime getDateExpires() { + return this.dateExpires; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getCreatedBy() { + return this.createdBy; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -246,13 +258,35 @@ public boolean equals(final Object o) { SyncListItem other = (SyncListItem) o; - return Objects.equals(index, other.index) && Objects.equals(accountSid, other.accountSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(listSid, other.listSid) && Objects.equals(url, other.url) && Objects.equals(revision, other.revision) && Objects.equals(data, other.data) && Objects.equals(dateExpires, other.dateExpires) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(createdBy, other.createdBy) ; + return ( + Objects.equals(index, other.index) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(listSid, other.listSid) && + Objects.equals(url, other.url) && + Objects.equals(revision, other.revision) && + Objects.equals(data, other.data) && + Objects.equals(dateExpires, other.dateExpires) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(createdBy, other.createdBy) + ); } @Override public int hashCode() { - return Objects.hash(index, accountSid, serviceSid, listSid, url, revision, data, dateExpires, dateCreated, dateUpdated, createdBy); + return Objects.hash( + index, + accountSid, + serviceSid, + listSid, + url, + revision, + data, + dateExpires, + dateCreated, + dateUpdated, + createdBy + ); } - } - diff --git a/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListItemCreator.java b/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListItemCreator.java index cd8bea5e79..3125a6112c 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListItemCreator.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListItemCreator.java @@ -15,8 +15,10 @@ package com.twilio.rest.sync.v1.service.synclist; import com.twilio.base.Creator; -import com.twilio.exception.ApiConnectionException; +import com.twilio.constant.EnumConstants; +import com.twilio.converter.Converter; import com.twilio.converter.Converter; +import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; @@ -25,13 +27,10 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.util.Map; -import com.twilio.converter.Converter; - import java.util.Map; +public class SyncListItemCreator extends Creator { - -public class SyncListItemCreator extends Creator{ private String pathServiceSid; private String pathListSid; private Map data; @@ -39,72 +38,89 @@ public class SyncListItemCreator extends Creator{ private Integer itemTtl; private Integer collectionTtl; - public SyncListItemCreator(final String pathServiceSid, final String pathListSid, final Map data) { + public SyncListItemCreator( + final String pathServiceSid, + final String pathListSid, + final Map data + ) { this.pathServiceSid = pathServiceSid; this.pathListSid = pathListSid; this.data = data; } - public SyncListItemCreator setData(final Map data){ + public SyncListItemCreator setData(final Map data) { this.data = data; return this; } - public SyncListItemCreator setTtl(final Integer ttl){ + + public SyncListItemCreator setTtl(final Integer ttl) { this.ttl = ttl; return this; } - public SyncListItemCreator setItemTtl(final Integer itemTtl){ + + public SyncListItemCreator setItemTtl(final Integer itemTtl) { this.itemTtl = itemTtl; return this; } - public SyncListItemCreator setCollectionTtl(final Integer collectionTtl){ + + public SyncListItemCreator setCollectionTtl(final Integer collectionTtl) { this.collectionTtl = collectionTtl; return this; } @Override - public SyncListItem create(final TwilioRestClient client){ + public SyncListItem create(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Lists/{ListSid}/Items"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ListSid"+"}", this.pathListSid.toString()); - path = path.replace("{"+"Data"+"}", this.data.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "ListSid" + "}", this.pathListSid.toString()); + path = path.replace("{" + "Data" + "}", this.data.toString()); Request request = new Request( HttpMethod.POST, Domains.SYNC.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncListItem creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "SyncListItem creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return SyncListItem.fromJson(response.getStream(), client.getObjectMapper()); + return SyncListItem.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (data != null) { - request.addPostParam("Data", Converter.mapToJson(data)); - + request.addPostParam("Data", Converter.mapToJson(data)); } if (ttl != null) { request.addPostParam("Ttl", ttl.toString()); - } if (itemTtl != null) { request.addPostParam("ItemTtl", itemTtl.toString()); - } if (collectionTtl != null) { request.addPostParam("CollectionTtl", collectionTtl.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListItemDeleter.java b/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListItemDeleter.java index 6f2592402e..7924be7bd2 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListItemDeleter.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListItemDeleter.java @@ -24,21 +24,24 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class SyncListItemDeleter extends Deleter { + private String pathServiceSid; private String pathListSid; private Integer pathIndex; private String ifMatch; - public SyncListItemDeleter(final String pathServiceSid, final String pathListSid, final Integer pathIndex){ + public SyncListItemDeleter( + final String pathServiceSid, + final String pathListSid, + final Integer pathIndex + ) { this.pathServiceSid = pathServiceSid; this.pathListSid = pathListSid; this.pathIndex = pathIndex; } - public SyncListItemDeleter setIfMatch(final String ifMatch){ + public SyncListItemDeleter setIfMatch(final String ifMatch) { this.ifMatch = ifMatch; return this; } @@ -47,9 +50,13 @@ public SyncListItemDeleter setIfMatch(final String ifMatch){ public boolean delete(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Lists/{ListSid}/Items/{Index}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ListSid"+"}", this.pathListSid.toString()); - path = path.replace("{"+"Index"+"}", this.pathIndex.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "ListSid" + "}", this.pathListSid.toString()); + path = path.replace("{" + "Index" + "}", this.pathIndex.toString()); Request request = new Request( HttpMethod.DELETE, @@ -60,9 +67,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncListItem delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "SyncListItem delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -70,10 +82,10 @@ public boolean delete(final TwilioRestClient client) { } return response.getStatusCode() == 204; } + private void addHeaderParams(final Request request) { if (ifMatch != null) { request.addHeaderParam("If-Match", ifMatch); - } } } diff --git a/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListItemFetcher.java b/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListItemFetcher.java index 3645737d17..964868a2e0 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListItemFetcher.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListItemFetcher.java @@ -24,28 +24,33 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class SyncListItemFetcher extends Fetcher { + private String pathServiceSid; private String pathListSid; private Integer pathIndex; - public SyncListItemFetcher(final String pathServiceSid, final String pathListSid, final Integer pathIndex){ + public SyncListItemFetcher( + final String pathServiceSid, + final String pathListSid, + final Integer pathIndex + ) { this.pathServiceSid = pathServiceSid; this.pathListSid = pathListSid; this.pathIndex = pathIndex; } - @Override public SyncListItem fetch(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Lists/{ListSid}/Items/{Index}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ListSid"+"}", this.pathListSid.toString()); - path = path.replace("{"+"Index"+"}", this.pathIndex.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "ListSid" + "}", this.pathListSid.toString()); + path = path.replace("{" + "Index" + "}", this.pathIndex.toString()); Request request = new Request( HttpMethod.GET, @@ -55,15 +60,23 @@ public SyncListItem fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncListItem fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "SyncListItem fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return SyncListItem.fromJson(response.getStream(), client.getObjectMapper()); + return SyncListItem.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListItemReader.java b/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListItemReader.java index bd4f1cb0a9..5d63ac733d 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListItemReader.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListItemReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.sync.v1.service.synclist; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,11 +25,9 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class SyncListItemReader extends Reader { + private String pathServiceSid; private String pathListSid; private SyncListItem.QueryResultOrder order; @@ -36,24 +35,34 @@ public class SyncListItemReader extends Reader { private SyncListItem.QueryFromBoundType bounds; private Integer pageSize; - public SyncListItemReader(final String pathServiceSid, final String pathListSid){ + public SyncListItemReader( + final String pathServiceSid, + final String pathListSid + ) { this.pathServiceSid = pathServiceSid; this.pathListSid = pathListSid; } - public SyncListItemReader setOrder(final SyncListItem.QueryResultOrder order){ + public SyncListItemReader setOrder( + final SyncListItem.QueryResultOrder order + ) { this.order = order; return this; } - public SyncListItemReader setFrom(final String from){ + + public SyncListItemReader setFrom(final String from) { this.from = from; return this; } - public SyncListItemReader setBounds(final SyncListItem.QueryFromBoundType bounds){ + + public SyncListItemReader setBounds( + final SyncListItem.QueryFromBoundType bounds + ) { this.bounds = bounds; return this; } - public SyncListItemReader setPageSize(final Integer pageSize){ + + public SyncListItemReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -65,8 +74,12 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Lists/{ListSid}/Items"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ListSid"+"}", this.pathListSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "ListSid" + "}", this.pathListSid.toString()); Request request = new Request( HttpMethod.GET, @@ -78,13 +91,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncListItem read failed: Unable to connect to server"); + throw new ApiConnectionException( + "SyncListItem read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -100,7 +121,10 @@ private Page pageForRequest(final TwilioRestClient client, final R } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.SYNC.toString()) @@ -108,9 +132,11 @@ public Page previousPage(final Page page, final Twil return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.SYNC.toString()) @@ -119,33 +145,30 @@ public Page nextPage(final Page page, final TwilioRe } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (order != null) { - request.addQueryParam("Order", order.toString()); } if (from != null) { - request.addQueryParam("From", from); } if (bounds != null) { - request.addQueryParam("Bounds", bounds.toString()); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListItemUpdater.java b/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListItemUpdater.java index df4dda13f0..4ba258cc2f 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListItemUpdater.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListItemUpdater.java @@ -15,8 +15,9 @@ package com.twilio.rest.sync.v1.service.synclist; import com.twilio.base.Updater; -import com.twilio.exception.ApiConnectionException; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Converter; +import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; @@ -24,12 +25,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - import java.util.Map; +public class SyncListItemUpdater extends Updater { -public class SyncListItemUpdater extends Updater{ private String pathServiceSid; private String pathListSid; private Integer pathIndex; @@ -39,83 +38,101 @@ public class SyncListItemUpdater extends Updater{ private Integer itemTtl; private Integer collectionTtl; - public SyncListItemUpdater(final String pathServiceSid, final String pathListSid, final Integer pathIndex){ + public SyncListItemUpdater( + final String pathServiceSid, + final String pathListSid, + final Integer pathIndex + ) { this.pathServiceSid = pathServiceSid; this.pathListSid = pathListSid; this.pathIndex = pathIndex; } - public SyncListItemUpdater setIfMatch(final String ifMatch){ + public SyncListItemUpdater setIfMatch(final String ifMatch) { this.ifMatch = ifMatch; return this; } - public SyncListItemUpdater setData(final Map data){ + + public SyncListItemUpdater setData(final Map data) { this.data = data; return this; } - public SyncListItemUpdater setTtl(final Integer ttl){ + + public SyncListItemUpdater setTtl(final Integer ttl) { this.ttl = ttl; return this; } - public SyncListItemUpdater setItemTtl(final Integer itemTtl){ + + public SyncListItemUpdater setItemTtl(final Integer itemTtl) { this.itemTtl = itemTtl; return this; } - public SyncListItemUpdater setCollectionTtl(final Integer collectionTtl){ + + public SyncListItemUpdater setCollectionTtl(final Integer collectionTtl) { this.collectionTtl = collectionTtl; return this; } @Override - public SyncListItem update(final TwilioRestClient client){ + public SyncListItem update(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Lists/{ListSid}/Items/{Index}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ListSid"+"}", this.pathListSid.toString()); - path = path.replace("{"+"Index"+"}", this.pathIndex.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "ListSid" + "}", this.pathListSid.toString()); + path = path.replace("{" + "Index" + "}", this.pathIndex.toString()); Request request = new Request( HttpMethod.POST, Domains.SYNC.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); addHeaderParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncListItem update failed: Unable to connect to server"); + throw new ApiConnectionException( + "SyncListItem update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return SyncListItem.fromJson(response.getStream(), client.getObjectMapper()); + return SyncListItem.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (data != null) { - request.addPostParam("Data", Converter.mapToJson(data)); - + request.addPostParam("Data", Converter.mapToJson(data)); } if (ttl != null) { request.addPostParam("Ttl", ttl.toString()); - } if (itemTtl != null) { request.addPostParam("ItemTtl", itemTtl.toString()); - } if (collectionTtl != null) { request.addPostParam("CollectionTtl", collectionTtl.toString()); - } } + private void addHeaderParams(final Request request) { if (ifMatch != null) { request.addHeaderParam("If-Match", ifMatch); - } } } diff --git a/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListPermission.java b/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListPermission.java index 052d61baf6..fb68a96e40 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListPermission.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListPermission.java @@ -22,48 +22,80 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class SyncListPermission extends Resource { + private static final long serialVersionUID = 225550881347017L; - public static SyncListPermissionDeleter deleter(final String pathServiceSid, final String pathListSid, final String pathIdentity){ - return new SyncListPermissionDeleter(pathServiceSid, pathListSid, pathIdentity); + public static SyncListPermissionDeleter deleter( + final String pathServiceSid, + final String pathListSid, + final String pathIdentity + ) { + return new SyncListPermissionDeleter( + pathServiceSid, + pathListSid, + pathIdentity + ); } - public static SyncListPermissionFetcher fetcher(final String pathServiceSid, final String pathListSid, final String pathIdentity){ - return new SyncListPermissionFetcher(pathServiceSid, pathListSid, pathIdentity); + public static SyncListPermissionFetcher fetcher( + final String pathServiceSid, + final String pathListSid, + final String pathIdentity + ) { + return new SyncListPermissionFetcher( + pathServiceSid, + pathListSid, + pathIdentity + ); } - public static SyncListPermissionReader reader(final String pathServiceSid, final String pathListSid){ + public static SyncListPermissionReader reader( + final String pathServiceSid, + final String pathListSid + ) { return new SyncListPermissionReader(pathServiceSid, pathListSid); } - public static SyncListPermissionUpdater updater(final String pathServiceSid, final String pathListSid, final String pathIdentity, final Boolean read, final Boolean write, final Boolean manage){ - return new SyncListPermissionUpdater(pathServiceSid, pathListSid, pathIdentity, read, write, manage); + public static SyncListPermissionUpdater updater( + final String pathServiceSid, + final String pathListSid, + final String pathIdentity, + final Boolean read, + final Boolean write, + final Boolean manage + ) { + return new SyncListPermissionUpdater( + pathServiceSid, + pathListSid, + pathIdentity, + read, + write, + manage + ); } /** - * Converts a JSON String into a SyncListPermission object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return SyncListPermission object represented by the provided JSON - */ - public static SyncListPermission fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a SyncListPermission object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return SyncListPermission object represented by the provided JSON + */ + public static SyncListPermission fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SyncListPermission.class); @@ -75,14 +107,17 @@ public static SyncListPermission fromJson(final String json, final ObjectMapper } /** - * Converts a JSON InputStream into a SyncListPermission object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return SyncListPermission object represented by the provided JSON - */ - public static SyncListPermission fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a SyncListPermission object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return SyncListPermission object represented by the provided JSON + */ + public static SyncListPermission fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SyncListPermission.class); @@ -104,29 +139,14 @@ public static SyncListPermission fromJson(final InputStream json, final ObjectMa @JsonCreator private SyncListPermission( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("list_sid") - final String listSid, - - @JsonProperty("identity") - final String identity, - - @JsonProperty("read") - final Boolean read, - - @JsonProperty("write") - final Boolean write, - - @JsonProperty("manage") - final Boolean manage, - - @JsonProperty("url") - final URI url + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("list_sid") final String listSid, + @JsonProperty("identity") final String identity, + @JsonProperty("read") final Boolean read, + @JsonProperty("write") final Boolean write, + @JsonProperty("manage") final Boolean manage, + @JsonProperty("url") final URI url ) { this.accountSid = accountSid; this.serviceSid = serviceSid; @@ -138,34 +158,41 @@ private SyncListPermission( this.url = url; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final String getListSid() { - return this.listSid; - } - public final String getIdentity() { - return this.identity; - } - public final Boolean getRead() { - return this.read; - } - public final Boolean getWrite() { - return this.write; - } - public final Boolean getManage() { - return this.manage; - } - public final URI getUrl() { - return this.url; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final String getListSid() { + return this.listSid; + } + + public final String getIdentity() { + return this.identity; + } + + public final Boolean getRead() { + return this.read; + } + + public final Boolean getWrite() { + return this.write; + } + + public final Boolean getManage() { + return this.manage; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -175,13 +202,29 @@ public boolean equals(final Object o) { SyncListPermission other = (SyncListPermission) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(listSid, other.listSid) && Objects.equals(identity, other.identity) && Objects.equals(read, other.read) && Objects.equals(write, other.write) && Objects.equals(manage, other.manage) && Objects.equals(url, other.url) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(listSid, other.listSid) && + Objects.equals(identity, other.identity) && + Objects.equals(read, other.read) && + Objects.equals(write, other.write) && + Objects.equals(manage, other.manage) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, serviceSid, listSid, identity, read, write, manage, url); + return Objects.hash( + accountSid, + serviceSid, + listSid, + identity, + read, + write, + manage, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListPermissionDeleter.java b/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListPermissionDeleter.java index d2703b6e0c..c03576976f 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListPermissionDeleter.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListPermissionDeleter.java @@ -24,27 +24,35 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class SyncListPermissionDeleter extends Deleter { + private String pathServiceSid; private String pathListSid; private String pathIdentity; - public SyncListPermissionDeleter(final String pathServiceSid, final String pathListSid, final String pathIdentity){ + public SyncListPermissionDeleter( + final String pathServiceSid, + final String pathListSid, + final String pathIdentity + ) { this.pathServiceSid = pathServiceSid; this.pathListSid = pathListSid; this.pathIdentity = pathIdentity; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/v1/Services/{ServiceSid}/Lists/{ListSid}/Permissions/{Identity}"; + String path = + "/v1/Services/{ServiceSid}/Lists/{ListSid}/Permissions/{Identity}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ListSid"+"}", this.pathListSid.toString()); - path = path.replace("{"+"Identity"+"}", this.pathIdentity.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "ListSid" + "}", this.pathListSid.toString()); + path = + path.replace("{" + "Identity" + "}", this.pathIdentity.toString()); Request request = new Request( HttpMethod.DELETE, @@ -54,9 +62,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncListPermission delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "SyncListPermission delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListPermissionFetcher.java b/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListPermissionFetcher.java index 9d27e85c08..5c0a7bbe33 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListPermissionFetcher.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListPermissionFetcher.java @@ -24,28 +24,35 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class SyncListPermissionFetcher extends Fetcher { + private String pathServiceSid; private String pathListSid; private String pathIdentity; - public SyncListPermissionFetcher(final String pathServiceSid, final String pathListSid, final String pathIdentity){ + public SyncListPermissionFetcher( + final String pathServiceSid, + final String pathListSid, + final String pathIdentity + ) { this.pathServiceSid = pathServiceSid; this.pathListSid = pathListSid; this.pathIdentity = pathIdentity; } - @Override public SyncListPermission fetch(final TwilioRestClient client) { - String path = "/v1/Services/{ServiceSid}/Lists/{ListSid}/Permissions/{Identity}"; + String path = + "/v1/Services/{ServiceSid}/Lists/{ListSid}/Permissions/{Identity}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ListSid"+"}", this.pathListSid.toString()); - path = path.replace("{"+"Identity"+"}", this.pathIdentity.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "ListSid" + "}", this.pathListSid.toString()); + path = + path.replace("{" + "Identity" + "}", this.pathIdentity.toString()); Request request = new Request( HttpMethod.GET, @@ -55,15 +62,23 @@ public SyncListPermission fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncListPermission fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "SyncListPermission fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return SyncListPermission.fromJson(response.getStream(), client.getObjectMapper()); + return SyncListPermission.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListPermissionReader.java b/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListPermissionReader.java index 0b959b4822..3218f40ff9 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListPermissionReader.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListPermissionReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.sync.v1.service.synclist; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,21 +25,22 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class SyncListPermissionReader extends Reader { + private String pathServiceSid; private String pathListSid; private Integer pageSize; - public SyncListPermissionReader(final String pathServiceSid, final String pathListSid){ + public SyncListPermissionReader( + final String pathServiceSid, + final String pathListSid + ) { this.pathServiceSid = pathServiceSid; this.pathListSid = pathListSid; } - public SyncListPermissionReader setPageSize(final Integer pageSize){ + public SyncListPermissionReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -50,8 +52,12 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Lists/{ListSid}/Permissions"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ListSid"+"}", this.pathListSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "ListSid" + "}", this.pathListSid.toString()); Request request = new Request( HttpMethod.GET, @@ -63,13 +69,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncListPermission read failed: Unable to connect to server"); + throw new ApiConnectionException( + "SyncListPermission read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -85,7 +99,10 @@ private Page pageForRequest(final TwilioRestClient client, f } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.SYNC.toString()) @@ -93,9 +110,11 @@ public Page previousPage(final Page page return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.SYNC.toString()) @@ -104,21 +123,21 @@ public Page nextPage(final Page page, fi } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListPermissionUpdater.java b/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListPermissionUpdater.java index 341c6ed42b..7f2316386a 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListPermissionUpdater.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListPermissionUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.sync.v1.service.synclist; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class SyncListPermissionUpdater extends Updater { - - -public class SyncListPermissionUpdater extends Updater{ private String pathServiceSid; private String pathListSid; private String pathIdentity; @@ -35,7 +34,14 @@ public class SyncListPermissionUpdater extends Updater{ private Boolean write; private Boolean manage; - public SyncListPermissionUpdater(final String pathServiceSid, final String pathListSid, final String pathIdentity, final Boolean read, final Boolean write, final Boolean manage){ + public SyncListPermissionUpdater( + final String pathServiceSid, + final String pathListSid, + final String pathIdentity, + final Boolean read, + final Boolean write, + final Boolean manage + ) { this.pathServiceSid = pathServiceSid; this.pathListSid = pathListSid; this.pathIdentity = pathIdentity; @@ -44,61 +50,76 @@ public SyncListPermissionUpdater(final String pathServiceSid, final String pathL this.manage = manage; } - public SyncListPermissionUpdater setRead(final Boolean read){ + public SyncListPermissionUpdater setRead(final Boolean read) { this.read = read; return this; } - public SyncListPermissionUpdater setWrite(final Boolean write){ + + public SyncListPermissionUpdater setWrite(final Boolean write) { this.write = write; return this; } - public SyncListPermissionUpdater setManage(final Boolean manage){ + + public SyncListPermissionUpdater setManage(final Boolean manage) { this.manage = manage; return this; } @Override - public SyncListPermission update(final TwilioRestClient client){ - String path = "/v1/Services/{ServiceSid}/Lists/{ListSid}/Permissions/{Identity}"; + public SyncListPermission update(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Lists/{ListSid}/Permissions/{Identity}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"ListSid"+"}", this.pathListSid.toString()); - path = path.replace("{"+"Identity"+"}", this.pathIdentity.toString()); - path = path.replace("{"+"Read"+"}", this.read.toString()); - path = path.replace("{"+"Write"+"}", this.write.toString()); - path = path.replace("{"+"Manage"+"}", this.manage.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "ListSid" + "}", this.pathListSid.toString()); + path = + path.replace("{" + "Identity" + "}", this.pathIdentity.toString()); + path = path.replace("{" + "Read" + "}", this.read.toString()); + path = path.replace("{" + "Write" + "}", this.write.toString()); + path = path.replace("{" + "Manage" + "}", this.manage.toString()); Request request = new Request( HttpMethod.POST, Domains.SYNC.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncListPermission update failed: Unable to connect to server"); + throw new ApiConnectionException( + "SyncListPermission update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return SyncListPermission.fromJson(response.getStream(), client.getObjectMapper()); + return SyncListPermission.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (read != null) { request.addPostParam("Read", read.toString()); - } if (write != null) { request.addPostParam("Write", write.toString()); - } if (manage != null) { request.addPostParam("Manage", manage.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapItem.java b/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapItem.java index 9df02eb757..d9f7b2c38a 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapItem.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapItem.java @@ -24,55 +24,74 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class SyncMapItem extends Resource { + private static final long serialVersionUID = 156890229646336L; - public static SyncMapItemCreator creator(final String pathServiceSid, final String pathMapSid, final String key, final Map data){ + public static SyncMapItemCreator creator( + final String pathServiceSid, + final String pathMapSid, + final String key, + final Map data + ) { return new SyncMapItemCreator(pathServiceSid, pathMapSid, key, data); } - public static SyncMapItemDeleter deleter(final String pathServiceSid, final String pathMapSid, final String pathKey){ + public static SyncMapItemDeleter deleter( + final String pathServiceSid, + final String pathMapSid, + final String pathKey + ) { return new SyncMapItemDeleter(pathServiceSid, pathMapSid, pathKey); } - public static SyncMapItemFetcher fetcher(final String pathServiceSid, final String pathMapSid, final String pathKey){ + public static SyncMapItemFetcher fetcher( + final String pathServiceSid, + final String pathMapSid, + final String pathKey + ) { return new SyncMapItemFetcher(pathServiceSid, pathMapSid, pathKey); } - public static SyncMapItemReader reader(final String pathServiceSid, final String pathMapSid){ + public static SyncMapItemReader reader( + final String pathServiceSid, + final String pathMapSid + ) { return new SyncMapItemReader(pathServiceSid, pathMapSid); } - public static SyncMapItemUpdater updater(final String pathServiceSid, final String pathMapSid, final String pathKey){ + public static SyncMapItemUpdater updater( + final String pathServiceSid, + final String pathMapSid, + final String pathKey + ) { return new SyncMapItemUpdater(pathServiceSid, pathMapSid, pathKey); } /** - * Converts a JSON String into a SyncMapItem object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return SyncMapItem object represented by the provided JSON - */ - public static SyncMapItem fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a SyncMapItem object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return SyncMapItem object represented by the provided JSON + */ + public static SyncMapItem fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SyncMapItem.class); @@ -84,14 +103,17 @@ public static SyncMapItem fromJson(final String json, final ObjectMapper objectM } /** - * Converts a JSON InputStream into a SyncMapItem object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return SyncMapItem object represented by the provided JSON - */ - public static SyncMapItem fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a SyncMapItem object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return SyncMapItem object represented by the provided JSON + */ + public static SyncMapItem fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SyncMapItem.class); @@ -101,6 +123,7 @@ public static SyncMapItem fromJson(final InputStream json, final ObjectMapper ob throw new ApiConnectionException(e.getMessage(), e); } } + public enum QueryFromBoundType { INCLUSIVE("inclusive"), EXCLUSIVE("exclusive"); @@ -120,6 +143,7 @@ public static QueryFromBoundType forValue(final String value) { return Promoter.enumFromString(value, QueryFromBoundType.values()); } } + public enum QueryResultOrder { ASC("asc"), DESC("desc"); @@ -154,38 +178,17 @@ public static QueryResultOrder forValue(final String value) { @JsonCreator private SyncMapItem( - @JsonProperty("key") - final String key, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("map_sid") - final String mapSid, - - @JsonProperty("url") - final URI url, - - @JsonProperty("revision") - final String revision, - - @JsonProperty("data") - final Map data, - - @JsonProperty("date_expires") - final String dateExpires, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("created_by") - final String createdBy + @JsonProperty("key") final String key, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("map_sid") final String mapSid, + @JsonProperty("url") final URI url, + @JsonProperty("revision") final String revision, + @JsonProperty("data") final Map data, + @JsonProperty("date_expires") final String dateExpires, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("created_by") final String createdBy ) { this.key = key; this.accountSid = accountSid; @@ -200,43 +203,53 @@ private SyncMapItem( this.createdBy = createdBy; } - public final String getKey() { - return this.key; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final String getMapSid() { - return this.mapSid; - } - public final URI getUrl() { - return this.url; - } - public final String getRevision() { - return this.revision; - } - public final Map getData() { - return this.data; - } - public final ZonedDateTime getDateExpires() { - return this.dateExpires; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getCreatedBy() { - return this.createdBy; - } + public final String getKey() { + return this.key; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final String getMapSid() { + return this.mapSid; + } + + public final URI getUrl() { + return this.url; + } + + public final String getRevision() { + return this.revision; + } + + public final Map getData() { + return this.data; + } + + public final ZonedDateTime getDateExpires() { + return this.dateExpires; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getCreatedBy() { + return this.createdBy; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -246,13 +259,35 @@ public boolean equals(final Object o) { SyncMapItem other = (SyncMapItem) o; - return Objects.equals(key, other.key) && Objects.equals(accountSid, other.accountSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(mapSid, other.mapSid) && Objects.equals(url, other.url) && Objects.equals(revision, other.revision) && Objects.equals(data, other.data) && Objects.equals(dateExpires, other.dateExpires) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(createdBy, other.createdBy) ; + return ( + Objects.equals(key, other.key) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(mapSid, other.mapSid) && + Objects.equals(url, other.url) && + Objects.equals(revision, other.revision) && + Objects.equals(data, other.data) && + Objects.equals(dateExpires, other.dateExpires) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(createdBy, other.createdBy) + ); } @Override public int hashCode() { - return Objects.hash(key, accountSid, serviceSid, mapSid, url, revision, data, dateExpires, dateCreated, dateUpdated, createdBy); + return Objects.hash( + key, + accountSid, + serviceSid, + mapSid, + url, + revision, + data, + dateExpires, + dateCreated, + dateUpdated, + createdBy + ); } - } - diff --git a/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapItemCreator.java b/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapItemCreator.java index b482d4fecf..7118825b70 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapItemCreator.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapItemCreator.java @@ -15,8 +15,10 @@ package com.twilio.rest.sync.v1.service.syncmap; import com.twilio.base.Creator; -import com.twilio.exception.ApiConnectionException; +import com.twilio.constant.EnumConstants; +import com.twilio.converter.Converter; import com.twilio.converter.Converter; +import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; @@ -25,13 +27,10 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.util.Map; -import com.twilio.converter.Converter; - import java.util.Map; +public class SyncMapItemCreator extends Creator { - -public class SyncMapItemCreator extends Creator{ private String pathServiceSid; private String pathMapSid; private String key; @@ -40,82 +39,100 @@ public class SyncMapItemCreator extends Creator{ private Integer itemTtl; private Integer collectionTtl; - public SyncMapItemCreator(final String pathServiceSid, final String pathMapSid, final String key, final Map data) { + public SyncMapItemCreator( + final String pathServiceSid, + final String pathMapSid, + final String key, + final Map data + ) { this.pathServiceSid = pathServiceSid; this.pathMapSid = pathMapSid; this.key = key; this.data = data; } - public SyncMapItemCreator setKey(final String key){ + public SyncMapItemCreator setKey(final String key) { this.key = key; return this; } - public SyncMapItemCreator setData(final Map data){ + + public SyncMapItemCreator setData(final Map data) { this.data = data; return this; } - public SyncMapItemCreator setTtl(final Integer ttl){ + + public SyncMapItemCreator setTtl(final Integer ttl) { this.ttl = ttl; return this; } - public SyncMapItemCreator setItemTtl(final Integer itemTtl){ + + public SyncMapItemCreator setItemTtl(final Integer itemTtl) { this.itemTtl = itemTtl; return this; } - public SyncMapItemCreator setCollectionTtl(final Integer collectionTtl){ + + public SyncMapItemCreator setCollectionTtl(final Integer collectionTtl) { this.collectionTtl = collectionTtl; return this; } @Override - public SyncMapItem create(final TwilioRestClient client){ + public SyncMapItem create(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Maps/{MapSid}/Items"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"MapSid"+"}", this.pathMapSid.toString()); - path = path.replace("{"+"Key"+"}", this.key.toString()); - path = path.replace("{"+"Data"+"}", this.data.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "MapSid" + "}", this.pathMapSid.toString()); + path = path.replace("{" + "Key" + "}", this.key.toString()); + path = path.replace("{" + "Data" + "}", this.data.toString()); Request request = new Request( HttpMethod.POST, Domains.SYNC.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncMapItem creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "SyncMapItem creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return SyncMapItem.fromJson(response.getStream(), client.getObjectMapper()); + return SyncMapItem.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (key != null) { request.addPostParam("Key", key); - } if (data != null) { - request.addPostParam("Data", Converter.mapToJson(data)); - + request.addPostParam("Data", Converter.mapToJson(data)); } if (ttl != null) { request.addPostParam("Ttl", ttl.toString()); - } if (itemTtl != null) { request.addPostParam("ItemTtl", itemTtl.toString()); - } if (collectionTtl != null) { request.addPostParam("CollectionTtl", collectionTtl.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapItemDeleter.java b/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapItemDeleter.java index 292f840faa..87d8015f59 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapItemDeleter.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapItemDeleter.java @@ -24,21 +24,24 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class SyncMapItemDeleter extends Deleter { + private String pathServiceSid; private String pathMapSid; private String pathKey; private String ifMatch; - public SyncMapItemDeleter(final String pathServiceSid, final String pathMapSid, final String pathKey){ + public SyncMapItemDeleter( + final String pathServiceSid, + final String pathMapSid, + final String pathKey + ) { this.pathServiceSid = pathServiceSid; this.pathMapSid = pathMapSid; this.pathKey = pathKey; } - public SyncMapItemDeleter setIfMatch(final String ifMatch){ + public SyncMapItemDeleter setIfMatch(final String ifMatch) { this.ifMatch = ifMatch; return this; } @@ -47,9 +50,13 @@ public SyncMapItemDeleter setIfMatch(final String ifMatch){ public boolean delete(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Maps/{MapSid}/Items/{Key}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"MapSid"+"}", this.pathMapSid.toString()); - path = path.replace("{"+"Key"+"}", this.pathKey.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "MapSid" + "}", this.pathMapSid.toString()); + path = path.replace("{" + "Key" + "}", this.pathKey.toString()); Request request = new Request( HttpMethod.DELETE, @@ -60,9 +67,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncMapItem delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "SyncMapItem delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -70,10 +82,10 @@ public boolean delete(final TwilioRestClient client) { } return response.getStatusCode() == 204; } + private void addHeaderParams(final Request request) { if (ifMatch != null) { request.addHeaderParam("If-Match", ifMatch); - } } } diff --git a/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapItemFetcher.java b/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapItemFetcher.java index c8887663c6..1414a43f6b 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapItemFetcher.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapItemFetcher.java @@ -24,28 +24,33 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class SyncMapItemFetcher extends Fetcher { + private String pathServiceSid; private String pathMapSid; private String pathKey; - public SyncMapItemFetcher(final String pathServiceSid, final String pathMapSid, final String pathKey){ + public SyncMapItemFetcher( + final String pathServiceSid, + final String pathMapSid, + final String pathKey + ) { this.pathServiceSid = pathServiceSid; this.pathMapSid = pathMapSid; this.pathKey = pathKey; } - @Override public SyncMapItem fetch(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Maps/{MapSid}/Items/{Key}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"MapSid"+"}", this.pathMapSid.toString()); - path = path.replace("{"+"Key"+"}", this.pathKey.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "MapSid" + "}", this.pathMapSid.toString()); + path = path.replace("{" + "Key" + "}", this.pathKey.toString()); Request request = new Request( HttpMethod.GET, @@ -55,15 +60,23 @@ public SyncMapItem fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncMapItem fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "SyncMapItem fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return SyncMapItem.fromJson(response.getStream(), client.getObjectMapper()); + return SyncMapItem.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapItemReader.java b/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapItemReader.java index 02871ae077..2ee39c9002 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapItemReader.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapItemReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.sync.v1.service.syncmap; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,11 +25,9 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class SyncMapItemReader extends Reader { + private String pathServiceSid; private String pathMapSid; private SyncMapItem.QueryResultOrder order; @@ -36,24 +35,34 @@ public class SyncMapItemReader extends Reader { private SyncMapItem.QueryFromBoundType bounds; private Integer pageSize; - public SyncMapItemReader(final String pathServiceSid, final String pathMapSid){ + public SyncMapItemReader( + final String pathServiceSid, + final String pathMapSid + ) { this.pathServiceSid = pathServiceSid; this.pathMapSid = pathMapSid; } - public SyncMapItemReader setOrder(final SyncMapItem.QueryResultOrder order){ + public SyncMapItemReader setOrder( + final SyncMapItem.QueryResultOrder order + ) { this.order = order; return this; } - public SyncMapItemReader setFrom(final String from){ + + public SyncMapItemReader setFrom(final String from) { this.from = from; return this; } - public SyncMapItemReader setBounds(final SyncMapItem.QueryFromBoundType bounds){ + + public SyncMapItemReader setBounds( + final SyncMapItem.QueryFromBoundType bounds + ) { this.bounds = bounds; return this; } - public SyncMapItemReader setPageSize(final Integer pageSize){ + + public SyncMapItemReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -65,8 +74,12 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Maps/{MapSid}/Items"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"MapSid"+"}", this.pathMapSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "MapSid" + "}", this.pathMapSid.toString()); Request request = new Request( HttpMethod.GET, @@ -78,13 +91,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncMapItem read failed: Unable to connect to server"); + throw new ApiConnectionException( + "SyncMapItem read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -100,7 +121,10 @@ private Page pageForRequest(final TwilioRestClient client, final Re } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.SYNC.toString()) @@ -108,9 +132,11 @@ public Page previousPage(final Page page, final Twilio return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.SYNC.toString()) @@ -119,33 +145,30 @@ public Page nextPage(final Page page, final TwilioRest } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (order != null) { - request.addQueryParam("Order", order.toString()); } if (from != null) { - request.addQueryParam("From", from); } if (bounds != null) { - request.addQueryParam("Bounds", bounds.toString()); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapItemUpdater.java b/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapItemUpdater.java index 6c8b382c7a..497d4af4da 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapItemUpdater.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapItemUpdater.java @@ -15,8 +15,9 @@ package com.twilio.rest.sync.v1.service.syncmap; import com.twilio.base.Updater; -import com.twilio.exception.ApiConnectionException; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Converter; +import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; @@ -24,12 +25,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - import java.util.Map; +public class SyncMapItemUpdater extends Updater { -public class SyncMapItemUpdater extends Updater{ private String pathServiceSid; private String pathMapSid; private String pathKey; @@ -39,83 +38,101 @@ public class SyncMapItemUpdater extends Updater{ private Integer itemTtl; private Integer collectionTtl; - public SyncMapItemUpdater(final String pathServiceSid, final String pathMapSid, final String pathKey){ + public SyncMapItemUpdater( + final String pathServiceSid, + final String pathMapSid, + final String pathKey + ) { this.pathServiceSid = pathServiceSid; this.pathMapSid = pathMapSid; this.pathKey = pathKey; } - public SyncMapItemUpdater setIfMatch(final String ifMatch){ + public SyncMapItemUpdater setIfMatch(final String ifMatch) { this.ifMatch = ifMatch; return this; } - public SyncMapItemUpdater setData(final Map data){ + + public SyncMapItemUpdater setData(final Map data) { this.data = data; return this; } - public SyncMapItemUpdater setTtl(final Integer ttl){ + + public SyncMapItemUpdater setTtl(final Integer ttl) { this.ttl = ttl; return this; } - public SyncMapItemUpdater setItemTtl(final Integer itemTtl){ + + public SyncMapItemUpdater setItemTtl(final Integer itemTtl) { this.itemTtl = itemTtl; return this; } - public SyncMapItemUpdater setCollectionTtl(final Integer collectionTtl){ + + public SyncMapItemUpdater setCollectionTtl(final Integer collectionTtl) { this.collectionTtl = collectionTtl; return this; } @Override - public SyncMapItem update(final TwilioRestClient client){ + public SyncMapItem update(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Maps/{MapSid}/Items/{Key}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"MapSid"+"}", this.pathMapSid.toString()); - path = path.replace("{"+"Key"+"}", this.pathKey.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "MapSid" + "}", this.pathMapSid.toString()); + path = path.replace("{" + "Key" + "}", this.pathKey.toString()); Request request = new Request( HttpMethod.POST, Domains.SYNC.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); addHeaderParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncMapItem update failed: Unable to connect to server"); + throw new ApiConnectionException( + "SyncMapItem update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return SyncMapItem.fromJson(response.getStream(), client.getObjectMapper()); + return SyncMapItem.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (data != null) { - request.addPostParam("Data", Converter.mapToJson(data)); - + request.addPostParam("Data", Converter.mapToJson(data)); } if (ttl != null) { request.addPostParam("Ttl", ttl.toString()); - } if (itemTtl != null) { request.addPostParam("ItemTtl", itemTtl.toString()); - } if (collectionTtl != null) { request.addPostParam("CollectionTtl", collectionTtl.toString()); - } } + private void addHeaderParams(final Request request) { if (ifMatch != null) { request.addHeaderParam("If-Match", ifMatch); - } } } diff --git a/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapPermission.java b/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapPermission.java index 28a8f022d5..013b9d4b9e 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapPermission.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapPermission.java @@ -22,48 +22,80 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class SyncMapPermission extends Resource { + private static final long serialVersionUID = 55149075645678L; - public static SyncMapPermissionDeleter deleter(final String pathServiceSid, final String pathMapSid, final String pathIdentity){ - return new SyncMapPermissionDeleter(pathServiceSid, pathMapSid, pathIdentity); + public static SyncMapPermissionDeleter deleter( + final String pathServiceSid, + final String pathMapSid, + final String pathIdentity + ) { + return new SyncMapPermissionDeleter( + pathServiceSid, + pathMapSid, + pathIdentity + ); } - public static SyncMapPermissionFetcher fetcher(final String pathServiceSid, final String pathMapSid, final String pathIdentity){ - return new SyncMapPermissionFetcher(pathServiceSid, pathMapSid, pathIdentity); + public static SyncMapPermissionFetcher fetcher( + final String pathServiceSid, + final String pathMapSid, + final String pathIdentity + ) { + return new SyncMapPermissionFetcher( + pathServiceSid, + pathMapSid, + pathIdentity + ); } - public static SyncMapPermissionReader reader(final String pathServiceSid, final String pathMapSid){ + public static SyncMapPermissionReader reader( + final String pathServiceSid, + final String pathMapSid + ) { return new SyncMapPermissionReader(pathServiceSid, pathMapSid); } - public static SyncMapPermissionUpdater updater(final String pathServiceSid, final String pathMapSid, final String pathIdentity, final Boolean read, final Boolean write, final Boolean manage){ - return new SyncMapPermissionUpdater(pathServiceSid, pathMapSid, pathIdentity, read, write, manage); + public static SyncMapPermissionUpdater updater( + final String pathServiceSid, + final String pathMapSid, + final String pathIdentity, + final Boolean read, + final Boolean write, + final Boolean manage + ) { + return new SyncMapPermissionUpdater( + pathServiceSid, + pathMapSid, + pathIdentity, + read, + write, + manage + ); } /** - * Converts a JSON String into a SyncMapPermission object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return SyncMapPermission object represented by the provided JSON - */ - public static SyncMapPermission fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a SyncMapPermission object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return SyncMapPermission object represented by the provided JSON + */ + public static SyncMapPermission fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SyncMapPermission.class); @@ -75,14 +107,17 @@ public static SyncMapPermission fromJson(final String json, final ObjectMapper o } /** - * Converts a JSON InputStream into a SyncMapPermission object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return SyncMapPermission object represented by the provided JSON - */ - public static SyncMapPermission fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a SyncMapPermission object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return SyncMapPermission object represented by the provided JSON + */ + public static SyncMapPermission fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SyncMapPermission.class); @@ -104,29 +139,14 @@ public static SyncMapPermission fromJson(final InputStream json, final ObjectMap @JsonCreator private SyncMapPermission( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("service_sid") - final String serviceSid, - - @JsonProperty("map_sid") - final String mapSid, - - @JsonProperty("identity") - final String identity, - - @JsonProperty("read") - final Boolean read, - - @JsonProperty("write") - final Boolean write, - - @JsonProperty("manage") - final Boolean manage, - - @JsonProperty("url") - final URI url + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("map_sid") final String mapSid, + @JsonProperty("identity") final String identity, + @JsonProperty("read") final Boolean read, + @JsonProperty("write") final Boolean write, + @JsonProperty("manage") final Boolean manage, + @JsonProperty("url") final URI url ) { this.accountSid = accountSid; this.serviceSid = serviceSid; @@ -138,34 +158,41 @@ private SyncMapPermission( this.url = url; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getServiceSid() { - return this.serviceSid; - } - public final String getMapSid() { - return this.mapSid; - } - public final String getIdentity() { - return this.identity; - } - public final Boolean getRead() { - return this.read; - } - public final Boolean getWrite() { - return this.write; - } - public final Boolean getManage() { - return this.manage; - } - public final URI getUrl() { - return this.url; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getServiceSid() { + return this.serviceSid; + } + + public final String getMapSid() { + return this.mapSid; + } + + public final String getIdentity() { + return this.identity; + } + + public final Boolean getRead() { + return this.read; + } + + public final Boolean getWrite() { + return this.write; + } + + public final Boolean getManage() { + return this.manage; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -175,13 +202,29 @@ public boolean equals(final Object o) { SyncMapPermission other = (SyncMapPermission) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(serviceSid, other.serviceSid) && Objects.equals(mapSid, other.mapSid) && Objects.equals(identity, other.identity) && Objects.equals(read, other.read) && Objects.equals(write, other.write) && Objects.equals(manage, other.manage) && Objects.equals(url, other.url) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(mapSid, other.mapSid) && + Objects.equals(identity, other.identity) && + Objects.equals(read, other.read) && + Objects.equals(write, other.write) && + Objects.equals(manage, other.manage) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, serviceSid, mapSid, identity, read, write, manage, url); + return Objects.hash( + accountSid, + serviceSid, + mapSid, + identity, + read, + write, + manage, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapPermissionDeleter.java b/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapPermissionDeleter.java index 9fb3ec93de..d0fde6d335 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapPermissionDeleter.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapPermissionDeleter.java @@ -24,27 +24,35 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class SyncMapPermissionDeleter extends Deleter { + private String pathServiceSid; private String pathMapSid; private String pathIdentity; - public SyncMapPermissionDeleter(final String pathServiceSid, final String pathMapSid, final String pathIdentity){ + public SyncMapPermissionDeleter( + final String pathServiceSid, + final String pathMapSid, + final String pathIdentity + ) { this.pathServiceSid = pathServiceSid; this.pathMapSid = pathMapSid; this.pathIdentity = pathIdentity; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/v1/Services/{ServiceSid}/Maps/{MapSid}/Permissions/{Identity}"; + String path = + "/v1/Services/{ServiceSid}/Maps/{MapSid}/Permissions/{Identity}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"MapSid"+"}", this.pathMapSid.toString()); - path = path.replace("{"+"Identity"+"}", this.pathIdentity.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "MapSid" + "}", this.pathMapSid.toString()); + path = + path.replace("{" + "Identity" + "}", this.pathIdentity.toString()); Request request = new Request( HttpMethod.DELETE, @@ -54,9 +62,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncMapPermission delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "SyncMapPermission delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapPermissionFetcher.java b/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapPermissionFetcher.java index 3da5e29d1e..e7450860f7 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapPermissionFetcher.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapPermissionFetcher.java @@ -24,28 +24,35 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class SyncMapPermissionFetcher extends Fetcher { + private String pathServiceSid; private String pathMapSid; private String pathIdentity; - public SyncMapPermissionFetcher(final String pathServiceSid, final String pathMapSid, final String pathIdentity){ + public SyncMapPermissionFetcher( + final String pathServiceSid, + final String pathMapSid, + final String pathIdentity + ) { this.pathServiceSid = pathServiceSid; this.pathMapSid = pathMapSid; this.pathIdentity = pathIdentity; } - @Override public SyncMapPermission fetch(final TwilioRestClient client) { - String path = "/v1/Services/{ServiceSid}/Maps/{MapSid}/Permissions/{Identity}"; + String path = + "/v1/Services/{ServiceSid}/Maps/{MapSid}/Permissions/{Identity}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"MapSid"+"}", this.pathMapSid.toString()); - path = path.replace("{"+"Identity"+"}", this.pathIdentity.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "MapSid" + "}", this.pathMapSid.toString()); + path = + path.replace("{" + "Identity" + "}", this.pathIdentity.toString()); Request request = new Request( HttpMethod.GET, @@ -55,15 +62,23 @@ public SyncMapPermission fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncMapPermission fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "SyncMapPermission fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return SyncMapPermission.fromJson(response.getStream(), client.getObjectMapper()); + return SyncMapPermission.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapPermissionReader.java b/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapPermissionReader.java index afeab7edbf..545e1a4733 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapPermissionReader.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapPermissionReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.sync.v1.service.syncmap; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,21 +25,22 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class SyncMapPermissionReader extends Reader { + private String pathServiceSid; private String pathMapSid; private Integer pageSize; - public SyncMapPermissionReader(final String pathServiceSid, final String pathMapSid){ + public SyncMapPermissionReader( + final String pathServiceSid, + final String pathMapSid + ) { this.pathServiceSid = pathServiceSid; this.pathMapSid = pathMapSid; } - public SyncMapPermissionReader setPageSize(final Integer pageSize){ + public SyncMapPermissionReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -50,8 +52,12 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Maps/{MapSid}/Permissions"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"MapSid"+"}", this.pathMapSid.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "MapSid" + "}", this.pathMapSid.toString()); Request request = new Request( HttpMethod.GET, @@ -63,13 +69,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncMapPermission read failed: Unable to connect to server"); + throw new ApiConnectionException( + "SyncMapPermission read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -85,7 +99,10 @@ private Page pageForRequest(final TwilioRestClient client, fi } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.SYNC.toString()) @@ -93,9 +110,11 @@ public Page previousPage(final Page page, return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.SYNC.toString()) @@ -104,21 +123,21 @@ public Page nextPage(final Page page, fina } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapPermissionUpdater.java b/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapPermissionUpdater.java index 9912fc2af5..8b50232596 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapPermissionUpdater.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapPermissionUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.sync.v1.service.syncmap; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class SyncMapPermissionUpdater extends Updater { - - -public class SyncMapPermissionUpdater extends Updater{ private String pathServiceSid; private String pathMapSid; private String pathIdentity; @@ -35,7 +34,14 @@ public class SyncMapPermissionUpdater extends Updater{ private Boolean write; private Boolean manage; - public SyncMapPermissionUpdater(final String pathServiceSid, final String pathMapSid, final String pathIdentity, final Boolean read, final Boolean write, final Boolean manage){ + public SyncMapPermissionUpdater( + final String pathServiceSid, + final String pathMapSid, + final String pathIdentity, + final Boolean read, + final Boolean write, + final Boolean manage + ) { this.pathServiceSid = pathServiceSid; this.pathMapSid = pathMapSid; this.pathIdentity = pathIdentity; @@ -44,61 +50,76 @@ public SyncMapPermissionUpdater(final String pathServiceSid, final String pathMa this.manage = manage; } - public SyncMapPermissionUpdater setRead(final Boolean read){ + public SyncMapPermissionUpdater setRead(final Boolean read) { this.read = read; return this; } - public SyncMapPermissionUpdater setWrite(final Boolean write){ + + public SyncMapPermissionUpdater setWrite(final Boolean write) { this.write = write; return this; } - public SyncMapPermissionUpdater setManage(final Boolean manage){ + + public SyncMapPermissionUpdater setManage(final Boolean manage) { this.manage = manage; return this; } @Override - public SyncMapPermission update(final TwilioRestClient client){ - String path = "/v1/Services/{ServiceSid}/Maps/{MapSid}/Permissions/{Identity}"; + public SyncMapPermission update(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Maps/{MapSid}/Permissions/{Identity}"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"MapSid"+"}", this.pathMapSid.toString()); - path = path.replace("{"+"Identity"+"}", this.pathIdentity.toString()); - path = path.replace("{"+"Read"+"}", this.read.toString()); - path = path.replace("{"+"Write"+"}", this.write.toString()); - path = path.replace("{"+"Manage"+"}", this.manage.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "MapSid" + "}", this.pathMapSid.toString()); + path = + path.replace("{" + "Identity" + "}", this.pathIdentity.toString()); + path = path.replace("{" + "Read" + "}", this.read.toString()); + path = path.replace("{" + "Write" + "}", this.write.toString()); + path = path.replace("{" + "Manage" + "}", this.manage.toString()); Request request = new Request( HttpMethod.POST, Domains.SYNC.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncMapPermission update failed: Unable to connect to server"); + throw new ApiConnectionException( + "SyncMapPermission update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return SyncMapPermission.fromJson(response.getStream(), client.getObjectMapper()); + return SyncMapPermission.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (read != null) { request.addPostParam("Read", read.toString()); - } if (write != null) { request.addPostParam("Write", write.toString()); - } if (manage != null) { request.addPostParam("Manage", manage.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/sync/v1/service/syncstream/StreamMessage.java b/src/main/java/com/twilio/rest/sync/v1/service/syncstream/StreamMessage.java index 96c5c7e4bc..7191f3acc2 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/syncstream/StreamMessage.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/syncstream/StreamMessage.java @@ -22,37 +22,40 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class StreamMessage extends Resource { + private static final long serialVersionUID = 233477236246646L; - public static StreamMessageCreator creator(final String pathServiceSid, final String pathStreamSid, final Map data){ + public static StreamMessageCreator creator( + final String pathServiceSid, + final String pathStreamSid, + final Map data + ) { return new StreamMessageCreator(pathServiceSid, pathStreamSid, data); } /** - * Converts a JSON String into a StreamMessage object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return StreamMessage object represented by the provided JSON - */ - public static StreamMessage fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a StreamMessage object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return StreamMessage object represented by the provided JSON + */ + public static StreamMessage fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, StreamMessage.class); @@ -64,14 +67,17 @@ public static StreamMessage fromJson(final String json, final ObjectMapper objec } /** - * Converts a JSON InputStream into a StreamMessage object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return StreamMessage object represented by the provided JSON - */ - public static StreamMessage fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a StreamMessage object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return StreamMessage object represented by the provided JSON + */ + public static StreamMessage fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, StreamMessage.class); @@ -87,26 +93,24 @@ public static StreamMessage fromJson(final InputStream json, final ObjectMapper @JsonCreator private StreamMessage( - @JsonProperty("sid") - final String sid, - - @JsonProperty("data") - final Map data + @JsonProperty("sid") final String sid, + @JsonProperty("data") final Map data ) { this.sid = sid; this.data = data; } - public final String getSid() { - return this.sid; - } - public final Map getData() { - return this.data; - } + public final String getSid() { + return this.sid; + } + + public final Map getData() { + return this.data; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -116,13 +120,13 @@ public boolean equals(final Object o) { StreamMessage other = (StreamMessage) o; - return Objects.equals(sid, other.sid) && Objects.equals(data, other.data) ; + return ( + Objects.equals(sid, other.sid) && Objects.equals(data, other.data) + ); } @Override public int hashCode() { return Objects.hash(sid, data); } - } - diff --git a/src/main/java/com/twilio/rest/sync/v1/service/syncstream/StreamMessageCreator.java b/src/main/java/com/twilio/rest/sync/v1/service/syncstream/StreamMessageCreator.java index 742758bc0f..50b46a5262 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/syncstream/StreamMessageCreator.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/syncstream/StreamMessageCreator.java @@ -15,8 +15,10 @@ package com.twilio.rest.sync.v1.service.syncstream; import com.twilio.base.Creator; -import com.twilio.exception.ApiConnectionException; +import com.twilio.constant.EnumConstants; +import com.twilio.converter.Converter; import com.twilio.converter.Converter; +import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; @@ -25,59 +27,77 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.util.Map; -import com.twilio.converter.Converter; - import java.util.Map; +public class StreamMessageCreator extends Creator { - -public class StreamMessageCreator extends Creator{ private String pathServiceSid; private String pathStreamSid; private Map data; - public StreamMessageCreator(final String pathServiceSid, final String pathStreamSid, final Map data) { + public StreamMessageCreator( + final String pathServiceSid, + final String pathStreamSid, + final Map data + ) { this.pathServiceSid = pathServiceSid; this.pathStreamSid = pathStreamSid; this.data = data; } - public StreamMessageCreator setData(final Map data){ + public StreamMessageCreator setData(final Map data) { this.data = data; return this; } @Override - public StreamMessage create(final TwilioRestClient client){ + public StreamMessage create(final TwilioRestClient client) { String path = "/v1/Services/{ServiceSid}/Streams/{StreamSid}/Messages"; - path = path.replace("{"+"ServiceSid"+"}", this.pathServiceSid.toString()); - path = path.replace("{"+"StreamSid"+"}", this.pathStreamSid.toString()); - path = path.replace("{"+"Data"+"}", this.data.toString()); + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "StreamSid" + "}", + this.pathStreamSid.toString() + ); + path = path.replace("{" + "Data" + "}", this.data.toString()); Request request = new Request( HttpMethod.POST, Domains.SYNC.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("StreamMessage creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "StreamMessage creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return StreamMessage.fromJson(response.getStream(), client.getObjectMapper()); + return StreamMessage.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (data != null) { - request.addPostParam("Data", Converter.mapToJson(data)); - + request.addPostParam("Data", Converter.mapToJson(data)); } } } diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/Workspace.java b/src/main/java/com/twilio/rest/taskrouter/v1/Workspace.java index 6c7788a6bb..1ef4856761 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/Workspace.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/Workspace.java @@ -24,55 +24,54 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Workspace extends Resource { + private static final long serialVersionUID = 259156582462753L; - public static WorkspaceCreator creator(final String friendlyName){ + public static WorkspaceCreator creator(final String friendlyName) { return new WorkspaceCreator(friendlyName); } - public static WorkspaceDeleter deleter(final String pathSid){ + public static WorkspaceDeleter deleter(final String pathSid) { return new WorkspaceDeleter(pathSid); } - public static WorkspaceFetcher fetcher(final String pathSid){ + public static WorkspaceFetcher fetcher(final String pathSid) { return new WorkspaceFetcher(pathSid); } - public static WorkspaceReader reader(){ + public static WorkspaceReader reader() { return new WorkspaceReader(); } - public static WorkspaceUpdater updater(final String pathSid){ + public static WorkspaceUpdater updater(final String pathSid) { return new WorkspaceUpdater(pathSid); } /** - * Converts a JSON String into a Workspace object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Workspace object represented by the provided JSON - */ - public static Workspace fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Workspace object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Workspace object represented by the provided JSON + */ + public static Workspace fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Workspace.class); @@ -84,14 +83,17 @@ public static Workspace fromJson(final String json, final ObjectMapper objectMap } /** - * Converts a JSON InputStream into a Workspace object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Workspace object represented by the provided JSON - */ - public static Workspace fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Workspace object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Workspace object represented by the provided JSON + */ + public static Workspace fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Workspace.class); @@ -101,6 +103,7 @@ public static Workspace fromJson(final InputStream json, final ObjectMapper obje throw new ApiConnectionException(e.getMessage(), e); } } + public enum QueueOrder { FIFO("FIFO"), LIFO("LIFO"); @@ -139,50 +142,23 @@ public static QueueOrder forValue(final String value) { @JsonCreator private Workspace( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("default_activity_name") - final String defaultActivityName, - - @JsonProperty("default_activity_sid") - final String defaultActivitySid, - - @JsonProperty("event_callback_url") - final URI eventCallbackUrl, - - @JsonProperty("events_filter") - final String eventsFilter, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("multi_task_enabled") - final Boolean multiTaskEnabled, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("timeout_activity_name") - final String timeoutActivityName, - - @JsonProperty("timeout_activity_sid") - final String timeoutActivitySid, - - @JsonProperty("prioritize_queue_order") - final Workspace.QueueOrder prioritizeQueueOrder, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("default_activity_name") final String defaultActivityName, + @JsonProperty("default_activity_sid") final String defaultActivitySid, + @JsonProperty("event_callback_url") final URI eventCallbackUrl, + @JsonProperty("events_filter") final String eventsFilter, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("multi_task_enabled") final Boolean multiTaskEnabled, + @JsonProperty("sid") final String sid, + @JsonProperty("timeout_activity_name") final String timeoutActivityName, + @JsonProperty("timeout_activity_sid") final String timeoutActivitySid, + @JsonProperty( + "prioritize_queue_order" + ) final Workspace.QueueOrder prioritizeQueueOrder, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.accountSid = accountSid; this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); @@ -201,55 +177,69 @@ private Workspace( this.links = links; } - public final String getAccountSid() { - return this.accountSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getDefaultActivityName() { - return this.defaultActivityName; - } - public final String getDefaultActivitySid() { - return this.defaultActivitySid; - } - public final URI getEventCallbackUrl() { - return this.eventCallbackUrl; - } - public final String getEventsFilter() { - return this.eventsFilter; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final Boolean getMultiTaskEnabled() { - return this.multiTaskEnabled; - } - public final String getSid() { - return this.sid; - } - public final String getTimeoutActivityName() { - return this.timeoutActivityName; - } - public final String getTimeoutActivitySid() { - return this.timeoutActivitySid; - } - public final Workspace.QueueOrder getPrioritizeQueueOrder() { - return this.prioritizeQueueOrder; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getDefaultActivityName() { + return this.defaultActivityName; + } + + public final String getDefaultActivitySid() { + return this.defaultActivitySid; + } + + public final URI getEventCallbackUrl() { + return this.eventCallbackUrl; + } + + public final String getEventsFilter() { + return this.eventsFilter; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final Boolean getMultiTaskEnabled() { + return this.multiTaskEnabled; + } + + public final String getSid() { + return this.sid; + } + + public final String getTimeoutActivityName() { + return this.timeoutActivityName; + } + + public final String getTimeoutActivitySid() { + return this.timeoutActivitySid; + } + + public final Workspace.QueueOrder getPrioritizeQueueOrder() { + return this.prioritizeQueueOrder; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -259,13 +249,43 @@ public boolean equals(final Object o) { Workspace other = (Workspace) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(defaultActivityName, other.defaultActivityName) && Objects.equals(defaultActivitySid, other.defaultActivitySid) && Objects.equals(eventCallbackUrl, other.eventCallbackUrl) && Objects.equals(eventsFilter, other.eventsFilter) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(multiTaskEnabled, other.multiTaskEnabled) && Objects.equals(sid, other.sid) && Objects.equals(timeoutActivityName, other.timeoutActivityName) && Objects.equals(timeoutActivitySid, other.timeoutActivitySid) && Objects.equals(prioritizeQueueOrder, other.prioritizeQueueOrder) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(defaultActivityName, other.defaultActivityName) && + Objects.equals(defaultActivitySid, other.defaultActivitySid) && + Objects.equals(eventCallbackUrl, other.eventCallbackUrl) && + Objects.equals(eventsFilter, other.eventsFilter) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(multiTaskEnabled, other.multiTaskEnabled) && + Objects.equals(sid, other.sid) && + Objects.equals(timeoutActivityName, other.timeoutActivityName) && + Objects.equals(timeoutActivitySid, other.timeoutActivitySid) && + Objects.equals(prioritizeQueueOrder, other.prioritizeQueueOrder) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, dateCreated, dateUpdated, defaultActivityName, defaultActivitySid, eventCallbackUrl, eventsFilter, friendlyName, multiTaskEnabled, sid, timeoutActivityName, timeoutActivitySid, prioritizeQueueOrder, url, links); + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + defaultActivityName, + defaultActivitySid, + eventCallbackUrl, + eventsFilter, + friendlyName, + multiTaskEnabled, + sid, + timeoutActivityName, + timeoutActivitySid, + prioritizeQueueOrder, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/WorkspaceCreator.java b/src/main/java/com/twilio/rest/taskrouter/v1/WorkspaceCreator.java index 526ad7448e..f07c601d4e 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/WorkspaceCreator.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/WorkspaceCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.taskrouter.v1; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -25,12 +26,10 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.net.URI; - - - import java.net.URI; -public class WorkspaceCreator extends Creator{ +public class WorkspaceCreator extends Creator { + private String friendlyName; private URI eventCallbackUrl; private String eventsFilter; @@ -42,84 +41,110 @@ public WorkspaceCreator(final String friendlyName) { this.friendlyName = friendlyName; } - public WorkspaceCreator setFriendlyName(final String friendlyName){ + public WorkspaceCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public WorkspaceCreator setEventCallbackUrl(final URI eventCallbackUrl){ + + public WorkspaceCreator setEventCallbackUrl(final URI eventCallbackUrl) { this.eventCallbackUrl = eventCallbackUrl; return this; } - public WorkspaceCreator setEventCallbackUrl(final String eventCallbackUrl){ + public WorkspaceCreator setEventCallbackUrl(final String eventCallbackUrl) { return setEventCallbackUrl(Promoter.uriFromString(eventCallbackUrl)); } - public WorkspaceCreator setEventsFilter(final String eventsFilter){ + + public WorkspaceCreator setEventsFilter(final String eventsFilter) { this.eventsFilter = eventsFilter; return this; } - public WorkspaceCreator setMultiTaskEnabled(final Boolean multiTaskEnabled){ + + public WorkspaceCreator setMultiTaskEnabled( + final Boolean multiTaskEnabled + ) { this.multiTaskEnabled = multiTaskEnabled; return this; } - public WorkspaceCreator setTemplate(final String template){ + + public WorkspaceCreator setTemplate(final String template) { this.template = template; return this; } - public WorkspaceCreator setPrioritizeQueueOrder(final Workspace.QueueOrder prioritizeQueueOrder){ + + public WorkspaceCreator setPrioritizeQueueOrder( + final Workspace.QueueOrder prioritizeQueueOrder + ) { this.prioritizeQueueOrder = prioritizeQueueOrder; return this; } @Override - public Workspace create(final TwilioRestClient client){ + public Workspace create(final TwilioRestClient client) { String path = "/v1/Workspaces"; - path = path.replace("{"+"FriendlyName"+"}", this.friendlyName.toString()); + path = + path.replace( + "{" + "FriendlyName" + "}", + this.friendlyName.toString() + ); Request request = new Request( HttpMethod.POST, Domains.TASKROUTER.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Workspace creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Workspace creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Workspace.fromJson(response.getStream(), client.getObjectMapper()); + return Workspace.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (eventCallbackUrl != null) { - request.addPostParam("EventCallbackUrl", eventCallbackUrl.toString()); - + request.addPostParam( + "EventCallbackUrl", + eventCallbackUrl.toString() + ); } if (eventsFilter != null) { request.addPostParam("EventsFilter", eventsFilter); - } if (multiTaskEnabled != null) { - request.addPostParam("MultiTaskEnabled", multiTaskEnabled.toString()); - + request.addPostParam( + "MultiTaskEnabled", + multiTaskEnabled.toString() + ); } if (template != null) { request.addPostParam("Template", template); - } if (prioritizeQueueOrder != null) { - request.addPostParam("PrioritizeQueueOrder", prioritizeQueueOrder.toString()); - + request.addPostParam( + "PrioritizeQueueOrder", + prioritizeQueueOrder.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/WorkspaceDeleter.java b/src/main/java/com/twilio/rest/taskrouter/v1/WorkspaceDeleter.java index e9d2c68811..57b96e79e2 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/WorkspaceDeleter.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/WorkspaceDeleter.java @@ -24,21 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class WorkspaceDeleter extends Deleter { + private String pathSid; - public WorkspaceDeleter(final String pathSid){ + public WorkspaceDeleter(final String pathSid) { this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Workspaces/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -48,9 +46,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Workspace delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Workspace delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/WorkspaceFetcher.java b/src/main/java/com/twilio/rest/taskrouter/v1/WorkspaceFetcher.java index 9367d7947c..d58b1d5716 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/WorkspaceFetcher.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/WorkspaceFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class WorkspaceFetcher extends Fetcher { + private String pathSid; - public WorkspaceFetcher(final String pathSid){ + public WorkspaceFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public Workspace fetch(final TwilioRestClient client) { String path = "/v1/Workspaces/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,15 +46,23 @@ public Workspace fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Workspace fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Workspace fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Workspace.fromJson(response.getStream(), client.getObjectMapper()); + return Workspace.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/WorkspaceReader.java b/src/main/java/com/twilio/rest/taskrouter/v1/WorkspaceReader.java index 3971e6d498..be680afe39 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/WorkspaceReader.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/WorkspaceReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.taskrouter.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,22 +25,20 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class WorkspaceReader extends Reader { + private String friendlyName; private Integer pageSize; - public WorkspaceReader(){ - } + public WorkspaceReader() {} - public WorkspaceReader setFriendlyName(final String friendlyName){ + public WorkspaceReader setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public WorkspaceReader setPageSize(final Integer pageSize){ + + public WorkspaceReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -62,13 +61,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Workspace read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Workspace read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -84,7 +91,10 @@ private Page pageForRequest(final TwilioRestClient client, final Requ } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.TASKROUTER.toString()) @@ -92,9 +102,11 @@ public Page previousPage(final Page page, final TwilioRest return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.TASKROUTER.toString()) @@ -103,25 +115,24 @@ public Page nextPage(final Page page, final TwilioRestClie } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (friendlyName != null) { - request.addQueryParam("FriendlyName", friendlyName); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/WorkspaceUpdater.java b/src/main/java/com/twilio/rest/taskrouter/v1/WorkspaceUpdater.java index 11f81652db..95810620c8 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/WorkspaceUpdater.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/WorkspaceUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.taskrouter.v1; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -24,12 +25,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.net.URI; +public class WorkspaceUpdater extends Updater { - -public class WorkspaceUpdater extends Updater{ private String pathSid; private String defaultActivitySid; private URI eventCallbackUrl; @@ -39,96 +38,122 @@ public class WorkspaceUpdater extends Updater{ private String timeoutActivitySid; private Workspace.QueueOrder prioritizeQueueOrder; - public WorkspaceUpdater(final String pathSid){ + public WorkspaceUpdater(final String pathSid) { this.pathSid = pathSid; } - public WorkspaceUpdater setDefaultActivitySid(final String defaultActivitySid){ + public WorkspaceUpdater setDefaultActivitySid( + final String defaultActivitySid + ) { this.defaultActivitySid = defaultActivitySid; return this; } - public WorkspaceUpdater setEventCallbackUrl(final URI eventCallbackUrl){ + + public WorkspaceUpdater setEventCallbackUrl(final URI eventCallbackUrl) { this.eventCallbackUrl = eventCallbackUrl; return this; } - public WorkspaceUpdater setEventCallbackUrl(final String eventCallbackUrl){ + public WorkspaceUpdater setEventCallbackUrl(final String eventCallbackUrl) { return setEventCallbackUrl(Promoter.uriFromString(eventCallbackUrl)); } - public WorkspaceUpdater setEventsFilter(final String eventsFilter){ + + public WorkspaceUpdater setEventsFilter(final String eventsFilter) { this.eventsFilter = eventsFilter; return this; } - public WorkspaceUpdater setFriendlyName(final String friendlyName){ + + public WorkspaceUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public WorkspaceUpdater setMultiTaskEnabled(final Boolean multiTaskEnabled){ + + public WorkspaceUpdater setMultiTaskEnabled( + final Boolean multiTaskEnabled + ) { this.multiTaskEnabled = multiTaskEnabled; return this; } - public WorkspaceUpdater setTimeoutActivitySid(final String timeoutActivitySid){ + + public WorkspaceUpdater setTimeoutActivitySid( + final String timeoutActivitySid + ) { this.timeoutActivitySid = timeoutActivitySid; return this; } - public WorkspaceUpdater setPrioritizeQueueOrder(final Workspace.QueueOrder prioritizeQueueOrder){ + + public WorkspaceUpdater setPrioritizeQueueOrder( + final Workspace.QueueOrder prioritizeQueueOrder + ) { this.prioritizeQueueOrder = prioritizeQueueOrder; return this; } @Override - public Workspace update(final TwilioRestClient client){ + public Workspace update(final TwilioRestClient client) { String path = "/v1/Workspaces/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.TASKROUTER.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Workspace update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Workspace update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Workspace.fromJson(response.getStream(), client.getObjectMapper()); + return Workspace.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (defaultActivitySid != null) { request.addPostParam("DefaultActivitySid", defaultActivitySid); - } if (eventCallbackUrl != null) { - request.addPostParam("EventCallbackUrl", eventCallbackUrl.toString()); - + request.addPostParam( + "EventCallbackUrl", + eventCallbackUrl.toString() + ); } if (eventsFilter != null) { request.addPostParam("EventsFilter", eventsFilter); - } if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (multiTaskEnabled != null) { - request.addPostParam("MultiTaskEnabled", multiTaskEnabled.toString()); - + request.addPostParam( + "MultiTaskEnabled", + multiTaskEnabled.toString() + ); } if (timeoutActivitySid != null) { request.addPostParam("TimeoutActivitySid", timeoutActivitySid); - } if (prioritizeQueueOrder != null) { - request.addPostParam("PrioritizeQueueOrder", prioritizeQueueOrder.toString()); - + request.addPostParam( + "PrioritizeQueueOrder", + prioritizeQueueOrder.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/Activity.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/Activity.java index a17555d851..93ff3f6239 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/Activity.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/Activity.java @@ -23,55 +23,66 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Activity extends Resource { + private static final long serialVersionUID = 20275383236164L; - public static ActivityCreator creator(final String pathWorkspaceSid, final String friendlyName){ + public static ActivityCreator creator( + final String pathWorkspaceSid, + final String friendlyName + ) { return new ActivityCreator(pathWorkspaceSid, friendlyName); } - public static ActivityDeleter deleter(final String pathWorkspaceSid, final String pathSid){ + public static ActivityDeleter deleter( + final String pathWorkspaceSid, + final String pathSid + ) { return new ActivityDeleter(pathWorkspaceSid, pathSid); } - public static ActivityFetcher fetcher(final String pathWorkspaceSid, final String pathSid){ + public static ActivityFetcher fetcher( + final String pathWorkspaceSid, + final String pathSid + ) { return new ActivityFetcher(pathWorkspaceSid, pathSid); } - public static ActivityReader reader(final String pathWorkspaceSid){ + public static ActivityReader reader(final String pathWorkspaceSid) { return new ActivityReader(pathWorkspaceSid); } - public static ActivityUpdater updater(final String pathWorkspaceSid, final String pathSid){ + public static ActivityUpdater updater( + final String pathWorkspaceSid, + final String pathSid + ) { return new ActivityUpdater(pathWorkspaceSid, pathSid); } /** - * Converts a JSON String into a Activity object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Activity object represented by the provided JSON - */ - public static Activity fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Activity object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Activity object represented by the provided JSON + */ + public static Activity fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Activity.class); @@ -83,14 +94,17 @@ public static Activity fromJson(final String json, final ObjectMapper objectMapp } /** - * Converts a JSON InputStream into a Activity object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Activity object represented by the provided JSON - */ - public static Activity fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Activity object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Activity object represented by the provided JSON + */ + public static Activity fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Activity.class); @@ -113,32 +127,15 @@ public static Activity fromJson(final InputStream json, final ObjectMapper objec @JsonCreator private Activity( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("available") - final Boolean available, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("workspace_sid") - final String workspaceSid, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("available") final Boolean available, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("sid") final String sid, + @JsonProperty("workspace_sid") final String workspaceSid, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.accountSid = accountSid; this.available = available; @@ -151,37 +148,45 @@ private Activity( this.links = links; } - public final String getAccountSid() { - return this.accountSid; - } - public final Boolean getAvailable() { - return this.available; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getSid() { - return this.sid; - } - public final String getWorkspaceSid() { - return this.workspaceSid; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final Boolean getAvailable() { + return this.available; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getSid() { + return this.sid; + } + + public final String getWorkspaceSid() { + return this.workspaceSid; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -191,13 +196,31 @@ public boolean equals(final Object o) { Activity other = (Activity) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(available, other.available) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(sid, other.sid) && Objects.equals(workspaceSid, other.workspaceSid) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(available, other.available) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(sid, other.sid) && + Objects.equals(workspaceSid, other.workspaceSid) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, available, dateCreated, dateUpdated, friendlyName, sid, workspaceSid, url, links); + return Objects.hash( + accountSid, + available, + dateCreated, + dateUpdated, + friendlyName, + sid, + workspaceSid, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/ActivityCreator.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/ActivityCreator.java index 0003aa33b7..b1be67cd7f 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/ActivityCreator.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/ActivityCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.taskrouter.v1.workspace; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,62 +25,80 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class ActivityCreator extends Creator { - - -public class ActivityCreator extends Creator{ private String pathWorkspaceSid; private String friendlyName; private Boolean available; - public ActivityCreator(final String pathWorkspaceSid, final String friendlyName) { + public ActivityCreator( + final String pathWorkspaceSid, + final String friendlyName + ) { this.pathWorkspaceSid = pathWorkspaceSid; this.friendlyName = friendlyName; } - public ActivityCreator setFriendlyName(final String friendlyName){ + public ActivityCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public ActivityCreator setAvailable(final Boolean available){ + + public ActivityCreator setAvailable(final Boolean available) { this.available = available; return this; } @Override - public Activity create(final TwilioRestClient client){ + public Activity create(final TwilioRestClient client) { String path = "/v1/Workspaces/{WorkspaceSid}/Activities"; - path = path.replace("{"+"WorkspaceSid"+"}", this.pathWorkspaceSid.toString()); - path = path.replace("{"+"FriendlyName"+"}", this.friendlyName.toString()); + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = + path.replace( + "{" + "FriendlyName" + "}", + this.friendlyName.toString() + ); Request request = new Request( HttpMethod.POST, Domains.TASKROUTER.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Activity creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Activity creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Activity.fromJson(response.getStream(), client.getObjectMapper()); + return Activity.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (available != null) { request.addPostParam("Available", available.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/ActivityDeleter.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/ActivityDeleter.java index bb05718906..35d24ae600 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/ActivityDeleter.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/ActivityDeleter.java @@ -24,24 +24,29 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class ActivityDeleter extends Deleter { + private String pathWorkspaceSid; private String pathSid; - public ActivityDeleter(final String pathWorkspaceSid, final String pathSid){ + public ActivityDeleter( + final String pathWorkspaceSid, + final String pathSid + ) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Workspaces/{WorkspaceSid}/Activities/{Sid}"; - path = path.replace("{"+"WorkspaceSid"+"}", this.pathWorkspaceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +56,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Activity delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Activity delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/ActivityFetcher.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/ActivityFetcher.java index a7a7c34d47..9d05a1e2dc 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/ActivityFetcher.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/ActivityFetcher.java @@ -24,25 +24,29 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class ActivityFetcher extends Fetcher { + private String pathWorkspaceSid; private String pathSid; - public ActivityFetcher(final String pathWorkspaceSid, final String pathSid){ + public ActivityFetcher( + final String pathWorkspaceSid, + final String pathSid + ) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathSid = pathSid; } - @Override public Activity fetch(final TwilioRestClient client) { String path = "/v1/Workspaces/{WorkspaceSid}/Activities/{Sid}"; - path = path.replace("{"+"WorkspaceSid"+"}", this.pathWorkspaceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,15 +56,23 @@ public Activity fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Activity fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Activity fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Activity.fromJson(response.getStream(), client.getObjectMapper()); + return Activity.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/ActivityReader.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/ActivityReader.java index ab1e129a84..ce46bfa8f1 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/ActivityReader.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/ActivityReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.taskrouter.v1.workspace; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,29 +25,29 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class ActivityReader extends Reader { + private String pathWorkspaceSid; private String friendlyName; private String available; private Integer pageSize; - public ActivityReader(final String pathWorkspaceSid){ + public ActivityReader(final String pathWorkspaceSid) { this.pathWorkspaceSid = pathWorkspaceSid; } - public ActivityReader setFriendlyName(final String friendlyName){ + public ActivityReader setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public ActivityReader setAvailable(final String available){ + + public ActivityReader setAvailable(final String available) { this.available = available; return this; } - public ActivityReader setPageSize(final Integer pageSize){ + + public ActivityReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -58,7 +59,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Workspaces/{WorkspaceSid}/Activities"; - path = path.replace("{"+"WorkspaceSid"+"}", this.pathWorkspaceSid.toString()); + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -70,13 +75,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Activity read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Activity read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -92,7 +105,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reque } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.TASKROUTER.toString()) @@ -100,9 +116,11 @@ public Page previousPage(final Page page, final TwilioRestCl return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.TASKROUTER.toString()) @@ -111,29 +129,27 @@ public Page nextPage(final Page page, final TwilioRestClient } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (friendlyName != null) { - request.addQueryParam("FriendlyName", friendlyName); } if (available != null) { - request.addQueryParam("Available", available); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/ActivityUpdater.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/ActivityUpdater.java index 92516d97ac..c230710ff7 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/ActivityUpdater.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/ActivityUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.taskrouter.v1.workspace; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,54 +25,68 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class ActivityUpdater extends Updater { - - -public class ActivityUpdater extends Updater{ private String pathWorkspaceSid; private String pathSid; private String friendlyName; - public ActivityUpdater(final String pathWorkspaceSid, final String pathSid){ + public ActivityUpdater( + final String pathWorkspaceSid, + final String pathSid + ) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathSid = pathSid; } - public ActivityUpdater setFriendlyName(final String friendlyName){ + public ActivityUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } @Override - public Activity update(final TwilioRestClient client){ + public Activity update(final TwilioRestClient client) { String path = "/v1/Workspaces/{WorkspaceSid}/Activities/{Sid}"; - path = path.replace("{"+"WorkspaceSid"+"}", this.pathWorkspaceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.TASKROUTER.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Activity update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Activity update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Activity.fromJson(response.getStream(), client.getObjectMapper()); + return Activity.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } } } diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/Event.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/Event.java index 06ebd84aae..93c3ae139a 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/Event.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/Event.java @@ -23,43 +23,45 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Event extends Resource { + private static final long serialVersionUID = 215026832174382L; - public static EventFetcher fetcher(final String pathWorkspaceSid, final String pathSid){ + public static EventFetcher fetcher( + final String pathWorkspaceSid, + final String pathSid + ) { return new EventFetcher(pathWorkspaceSid, pathSid); } - public static EventReader reader(final String pathWorkspaceSid){ + public static EventReader reader(final String pathWorkspaceSid) { return new EventReader(pathWorkspaceSid); } /** - * Converts a JSON String into a Event object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Event object represented by the provided JSON - */ - public static Event fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Event object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Event object represented by the provided JSON + */ + public static Event fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Event.class); @@ -71,14 +73,17 @@ public static Event fromJson(final String json, final ObjectMapper objectMapper) } /** - * Converts a JSON InputStream into a Event object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Event object represented by the provided JSON - */ - public static Event fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Event object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Event object represented by the provided JSON + */ + public static Event fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Event.class); @@ -109,56 +114,23 @@ public static Event fromJson(final InputStream json, final ObjectMapper objectMa @JsonCreator private Event( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("actor_sid") - final String actorSid, - - @JsonProperty("actor_type") - final String actorType, - - @JsonProperty("actor_url") - final URI actorUrl, - - @JsonProperty("description") - final String description, - - @JsonProperty("event_data") - final Map eventData, - - @JsonProperty("event_date") - final String eventDate, - - @JsonProperty("event_date_ms") - final Long eventDateMs, - - @JsonProperty("event_type") - final String eventType, - - @JsonProperty("resource_sid") - final String resourceSid, - - @JsonProperty("resource_type") - final String resourceType, - - @JsonProperty("resource_url") - final URI resourceUrl, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("source") - final String source, - - @JsonProperty("source_ip_address") - final String sourceIpAddress, - - @JsonProperty("url") - final URI url, - - @JsonProperty("workspace_sid") - final String workspaceSid + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("actor_sid") final String actorSid, + @JsonProperty("actor_type") final String actorType, + @JsonProperty("actor_url") final URI actorUrl, + @JsonProperty("description") final String description, + @JsonProperty("event_data") final Map eventData, + @JsonProperty("event_date") final String eventDate, + @JsonProperty("event_date_ms") final Long eventDateMs, + @JsonProperty("event_type") final String eventType, + @JsonProperty("resource_sid") final String resourceSid, + @JsonProperty("resource_type") final String resourceType, + @JsonProperty("resource_url") final URI resourceUrl, + @JsonProperty("sid") final String sid, + @JsonProperty("source") final String source, + @JsonProperty("source_ip_address") final String sourceIpAddress, + @JsonProperty("url") final URI url, + @JsonProperty("workspace_sid") final String workspaceSid ) { this.accountSid = accountSid; this.actorSid = actorSid; @@ -179,61 +151,77 @@ private Event( this.workspaceSid = workspaceSid; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getActorSid() { - return this.actorSid; - } - public final String getActorType() { - return this.actorType; - } - public final URI getActorUrl() { - return this.actorUrl; - } - public final String getDescription() { - return this.description; - } - public final Map getEventData() { - return this.eventData; - } - public final ZonedDateTime getEventDate() { - return this.eventDate; - } - public final Long getEventDateMs() { - return this.eventDateMs; - } - public final String getEventType() { - return this.eventType; - } - public final String getResourceSid() { - return this.resourceSid; - } - public final String getResourceType() { - return this.resourceType; - } - public final URI getResourceUrl() { - return this.resourceUrl; - } - public final String getSid() { - return this.sid; - } - public final String getSource() { - return this.source; - } - public final String getSourceIpAddress() { - return this.sourceIpAddress; - } - public final URI getUrl() { - return this.url; - } - public final String getWorkspaceSid() { - return this.workspaceSid; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getActorSid() { + return this.actorSid; + } + + public final String getActorType() { + return this.actorType; + } + + public final URI getActorUrl() { + return this.actorUrl; + } + + public final String getDescription() { + return this.description; + } + + public final Map getEventData() { + return this.eventData; + } + + public final ZonedDateTime getEventDate() { + return this.eventDate; + } + + public final Long getEventDateMs() { + return this.eventDateMs; + } + + public final String getEventType() { + return this.eventType; + } + + public final String getResourceSid() { + return this.resourceSid; + } + + public final String getResourceType() { + return this.resourceType; + } + + public final URI getResourceUrl() { + return this.resourceUrl; + } + + public final String getSid() { + return this.sid; + } + + public final String getSource() { + return this.source; + } + + public final String getSourceIpAddress() { + return this.sourceIpAddress; + } + + public final URI getUrl() { + return this.url; + } + + public final String getWorkspaceSid() { + return this.workspaceSid; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -243,13 +231,47 @@ public boolean equals(final Object o) { Event other = (Event) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(actorSid, other.actorSid) && Objects.equals(actorType, other.actorType) && Objects.equals(actorUrl, other.actorUrl) && Objects.equals(description, other.description) && Objects.equals(eventData, other.eventData) && Objects.equals(eventDate, other.eventDate) && Objects.equals(eventDateMs, other.eventDateMs) && Objects.equals(eventType, other.eventType) && Objects.equals(resourceSid, other.resourceSid) && Objects.equals(resourceType, other.resourceType) && Objects.equals(resourceUrl, other.resourceUrl) && Objects.equals(sid, other.sid) && Objects.equals(source, other.source) && Objects.equals(sourceIpAddress, other.sourceIpAddress) && Objects.equals(url, other.url) && Objects.equals(workspaceSid, other.workspaceSid) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(actorSid, other.actorSid) && + Objects.equals(actorType, other.actorType) && + Objects.equals(actorUrl, other.actorUrl) && + Objects.equals(description, other.description) && + Objects.equals(eventData, other.eventData) && + Objects.equals(eventDate, other.eventDate) && + Objects.equals(eventDateMs, other.eventDateMs) && + Objects.equals(eventType, other.eventType) && + Objects.equals(resourceSid, other.resourceSid) && + Objects.equals(resourceType, other.resourceType) && + Objects.equals(resourceUrl, other.resourceUrl) && + Objects.equals(sid, other.sid) && + Objects.equals(source, other.source) && + Objects.equals(sourceIpAddress, other.sourceIpAddress) && + Objects.equals(url, other.url) && + Objects.equals(workspaceSid, other.workspaceSid) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, actorSid, actorType, actorUrl, description, eventData, eventDate, eventDateMs, eventType, resourceSid, resourceType, resourceUrl, sid, source, sourceIpAddress, url, workspaceSid); + return Objects.hash( + accountSid, + actorSid, + actorType, + actorUrl, + description, + eventData, + eventDate, + eventDateMs, + eventType, + resourceSid, + resourceType, + resourceUrl, + sid, + source, + sourceIpAddress, + url, + workspaceSid + ); } - } - diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/EventFetcher.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/EventFetcher.java index 684c7f7589..d511ee302b 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/EventFetcher.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/EventFetcher.java @@ -24,25 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class EventFetcher extends Fetcher { + private String pathWorkspaceSid; private String pathSid; - public EventFetcher(final String pathWorkspaceSid, final String pathSid){ + public EventFetcher(final String pathWorkspaceSid, final String pathSid) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathSid = pathSid; } - @Override public Event fetch(final TwilioRestClient client) { String path = "/v1/Workspaces/{WorkspaceSid}/Events/{Sid}"; - path = path.replace("{"+"WorkspaceSid"+"}", this.pathWorkspaceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,9 +53,14 @@ public Event fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Event fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Event fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/EventReader.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/EventReader.java index ad36aa198c..795d11462c 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/EventReader.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/EventReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.taskrouter.v1.workspace; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,12 +25,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; import java.time.ZonedDateTime; - - public class EventReader extends Reader { + private String pathWorkspaceSid; private ZonedDateTime endDate; private String eventType; @@ -44,55 +43,66 @@ public class EventReader extends Reader { private String sid; private Integer pageSize; - public EventReader(final String pathWorkspaceSid){ + public EventReader(final String pathWorkspaceSid) { this.pathWorkspaceSid = pathWorkspaceSid; } - public EventReader setEndDate(final ZonedDateTime endDate){ + public EventReader setEndDate(final ZonedDateTime endDate) { this.endDate = endDate; return this; } - public EventReader setEventType(final String eventType){ + + public EventReader setEventType(final String eventType) { this.eventType = eventType; return this; } - public EventReader setMinutes(final Integer minutes){ + + public EventReader setMinutes(final Integer minutes) { this.minutes = minutes; return this; } - public EventReader setReservationSid(final String reservationSid){ + + public EventReader setReservationSid(final String reservationSid) { this.reservationSid = reservationSid; return this; } - public EventReader setStartDate(final ZonedDateTime startDate){ + + public EventReader setStartDate(final ZonedDateTime startDate) { this.startDate = startDate; return this; } - public EventReader setTaskQueueSid(final String taskQueueSid){ + + public EventReader setTaskQueueSid(final String taskQueueSid) { this.taskQueueSid = taskQueueSid; return this; } - public EventReader setTaskSid(final String taskSid){ + + public EventReader setTaskSid(final String taskSid) { this.taskSid = taskSid; return this; } - public EventReader setWorkerSid(final String workerSid){ + + public EventReader setWorkerSid(final String workerSid) { this.workerSid = workerSid; return this; } - public EventReader setWorkflowSid(final String workflowSid){ + + public EventReader setWorkflowSid(final String workflowSid) { this.workflowSid = workflowSid; return this; } - public EventReader setTaskChannel(final String taskChannel){ + + public EventReader setTaskChannel(final String taskChannel) { this.taskChannel = taskChannel; return this; } - public EventReader setSid(final String sid){ + + public EventReader setSid(final String sid) { this.sid = sid; return this; } - public EventReader setPageSize(final Integer pageSize){ + + public EventReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -104,7 +114,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Workspaces/{WorkspaceSid}/Events"; - path = path.replace("{"+"WorkspaceSid"+"}", this.pathWorkspaceSid.toString()); + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -116,13 +130,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Event read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Event read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -138,7 +160,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.TASKROUTER.toString()) @@ -146,9 +171,11 @@ public Page previousPage(final Page page, final TwilioRestClient c return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.TASKROUTER.toString()) @@ -157,65 +184,59 @@ public Page nextPage(final Page page, final TwilioRestClient clien } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (endDate != null) { request.addQueryParam("EndDate", endDate.toInstant().toString()); } if (eventType != null) { - request.addQueryParam("EventType", eventType); } if (minutes != null) { - request.addQueryParam("Minutes", minutes.toString()); } if (reservationSid != null) { - request.addQueryParam("ReservationSid", reservationSid); } if (startDate != null) { - request.addQueryParam("StartDate", startDate.toInstant().toString()); + request.addQueryParam( + "StartDate", + startDate.toInstant().toString() + ); } if (taskQueueSid != null) { - request.addQueryParam("TaskQueueSid", taskQueueSid); } if (taskSid != null) { - request.addQueryParam("TaskSid", taskSid); } if (workerSid != null) { - request.addQueryParam("WorkerSid", workerSid); } if (workflowSid != null) { - request.addQueryParam("WorkflowSid", workflowSid); } if (taskChannel != null) { - request.addQueryParam("TaskChannel", taskChannel); } if (sid != null) { - request.addQueryParam("Sid", sid); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/Task.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/Task.java index 1314b96d18..0da8467d60 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/Task.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/Task.java @@ -24,55 +24,63 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Task extends Resource { + private static final long serialVersionUID = 66438798069009L; - public static TaskCreator creator(final String pathWorkspaceSid){ + public static TaskCreator creator(final String pathWorkspaceSid) { return new TaskCreator(pathWorkspaceSid); } - public static TaskDeleter deleter(final String pathWorkspaceSid, final String pathSid){ + public static TaskDeleter deleter( + final String pathWorkspaceSid, + final String pathSid + ) { return new TaskDeleter(pathWorkspaceSid, pathSid); } - public static TaskFetcher fetcher(final String pathWorkspaceSid, final String pathSid){ + public static TaskFetcher fetcher( + final String pathWorkspaceSid, + final String pathSid + ) { return new TaskFetcher(pathWorkspaceSid, pathSid); } - public static TaskReader reader(final String pathWorkspaceSid){ + public static TaskReader reader(final String pathWorkspaceSid) { return new TaskReader(pathWorkspaceSid); } - public static TaskUpdater updater(final String pathWorkspaceSid, final String pathSid){ + public static TaskUpdater updater( + final String pathWorkspaceSid, + final String pathSid + ) { return new TaskUpdater(pathWorkspaceSid, pathSid); } /** - * Converts a JSON String into a Task object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Task object represented by the provided JSON - */ - public static Task fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Task object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Task object represented by the provided JSON + */ + public static Task fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Task.class); @@ -84,14 +92,17 @@ public static Task fromJson(final String json, final ObjectMapper objectMapper) } /** - * Converts a JSON InputStream into a Task object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Task object represented by the provided JSON - */ - public static Task fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Task object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Task object represented by the provided JSON + */ + public static Task fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Task.class); @@ -101,6 +112,7 @@ public static Task fromJson(final InputStream json, final ObjectMapper objectMap throw new ApiConnectionException(e.getMessage(), e); } } + public enum Status { PENDING("pending"), RESERVED("reserved"), @@ -149,68 +161,35 @@ public static Status forValue(final String value) { @JsonCreator private Task( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("age") - final Integer age, - - @JsonProperty("assignment_status") - final Task.Status assignmentStatus, - - @JsonProperty("attributes") - final String attributes, - - @JsonProperty("addons") - final String addons, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("task_queue_entered_date") - final String taskQueueEnteredDate, - - @JsonProperty("priority") - final Integer priority, - - @JsonProperty("reason") - final String reason, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("task_queue_sid") - final String taskQueueSid, - - @JsonProperty("task_queue_friendly_name") - final String taskQueueFriendlyName, - - @JsonProperty("task_channel_sid") - final String taskChannelSid, - - @JsonProperty("task_channel_unique_name") - final String taskChannelUniqueName, - - @JsonProperty("timeout") - final Integer timeout, - - @JsonProperty("workflow_sid") - final String workflowSid, - - @JsonProperty("workflow_friendly_name") - final String workflowFriendlyName, - - @JsonProperty("workspace_sid") - final String workspaceSid, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("age") final Integer age, + @JsonProperty("assignment_status") final Task.Status assignmentStatus, + @JsonProperty("attributes") final String attributes, + @JsonProperty("addons") final String addons, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty( + "task_queue_entered_date" + ) final String taskQueueEnteredDate, + @JsonProperty("priority") final Integer priority, + @JsonProperty("reason") final String reason, + @JsonProperty("sid") final String sid, + @JsonProperty("task_queue_sid") final String taskQueueSid, + @JsonProperty( + "task_queue_friendly_name" + ) final String taskQueueFriendlyName, + @JsonProperty("task_channel_sid") final String taskChannelSid, + @JsonProperty( + "task_channel_unique_name" + ) final String taskChannelUniqueName, + @JsonProperty("timeout") final Integer timeout, + @JsonProperty("workflow_sid") final String workflowSid, + @JsonProperty( + "workflow_friendly_name" + ) final String workflowFriendlyName, + @JsonProperty("workspace_sid") final String workspaceSid, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.accountSid = accountSid; this.age = age; @@ -219,7 +198,8 @@ private Task( this.addons = addons; this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.taskQueueEnteredDate = DateConverter.iso8601DateTimeFromString(taskQueueEnteredDate); + this.taskQueueEnteredDate = + DateConverter.iso8601DateTimeFromString(taskQueueEnteredDate); this.priority = priority; this.reason = reason; this.sid = sid; @@ -235,73 +215,93 @@ private Task( this.links = links; } - public final String getAccountSid() { - return this.accountSid; - } - public final Integer getAge() { - return this.age; - } - public final Task.Status getAssignmentStatus() { - return this.assignmentStatus; - } - public final String getAttributes() { - return this.attributes; - } - public final String getAddons() { - return this.addons; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final ZonedDateTime getTaskQueueEnteredDate() { - return this.taskQueueEnteredDate; - } - public final Integer getPriority() { - return this.priority; - } - public final String getReason() { - return this.reason; - } - public final String getSid() { - return this.sid; - } - public final String getTaskQueueSid() { - return this.taskQueueSid; - } - public final String getTaskQueueFriendlyName() { - return this.taskQueueFriendlyName; - } - public final String getTaskChannelSid() { - return this.taskChannelSid; - } - public final String getTaskChannelUniqueName() { - return this.taskChannelUniqueName; - } - public final Integer getTimeout() { - return this.timeout; - } - public final String getWorkflowSid() { - return this.workflowSid; - } - public final String getWorkflowFriendlyName() { - return this.workflowFriendlyName; - } - public final String getWorkspaceSid() { - return this.workspaceSid; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final Integer getAge() { + return this.age; + } + + public final Task.Status getAssignmentStatus() { + return this.assignmentStatus; + } + + public final String getAttributes() { + return this.attributes; + } + + public final String getAddons() { + return this.addons; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final ZonedDateTime getTaskQueueEnteredDate() { + return this.taskQueueEnteredDate; + } + + public final Integer getPriority() { + return this.priority; + } + + public final String getReason() { + return this.reason; + } + + public final String getSid() { + return this.sid; + } + + public final String getTaskQueueSid() { + return this.taskQueueSid; + } + + public final String getTaskQueueFriendlyName() { + return this.taskQueueFriendlyName; + } + + public final String getTaskChannelSid() { + return this.taskChannelSid; + } + + public final String getTaskChannelUniqueName() { + return this.taskChannelUniqueName; + } + + public final Integer getTimeout() { + return this.timeout; + } + + public final String getWorkflowSid() { + return this.workflowSid; + } + + public final String getWorkflowFriendlyName() { + return this.workflowFriendlyName; + } + + public final String getWorkspaceSid() { + return this.workspaceSid; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -311,13 +311,61 @@ public boolean equals(final Object o) { Task other = (Task) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(age, other.age) && Objects.equals(assignmentStatus, other.assignmentStatus) && Objects.equals(attributes, other.attributes) && Objects.equals(addons, other.addons) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(taskQueueEnteredDate, other.taskQueueEnteredDate) && Objects.equals(priority, other.priority) && Objects.equals(reason, other.reason) && Objects.equals(sid, other.sid) && Objects.equals(taskQueueSid, other.taskQueueSid) && Objects.equals(taskQueueFriendlyName, other.taskQueueFriendlyName) && Objects.equals(taskChannelSid, other.taskChannelSid) && Objects.equals(taskChannelUniqueName, other.taskChannelUniqueName) && Objects.equals(timeout, other.timeout) && Objects.equals(workflowSid, other.workflowSid) && Objects.equals(workflowFriendlyName, other.workflowFriendlyName) && Objects.equals(workspaceSid, other.workspaceSid) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(age, other.age) && + Objects.equals(assignmentStatus, other.assignmentStatus) && + Objects.equals(attributes, other.attributes) && + Objects.equals(addons, other.addons) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(taskQueueEnteredDate, other.taskQueueEnteredDate) && + Objects.equals(priority, other.priority) && + Objects.equals(reason, other.reason) && + Objects.equals(sid, other.sid) && + Objects.equals(taskQueueSid, other.taskQueueSid) && + Objects.equals( + taskQueueFriendlyName, + other.taskQueueFriendlyName + ) && + Objects.equals(taskChannelSid, other.taskChannelSid) && + Objects.equals( + taskChannelUniqueName, + other.taskChannelUniqueName + ) && + Objects.equals(timeout, other.timeout) && + Objects.equals(workflowSid, other.workflowSid) && + Objects.equals(workflowFriendlyName, other.workflowFriendlyName) && + Objects.equals(workspaceSid, other.workspaceSid) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, age, assignmentStatus, attributes, addons, dateCreated, dateUpdated, taskQueueEnteredDate, priority, reason, sid, taskQueueSid, taskQueueFriendlyName, taskChannelSid, taskChannelUniqueName, timeout, workflowSid, workflowFriendlyName, workspaceSid, url, links); + return Objects.hash( + accountSid, + age, + assignmentStatus, + attributes, + addons, + dateCreated, + dateUpdated, + taskQueueEnteredDate, + priority, + reason, + sid, + taskQueueSid, + taskQueueFriendlyName, + taskChannelSid, + taskChannelUniqueName, + timeout, + workflowSid, + workflowFriendlyName, + workspaceSid, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskChannel.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskChannel.java index 2664c10cec..cc930c6237 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskChannel.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskChannel.java @@ -23,55 +23,71 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class TaskChannel extends Resource { + private static final long serialVersionUID = 156990545444191L; - public static TaskChannelCreator creator(final String pathWorkspaceSid, final String friendlyName, final String uniqueName){ - return new TaskChannelCreator(pathWorkspaceSid, friendlyName, uniqueName); + public static TaskChannelCreator creator( + final String pathWorkspaceSid, + final String friendlyName, + final String uniqueName + ) { + return new TaskChannelCreator( + pathWorkspaceSid, + friendlyName, + uniqueName + ); } - public static TaskChannelDeleter deleter(final String pathWorkspaceSid, final String pathSid){ + public static TaskChannelDeleter deleter( + final String pathWorkspaceSid, + final String pathSid + ) { return new TaskChannelDeleter(pathWorkspaceSid, pathSid); } - public static TaskChannelFetcher fetcher(final String pathWorkspaceSid, final String pathSid){ + public static TaskChannelFetcher fetcher( + final String pathWorkspaceSid, + final String pathSid + ) { return new TaskChannelFetcher(pathWorkspaceSid, pathSid); } - public static TaskChannelReader reader(final String pathWorkspaceSid){ + public static TaskChannelReader reader(final String pathWorkspaceSid) { return new TaskChannelReader(pathWorkspaceSid); } - public static TaskChannelUpdater updater(final String pathWorkspaceSid, final String pathSid){ + public static TaskChannelUpdater updater( + final String pathWorkspaceSid, + final String pathSid + ) { return new TaskChannelUpdater(pathWorkspaceSid, pathSid); } /** - * Converts a JSON String into a TaskChannel object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return TaskChannel object represented by the provided JSON - */ - public static TaskChannel fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a TaskChannel object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return TaskChannel object represented by the provided JSON + */ + public static TaskChannel fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, TaskChannel.class); @@ -83,14 +99,17 @@ public static TaskChannel fromJson(final String json, final ObjectMapper objectM } /** - * Converts a JSON InputStream into a TaskChannel object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return TaskChannel object represented by the provided JSON - */ - public static TaskChannel fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a TaskChannel object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return TaskChannel object represented by the provided JSON + */ + public static TaskChannel fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, TaskChannel.class); @@ -114,35 +133,18 @@ public static TaskChannel fromJson(final InputStream json, final ObjectMapper ob @JsonCreator private TaskChannel( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("unique_name") - final String uniqueName, - - @JsonProperty("workspace_sid") - final String workspaceSid, - - @JsonProperty("channel_optimized_routing") - final Boolean channelOptimizedRouting, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("sid") final String sid, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("workspace_sid") final String workspaceSid, + @JsonProperty( + "channel_optimized_routing" + ) final Boolean channelOptimizedRouting, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.accountSid = accountSid; this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); @@ -156,40 +158,49 @@ private TaskChannel( this.links = links; } - public final String getAccountSid() { - return this.accountSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getSid() { - return this.sid; - } - public final String getUniqueName() { - return this.uniqueName; - } - public final String getWorkspaceSid() { - return this.workspaceSid; - } - public final Boolean getChannelOptimizedRouting() { - return this.channelOptimizedRouting; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getSid() { + return this.sid; + } + + public final String getUniqueName() { + return this.uniqueName; + } + + public final String getWorkspaceSid() { + return this.workspaceSid; + } + + public final Boolean getChannelOptimizedRouting() { + return this.channelOptimizedRouting; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -199,13 +210,36 @@ public boolean equals(final Object o) { TaskChannel other = (TaskChannel) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(sid, other.sid) && Objects.equals(uniqueName, other.uniqueName) && Objects.equals(workspaceSid, other.workspaceSid) && Objects.equals(channelOptimizedRouting, other.channelOptimizedRouting) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(sid, other.sid) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(workspaceSid, other.workspaceSid) && + Objects.equals( + channelOptimizedRouting, + other.channelOptimizedRouting + ) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, dateCreated, dateUpdated, friendlyName, sid, uniqueName, workspaceSid, channelOptimizedRouting, url, links); + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + friendlyName, + sid, + uniqueName, + workspaceSid, + channelOptimizedRouting, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskChannelCreator.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskChannelCreator.java index 2c426d2231..1b6537ab68 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskChannelCreator.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskChannelCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.taskrouter.v1.workspace; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,73 +25,98 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class TaskChannelCreator extends Creator { - - -public class TaskChannelCreator extends Creator{ private String pathWorkspaceSid; private String friendlyName; private String uniqueName; private Boolean channelOptimizedRouting; - public TaskChannelCreator(final String pathWorkspaceSid, final String friendlyName, final String uniqueName) { + public TaskChannelCreator( + final String pathWorkspaceSid, + final String friendlyName, + final String uniqueName + ) { this.pathWorkspaceSid = pathWorkspaceSid; this.friendlyName = friendlyName; this.uniqueName = uniqueName; } - public TaskChannelCreator setFriendlyName(final String friendlyName){ + public TaskChannelCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public TaskChannelCreator setUniqueName(final String uniqueName){ + + public TaskChannelCreator setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - public TaskChannelCreator setChannelOptimizedRouting(final Boolean channelOptimizedRouting){ + + public TaskChannelCreator setChannelOptimizedRouting( + final Boolean channelOptimizedRouting + ) { this.channelOptimizedRouting = channelOptimizedRouting; return this; } @Override - public TaskChannel create(final TwilioRestClient client){ + public TaskChannel create(final TwilioRestClient client) { String path = "/v1/Workspaces/{WorkspaceSid}/TaskChannels"; - path = path.replace("{"+"WorkspaceSid"+"}", this.pathWorkspaceSid.toString()); - path = path.replace("{"+"FriendlyName"+"}", this.friendlyName.toString()); - path = path.replace("{"+"UniqueName"+"}", this.uniqueName.toString()); + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = + path.replace( + "{" + "FriendlyName" + "}", + this.friendlyName.toString() + ); + path = + path.replace("{" + "UniqueName" + "}", this.uniqueName.toString()); Request request = new Request( HttpMethod.POST, Domains.TASKROUTER.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("TaskChannel creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "TaskChannel creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return TaskChannel.fromJson(response.getStream(), client.getObjectMapper()); + return TaskChannel.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (uniqueName != null) { request.addPostParam("UniqueName", uniqueName); - } if (channelOptimizedRouting != null) { - request.addPostParam("ChannelOptimizedRouting", channelOptimizedRouting.toString()); - + request.addPostParam( + "ChannelOptimizedRouting", + channelOptimizedRouting.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskChannelDeleter.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskChannelDeleter.java index b41a46bdff..41e710c65a 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskChannelDeleter.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskChannelDeleter.java @@ -24,24 +24,29 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class TaskChannelDeleter extends Deleter { + private String pathWorkspaceSid; private String pathSid; - public TaskChannelDeleter(final String pathWorkspaceSid, final String pathSid){ + public TaskChannelDeleter( + final String pathWorkspaceSid, + final String pathSid + ) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Workspaces/{WorkspaceSid}/TaskChannels/{Sid}"; - path = path.replace("{"+"WorkspaceSid"+"}", this.pathWorkspaceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +56,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("TaskChannel delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "TaskChannel delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskChannelFetcher.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskChannelFetcher.java index 4952a747d3..97b3838517 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskChannelFetcher.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskChannelFetcher.java @@ -24,25 +24,29 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class TaskChannelFetcher extends Fetcher { + private String pathWorkspaceSid; private String pathSid; - public TaskChannelFetcher(final String pathWorkspaceSid, final String pathSid){ + public TaskChannelFetcher( + final String pathWorkspaceSid, + final String pathSid + ) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathSid = pathSid; } - @Override public TaskChannel fetch(final TwilioRestClient client) { String path = "/v1/Workspaces/{WorkspaceSid}/TaskChannels/{Sid}"; - path = path.replace("{"+"WorkspaceSid"+"}", this.pathWorkspaceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,15 +56,23 @@ public TaskChannel fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("TaskChannel fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "TaskChannel fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return TaskChannel.fromJson(response.getStream(), client.getObjectMapper()); + return TaskChannel.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskChannelReader.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskChannelReader.java index d1fde0d039..2334e6cb17 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskChannelReader.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskChannelReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.taskrouter.v1.workspace; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,19 +25,17 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class TaskChannelReader extends Reader { + private String pathWorkspaceSid; private Integer pageSize; - public TaskChannelReader(final String pathWorkspaceSid){ + public TaskChannelReader(final String pathWorkspaceSid) { this.pathWorkspaceSid = pathWorkspaceSid; } - public TaskChannelReader setPageSize(final Integer pageSize){ + public TaskChannelReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -48,7 +47,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Workspaces/{WorkspaceSid}/TaskChannels"; - path = path.replace("{"+"WorkspaceSid"+"}", this.pathWorkspaceSid.toString()); + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -60,13 +63,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("TaskChannel read failed: Unable to connect to server"); + throw new ApiConnectionException( + "TaskChannel read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +93,10 @@ private Page pageForRequest(final TwilioRestClient client, final Re } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.TASKROUTER.toString()) @@ -90,9 +104,11 @@ public Page previousPage(final Page page, final Twilio return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.TASKROUTER.toString()) @@ -101,21 +117,21 @@ public Page nextPage(final Page page, final TwilioRest } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskChannelUpdater.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskChannelUpdater.java index 3e3cec1346..5713b2b5ed 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskChannelUpdater.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskChannelUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.taskrouter.v1.workspace; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,63 +25,82 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class TaskChannelUpdater extends Updater { - - -public class TaskChannelUpdater extends Updater{ private String pathWorkspaceSid; private String pathSid; private String friendlyName; private Boolean channelOptimizedRouting; - public TaskChannelUpdater(final String pathWorkspaceSid, final String pathSid){ + public TaskChannelUpdater( + final String pathWorkspaceSid, + final String pathSid + ) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathSid = pathSid; } - public TaskChannelUpdater setFriendlyName(final String friendlyName){ + public TaskChannelUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public TaskChannelUpdater setChannelOptimizedRouting(final Boolean channelOptimizedRouting){ + + public TaskChannelUpdater setChannelOptimizedRouting( + final Boolean channelOptimizedRouting + ) { this.channelOptimizedRouting = channelOptimizedRouting; return this; } @Override - public TaskChannel update(final TwilioRestClient client){ + public TaskChannel update(final TwilioRestClient client) { String path = "/v1/Workspaces/{WorkspaceSid}/TaskChannels/{Sid}"; - path = path.replace("{"+"WorkspaceSid"+"}", this.pathWorkspaceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.TASKROUTER.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("TaskChannel update failed: Unable to connect to server"); + throw new ApiConnectionException( + "TaskChannel update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return TaskChannel.fromJson(response.getStream(), client.getObjectMapper()); + return TaskChannel.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (channelOptimizedRouting != null) { - request.addPostParam("ChannelOptimizedRouting", channelOptimizedRouting.toString()); - + request.addPostParam( + "ChannelOptimizedRouting", + channelOptimizedRouting.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskCreator.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskCreator.java index 622b80710b..1c483f40c2 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskCreator.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.taskrouter.v1.workspace; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class TaskCreator extends Creator { - - -public class TaskCreator extends Creator{ private String pathWorkspaceSid; private Integer timeout; private Integer priority; @@ -39,44 +38,58 @@ public TaskCreator(final String pathWorkspaceSid) { this.pathWorkspaceSid = pathWorkspaceSid; } - public TaskCreator setTimeout(final Integer timeout){ + public TaskCreator setTimeout(final Integer timeout) { this.timeout = timeout; return this; } - public TaskCreator setPriority(final Integer priority){ + + public TaskCreator setPriority(final Integer priority) { this.priority = priority; return this; } - public TaskCreator setTaskChannel(final String taskChannel){ + + public TaskCreator setTaskChannel(final String taskChannel) { this.taskChannel = taskChannel; return this; } - public TaskCreator setWorkflowSid(final String workflowSid){ + + public TaskCreator setWorkflowSid(final String workflowSid) { this.workflowSid = workflowSid; return this; } - public TaskCreator setAttributes(final String attributes){ + + public TaskCreator setAttributes(final String attributes) { this.attributes = attributes; return this; } @Override - public Task create(final TwilioRestClient client){ + public Task create(final TwilioRestClient client) { String path = "/v1/Workspaces/{WorkspaceSid}/Tasks"; - path = path.replace("{"+"WorkspaceSid"+"}", this.pathWorkspaceSid.toString()); + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.TASKROUTER.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Task creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Task creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -85,26 +98,22 @@ public Task create(final TwilioRestClient client){ return Task.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (timeout != null) { request.addPostParam("Timeout", timeout.toString()); - } if (priority != null) { request.addPostParam("Priority", priority.toString()); - } if (taskChannel != null) { request.addPostParam("TaskChannel", taskChannel); - } if (workflowSid != null) { request.addPostParam("WorkflowSid", workflowSid); - } if (attributes != null) { request.addPostParam("Attributes", attributes); - } } } diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskDeleter.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskDeleter.java index 1f1943be9a..02bac894b9 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskDeleter.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskDeleter.java @@ -24,19 +24,18 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class TaskDeleter extends Deleter { + private String pathWorkspaceSid; private String pathSid; private String ifMatch; - public TaskDeleter(final String pathWorkspaceSid, final String pathSid){ + public TaskDeleter(final String pathWorkspaceSid, final String pathSid) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathSid = pathSid; } - public TaskDeleter setIfMatch(final String ifMatch){ + public TaskDeleter setIfMatch(final String ifMatch) { this.ifMatch = ifMatch; return this; } @@ -45,8 +44,12 @@ public TaskDeleter setIfMatch(final String ifMatch){ public boolean delete(final TwilioRestClient client) { String path = "/v1/Workspaces/{WorkspaceSid}/Tasks/{Sid}"; - path = path.replace("{"+"WorkspaceSid"+"}", this.pathWorkspaceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -57,9 +60,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Task delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Task delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -67,10 +75,10 @@ public boolean delete(final TwilioRestClient client) { } return response.getStatusCode() == 204; } + private void addHeaderParams(final Request request) { if (ifMatch != null) { request.addHeaderParam("If-Match", ifMatch); - } } } diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskFetcher.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskFetcher.java index 56dbade8c7..ff19350d9c 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskFetcher.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskFetcher.java @@ -24,25 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class TaskFetcher extends Fetcher { + private String pathWorkspaceSid; private String pathSid; - public TaskFetcher(final String pathWorkspaceSid, final String pathSid){ + public TaskFetcher(final String pathWorkspaceSid, final String pathSid) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathSid = pathSid; } - @Override public Task fetch(final TwilioRestClient client) { String path = "/v1/Workspaces/{WorkspaceSid}/Tasks/{Sid}"; - path = path.replace("{"+"WorkspaceSid"+"}", this.pathWorkspaceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,9 +53,14 @@ public Task fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Task fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Task fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskQueue.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskQueue.java index 145dadfd48..520a4723bf 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskQueue.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskQueue.java @@ -24,55 +24,66 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class TaskQueue extends Resource { + private static final long serialVersionUID = 234230912116687L; - public static TaskQueueCreator creator(final String pathWorkspaceSid, final String friendlyName){ + public static TaskQueueCreator creator( + final String pathWorkspaceSid, + final String friendlyName + ) { return new TaskQueueCreator(pathWorkspaceSid, friendlyName); } - public static TaskQueueDeleter deleter(final String pathWorkspaceSid, final String pathSid){ + public static TaskQueueDeleter deleter( + final String pathWorkspaceSid, + final String pathSid + ) { return new TaskQueueDeleter(pathWorkspaceSid, pathSid); } - public static TaskQueueFetcher fetcher(final String pathWorkspaceSid, final String pathSid){ + public static TaskQueueFetcher fetcher( + final String pathWorkspaceSid, + final String pathSid + ) { return new TaskQueueFetcher(pathWorkspaceSid, pathSid); } - public static TaskQueueReader reader(final String pathWorkspaceSid){ + public static TaskQueueReader reader(final String pathWorkspaceSid) { return new TaskQueueReader(pathWorkspaceSid); } - public static TaskQueueUpdater updater(final String pathWorkspaceSid, final String pathSid){ + public static TaskQueueUpdater updater( + final String pathWorkspaceSid, + final String pathSid + ) { return new TaskQueueUpdater(pathWorkspaceSid, pathSid); } /** - * Converts a JSON String into a TaskQueue object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return TaskQueue object represented by the provided JSON - */ - public static TaskQueue fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a TaskQueue object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return TaskQueue object represented by the provided JSON + */ + public static TaskQueue fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, TaskQueue.class); @@ -84,14 +95,17 @@ public static TaskQueue fromJson(final String json, final ObjectMapper objectMap } /** - * Converts a JSON InputStream into a TaskQueue object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return TaskQueue object represented by the provided JSON - */ - public static TaskQueue fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a TaskQueue object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return TaskQueue object represented by the provided JSON + */ + public static TaskQueue fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, TaskQueue.class); @@ -101,6 +115,7 @@ public static TaskQueue fromJson(final InputStream json, final ObjectMapper obje throw new ApiConnectionException(e.getMessage(), e); } } + public enum TaskOrder { FIFO("FIFO"), LIFO("LIFO"); @@ -139,50 +154,29 @@ public static TaskOrder forValue(final String value) { @JsonCreator private TaskQueue( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("assignment_activity_sid") - final String assignmentActivitySid, - - @JsonProperty("assignment_activity_name") - final String assignmentActivityName, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("max_reserved_workers") - final Integer maxReservedWorkers, - - @JsonProperty("reservation_activity_sid") - final String reservationActivitySid, - - @JsonProperty("reservation_activity_name") - final String reservationActivityName, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("target_workers") - final String targetWorkers, - - @JsonProperty("task_order") - final TaskQueue.TaskOrder taskOrder, - - @JsonProperty("url") - final URI url, - - @JsonProperty("workspace_sid") - final String workspaceSid, - - @JsonProperty("links") - final Map links + @JsonProperty("account_sid") final String accountSid, + @JsonProperty( + "assignment_activity_sid" + ) final String assignmentActivitySid, + @JsonProperty( + "assignment_activity_name" + ) final String assignmentActivityName, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("max_reserved_workers") final Integer maxReservedWorkers, + @JsonProperty( + "reservation_activity_sid" + ) final String reservationActivitySid, + @JsonProperty( + "reservation_activity_name" + ) final String reservationActivityName, + @JsonProperty("sid") final String sid, + @JsonProperty("target_workers") final String targetWorkers, + @JsonProperty("task_order") final TaskQueue.TaskOrder taskOrder, + @JsonProperty("url") final URI url, + @JsonProperty("workspace_sid") final String workspaceSid, + @JsonProperty("links") final Map links ) { this.accountSid = accountSid; this.assignmentActivitySid = assignmentActivitySid; @@ -201,55 +195,69 @@ private TaskQueue( this.links = links; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getAssignmentActivitySid() { - return this.assignmentActivitySid; - } - public final String getAssignmentActivityName() { - return this.assignmentActivityName; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final Integer getMaxReservedWorkers() { - return this.maxReservedWorkers; - } - public final String getReservationActivitySid() { - return this.reservationActivitySid; - } - public final String getReservationActivityName() { - return this.reservationActivityName; - } - public final String getSid() { - return this.sid; - } - public final String getTargetWorkers() { - return this.targetWorkers; - } - public final TaskQueue.TaskOrder getTaskOrder() { - return this.taskOrder; - } - public final URI getUrl() { - return this.url; - } - public final String getWorkspaceSid() { - return this.workspaceSid; - } - public final Map getLinks() { - return this.links; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getAssignmentActivitySid() { + return this.assignmentActivitySid; + } + + public final String getAssignmentActivityName() { + return this.assignmentActivityName; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final Integer getMaxReservedWorkers() { + return this.maxReservedWorkers; + } + + public final String getReservationActivitySid() { + return this.reservationActivitySid; + } + + public final String getReservationActivityName() { + return this.reservationActivityName; + } + + public final String getSid() { + return this.sid; + } + + public final String getTargetWorkers() { + return this.targetWorkers; + } + + public final TaskQueue.TaskOrder getTaskOrder() { + return this.taskOrder; + } + + public final URI getUrl() { + return this.url; + } + + public final String getWorkspaceSid() { + return this.workspaceSid; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -259,13 +267,55 @@ public boolean equals(final Object o) { TaskQueue other = (TaskQueue) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(assignmentActivitySid, other.assignmentActivitySid) && Objects.equals(assignmentActivityName, other.assignmentActivityName) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(maxReservedWorkers, other.maxReservedWorkers) && Objects.equals(reservationActivitySid, other.reservationActivitySid) && Objects.equals(reservationActivityName, other.reservationActivityName) && Objects.equals(sid, other.sid) && Objects.equals(targetWorkers, other.targetWorkers) && Objects.equals(taskOrder, other.taskOrder) && Objects.equals(url, other.url) && Objects.equals(workspaceSid, other.workspaceSid) && Objects.equals(links, other.links) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals( + assignmentActivitySid, + other.assignmentActivitySid + ) && + Objects.equals( + assignmentActivityName, + other.assignmentActivityName + ) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(maxReservedWorkers, other.maxReservedWorkers) && + Objects.equals( + reservationActivitySid, + other.reservationActivitySid + ) && + Objects.equals( + reservationActivityName, + other.reservationActivityName + ) && + Objects.equals(sid, other.sid) && + Objects.equals(targetWorkers, other.targetWorkers) && + Objects.equals(taskOrder, other.taskOrder) && + Objects.equals(url, other.url) && + Objects.equals(workspaceSid, other.workspaceSid) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, assignmentActivitySid, assignmentActivityName, dateCreated, dateUpdated, friendlyName, maxReservedWorkers, reservationActivitySid, reservationActivityName, sid, targetWorkers, taskOrder, url, workspaceSid, links); + return Objects.hash( + accountSid, + assignmentActivitySid, + assignmentActivityName, + dateCreated, + dateUpdated, + friendlyName, + maxReservedWorkers, + reservationActivitySid, + reservationActivityName, + sid, + targetWorkers, + taskOrder, + url, + workspaceSid, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskQueueCreator.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskQueueCreator.java index 0368ff0517..91c712c086 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskQueueCreator.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskQueueCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.taskrouter.v1.workspace; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class TaskQueueCreator extends Creator { - - -public class TaskQueueCreator extends Creator{ private String pathWorkspaceSid; private String friendlyName; private String targetWorkers; @@ -36,86 +35,121 @@ public class TaskQueueCreator extends Creator{ private String reservationActivitySid; private String assignmentActivitySid; - public TaskQueueCreator(final String pathWorkspaceSid, final String friendlyName) { + public TaskQueueCreator( + final String pathWorkspaceSid, + final String friendlyName + ) { this.pathWorkspaceSid = pathWorkspaceSid; this.friendlyName = friendlyName; } - public TaskQueueCreator setFriendlyName(final String friendlyName){ + public TaskQueueCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public TaskQueueCreator setTargetWorkers(final String targetWorkers){ + + public TaskQueueCreator setTargetWorkers(final String targetWorkers) { this.targetWorkers = targetWorkers; return this; } - public TaskQueueCreator setMaxReservedWorkers(final Integer maxReservedWorkers){ + + public TaskQueueCreator setMaxReservedWorkers( + final Integer maxReservedWorkers + ) { this.maxReservedWorkers = maxReservedWorkers; return this; } - public TaskQueueCreator setTaskOrder(final TaskQueue.TaskOrder taskOrder){ + + public TaskQueueCreator setTaskOrder(final TaskQueue.TaskOrder taskOrder) { this.taskOrder = taskOrder; return this; } - public TaskQueueCreator setReservationActivitySid(final String reservationActivitySid){ + + public TaskQueueCreator setReservationActivitySid( + final String reservationActivitySid + ) { this.reservationActivitySid = reservationActivitySid; return this; } - public TaskQueueCreator setAssignmentActivitySid(final String assignmentActivitySid){ + + public TaskQueueCreator setAssignmentActivitySid( + final String assignmentActivitySid + ) { this.assignmentActivitySid = assignmentActivitySid; return this; } @Override - public TaskQueue create(final TwilioRestClient client){ + public TaskQueue create(final TwilioRestClient client) { String path = "/v1/Workspaces/{WorkspaceSid}/TaskQueues"; - path = path.replace("{"+"WorkspaceSid"+"}", this.pathWorkspaceSid.toString()); - path = path.replace("{"+"FriendlyName"+"}", this.friendlyName.toString()); + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = + path.replace( + "{" + "FriendlyName" + "}", + this.friendlyName.toString() + ); Request request = new Request( HttpMethod.POST, Domains.TASKROUTER.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("TaskQueue creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "TaskQueue creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return TaskQueue.fromJson(response.getStream(), client.getObjectMapper()); + return TaskQueue.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (targetWorkers != null) { request.addPostParam("TargetWorkers", targetWorkers); - } if (maxReservedWorkers != null) { - request.addPostParam("MaxReservedWorkers", maxReservedWorkers.toString()); - + request.addPostParam( + "MaxReservedWorkers", + maxReservedWorkers.toString() + ); } if (taskOrder != null) { request.addPostParam("TaskOrder", taskOrder.toString()); - } if (reservationActivitySid != null) { - request.addPostParam("ReservationActivitySid", reservationActivitySid); - + request.addPostParam( + "ReservationActivitySid", + reservationActivitySid + ); } if (assignmentActivitySid != null) { - request.addPostParam("AssignmentActivitySid", assignmentActivitySid); - + request.addPostParam( + "AssignmentActivitySid", + assignmentActivitySid + ); } } } diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskQueueDeleter.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskQueueDeleter.java index 5f72a21ecb..5d3e887858 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskQueueDeleter.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskQueueDeleter.java @@ -24,24 +24,29 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class TaskQueueDeleter extends Deleter { + private String pathWorkspaceSid; private String pathSid; - public TaskQueueDeleter(final String pathWorkspaceSid, final String pathSid){ + public TaskQueueDeleter( + final String pathWorkspaceSid, + final String pathSid + ) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Workspaces/{WorkspaceSid}/TaskQueues/{Sid}"; - path = path.replace("{"+"WorkspaceSid"+"}", this.pathWorkspaceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +56,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("TaskQueue delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "TaskQueue delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskQueueFetcher.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskQueueFetcher.java index 86c66ebb08..422c3a478b 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskQueueFetcher.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskQueueFetcher.java @@ -24,25 +24,29 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class TaskQueueFetcher extends Fetcher { + private String pathWorkspaceSid; private String pathSid; - public TaskQueueFetcher(final String pathWorkspaceSid, final String pathSid){ + public TaskQueueFetcher( + final String pathWorkspaceSid, + final String pathSid + ) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathSid = pathSid; } - @Override public TaskQueue fetch(final TwilioRestClient client) { String path = "/v1/Workspaces/{WorkspaceSid}/TaskQueues/{Sid}"; - path = path.replace("{"+"WorkspaceSid"+"}", this.pathWorkspaceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,15 +56,23 @@ public TaskQueue fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("TaskQueue fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "TaskQueue fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return TaskQueue.fromJson(response.getStream(), client.getObjectMapper()); + return TaskQueue.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskQueueReader.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskQueueReader.java index 8a6c29cf3f..595145c3c5 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskQueueReader.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskQueueReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.taskrouter.v1.workspace; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,11 +25,9 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class TaskQueueReader extends Reader { + private String pathWorkspaceSid; private String friendlyName; private String evaluateWorkerAttributes; @@ -36,27 +35,33 @@ public class TaskQueueReader extends Reader { private String ordering; private Integer pageSize; - public TaskQueueReader(final String pathWorkspaceSid){ + public TaskQueueReader(final String pathWorkspaceSid) { this.pathWorkspaceSid = pathWorkspaceSid; } - public TaskQueueReader setFriendlyName(final String friendlyName){ + public TaskQueueReader setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public TaskQueueReader setEvaluateWorkerAttributes(final String evaluateWorkerAttributes){ + + public TaskQueueReader setEvaluateWorkerAttributes( + final String evaluateWorkerAttributes + ) { this.evaluateWorkerAttributes = evaluateWorkerAttributes; return this; } - public TaskQueueReader setWorkerSid(final String workerSid){ + + public TaskQueueReader setWorkerSid(final String workerSid) { this.workerSid = workerSid; return this; } - public TaskQueueReader setOrdering(final String ordering){ + + public TaskQueueReader setOrdering(final String ordering) { this.ordering = ordering; return this; } - public TaskQueueReader setPageSize(final Integer pageSize){ + + public TaskQueueReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -68,7 +73,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Workspaces/{WorkspaceSid}/TaskQueues"; - path = path.replace("{"+"WorkspaceSid"+"}", this.pathWorkspaceSid.toString()); + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -80,13 +89,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("TaskQueue read failed: Unable to connect to server"); + throw new ApiConnectionException( + "TaskQueue read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -102,7 +119,10 @@ private Page pageForRequest(final TwilioRestClient client, final Requ } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.TASKROUTER.toString()) @@ -110,9 +130,11 @@ public Page previousPage(final Page page, final TwilioRest return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.TASKROUTER.toString()) @@ -121,37 +143,36 @@ public Page nextPage(final Page page, final TwilioRestClie } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (friendlyName != null) { - request.addQueryParam("FriendlyName", friendlyName); } if (evaluateWorkerAttributes != null) { - - request.addQueryParam("EvaluateWorkerAttributes", evaluateWorkerAttributes); + request.addQueryParam( + "EvaluateWorkerAttributes", + evaluateWorkerAttributes + ); } if (workerSid != null) { - request.addQueryParam("WorkerSid", workerSid); } if (ordering != null) { - request.addQueryParam("Ordering", ordering); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskQueueUpdater.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskQueueUpdater.java index 6a797dec5b..cbeb21b544 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskQueueUpdater.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskQueueUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.taskrouter.v1.workspace; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class TaskQueueUpdater extends Updater { - - -public class TaskQueueUpdater extends Updater{ private String pathWorkspaceSid; private String pathSid; private String friendlyName; @@ -37,86 +36,117 @@ public class TaskQueueUpdater extends Updater{ private Integer maxReservedWorkers; private TaskQueue.TaskOrder taskOrder; - public TaskQueueUpdater(final String pathWorkspaceSid, final String pathSid){ + public TaskQueueUpdater( + final String pathWorkspaceSid, + final String pathSid + ) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathSid = pathSid; } - public TaskQueueUpdater setFriendlyName(final String friendlyName){ + public TaskQueueUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public TaskQueueUpdater setTargetWorkers(final String targetWorkers){ + + public TaskQueueUpdater setTargetWorkers(final String targetWorkers) { this.targetWorkers = targetWorkers; return this; } - public TaskQueueUpdater setReservationActivitySid(final String reservationActivitySid){ + + public TaskQueueUpdater setReservationActivitySid( + final String reservationActivitySid + ) { this.reservationActivitySid = reservationActivitySid; return this; } - public TaskQueueUpdater setAssignmentActivitySid(final String assignmentActivitySid){ + + public TaskQueueUpdater setAssignmentActivitySid( + final String assignmentActivitySid + ) { this.assignmentActivitySid = assignmentActivitySid; return this; } - public TaskQueueUpdater setMaxReservedWorkers(final Integer maxReservedWorkers){ + + public TaskQueueUpdater setMaxReservedWorkers( + final Integer maxReservedWorkers + ) { this.maxReservedWorkers = maxReservedWorkers; return this; } - public TaskQueueUpdater setTaskOrder(final TaskQueue.TaskOrder taskOrder){ + + public TaskQueueUpdater setTaskOrder(final TaskQueue.TaskOrder taskOrder) { this.taskOrder = taskOrder; return this; } @Override - public TaskQueue update(final TwilioRestClient client){ + public TaskQueue update(final TwilioRestClient client) { String path = "/v1/Workspaces/{WorkspaceSid}/TaskQueues/{Sid}"; - path = path.replace("{"+"WorkspaceSid"+"}", this.pathWorkspaceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.TASKROUTER.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("TaskQueue update failed: Unable to connect to server"); + throw new ApiConnectionException( + "TaskQueue update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return TaskQueue.fromJson(response.getStream(), client.getObjectMapper()); + return TaskQueue.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (targetWorkers != null) { request.addPostParam("TargetWorkers", targetWorkers); - } if (reservationActivitySid != null) { - request.addPostParam("ReservationActivitySid", reservationActivitySid); - + request.addPostParam( + "ReservationActivitySid", + reservationActivitySid + ); } if (assignmentActivitySid != null) { - request.addPostParam("AssignmentActivitySid", assignmentActivitySid); - + request.addPostParam( + "AssignmentActivitySid", + assignmentActivitySid + ); } if (maxReservedWorkers != null) { - request.addPostParam("MaxReservedWorkers", maxReservedWorkers.toString()); - + request.addPostParam( + "MaxReservedWorkers", + maxReservedWorkers.toString() + ); } if (taskOrder != null) { request.addPostParam("TaskOrder", taskOrder.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskReader.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskReader.java index dab0d7cab8..b2ce0f5dd1 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskReader.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.taskrouter.v1.workspace; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.converter.Promoter; @@ -25,12 +26,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - import java.util.List; - public class TaskReader extends Reader { + private String pathWorkspaceSid; private Integer priority; private List assignmentStatus; @@ -43,50 +42,62 @@ public class TaskReader extends Reader { private Boolean hasAddons; private Integer pageSize; - public TaskReader(final String pathWorkspaceSid){ + public TaskReader(final String pathWorkspaceSid) { this.pathWorkspaceSid = pathWorkspaceSid; } - public TaskReader setPriority(final Integer priority){ + public TaskReader setPriority(final Integer priority) { this.priority = priority; return this; } - public TaskReader setAssignmentStatus(final List assignmentStatus){ + + public TaskReader setAssignmentStatus(final List assignmentStatus) { this.assignmentStatus = assignmentStatus; return this; } - public TaskReader setAssignmentStatus(final String assignmentStatus){ + + public TaskReader setAssignmentStatus(final String assignmentStatus) { return setAssignmentStatus(Promoter.listOfOne(assignmentStatus)); } - public TaskReader setWorkflowSid(final String workflowSid){ + + public TaskReader setWorkflowSid(final String workflowSid) { this.workflowSid = workflowSid; return this; } - public TaskReader setWorkflowName(final String workflowName){ + + public TaskReader setWorkflowName(final String workflowName) { this.workflowName = workflowName; return this; } - public TaskReader setTaskQueueSid(final String taskQueueSid){ + + public TaskReader setTaskQueueSid(final String taskQueueSid) { this.taskQueueSid = taskQueueSid; return this; } - public TaskReader setTaskQueueName(final String taskQueueName){ + + public TaskReader setTaskQueueName(final String taskQueueName) { this.taskQueueName = taskQueueName; return this; } - public TaskReader setEvaluateTaskAttributes(final String evaluateTaskAttributes){ + + public TaskReader setEvaluateTaskAttributes( + final String evaluateTaskAttributes + ) { this.evaluateTaskAttributes = evaluateTaskAttributes; return this; } - public TaskReader setOrdering(final String ordering){ + + public TaskReader setOrdering(final String ordering) { this.ordering = ordering; return this; } - public TaskReader setHasAddons(final Boolean hasAddons){ + + public TaskReader setHasAddons(final Boolean hasAddons) { this.hasAddons = hasAddons; return this; } - public TaskReader setPageSize(final Integer pageSize){ + + public TaskReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -98,7 +109,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Workspaces/{WorkspaceSid}/Tasks"; - path = path.replace("{"+"WorkspaceSid"+"}", this.pathWorkspaceSid.toString()); + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -110,13 +125,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Task read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Task read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -132,7 +155,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request r } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.TASKROUTER.toString()) @@ -140,9 +166,11 @@ public Page previousPage(final Page page, final TwilioRestClient cli return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.TASKROUTER.toString()) @@ -151,17 +179,17 @@ public Page nextPage(final Page page, final TwilioRestClient client) } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (priority != null) { - request.addQueryParam("Priority", priority.toString()); } if (assignmentStatus != null) { @@ -170,39 +198,34 @@ private void addQueryParams(final Request request) { } } if (workflowSid != null) { - request.addQueryParam("WorkflowSid", workflowSid); } if (workflowName != null) { - request.addQueryParam("WorkflowName", workflowName); } if (taskQueueSid != null) { - request.addQueryParam("TaskQueueSid", taskQueueSid); } if (taskQueueName != null) { - request.addQueryParam("TaskQueueName", taskQueueName); } if (evaluateTaskAttributes != null) { - - request.addQueryParam("EvaluateTaskAttributes", evaluateTaskAttributes); + request.addQueryParam( + "EvaluateTaskAttributes", + evaluateTaskAttributes + ); } if (ordering != null) { - request.addQueryParam("Ordering", ordering); } if (hasAddons != null) { - request.addQueryParam("HasAddons", hasAddons.toString()); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskUpdater.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskUpdater.java index f0cd5ffdde..5d9bd4d58c 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskUpdater.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.taskrouter.v1.workspace; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class TaskUpdater extends Updater { - - -public class TaskUpdater extends Updater{ private String pathWorkspaceSid; private String pathSid; private String ifMatch; @@ -37,55 +36,70 @@ public class TaskUpdater extends Updater{ private Integer priority; private String taskChannel; - public TaskUpdater(final String pathWorkspaceSid, final String pathSid){ + public TaskUpdater(final String pathWorkspaceSid, final String pathSid) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathSid = pathSid; } - public TaskUpdater setIfMatch(final String ifMatch){ + public TaskUpdater setIfMatch(final String ifMatch) { this.ifMatch = ifMatch; return this; } - public TaskUpdater setAttributes(final String attributes){ + + public TaskUpdater setAttributes(final String attributes) { this.attributes = attributes; return this; } - public TaskUpdater setAssignmentStatus(final Task.Status assignmentStatus){ + + public TaskUpdater setAssignmentStatus(final Task.Status assignmentStatus) { this.assignmentStatus = assignmentStatus; return this; } - public TaskUpdater setReason(final String reason){ + + public TaskUpdater setReason(final String reason) { this.reason = reason; return this; } - public TaskUpdater setPriority(final Integer priority){ + + public TaskUpdater setPriority(final Integer priority) { this.priority = priority; return this; } - public TaskUpdater setTaskChannel(final String taskChannel){ + + public TaskUpdater setTaskChannel(final String taskChannel) { this.taskChannel = taskChannel; return this; } @Override - public Task update(final TwilioRestClient client){ + public Task update(final TwilioRestClient client) { String path = "/v1/Workspaces/{WorkspaceSid}/Tasks/{Sid}"; - path = path.replace("{"+"WorkspaceSid"+"}", this.pathWorkspaceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.TASKROUTER.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); addHeaderParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Task update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Task update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -94,32 +108,31 @@ public Task update(final TwilioRestClient client){ return Task.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (attributes != null) { request.addPostParam("Attributes", attributes); - } if (assignmentStatus != null) { - request.addPostParam("AssignmentStatus", assignmentStatus.toString()); - + request.addPostParam( + "AssignmentStatus", + assignmentStatus.toString() + ); } if (reason != null) { request.addPostParam("Reason", reason); - } if (priority != null) { request.addPostParam("Priority", priority.toString()); - } if (taskChannel != null) { request.addPostParam("TaskChannel", taskChannel); - } } + private void addHeaderParams(final Request request) { if (ifMatch != null) { request.addHeaderParam("If-Match", ifMatch); - } } } diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/Worker.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/Worker.java index e98d80c8e6..9c7b7cfee7 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/Worker.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/Worker.java @@ -23,55 +23,66 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Worker extends Resource { + private static final long serialVersionUID = 110824061154379L; - public static WorkerCreator creator(final String pathWorkspaceSid, final String friendlyName){ + public static WorkerCreator creator( + final String pathWorkspaceSid, + final String friendlyName + ) { return new WorkerCreator(pathWorkspaceSid, friendlyName); } - public static WorkerDeleter deleter(final String pathWorkspaceSid, final String pathSid){ + public static WorkerDeleter deleter( + final String pathWorkspaceSid, + final String pathSid + ) { return new WorkerDeleter(pathWorkspaceSid, pathSid); } - public static WorkerFetcher fetcher(final String pathWorkspaceSid, final String pathSid){ + public static WorkerFetcher fetcher( + final String pathWorkspaceSid, + final String pathSid + ) { return new WorkerFetcher(pathWorkspaceSid, pathSid); } - public static WorkerReader reader(final String pathWorkspaceSid){ + public static WorkerReader reader(final String pathWorkspaceSid) { return new WorkerReader(pathWorkspaceSid); } - public static WorkerUpdater updater(final String pathWorkspaceSid, final String pathSid){ + public static WorkerUpdater updater( + final String pathWorkspaceSid, + final String pathSid + ) { return new WorkerUpdater(pathWorkspaceSid, pathSid); } /** - * Converts a JSON String into a Worker object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Worker object represented by the provided JSON - */ - public static Worker fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Worker object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Worker object represented by the provided JSON + */ + public static Worker fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Worker.class); @@ -83,14 +94,17 @@ public static Worker fromJson(final String json, final ObjectMapper objectMapper } /** - * Converts a JSON InputStream into a Worker object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Worker object represented by the provided JSON - */ - public static Worker fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Worker object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Worker object represented by the provided JSON + */ + public static Worker fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Worker.class); @@ -117,44 +131,19 @@ public static Worker fromJson(final InputStream json, final ObjectMapper objectM @JsonCreator private Worker( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("activity_name") - final String activityName, - - @JsonProperty("activity_sid") - final String activitySid, - - @JsonProperty("attributes") - final String attributes, - - @JsonProperty("available") - final Boolean available, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_status_changed") - final String dateStatusChanged, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("workspace_sid") - final String workspaceSid, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("activity_name") final String activityName, + @JsonProperty("activity_sid") final String activitySid, + @JsonProperty("attributes") final String attributes, + @JsonProperty("available") final Boolean available, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_status_changed") final String dateStatusChanged, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("sid") final String sid, + @JsonProperty("workspace_sid") final String workspaceSid, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.accountSid = accountSid; this.activityName = activityName; @@ -162,7 +151,8 @@ private Worker( this.attributes = attributes; this.available = available; this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateStatusChanged = DateConverter.iso8601DateTimeFromString(dateStatusChanged); + this.dateStatusChanged = + DateConverter.iso8601DateTimeFromString(dateStatusChanged); this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); this.friendlyName = friendlyName; this.sid = sid; @@ -171,49 +161,61 @@ private Worker( this.links = links; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getActivityName() { - return this.activityName; - } - public final String getActivitySid() { - return this.activitySid; - } - public final String getAttributes() { - return this.attributes; - } - public final Boolean getAvailable() { - return this.available; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateStatusChanged() { - return this.dateStatusChanged; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getSid() { - return this.sid; - } - public final String getWorkspaceSid() { - return this.workspaceSid; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getActivityName() { + return this.activityName; + } + + public final String getActivitySid() { + return this.activitySid; + } + + public final String getAttributes() { + return this.attributes; + } + + public final Boolean getAvailable() { + return this.available; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateStatusChanged() { + return this.dateStatusChanged; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getSid() { + return this.sid; + } + + public final String getWorkspaceSid() { + return this.workspaceSid; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -223,13 +225,39 @@ public boolean equals(final Object o) { Worker other = (Worker) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(activityName, other.activityName) && Objects.equals(activitySid, other.activitySid) && Objects.equals(attributes, other.attributes) && Objects.equals(available, other.available) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateStatusChanged, other.dateStatusChanged) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(sid, other.sid) && Objects.equals(workspaceSid, other.workspaceSid) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(activityName, other.activityName) && + Objects.equals(activitySid, other.activitySid) && + Objects.equals(attributes, other.attributes) && + Objects.equals(available, other.available) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateStatusChanged, other.dateStatusChanged) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(sid, other.sid) && + Objects.equals(workspaceSid, other.workspaceSid) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, activityName, activitySid, attributes, available, dateCreated, dateStatusChanged, dateUpdated, friendlyName, sid, workspaceSid, url, links); + return Objects.hash( + accountSid, + activityName, + activitySid, + attributes, + available, + dateCreated, + dateStatusChanged, + dateUpdated, + friendlyName, + sid, + workspaceSid, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkerCreator.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkerCreator.java index 6070d5a76f..4348783d6d 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkerCreator.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkerCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.taskrouter.v1.workspace; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,51 +25,68 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class WorkerCreator extends Creator { - - -public class WorkerCreator extends Creator{ private String pathWorkspaceSid; private String friendlyName; private String activitySid; private String attributes; - public WorkerCreator(final String pathWorkspaceSid, final String friendlyName) { + public WorkerCreator( + final String pathWorkspaceSid, + final String friendlyName + ) { this.pathWorkspaceSid = pathWorkspaceSid; this.friendlyName = friendlyName; } - public WorkerCreator setFriendlyName(final String friendlyName){ + public WorkerCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public WorkerCreator setActivitySid(final String activitySid){ + + public WorkerCreator setActivitySid(final String activitySid) { this.activitySid = activitySid; return this; } - public WorkerCreator setAttributes(final String attributes){ + + public WorkerCreator setAttributes(final String attributes) { this.attributes = attributes; return this; } @Override - public Worker create(final TwilioRestClient client){ + public Worker create(final TwilioRestClient client) { String path = "/v1/Workspaces/{WorkspaceSid}/Workers"; - path = path.replace("{"+"WorkspaceSid"+"}", this.pathWorkspaceSid.toString()); - path = path.replace("{"+"FriendlyName"+"}", this.friendlyName.toString()); + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = + path.replace( + "{" + "FriendlyName" + "}", + this.friendlyName.toString() + ); Request request = new Request( HttpMethod.POST, Domains.TASKROUTER.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Worker creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Worker creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -77,18 +95,16 @@ public Worker create(final TwilioRestClient client){ return Worker.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (activitySid != null) { request.addPostParam("ActivitySid", activitySid); - } if (attributes != null) { request.addPostParam("Attributes", attributes); - } } } diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkerDeleter.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkerDeleter.java index f35fe0f2cc..2194615979 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkerDeleter.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkerDeleter.java @@ -24,19 +24,18 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class WorkerDeleter extends Deleter { + private String pathWorkspaceSid; private String pathSid; private String ifMatch; - public WorkerDeleter(final String pathWorkspaceSid, final String pathSid){ + public WorkerDeleter(final String pathWorkspaceSid, final String pathSid) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathSid = pathSid; } - public WorkerDeleter setIfMatch(final String ifMatch){ + public WorkerDeleter setIfMatch(final String ifMatch) { this.ifMatch = ifMatch; return this; } @@ -45,8 +44,12 @@ public WorkerDeleter setIfMatch(final String ifMatch){ public boolean delete(final TwilioRestClient client) { String path = "/v1/Workspaces/{WorkspaceSid}/Workers/{Sid}"; - path = path.replace("{"+"WorkspaceSid"+"}", this.pathWorkspaceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -57,9 +60,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Worker delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Worker delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -67,10 +75,10 @@ public boolean delete(final TwilioRestClient client) { } return response.getStatusCode() == 204; } + private void addHeaderParams(final Request request) { if (ifMatch != null) { request.addHeaderParam("If-Match", ifMatch); - } } } diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkerFetcher.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkerFetcher.java index b76457fd71..89a26a8079 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkerFetcher.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkerFetcher.java @@ -24,25 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class WorkerFetcher extends Fetcher { + private String pathWorkspaceSid; private String pathSid; - public WorkerFetcher(final String pathWorkspaceSid, final String pathSid){ + public WorkerFetcher(final String pathWorkspaceSid, final String pathSid) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathSid = pathSid; } - @Override public Worker fetch(final TwilioRestClient client) { String path = "/v1/Workspaces/{WorkspaceSid}/Workers/{Sid}"; - path = path.replace("{"+"WorkspaceSid"+"}", this.pathWorkspaceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,9 +53,14 @@ public Worker fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Worker fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Worker fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkerReader.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkerReader.java index 3d6f00d5c1..acc160e9e3 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkerReader.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkerReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.taskrouter.v1.workspace; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,11 +25,9 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class WorkerReader extends Reader { + private String pathWorkspaceSid; private String activityName; private String activitySid; @@ -40,43 +39,53 @@ public class WorkerReader extends Reader { private String ordering; private Integer pageSize; - public WorkerReader(final String pathWorkspaceSid){ + public WorkerReader(final String pathWorkspaceSid) { this.pathWorkspaceSid = pathWorkspaceSid; } - public WorkerReader setActivityName(final String activityName){ + public WorkerReader setActivityName(final String activityName) { this.activityName = activityName; return this; } - public WorkerReader setActivitySid(final String activitySid){ + + public WorkerReader setActivitySid(final String activitySid) { this.activitySid = activitySid; return this; } - public WorkerReader setAvailable(final String available){ + + public WorkerReader setAvailable(final String available) { this.available = available; return this; } - public WorkerReader setFriendlyName(final String friendlyName){ + + public WorkerReader setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public WorkerReader setTargetWorkersExpression(final String targetWorkersExpression){ + + public WorkerReader setTargetWorkersExpression( + final String targetWorkersExpression + ) { this.targetWorkersExpression = targetWorkersExpression; return this; } - public WorkerReader setTaskQueueName(final String taskQueueName){ + + public WorkerReader setTaskQueueName(final String taskQueueName) { this.taskQueueName = taskQueueName; return this; } - public WorkerReader setTaskQueueSid(final String taskQueueSid){ + + public WorkerReader setTaskQueueSid(final String taskQueueSid) { this.taskQueueSid = taskQueueSid; return this; } - public WorkerReader setOrdering(final String ordering){ + + public WorkerReader setOrdering(final String ordering) { this.ordering = ordering; return this; } - public WorkerReader setPageSize(final Integer pageSize){ + + public WorkerReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -88,7 +97,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Workspaces/{WorkspaceSid}/Workers"; - path = path.replace("{"+"WorkspaceSid"+"}", this.pathWorkspaceSid.toString()); + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -100,13 +113,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Worker read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Worker read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -122,7 +143,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.TASKROUTER.toString()) @@ -130,9 +154,11 @@ public Page previousPage(final Page page, final TwilioRestClient return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.TASKROUTER.toString()) @@ -141,53 +167,48 @@ public Page nextPage(final Page page, final TwilioRestClient cli } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (activityName != null) { - request.addQueryParam("ActivityName", activityName); } if (activitySid != null) { - request.addQueryParam("ActivitySid", activitySid); } if (available != null) { - request.addQueryParam("Available", available); } if (friendlyName != null) { - request.addQueryParam("FriendlyName", friendlyName); } if (targetWorkersExpression != null) { - - request.addQueryParam("TargetWorkersExpression", targetWorkersExpression); + request.addQueryParam( + "TargetWorkersExpression", + targetWorkersExpression + ); } if (taskQueueName != null) { - request.addQueryParam("TaskQueueName", taskQueueName); } if (taskQueueSid != null) { - request.addQueryParam("TaskQueueSid", taskQueueSid); } if (ordering != null) { - request.addQueryParam("Ordering", ordering); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkerUpdater.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkerUpdater.java index a1ba6c7ebe..20899cd27d 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkerUpdater.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkerUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.taskrouter.v1.workspace; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class WorkerUpdater extends Updater { - - -public class WorkerUpdater extends Updater{ private String pathWorkspaceSid; private String pathSid; private String ifMatch; @@ -36,51 +35,67 @@ public class WorkerUpdater extends Updater{ private String friendlyName; private Boolean rejectPendingReservations; - public WorkerUpdater(final String pathWorkspaceSid, final String pathSid){ + public WorkerUpdater(final String pathWorkspaceSid, final String pathSid) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathSid = pathSid; } - public WorkerUpdater setIfMatch(final String ifMatch){ + public WorkerUpdater setIfMatch(final String ifMatch) { this.ifMatch = ifMatch; return this; } - public WorkerUpdater setActivitySid(final String activitySid){ + + public WorkerUpdater setActivitySid(final String activitySid) { this.activitySid = activitySid; return this; } - public WorkerUpdater setAttributes(final String attributes){ + + public WorkerUpdater setAttributes(final String attributes) { this.attributes = attributes; return this; } - public WorkerUpdater setFriendlyName(final String friendlyName){ + + public WorkerUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public WorkerUpdater setRejectPendingReservations(final Boolean rejectPendingReservations){ + + public WorkerUpdater setRejectPendingReservations( + final Boolean rejectPendingReservations + ) { this.rejectPendingReservations = rejectPendingReservations; return this; } @Override - public Worker update(final TwilioRestClient client){ + public Worker update(final TwilioRestClient client) { String path = "/v1/Workspaces/{WorkspaceSid}/Workers/{Sid}"; - path = path.replace("{"+"WorkspaceSid"+"}", this.pathWorkspaceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.TASKROUTER.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); addHeaderParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Worker update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Worker update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -89,28 +104,28 @@ public Worker update(final TwilioRestClient client){ return Worker.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (activitySid != null) { request.addPostParam("ActivitySid", activitySid); - } if (attributes != null) { request.addPostParam("Attributes", attributes); - } if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (rejectPendingReservations != null) { - request.addPostParam("RejectPendingReservations", rejectPendingReservations.toString()); - + request.addPostParam( + "RejectPendingReservations", + rejectPendingReservations.toString() + ); } } + private void addHeaderParams(final Request request) { if (ifMatch != null) { request.addHeaderParam("If-Match", ifMatch); - } } } diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/Workflow.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/Workflow.java index d703d1c4f3..20ee3718b4 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/Workflow.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/Workflow.java @@ -23,55 +23,71 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Workflow extends Resource { + private static final long serialVersionUID = 204168447451968L; - public static WorkflowCreator creator(final String pathWorkspaceSid, final String friendlyName, final String configuration){ - return new WorkflowCreator(pathWorkspaceSid, friendlyName, configuration); + public static WorkflowCreator creator( + final String pathWorkspaceSid, + final String friendlyName, + final String configuration + ) { + return new WorkflowCreator( + pathWorkspaceSid, + friendlyName, + configuration + ); } - public static WorkflowDeleter deleter(final String pathWorkspaceSid, final String pathSid){ + public static WorkflowDeleter deleter( + final String pathWorkspaceSid, + final String pathSid + ) { return new WorkflowDeleter(pathWorkspaceSid, pathSid); } - public static WorkflowFetcher fetcher(final String pathWorkspaceSid, final String pathSid){ + public static WorkflowFetcher fetcher( + final String pathWorkspaceSid, + final String pathSid + ) { return new WorkflowFetcher(pathWorkspaceSid, pathSid); } - public static WorkflowReader reader(final String pathWorkspaceSid){ + public static WorkflowReader reader(final String pathWorkspaceSid) { return new WorkflowReader(pathWorkspaceSid); } - public static WorkflowUpdater updater(final String pathWorkspaceSid, final String pathSid){ + public static WorkflowUpdater updater( + final String pathWorkspaceSid, + final String pathSid + ) { return new WorkflowUpdater(pathWorkspaceSid, pathSid); } /** - * Converts a JSON String into a Workflow object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Workflow object represented by the provided JSON - */ - public static Workflow fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Workflow object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Workflow object represented by the provided JSON + */ + public static Workflow fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Workflow.class); @@ -83,14 +99,17 @@ public static Workflow fromJson(final String json, final ObjectMapper objectMapp } /** - * Converts a JSON InputStream into a Workflow object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Workflow object represented by the provided JSON - */ - public static Workflow fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Workflow object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Workflow object represented by the provided JSON + */ + public static Workflow fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Workflow.class); @@ -117,44 +136,25 @@ public static Workflow fromJson(final InputStream json, final ObjectMapper objec @JsonCreator private Workflow( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("assignment_callback_url") - final URI assignmentCallbackUrl, - - @JsonProperty("configuration") - final String configuration, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("document_content_type") - final String documentContentType, - - @JsonProperty("fallback_assignment_callback_url") - final URI fallbackAssignmentCallbackUrl, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("task_reservation_timeout") - final Integer taskReservationTimeout, - - @JsonProperty("workspace_sid") - final String workspaceSid, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("account_sid") final String accountSid, + @JsonProperty( + "assignment_callback_url" + ) final URI assignmentCallbackUrl, + @JsonProperty("configuration") final String configuration, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("document_content_type") final String documentContentType, + @JsonProperty( + "fallback_assignment_callback_url" + ) final URI fallbackAssignmentCallbackUrl, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("sid") final String sid, + @JsonProperty( + "task_reservation_timeout" + ) final Integer taskReservationTimeout, + @JsonProperty("workspace_sid") final String workspaceSid, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.accountSid = accountSid; this.assignmentCallbackUrl = assignmentCallbackUrl; @@ -171,49 +171,61 @@ private Workflow( this.links = links; } - public final String getAccountSid() { - return this.accountSid; - } - public final URI getAssignmentCallbackUrl() { - return this.assignmentCallbackUrl; - } - public final String getConfiguration() { - return this.configuration; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getDocumentContentType() { - return this.documentContentType; - } - public final URI getFallbackAssignmentCallbackUrl() { - return this.fallbackAssignmentCallbackUrl; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getSid() { - return this.sid; - } - public final Integer getTaskReservationTimeout() { - return this.taskReservationTimeout; - } - public final String getWorkspaceSid() { - return this.workspaceSid; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final URI getAssignmentCallbackUrl() { + return this.assignmentCallbackUrl; + } + + public final String getConfiguration() { + return this.configuration; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getDocumentContentType() { + return this.documentContentType; + } + + public final URI getFallbackAssignmentCallbackUrl() { + return this.fallbackAssignmentCallbackUrl; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getSid() { + return this.sid; + } + + public final Integer getTaskReservationTimeout() { + return this.taskReservationTimeout; + } + + public final String getWorkspaceSid() { + return this.workspaceSid; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -223,13 +235,48 @@ public boolean equals(final Object o) { Workflow other = (Workflow) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(assignmentCallbackUrl, other.assignmentCallbackUrl) && Objects.equals(configuration, other.configuration) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(documentContentType, other.documentContentType) && Objects.equals(fallbackAssignmentCallbackUrl, other.fallbackAssignmentCallbackUrl) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(sid, other.sid) && Objects.equals(taskReservationTimeout, other.taskReservationTimeout) && Objects.equals(workspaceSid, other.workspaceSid) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals( + assignmentCallbackUrl, + other.assignmentCallbackUrl + ) && + Objects.equals(configuration, other.configuration) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(documentContentType, other.documentContentType) && + Objects.equals( + fallbackAssignmentCallbackUrl, + other.fallbackAssignmentCallbackUrl + ) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(sid, other.sid) && + Objects.equals( + taskReservationTimeout, + other.taskReservationTimeout + ) && + Objects.equals(workspaceSid, other.workspaceSid) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, assignmentCallbackUrl, configuration, dateCreated, dateUpdated, documentContentType, fallbackAssignmentCallbackUrl, friendlyName, sid, taskReservationTimeout, workspaceSid, url, links); + return Objects.hash( + accountSid, + assignmentCallbackUrl, + configuration, + dateCreated, + dateUpdated, + documentContentType, + fallbackAssignmentCallbackUrl, + friendlyName, + sid, + taskReservationTimeout, + workspaceSid, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkflowCreator.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkflowCreator.java index d81912ff82..4a7e46f197 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkflowCreator.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkflowCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.taskrouter.v1.workspace; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -25,12 +26,10 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.net.URI; - - - import java.net.URI; -public class WorkflowCreator extends Creator{ +public class WorkflowCreator extends Creator { + private String pathWorkspaceSid; private String friendlyName; private String configuration; @@ -38,88 +37,136 @@ public class WorkflowCreator extends Creator{ private URI fallbackAssignmentCallbackUrl; private Integer taskReservationTimeout; - public WorkflowCreator(final String pathWorkspaceSid, final String friendlyName, final String configuration) { + public WorkflowCreator( + final String pathWorkspaceSid, + final String friendlyName, + final String configuration + ) { this.pathWorkspaceSid = pathWorkspaceSid; this.friendlyName = friendlyName; this.configuration = configuration; } - public WorkflowCreator setFriendlyName(final String friendlyName){ + public WorkflowCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public WorkflowCreator setConfiguration(final String configuration){ + + public WorkflowCreator setConfiguration(final String configuration) { this.configuration = configuration; return this; } - public WorkflowCreator setAssignmentCallbackUrl(final URI assignmentCallbackUrl){ + + public WorkflowCreator setAssignmentCallbackUrl( + final URI assignmentCallbackUrl + ) { this.assignmentCallbackUrl = assignmentCallbackUrl; return this; } - public WorkflowCreator setAssignmentCallbackUrl(final String assignmentCallbackUrl){ - return setAssignmentCallbackUrl(Promoter.uriFromString(assignmentCallbackUrl)); + public WorkflowCreator setAssignmentCallbackUrl( + final String assignmentCallbackUrl + ) { + return setAssignmentCallbackUrl( + Promoter.uriFromString(assignmentCallbackUrl) + ); } - public WorkflowCreator setFallbackAssignmentCallbackUrl(final URI fallbackAssignmentCallbackUrl){ + + public WorkflowCreator setFallbackAssignmentCallbackUrl( + final URI fallbackAssignmentCallbackUrl + ) { this.fallbackAssignmentCallbackUrl = fallbackAssignmentCallbackUrl; return this; } - public WorkflowCreator setFallbackAssignmentCallbackUrl(final String fallbackAssignmentCallbackUrl){ - return setFallbackAssignmentCallbackUrl(Promoter.uriFromString(fallbackAssignmentCallbackUrl)); + public WorkflowCreator setFallbackAssignmentCallbackUrl( + final String fallbackAssignmentCallbackUrl + ) { + return setFallbackAssignmentCallbackUrl( + Promoter.uriFromString(fallbackAssignmentCallbackUrl) + ); } - public WorkflowCreator setTaskReservationTimeout(final Integer taskReservationTimeout){ + + public WorkflowCreator setTaskReservationTimeout( + final Integer taskReservationTimeout + ) { this.taskReservationTimeout = taskReservationTimeout; return this; } @Override - public Workflow create(final TwilioRestClient client){ + public Workflow create(final TwilioRestClient client) { String path = "/v1/Workspaces/{WorkspaceSid}/Workflows"; - path = path.replace("{"+"WorkspaceSid"+"}", this.pathWorkspaceSid.toString()); - path = path.replace("{"+"FriendlyName"+"}", this.friendlyName.toString()); - path = path.replace("{"+"Configuration"+"}", this.configuration.toString()); + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = + path.replace( + "{" + "FriendlyName" + "}", + this.friendlyName.toString() + ); + path = + path.replace( + "{" + "Configuration" + "}", + this.configuration.toString() + ); Request request = new Request( HttpMethod.POST, Domains.TASKROUTER.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Workflow creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Workflow creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Workflow.fromJson(response.getStream(), client.getObjectMapper()); + return Workflow.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (configuration != null) { request.addPostParam("Configuration", configuration); - } if (assignmentCallbackUrl != null) { - request.addPostParam("AssignmentCallbackUrl", assignmentCallbackUrl.toString()); - + request.addPostParam( + "AssignmentCallbackUrl", + assignmentCallbackUrl.toString() + ); } if (fallbackAssignmentCallbackUrl != null) { - request.addPostParam("FallbackAssignmentCallbackUrl", fallbackAssignmentCallbackUrl.toString()); - + request.addPostParam( + "FallbackAssignmentCallbackUrl", + fallbackAssignmentCallbackUrl.toString() + ); } if (taskReservationTimeout != null) { - request.addPostParam("TaskReservationTimeout", taskReservationTimeout.toString()); - + request.addPostParam( + "TaskReservationTimeout", + taskReservationTimeout.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkflowDeleter.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkflowDeleter.java index defef41e9d..24098561d2 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkflowDeleter.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkflowDeleter.java @@ -24,24 +24,29 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class WorkflowDeleter extends Deleter { + private String pathWorkspaceSid; private String pathSid; - public WorkflowDeleter(final String pathWorkspaceSid, final String pathSid){ + public WorkflowDeleter( + final String pathWorkspaceSid, + final String pathSid + ) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Workspaces/{WorkspaceSid}/Workflows/{Sid}"; - path = path.replace("{"+"WorkspaceSid"+"}", this.pathWorkspaceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +56,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Workflow delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Workflow delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkflowFetcher.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkflowFetcher.java index 300282a477..494033c7ea 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkflowFetcher.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkflowFetcher.java @@ -24,25 +24,29 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class WorkflowFetcher extends Fetcher { + private String pathWorkspaceSid; private String pathSid; - public WorkflowFetcher(final String pathWorkspaceSid, final String pathSid){ + public WorkflowFetcher( + final String pathWorkspaceSid, + final String pathSid + ) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathSid = pathSid; } - @Override public Workflow fetch(final TwilioRestClient client) { String path = "/v1/Workspaces/{WorkspaceSid}/Workflows/{Sid}"; - path = path.replace("{"+"WorkspaceSid"+"}", this.pathWorkspaceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,15 +56,23 @@ public Workflow fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Workflow fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Workflow fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Workflow.fromJson(response.getStream(), client.getObjectMapper()); + return Workflow.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkflowReader.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkflowReader.java index 8f99fbea8d..fa42f10f61 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkflowReader.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkflowReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.taskrouter.v1.workspace; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,24 +25,23 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class WorkflowReader extends Reader { + private String pathWorkspaceSid; private String friendlyName; private Integer pageSize; - public WorkflowReader(final String pathWorkspaceSid){ + public WorkflowReader(final String pathWorkspaceSid) { this.pathWorkspaceSid = pathWorkspaceSid; } - public WorkflowReader setFriendlyName(final String friendlyName){ + public WorkflowReader setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public WorkflowReader setPageSize(final Integer pageSize){ + + public WorkflowReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -53,7 +53,11 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Workspaces/{WorkspaceSid}/Workflows"; - path = path.replace("{"+"WorkspaceSid"+"}", this.pathWorkspaceSid.toString()); + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -65,13 +69,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Workflow read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Workflow read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -87,7 +99,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reque } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.TASKROUTER.toString()) @@ -95,9 +110,11 @@ public Page previousPage(final Page page, final TwilioRestCl return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.TASKROUTER.toString()) @@ -106,25 +123,24 @@ public Page nextPage(final Page page, final TwilioRestClient } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (friendlyName != null) { - request.addQueryParam("FriendlyName", friendlyName); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkflowUpdater.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkflowUpdater.java index 83b91bb347..f1b23e340c 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkflowUpdater.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkflowUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.taskrouter.v1.workspace; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -24,12 +25,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.net.URI; +public class WorkflowUpdater extends Updater { - -public class WorkflowUpdater extends Updater{ private String pathWorkspaceSid; private String pathSid; private String friendlyName; @@ -39,94 +38,133 @@ public class WorkflowUpdater extends Updater{ private Integer taskReservationTimeout; private String reEvaluateTasks; - public WorkflowUpdater(final String pathWorkspaceSid, final String pathSid){ + public WorkflowUpdater( + final String pathWorkspaceSid, + final String pathSid + ) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathSid = pathSid; } - public WorkflowUpdater setFriendlyName(final String friendlyName){ + public WorkflowUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public WorkflowUpdater setAssignmentCallbackUrl(final URI assignmentCallbackUrl){ + + public WorkflowUpdater setAssignmentCallbackUrl( + final URI assignmentCallbackUrl + ) { this.assignmentCallbackUrl = assignmentCallbackUrl; return this; } - public WorkflowUpdater setAssignmentCallbackUrl(final String assignmentCallbackUrl){ - return setAssignmentCallbackUrl(Promoter.uriFromString(assignmentCallbackUrl)); + public WorkflowUpdater setAssignmentCallbackUrl( + final String assignmentCallbackUrl + ) { + return setAssignmentCallbackUrl( + Promoter.uriFromString(assignmentCallbackUrl) + ); } - public WorkflowUpdater setFallbackAssignmentCallbackUrl(final URI fallbackAssignmentCallbackUrl){ + + public WorkflowUpdater setFallbackAssignmentCallbackUrl( + final URI fallbackAssignmentCallbackUrl + ) { this.fallbackAssignmentCallbackUrl = fallbackAssignmentCallbackUrl; return this; } - public WorkflowUpdater setFallbackAssignmentCallbackUrl(final String fallbackAssignmentCallbackUrl){ - return setFallbackAssignmentCallbackUrl(Promoter.uriFromString(fallbackAssignmentCallbackUrl)); + public WorkflowUpdater setFallbackAssignmentCallbackUrl( + final String fallbackAssignmentCallbackUrl + ) { + return setFallbackAssignmentCallbackUrl( + Promoter.uriFromString(fallbackAssignmentCallbackUrl) + ); } - public WorkflowUpdater setConfiguration(final String configuration){ + + public WorkflowUpdater setConfiguration(final String configuration) { this.configuration = configuration; return this; } - public WorkflowUpdater setTaskReservationTimeout(final Integer taskReservationTimeout){ + + public WorkflowUpdater setTaskReservationTimeout( + final Integer taskReservationTimeout + ) { this.taskReservationTimeout = taskReservationTimeout; return this; } - public WorkflowUpdater setReEvaluateTasks(final String reEvaluateTasks){ + + public WorkflowUpdater setReEvaluateTasks(final String reEvaluateTasks) { this.reEvaluateTasks = reEvaluateTasks; return this; } @Override - public Workflow update(final TwilioRestClient client){ + public Workflow update(final TwilioRestClient client) { String path = "/v1/Workspaces/{WorkspaceSid}/Workflows/{Sid}"; - path = path.replace("{"+"WorkspaceSid"+"}", this.pathWorkspaceSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.TASKROUTER.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Workflow update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Workflow update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Workflow.fromJson(response.getStream(), client.getObjectMapper()); + return Workflow.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (assignmentCallbackUrl != null) { - request.addPostParam("AssignmentCallbackUrl", assignmentCallbackUrl.toString()); - + request.addPostParam( + "AssignmentCallbackUrl", + assignmentCallbackUrl.toString() + ); } if (fallbackAssignmentCallbackUrl != null) { - request.addPostParam("FallbackAssignmentCallbackUrl", fallbackAssignmentCallbackUrl.toString()); - + request.addPostParam( + "FallbackAssignmentCallbackUrl", + fallbackAssignmentCallbackUrl.toString() + ); } if (configuration != null) { request.addPostParam("Configuration", configuration); - } if (taskReservationTimeout != null) { - request.addPostParam("TaskReservationTimeout", taskReservationTimeout.toString()); - + request.addPostParam( + "TaskReservationTimeout", + taskReservationTimeout.toString() + ); } if (reEvaluateTasks != null) { request.addPostParam("ReEvaluateTasks", reEvaluateTasks); - } } } diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkspaceCumulativeStatistics.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkspaceCumulativeStatistics.java index d3750f2db9..3e20b64b6f 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkspaceCumulativeStatistics.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkspaceCumulativeStatistics.java @@ -23,42 +23,46 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class WorkspaceCumulativeStatistics extends Resource { + private static final long serialVersionUID = 84911824165722L; - public static WorkspaceCumulativeStatisticsFetcher fetcher(final String pathWorkspaceSid){ + public static WorkspaceCumulativeStatisticsFetcher fetcher( + final String pathWorkspaceSid + ) { return new WorkspaceCumulativeStatisticsFetcher(pathWorkspaceSid); } /** - * Converts a JSON String into a WorkspaceCumulativeStatistics object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return WorkspaceCumulativeStatistics object represented by the provided JSON - */ - public static WorkspaceCumulativeStatistics fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a WorkspaceCumulativeStatistics object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return WorkspaceCumulativeStatistics object represented by the provided JSON + */ + public static WorkspaceCumulativeStatistics fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, WorkspaceCumulativeStatistics.class); + return objectMapper.readValue( + json, + WorkspaceCumulativeStatistics.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -67,17 +71,23 @@ public static WorkspaceCumulativeStatistics fromJson(final String json, final Ob } /** - * Converts a JSON InputStream into a WorkspaceCumulativeStatistics object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return WorkspaceCumulativeStatistics object represented by the provided JSON - */ - public static WorkspaceCumulativeStatistics fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a WorkspaceCumulativeStatistics object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return WorkspaceCumulativeStatistics object represented by the provided JSON + */ + public static WorkspaceCumulativeStatistics fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, WorkspaceCumulativeStatistics.class); + return objectMapper.readValue( + json, + WorkspaceCumulativeStatistics.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -109,68 +119,47 @@ public static WorkspaceCumulativeStatistics fromJson(final InputStream json, fin @JsonCreator private WorkspaceCumulativeStatistics( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("avg_task_acceptance_time") - final Integer avgTaskAcceptanceTime, - - @JsonProperty("start_time") - final String startTime, - - @JsonProperty("end_time") - final String endTime, - - @JsonProperty("reservations_created") - final Integer reservationsCreated, - - @JsonProperty("reservations_accepted") - final Integer reservationsAccepted, - - @JsonProperty("reservations_rejected") - final Integer reservationsRejected, - - @JsonProperty("reservations_timed_out") - final Integer reservationsTimedOut, - - @JsonProperty("reservations_canceled") - final Integer reservationsCanceled, - - @JsonProperty("reservations_rescinded") - final Integer reservationsRescinded, - - @JsonProperty("split_by_wait_time") - final Map splitByWaitTime, - - @JsonProperty("wait_duration_until_accepted") - final Map waitDurationUntilAccepted, - - @JsonProperty("wait_duration_until_canceled") - final Map waitDurationUntilCanceled, - - @JsonProperty("tasks_canceled") - final Integer tasksCanceled, - - @JsonProperty("tasks_completed") - final Integer tasksCompleted, - - @JsonProperty("tasks_created") - final Integer tasksCreated, - - @JsonProperty("tasks_deleted") - final Integer tasksDeleted, - - @JsonProperty("tasks_moved") - final Integer tasksMoved, - - @JsonProperty("tasks_timed_out_in_workflow") - final Integer tasksTimedOutInWorkflow, - - @JsonProperty("workspace_sid") - final String workspaceSid, - - @JsonProperty("url") - final URI url + @JsonProperty("account_sid") final String accountSid, + @JsonProperty( + "avg_task_acceptance_time" + ) final Integer avgTaskAcceptanceTime, + @JsonProperty("start_time") final String startTime, + @JsonProperty("end_time") final String endTime, + @JsonProperty("reservations_created") final Integer reservationsCreated, + @JsonProperty( + "reservations_accepted" + ) final Integer reservationsAccepted, + @JsonProperty( + "reservations_rejected" + ) final Integer reservationsRejected, + @JsonProperty( + "reservations_timed_out" + ) final Integer reservationsTimedOut, + @JsonProperty( + "reservations_canceled" + ) final Integer reservationsCanceled, + @JsonProperty( + "reservations_rescinded" + ) final Integer reservationsRescinded, + @JsonProperty( + "split_by_wait_time" + ) final Map splitByWaitTime, + @JsonProperty( + "wait_duration_until_accepted" + ) final Map waitDurationUntilAccepted, + @JsonProperty( + "wait_duration_until_canceled" + ) final Map waitDurationUntilCanceled, + @JsonProperty("tasks_canceled") final Integer tasksCanceled, + @JsonProperty("tasks_completed") final Integer tasksCompleted, + @JsonProperty("tasks_created") final Integer tasksCreated, + @JsonProperty("tasks_deleted") final Integer tasksDeleted, + @JsonProperty("tasks_moved") final Integer tasksMoved, + @JsonProperty( + "tasks_timed_out_in_workflow" + ) final Integer tasksTimedOutInWorkflow, + @JsonProperty("workspace_sid") final String workspaceSid, + @JsonProperty("url") final URI url ) { this.accountSid = accountSid; this.avgTaskAcceptanceTime = avgTaskAcceptanceTime; @@ -195,73 +184,93 @@ private WorkspaceCumulativeStatistics( this.url = url; } - public final String getAccountSid() { - return this.accountSid; - } - public final Integer getAvgTaskAcceptanceTime() { - return this.avgTaskAcceptanceTime; - } - public final ZonedDateTime getStartTime() { - return this.startTime; - } - public final ZonedDateTime getEndTime() { - return this.endTime; - } - public final Integer getReservationsCreated() { - return this.reservationsCreated; - } - public final Integer getReservationsAccepted() { - return this.reservationsAccepted; - } - public final Integer getReservationsRejected() { - return this.reservationsRejected; - } - public final Integer getReservationsTimedOut() { - return this.reservationsTimedOut; - } - public final Integer getReservationsCanceled() { - return this.reservationsCanceled; - } - public final Integer getReservationsRescinded() { - return this.reservationsRescinded; - } - public final Map getSplitByWaitTime() { - return this.splitByWaitTime; - } - public final Map getWaitDurationUntilAccepted() { - return this.waitDurationUntilAccepted; - } - public final Map getWaitDurationUntilCanceled() { - return this.waitDurationUntilCanceled; - } - public final Integer getTasksCanceled() { - return this.tasksCanceled; - } - public final Integer getTasksCompleted() { - return this.tasksCompleted; - } - public final Integer getTasksCreated() { - return this.tasksCreated; - } - public final Integer getTasksDeleted() { - return this.tasksDeleted; - } - public final Integer getTasksMoved() { - return this.tasksMoved; - } - public final Integer getTasksTimedOutInWorkflow() { - return this.tasksTimedOutInWorkflow; - } - public final String getWorkspaceSid() { - return this.workspaceSid; - } - public final URI getUrl() { - return this.url; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final Integer getAvgTaskAcceptanceTime() { + return this.avgTaskAcceptanceTime; + } + + public final ZonedDateTime getStartTime() { + return this.startTime; + } + + public final ZonedDateTime getEndTime() { + return this.endTime; + } + + public final Integer getReservationsCreated() { + return this.reservationsCreated; + } + + public final Integer getReservationsAccepted() { + return this.reservationsAccepted; + } + + public final Integer getReservationsRejected() { + return this.reservationsRejected; + } + + public final Integer getReservationsTimedOut() { + return this.reservationsTimedOut; + } + + public final Integer getReservationsCanceled() { + return this.reservationsCanceled; + } + + public final Integer getReservationsRescinded() { + return this.reservationsRescinded; + } + + public final Map getSplitByWaitTime() { + return this.splitByWaitTime; + } + + public final Map getWaitDurationUntilAccepted() { + return this.waitDurationUntilAccepted; + } + + public final Map getWaitDurationUntilCanceled() { + return this.waitDurationUntilCanceled; + } + + public final Integer getTasksCanceled() { + return this.tasksCanceled; + } + + public final Integer getTasksCompleted() { + return this.tasksCompleted; + } + + public final Integer getTasksCreated() { + return this.tasksCreated; + } + + public final Integer getTasksDeleted() { + return this.tasksDeleted; + } + + public final Integer getTasksMoved() { + return this.tasksMoved; + } + + public final Integer getTasksTimedOutInWorkflow() { + return this.tasksTimedOutInWorkflow; + } + + public final String getWorkspaceSid() { + return this.workspaceSid; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -271,13 +280,70 @@ public boolean equals(final Object o) { WorkspaceCumulativeStatistics other = (WorkspaceCumulativeStatistics) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(avgTaskAcceptanceTime, other.avgTaskAcceptanceTime) && Objects.equals(startTime, other.startTime) && Objects.equals(endTime, other.endTime) && Objects.equals(reservationsCreated, other.reservationsCreated) && Objects.equals(reservationsAccepted, other.reservationsAccepted) && Objects.equals(reservationsRejected, other.reservationsRejected) && Objects.equals(reservationsTimedOut, other.reservationsTimedOut) && Objects.equals(reservationsCanceled, other.reservationsCanceled) && Objects.equals(reservationsRescinded, other.reservationsRescinded) && Objects.equals(splitByWaitTime, other.splitByWaitTime) && Objects.equals(waitDurationUntilAccepted, other.waitDurationUntilAccepted) && Objects.equals(waitDurationUntilCanceled, other.waitDurationUntilCanceled) && Objects.equals(tasksCanceled, other.tasksCanceled) && Objects.equals(tasksCompleted, other.tasksCompleted) && Objects.equals(tasksCreated, other.tasksCreated) && Objects.equals(tasksDeleted, other.tasksDeleted) && Objects.equals(tasksMoved, other.tasksMoved) && Objects.equals(tasksTimedOutInWorkflow, other.tasksTimedOutInWorkflow) && Objects.equals(workspaceSid, other.workspaceSid) && Objects.equals(url, other.url) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals( + avgTaskAcceptanceTime, + other.avgTaskAcceptanceTime + ) && + Objects.equals(startTime, other.startTime) && + Objects.equals(endTime, other.endTime) && + Objects.equals(reservationsCreated, other.reservationsCreated) && + Objects.equals(reservationsAccepted, other.reservationsAccepted) && + Objects.equals(reservationsRejected, other.reservationsRejected) && + Objects.equals(reservationsTimedOut, other.reservationsTimedOut) && + Objects.equals(reservationsCanceled, other.reservationsCanceled) && + Objects.equals( + reservationsRescinded, + other.reservationsRescinded + ) && + Objects.equals(splitByWaitTime, other.splitByWaitTime) && + Objects.equals( + waitDurationUntilAccepted, + other.waitDurationUntilAccepted + ) && + Objects.equals( + waitDurationUntilCanceled, + other.waitDurationUntilCanceled + ) && + Objects.equals(tasksCanceled, other.tasksCanceled) && + Objects.equals(tasksCompleted, other.tasksCompleted) && + Objects.equals(tasksCreated, other.tasksCreated) && + Objects.equals(tasksDeleted, other.tasksDeleted) && + Objects.equals(tasksMoved, other.tasksMoved) && + Objects.equals( + tasksTimedOutInWorkflow, + other.tasksTimedOutInWorkflow + ) && + Objects.equals(workspaceSid, other.workspaceSid) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, avgTaskAcceptanceTime, startTime, endTime, reservationsCreated, reservationsAccepted, reservationsRejected, reservationsTimedOut, reservationsCanceled, reservationsRescinded, splitByWaitTime, waitDurationUntilAccepted, waitDurationUntilCanceled, tasksCanceled, tasksCompleted, tasksCreated, tasksDeleted, tasksMoved, tasksTimedOutInWorkflow, workspaceSid, url); + return Objects.hash( + accountSid, + avgTaskAcceptanceTime, + startTime, + endTime, + reservationsCreated, + reservationsAccepted, + reservationsRejected, + reservationsTimedOut, + reservationsCanceled, + reservationsRescinded, + splitByWaitTime, + waitDurationUntilAccepted, + waitDurationUntilCanceled, + tasksCanceled, + tasksCompleted, + tasksCreated, + tasksDeleted, + tasksMoved, + tasksTimedOutInWorkflow, + workspaceSid, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkspaceCumulativeStatisticsFetcher.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkspaceCumulativeStatisticsFetcher.java index 9814277cc6..69f9e91a31 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkspaceCumulativeStatisticsFetcher.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkspaceCumulativeStatisticsFetcher.java @@ -23,12 +23,11 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.time.ZonedDateTime; +public class WorkspaceCumulativeStatisticsFetcher + extends Fetcher { - -public class WorkspaceCumulativeStatisticsFetcher extends Fetcher { private String pathWorkspaceSid; private ZonedDateTime endDate; private Integer minutes; @@ -36,27 +35,41 @@ public class WorkspaceCumulativeStatisticsFetcher extends Fetcher> activityStatistics, - - @JsonProperty("longest_task_waiting_age") - final Integer longestTaskWaitingAge, - - @JsonProperty("longest_task_waiting_sid") - final String longestTaskWaitingSid, - - @JsonProperty("tasks_by_priority") - final Map tasksByPriority, - - @JsonProperty("tasks_by_status") - final Map tasksByStatus, - - @JsonProperty("total_tasks") - final Integer totalTasks, - - @JsonProperty("total_workers") - final Integer totalWorkers, - - @JsonProperty("workspace_sid") - final String workspaceSid, - - @JsonProperty("url") - final URI url + @JsonProperty("account_sid") final String accountSid, + @JsonProperty( + "activity_statistics" + ) final List> activityStatistics, + @JsonProperty( + "longest_task_waiting_age" + ) final Integer longestTaskWaitingAge, + @JsonProperty( + "longest_task_waiting_sid" + ) final String longestTaskWaitingSid, + @JsonProperty( + "tasks_by_priority" + ) final Map tasksByPriority, + @JsonProperty( + "tasks_by_status" + ) final Map tasksByStatus, + @JsonProperty("total_tasks") final Integer totalTasks, + @JsonProperty("total_workers") final Integer totalWorkers, + @JsonProperty("workspace_sid") final String workspaceSid, + @JsonProperty("url") final URI url ) { this.accountSid = accountSid; this.activityStatistics = activityStatistics; @@ -139,40 +140,49 @@ private WorkspaceRealTimeStatistics( this.url = url; } - public final String getAccountSid() { - return this.accountSid; - } - public final List> getActivityStatistics() { - return this.activityStatistics; - } - public final Integer getLongestTaskWaitingAge() { - return this.longestTaskWaitingAge; - } - public final String getLongestTaskWaitingSid() { - return this.longestTaskWaitingSid; - } - public final Map getTasksByPriority() { - return this.tasksByPriority; - } - public final Map getTasksByStatus() { - return this.tasksByStatus; - } - public final Integer getTotalTasks() { - return this.totalTasks; - } - public final Integer getTotalWorkers() { - return this.totalWorkers; - } - public final String getWorkspaceSid() { - return this.workspaceSid; - } - public final URI getUrl() { - return this.url; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final List> getActivityStatistics() { + return this.activityStatistics; + } + + public final Integer getLongestTaskWaitingAge() { + return this.longestTaskWaitingAge; + } + + public final String getLongestTaskWaitingSid() { + return this.longestTaskWaitingSid; + } + + public final Map getTasksByPriority() { + return this.tasksByPriority; + } + + public final Map getTasksByStatus() { + return this.tasksByStatus; + } + + public final Integer getTotalTasks() { + return this.totalTasks; + } + + public final Integer getTotalWorkers() { + return this.totalWorkers; + } + + public final String getWorkspaceSid() { + return this.workspaceSid; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -182,13 +192,39 @@ public boolean equals(final Object o) { WorkspaceRealTimeStatistics other = (WorkspaceRealTimeStatistics) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(activityStatistics, other.activityStatistics) && Objects.equals(longestTaskWaitingAge, other.longestTaskWaitingAge) && Objects.equals(longestTaskWaitingSid, other.longestTaskWaitingSid) && Objects.equals(tasksByPriority, other.tasksByPriority) && Objects.equals(tasksByStatus, other.tasksByStatus) && Objects.equals(totalTasks, other.totalTasks) && Objects.equals(totalWorkers, other.totalWorkers) && Objects.equals(workspaceSid, other.workspaceSid) && Objects.equals(url, other.url) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(activityStatistics, other.activityStatistics) && + Objects.equals( + longestTaskWaitingAge, + other.longestTaskWaitingAge + ) && + Objects.equals( + longestTaskWaitingSid, + other.longestTaskWaitingSid + ) && + Objects.equals(tasksByPriority, other.tasksByPriority) && + Objects.equals(tasksByStatus, other.tasksByStatus) && + Objects.equals(totalTasks, other.totalTasks) && + Objects.equals(totalWorkers, other.totalWorkers) && + Objects.equals(workspaceSid, other.workspaceSid) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, activityStatistics, longestTaskWaitingAge, longestTaskWaitingSid, tasksByPriority, tasksByStatus, totalTasks, totalWorkers, workspaceSid, url); + return Objects.hash( + accountSid, + activityStatistics, + longestTaskWaitingAge, + longestTaskWaitingSid, + tasksByPriority, + tasksByStatus, + totalTasks, + totalWorkers, + workspaceSid, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkspaceRealTimeStatisticsFetcher.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkspaceRealTimeStatisticsFetcher.java index 2bdb2732e6..a43848170c 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkspaceRealTimeStatisticsFetcher.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkspaceRealTimeStatisticsFetcher.java @@ -24,18 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class WorkspaceRealTimeStatisticsFetcher + extends Fetcher { - - -public class WorkspaceRealTimeStatisticsFetcher extends Fetcher { private String pathWorkspaceSid; private String taskChannel; - public WorkspaceRealTimeStatisticsFetcher(final String pathWorkspaceSid){ + public WorkspaceRealTimeStatisticsFetcher(final String pathWorkspaceSid) { this.pathWorkspaceSid = pathWorkspaceSid; } - public WorkspaceRealTimeStatisticsFetcher setTaskChannel(final String taskChannel){ + public WorkspaceRealTimeStatisticsFetcher setTaskChannel( + final String taskChannel + ) { this.taskChannel = taskChannel; return this; } @@ -44,7 +45,11 @@ public WorkspaceRealTimeStatisticsFetcher setTaskChannel(final String taskChanne public WorkspaceRealTimeStatistics fetch(final TwilioRestClient client) { String path = "/v1/Workspaces/{WorkspaceSid}/RealTimeStatistics"; - path = path.replace("{"+"WorkspaceSid"+"}", this.pathWorkspaceSid.toString()); + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -55,20 +60,28 @@ public WorkspaceRealTimeStatistics fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("WorkspaceRealTimeStatistics fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "WorkspaceRealTimeStatistics fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return WorkspaceRealTimeStatistics.fromJson(response.getStream(), client.getObjectMapper()); + return WorkspaceRealTimeStatistics.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addQueryParams(final Request request) { if (taskChannel != null) { - request.addQueryParam("TaskChannel", taskChannel); } } diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkspaceStatistics.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkspaceStatistics.java index 5650c58506..f6fd4dabee 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkspaceStatistics.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkspaceStatistics.java @@ -22,38 +22,39 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class WorkspaceStatistics extends Resource { + private static final long serialVersionUID = 274987650256203L; - public static WorkspaceStatisticsFetcher fetcher(final String pathWorkspaceSid){ + public static WorkspaceStatisticsFetcher fetcher( + final String pathWorkspaceSid + ) { return new WorkspaceStatisticsFetcher(pathWorkspaceSid); } /** - * Converts a JSON String into a WorkspaceStatistics object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return WorkspaceStatistics object represented by the provided JSON - */ - public static WorkspaceStatistics fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a WorkspaceStatistics object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return WorkspaceStatistics object represented by the provided JSON + */ + public static WorkspaceStatistics fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, WorkspaceStatistics.class); @@ -65,14 +66,17 @@ public static WorkspaceStatistics fromJson(final String json, final ObjectMapper } /** - * Converts a JSON InputStream into a WorkspaceStatistics object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return WorkspaceStatistics object represented by the provided JSON - */ - public static WorkspaceStatistics fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a WorkspaceStatistics object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return WorkspaceStatistics object represented by the provided JSON + */ + public static WorkspaceStatistics fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, WorkspaceStatistics.class); @@ -91,20 +95,11 @@ public static WorkspaceStatistics fromJson(final InputStream json, final ObjectM @JsonCreator private WorkspaceStatistics( - @JsonProperty("realtime") - final Map realtime, - - @JsonProperty("cumulative") - final Map cumulative, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("workspace_sid") - final String workspaceSid, - - @JsonProperty("url") - final URI url + @JsonProperty("realtime") final Map realtime, + @JsonProperty("cumulative") final Map cumulative, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("workspace_sid") final String workspaceSid, + @JsonProperty("url") final URI url ) { this.realtime = realtime; this.cumulative = cumulative; @@ -113,25 +108,29 @@ private WorkspaceStatistics( this.url = url; } - public final Map getRealtime() { - return this.realtime; - } - public final Map getCumulative() { - return this.cumulative; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getWorkspaceSid() { - return this.workspaceSid; - } - public final URI getUrl() { - return this.url; - } + public final Map getRealtime() { + return this.realtime; + } + + public final Map getCumulative() { + return this.cumulative; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getWorkspaceSid() { + return this.workspaceSid; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -141,13 +140,23 @@ public boolean equals(final Object o) { WorkspaceStatistics other = (WorkspaceStatistics) o; - return Objects.equals(realtime, other.realtime) && Objects.equals(cumulative, other.cumulative) && Objects.equals(accountSid, other.accountSid) && Objects.equals(workspaceSid, other.workspaceSid) && Objects.equals(url, other.url) ; + return ( + Objects.equals(realtime, other.realtime) && + Objects.equals(cumulative, other.cumulative) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(workspaceSid, other.workspaceSid) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(realtime, cumulative, accountSid, workspaceSid, url); + return Objects.hash( + realtime, + cumulative, + accountSid, + workspaceSid, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkspaceStatisticsFetcher.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkspaceStatisticsFetcher.java index 9e0ff152cf..675bec7cce 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkspaceStatisticsFetcher.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkspaceStatisticsFetcher.java @@ -23,12 +23,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.time.ZonedDateTime; - - public class WorkspaceStatisticsFetcher extends Fetcher { + private String pathWorkspaceSid; private Integer minutes; private ZonedDateTime startDate; @@ -36,27 +34,35 @@ public class WorkspaceStatisticsFetcher extends Fetcher { private String taskChannel; private String splitByWaitTime; - public WorkspaceStatisticsFetcher(final String pathWorkspaceSid){ + public WorkspaceStatisticsFetcher(final String pathWorkspaceSid) { this.pathWorkspaceSid = pathWorkspaceSid; } - public WorkspaceStatisticsFetcher setMinutes(final Integer minutes){ + public WorkspaceStatisticsFetcher setMinutes(final Integer minutes) { this.minutes = minutes; return this; } - public WorkspaceStatisticsFetcher setStartDate(final ZonedDateTime startDate){ + + public WorkspaceStatisticsFetcher setStartDate( + final ZonedDateTime startDate + ) { this.startDate = startDate; return this; } - public WorkspaceStatisticsFetcher setEndDate(final ZonedDateTime endDate){ + + public WorkspaceStatisticsFetcher setEndDate(final ZonedDateTime endDate) { this.endDate = endDate; return this; } - public WorkspaceStatisticsFetcher setTaskChannel(final String taskChannel){ + + public WorkspaceStatisticsFetcher setTaskChannel(final String taskChannel) { this.taskChannel = taskChannel; return this; } - public WorkspaceStatisticsFetcher setSplitByWaitTime(final String splitByWaitTime){ + + public WorkspaceStatisticsFetcher setSplitByWaitTime( + final String splitByWaitTime + ) { this.splitByWaitTime = splitByWaitTime; return this; } @@ -65,7 +71,11 @@ public WorkspaceStatisticsFetcher setSplitByWaitTime(final String splitByWaitTim public WorkspaceStatistics fetch(final TwilioRestClient client) { String path = "/v1/Workspaces/{WorkspaceSid}/Statistics"; - path = path.replace("{"+"WorkspaceSid"+"}", this.pathWorkspaceSid.toString()); + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -76,24 +86,35 @@ public WorkspaceStatistics fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("WorkspaceStatistics fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "WorkspaceStatistics fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return WorkspaceStatistics.fromJson(response.getStream(), client.getObjectMapper()); + return WorkspaceStatistics.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addQueryParams(final Request request) { if (minutes != null) { - request.addQueryParam("Minutes", minutes.toString()); } if (startDate != null) { - request.addQueryParam("StartDate", startDate.toInstant().toString()); + request.addQueryParam( + "StartDate", + startDate.toInstant().toString() + ); } if (endDate != null) { @@ -101,11 +122,9 @@ private void addQueryParams(final Request request) { } if (taskChannel != null) { - request.addQueryParam("TaskChannel", taskChannel); } if (splitByWaitTime != null) { - request.addQueryParam("SplitByWaitTime", splitByWaitTime); } } diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/task/Reservation.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/task/Reservation.java index 116647cf53..0dcfc55962 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/task/Reservation.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/task/Reservation.java @@ -24,47 +24,57 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Reservation extends Resource { + private static final long serialVersionUID = 88353198782173L; - public static ReservationFetcher fetcher(final String pathWorkspaceSid, final String pathTaskSid, final String pathSid){ + public static ReservationFetcher fetcher( + final String pathWorkspaceSid, + final String pathTaskSid, + final String pathSid + ) { return new ReservationFetcher(pathWorkspaceSid, pathTaskSid, pathSid); } - public static ReservationReader reader(final String pathWorkspaceSid, final String pathTaskSid){ + public static ReservationReader reader( + final String pathWorkspaceSid, + final String pathTaskSid + ) { return new ReservationReader(pathWorkspaceSid, pathTaskSid); } - public static ReservationUpdater updater(final String pathWorkspaceSid, final String pathTaskSid, final String pathSid){ + public static ReservationUpdater updater( + final String pathWorkspaceSid, + final String pathTaskSid, + final String pathSid + ) { return new ReservationUpdater(pathWorkspaceSid, pathTaskSid, pathSid); } /** - * Converts a JSON String into a Reservation object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Reservation object represented by the provided JSON - */ - public static Reservation fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Reservation object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Reservation object represented by the provided JSON + */ + public static Reservation fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Reservation.class); @@ -76,14 +86,17 @@ public static Reservation fromJson(final String json, final ObjectMapper objectM } /** - * Converts a JSON InputStream into a Reservation object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Reservation object represented by the provided JSON - */ - public static Reservation fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Reservation object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Reservation object represented by the provided JSON + */ + public static Reservation fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Reservation.class); @@ -93,6 +106,7 @@ public static Reservation fromJson(final InputStream json, final ObjectMapper ob throw new ApiConnectionException(e.getMessage(), e); } } + public enum CallStatus { INITIATED("initiated"), RINGING("ringing"), @@ -114,6 +128,7 @@ public static CallStatus forValue(final String value) { return Promoter.enumFromString(value, CallStatus.values()); } } + public enum ConferenceEvent { START("start"), END("end"), @@ -138,6 +153,7 @@ public static ConferenceEvent forValue(final String value) { return Promoter.enumFromString(value, ConferenceEvent.values()); } } + public enum Status { PENDING("pending"), ACCEPTED("accepted"), @@ -163,6 +179,7 @@ public static Status forValue(final String value) { return Promoter.enumFromString(value, Status.values()); } } + public enum SupervisorMode { MONITOR("monitor"), WHISPER("whisper"), @@ -198,38 +215,19 @@ public static SupervisorMode forValue(final String value) { @JsonCreator private Reservation( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("reservation_status") - final Reservation.Status reservationStatus, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("task_sid") - final String taskSid, - - @JsonProperty("worker_name") - final String workerName, - - @JsonProperty("worker_sid") - final String workerSid, - - @JsonProperty("workspace_sid") - final String workspaceSid, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty( + "reservation_status" + ) final Reservation.Status reservationStatus, + @JsonProperty("sid") final String sid, + @JsonProperty("task_sid") final String taskSid, + @JsonProperty("worker_name") final String workerName, + @JsonProperty("worker_sid") final String workerSid, + @JsonProperty("workspace_sid") final String workspaceSid, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.accountSid = accountSid; this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); @@ -244,43 +242,53 @@ private Reservation( this.links = links; } - public final String getAccountSid() { - return this.accountSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final Reservation.Status getReservationStatus() { - return this.reservationStatus; - } - public final String getSid() { - return this.sid; - } - public final String getTaskSid() { - return this.taskSid; - } - public final String getWorkerName() { - return this.workerName; - } - public final String getWorkerSid() { - return this.workerSid; - } - public final String getWorkspaceSid() { - return this.workspaceSid; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final Reservation.Status getReservationStatus() { + return this.reservationStatus; + } + + public final String getSid() { + return this.sid; + } + + public final String getTaskSid() { + return this.taskSid; + } + + public final String getWorkerName() { + return this.workerName; + } + + public final String getWorkerSid() { + return this.workerSid; + } + + public final String getWorkspaceSid() { + return this.workspaceSid; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -290,13 +298,35 @@ public boolean equals(final Object o) { Reservation other = (Reservation) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(reservationStatus, other.reservationStatus) && Objects.equals(sid, other.sid) && Objects.equals(taskSid, other.taskSid) && Objects.equals(workerName, other.workerName) && Objects.equals(workerSid, other.workerSid) && Objects.equals(workspaceSid, other.workspaceSid) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(reservationStatus, other.reservationStatus) && + Objects.equals(sid, other.sid) && + Objects.equals(taskSid, other.taskSid) && + Objects.equals(workerName, other.workerName) && + Objects.equals(workerSid, other.workerSid) && + Objects.equals(workspaceSid, other.workspaceSid) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, dateCreated, dateUpdated, reservationStatus, sid, taskSid, workerName, workerSid, workspaceSid, url, links); + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + reservationStatus, + sid, + taskSid, + workerName, + workerSid, + workspaceSid, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/task/ReservationFetcher.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/task/ReservationFetcher.java index 4e1e9cb9cc..c3b266aa6b 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/task/ReservationFetcher.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/task/ReservationFetcher.java @@ -24,28 +24,34 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class ReservationFetcher extends Fetcher { + private String pathWorkspaceSid; private String pathTaskSid; private String pathSid; - public ReservationFetcher(final String pathWorkspaceSid, final String pathTaskSid, final String pathSid){ + public ReservationFetcher( + final String pathWorkspaceSid, + final String pathTaskSid, + final String pathSid + ) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathTaskSid = pathTaskSid; this.pathSid = pathSid; } - @Override public Reservation fetch(final TwilioRestClient client) { - String path = "/v1/Workspaces/{WorkspaceSid}/Tasks/{TaskSid}/Reservations/{Sid}"; + String path = + "/v1/Workspaces/{WorkspaceSid}/Tasks/{TaskSid}/Reservations/{Sid}"; - path = path.replace("{"+"WorkspaceSid"+"}", this.pathWorkspaceSid.toString()); - path = path.replace("{"+"TaskSid"+"}", this.pathTaskSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = path.replace("{" + "TaskSid" + "}", this.pathTaskSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -55,15 +61,23 @@ public Reservation fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Reservation fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Reservation fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Reservation.fromJson(response.getStream(), client.getObjectMapper()); + return Reservation.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/task/ReservationReader.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/task/ReservationReader.java index 519ead6b93..1bcdaeb2e1 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/task/ReservationReader.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/task/ReservationReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.taskrouter.v1.workspace.task; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,31 +25,36 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class ReservationReader extends Reader { + private String pathWorkspaceSid; private String pathTaskSid; private Reservation.Status reservationStatus; private String workerSid; private Integer pageSize; - public ReservationReader(final String pathWorkspaceSid, final String pathTaskSid){ + public ReservationReader( + final String pathWorkspaceSid, + final String pathTaskSid + ) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathTaskSid = pathTaskSid; } - public ReservationReader setReservationStatus(final Reservation.Status reservationStatus){ + public ReservationReader setReservationStatus( + final Reservation.Status reservationStatus + ) { this.reservationStatus = reservationStatus; return this; } - public ReservationReader setWorkerSid(final String workerSid){ + + public ReservationReader setWorkerSid(final String workerSid) { this.workerSid = workerSid; return this; } - public ReservationReader setPageSize(final Integer pageSize){ + + public ReservationReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -59,9 +65,14 @@ public ResourceSet read(final TwilioRestClient client) { } public Page firstPage(final TwilioRestClient client) { - String path = "/v1/Workspaces/{WorkspaceSid}/Tasks/{TaskSid}/Reservations"; - path = path.replace("{"+"WorkspaceSid"+"}", this.pathWorkspaceSid.toString()); - path = path.replace("{"+"TaskSid"+"}", this.pathTaskSid.toString()); + String path = + "/v1/Workspaces/{WorkspaceSid}/Tasks/{TaskSid}/Reservations"; + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = path.replace("{" + "TaskSid" + "}", this.pathTaskSid.toString()); Request request = new Request( HttpMethod.GET, @@ -73,13 +84,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Reservation read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Reservation read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -95,7 +114,10 @@ private Page pageForRequest(final TwilioRestClient client, final Re } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.TASKROUTER.toString()) @@ -103,9 +125,11 @@ public Page previousPage(final Page page, final Twilio return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.TASKROUTER.toString()) @@ -114,29 +138,30 @@ public Page nextPage(final Page page, final TwilioRest } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (reservationStatus != null) { - - request.addQueryParam("ReservationStatus", reservationStatus.toString()); + request.addQueryParam( + "ReservationStatus", + reservationStatus.toString() + ); } if (workerSid != null) { - request.addQueryParam("WorkerSid", workerSid); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/task/ReservationUpdater.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/task/ReservationUpdater.java index de5297917e..9496367e64 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/task/ReservationUpdater.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/task/ReservationUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.taskrouter.v1.workspace.task; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -24,13 +25,11 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.net.URI; - import java.util.List; +public class ReservationUpdater extends Updater { -public class ReservationUpdater extends Updater{ private String pathWorkspaceSid; private String pathTaskSid; private String pathSid; @@ -89,526 +88,676 @@ public class ReservationUpdater extends Updater{ private Boolean endConferenceOnCustomerExit; private Boolean beepOnCustomerEntrance; - public ReservationUpdater(final String pathWorkspaceSid, final String pathTaskSid, final String pathSid){ + public ReservationUpdater( + final String pathWorkspaceSid, + final String pathTaskSid, + final String pathSid + ) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathTaskSid = pathTaskSid; this.pathSid = pathSid; } - public ReservationUpdater setIfMatch(final String ifMatch){ + public ReservationUpdater setIfMatch(final String ifMatch) { this.ifMatch = ifMatch; return this; } - public ReservationUpdater setReservationStatus(final Reservation.Status reservationStatus){ + + public ReservationUpdater setReservationStatus( + final Reservation.Status reservationStatus + ) { this.reservationStatus = reservationStatus; return this; } - public ReservationUpdater setWorkerActivitySid(final String workerActivitySid){ + + public ReservationUpdater setWorkerActivitySid( + final String workerActivitySid + ) { this.workerActivitySid = workerActivitySid; return this; } - public ReservationUpdater setInstruction(final String instruction){ + + public ReservationUpdater setInstruction(final String instruction) { this.instruction = instruction; return this; } - public ReservationUpdater setDequeuePostWorkActivitySid(final String dequeuePostWorkActivitySid){ + + public ReservationUpdater setDequeuePostWorkActivitySid( + final String dequeuePostWorkActivitySid + ) { this.dequeuePostWorkActivitySid = dequeuePostWorkActivitySid; return this; } - public ReservationUpdater setDequeueFrom(final String dequeueFrom){ + + public ReservationUpdater setDequeueFrom(final String dequeueFrom) { this.dequeueFrom = dequeueFrom; return this; } - public ReservationUpdater setDequeueRecord(final String dequeueRecord){ + + public ReservationUpdater setDequeueRecord(final String dequeueRecord) { this.dequeueRecord = dequeueRecord; return this; } - public ReservationUpdater setDequeueTimeout(final Integer dequeueTimeout){ + + public ReservationUpdater setDequeueTimeout(final Integer dequeueTimeout) { this.dequeueTimeout = dequeueTimeout; return this; } - public ReservationUpdater setDequeueTo(final String dequeueTo){ + + public ReservationUpdater setDequeueTo(final String dequeueTo) { this.dequeueTo = dequeueTo; return this; } - public ReservationUpdater setDequeueStatusCallbackUrl(final URI dequeueStatusCallbackUrl){ + + public ReservationUpdater setDequeueStatusCallbackUrl( + final URI dequeueStatusCallbackUrl + ) { this.dequeueStatusCallbackUrl = dequeueStatusCallbackUrl; return this; } - public ReservationUpdater setDequeueStatusCallbackUrl(final String dequeueStatusCallbackUrl){ - return setDequeueStatusCallbackUrl(Promoter.uriFromString(dequeueStatusCallbackUrl)); + public ReservationUpdater setDequeueStatusCallbackUrl( + final String dequeueStatusCallbackUrl + ) { + return setDequeueStatusCallbackUrl( + Promoter.uriFromString(dequeueStatusCallbackUrl) + ); } - public ReservationUpdater setCallFrom(final String callFrom){ + + public ReservationUpdater setCallFrom(final String callFrom) { this.callFrom = callFrom; return this; } - public ReservationUpdater setCallRecord(final String callRecord){ + + public ReservationUpdater setCallRecord(final String callRecord) { this.callRecord = callRecord; return this; } - public ReservationUpdater setCallTimeout(final Integer callTimeout){ + + public ReservationUpdater setCallTimeout(final Integer callTimeout) { this.callTimeout = callTimeout; return this; } - public ReservationUpdater setCallTo(final String callTo){ + + public ReservationUpdater setCallTo(final String callTo) { this.callTo = callTo; return this; } - public ReservationUpdater setCallUrl(final URI callUrl){ + + public ReservationUpdater setCallUrl(final URI callUrl) { this.callUrl = callUrl; return this; } - public ReservationUpdater setCallUrl(final String callUrl){ + public ReservationUpdater setCallUrl(final String callUrl) { return setCallUrl(Promoter.uriFromString(callUrl)); } - public ReservationUpdater setCallStatusCallbackUrl(final URI callStatusCallbackUrl){ + + public ReservationUpdater setCallStatusCallbackUrl( + final URI callStatusCallbackUrl + ) { this.callStatusCallbackUrl = callStatusCallbackUrl; return this; } - public ReservationUpdater setCallStatusCallbackUrl(final String callStatusCallbackUrl){ - return setCallStatusCallbackUrl(Promoter.uriFromString(callStatusCallbackUrl)); + public ReservationUpdater setCallStatusCallbackUrl( + final String callStatusCallbackUrl + ) { + return setCallStatusCallbackUrl( + Promoter.uriFromString(callStatusCallbackUrl) + ); } - public ReservationUpdater setCallAccept(final Boolean callAccept){ + + public ReservationUpdater setCallAccept(final Boolean callAccept) { this.callAccept = callAccept; return this; } - public ReservationUpdater setRedirectCallSid(final String redirectCallSid){ + + public ReservationUpdater setRedirectCallSid(final String redirectCallSid) { this.redirectCallSid = redirectCallSid; return this; } - public ReservationUpdater setRedirectAccept(final Boolean redirectAccept){ + + public ReservationUpdater setRedirectAccept(final Boolean redirectAccept) { this.redirectAccept = redirectAccept; return this; } - public ReservationUpdater setRedirectUrl(final URI redirectUrl){ + + public ReservationUpdater setRedirectUrl(final URI redirectUrl) { this.redirectUrl = redirectUrl; return this; } - public ReservationUpdater setRedirectUrl(final String redirectUrl){ + public ReservationUpdater setRedirectUrl(final String redirectUrl) { return setRedirectUrl(Promoter.uriFromString(redirectUrl)); } - public ReservationUpdater setTo(final String to){ + + public ReservationUpdater setTo(final String to) { this.to = to; return this; } - public ReservationUpdater setFrom(final String from){ + + public ReservationUpdater setFrom(final String from) { this.from = from; return this; } - public ReservationUpdater setStatusCallback(final URI statusCallback){ + + public ReservationUpdater setStatusCallback(final URI statusCallback) { this.statusCallback = statusCallback; return this; } - public ReservationUpdater setStatusCallback(final String statusCallback){ + public ReservationUpdater setStatusCallback(final String statusCallback) { return setStatusCallback(Promoter.uriFromString(statusCallback)); } - public ReservationUpdater setStatusCallbackMethod(final HttpMethod statusCallbackMethod){ + + public ReservationUpdater setStatusCallbackMethod( + final HttpMethod statusCallbackMethod + ) { this.statusCallbackMethod = statusCallbackMethod; return this; } - public ReservationUpdater setStatusCallbackEvent(final List statusCallbackEvent){ + + public ReservationUpdater setStatusCallbackEvent( + final List statusCallbackEvent + ) { this.statusCallbackEvent = statusCallbackEvent; return this; } - public ReservationUpdater setStatusCallbackEvent(final Reservation.CallStatus statusCallbackEvent){ + + public ReservationUpdater setStatusCallbackEvent( + final Reservation.CallStatus statusCallbackEvent + ) { return setStatusCallbackEvent(Promoter.listOfOne(statusCallbackEvent)); } - public ReservationUpdater setTimeout(final Integer timeout){ + + public ReservationUpdater setTimeout(final Integer timeout) { this.timeout = timeout; return this; } - public ReservationUpdater setRecord(final Boolean record){ + + public ReservationUpdater setRecord(final Boolean record) { this.record = record; return this; } - public ReservationUpdater setMuted(final Boolean muted){ + + public ReservationUpdater setMuted(final Boolean muted) { this.muted = muted; return this; } - public ReservationUpdater setBeep(final String beep){ + + public ReservationUpdater setBeep(final String beep) { this.beep = beep; return this; } - public ReservationUpdater setStartConferenceOnEnter(final Boolean startConferenceOnEnter){ + + public ReservationUpdater setStartConferenceOnEnter( + final Boolean startConferenceOnEnter + ) { this.startConferenceOnEnter = startConferenceOnEnter; return this; } - public ReservationUpdater setEndConferenceOnExit(final Boolean endConferenceOnExit){ + + public ReservationUpdater setEndConferenceOnExit( + final Boolean endConferenceOnExit + ) { this.endConferenceOnExit = endConferenceOnExit; return this; } - public ReservationUpdater setWaitUrl(final URI waitUrl){ + + public ReservationUpdater setWaitUrl(final URI waitUrl) { this.waitUrl = waitUrl; return this; } - public ReservationUpdater setWaitUrl(final String waitUrl){ + public ReservationUpdater setWaitUrl(final String waitUrl) { return setWaitUrl(Promoter.uriFromString(waitUrl)); } - public ReservationUpdater setWaitMethod(final HttpMethod waitMethod){ + + public ReservationUpdater setWaitMethod(final HttpMethod waitMethod) { this.waitMethod = waitMethod; return this; } - public ReservationUpdater setEarlyMedia(final Boolean earlyMedia){ + + public ReservationUpdater setEarlyMedia(final Boolean earlyMedia) { this.earlyMedia = earlyMedia; return this; } - public ReservationUpdater setMaxParticipants(final Integer maxParticipants){ + + public ReservationUpdater setMaxParticipants( + final Integer maxParticipants + ) { this.maxParticipants = maxParticipants; return this; } - public ReservationUpdater setConferenceStatusCallback(final URI conferenceStatusCallback){ + + public ReservationUpdater setConferenceStatusCallback( + final URI conferenceStatusCallback + ) { this.conferenceStatusCallback = conferenceStatusCallback; return this; } - public ReservationUpdater setConferenceStatusCallback(final String conferenceStatusCallback){ - return setConferenceStatusCallback(Promoter.uriFromString(conferenceStatusCallback)); + public ReservationUpdater setConferenceStatusCallback( + final String conferenceStatusCallback + ) { + return setConferenceStatusCallback( + Promoter.uriFromString(conferenceStatusCallback) + ); } - public ReservationUpdater setConferenceStatusCallbackMethod(final HttpMethod conferenceStatusCallbackMethod){ + + public ReservationUpdater setConferenceStatusCallbackMethod( + final HttpMethod conferenceStatusCallbackMethod + ) { this.conferenceStatusCallbackMethod = conferenceStatusCallbackMethod; return this; } - public ReservationUpdater setConferenceStatusCallbackEvent(final List conferenceStatusCallbackEvent){ + + public ReservationUpdater setConferenceStatusCallbackEvent( + final List conferenceStatusCallbackEvent + ) { this.conferenceStatusCallbackEvent = conferenceStatusCallbackEvent; return this; } - public ReservationUpdater setConferenceStatusCallbackEvent(final Reservation.ConferenceEvent conferenceStatusCallbackEvent){ - return setConferenceStatusCallbackEvent(Promoter.listOfOne(conferenceStatusCallbackEvent)); + + public ReservationUpdater setConferenceStatusCallbackEvent( + final Reservation.ConferenceEvent conferenceStatusCallbackEvent + ) { + return setConferenceStatusCallbackEvent( + Promoter.listOfOne(conferenceStatusCallbackEvent) + ); } - public ReservationUpdater setConferenceRecord(final String conferenceRecord){ + + public ReservationUpdater setConferenceRecord( + final String conferenceRecord + ) { this.conferenceRecord = conferenceRecord; return this; } - public ReservationUpdater setConferenceTrim(final String conferenceTrim){ + + public ReservationUpdater setConferenceTrim(final String conferenceTrim) { this.conferenceTrim = conferenceTrim; return this; } - public ReservationUpdater setRecordingChannels(final String recordingChannels){ + + public ReservationUpdater setRecordingChannels( + final String recordingChannels + ) { this.recordingChannels = recordingChannels; return this; } - public ReservationUpdater setRecordingStatusCallback(final URI recordingStatusCallback){ + + public ReservationUpdater setRecordingStatusCallback( + final URI recordingStatusCallback + ) { this.recordingStatusCallback = recordingStatusCallback; return this; } - public ReservationUpdater setRecordingStatusCallback(final String recordingStatusCallback){ - return setRecordingStatusCallback(Promoter.uriFromString(recordingStatusCallback)); + public ReservationUpdater setRecordingStatusCallback( + final String recordingStatusCallback + ) { + return setRecordingStatusCallback( + Promoter.uriFromString(recordingStatusCallback) + ); } - public ReservationUpdater setRecordingStatusCallbackMethod(final HttpMethod recordingStatusCallbackMethod){ + + public ReservationUpdater setRecordingStatusCallbackMethod( + final HttpMethod recordingStatusCallbackMethod + ) { this.recordingStatusCallbackMethod = recordingStatusCallbackMethod; return this; } - public ReservationUpdater setConferenceRecordingStatusCallback(final URI conferenceRecordingStatusCallback){ - this.conferenceRecordingStatusCallback = conferenceRecordingStatusCallback; + + public ReservationUpdater setConferenceRecordingStatusCallback( + final URI conferenceRecordingStatusCallback + ) { + this.conferenceRecordingStatusCallback = + conferenceRecordingStatusCallback; return this; } - public ReservationUpdater setConferenceRecordingStatusCallback(final String conferenceRecordingStatusCallback){ - return setConferenceRecordingStatusCallback(Promoter.uriFromString(conferenceRecordingStatusCallback)); + public ReservationUpdater setConferenceRecordingStatusCallback( + final String conferenceRecordingStatusCallback + ) { + return setConferenceRecordingStatusCallback( + Promoter.uriFromString(conferenceRecordingStatusCallback) + ); } - public ReservationUpdater setConferenceRecordingStatusCallbackMethod(final HttpMethod conferenceRecordingStatusCallbackMethod){ - this.conferenceRecordingStatusCallbackMethod = conferenceRecordingStatusCallbackMethod; + + public ReservationUpdater setConferenceRecordingStatusCallbackMethod( + final HttpMethod conferenceRecordingStatusCallbackMethod + ) { + this.conferenceRecordingStatusCallbackMethod = + conferenceRecordingStatusCallbackMethod; return this; } - public ReservationUpdater setRegion(final String region){ + + public ReservationUpdater setRegion(final String region) { this.region = region; return this; } - public ReservationUpdater setSipAuthUsername(final String sipAuthUsername){ + + public ReservationUpdater setSipAuthUsername(final String sipAuthUsername) { this.sipAuthUsername = sipAuthUsername; return this; } - public ReservationUpdater setSipAuthPassword(final String sipAuthPassword){ + + public ReservationUpdater setSipAuthPassword(final String sipAuthPassword) { this.sipAuthPassword = sipAuthPassword; return this; } - public ReservationUpdater setDequeueStatusCallbackEvent(final List dequeueStatusCallbackEvent){ + + public ReservationUpdater setDequeueStatusCallbackEvent( + final List dequeueStatusCallbackEvent + ) { this.dequeueStatusCallbackEvent = dequeueStatusCallbackEvent; return this; } - public ReservationUpdater setDequeueStatusCallbackEvent(final String dequeueStatusCallbackEvent){ - return setDequeueStatusCallbackEvent(Promoter.listOfOne(dequeueStatusCallbackEvent)); + + public ReservationUpdater setDequeueStatusCallbackEvent( + final String dequeueStatusCallbackEvent + ) { + return setDequeueStatusCallbackEvent( + Promoter.listOfOne(dequeueStatusCallbackEvent) + ); } - public ReservationUpdater setPostWorkActivitySid(final String postWorkActivitySid){ + + public ReservationUpdater setPostWorkActivitySid( + final String postWorkActivitySid + ) { this.postWorkActivitySid = postWorkActivitySid; return this; } - public ReservationUpdater setSupervisorMode(final Reservation.SupervisorMode supervisorMode){ + + public ReservationUpdater setSupervisorMode( + final Reservation.SupervisorMode supervisorMode + ) { this.supervisorMode = supervisorMode; return this; } - public ReservationUpdater setSupervisor(final String supervisor){ + + public ReservationUpdater setSupervisor(final String supervisor) { this.supervisor = supervisor; return this; } - public ReservationUpdater setEndConferenceOnCustomerExit(final Boolean endConferenceOnCustomerExit){ + + public ReservationUpdater setEndConferenceOnCustomerExit( + final Boolean endConferenceOnCustomerExit + ) { this.endConferenceOnCustomerExit = endConferenceOnCustomerExit; return this; } - public ReservationUpdater setBeepOnCustomerEntrance(final Boolean beepOnCustomerEntrance){ + + public ReservationUpdater setBeepOnCustomerEntrance( + final Boolean beepOnCustomerEntrance + ) { this.beepOnCustomerEntrance = beepOnCustomerEntrance; return this; } @Override - public Reservation update(final TwilioRestClient client){ - String path = "/v1/Workspaces/{WorkspaceSid}/Tasks/{TaskSid}/Reservations/{Sid}"; + public Reservation update(final TwilioRestClient client) { + String path = + "/v1/Workspaces/{WorkspaceSid}/Tasks/{TaskSid}/Reservations/{Sid}"; - path = path.replace("{"+"WorkspaceSid"+"}", this.pathWorkspaceSid.toString()); - path = path.replace("{"+"TaskSid"+"}", this.pathTaskSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = path.replace("{" + "TaskSid" + "}", this.pathTaskSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.TASKROUTER.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); addHeaderParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Reservation update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Reservation update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Reservation.fromJson(response.getStream(), client.getObjectMapper()); + return Reservation.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (reservationStatus != null) { - request.addPostParam("ReservationStatus", reservationStatus.toString()); - + request.addPostParam( + "ReservationStatus", + reservationStatus.toString() + ); } if (workerActivitySid != null) { request.addPostParam("WorkerActivitySid", workerActivitySid); - } if (instruction != null) { request.addPostParam("Instruction", instruction); - } if (dequeuePostWorkActivitySid != null) { - request.addPostParam("DequeuePostWorkActivitySid", dequeuePostWorkActivitySid); - + request.addPostParam( + "DequeuePostWorkActivitySid", + dequeuePostWorkActivitySid + ); } if (dequeueFrom != null) { request.addPostParam("DequeueFrom", dequeueFrom); - } if (dequeueRecord != null) { request.addPostParam("DequeueRecord", dequeueRecord); - } if (dequeueTimeout != null) { request.addPostParam("DequeueTimeout", dequeueTimeout.toString()); - } if (dequeueTo != null) { request.addPostParam("DequeueTo", dequeueTo); - } if (dequeueStatusCallbackUrl != null) { - request.addPostParam("DequeueStatusCallbackUrl", dequeueStatusCallbackUrl.toString()); - + request.addPostParam( + "DequeueStatusCallbackUrl", + dequeueStatusCallbackUrl.toString() + ); } if (callFrom != null) { request.addPostParam("CallFrom", callFrom); - } if (callRecord != null) { request.addPostParam("CallRecord", callRecord); - } if (callTimeout != null) { request.addPostParam("CallTimeout", callTimeout.toString()); - } if (callTo != null) { request.addPostParam("CallTo", callTo); - } if (callUrl != null) { request.addPostParam("CallUrl", callUrl.toString()); - } if (callStatusCallbackUrl != null) { - request.addPostParam("CallStatusCallbackUrl", callStatusCallbackUrl.toString()); - + request.addPostParam( + "CallStatusCallbackUrl", + callStatusCallbackUrl.toString() + ); } if (callAccept != null) { request.addPostParam("CallAccept", callAccept.toString()); - } if (redirectCallSid != null) { request.addPostParam("RedirectCallSid", redirectCallSid); - } if (redirectAccept != null) { request.addPostParam("RedirectAccept", redirectAccept.toString()); - } if (redirectUrl != null) { request.addPostParam("RedirectUrl", redirectUrl.toString()); - } if (to != null) { request.addPostParam("To", to); - } if (from != null) { request.addPostParam("From", from); - } if (statusCallback != null) { request.addPostParam("StatusCallback", statusCallback.toString()); - } if (statusCallbackMethod != null) { - request.addPostParam("StatusCallbackMethod", statusCallbackMethod.toString()); - + request.addPostParam( + "StatusCallbackMethod", + statusCallbackMethod.toString() + ); } if (statusCallbackEvent != null) { for (Reservation.CallStatus prop : statusCallbackEvent) { request.addPostParam("StatusCallbackEvent", prop.toString()); } - } if (timeout != null) { request.addPostParam("Timeout", timeout.toString()); - } if (record != null) { request.addPostParam("Record", record.toString()); - } if (muted != null) { request.addPostParam("Muted", muted.toString()); - } if (beep != null) { request.addPostParam("Beep", beep); - } if (startConferenceOnEnter != null) { - request.addPostParam("StartConferenceOnEnter", startConferenceOnEnter.toString()); - + request.addPostParam( + "StartConferenceOnEnter", + startConferenceOnEnter.toString() + ); } if (endConferenceOnExit != null) { - request.addPostParam("EndConferenceOnExit", endConferenceOnExit.toString()); - + request.addPostParam( + "EndConferenceOnExit", + endConferenceOnExit.toString() + ); } if (waitUrl != null) { request.addPostParam("WaitUrl", waitUrl.toString()); - } if (waitMethod != null) { request.addPostParam("WaitMethod", waitMethod.toString()); - } if (earlyMedia != null) { request.addPostParam("EarlyMedia", earlyMedia.toString()); - } if (maxParticipants != null) { request.addPostParam("MaxParticipants", maxParticipants.toString()); - } if (conferenceStatusCallback != null) { - request.addPostParam("ConferenceStatusCallback", conferenceStatusCallback.toString()); - + request.addPostParam( + "ConferenceStatusCallback", + conferenceStatusCallback.toString() + ); } if (conferenceStatusCallbackMethod != null) { - request.addPostParam("ConferenceStatusCallbackMethod", conferenceStatusCallbackMethod.toString()); - + request.addPostParam( + "ConferenceStatusCallbackMethod", + conferenceStatusCallbackMethod.toString() + ); } if (conferenceStatusCallbackEvent != null) { for (Reservation.ConferenceEvent prop : conferenceStatusCallbackEvent) { - request.addPostParam("ConferenceStatusCallbackEvent", prop.toString()); + request.addPostParam( + "ConferenceStatusCallbackEvent", + prop.toString() + ); } - } if (conferenceRecord != null) { request.addPostParam("ConferenceRecord", conferenceRecord); - } if (conferenceTrim != null) { request.addPostParam("ConferenceTrim", conferenceTrim); - } if (recordingChannels != null) { request.addPostParam("RecordingChannels", recordingChannels); - } if (recordingStatusCallback != null) { - request.addPostParam("RecordingStatusCallback", recordingStatusCallback.toString()); - + request.addPostParam( + "RecordingStatusCallback", + recordingStatusCallback.toString() + ); } if (recordingStatusCallbackMethod != null) { - request.addPostParam("RecordingStatusCallbackMethod", recordingStatusCallbackMethod.toString()); - + request.addPostParam( + "RecordingStatusCallbackMethod", + recordingStatusCallbackMethod.toString() + ); } if (conferenceRecordingStatusCallback != null) { - request.addPostParam("ConferenceRecordingStatusCallback", conferenceRecordingStatusCallback.toString()); - + request.addPostParam( + "ConferenceRecordingStatusCallback", + conferenceRecordingStatusCallback.toString() + ); } if (conferenceRecordingStatusCallbackMethod != null) { - request.addPostParam("ConferenceRecordingStatusCallbackMethod", conferenceRecordingStatusCallbackMethod.toString()); - + request.addPostParam( + "ConferenceRecordingStatusCallbackMethod", + conferenceRecordingStatusCallbackMethod.toString() + ); } if (region != null) { request.addPostParam("Region", region); - } if (sipAuthUsername != null) { request.addPostParam("SipAuthUsername", sipAuthUsername); - } if (sipAuthPassword != null) { request.addPostParam("SipAuthPassword", sipAuthPassword); - } if (dequeueStatusCallbackEvent != null) { for (String prop : dequeueStatusCallbackEvent) { request.addPostParam("DequeueStatusCallbackEvent", prop); } - } if (postWorkActivitySid != null) { request.addPostParam("PostWorkActivitySid", postWorkActivitySid); - } if (supervisorMode != null) { request.addPostParam("SupervisorMode", supervisorMode.toString()); - } if (supervisor != null) { request.addPostParam("Supervisor", supervisor); - } if (endConferenceOnCustomerExit != null) { - request.addPostParam("EndConferenceOnCustomerExit", endConferenceOnCustomerExit.toString()); - + request.addPostParam( + "EndConferenceOnCustomerExit", + endConferenceOnCustomerExit.toString() + ); } if (beepOnCustomerEntrance != null) { - request.addPostParam("BeepOnCustomerEntrance", beepOnCustomerEntrance.toString()); - + request.addPostParam( + "BeepOnCustomerEntrance", + beepOnCustomerEntrance.toString() + ); } } + private void addHeaderParams(final Request request) { if (ifMatch != null) { request.addHeaderParam("If-Match", ifMatch); - } } } diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueueCumulativeStatistics.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueueCumulativeStatistics.java index dc8f43819f..7a0e144f7d 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueueCumulativeStatistics.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueueCumulativeStatistics.java @@ -23,42 +23,50 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class TaskQueueCumulativeStatistics extends Resource { + private static final long serialVersionUID = 113454189238794L; - public static TaskQueueCumulativeStatisticsFetcher fetcher(final String pathWorkspaceSid, final String pathTaskQueueSid){ - return new TaskQueueCumulativeStatisticsFetcher(pathWorkspaceSid, pathTaskQueueSid); + public static TaskQueueCumulativeStatisticsFetcher fetcher( + final String pathWorkspaceSid, + final String pathTaskQueueSid + ) { + return new TaskQueueCumulativeStatisticsFetcher( + pathWorkspaceSid, + pathTaskQueueSid + ); } /** - * Converts a JSON String into a TaskQueueCumulativeStatistics object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return TaskQueueCumulativeStatistics object represented by the provided JSON - */ - public static TaskQueueCumulativeStatistics fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a TaskQueueCumulativeStatistics object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return TaskQueueCumulativeStatistics object represented by the provided JSON + */ + public static TaskQueueCumulativeStatistics fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, TaskQueueCumulativeStatistics.class); + return objectMapper.readValue( + json, + TaskQueueCumulativeStatistics.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -67,17 +75,23 @@ public static TaskQueueCumulativeStatistics fromJson(final String json, final Ob } /** - * Converts a JSON InputStream into a TaskQueueCumulativeStatistics object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return TaskQueueCumulativeStatistics object represented by the provided JSON - */ - public static TaskQueueCumulativeStatistics fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a TaskQueueCumulativeStatistics object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return TaskQueueCumulativeStatistics object represented by the provided JSON + */ + public static TaskQueueCumulativeStatistics fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, TaskQueueCumulativeStatistics.class); + return objectMapper.readValue( + json, + TaskQueueCumulativeStatistics.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -110,71 +124,48 @@ public static TaskQueueCumulativeStatistics fromJson(final InputStream json, fin @JsonCreator private TaskQueueCumulativeStatistics( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("avg_task_acceptance_time") - final Integer avgTaskAcceptanceTime, - - @JsonProperty("start_time") - final String startTime, - - @JsonProperty("end_time") - final String endTime, - - @JsonProperty("reservations_created") - final Integer reservationsCreated, - - @JsonProperty("reservations_accepted") - final Integer reservationsAccepted, - - @JsonProperty("reservations_rejected") - final Integer reservationsRejected, - - @JsonProperty("reservations_timed_out") - final Integer reservationsTimedOut, - - @JsonProperty("reservations_canceled") - final Integer reservationsCanceled, - - @JsonProperty("reservations_rescinded") - final Integer reservationsRescinded, - - @JsonProperty("split_by_wait_time") - final Map splitByWaitTime, - - @JsonProperty("task_queue_sid") - final String taskQueueSid, - - @JsonProperty("wait_duration_until_accepted") - final Map waitDurationUntilAccepted, - - @JsonProperty("wait_duration_until_canceled") - final Map waitDurationUntilCanceled, - - @JsonProperty("wait_duration_in_queue_until_accepted") - final Map waitDurationInQueueUntilAccepted, - - @JsonProperty("tasks_canceled") - final Integer tasksCanceled, - - @JsonProperty("tasks_completed") - final Integer tasksCompleted, - - @JsonProperty("tasks_deleted") - final Integer tasksDeleted, - - @JsonProperty("tasks_entered") - final Integer tasksEntered, - - @JsonProperty("tasks_moved") - final Integer tasksMoved, - - @JsonProperty("workspace_sid") - final String workspaceSid, - - @JsonProperty("url") - final URI url + @JsonProperty("account_sid") final String accountSid, + @JsonProperty( + "avg_task_acceptance_time" + ) final Integer avgTaskAcceptanceTime, + @JsonProperty("start_time") final String startTime, + @JsonProperty("end_time") final String endTime, + @JsonProperty("reservations_created") final Integer reservationsCreated, + @JsonProperty( + "reservations_accepted" + ) final Integer reservationsAccepted, + @JsonProperty( + "reservations_rejected" + ) final Integer reservationsRejected, + @JsonProperty( + "reservations_timed_out" + ) final Integer reservationsTimedOut, + @JsonProperty( + "reservations_canceled" + ) final Integer reservationsCanceled, + @JsonProperty( + "reservations_rescinded" + ) final Integer reservationsRescinded, + @JsonProperty( + "split_by_wait_time" + ) final Map splitByWaitTime, + @JsonProperty("task_queue_sid") final String taskQueueSid, + @JsonProperty( + "wait_duration_until_accepted" + ) final Map waitDurationUntilAccepted, + @JsonProperty( + "wait_duration_until_canceled" + ) final Map waitDurationUntilCanceled, + @JsonProperty( + "wait_duration_in_queue_until_accepted" + ) final Map waitDurationInQueueUntilAccepted, + @JsonProperty("tasks_canceled") final Integer tasksCanceled, + @JsonProperty("tasks_completed") final Integer tasksCompleted, + @JsonProperty("tasks_deleted") final Integer tasksDeleted, + @JsonProperty("tasks_entered") final Integer tasksEntered, + @JsonProperty("tasks_moved") final Integer tasksMoved, + @JsonProperty("workspace_sid") final String workspaceSid, + @JsonProperty("url") final URI url ) { this.accountSid = accountSid; this.avgTaskAcceptanceTime = avgTaskAcceptanceTime; @@ -190,7 +181,8 @@ private TaskQueueCumulativeStatistics( this.taskQueueSid = taskQueueSid; this.waitDurationUntilAccepted = waitDurationUntilAccepted; this.waitDurationUntilCanceled = waitDurationUntilCanceled; - this.waitDurationInQueueUntilAccepted = waitDurationInQueueUntilAccepted; + this.waitDurationInQueueUntilAccepted = + waitDurationInQueueUntilAccepted; this.tasksCanceled = tasksCanceled; this.tasksCompleted = tasksCompleted; this.tasksDeleted = tasksDeleted; @@ -200,76 +192,97 @@ private TaskQueueCumulativeStatistics( this.url = url; } - public final String getAccountSid() { - return this.accountSid; - } - public final Integer getAvgTaskAcceptanceTime() { - return this.avgTaskAcceptanceTime; - } - public final ZonedDateTime getStartTime() { - return this.startTime; - } - public final ZonedDateTime getEndTime() { - return this.endTime; - } - public final Integer getReservationsCreated() { - return this.reservationsCreated; - } - public final Integer getReservationsAccepted() { - return this.reservationsAccepted; - } - public final Integer getReservationsRejected() { - return this.reservationsRejected; - } - public final Integer getReservationsTimedOut() { - return this.reservationsTimedOut; - } - public final Integer getReservationsCanceled() { - return this.reservationsCanceled; - } - public final Integer getReservationsRescinded() { - return this.reservationsRescinded; - } - public final Map getSplitByWaitTime() { - return this.splitByWaitTime; - } - public final String getTaskQueueSid() { - return this.taskQueueSid; - } - public final Map getWaitDurationUntilAccepted() { - return this.waitDurationUntilAccepted; - } - public final Map getWaitDurationUntilCanceled() { - return this.waitDurationUntilCanceled; - } - public final Map getWaitDurationInQueueUntilAccepted() { - return this.waitDurationInQueueUntilAccepted; - } - public final Integer getTasksCanceled() { - return this.tasksCanceled; - } - public final Integer getTasksCompleted() { - return this.tasksCompleted; - } - public final Integer getTasksDeleted() { - return this.tasksDeleted; - } - public final Integer getTasksEntered() { - return this.tasksEntered; - } - public final Integer getTasksMoved() { - return this.tasksMoved; - } - public final String getWorkspaceSid() { - return this.workspaceSid; - } - public final URI getUrl() { - return this.url; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final Integer getAvgTaskAcceptanceTime() { + return this.avgTaskAcceptanceTime; + } + + public final ZonedDateTime getStartTime() { + return this.startTime; + } + + public final ZonedDateTime getEndTime() { + return this.endTime; + } + + public final Integer getReservationsCreated() { + return this.reservationsCreated; + } + + public final Integer getReservationsAccepted() { + return this.reservationsAccepted; + } + + public final Integer getReservationsRejected() { + return this.reservationsRejected; + } + + public final Integer getReservationsTimedOut() { + return this.reservationsTimedOut; + } + + public final Integer getReservationsCanceled() { + return this.reservationsCanceled; + } + + public final Integer getReservationsRescinded() { + return this.reservationsRescinded; + } + + public final Map getSplitByWaitTime() { + return this.splitByWaitTime; + } + + public final String getTaskQueueSid() { + return this.taskQueueSid; + } + + public final Map getWaitDurationUntilAccepted() { + return this.waitDurationUntilAccepted; + } + + public final Map getWaitDurationUntilCanceled() { + return this.waitDurationUntilCanceled; + } + + public final Map getWaitDurationInQueueUntilAccepted() { + return this.waitDurationInQueueUntilAccepted; + } + + public final Integer getTasksCanceled() { + return this.tasksCanceled; + } + + public final Integer getTasksCompleted() { + return this.tasksCompleted; + } + + public final Integer getTasksDeleted() { + return this.tasksDeleted; + } + + public final Integer getTasksEntered() { + return this.tasksEntered; + } + + public final Integer getTasksMoved() { + return this.tasksMoved; + } + + public final String getWorkspaceSid() { + return this.workspaceSid; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -279,13 +292,72 @@ public boolean equals(final Object o) { TaskQueueCumulativeStatistics other = (TaskQueueCumulativeStatistics) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(avgTaskAcceptanceTime, other.avgTaskAcceptanceTime) && Objects.equals(startTime, other.startTime) && Objects.equals(endTime, other.endTime) && Objects.equals(reservationsCreated, other.reservationsCreated) && Objects.equals(reservationsAccepted, other.reservationsAccepted) && Objects.equals(reservationsRejected, other.reservationsRejected) && Objects.equals(reservationsTimedOut, other.reservationsTimedOut) && Objects.equals(reservationsCanceled, other.reservationsCanceled) && Objects.equals(reservationsRescinded, other.reservationsRescinded) && Objects.equals(splitByWaitTime, other.splitByWaitTime) && Objects.equals(taskQueueSid, other.taskQueueSid) && Objects.equals(waitDurationUntilAccepted, other.waitDurationUntilAccepted) && Objects.equals(waitDurationUntilCanceled, other.waitDurationUntilCanceled) && Objects.equals(waitDurationInQueueUntilAccepted, other.waitDurationInQueueUntilAccepted) && Objects.equals(tasksCanceled, other.tasksCanceled) && Objects.equals(tasksCompleted, other.tasksCompleted) && Objects.equals(tasksDeleted, other.tasksDeleted) && Objects.equals(tasksEntered, other.tasksEntered) && Objects.equals(tasksMoved, other.tasksMoved) && Objects.equals(workspaceSid, other.workspaceSid) && Objects.equals(url, other.url) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals( + avgTaskAcceptanceTime, + other.avgTaskAcceptanceTime + ) && + Objects.equals(startTime, other.startTime) && + Objects.equals(endTime, other.endTime) && + Objects.equals(reservationsCreated, other.reservationsCreated) && + Objects.equals(reservationsAccepted, other.reservationsAccepted) && + Objects.equals(reservationsRejected, other.reservationsRejected) && + Objects.equals(reservationsTimedOut, other.reservationsTimedOut) && + Objects.equals(reservationsCanceled, other.reservationsCanceled) && + Objects.equals( + reservationsRescinded, + other.reservationsRescinded + ) && + Objects.equals(splitByWaitTime, other.splitByWaitTime) && + Objects.equals(taskQueueSid, other.taskQueueSid) && + Objects.equals( + waitDurationUntilAccepted, + other.waitDurationUntilAccepted + ) && + Objects.equals( + waitDurationUntilCanceled, + other.waitDurationUntilCanceled + ) && + Objects.equals( + waitDurationInQueueUntilAccepted, + other.waitDurationInQueueUntilAccepted + ) && + Objects.equals(tasksCanceled, other.tasksCanceled) && + Objects.equals(tasksCompleted, other.tasksCompleted) && + Objects.equals(tasksDeleted, other.tasksDeleted) && + Objects.equals(tasksEntered, other.tasksEntered) && + Objects.equals(tasksMoved, other.tasksMoved) && + Objects.equals(workspaceSid, other.workspaceSid) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, avgTaskAcceptanceTime, startTime, endTime, reservationsCreated, reservationsAccepted, reservationsRejected, reservationsTimedOut, reservationsCanceled, reservationsRescinded, splitByWaitTime, taskQueueSid, waitDurationUntilAccepted, waitDurationUntilCanceled, waitDurationInQueueUntilAccepted, tasksCanceled, tasksCompleted, tasksDeleted, tasksEntered, tasksMoved, workspaceSid, url); + return Objects.hash( + accountSid, + avgTaskAcceptanceTime, + startTime, + endTime, + reservationsCreated, + reservationsAccepted, + reservationsRejected, + reservationsTimedOut, + reservationsCanceled, + reservationsRescinded, + splitByWaitTime, + taskQueueSid, + waitDurationUntilAccepted, + waitDurationUntilCanceled, + waitDurationInQueueUntilAccepted, + tasksCanceled, + tasksCompleted, + tasksDeleted, + tasksEntered, + tasksMoved, + workspaceSid, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueueCumulativeStatisticsFetcher.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueueCumulativeStatisticsFetcher.java index 600bfd402e..e6209d16cf 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueueCumulativeStatisticsFetcher.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueueCumulativeStatisticsFetcher.java @@ -23,12 +23,11 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.time.ZonedDateTime; +public class TaskQueueCumulativeStatisticsFetcher + extends Fetcher { - -public class TaskQueueCumulativeStatisticsFetcher extends Fetcher { private String pathWorkspaceSid; private String pathTaskQueueSid; private ZonedDateTime endDate; @@ -37,38 +36,64 @@ public class TaskQueueCumulativeStatisticsFetcher extends Fetcher> activityStatistics, - - @JsonProperty("longest_task_waiting_age") - final Integer longestTaskWaitingAge, - - @JsonProperty("longest_task_waiting_sid") - final String longestTaskWaitingSid, - - @JsonProperty("longest_relative_task_age_in_queue") - final Integer longestRelativeTaskAgeInQueue, - - @JsonProperty("longest_relative_task_sid_in_queue") - final String longestRelativeTaskSidInQueue, - - @JsonProperty("task_queue_sid") - final String taskQueueSid, - - @JsonProperty("tasks_by_priority") - final Map tasksByPriority, - - @JsonProperty("tasks_by_status") - final Map tasksByStatus, - - @JsonProperty("total_available_workers") - final Integer totalAvailableWorkers, - - @JsonProperty("total_eligible_workers") - final Integer totalEligibleWorkers, - - @JsonProperty("total_tasks") - final Integer totalTasks, - - @JsonProperty("workspace_sid") - final String workspaceSid, - - @JsonProperty("url") - final URI url + @JsonProperty("account_sid") final String accountSid, + @JsonProperty( + "activity_statistics" + ) final List> activityStatistics, + @JsonProperty( + "longest_task_waiting_age" + ) final Integer longestTaskWaitingAge, + @JsonProperty( + "longest_task_waiting_sid" + ) final String longestTaskWaitingSid, + @JsonProperty( + "longest_relative_task_age_in_queue" + ) final Integer longestRelativeTaskAgeInQueue, + @JsonProperty( + "longest_relative_task_sid_in_queue" + ) final String longestRelativeTaskSidInQueue, + @JsonProperty("task_queue_sid") final String taskQueueSid, + @JsonProperty( + "tasks_by_priority" + ) final Map tasksByPriority, + @JsonProperty( + "tasks_by_status" + ) final Map tasksByStatus, + @JsonProperty( + "total_available_workers" + ) final Integer totalAvailableWorkers, + @JsonProperty( + "total_eligible_workers" + ) final Integer totalEligibleWorkers, + @JsonProperty("total_tasks") final Integer totalTasks, + @JsonProperty("workspace_sid") final String workspaceSid, + @JsonProperty("url") final URI url ) { this.accountSid = accountSid; this.activityStatistics = activityStatistics; @@ -159,52 +164,65 @@ private TaskQueueRealTimeStatistics( this.url = url; } - public final String getAccountSid() { - return this.accountSid; - } - public final List> getActivityStatistics() { - return this.activityStatistics; - } - public final Integer getLongestTaskWaitingAge() { - return this.longestTaskWaitingAge; - } - public final String getLongestTaskWaitingSid() { - return this.longestTaskWaitingSid; - } - public final Integer getLongestRelativeTaskAgeInQueue() { - return this.longestRelativeTaskAgeInQueue; - } - public final String getLongestRelativeTaskSidInQueue() { - return this.longestRelativeTaskSidInQueue; - } - public final String getTaskQueueSid() { - return this.taskQueueSid; - } - public final Map getTasksByPriority() { - return this.tasksByPriority; - } - public final Map getTasksByStatus() { - return this.tasksByStatus; - } - public final Integer getTotalAvailableWorkers() { - return this.totalAvailableWorkers; - } - public final Integer getTotalEligibleWorkers() { - return this.totalEligibleWorkers; - } - public final Integer getTotalTasks() { - return this.totalTasks; - } - public final String getWorkspaceSid() { - return this.workspaceSid; - } - public final URI getUrl() { - return this.url; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final List> getActivityStatistics() { + return this.activityStatistics; + } + + public final Integer getLongestTaskWaitingAge() { + return this.longestTaskWaitingAge; + } + + public final String getLongestTaskWaitingSid() { + return this.longestTaskWaitingSid; + } + + public final Integer getLongestRelativeTaskAgeInQueue() { + return this.longestRelativeTaskAgeInQueue; + } + + public final String getLongestRelativeTaskSidInQueue() { + return this.longestRelativeTaskSidInQueue; + } + + public final String getTaskQueueSid() { + return this.taskQueueSid; + } + + public final Map getTasksByPriority() { + return this.tasksByPriority; + } + + public final Map getTasksByStatus() { + return this.tasksByStatus; + } + + public final Integer getTotalAvailableWorkers() { + return this.totalAvailableWorkers; + } + + public final Integer getTotalEligibleWorkers() { + return this.totalEligibleWorkers; + } + + public final Integer getTotalTasks() { + return this.totalTasks; + } + + public final String getWorkspaceSid() { + return this.workspaceSid; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -214,13 +232,56 @@ public boolean equals(final Object o) { TaskQueueRealTimeStatistics other = (TaskQueueRealTimeStatistics) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(activityStatistics, other.activityStatistics) && Objects.equals(longestTaskWaitingAge, other.longestTaskWaitingAge) && Objects.equals(longestTaskWaitingSid, other.longestTaskWaitingSid) && Objects.equals(longestRelativeTaskAgeInQueue, other.longestRelativeTaskAgeInQueue) && Objects.equals(longestRelativeTaskSidInQueue, other.longestRelativeTaskSidInQueue) && Objects.equals(taskQueueSid, other.taskQueueSid) && Objects.equals(tasksByPriority, other.tasksByPriority) && Objects.equals(tasksByStatus, other.tasksByStatus) && Objects.equals(totalAvailableWorkers, other.totalAvailableWorkers) && Objects.equals(totalEligibleWorkers, other.totalEligibleWorkers) && Objects.equals(totalTasks, other.totalTasks) && Objects.equals(workspaceSid, other.workspaceSid) && Objects.equals(url, other.url) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(activityStatistics, other.activityStatistics) && + Objects.equals( + longestTaskWaitingAge, + other.longestTaskWaitingAge + ) && + Objects.equals( + longestTaskWaitingSid, + other.longestTaskWaitingSid + ) && + Objects.equals( + longestRelativeTaskAgeInQueue, + other.longestRelativeTaskAgeInQueue + ) && + Objects.equals( + longestRelativeTaskSidInQueue, + other.longestRelativeTaskSidInQueue + ) && + Objects.equals(taskQueueSid, other.taskQueueSid) && + Objects.equals(tasksByPriority, other.tasksByPriority) && + Objects.equals(tasksByStatus, other.tasksByStatus) && + Objects.equals( + totalAvailableWorkers, + other.totalAvailableWorkers + ) && + Objects.equals(totalEligibleWorkers, other.totalEligibleWorkers) && + Objects.equals(totalTasks, other.totalTasks) && + Objects.equals(workspaceSid, other.workspaceSid) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, activityStatistics, longestTaskWaitingAge, longestTaskWaitingSid, longestRelativeTaskAgeInQueue, longestRelativeTaskSidInQueue, taskQueueSid, tasksByPriority, tasksByStatus, totalAvailableWorkers, totalEligibleWorkers, totalTasks, workspaceSid, url); + return Objects.hash( + accountSid, + activityStatistics, + longestTaskWaitingAge, + longestTaskWaitingSid, + longestRelativeTaskAgeInQueue, + longestRelativeTaskSidInQueue, + taskQueueSid, + tasksByPriority, + tasksByStatus, + totalAvailableWorkers, + totalEligibleWorkers, + totalTasks, + workspaceSid, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueueRealTimeStatisticsFetcher.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueueRealTimeStatisticsFetcher.java index 1c91ef0760..e1dff90fcf 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueueRealTimeStatisticsFetcher.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueueRealTimeStatisticsFetcher.java @@ -24,30 +24,43 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class TaskQueueRealTimeStatisticsFetcher + extends Fetcher { - - -public class TaskQueueRealTimeStatisticsFetcher extends Fetcher { private String pathWorkspaceSid; private String pathTaskQueueSid; private String taskChannel; - public TaskQueueRealTimeStatisticsFetcher(final String pathWorkspaceSid, final String pathTaskQueueSid){ + public TaskQueueRealTimeStatisticsFetcher( + final String pathWorkspaceSid, + final String pathTaskQueueSid + ) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathTaskQueueSid = pathTaskQueueSid; } - public TaskQueueRealTimeStatisticsFetcher setTaskChannel(final String taskChannel){ + public TaskQueueRealTimeStatisticsFetcher setTaskChannel( + final String taskChannel + ) { this.taskChannel = taskChannel; return this; } @Override public TaskQueueRealTimeStatistics fetch(final TwilioRestClient client) { - String path = "/v1/Workspaces/{WorkspaceSid}/TaskQueues/{TaskQueueSid}/RealTimeStatistics"; + String path = + "/v1/Workspaces/{WorkspaceSid}/TaskQueues/{TaskQueueSid}/RealTimeStatistics"; - path = path.replace("{"+"WorkspaceSid"+"}", this.pathWorkspaceSid.toString()); - path = path.replace("{"+"TaskQueueSid"+"}", this.pathTaskQueueSid.toString()); + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = + path.replace( + "{" + "TaskQueueSid" + "}", + this.pathTaskQueueSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -58,20 +71,28 @@ public TaskQueueRealTimeStatistics fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("TaskQueueRealTimeStatistics fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "TaskQueueRealTimeStatistics fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return TaskQueueRealTimeStatistics.fromJson(response.getStream(), client.getObjectMapper()); + return TaskQueueRealTimeStatistics.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addQueryParams(final Request request) { if (taskChannel != null) { - request.addQueryParam("TaskChannel", taskChannel); } } diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueueStatistics.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueueStatistics.java index 3c2b9feb3a..03c1f13c85 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueueStatistics.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueueStatistics.java @@ -22,38 +22,43 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class TaskQueueStatistics extends Resource { + private static final long serialVersionUID = 273955433542749L; - public static TaskQueueStatisticsFetcher fetcher(final String pathWorkspaceSid, final String pathTaskQueueSid){ - return new TaskQueueStatisticsFetcher(pathWorkspaceSid, pathTaskQueueSid); + public static TaskQueueStatisticsFetcher fetcher( + final String pathWorkspaceSid, + final String pathTaskQueueSid + ) { + return new TaskQueueStatisticsFetcher( + pathWorkspaceSid, + pathTaskQueueSid + ); } /** - * Converts a JSON String into a TaskQueueStatistics object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return TaskQueueStatistics object represented by the provided JSON - */ - public static TaskQueueStatistics fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a TaskQueueStatistics object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return TaskQueueStatistics object represented by the provided JSON + */ + public static TaskQueueStatistics fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, TaskQueueStatistics.class); @@ -65,14 +70,17 @@ public static TaskQueueStatistics fromJson(final String json, final ObjectMapper } /** - * Converts a JSON InputStream into a TaskQueueStatistics object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return TaskQueueStatistics object represented by the provided JSON - */ - public static TaskQueueStatistics fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a TaskQueueStatistics object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return TaskQueueStatistics object represented by the provided JSON + */ + public static TaskQueueStatistics fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, TaskQueueStatistics.class); @@ -92,23 +100,12 @@ public static TaskQueueStatistics fromJson(final InputStream json, final ObjectM @JsonCreator private TaskQueueStatistics( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("cumulative") - final Map cumulative, - - @JsonProperty("realtime") - final Map realtime, - - @JsonProperty("task_queue_sid") - final String taskQueueSid, - - @JsonProperty("workspace_sid") - final String workspaceSid, - - @JsonProperty("url") - final URI url + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("cumulative") final Map cumulative, + @JsonProperty("realtime") final Map realtime, + @JsonProperty("task_queue_sid") final String taskQueueSid, + @JsonProperty("workspace_sid") final String workspaceSid, + @JsonProperty("url") final URI url ) { this.accountSid = accountSid; this.cumulative = cumulative; @@ -118,28 +115,33 @@ private TaskQueueStatistics( this.url = url; } - public final String getAccountSid() { - return this.accountSid; - } - public final Map getCumulative() { - return this.cumulative; - } - public final Map getRealtime() { - return this.realtime; - } - public final String getTaskQueueSid() { - return this.taskQueueSid; - } - public final String getWorkspaceSid() { - return this.workspaceSid; - } - public final URI getUrl() { - return this.url; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final Map getCumulative() { + return this.cumulative; + } + + public final Map getRealtime() { + return this.realtime; + } + + public final String getTaskQueueSid() { + return this.taskQueueSid; + } + + public final String getWorkspaceSid() { + return this.workspaceSid; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -149,13 +151,25 @@ public boolean equals(final Object o) { TaskQueueStatistics other = (TaskQueueStatistics) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(cumulative, other.cumulative) && Objects.equals(realtime, other.realtime) && Objects.equals(taskQueueSid, other.taskQueueSid) && Objects.equals(workspaceSid, other.workspaceSid) && Objects.equals(url, other.url) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(cumulative, other.cumulative) && + Objects.equals(realtime, other.realtime) && + Objects.equals(taskQueueSid, other.taskQueueSid) && + Objects.equals(workspaceSid, other.workspaceSid) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, cumulative, realtime, taskQueueSid, workspaceSid, url); + return Objects.hash( + accountSid, + cumulative, + realtime, + taskQueueSid, + workspaceSid, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueueStatisticsFetcher.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueueStatisticsFetcher.java index f916917980..d8d8129ac5 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueueStatisticsFetcher.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueueStatisticsFetcher.java @@ -23,12 +23,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.time.ZonedDateTime; - - public class TaskQueueStatisticsFetcher extends Fetcher { + private String pathWorkspaceSid; private String pathTaskQueueSid; private ZonedDateTime endDate; @@ -37,38 +35,58 @@ public class TaskQueueStatisticsFetcher extends Fetcher { private String taskChannel; private String splitByWaitTime; - public TaskQueueStatisticsFetcher(final String pathWorkspaceSid, final String pathTaskQueueSid){ + public TaskQueueStatisticsFetcher( + final String pathWorkspaceSid, + final String pathTaskQueueSid + ) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathTaskQueueSid = pathTaskQueueSid; } - public TaskQueueStatisticsFetcher setEndDate(final ZonedDateTime endDate){ + public TaskQueueStatisticsFetcher setEndDate(final ZonedDateTime endDate) { this.endDate = endDate; return this; } - public TaskQueueStatisticsFetcher setMinutes(final Integer minutes){ + + public TaskQueueStatisticsFetcher setMinutes(final Integer minutes) { this.minutes = minutes; return this; } - public TaskQueueStatisticsFetcher setStartDate(final ZonedDateTime startDate){ + + public TaskQueueStatisticsFetcher setStartDate( + final ZonedDateTime startDate + ) { this.startDate = startDate; return this; } - public TaskQueueStatisticsFetcher setTaskChannel(final String taskChannel){ + + public TaskQueueStatisticsFetcher setTaskChannel(final String taskChannel) { this.taskChannel = taskChannel; return this; } - public TaskQueueStatisticsFetcher setSplitByWaitTime(final String splitByWaitTime){ + + public TaskQueueStatisticsFetcher setSplitByWaitTime( + final String splitByWaitTime + ) { this.splitByWaitTime = splitByWaitTime; return this; } @Override public TaskQueueStatistics fetch(final TwilioRestClient client) { - String path = "/v1/Workspaces/{WorkspaceSid}/TaskQueues/{TaskQueueSid}/Statistics"; + String path = + "/v1/Workspaces/{WorkspaceSid}/TaskQueues/{TaskQueueSid}/Statistics"; - path = path.replace("{"+"WorkspaceSid"+"}", this.pathWorkspaceSid.toString()); - path = path.replace("{"+"TaskQueueSid"+"}", this.pathTaskQueueSid.toString()); + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = + path.replace( + "{" + "TaskQueueSid" + "}", + this.pathTaskQueueSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -79,36 +97,45 @@ public TaskQueueStatistics fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("TaskQueueStatistics fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "TaskQueueStatistics fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return TaskQueueStatistics.fromJson(response.getStream(), client.getObjectMapper()); + return TaskQueueStatistics.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addQueryParams(final Request request) { if (endDate != null) { request.addQueryParam("EndDate", endDate.toInstant().toString()); } if (minutes != null) { - request.addQueryParam("Minutes", minutes.toString()); } if (startDate != null) { - request.addQueryParam("StartDate", startDate.toInstant().toString()); + request.addQueryParam( + "StartDate", + startDate.toInstant().toString() + ); } if (taskChannel != null) { - request.addQueryParam("TaskChannel", taskChannel); } if (splitByWaitTime != null) { - request.addQueryParam("SplitByWaitTime", splitByWaitTime); } } diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueuesStatistics.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueuesStatistics.java index 85fb5bfd53..e11fe3b88e 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueuesStatistics.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueuesStatistics.java @@ -22,37 +22,38 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class TaskQueuesStatistics extends Resource { + private static final long serialVersionUID = 167349245476595L; - public static TaskQueuesStatisticsReader reader(final String pathWorkspaceSid){ + public static TaskQueuesStatisticsReader reader( + final String pathWorkspaceSid + ) { return new TaskQueuesStatisticsReader(pathWorkspaceSid); } /** - * Converts a JSON String into a TaskQueuesStatistics object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return TaskQueuesStatistics object represented by the provided JSON - */ - public static TaskQueuesStatistics fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a TaskQueuesStatistics object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return TaskQueuesStatistics object represented by the provided JSON + */ + public static TaskQueuesStatistics fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, TaskQueuesStatistics.class); @@ -64,14 +65,17 @@ public static TaskQueuesStatistics fromJson(final String json, final ObjectMappe } /** - * Converts a JSON InputStream into a TaskQueuesStatistics object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return TaskQueuesStatistics object represented by the provided JSON - */ - public static TaskQueuesStatistics fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a TaskQueuesStatistics object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return TaskQueuesStatistics object represented by the provided JSON + */ + public static TaskQueuesStatistics fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, TaskQueuesStatistics.class); @@ -90,20 +94,11 @@ public static TaskQueuesStatistics fromJson(final InputStream json, final Object @JsonCreator private TaskQueuesStatistics( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("cumulative") - final Map cumulative, - - @JsonProperty("realtime") - final Map realtime, - - @JsonProperty("task_queue_sid") - final String taskQueueSid, - - @JsonProperty("workspace_sid") - final String workspaceSid + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("cumulative") final Map cumulative, + @JsonProperty("realtime") final Map realtime, + @JsonProperty("task_queue_sid") final String taskQueueSid, + @JsonProperty("workspace_sid") final String workspaceSid ) { this.accountSid = accountSid; this.cumulative = cumulative; @@ -112,25 +107,29 @@ private TaskQueuesStatistics( this.workspaceSid = workspaceSid; } - public final String getAccountSid() { - return this.accountSid; - } - public final Map getCumulative() { - return this.cumulative; - } - public final Map getRealtime() { - return this.realtime; - } - public final String getTaskQueueSid() { - return this.taskQueueSid; - } - public final String getWorkspaceSid() { - return this.workspaceSid; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final Map getCumulative() { + return this.cumulative; + } + + public final Map getRealtime() { + return this.realtime; + } + + public final String getTaskQueueSid() { + return this.taskQueueSid; + } + + public final String getWorkspaceSid() { + return this.workspaceSid; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -140,13 +139,23 @@ public boolean equals(final Object o) { TaskQueuesStatistics other = (TaskQueuesStatistics) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(cumulative, other.cumulative) && Objects.equals(realtime, other.realtime) && Objects.equals(taskQueueSid, other.taskQueueSid) && Objects.equals(workspaceSid, other.workspaceSid) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(cumulative, other.cumulative) && + Objects.equals(realtime, other.realtime) && + Objects.equals(taskQueueSid, other.taskQueueSid) && + Objects.equals(workspaceSid, other.workspaceSid) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, cumulative, realtime, taskQueueSid, workspaceSid); + return Objects.hash( + accountSid, + cumulative, + realtime, + taskQueueSid, + workspaceSid + ); } - } - diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueuesStatisticsReader.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueuesStatisticsReader.java index e6fd627d8c..fd5aa3bed0 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueuesStatisticsReader.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueuesStatisticsReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.taskrouter.v1.workspace.taskqueue; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,12 +25,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; import java.time.ZonedDateTime; - - public class TaskQueuesStatisticsReader extends Reader { + private String pathWorkspaceSid; private ZonedDateTime endDate; private String friendlyName; @@ -39,47 +38,65 @@ public class TaskQueuesStatisticsReader extends Reader { private String splitByWaitTime; private Integer pageSize; - public TaskQueuesStatisticsReader(final String pathWorkspaceSid){ + public TaskQueuesStatisticsReader(final String pathWorkspaceSid) { this.pathWorkspaceSid = pathWorkspaceSid; } - public TaskQueuesStatisticsReader setEndDate(final ZonedDateTime endDate){ + public TaskQueuesStatisticsReader setEndDate(final ZonedDateTime endDate) { this.endDate = endDate; return this; } - public TaskQueuesStatisticsReader setFriendlyName(final String friendlyName){ + + public TaskQueuesStatisticsReader setFriendlyName( + final String friendlyName + ) { this.friendlyName = friendlyName; return this; } - public TaskQueuesStatisticsReader setMinutes(final Integer minutes){ + + public TaskQueuesStatisticsReader setMinutes(final Integer minutes) { this.minutes = minutes; return this; } - public TaskQueuesStatisticsReader setStartDate(final ZonedDateTime startDate){ + + public TaskQueuesStatisticsReader setStartDate( + final ZonedDateTime startDate + ) { this.startDate = startDate; return this; } - public TaskQueuesStatisticsReader setTaskChannel(final String taskChannel){ + + public TaskQueuesStatisticsReader setTaskChannel(final String taskChannel) { this.taskChannel = taskChannel; return this; } - public TaskQueuesStatisticsReader setSplitByWaitTime(final String splitByWaitTime){ + + public TaskQueuesStatisticsReader setSplitByWaitTime( + final String splitByWaitTime + ) { this.splitByWaitTime = splitByWaitTime; return this; } - public TaskQueuesStatisticsReader setPageSize(final Integer pageSize){ + + public TaskQueuesStatisticsReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @Override - public ResourceSet read(final TwilioRestClient client) { + public ResourceSet read( + final TwilioRestClient client + ) { return new ResourceSet<>(this, client, firstPage(client)); } public Page firstPage(final TwilioRestClient client) { String path = "/v1/Workspaces/{WorkspaceSid}/TaskQueues/Statistics"; - path = path.replace("{"+"WorkspaceSid"+"}", this.pathWorkspaceSid.toString()); + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -91,13 +108,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("TaskQueuesStatistics read failed: Unable to connect to server"); + throw new ApiConnectionException( + "TaskQueuesStatistics read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -113,7 +138,10 @@ private Page pageForRequest(final TwilioRestClient client, } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.TASKROUTER.toString()) @@ -121,9 +149,11 @@ public Page previousPage(final Page return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.TASKROUTER.toString()) @@ -132,45 +162,44 @@ public Page nextPage(final Page page } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (endDate != null) { request.addQueryParam("EndDate", endDate.toInstant().toString()); } if (friendlyName != null) { - request.addQueryParam("FriendlyName", friendlyName); } if (minutes != null) { - request.addQueryParam("Minutes", minutes.toString()); } if (startDate != null) { - request.addQueryParam("StartDate", startDate.toInstant().toString()); + request.addQueryParam( + "StartDate", + startDate.toInstant().toString() + ); } if (taskChannel != null) { - request.addQueryParam("TaskChannel", taskChannel); } if (splitByWaitTime != null) { - request.addQueryParam("SplitByWaitTime", splitByWaitTime); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/Reservation.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/Reservation.java index 0cec0aee26..04a4770747 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/Reservation.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/Reservation.java @@ -24,47 +24,57 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Reservation extends Resource { + private static final long serialVersionUID = 88353198782173L; - public static ReservationFetcher fetcher(final String pathWorkspaceSid, final String pathWorkerSid, final String pathSid){ + public static ReservationFetcher fetcher( + final String pathWorkspaceSid, + final String pathWorkerSid, + final String pathSid + ) { return new ReservationFetcher(pathWorkspaceSid, pathWorkerSid, pathSid); } - public static ReservationReader reader(final String pathWorkspaceSid, final String pathWorkerSid){ + public static ReservationReader reader( + final String pathWorkspaceSid, + final String pathWorkerSid + ) { return new ReservationReader(pathWorkspaceSid, pathWorkerSid); } - public static ReservationUpdater updater(final String pathWorkspaceSid, final String pathWorkerSid, final String pathSid){ + public static ReservationUpdater updater( + final String pathWorkspaceSid, + final String pathWorkerSid, + final String pathSid + ) { return new ReservationUpdater(pathWorkspaceSid, pathWorkerSid, pathSid); } /** - * Converts a JSON String into a Reservation object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Reservation object represented by the provided JSON - */ - public static Reservation fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Reservation object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Reservation object represented by the provided JSON + */ + public static Reservation fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Reservation.class); @@ -76,14 +86,17 @@ public static Reservation fromJson(final String json, final ObjectMapper objectM } /** - * Converts a JSON InputStream into a Reservation object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Reservation object represented by the provided JSON - */ - public static Reservation fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Reservation object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Reservation object represented by the provided JSON + */ + public static Reservation fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Reservation.class); @@ -93,6 +106,7 @@ public static Reservation fromJson(final InputStream json, final ObjectMapper ob throw new ApiConnectionException(e.getMessage(), e); } } + public enum CallStatus { INITIATED("initiated"), RINGING("ringing"), @@ -114,6 +128,7 @@ public static CallStatus forValue(final String value) { return Promoter.enumFromString(value, CallStatus.values()); } } + public enum ConferenceEvent { START("start"), END("end"), @@ -138,6 +153,7 @@ public static ConferenceEvent forValue(final String value) { return Promoter.enumFromString(value, ConferenceEvent.values()); } } + public enum Status { PENDING("pending"), ACCEPTED("accepted"), @@ -178,38 +194,19 @@ public static Status forValue(final String value) { @JsonCreator private Reservation( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("reservation_status") - final Reservation.Status reservationStatus, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("task_sid") - final String taskSid, - - @JsonProperty("worker_name") - final String workerName, - - @JsonProperty("worker_sid") - final String workerSid, - - @JsonProperty("workspace_sid") - final String workspaceSid, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty( + "reservation_status" + ) final Reservation.Status reservationStatus, + @JsonProperty("sid") final String sid, + @JsonProperty("task_sid") final String taskSid, + @JsonProperty("worker_name") final String workerName, + @JsonProperty("worker_sid") final String workerSid, + @JsonProperty("workspace_sid") final String workspaceSid, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.accountSid = accountSid; this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); @@ -224,43 +221,53 @@ private Reservation( this.links = links; } - public final String getAccountSid() { - return this.accountSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final Reservation.Status getReservationStatus() { - return this.reservationStatus; - } - public final String getSid() { - return this.sid; - } - public final String getTaskSid() { - return this.taskSid; - } - public final String getWorkerName() { - return this.workerName; - } - public final String getWorkerSid() { - return this.workerSid; - } - public final String getWorkspaceSid() { - return this.workspaceSid; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final Reservation.Status getReservationStatus() { + return this.reservationStatus; + } + + public final String getSid() { + return this.sid; + } + + public final String getTaskSid() { + return this.taskSid; + } + + public final String getWorkerName() { + return this.workerName; + } + + public final String getWorkerSid() { + return this.workerSid; + } + + public final String getWorkspaceSid() { + return this.workspaceSid; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -270,13 +277,35 @@ public boolean equals(final Object o) { Reservation other = (Reservation) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(reservationStatus, other.reservationStatus) && Objects.equals(sid, other.sid) && Objects.equals(taskSid, other.taskSid) && Objects.equals(workerName, other.workerName) && Objects.equals(workerSid, other.workerSid) && Objects.equals(workspaceSid, other.workspaceSid) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(reservationStatus, other.reservationStatus) && + Objects.equals(sid, other.sid) && + Objects.equals(taskSid, other.taskSid) && + Objects.equals(workerName, other.workerName) && + Objects.equals(workerSid, other.workerSid) && + Objects.equals(workspaceSid, other.workspaceSid) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, dateCreated, dateUpdated, reservationStatus, sid, taskSid, workerName, workerSid, workspaceSid, url, links); + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + reservationStatus, + sid, + taskSid, + workerName, + workerSid, + workspaceSid, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/ReservationFetcher.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/ReservationFetcher.java index bc119a125a..6709a371ea 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/ReservationFetcher.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/ReservationFetcher.java @@ -24,28 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class ReservationFetcher extends Fetcher { + private String pathWorkspaceSid; private String pathWorkerSid; private String pathSid; - public ReservationFetcher(final String pathWorkspaceSid, final String pathWorkerSid, final String pathSid){ + public ReservationFetcher( + final String pathWorkspaceSid, + final String pathWorkerSid, + final String pathSid + ) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathWorkerSid = pathWorkerSid; this.pathSid = pathSid; } - @Override public Reservation fetch(final TwilioRestClient client) { - String path = "/v1/Workspaces/{WorkspaceSid}/Workers/{WorkerSid}/Reservations/{Sid}"; + String path = + "/v1/Workspaces/{WorkspaceSid}/Workers/{WorkerSid}/Reservations/{Sid}"; - path = path.replace("{"+"WorkspaceSid"+"}", this.pathWorkspaceSid.toString()); - path = path.replace("{"+"WorkerSid"+"}", this.pathWorkerSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = + path.replace( + "{" + "WorkerSid" + "}", + this.pathWorkerSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -55,15 +65,23 @@ public Reservation fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Reservation fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Reservation fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Reservation.fromJson(response.getStream(), client.getObjectMapper()); + return Reservation.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/ReservationReader.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/ReservationReader.java index 96d1771c20..dd19336fbd 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/ReservationReader.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/ReservationReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.taskrouter.v1.workspace.worker; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,26 +25,30 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class ReservationReader extends Reader { + private String pathWorkspaceSid; private String pathWorkerSid; private Reservation.Status reservationStatus; private Integer pageSize; - public ReservationReader(final String pathWorkspaceSid, final String pathWorkerSid){ + public ReservationReader( + final String pathWorkspaceSid, + final String pathWorkerSid + ) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathWorkerSid = pathWorkerSid; } - public ReservationReader setReservationStatus(final Reservation.Status reservationStatus){ + public ReservationReader setReservationStatus( + final Reservation.Status reservationStatus + ) { this.reservationStatus = reservationStatus; return this; } - public ReservationReader setPageSize(final Integer pageSize){ + + public ReservationReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -54,9 +59,18 @@ public ResourceSet read(final TwilioRestClient client) { } public Page firstPage(final TwilioRestClient client) { - String path = "/v1/Workspaces/{WorkspaceSid}/Workers/{WorkerSid}/Reservations"; - path = path.replace("{"+"WorkspaceSid"+"}", this.pathWorkspaceSid.toString()); - path = path.replace("{"+"WorkerSid"+"}", this.pathWorkerSid.toString()); + String path = + "/v1/Workspaces/{WorkspaceSid}/Workers/{WorkerSid}/Reservations"; + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = + path.replace( + "{" + "WorkerSid" + "}", + this.pathWorkerSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -68,13 +82,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Reservation read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Reservation read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -90,7 +112,10 @@ private Page pageForRequest(final TwilioRestClient client, final Re } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.TASKROUTER.toString()) @@ -98,9 +123,11 @@ public Page previousPage(final Page page, final Twilio return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.TASKROUTER.toString()) @@ -109,25 +136,27 @@ public Page nextPage(final Page page, final TwilioRest } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (reservationStatus != null) { - - request.addQueryParam("ReservationStatus", reservationStatus.toString()); + request.addQueryParam( + "ReservationStatus", + reservationStatus.toString() + ); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/ReservationUpdater.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/ReservationUpdater.java index 1763411c10..12f8179c52 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/ReservationUpdater.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/ReservationUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.taskrouter.v1.workspace.worker; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -24,13 +25,11 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.net.URI; - import java.util.List; +public class ReservationUpdater extends Updater { -public class ReservationUpdater extends Updater{ private String pathWorkspaceSid; private String pathWorkerSid; private String pathSid; @@ -87,510 +86,662 @@ public class ReservationUpdater extends Updater{ private Boolean endConferenceOnCustomerExit; private Boolean beepOnCustomerEntrance; - public ReservationUpdater(final String pathWorkspaceSid, final String pathWorkerSid, final String pathSid){ + public ReservationUpdater( + final String pathWorkspaceSid, + final String pathWorkerSid, + final String pathSid + ) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathWorkerSid = pathWorkerSid; this.pathSid = pathSid; } - public ReservationUpdater setIfMatch(final String ifMatch){ + public ReservationUpdater setIfMatch(final String ifMatch) { this.ifMatch = ifMatch; return this; } - public ReservationUpdater setReservationStatus(final Reservation.Status reservationStatus){ + + public ReservationUpdater setReservationStatus( + final Reservation.Status reservationStatus + ) { this.reservationStatus = reservationStatus; return this; } - public ReservationUpdater setWorkerActivitySid(final String workerActivitySid){ + + public ReservationUpdater setWorkerActivitySid( + final String workerActivitySid + ) { this.workerActivitySid = workerActivitySid; return this; } - public ReservationUpdater setInstruction(final String instruction){ + + public ReservationUpdater setInstruction(final String instruction) { this.instruction = instruction; return this; } - public ReservationUpdater setDequeuePostWorkActivitySid(final String dequeuePostWorkActivitySid){ + + public ReservationUpdater setDequeuePostWorkActivitySid( + final String dequeuePostWorkActivitySid + ) { this.dequeuePostWorkActivitySid = dequeuePostWorkActivitySid; return this; } - public ReservationUpdater setDequeueFrom(final String dequeueFrom){ + + public ReservationUpdater setDequeueFrom(final String dequeueFrom) { this.dequeueFrom = dequeueFrom; return this; } - public ReservationUpdater setDequeueRecord(final String dequeueRecord){ + + public ReservationUpdater setDequeueRecord(final String dequeueRecord) { this.dequeueRecord = dequeueRecord; return this; } - public ReservationUpdater setDequeueTimeout(final Integer dequeueTimeout){ + + public ReservationUpdater setDequeueTimeout(final Integer dequeueTimeout) { this.dequeueTimeout = dequeueTimeout; return this; } - public ReservationUpdater setDequeueTo(final String dequeueTo){ + + public ReservationUpdater setDequeueTo(final String dequeueTo) { this.dequeueTo = dequeueTo; return this; } - public ReservationUpdater setDequeueStatusCallbackUrl(final URI dequeueStatusCallbackUrl){ + + public ReservationUpdater setDequeueStatusCallbackUrl( + final URI dequeueStatusCallbackUrl + ) { this.dequeueStatusCallbackUrl = dequeueStatusCallbackUrl; return this; } - public ReservationUpdater setDequeueStatusCallbackUrl(final String dequeueStatusCallbackUrl){ - return setDequeueStatusCallbackUrl(Promoter.uriFromString(dequeueStatusCallbackUrl)); + public ReservationUpdater setDequeueStatusCallbackUrl( + final String dequeueStatusCallbackUrl + ) { + return setDequeueStatusCallbackUrl( + Promoter.uriFromString(dequeueStatusCallbackUrl) + ); } - public ReservationUpdater setCallFrom(final String callFrom){ + + public ReservationUpdater setCallFrom(final String callFrom) { this.callFrom = callFrom; return this; } - public ReservationUpdater setCallRecord(final String callRecord){ + + public ReservationUpdater setCallRecord(final String callRecord) { this.callRecord = callRecord; return this; } - public ReservationUpdater setCallTimeout(final Integer callTimeout){ + + public ReservationUpdater setCallTimeout(final Integer callTimeout) { this.callTimeout = callTimeout; return this; } - public ReservationUpdater setCallTo(final String callTo){ + + public ReservationUpdater setCallTo(final String callTo) { this.callTo = callTo; return this; } - public ReservationUpdater setCallUrl(final URI callUrl){ + + public ReservationUpdater setCallUrl(final URI callUrl) { this.callUrl = callUrl; return this; } - public ReservationUpdater setCallUrl(final String callUrl){ + public ReservationUpdater setCallUrl(final String callUrl) { return setCallUrl(Promoter.uriFromString(callUrl)); } - public ReservationUpdater setCallStatusCallbackUrl(final URI callStatusCallbackUrl){ + + public ReservationUpdater setCallStatusCallbackUrl( + final URI callStatusCallbackUrl + ) { this.callStatusCallbackUrl = callStatusCallbackUrl; return this; } - public ReservationUpdater setCallStatusCallbackUrl(final String callStatusCallbackUrl){ - return setCallStatusCallbackUrl(Promoter.uriFromString(callStatusCallbackUrl)); + public ReservationUpdater setCallStatusCallbackUrl( + final String callStatusCallbackUrl + ) { + return setCallStatusCallbackUrl( + Promoter.uriFromString(callStatusCallbackUrl) + ); } - public ReservationUpdater setCallAccept(final Boolean callAccept){ + + public ReservationUpdater setCallAccept(final Boolean callAccept) { this.callAccept = callAccept; return this; } - public ReservationUpdater setRedirectCallSid(final String redirectCallSid){ + + public ReservationUpdater setRedirectCallSid(final String redirectCallSid) { this.redirectCallSid = redirectCallSid; return this; } - public ReservationUpdater setRedirectAccept(final Boolean redirectAccept){ + + public ReservationUpdater setRedirectAccept(final Boolean redirectAccept) { this.redirectAccept = redirectAccept; return this; } - public ReservationUpdater setRedirectUrl(final URI redirectUrl){ + + public ReservationUpdater setRedirectUrl(final URI redirectUrl) { this.redirectUrl = redirectUrl; return this; } - public ReservationUpdater setRedirectUrl(final String redirectUrl){ + public ReservationUpdater setRedirectUrl(final String redirectUrl) { return setRedirectUrl(Promoter.uriFromString(redirectUrl)); } - public ReservationUpdater setTo(final String to){ + + public ReservationUpdater setTo(final String to) { this.to = to; return this; } - public ReservationUpdater setFrom(final String from){ + + public ReservationUpdater setFrom(final String from) { this.from = from; return this; } - public ReservationUpdater setStatusCallback(final URI statusCallback){ + + public ReservationUpdater setStatusCallback(final URI statusCallback) { this.statusCallback = statusCallback; return this; } - public ReservationUpdater setStatusCallback(final String statusCallback){ + public ReservationUpdater setStatusCallback(final String statusCallback) { return setStatusCallback(Promoter.uriFromString(statusCallback)); } - public ReservationUpdater setStatusCallbackMethod(final HttpMethod statusCallbackMethod){ + + public ReservationUpdater setStatusCallbackMethod( + final HttpMethod statusCallbackMethod + ) { this.statusCallbackMethod = statusCallbackMethod; return this; } - public ReservationUpdater setStatusCallbackEvent(final List statusCallbackEvent){ + + public ReservationUpdater setStatusCallbackEvent( + final List statusCallbackEvent + ) { this.statusCallbackEvent = statusCallbackEvent; return this; } - public ReservationUpdater setStatusCallbackEvent(final Reservation.CallStatus statusCallbackEvent){ + + public ReservationUpdater setStatusCallbackEvent( + final Reservation.CallStatus statusCallbackEvent + ) { return setStatusCallbackEvent(Promoter.listOfOne(statusCallbackEvent)); } - public ReservationUpdater setTimeout(final Integer timeout){ + + public ReservationUpdater setTimeout(final Integer timeout) { this.timeout = timeout; return this; } - public ReservationUpdater setRecord(final Boolean record){ + + public ReservationUpdater setRecord(final Boolean record) { this.record = record; return this; } - public ReservationUpdater setMuted(final Boolean muted){ + + public ReservationUpdater setMuted(final Boolean muted) { this.muted = muted; return this; } - public ReservationUpdater setBeep(final String beep){ + + public ReservationUpdater setBeep(final String beep) { this.beep = beep; return this; } - public ReservationUpdater setStartConferenceOnEnter(final Boolean startConferenceOnEnter){ + + public ReservationUpdater setStartConferenceOnEnter( + final Boolean startConferenceOnEnter + ) { this.startConferenceOnEnter = startConferenceOnEnter; return this; } - public ReservationUpdater setEndConferenceOnExit(final Boolean endConferenceOnExit){ + + public ReservationUpdater setEndConferenceOnExit( + final Boolean endConferenceOnExit + ) { this.endConferenceOnExit = endConferenceOnExit; return this; } - public ReservationUpdater setWaitUrl(final URI waitUrl){ + + public ReservationUpdater setWaitUrl(final URI waitUrl) { this.waitUrl = waitUrl; return this; } - public ReservationUpdater setWaitUrl(final String waitUrl){ + public ReservationUpdater setWaitUrl(final String waitUrl) { return setWaitUrl(Promoter.uriFromString(waitUrl)); } - public ReservationUpdater setWaitMethod(final HttpMethod waitMethod){ + + public ReservationUpdater setWaitMethod(final HttpMethod waitMethod) { this.waitMethod = waitMethod; return this; } - public ReservationUpdater setEarlyMedia(final Boolean earlyMedia){ + + public ReservationUpdater setEarlyMedia(final Boolean earlyMedia) { this.earlyMedia = earlyMedia; return this; } - public ReservationUpdater setMaxParticipants(final Integer maxParticipants){ + + public ReservationUpdater setMaxParticipants( + final Integer maxParticipants + ) { this.maxParticipants = maxParticipants; return this; } - public ReservationUpdater setConferenceStatusCallback(final URI conferenceStatusCallback){ + + public ReservationUpdater setConferenceStatusCallback( + final URI conferenceStatusCallback + ) { this.conferenceStatusCallback = conferenceStatusCallback; return this; } - public ReservationUpdater setConferenceStatusCallback(final String conferenceStatusCallback){ - return setConferenceStatusCallback(Promoter.uriFromString(conferenceStatusCallback)); + public ReservationUpdater setConferenceStatusCallback( + final String conferenceStatusCallback + ) { + return setConferenceStatusCallback( + Promoter.uriFromString(conferenceStatusCallback) + ); } - public ReservationUpdater setConferenceStatusCallbackMethod(final HttpMethod conferenceStatusCallbackMethod){ + + public ReservationUpdater setConferenceStatusCallbackMethod( + final HttpMethod conferenceStatusCallbackMethod + ) { this.conferenceStatusCallbackMethod = conferenceStatusCallbackMethod; return this; } - public ReservationUpdater setConferenceStatusCallbackEvent(final List conferenceStatusCallbackEvent){ + + public ReservationUpdater setConferenceStatusCallbackEvent( + final List conferenceStatusCallbackEvent + ) { this.conferenceStatusCallbackEvent = conferenceStatusCallbackEvent; return this; } - public ReservationUpdater setConferenceStatusCallbackEvent(final Reservation.ConferenceEvent conferenceStatusCallbackEvent){ - return setConferenceStatusCallbackEvent(Promoter.listOfOne(conferenceStatusCallbackEvent)); + + public ReservationUpdater setConferenceStatusCallbackEvent( + final Reservation.ConferenceEvent conferenceStatusCallbackEvent + ) { + return setConferenceStatusCallbackEvent( + Promoter.listOfOne(conferenceStatusCallbackEvent) + ); } - public ReservationUpdater setConferenceRecord(final String conferenceRecord){ + + public ReservationUpdater setConferenceRecord( + final String conferenceRecord + ) { this.conferenceRecord = conferenceRecord; return this; } - public ReservationUpdater setConferenceTrim(final String conferenceTrim){ + + public ReservationUpdater setConferenceTrim(final String conferenceTrim) { this.conferenceTrim = conferenceTrim; return this; } - public ReservationUpdater setRecordingChannels(final String recordingChannels){ + + public ReservationUpdater setRecordingChannels( + final String recordingChannels + ) { this.recordingChannels = recordingChannels; return this; } - public ReservationUpdater setRecordingStatusCallback(final URI recordingStatusCallback){ + + public ReservationUpdater setRecordingStatusCallback( + final URI recordingStatusCallback + ) { this.recordingStatusCallback = recordingStatusCallback; return this; } - public ReservationUpdater setRecordingStatusCallback(final String recordingStatusCallback){ - return setRecordingStatusCallback(Promoter.uriFromString(recordingStatusCallback)); + public ReservationUpdater setRecordingStatusCallback( + final String recordingStatusCallback + ) { + return setRecordingStatusCallback( + Promoter.uriFromString(recordingStatusCallback) + ); } - public ReservationUpdater setRecordingStatusCallbackMethod(final HttpMethod recordingStatusCallbackMethod){ + + public ReservationUpdater setRecordingStatusCallbackMethod( + final HttpMethod recordingStatusCallbackMethod + ) { this.recordingStatusCallbackMethod = recordingStatusCallbackMethod; return this; } - public ReservationUpdater setConferenceRecordingStatusCallback(final URI conferenceRecordingStatusCallback){ - this.conferenceRecordingStatusCallback = conferenceRecordingStatusCallback; + + public ReservationUpdater setConferenceRecordingStatusCallback( + final URI conferenceRecordingStatusCallback + ) { + this.conferenceRecordingStatusCallback = + conferenceRecordingStatusCallback; return this; } - public ReservationUpdater setConferenceRecordingStatusCallback(final String conferenceRecordingStatusCallback){ - return setConferenceRecordingStatusCallback(Promoter.uriFromString(conferenceRecordingStatusCallback)); + public ReservationUpdater setConferenceRecordingStatusCallback( + final String conferenceRecordingStatusCallback + ) { + return setConferenceRecordingStatusCallback( + Promoter.uriFromString(conferenceRecordingStatusCallback) + ); } - public ReservationUpdater setConferenceRecordingStatusCallbackMethod(final HttpMethod conferenceRecordingStatusCallbackMethod){ - this.conferenceRecordingStatusCallbackMethod = conferenceRecordingStatusCallbackMethod; + + public ReservationUpdater setConferenceRecordingStatusCallbackMethod( + final HttpMethod conferenceRecordingStatusCallbackMethod + ) { + this.conferenceRecordingStatusCallbackMethod = + conferenceRecordingStatusCallbackMethod; return this; } - public ReservationUpdater setRegion(final String region){ + + public ReservationUpdater setRegion(final String region) { this.region = region; return this; } - public ReservationUpdater setSipAuthUsername(final String sipAuthUsername){ + + public ReservationUpdater setSipAuthUsername(final String sipAuthUsername) { this.sipAuthUsername = sipAuthUsername; return this; } - public ReservationUpdater setSipAuthPassword(final String sipAuthPassword){ + + public ReservationUpdater setSipAuthPassword(final String sipAuthPassword) { this.sipAuthPassword = sipAuthPassword; return this; } - public ReservationUpdater setDequeueStatusCallbackEvent(final List dequeueStatusCallbackEvent){ + + public ReservationUpdater setDequeueStatusCallbackEvent( + final List dequeueStatusCallbackEvent + ) { this.dequeueStatusCallbackEvent = dequeueStatusCallbackEvent; return this; } - public ReservationUpdater setDequeueStatusCallbackEvent(final String dequeueStatusCallbackEvent){ - return setDequeueStatusCallbackEvent(Promoter.listOfOne(dequeueStatusCallbackEvent)); + + public ReservationUpdater setDequeueStatusCallbackEvent( + final String dequeueStatusCallbackEvent + ) { + return setDequeueStatusCallbackEvent( + Promoter.listOfOne(dequeueStatusCallbackEvent) + ); } - public ReservationUpdater setPostWorkActivitySid(final String postWorkActivitySid){ + + public ReservationUpdater setPostWorkActivitySid( + final String postWorkActivitySid + ) { this.postWorkActivitySid = postWorkActivitySid; return this; } - public ReservationUpdater setEndConferenceOnCustomerExit(final Boolean endConferenceOnCustomerExit){ + + public ReservationUpdater setEndConferenceOnCustomerExit( + final Boolean endConferenceOnCustomerExit + ) { this.endConferenceOnCustomerExit = endConferenceOnCustomerExit; return this; } - public ReservationUpdater setBeepOnCustomerEntrance(final Boolean beepOnCustomerEntrance){ + + public ReservationUpdater setBeepOnCustomerEntrance( + final Boolean beepOnCustomerEntrance + ) { this.beepOnCustomerEntrance = beepOnCustomerEntrance; return this; } @Override - public Reservation update(final TwilioRestClient client){ - String path = "/v1/Workspaces/{WorkspaceSid}/Workers/{WorkerSid}/Reservations/{Sid}"; + public Reservation update(final TwilioRestClient client) { + String path = + "/v1/Workspaces/{WorkspaceSid}/Workers/{WorkerSid}/Reservations/{Sid}"; - path = path.replace("{"+"WorkspaceSid"+"}", this.pathWorkspaceSid.toString()); - path = path.replace("{"+"WorkerSid"+"}", this.pathWorkerSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = + path.replace( + "{" + "WorkerSid" + "}", + this.pathWorkerSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.TASKROUTER.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); addHeaderParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Reservation update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Reservation update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Reservation.fromJson(response.getStream(), client.getObjectMapper()); + return Reservation.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (reservationStatus != null) { - request.addPostParam("ReservationStatus", reservationStatus.toString()); - + request.addPostParam( + "ReservationStatus", + reservationStatus.toString() + ); } if (workerActivitySid != null) { request.addPostParam("WorkerActivitySid", workerActivitySid); - } if (instruction != null) { request.addPostParam("Instruction", instruction); - } if (dequeuePostWorkActivitySid != null) { - request.addPostParam("DequeuePostWorkActivitySid", dequeuePostWorkActivitySid); - + request.addPostParam( + "DequeuePostWorkActivitySid", + dequeuePostWorkActivitySid + ); } if (dequeueFrom != null) { request.addPostParam("DequeueFrom", dequeueFrom); - } if (dequeueRecord != null) { request.addPostParam("DequeueRecord", dequeueRecord); - } if (dequeueTimeout != null) { request.addPostParam("DequeueTimeout", dequeueTimeout.toString()); - } if (dequeueTo != null) { request.addPostParam("DequeueTo", dequeueTo); - } if (dequeueStatusCallbackUrl != null) { - request.addPostParam("DequeueStatusCallbackUrl", dequeueStatusCallbackUrl.toString()); - + request.addPostParam( + "DequeueStatusCallbackUrl", + dequeueStatusCallbackUrl.toString() + ); } if (callFrom != null) { request.addPostParam("CallFrom", callFrom); - } if (callRecord != null) { request.addPostParam("CallRecord", callRecord); - } if (callTimeout != null) { request.addPostParam("CallTimeout", callTimeout.toString()); - } if (callTo != null) { request.addPostParam("CallTo", callTo); - } if (callUrl != null) { request.addPostParam("CallUrl", callUrl.toString()); - } if (callStatusCallbackUrl != null) { - request.addPostParam("CallStatusCallbackUrl", callStatusCallbackUrl.toString()); - + request.addPostParam( + "CallStatusCallbackUrl", + callStatusCallbackUrl.toString() + ); } if (callAccept != null) { request.addPostParam("CallAccept", callAccept.toString()); - } if (redirectCallSid != null) { request.addPostParam("RedirectCallSid", redirectCallSid); - } if (redirectAccept != null) { request.addPostParam("RedirectAccept", redirectAccept.toString()); - } if (redirectUrl != null) { request.addPostParam("RedirectUrl", redirectUrl.toString()); - } if (to != null) { request.addPostParam("To", to); - } if (from != null) { request.addPostParam("From", from); - } if (statusCallback != null) { request.addPostParam("StatusCallback", statusCallback.toString()); - } if (statusCallbackMethod != null) { - request.addPostParam("StatusCallbackMethod", statusCallbackMethod.toString()); - + request.addPostParam( + "StatusCallbackMethod", + statusCallbackMethod.toString() + ); } if (statusCallbackEvent != null) { for (Reservation.CallStatus prop : statusCallbackEvent) { request.addPostParam("StatusCallbackEvent", prop.toString()); } - } if (timeout != null) { request.addPostParam("Timeout", timeout.toString()); - } if (record != null) { request.addPostParam("Record", record.toString()); - } if (muted != null) { request.addPostParam("Muted", muted.toString()); - } if (beep != null) { request.addPostParam("Beep", beep); - } if (startConferenceOnEnter != null) { - request.addPostParam("StartConferenceOnEnter", startConferenceOnEnter.toString()); - + request.addPostParam( + "StartConferenceOnEnter", + startConferenceOnEnter.toString() + ); } if (endConferenceOnExit != null) { - request.addPostParam("EndConferenceOnExit", endConferenceOnExit.toString()); - + request.addPostParam( + "EndConferenceOnExit", + endConferenceOnExit.toString() + ); } if (waitUrl != null) { request.addPostParam("WaitUrl", waitUrl.toString()); - } if (waitMethod != null) { request.addPostParam("WaitMethod", waitMethod.toString()); - } if (earlyMedia != null) { request.addPostParam("EarlyMedia", earlyMedia.toString()); - } if (maxParticipants != null) { request.addPostParam("MaxParticipants", maxParticipants.toString()); - } if (conferenceStatusCallback != null) { - request.addPostParam("ConferenceStatusCallback", conferenceStatusCallback.toString()); - + request.addPostParam( + "ConferenceStatusCallback", + conferenceStatusCallback.toString() + ); } if (conferenceStatusCallbackMethod != null) { - request.addPostParam("ConferenceStatusCallbackMethod", conferenceStatusCallbackMethod.toString()); - + request.addPostParam( + "ConferenceStatusCallbackMethod", + conferenceStatusCallbackMethod.toString() + ); } if (conferenceStatusCallbackEvent != null) { for (Reservation.ConferenceEvent prop : conferenceStatusCallbackEvent) { - request.addPostParam("ConferenceStatusCallbackEvent", prop.toString()); + request.addPostParam( + "ConferenceStatusCallbackEvent", + prop.toString() + ); } - } if (conferenceRecord != null) { request.addPostParam("ConferenceRecord", conferenceRecord); - } if (conferenceTrim != null) { request.addPostParam("ConferenceTrim", conferenceTrim); - } if (recordingChannels != null) { request.addPostParam("RecordingChannels", recordingChannels); - } if (recordingStatusCallback != null) { - request.addPostParam("RecordingStatusCallback", recordingStatusCallback.toString()); - + request.addPostParam( + "RecordingStatusCallback", + recordingStatusCallback.toString() + ); } if (recordingStatusCallbackMethod != null) { - request.addPostParam("RecordingStatusCallbackMethod", recordingStatusCallbackMethod.toString()); - + request.addPostParam( + "RecordingStatusCallbackMethod", + recordingStatusCallbackMethod.toString() + ); } if (conferenceRecordingStatusCallback != null) { - request.addPostParam("ConferenceRecordingStatusCallback", conferenceRecordingStatusCallback.toString()); - + request.addPostParam( + "ConferenceRecordingStatusCallback", + conferenceRecordingStatusCallback.toString() + ); } if (conferenceRecordingStatusCallbackMethod != null) { - request.addPostParam("ConferenceRecordingStatusCallbackMethod", conferenceRecordingStatusCallbackMethod.toString()); - + request.addPostParam( + "ConferenceRecordingStatusCallbackMethod", + conferenceRecordingStatusCallbackMethod.toString() + ); } if (region != null) { request.addPostParam("Region", region); - } if (sipAuthUsername != null) { request.addPostParam("SipAuthUsername", sipAuthUsername); - } if (sipAuthPassword != null) { request.addPostParam("SipAuthPassword", sipAuthPassword); - } if (dequeueStatusCallbackEvent != null) { for (String prop : dequeueStatusCallbackEvent) { request.addPostParam("DequeueStatusCallbackEvent", prop); } - } if (postWorkActivitySid != null) { request.addPostParam("PostWorkActivitySid", postWorkActivitySid); - } if (endConferenceOnCustomerExit != null) { - request.addPostParam("EndConferenceOnCustomerExit", endConferenceOnCustomerExit.toString()); - + request.addPostParam( + "EndConferenceOnCustomerExit", + endConferenceOnCustomerExit.toString() + ); } if (beepOnCustomerEntrance != null) { - request.addPostParam("BeepOnCustomerEntrance", beepOnCustomerEntrance.toString()); - + request.addPostParam( + "BeepOnCustomerEntrance", + beepOnCustomerEntrance.toString() + ); } } + private void addHeaderParams(final Request request) { if (ifMatch != null) { request.addHeaderParam("If-Match", ifMatch); - } } } diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkerChannel.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkerChannel.java index 3215e2dca0..61728d5229 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkerChannel.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkerChannel.java @@ -23,45 +23,63 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class WorkerChannel extends Resource { + private static final long serialVersionUID = 38376318052081L; - public static WorkerChannelFetcher fetcher(final String pathWorkspaceSid, final String pathWorkerSid, final String pathSid){ - return new WorkerChannelFetcher(pathWorkspaceSid, pathWorkerSid, pathSid); + public static WorkerChannelFetcher fetcher( + final String pathWorkspaceSid, + final String pathWorkerSid, + final String pathSid + ) { + return new WorkerChannelFetcher( + pathWorkspaceSid, + pathWorkerSid, + pathSid + ); } - public static WorkerChannelReader reader(final String pathWorkspaceSid, final String pathWorkerSid){ + public static WorkerChannelReader reader( + final String pathWorkspaceSid, + final String pathWorkerSid + ) { return new WorkerChannelReader(pathWorkspaceSid, pathWorkerSid); } - public static WorkerChannelUpdater updater(final String pathWorkspaceSid, final String pathWorkerSid, final String pathSid){ - return new WorkerChannelUpdater(pathWorkspaceSid, pathWorkerSid, pathSid); + public static WorkerChannelUpdater updater( + final String pathWorkspaceSid, + final String pathWorkerSid, + final String pathSid + ) { + return new WorkerChannelUpdater( + pathWorkspaceSid, + pathWorkerSid, + pathSid + ); } /** - * Converts a JSON String into a WorkerChannel object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return WorkerChannel object represented by the provided JSON - */ - public static WorkerChannel fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a WorkerChannel object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return WorkerChannel object represented by the provided JSON + */ + public static WorkerChannel fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, WorkerChannel.class); @@ -73,14 +91,17 @@ public static WorkerChannel fromJson(final String json, final ObjectMapper objec } /** - * Converts a JSON InputStream into a WorkerChannel object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return WorkerChannel object represented by the provided JSON - */ - public static WorkerChannel fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a WorkerChannel object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return WorkerChannel object represented by the provided JSON + */ + public static WorkerChannel fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, WorkerChannel.class); @@ -107,44 +128,23 @@ public static WorkerChannel fromJson(final InputStream json, final ObjectMapper @JsonCreator private WorkerChannel( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("assigned_tasks") - final Integer assignedTasks, - - @JsonProperty("available") - final Boolean available, - - @JsonProperty("available_capacity_percentage") - final Integer availableCapacityPercentage, - - @JsonProperty("configured_capacity") - final Integer configuredCapacity, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("task_channel_sid") - final String taskChannelSid, - - @JsonProperty("task_channel_unique_name") - final String taskChannelUniqueName, - - @JsonProperty("worker_sid") - final String workerSid, - - @JsonProperty("workspace_sid") - final String workspaceSid, - - @JsonProperty("url") - final URI url + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("assigned_tasks") final Integer assignedTasks, + @JsonProperty("available") final Boolean available, + @JsonProperty( + "available_capacity_percentage" + ) final Integer availableCapacityPercentage, + @JsonProperty("configured_capacity") final Integer configuredCapacity, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("sid") final String sid, + @JsonProperty("task_channel_sid") final String taskChannelSid, + @JsonProperty( + "task_channel_unique_name" + ) final String taskChannelUniqueName, + @JsonProperty("worker_sid") final String workerSid, + @JsonProperty("workspace_sid") final String workspaceSid, + @JsonProperty("url") final URI url ) { this.accountSid = accountSid; this.assignedTasks = assignedTasks; @@ -161,49 +161,61 @@ private WorkerChannel( this.url = url; } - public final String getAccountSid() { - return this.accountSid; - } - public final Integer getAssignedTasks() { - return this.assignedTasks; - } - public final Boolean getAvailable() { - return this.available; - } - public final Integer getAvailableCapacityPercentage() { - return this.availableCapacityPercentage; - } - public final Integer getConfiguredCapacity() { - return this.configuredCapacity; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getSid() { - return this.sid; - } - public final String getTaskChannelSid() { - return this.taskChannelSid; - } - public final String getTaskChannelUniqueName() { - return this.taskChannelUniqueName; - } - public final String getWorkerSid() { - return this.workerSid; - } - public final String getWorkspaceSid() { - return this.workspaceSid; - } - public final URI getUrl() { - return this.url; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final Integer getAssignedTasks() { + return this.assignedTasks; + } + + public final Boolean getAvailable() { + return this.available; + } + + public final Integer getAvailableCapacityPercentage() { + return this.availableCapacityPercentage; + } + + public final Integer getConfiguredCapacity() { + return this.configuredCapacity; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getSid() { + return this.sid; + } + + public final String getTaskChannelSid() { + return this.taskChannelSid; + } + + public final String getTaskChannelUniqueName() { + return this.taskChannelUniqueName; + } + + public final String getWorkerSid() { + return this.workerSid; + } + + public final String getWorkspaceSid() { + return this.workspaceSid; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -213,13 +225,45 @@ public boolean equals(final Object o) { WorkerChannel other = (WorkerChannel) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(assignedTasks, other.assignedTasks) && Objects.equals(available, other.available) && Objects.equals(availableCapacityPercentage, other.availableCapacityPercentage) && Objects.equals(configuredCapacity, other.configuredCapacity) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(sid, other.sid) && Objects.equals(taskChannelSid, other.taskChannelSid) && Objects.equals(taskChannelUniqueName, other.taskChannelUniqueName) && Objects.equals(workerSid, other.workerSid) && Objects.equals(workspaceSid, other.workspaceSid) && Objects.equals(url, other.url) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(assignedTasks, other.assignedTasks) && + Objects.equals(available, other.available) && + Objects.equals( + availableCapacityPercentage, + other.availableCapacityPercentage + ) && + Objects.equals(configuredCapacity, other.configuredCapacity) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(sid, other.sid) && + Objects.equals(taskChannelSid, other.taskChannelSid) && + Objects.equals( + taskChannelUniqueName, + other.taskChannelUniqueName + ) && + Objects.equals(workerSid, other.workerSid) && + Objects.equals(workspaceSid, other.workspaceSid) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, assignedTasks, available, availableCapacityPercentage, configuredCapacity, dateCreated, dateUpdated, sid, taskChannelSid, taskChannelUniqueName, workerSid, workspaceSid, url); + return Objects.hash( + accountSid, + assignedTasks, + available, + availableCapacityPercentage, + configuredCapacity, + dateCreated, + dateUpdated, + sid, + taskChannelSid, + taskChannelUniqueName, + workerSid, + workspaceSid, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkerChannelFetcher.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkerChannelFetcher.java index a00a9f9ebb..399e0e137b 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkerChannelFetcher.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkerChannelFetcher.java @@ -24,28 +24,38 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class WorkerChannelFetcher extends Fetcher { + private String pathWorkspaceSid; private String pathWorkerSid; private String pathSid; - public WorkerChannelFetcher(final String pathWorkspaceSid, final String pathWorkerSid, final String pathSid){ + public WorkerChannelFetcher( + final String pathWorkspaceSid, + final String pathWorkerSid, + final String pathSid + ) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathWorkerSid = pathWorkerSid; this.pathSid = pathSid; } - @Override public WorkerChannel fetch(final TwilioRestClient client) { - String path = "/v1/Workspaces/{WorkspaceSid}/Workers/{WorkerSid}/Channels/{Sid}"; + String path = + "/v1/Workspaces/{WorkspaceSid}/Workers/{WorkerSid}/Channels/{Sid}"; - path = path.replace("{"+"WorkspaceSid"+"}", this.pathWorkspaceSid.toString()); - path = path.replace("{"+"WorkerSid"+"}", this.pathWorkerSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = + path.replace( + "{" + "WorkerSid" + "}", + this.pathWorkerSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -55,15 +65,23 @@ public WorkerChannel fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("WorkerChannel fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "WorkerChannel fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return WorkerChannel.fromJson(response.getStream(), client.getObjectMapper()); + return WorkerChannel.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkerChannelReader.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkerChannelReader.java index 7c2755e7f8..5ebebf7f24 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkerChannelReader.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkerChannelReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.taskrouter.v1.workspace.worker; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,21 +25,22 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class WorkerChannelReader extends Reader { + private String pathWorkspaceSid; private String pathWorkerSid; private Integer pageSize; - public WorkerChannelReader(final String pathWorkspaceSid, final String pathWorkerSid){ + public WorkerChannelReader( + final String pathWorkspaceSid, + final String pathWorkerSid + ) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathWorkerSid = pathWorkerSid; } - public WorkerChannelReader setPageSize(final Integer pageSize){ + public WorkerChannelReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -49,9 +51,18 @@ public ResourceSet read(final TwilioRestClient client) { } public Page firstPage(final TwilioRestClient client) { - String path = "/v1/Workspaces/{WorkspaceSid}/Workers/{WorkerSid}/Channels"; - path = path.replace("{"+"WorkspaceSid"+"}", this.pathWorkspaceSid.toString()); - path = path.replace("{"+"WorkerSid"+"}", this.pathWorkerSid.toString()); + String path = + "/v1/Workspaces/{WorkspaceSid}/Workers/{WorkerSid}/Channels"; + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = + path.replace( + "{" + "WorkerSid" + "}", + this.pathWorkerSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -63,13 +74,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("WorkerChannel read failed: Unable to connect to server"); + throw new ApiConnectionException( + "WorkerChannel read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -85,7 +104,10 @@ private Page pageForRequest(final TwilioRestClient client, final } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.TASKROUTER.toString()) @@ -93,9 +115,11 @@ public Page previousPage(final Page page, final Tw return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.TASKROUTER.toString()) @@ -104,21 +128,21 @@ public Page nextPage(final Page page, final Twilio } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkerChannelUpdater.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkerChannelUpdater.java index c78829aa92..217d5d252f 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkerChannelUpdater.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkerChannelUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.taskrouter.v1.workspace.worker; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,66 +25,86 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class WorkerChannelUpdater extends Updater { - - -public class WorkerChannelUpdater extends Updater{ private String pathWorkspaceSid; private String pathWorkerSid; private String pathSid; private Integer capacity; private Boolean available; - public WorkerChannelUpdater(final String pathWorkspaceSid, final String pathWorkerSid, final String pathSid){ + public WorkerChannelUpdater( + final String pathWorkspaceSid, + final String pathWorkerSid, + final String pathSid + ) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathWorkerSid = pathWorkerSid; this.pathSid = pathSid; } - public WorkerChannelUpdater setCapacity(final Integer capacity){ + public WorkerChannelUpdater setCapacity(final Integer capacity) { this.capacity = capacity; return this; } - public WorkerChannelUpdater setAvailable(final Boolean available){ + + public WorkerChannelUpdater setAvailable(final Boolean available) { this.available = available; return this; } @Override - public WorkerChannel update(final TwilioRestClient client){ - String path = "/v1/Workspaces/{WorkspaceSid}/Workers/{WorkerSid}/Channels/{Sid}"; + public WorkerChannel update(final TwilioRestClient client) { + String path = + "/v1/Workspaces/{WorkspaceSid}/Workers/{WorkerSid}/Channels/{Sid}"; - path = path.replace("{"+"WorkspaceSid"+"}", this.pathWorkspaceSid.toString()); - path = path.replace("{"+"WorkerSid"+"}", this.pathWorkerSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = + path.replace( + "{" + "WorkerSid" + "}", + this.pathWorkerSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.TASKROUTER.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("WorkerChannel update failed: Unable to connect to server"); + throw new ApiConnectionException( + "WorkerChannel update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return WorkerChannel.fromJson(response.getStream(), client.getObjectMapper()); + return WorkerChannel.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (capacity != null) { request.addPostParam("Capacity", capacity.toString()); - } if (available != null) { request.addPostParam("Available", available.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkerStatistics.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkerStatistics.java index 7be0c242eb..d2ab882d7d 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkerStatistics.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkerStatistics.java @@ -22,38 +22,40 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class WorkerStatistics extends Resource { + private static final long serialVersionUID = 54379371741662L; - public static WorkerStatisticsFetcher fetcher(final String pathWorkspaceSid, final String pathWorkerSid){ + public static WorkerStatisticsFetcher fetcher( + final String pathWorkspaceSid, + final String pathWorkerSid + ) { return new WorkerStatisticsFetcher(pathWorkspaceSid, pathWorkerSid); } /** - * Converts a JSON String into a WorkerStatistics object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return WorkerStatistics object represented by the provided JSON - */ - public static WorkerStatistics fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a WorkerStatistics object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return WorkerStatistics object represented by the provided JSON + */ + public static WorkerStatistics fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, WorkerStatistics.class); @@ -65,14 +67,17 @@ public static WorkerStatistics fromJson(final String json, final ObjectMapper ob } /** - * Converts a JSON InputStream into a WorkerStatistics object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return WorkerStatistics object represented by the provided JSON - */ - public static WorkerStatistics fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a WorkerStatistics object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return WorkerStatistics object represented by the provided JSON + */ + public static WorkerStatistics fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, WorkerStatistics.class); @@ -91,20 +96,11 @@ public static WorkerStatistics fromJson(final InputStream json, final ObjectMapp @JsonCreator private WorkerStatistics( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("cumulative") - final Map cumulative, - - @JsonProperty("worker_sid") - final String workerSid, - - @JsonProperty("workspace_sid") - final String workspaceSid, - - @JsonProperty("url") - final URI url + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("cumulative") final Map cumulative, + @JsonProperty("worker_sid") final String workerSid, + @JsonProperty("workspace_sid") final String workspaceSid, + @JsonProperty("url") final URI url ) { this.accountSid = accountSid; this.cumulative = cumulative; @@ -113,25 +109,29 @@ private WorkerStatistics( this.url = url; } - public final String getAccountSid() { - return this.accountSid; - } - public final Map getCumulative() { - return this.cumulative; - } - public final String getWorkerSid() { - return this.workerSid; - } - public final String getWorkspaceSid() { - return this.workspaceSid; - } - public final URI getUrl() { - return this.url; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final Map getCumulative() { + return this.cumulative; + } + + public final String getWorkerSid() { + return this.workerSid; + } + + public final String getWorkspaceSid() { + return this.workspaceSid; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -141,13 +141,23 @@ public boolean equals(final Object o) { WorkerStatistics other = (WorkerStatistics) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(cumulative, other.cumulative) && Objects.equals(workerSid, other.workerSid) && Objects.equals(workspaceSid, other.workspaceSid) && Objects.equals(url, other.url) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(cumulative, other.cumulative) && + Objects.equals(workerSid, other.workerSid) && + Objects.equals(workspaceSid, other.workspaceSid) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, cumulative, workerSid, workspaceSid, url); + return Objects.hash( + accountSid, + cumulative, + workerSid, + workspaceSid, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkerStatisticsFetcher.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkerStatisticsFetcher.java index 2b0689d53e..8ed04c5d74 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkerStatisticsFetcher.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkerStatisticsFetcher.java @@ -23,12 +23,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.time.ZonedDateTime; - - public class WorkerStatisticsFetcher extends Fetcher { + private String pathWorkspaceSid; private String pathWorkerSid; private Integer minutes; @@ -36,34 +34,49 @@ public class WorkerStatisticsFetcher extends Fetcher { private ZonedDateTime endDate; private String taskChannel; - public WorkerStatisticsFetcher(final String pathWorkspaceSid, final String pathWorkerSid){ + public WorkerStatisticsFetcher( + final String pathWorkspaceSid, + final String pathWorkerSid + ) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathWorkerSid = pathWorkerSid; } - public WorkerStatisticsFetcher setMinutes(final Integer minutes){ + public WorkerStatisticsFetcher setMinutes(final Integer minutes) { this.minutes = minutes; return this; } - public WorkerStatisticsFetcher setStartDate(final ZonedDateTime startDate){ + + public WorkerStatisticsFetcher setStartDate(final ZonedDateTime startDate) { this.startDate = startDate; return this; } - public WorkerStatisticsFetcher setEndDate(final ZonedDateTime endDate){ + + public WorkerStatisticsFetcher setEndDate(final ZonedDateTime endDate) { this.endDate = endDate; return this; } - public WorkerStatisticsFetcher setTaskChannel(final String taskChannel){ + + public WorkerStatisticsFetcher setTaskChannel(final String taskChannel) { this.taskChannel = taskChannel; return this; } @Override public WorkerStatistics fetch(final TwilioRestClient client) { - String path = "/v1/Workspaces/{WorkspaceSid}/Workers/{WorkerSid}/Statistics"; + String path = + "/v1/Workspaces/{WorkspaceSid}/Workers/{WorkerSid}/Statistics"; - path = path.replace("{"+"WorkspaceSid"+"}", this.pathWorkspaceSid.toString()); - path = path.replace("{"+"WorkerSid"+"}", this.pathWorkerSid.toString()); + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = + path.replace( + "{" + "WorkerSid" + "}", + this.pathWorkerSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -74,24 +87,35 @@ public WorkerStatistics fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("WorkerStatistics fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "WorkerStatistics fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return WorkerStatistics.fromJson(response.getStream(), client.getObjectMapper()); + return WorkerStatistics.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addQueryParams(final Request request) { if (minutes != null) { - request.addQueryParam("Minutes", minutes.toString()); } if (startDate != null) { - request.addQueryParam("StartDate", startDate.toInstant().toString()); + request.addQueryParam( + "StartDate", + startDate.toInstant().toString() + ); } if (endDate != null) { @@ -99,7 +123,6 @@ private void addQueryParams(final Request request) { } if (taskChannel != null) { - request.addQueryParam("TaskChannel", taskChannel); } } diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkersCumulativeStatistics.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkersCumulativeStatistics.java index 52de6157aa..0fdc8a9066 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkersCumulativeStatistics.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkersCumulativeStatistics.java @@ -23,43 +23,47 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.List; import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class WorkersCumulativeStatistics extends Resource { + private static final long serialVersionUID = 68159864681377L; - public static WorkersCumulativeStatisticsFetcher fetcher(final String pathWorkspaceSid){ + public static WorkersCumulativeStatisticsFetcher fetcher( + final String pathWorkspaceSid + ) { return new WorkersCumulativeStatisticsFetcher(pathWorkspaceSid); } /** - * Converts a JSON String into a WorkersCumulativeStatistics object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return WorkersCumulativeStatistics object represented by the provided JSON - */ - public static WorkersCumulativeStatistics fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a WorkersCumulativeStatistics object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return WorkersCumulativeStatistics object represented by the provided JSON + */ + public static WorkersCumulativeStatistics fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, WorkersCumulativeStatistics.class); + return objectMapper.readValue( + json, + WorkersCumulativeStatistics.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -68,17 +72,23 @@ public static WorkersCumulativeStatistics fromJson(final String json, final Obje } /** - * Converts a JSON InputStream into a WorkersCumulativeStatistics object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return WorkersCumulativeStatistics object represented by the provided JSON - */ - public static WorkersCumulativeStatistics fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a WorkersCumulativeStatistics object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return WorkersCumulativeStatistics object represented by the provided JSON + */ + public static WorkersCumulativeStatistics fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, WorkersCumulativeStatistics.class); + return objectMapper.readValue( + json, + WorkersCumulativeStatistics.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -101,41 +111,30 @@ public static WorkersCumulativeStatistics fromJson(final InputStream json, final @JsonCreator private WorkersCumulativeStatistics( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("start_time") - final String startTime, - - @JsonProperty("end_time") - final String endTime, - - @JsonProperty("activity_durations") - final List> activityDurations, - - @JsonProperty("reservations_created") - final Integer reservationsCreated, - - @JsonProperty("reservations_accepted") - final Integer reservationsAccepted, - - @JsonProperty("reservations_rejected") - final Integer reservationsRejected, - - @JsonProperty("reservations_timed_out") - final Integer reservationsTimedOut, - - @JsonProperty("reservations_canceled") - final Integer reservationsCanceled, - - @JsonProperty("reservations_rescinded") - final Integer reservationsRescinded, - - @JsonProperty("workspace_sid") - final String workspaceSid, - - @JsonProperty("url") - final URI url + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("start_time") final String startTime, + @JsonProperty("end_time") final String endTime, + @JsonProperty( + "activity_durations" + ) final List> activityDurations, + @JsonProperty("reservations_created") final Integer reservationsCreated, + @JsonProperty( + "reservations_accepted" + ) final Integer reservationsAccepted, + @JsonProperty( + "reservations_rejected" + ) final Integer reservationsRejected, + @JsonProperty( + "reservations_timed_out" + ) final Integer reservationsTimedOut, + @JsonProperty( + "reservations_canceled" + ) final Integer reservationsCanceled, + @JsonProperty( + "reservations_rescinded" + ) final Integer reservationsRescinded, + @JsonProperty("workspace_sid") final String workspaceSid, + @JsonProperty("url") final URI url ) { this.accountSid = accountSid; this.startTime = DateConverter.iso8601DateTimeFromString(startTime); @@ -151,46 +150,57 @@ private WorkersCumulativeStatistics( this.url = url; } - public final String getAccountSid() { - return this.accountSid; - } - public final ZonedDateTime getStartTime() { - return this.startTime; - } - public final ZonedDateTime getEndTime() { - return this.endTime; - } - public final List> getActivityDurations() { - return this.activityDurations; - } - public final Integer getReservationsCreated() { - return this.reservationsCreated; - } - public final Integer getReservationsAccepted() { - return this.reservationsAccepted; - } - public final Integer getReservationsRejected() { - return this.reservationsRejected; - } - public final Integer getReservationsTimedOut() { - return this.reservationsTimedOut; - } - public final Integer getReservationsCanceled() { - return this.reservationsCanceled; - } - public final Integer getReservationsRescinded() { - return this.reservationsRescinded; - } - public final String getWorkspaceSid() { - return this.workspaceSid; - } - public final URI getUrl() { - return this.url; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final ZonedDateTime getStartTime() { + return this.startTime; + } + + public final ZonedDateTime getEndTime() { + return this.endTime; + } + + public final List> getActivityDurations() { + return this.activityDurations; + } + + public final Integer getReservationsCreated() { + return this.reservationsCreated; + } + + public final Integer getReservationsAccepted() { + return this.reservationsAccepted; + } + + public final Integer getReservationsRejected() { + return this.reservationsRejected; + } + + public final Integer getReservationsTimedOut() { + return this.reservationsTimedOut; + } + + public final Integer getReservationsCanceled() { + return this.reservationsCanceled; + } + + public final Integer getReservationsRescinded() { + return this.reservationsRescinded; + } + + public final String getWorkspaceSid() { + return this.workspaceSid; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -200,13 +210,40 @@ public boolean equals(final Object o) { WorkersCumulativeStatistics other = (WorkersCumulativeStatistics) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(startTime, other.startTime) && Objects.equals(endTime, other.endTime) && Objects.equals(activityDurations, other.activityDurations) && Objects.equals(reservationsCreated, other.reservationsCreated) && Objects.equals(reservationsAccepted, other.reservationsAccepted) && Objects.equals(reservationsRejected, other.reservationsRejected) && Objects.equals(reservationsTimedOut, other.reservationsTimedOut) && Objects.equals(reservationsCanceled, other.reservationsCanceled) && Objects.equals(reservationsRescinded, other.reservationsRescinded) && Objects.equals(workspaceSid, other.workspaceSid) && Objects.equals(url, other.url) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(startTime, other.startTime) && + Objects.equals(endTime, other.endTime) && + Objects.equals(activityDurations, other.activityDurations) && + Objects.equals(reservationsCreated, other.reservationsCreated) && + Objects.equals(reservationsAccepted, other.reservationsAccepted) && + Objects.equals(reservationsRejected, other.reservationsRejected) && + Objects.equals(reservationsTimedOut, other.reservationsTimedOut) && + Objects.equals(reservationsCanceled, other.reservationsCanceled) && + Objects.equals( + reservationsRescinded, + other.reservationsRescinded + ) && + Objects.equals(workspaceSid, other.workspaceSid) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, startTime, endTime, activityDurations, reservationsCreated, reservationsAccepted, reservationsRejected, reservationsTimedOut, reservationsCanceled, reservationsRescinded, workspaceSid, url); + return Objects.hash( + accountSid, + startTime, + endTime, + activityDurations, + reservationsCreated, + reservationsAccepted, + reservationsRejected, + reservationsTimedOut, + reservationsCanceled, + reservationsRescinded, + workspaceSid, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkersCumulativeStatisticsFetcher.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkersCumulativeStatisticsFetcher.java index 8b7116b977..6483923c81 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkersCumulativeStatisticsFetcher.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkersCumulativeStatisticsFetcher.java @@ -23,44 +23,59 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.time.ZonedDateTime; +public class WorkersCumulativeStatisticsFetcher + extends Fetcher { - -public class WorkersCumulativeStatisticsFetcher extends Fetcher { private String pathWorkspaceSid; private ZonedDateTime endDate; private Integer minutes; private ZonedDateTime startDate; private String taskChannel; - public WorkersCumulativeStatisticsFetcher(final String pathWorkspaceSid){ + public WorkersCumulativeStatisticsFetcher(final String pathWorkspaceSid) { this.pathWorkspaceSid = pathWorkspaceSid; } - public WorkersCumulativeStatisticsFetcher setEndDate(final ZonedDateTime endDate){ + public WorkersCumulativeStatisticsFetcher setEndDate( + final ZonedDateTime endDate + ) { this.endDate = endDate; return this; } - public WorkersCumulativeStatisticsFetcher setMinutes(final Integer minutes){ + + public WorkersCumulativeStatisticsFetcher setMinutes( + final Integer minutes + ) { this.minutes = minutes; return this; } - public WorkersCumulativeStatisticsFetcher setStartDate(final ZonedDateTime startDate){ + + public WorkersCumulativeStatisticsFetcher setStartDate( + final ZonedDateTime startDate + ) { this.startDate = startDate; return this; } - public WorkersCumulativeStatisticsFetcher setTaskChannel(final String taskChannel){ + + public WorkersCumulativeStatisticsFetcher setTaskChannel( + final String taskChannel + ) { this.taskChannel = taskChannel; return this; } @Override public WorkersCumulativeStatistics fetch(final TwilioRestClient client) { - String path = "/v1/Workspaces/{WorkspaceSid}/Workers/CumulativeStatistics"; + String path = + "/v1/Workspaces/{WorkspaceSid}/Workers/CumulativeStatistics"; - path = path.replace("{"+"WorkspaceSid"+"}", this.pathWorkspaceSid.toString()); + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -71,32 +86,42 @@ public WorkersCumulativeStatistics fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("WorkersCumulativeStatistics fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "WorkersCumulativeStatistics fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return WorkersCumulativeStatistics.fromJson(response.getStream(), client.getObjectMapper()); + return WorkersCumulativeStatistics.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addQueryParams(final Request request) { if (endDate != null) { request.addQueryParam("EndDate", endDate.toInstant().toString()); } if (minutes != null) { - request.addQueryParam("Minutes", minutes.toString()); } if (startDate != null) { - request.addQueryParam("StartDate", startDate.toInstant().toString()); + request.addQueryParam( + "StartDate", + startDate.toInstant().toString() + ); } if (taskChannel != null) { - request.addQueryParam("TaskChannel", taskChannel); } } diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkersRealTimeStatistics.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkersRealTimeStatistics.java index 5d7ad23782..5105811502 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkersRealTimeStatistics.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkersRealTimeStatistics.java @@ -22,42 +22,46 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.List; import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class WorkersRealTimeStatistics extends Resource { + private static final long serialVersionUID = 209947407394347L; - public static WorkersRealTimeStatisticsFetcher fetcher(final String pathWorkspaceSid){ + public static WorkersRealTimeStatisticsFetcher fetcher( + final String pathWorkspaceSid + ) { return new WorkersRealTimeStatisticsFetcher(pathWorkspaceSid); } /** - * Converts a JSON String into a WorkersRealTimeStatistics object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return WorkersRealTimeStatistics object represented by the provided JSON - */ - public static WorkersRealTimeStatistics fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a WorkersRealTimeStatistics object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return WorkersRealTimeStatistics object represented by the provided JSON + */ + public static WorkersRealTimeStatistics fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, WorkersRealTimeStatistics.class); + return objectMapper.readValue( + json, + WorkersRealTimeStatistics.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -66,17 +70,23 @@ public static WorkersRealTimeStatistics fromJson(final String json, final Object } /** - * Converts a JSON InputStream into a WorkersRealTimeStatistics object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return WorkersRealTimeStatistics object represented by the provided JSON - */ - public static WorkersRealTimeStatistics fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a WorkersRealTimeStatistics object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return WorkersRealTimeStatistics object represented by the provided JSON + */ + public static WorkersRealTimeStatistics fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, WorkersRealTimeStatistics.class); + return objectMapper.readValue( + json, + WorkersRealTimeStatistics.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -92,20 +102,13 @@ public static WorkersRealTimeStatistics fromJson(final InputStream json, final O @JsonCreator private WorkersRealTimeStatistics( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("activity_statistics") - final List> activityStatistics, - - @JsonProperty("total_workers") - final Integer totalWorkers, - - @JsonProperty("workspace_sid") - final String workspaceSid, - - @JsonProperty("url") - final URI url + @JsonProperty("account_sid") final String accountSid, + @JsonProperty( + "activity_statistics" + ) final List> activityStatistics, + @JsonProperty("total_workers") final Integer totalWorkers, + @JsonProperty("workspace_sid") final String workspaceSid, + @JsonProperty("url") final URI url ) { this.accountSid = accountSid; this.activityStatistics = activityStatistics; @@ -114,25 +117,29 @@ private WorkersRealTimeStatistics( this.url = url; } - public final String getAccountSid() { - return this.accountSid; - } - public final List> getActivityStatistics() { - return this.activityStatistics; - } - public final Integer getTotalWorkers() { - return this.totalWorkers; - } - public final String getWorkspaceSid() { - return this.workspaceSid; - } - public final URI getUrl() { - return this.url; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final List> getActivityStatistics() { + return this.activityStatistics; + } + + public final Integer getTotalWorkers() { + return this.totalWorkers; + } + + public final String getWorkspaceSid() { + return this.workspaceSid; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -142,13 +149,23 @@ public boolean equals(final Object o) { WorkersRealTimeStatistics other = (WorkersRealTimeStatistics) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(activityStatistics, other.activityStatistics) && Objects.equals(totalWorkers, other.totalWorkers) && Objects.equals(workspaceSid, other.workspaceSid) && Objects.equals(url, other.url) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(activityStatistics, other.activityStatistics) && + Objects.equals(totalWorkers, other.totalWorkers) && + Objects.equals(workspaceSid, other.workspaceSid) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, activityStatistics, totalWorkers, workspaceSid, url); + return Objects.hash( + accountSid, + activityStatistics, + totalWorkers, + workspaceSid, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkersRealTimeStatisticsFetcher.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkersRealTimeStatisticsFetcher.java index 6b9c69e401..1f842833ce 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkersRealTimeStatisticsFetcher.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkersRealTimeStatisticsFetcher.java @@ -24,27 +24,33 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class WorkersRealTimeStatisticsFetcher + extends Fetcher { - - -public class WorkersRealTimeStatisticsFetcher extends Fetcher { private String pathWorkspaceSid; private String taskChannel; - public WorkersRealTimeStatisticsFetcher(final String pathWorkspaceSid){ + public WorkersRealTimeStatisticsFetcher(final String pathWorkspaceSid) { this.pathWorkspaceSid = pathWorkspaceSid; } - public WorkersRealTimeStatisticsFetcher setTaskChannel(final String taskChannel){ + public WorkersRealTimeStatisticsFetcher setTaskChannel( + final String taskChannel + ) { this.taskChannel = taskChannel; return this; } @Override public WorkersRealTimeStatistics fetch(final TwilioRestClient client) { - String path = "/v1/Workspaces/{WorkspaceSid}/Workers/RealTimeStatistics"; + String path = + "/v1/Workspaces/{WorkspaceSid}/Workers/RealTimeStatistics"; - path = path.replace("{"+"WorkspaceSid"+"}", this.pathWorkspaceSid.toString()); + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -55,20 +61,28 @@ public WorkersRealTimeStatistics fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("WorkersRealTimeStatistics fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "WorkersRealTimeStatistics fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return WorkersRealTimeStatistics.fromJson(response.getStream(), client.getObjectMapper()); + return WorkersRealTimeStatistics.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addQueryParams(final Request request) { if (taskChannel != null) { - request.addQueryParam("TaskChannel", taskChannel); } } diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkersStatistics.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkersStatistics.java index 44fefd3add..5b3ee1f9bd 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkersStatistics.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkersStatistics.java @@ -22,38 +22,39 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class WorkersStatistics extends Resource { + private static final long serialVersionUID = 274987650256203L; - public static WorkersStatisticsFetcher fetcher(final String pathWorkspaceSid){ + public static WorkersStatisticsFetcher fetcher( + final String pathWorkspaceSid + ) { return new WorkersStatisticsFetcher(pathWorkspaceSid); } /** - * Converts a JSON String into a WorkersStatistics object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return WorkersStatistics object represented by the provided JSON - */ - public static WorkersStatistics fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a WorkersStatistics object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return WorkersStatistics object represented by the provided JSON + */ + public static WorkersStatistics fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, WorkersStatistics.class); @@ -65,14 +66,17 @@ public static WorkersStatistics fromJson(final String json, final ObjectMapper o } /** - * Converts a JSON InputStream into a WorkersStatistics object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return WorkersStatistics object represented by the provided JSON - */ - public static WorkersStatistics fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a WorkersStatistics object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return WorkersStatistics object represented by the provided JSON + */ + public static WorkersStatistics fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, WorkersStatistics.class); @@ -91,20 +95,11 @@ public static WorkersStatistics fromJson(final InputStream json, final ObjectMap @JsonCreator private WorkersStatistics( - @JsonProperty("realtime") - final Map realtime, - - @JsonProperty("cumulative") - final Map cumulative, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("workspace_sid") - final String workspaceSid, - - @JsonProperty("url") - final URI url + @JsonProperty("realtime") final Map realtime, + @JsonProperty("cumulative") final Map cumulative, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("workspace_sid") final String workspaceSid, + @JsonProperty("url") final URI url ) { this.realtime = realtime; this.cumulative = cumulative; @@ -113,25 +108,29 @@ private WorkersStatistics( this.url = url; } - public final Map getRealtime() { - return this.realtime; - } - public final Map getCumulative() { - return this.cumulative; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getWorkspaceSid() { - return this.workspaceSid; - } - public final URI getUrl() { - return this.url; - } + public final Map getRealtime() { + return this.realtime; + } + + public final Map getCumulative() { + return this.cumulative; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getWorkspaceSid() { + return this.workspaceSid; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -141,13 +140,23 @@ public boolean equals(final Object o) { WorkersStatistics other = (WorkersStatistics) o; - return Objects.equals(realtime, other.realtime) && Objects.equals(cumulative, other.cumulative) && Objects.equals(accountSid, other.accountSid) && Objects.equals(workspaceSid, other.workspaceSid) && Objects.equals(url, other.url) ; + return ( + Objects.equals(realtime, other.realtime) && + Objects.equals(cumulative, other.cumulative) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(workspaceSid, other.workspaceSid) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(realtime, cumulative, accountSid, workspaceSid, url); + return Objects.hash( + realtime, + cumulative, + accountSid, + workspaceSid, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkersStatisticsFetcher.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkersStatisticsFetcher.java index 7937de7c2e..bfde1abbfb 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkersStatisticsFetcher.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkersStatisticsFetcher.java @@ -23,12 +23,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.time.ZonedDateTime; - - public class WorkersStatisticsFetcher extends Fetcher { + private String pathWorkspaceSid; private Integer minutes; private ZonedDateTime startDate; @@ -38,35 +36,45 @@ public class WorkersStatisticsFetcher extends Fetcher { private String friendlyName; private String taskChannel; - public WorkersStatisticsFetcher(final String pathWorkspaceSid){ + public WorkersStatisticsFetcher(final String pathWorkspaceSid) { this.pathWorkspaceSid = pathWorkspaceSid; } - public WorkersStatisticsFetcher setMinutes(final Integer minutes){ + public WorkersStatisticsFetcher setMinutes(final Integer minutes) { this.minutes = minutes; return this; } - public WorkersStatisticsFetcher setStartDate(final ZonedDateTime startDate){ + + public WorkersStatisticsFetcher setStartDate( + final ZonedDateTime startDate + ) { this.startDate = startDate; return this; } - public WorkersStatisticsFetcher setEndDate(final ZonedDateTime endDate){ + + public WorkersStatisticsFetcher setEndDate(final ZonedDateTime endDate) { this.endDate = endDate; return this; } - public WorkersStatisticsFetcher setTaskQueueSid(final String taskQueueSid){ + + public WorkersStatisticsFetcher setTaskQueueSid(final String taskQueueSid) { this.taskQueueSid = taskQueueSid; return this; } - public WorkersStatisticsFetcher setTaskQueueName(final String taskQueueName){ + + public WorkersStatisticsFetcher setTaskQueueName( + final String taskQueueName + ) { this.taskQueueName = taskQueueName; return this; } - public WorkersStatisticsFetcher setFriendlyName(final String friendlyName){ + + public WorkersStatisticsFetcher setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public WorkersStatisticsFetcher setTaskChannel(final String taskChannel){ + + public WorkersStatisticsFetcher setTaskChannel(final String taskChannel) { this.taskChannel = taskChannel; return this; } @@ -75,7 +83,11 @@ public WorkersStatisticsFetcher setTaskChannel(final String taskChannel){ public WorkersStatistics fetch(final TwilioRestClient client) { String path = "/v1/Workspaces/{WorkspaceSid}/Workers/Statistics"; - path = path.replace("{"+"WorkspaceSid"+"}", this.pathWorkspaceSid.toString()); + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -86,24 +98,35 @@ public WorkersStatistics fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("WorkersStatistics fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "WorkersStatistics fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return WorkersStatistics.fromJson(response.getStream(), client.getObjectMapper()); + return WorkersStatistics.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addQueryParams(final Request request) { if (minutes != null) { - request.addQueryParam("Minutes", minutes.toString()); } if (startDate != null) { - request.addQueryParam("StartDate", startDate.toInstant().toString()); + request.addQueryParam( + "StartDate", + startDate.toInstant().toString() + ); } if (endDate != null) { @@ -111,19 +134,15 @@ private void addQueryParams(final Request request) { } if (taskQueueSid != null) { - request.addQueryParam("TaskQueueSid", taskQueueSid); } if (taskQueueName != null) { - request.addQueryParam("TaskQueueName", taskQueueName); } if (friendlyName != null) { - request.addQueryParam("FriendlyName", friendlyName); } if (taskChannel != null) { - request.addQueryParam("TaskChannel", taskChannel); } } diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/workflow/WorkflowCumulativeStatistics.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/workflow/WorkflowCumulativeStatistics.java index 588d230f2b..1921b0c157 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/workflow/WorkflowCumulativeStatistics.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/workflow/WorkflowCumulativeStatistics.java @@ -23,42 +23,50 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class WorkflowCumulativeStatistics extends Resource { + private static final long serialVersionUID = 209789504024863L; - public static WorkflowCumulativeStatisticsFetcher fetcher(final String pathWorkspaceSid, final String pathWorkflowSid){ - return new WorkflowCumulativeStatisticsFetcher(pathWorkspaceSid, pathWorkflowSid); + public static WorkflowCumulativeStatisticsFetcher fetcher( + final String pathWorkspaceSid, + final String pathWorkflowSid + ) { + return new WorkflowCumulativeStatisticsFetcher( + pathWorkspaceSid, + pathWorkflowSid + ); } /** - * Converts a JSON String into a WorkflowCumulativeStatistics object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return WorkflowCumulativeStatistics object represented by the provided JSON - */ - public static WorkflowCumulativeStatistics fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a WorkflowCumulativeStatistics object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return WorkflowCumulativeStatistics object represented by the provided JSON + */ + public static WorkflowCumulativeStatistics fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, WorkflowCumulativeStatistics.class); + return objectMapper.readValue( + json, + WorkflowCumulativeStatistics.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -67,17 +75,23 @@ public static WorkflowCumulativeStatistics fromJson(final String json, final Obj } /** - * Converts a JSON InputStream into a WorkflowCumulativeStatistics object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return WorkflowCumulativeStatistics object represented by the provided JSON - */ - public static WorkflowCumulativeStatistics fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a WorkflowCumulativeStatistics object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return WorkflowCumulativeStatistics object represented by the provided JSON + */ + public static WorkflowCumulativeStatistics fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, WorkflowCumulativeStatistics.class); + return objectMapper.readValue( + json, + WorkflowCumulativeStatistics.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -110,71 +124,48 @@ public static WorkflowCumulativeStatistics fromJson(final InputStream json, fina @JsonCreator private WorkflowCumulativeStatistics( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("avg_task_acceptance_time") - final Integer avgTaskAcceptanceTime, - - @JsonProperty("start_time") - final String startTime, - - @JsonProperty("end_time") - final String endTime, - - @JsonProperty("reservations_created") - final Integer reservationsCreated, - - @JsonProperty("reservations_accepted") - final Integer reservationsAccepted, - - @JsonProperty("reservations_rejected") - final Integer reservationsRejected, - - @JsonProperty("reservations_timed_out") - final Integer reservationsTimedOut, - - @JsonProperty("reservations_canceled") - final Integer reservationsCanceled, - - @JsonProperty("reservations_rescinded") - final Integer reservationsRescinded, - - @JsonProperty("split_by_wait_time") - final Map splitByWaitTime, - - @JsonProperty("wait_duration_until_accepted") - final Map waitDurationUntilAccepted, - - @JsonProperty("wait_duration_until_canceled") - final Map waitDurationUntilCanceled, - - @JsonProperty("tasks_canceled") - final Integer tasksCanceled, - - @JsonProperty("tasks_completed") - final Integer tasksCompleted, - - @JsonProperty("tasks_entered") - final Integer tasksEntered, - - @JsonProperty("tasks_deleted") - final Integer tasksDeleted, - - @JsonProperty("tasks_moved") - final Integer tasksMoved, - - @JsonProperty("tasks_timed_out_in_workflow") - final Integer tasksTimedOutInWorkflow, - - @JsonProperty("workflow_sid") - final String workflowSid, - - @JsonProperty("workspace_sid") - final String workspaceSid, - - @JsonProperty("url") - final URI url + @JsonProperty("account_sid") final String accountSid, + @JsonProperty( + "avg_task_acceptance_time" + ) final Integer avgTaskAcceptanceTime, + @JsonProperty("start_time") final String startTime, + @JsonProperty("end_time") final String endTime, + @JsonProperty("reservations_created") final Integer reservationsCreated, + @JsonProperty( + "reservations_accepted" + ) final Integer reservationsAccepted, + @JsonProperty( + "reservations_rejected" + ) final Integer reservationsRejected, + @JsonProperty( + "reservations_timed_out" + ) final Integer reservationsTimedOut, + @JsonProperty( + "reservations_canceled" + ) final Integer reservationsCanceled, + @JsonProperty( + "reservations_rescinded" + ) final Integer reservationsRescinded, + @JsonProperty( + "split_by_wait_time" + ) final Map splitByWaitTime, + @JsonProperty( + "wait_duration_until_accepted" + ) final Map waitDurationUntilAccepted, + @JsonProperty( + "wait_duration_until_canceled" + ) final Map waitDurationUntilCanceled, + @JsonProperty("tasks_canceled") final Integer tasksCanceled, + @JsonProperty("tasks_completed") final Integer tasksCompleted, + @JsonProperty("tasks_entered") final Integer tasksEntered, + @JsonProperty("tasks_deleted") final Integer tasksDeleted, + @JsonProperty("tasks_moved") final Integer tasksMoved, + @JsonProperty( + "tasks_timed_out_in_workflow" + ) final Integer tasksTimedOutInWorkflow, + @JsonProperty("workflow_sid") final String workflowSid, + @JsonProperty("workspace_sid") final String workspaceSid, + @JsonProperty("url") final URI url ) { this.accountSid = accountSid; this.avgTaskAcceptanceTime = avgTaskAcceptanceTime; @@ -200,76 +191,97 @@ private WorkflowCumulativeStatistics( this.url = url; } - public final String getAccountSid() { - return this.accountSid; - } - public final Integer getAvgTaskAcceptanceTime() { - return this.avgTaskAcceptanceTime; - } - public final ZonedDateTime getStartTime() { - return this.startTime; - } - public final ZonedDateTime getEndTime() { - return this.endTime; - } - public final Integer getReservationsCreated() { - return this.reservationsCreated; - } - public final Integer getReservationsAccepted() { - return this.reservationsAccepted; - } - public final Integer getReservationsRejected() { - return this.reservationsRejected; - } - public final Integer getReservationsTimedOut() { - return this.reservationsTimedOut; - } - public final Integer getReservationsCanceled() { - return this.reservationsCanceled; - } - public final Integer getReservationsRescinded() { - return this.reservationsRescinded; - } - public final Map getSplitByWaitTime() { - return this.splitByWaitTime; - } - public final Map getWaitDurationUntilAccepted() { - return this.waitDurationUntilAccepted; - } - public final Map getWaitDurationUntilCanceled() { - return this.waitDurationUntilCanceled; - } - public final Integer getTasksCanceled() { - return this.tasksCanceled; - } - public final Integer getTasksCompleted() { - return this.tasksCompleted; - } - public final Integer getTasksEntered() { - return this.tasksEntered; - } - public final Integer getTasksDeleted() { - return this.tasksDeleted; - } - public final Integer getTasksMoved() { - return this.tasksMoved; - } - public final Integer getTasksTimedOutInWorkflow() { - return this.tasksTimedOutInWorkflow; - } - public final String getWorkflowSid() { - return this.workflowSid; - } - public final String getWorkspaceSid() { - return this.workspaceSid; - } - public final URI getUrl() { - return this.url; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final Integer getAvgTaskAcceptanceTime() { + return this.avgTaskAcceptanceTime; + } + + public final ZonedDateTime getStartTime() { + return this.startTime; + } + + public final ZonedDateTime getEndTime() { + return this.endTime; + } + + public final Integer getReservationsCreated() { + return this.reservationsCreated; + } + + public final Integer getReservationsAccepted() { + return this.reservationsAccepted; + } + + public final Integer getReservationsRejected() { + return this.reservationsRejected; + } + + public final Integer getReservationsTimedOut() { + return this.reservationsTimedOut; + } + + public final Integer getReservationsCanceled() { + return this.reservationsCanceled; + } + + public final Integer getReservationsRescinded() { + return this.reservationsRescinded; + } + + public final Map getSplitByWaitTime() { + return this.splitByWaitTime; + } + + public final Map getWaitDurationUntilAccepted() { + return this.waitDurationUntilAccepted; + } + + public final Map getWaitDurationUntilCanceled() { + return this.waitDurationUntilCanceled; + } + + public final Integer getTasksCanceled() { + return this.tasksCanceled; + } + + public final Integer getTasksCompleted() { + return this.tasksCompleted; + } + + public final Integer getTasksEntered() { + return this.tasksEntered; + } + + public final Integer getTasksDeleted() { + return this.tasksDeleted; + } + + public final Integer getTasksMoved() { + return this.tasksMoved; + } + + public final Integer getTasksTimedOutInWorkflow() { + return this.tasksTimedOutInWorkflow; + } + + public final String getWorkflowSid() { + return this.workflowSid; + } + + public final String getWorkspaceSid() { + return this.workspaceSid; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -279,13 +291,72 @@ public boolean equals(final Object o) { WorkflowCumulativeStatistics other = (WorkflowCumulativeStatistics) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(avgTaskAcceptanceTime, other.avgTaskAcceptanceTime) && Objects.equals(startTime, other.startTime) && Objects.equals(endTime, other.endTime) && Objects.equals(reservationsCreated, other.reservationsCreated) && Objects.equals(reservationsAccepted, other.reservationsAccepted) && Objects.equals(reservationsRejected, other.reservationsRejected) && Objects.equals(reservationsTimedOut, other.reservationsTimedOut) && Objects.equals(reservationsCanceled, other.reservationsCanceled) && Objects.equals(reservationsRescinded, other.reservationsRescinded) && Objects.equals(splitByWaitTime, other.splitByWaitTime) && Objects.equals(waitDurationUntilAccepted, other.waitDurationUntilAccepted) && Objects.equals(waitDurationUntilCanceled, other.waitDurationUntilCanceled) && Objects.equals(tasksCanceled, other.tasksCanceled) && Objects.equals(tasksCompleted, other.tasksCompleted) && Objects.equals(tasksEntered, other.tasksEntered) && Objects.equals(tasksDeleted, other.tasksDeleted) && Objects.equals(tasksMoved, other.tasksMoved) && Objects.equals(tasksTimedOutInWorkflow, other.tasksTimedOutInWorkflow) && Objects.equals(workflowSid, other.workflowSid) && Objects.equals(workspaceSid, other.workspaceSid) && Objects.equals(url, other.url) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals( + avgTaskAcceptanceTime, + other.avgTaskAcceptanceTime + ) && + Objects.equals(startTime, other.startTime) && + Objects.equals(endTime, other.endTime) && + Objects.equals(reservationsCreated, other.reservationsCreated) && + Objects.equals(reservationsAccepted, other.reservationsAccepted) && + Objects.equals(reservationsRejected, other.reservationsRejected) && + Objects.equals(reservationsTimedOut, other.reservationsTimedOut) && + Objects.equals(reservationsCanceled, other.reservationsCanceled) && + Objects.equals( + reservationsRescinded, + other.reservationsRescinded + ) && + Objects.equals(splitByWaitTime, other.splitByWaitTime) && + Objects.equals( + waitDurationUntilAccepted, + other.waitDurationUntilAccepted + ) && + Objects.equals( + waitDurationUntilCanceled, + other.waitDurationUntilCanceled + ) && + Objects.equals(tasksCanceled, other.tasksCanceled) && + Objects.equals(tasksCompleted, other.tasksCompleted) && + Objects.equals(tasksEntered, other.tasksEntered) && + Objects.equals(tasksDeleted, other.tasksDeleted) && + Objects.equals(tasksMoved, other.tasksMoved) && + Objects.equals( + tasksTimedOutInWorkflow, + other.tasksTimedOutInWorkflow + ) && + Objects.equals(workflowSid, other.workflowSid) && + Objects.equals(workspaceSid, other.workspaceSid) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, avgTaskAcceptanceTime, startTime, endTime, reservationsCreated, reservationsAccepted, reservationsRejected, reservationsTimedOut, reservationsCanceled, reservationsRescinded, splitByWaitTime, waitDurationUntilAccepted, waitDurationUntilCanceled, tasksCanceled, tasksCompleted, tasksEntered, tasksDeleted, tasksMoved, tasksTimedOutInWorkflow, workflowSid, workspaceSid, url); + return Objects.hash( + accountSid, + avgTaskAcceptanceTime, + startTime, + endTime, + reservationsCreated, + reservationsAccepted, + reservationsRejected, + reservationsTimedOut, + reservationsCanceled, + reservationsRescinded, + splitByWaitTime, + waitDurationUntilAccepted, + waitDurationUntilCanceled, + tasksCanceled, + tasksCompleted, + tasksEntered, + tasksDeleted, + tasksMoved, + tasksTimedOutInWorkflow, + workflowSid, + workspaceSid, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/workflow/WorkflowCumulativeStatisticsFetcher.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/workflow/WorkflowCumulativeStatisticsFetcher.java index 265751446b..2a5662afc5 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/workflow/WorkflowCumulativeStatisticsFetcher.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/workflow/WorkflowCumulativeStatisticsFetcher.java @@ -23,12 +23,11 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.time.ZonedDateTime; +public class WorkflowCumulativeStatisticsFetcher + extends Fetcher { - -public class WorkflowCumulativeStatisticsFetcher extends Fetcher { private String pathWorkspaceSid; private String pathWorkflowSid; private ZonedDateTime endDate; @@ -37,38 +36,64 @@ public class WorkflowCumulativeStatisticsFetcher extends Fetcher tasksByPriority, - - @JsonProperty("tasks_by_status") - final Map tasksByStatus, - - @JsonProperty("total_tasks") - final Integer totalTasks, - - @JsonProperty("workflow_sid") - final String workflowSid, - - @JsonProperty("workspace_sid") - final String workspaceSid, - - @JsonProperty("url") - final URI url + @JsonProperty("account_sid") final String accountSid, + @JsonProperty( + "longest_task_waiting_age" + ) final Integer longestTaskWaitingAge, + @JsonProperty( + "longest_task_waiting_sid" + ) final String longestTaskWaitingSid, + @JsonProperty( + "tasks_by_priority" + ) final Map tasksByPriority, + @JsonProperty( + "tasks_by_status" + ) final Map tasksByStatus, + @JsonProperty("total_tasks") final Integer totalTasks, + @JsonProperty("workflow_sid") final String workflowSid, + @JsonProperty("workspace_sid") final String workspaceSid, + @JsonProperty("url") final URI url ) { this.accountSid = accountSid; this.longestTaskWaitingAge = longestTaskWaitingAge; @@ -133,37 +138,45 @@ private WorkflowRealTimeStatistics( this.url = url; } - public final String getAccountSid() { - return this.accountSid; - } - public final Integer getLongestTaskWaitingAge() { - return this.longestTaskWaitingAge; - } - public final String getLongestTaskWaitingSid() { - return this.longestTaskWaitingSid; - } - public final Map getTasksByPriority() { - return this.tasksByPriority; - } - public final Map getTasksByStatus() { - return this.tasksByStatus; - } - public final Integer getTotalTasks() { - return this.totalTasks; - } - public final String getWorkflowSid() { - return this.workflowSid; - } - public final String getWorkspaceSid() { - return this.workspaceSid; - } - public final URI getUrl() { - return this.url; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final Integer getLongestTaskWaitingAge() { + return this.longestTaskWaitingAge; + } + + public final String getLongestTaskWaitingSid() { + return this.longestTaskWaitingSid; + } + + public final Map getTasksByPriority() { + return this.tasksByPriority; + } + + public final Map getTasksByStatus() { + return this.tasksByStatus; + } + + public final Integer getTotalTasks() { + return this.totalTasks; + } + + public final String getWorkflowSid() { + return this.workflowSid; + } + + public final String getWorkspaceSid() { + return this.workspaceSid; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -173,13 +186,37 @@ public boolean equals(final Object o) { WorkflowRealTimeStatistics other = (WorkflowRealTimeStatistics) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(longestTaskWaitingAge, other.longestTaskWaitingAge) && Objects.equals(longestTaskWaitingSid, other.longestTaskWaitingSid) && Objects.equals(tasksByPriority, other.tasksByPriority) && Objects.equals(tasksByStatus, other.tasksByStatus) && Objects.equals(totalTasks, other.totalTasks) && Objects.equals(workflowSid, other.workflowSid) && Objects.equals(workspaceSid, other.workspaceSid) && Objects.equals(url, other.url) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals( + longestTaskWaitingAge, + other.longestTaskWaitingAge + ) && + Objects.equals( + longestTaskWaitingSid, + other.longestTaskWaitingSid + ) && + Objects.equals(tasksByPriority, other.tasksByPriority) && + Objects.equals(tasksByStatus, other.tasksByStatus) && + Objects.equals(totalTasks, other.totalTasks) && + Objects.equals(workflowSid, other.workflowSid) && + Objects.equals(workspaceSid, other.workspaceSid) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, longestTaskWaitingAge, longestTaskWaitingSid, tasksByPriority, tasksByStatus, totalTasks, workflowSid, workspaceSid, url); + return Objects.hash( + accountSid, + longestTaskWaitingAge, + longestTaskWaitingSid, + tasksByPriority, + tasksByStatus, + totalTasks, + workflowSid, + workspaceSid, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/workflow/WorkflowRealTimeStatisticsFetcher.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/workflow/WorkflowRealTimeStatisticsFetcher.java index 9b59b8325c..0cd4cdf343 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/workflow/WorkflowRealTimeStatisticsFetcher.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/workflow/WorkflowRealTimeStatisticsFetcher.java @@ -24,30 +24,43 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class WorkflowRealTimeStatisticsFetcher + extends Fetcher { - - -public class WorkflowRealTimeStatisticsFetcher extends Fetcher { private String pathWorkspaceSid; private String pathWorkflowSid; private String taskChannel; - public WorkflowRealTimeStatisticsFetcher(final String pathWorkspaceSid, final String pathWorkflowSid){ + public WorkflowRealTimeStatisticsFetcher( + final String pathWorkspaceSid, + final String pathWorkflowSid + ) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathWorkflowSid = pathWorkflowSid; } - public WorkflowRealTimeStatisticsFetcher setTaskChannel(final String taskChannel){ + public WorkflowRealTimeStatisticsFetcher setTaskChannel( + final String taskChannel + ) { this.taskChannel = taskChannel; return this; } @Override public WorkflowRealTimeStatistics fetch(final TwilioRestClient client) { - String path = "/v1/Workspaces/{WorkspaceSid}/Workflows/{WorkflowSid}/RealTimeStatistics"; + String path = + "/v1/Workspaces/{WorkspaceSid}/Workflows/{WorkflowSid}/RealTimeStatistics"; - path = path.replace("{"+"WorkspaceSid"+"}", this.pathWorkspaceSid.toString()); - path = path.replace("{"+"WorkflowSid"+"}", this.pathWorkflowSid.toString()); + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = + path.replace( + "{" + "WorkflowSid" + "}", + this.pathWorkflowSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -58,20 +71,28 @@ public WorkflowRealTimeStatistics fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("WorkflowRealTimeStatistics fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "WorkflowRealTimeStatistics fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return WorkflowRealTimeStatistics.fromJson(response.getStream(), client.getObjectMapper()); + return WorkflowRealTimeStatistics.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addQueryParams(final Request request) { if (taskChannel != null) { - request.addQueryParam("TaskChannel", taskChannel); } } diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/workflow/WorkflowStatistics.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/workflow/WorkflowStatistics.java index 8de5ff0d81..f651aaccf4 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/workflow/WorkflowStatistics.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/workflow/WorkflowStatistics.java @@ -22,38 +22,40 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class WorkflowStatistics extends Resource { + private static final long serialVersionUID = 124113751515927L; - public static WorkflowStatisticsFetcher fetcher(final String pathWorkspaceSid, final String pathWorkflowSid){ + public static WorkflowStatisticsFetcher fetcher( + final String pathWorkspaceSid, + final String pathWorkflowSid + ) { return new WorkflowStatisticsFetcher(pathWorkspaceSid, pathWorkflowSid); } /** - * Converts a JSON String into a WorkflowStatistics object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return WorkflowStatistics object represented by the provided JSON - */ - public static WorkflowStatistics fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a WorkflowStatistics object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return WorkflowStatistics object represented by the provided JSON + */ + public static WorkflowStatistics fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, WorkflowStatistics.class); @@ -65,14 +67,17 @@ public static WorkflowStatistics fromJson(final String json, final ObjectMapper } /** - * Converts a JSON InputStream into a WorkflowStatistics object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return WorkflowStatistics object represented by the provided JSON - */ - public static WorkflowStatistics fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a WorkflowStatistics object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return WorkflowStatistics object represented by the provided JSON + */ + public static WorkflowStatistics fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, WorkflowStatistics.class); @@ -92,23 +97,12 @@ public static WorkflowStatistics fromJson(final InputStream json, final ObjectMa @JsonCreator private WorkflowStatistics( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("cumulative") - final Map cumulative, - - @JsonProperty("realtime") - final Map realtime, - - @JsonProperty("workflow_sid") - final String workflowSid, - - @JsonProperty("workspace_sid") - final String workspaceSid, - - @JsonProperty("url") - final URI url + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("cumulative") final Map cumulative, + @JsonProperty("realtime") final Map realtime, + @JsonProperty("workflow_sid") final String workflowSid, + @JsonProperty("workspace_sid") final String workspaceSid, + @JsonProperty("url") final URI url ) { this.accountSid = accountSid; this.cumulative = cumulative; @@ -118,28 +112,33 @@ private WorkflowStatistics( this.url = url; } - public final String getAccountSid() { - return this.accountSid; - } - public final Map getCumulative() { - return this.cumulative; - } - public final Map getRealtime() { - return this.realtime; - } - public final String getWorkflowSid() { - return this.workflowSid; - } - public final String getWorkspaceSid() { - return this.workspaceSid; - } - public final URI getUrl() { - return this.url; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final Map getCumulative() { + return this.cumulative; + } + + public final Map getRealtime() { + return this.realtime; + } + + public final String getWorkflowSid() { + return this.workflowSid; + } + + public final String getWorkspaceSid() { + return this.workspaceSid; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -149,13 +148,25 @@ public boolean equals(final Object o) { WorkflowStatistics other = (WorkflowStatistics) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(cumulative, other.cumulative) && Objects.equals(realtime, other.realtime) && Objects.equals(workflowSid, other.workflowSid) && Objects.equals(workspaceSid, other.workspaceSid) && Objects.equals(url, other.url) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(cumulative, other.cumulative) && + Objects.equals(realtime, other.realtime) && + Objects.equals(workflowSid, other.workflowSid) && + Objects.equals(workspaceSid, other.workspaceSid) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, cumulative, realtime, workflowSid, workspaceSid, url); + return Objects.hash( + accountSid, + cumulative, + realtime, + workflowSid, + workspaceSid, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/workflow/WorkflowStatisticsFetcher.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/workflow/WorkflowStatisticsFetcher.java index 8650d5d10f..1cedd0c303 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/workflow/WorkflowStatisticsFetcher.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/workflow/WorkflowStatisticsFetcher.java @@ -23,12 +23,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.time.ZonedDateTime; - - public class WorkflowStatisticsFetcher extends Fetcher { + private String pathWorkspaceSid; private String pathWorkflowSid; private Integer minutes; @@ -37,38 +35,58 @@ public class WorkflowStatisticsFetcher extends Fetcher { private String taskChannel; private String splitByWaitTime; - public WorkflowStatisticsFetcher(final String pathWorkspaceSid, final String pathWorkflowSid){ + public WorkflowStatisticsFetcher( + final String pathWorkspaceSid, + final String pathWorkflowSid + ) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathWorkflowSid = pathWorkflowSid; } - public WorkflowStatisticsFetcher setMinutes(final Integer minutes){ + public WorkflowStatisticsFetcher setMinutes(final Integer minutes) { this.minutes = minutes; return this; } - public WorkflowStatisticsFetcher setStartDate(final ZonedDateTime startDate){ + + public WorkflowStatisticsFetcher setStartDate( + final ZonedDateTime startDate + ) { this.startDate = startDate; return this; } - public WorkflowStatisticsFetcher setEndDate(final ZonedDateTime endDate){ + + public WorkflowStatisticsFetcher setEndDate(final ZonedDateTime endDate) { this.endDate = endDate; return this; } - public WorkflowStatisticsFetcher setTaskChannel(final String taskChannel){ + + public WorkflowStatisticsFetcher setTaskChannel(final String taskChannel) { this.taskChannel = taskChannel; return this; } - public WorkflowStatisticsFetcher setSplitByWaitTime(final String splitByWaitTime){ + + public WorkflowStatisticsFetcher setSplitByWaitTime( + final String splitByWaitTime + ) { this.splitByWaitTime = splitByWaitTime; return this; } @Override public WorkflowStatistics fetch(final TwilioRestClient client) { - String path = "/v1/Workspaces/{WorkspaceSid}/Workflows/{WorkflowSid}/Statistics"; + String path = + "/v1/Workspaces/{WorkspaceSid}/Workflows/{WorkflowSid}/Statistics"; - path = path.replace("{"+"WorkspaceSid"+"}", this.pathWorkspaceSid.toString()); - path = path.replace("{"+"WorkflowSid"+"}", this.pathWorkflowSid.toString()); + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = + path.replace( + "{" + "WorkflowSid" + "}", + this.pathWorkflowSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -79,24 +97,35 @@ public WorkflowStatistics fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("WorkflowStatistics fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "WorkflowStatistics fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return WorkflowStatistics.fromJson(response.getStream(), client.getObjectMapper()); + return WorkflowStatistics.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addQueryParams(final Request request) { if (minutes != null) { - request.addQueryParam("Minutes", minutes.toString()); } if (startDate != null) { - request.addQueryParam("StartDate", startDate.toInstant().toString()); + request.addQueryParam( + "StartDate", + startDate.toInstant().toString() + ); } if (endDate != null) { @@ -104,11 +133,9 @@ private void addQueryParams(final Request request) { } if (taskChannel != null) { - request.addQueryParam("TaskChannel", taskChannel); } if (splitByWaitTime != null) { - request.addQueryParam("SplitByWaitTime", splitByWaitTime); } } diff --git a/src/main/java/com/twilio/rest/trunking/v1/Trunk.java b/src/main/java/com/twilio/rest/trunking/v1/Trunk.java index 17df8d2eb2..65fd01f6fe 100644 --- a/src/main/java/com/twilio/rest/trunking/v1/Trunk.java +++ b/src/main/java/com/twilio/rest/trunking/v1/Trunk.java @@ -24,57 +24,56 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; import com.twilio.http.HttpMethod; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.List; import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Trunk extends Resource { + private static final long serialVersionUID = 225938897286327L; - public static TrunkCreator creator(){ + public static TrunkCreator creator() { return new TrunkCreator(); } - public static TrunkDeleter deleter(final String pathSid){ + public static TrunkDeleter deleter(final String pathSid) { return new TrunkDeleter(pathSid); } - public static TrunkFetcher fetcher(final String pathSid){ + public static TrunkFetcher fetcher(final String pathSid) { return new TrunkFetcher(pathSid); } - public static TrunkReader reader(){ + public static TrunkReader reader() { return new TrunkReader(); } - public static TrunkUpdater updater(final String pathSid){ + public static TrunkUpdater updater(final String pathSid) { return new TrunkUpdater(pathSid); } /** - * Converts a JSON String into a Trunk object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Trunk object represented by the provided JSON - */ - public static Trunk fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Trunk object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Trunk object represented by the provided JSON + */ + public static Trunk fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Trunk.class); @@ -86,14 +85,17 @@ public static Trunk fromJson(final String json, final ObjectMapper objectMapper) } /** - * Converts a JSON InputStream into a Trunk object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Trunk object represented by the provided JSON - */ - public static Trunk fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Trunk object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Trunk object represented by the provided JSON + */ + public static Trunk fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Trunk.class); @@ -103,6 +105,7 @@ public static Trunk fromJson(final InputStream json, final ObjectMapper objectMa throw new ApiConnectionException(e.getMessage(), e); } } + public enum TransferCallerId { FROM_TRANSFEREE("from-transferee"), FROM_TRANSFEROR("from-transferor"); @@ -122,6 +125,7 @@ public static TransferCallerId forValue(final String value) { return Promoter.enumFromString(value, TransferCallerId.values()); } } + public enum TransferSetting { DISABLE_ALL("disable-all"), ENABLE_ALL("enable-all"), @@ -163,56 +167,27 @@ public static TransferSetting forValue(final String value) { @JsonCreator private Trunk( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("domain_name") - final String domainName, - - @JsonProperty("disaster_recovery_method") - final HttpMethod disasterRecoveryMethod, - - @JsonProperty("disaster_recovery_url") - final URI disasterRecoveryUrl, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("secure") - final Boolean secure, - - @JsonProperty("recording") - final Map recording, - - @JsonProperty("transfer_mode") - final Trunk.TransferSetting transferMode, - - @JsonProperty("transfer_caller_id") - final Trunk.TransferCallerId transferCallerId, - - @JsonProperty("cnam_lookup_enabled") - final Boolean cnamLookupEnabled, - - @JsonProperty("auth_type") - final String authType, - - @JsonProperty("auth_type_set") - final List authTypeSet, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("domain_name") final String domainName, + @JsonProperty( + "disaster_recovery_method" + ) final HttpMethod disasterRecoveryMethod, + @JsonProperty("disaster_recovery_url") final URI disasterRecoveryUrl, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("secure") final Boolean secure, + @JsonProperty("recording") final Map recording, + @JsonProperty("transfer_mode") final Trunk.TransferSetting transferMode, + @JsonProperty( + "transfer_caller_id" + ) final Trunk.TransferCallerId transferCallerId, + @JsonProperty("cnam_lookup_enabled") final Boolean cnamLookupEnabled, + @JsonProperty("auth_type") final String authType, + @JsonProperty("auth_type_set") final List authTypeSet, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.accountSid = accountSid; this.domainName = domainName; @@ -233,61 +208,77 @@ private Trunk( this.links = links; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getDomainName() { - return this.domainName; - } - public final HttpMethod getDisasterRecoveryMethod() { - return this.disasterRecoveryMethod; - } - public final URI getDisasterRecoveryUrl() { - return this.disasterRecoveryUrl; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final Boolean getSecure() { - return this.secure; - } - public final Map getRecording() { - return this.recording; - } - public final Trunk.TransferSetting getTransferMode() { - return this.transferMode; - } - public final Trunk.TransferCallerId getTransferCallerId() { - return this.transferCallerId; - } - public final Boolean getCnamLookupEnabled() { - return this.cnamLookupEnabled; - } - public final String getAuthType() { - return this.authType; - } - public final List getAuthTypeSet() { - return this.authTypeSet; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getSid() { - return this.sid; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getDomainName() { + return this.domainName; + } + + public final HttpMethod getDisasterRecoveryMethod() { + return this.disasterRecoveryMethod; + } + + public final URI getDisasterRecoveryUrl() { + return this.disasterRecoveryUrl; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final Boolean getSecure() { + return this.secure; + } + + public final Map getRecording() { + return this.recording; + } + + public final Trunk.TransferSetting getTransferMode() { + return this.transferMode; + } + + public final Trunk.TransferCallerId getTransferCallerId() { + return this.transferCallerId; + } + + public final Boolean getCnamLookupEnabled() { + return this.cnamLookupEnabled; + } + + public final String getAuthType() { + return this.authType; + } + + public final List getAuthTypeSet() { + return this.authTypeSet; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getSid() { + return this.sid; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -297,13 +288,50 @@ public boolean equals(final Object o) { Trunk other = (Trunk) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(domainName, other.domainName) && Objects.equals(disasterRecoveryMethod, other.disasterRecoveryMethod) && Objects.equals(disasterRecoveryUrl, other.disasterRecoveryUrl) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(secure, other.secure) && Objects.equals(recording, other.recording) && Objects.equals(transferMode, other.transferMode) && Objects.equals(transferCallerId, other.transferCallerId) && Objects.equals(cnamLookupEnabled, other.cnamLookupEnabled) && Objects.equals(authType, other.authType) && Objects.equals(authTypeSet, other.authTypeSet) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(sid, other.sid) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(domainName, other.domainName) && + Objects.equals( + disasterRecoveryMethod, + other.disasterRecoveryMethod + ) && + Objects.equals(disasterRecoveryUrl, other.disasterRecoveryUrl) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(secure, other.secure) && + Objects.equals(recording, other.recording) && + Objects.equals(transferMode, other.transferMode) && + Objects.equals(transferCallerId, other.transferCallerId) && + Objects.equals(cnamLookupEnabled, other.cnamLookupEnabled) && + Objects.equals(authType, other.authType) && + Objects.equals(authTypeSet, other.authTypeSet) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, domainName, disasterRecoveryMethod, disasterRecoveryUrl, friendlyName, secure, recording, transferMode, transferCallerId, cnamLookupEnabled, authType, authTypeSet, dateCreated, dateUpdated, sid, url, links); + return Objects.hash( + accountSid, + domainName, + disasterRecoveryMethod, + disasterRecoveryUrl, + friendlyName, + secure, + recording, + transferMode, + transferCallerId, + cnamLookupEnabled, + authType, + authTypeSet, + dateCreated, + dateUpdated, + sid, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/trunking/v1/TrunkCreator.java b/src/main/java/com/twilio/rest/trunking/v1/TrunkCreator.java index 8e0be4d5e3..db65b759bf 100644 --- a/src/main/java/com/twilio/rest/trunking/v1/TrunkCreator.java +++ b/src/main/java/com/twilio/rest/trunking/v1/TrunkCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.trunking.v1; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -25,12 +26,10 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.net.URI; - - - import java.net.URI; -public class TrunkCreator extends Creator{ +public class TrunkCreator extends Creator { + private String friendlyName; private String domainName; private URI disasterRecoveryUrl; @@ -40,62 +39,83 @@ public class TrunkCreator extends Creator{ private Boolean cnamLookupEnabled; private Trunk.TransferCallerId transferCallerId; - public TrunkCreator() { - } + public TrunkCreator() {} - public TrunkCreator setFriendlyName(final String friendlyName){ + public TrunkCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public TrunkCreator setDomainName(final String domainName){ + + public TrunkCreator setDomainName(final String domainName) { this.domainName = domainName; return this; } - public TrunkCreator setDisasterRecoveryUrl(final URI disasterRecoveryUrl){ + + public TrunkCreator setDisasterRecoveryUrl(final URI disasterRecoveryUrl) { this.disasterRecoveryUrl = disasterRecoveryUrl; return this; } - public TrunkCreator setDisasterRecoveryUrl(final String disasterRecoveryUrl){ - return setDisasterRecoveryUrl(Promoter.uriFromString(disasterRecoveryUrl)); + public TrunkCreator setDisasterRecoveryUrl( + final String disasterRecoveryUrl + ) { + return setDisasterRecoveryUrl( + Promoter.uriFromString(disasterRecoveryUrl) + ); } - public TrunkCreator setDisasterRecoveryMethod(final HttpMethod disasterRecoveryMethod){ + + public TrunkCreator setDisasterRecoveryMethod( + final HttpMethod disasterRecoveryMethod + ) { this.disasterRecoveryMethod = disasterRecoveryMethod; return this; } - public TrunkCreator setTransferMode(final Trunk.TransferSetting transferMode){ + + public TrunkCreator setTransferMode( + final Trunk.TransferSetting transferMode + ) { this.transferMode = transferMode; return this; } - public TrunkCreator setSecure(final Boolean secure){ + + public TrunkCreator setSecure(final Boolean secure) { this.secure = secure; return this; } - public TrunkCreator setCnamLookupEnabled(final Boolean cnamLookupEnabled){ + + public TrunkCreator setCnamLookupEnabled(final Boolean cnamLookupEnabled) { this.cnamLookupEnabled = cnamLookupEnabled; return this; } - public TrunkCreator setTransferCallerId(final Trunk.TransferCallerId transferCallerId){ + + public TrunkCreator setTransferCallerId( + final Trunk.TransferCallerId transferCallerId + ) { this.transferCallerId = transferCallerId; return this; } @Override - public Trunk create(final TwilioRestClient client){ + public Trunk create(final TwilioRestClient client) { String path = "/v1/Trunks"; - Request request = new Request( HttpMethod.POST, Domains.TRUNKING.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Trunk creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Trunk creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -104,38 +124,43 @@ public Trunk create(final TwilioRestClient client){ return Trunk.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (domainName != null) { request.addPostParam("DomainName", domainName); - } if (disasterRecoveryUrl != null) { - request.addPostParam("DisasterRecoveryUrl", disasterRecoveryUrl.toString()); - + request.addPostParam( + "DisasterRecoveryUrl", + disasterRecoveryUrl.toString() + ); } if (disasterRecoveryMethod != null) { - request.addPostParam("DisasterRecoveryMethod", disasterRecoveryMethod.toString()); - + request.addPostParam( + "DisasterRecoveryMethod", + disasterRecoveryMethod.toString() + ); } if (transferMode != null) { request.addPostParam("TransferMode", transferMode.toString()); - } if (secure != null) { request.addPostParam("Secure", secure.toString()); - } if (cnamLookupEnabled != null) { - request.addPostParam("CnamLookupEnabled", cnamLookupEnabled.toString()); - + request.addPostParam( + "CnamLookupEnabled", + cnamLookupEnabled.toString() + ); } if (transferCallerId != null) { - request.addPostParam("TransferCallerId", transferCallerId.toString()); - + request.addPostParam( + "TransferCallerId", + transferCallerId.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/trunking/v1/TrunkDeleter.java b/src/main/java/com/twilio/rest/trunking/v1/TrunkDeleter.java index 3f3747dff4..57d7caf1ac 100644 --- a/src/main/java/com/twilio/rest/trunking/v1/TrunkDeleter.java +++ b/src/main/java/com/twilio/rest/trunking/v1/TrunkDeleter.java @@ -24,21 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class TrunkDeleter extends Deleter { + private String pathSid; - public TrunkDeleter(final String pathSid){ + public TrunkDeleter(final String pathSid) { this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Trunks/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -48,9 +46,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Trunk delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Trunk delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/trunking/v1/TrunkFetcher.java b/src/main/java/com/twilio/rest/trunking/v1/TrunkFetcher.java index c98899a99e..9036e4f1ce 100644 --- a/src/main/java/com/twilio/rest/trunking/v1/TrunkFetcher.java +++ b/src/main/java/com/twilio/rest/trunking/v1/TrunkFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class TrunkFetcher extends Fetcher { + private String pathSid; - public TrunkFetcher(final String pathSid){ + public TrunkFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public Trunk fetch(final TwilioRestClient client) { String path = "/v1/Trunks/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,9 +46,14 @@ public Trunk fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Trunk fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Trunk fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/trunking/v1/TrunkReader.java b/src/main/java/com/twilio/rest/trunking/v1/TrunkReader.java index 2d7bba2390..8a72202cc1 100644 --- a/src/main/java/com/twilio/rest/trunking/v1/TrunkReader.java +++ b/src/main/java/com/twilio/rest/trunking/v1/TrunkReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.trunking.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,17 +25,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class TrunkReader extends Reader { + private Integer pageSize; - public TrunkReader(){ - } + public TrunkReader() {} - public TrunkReader setPageSize(final Integer pageSize){ + public TrunkReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -57,13 +55,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Trunk read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Trunk read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -79,7 +85,10 @@ private Page pageForRequest(final TwilioRestClient client, final Request } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.TRUNKING.toString()) @@ -87,9 +96,11 @@ public Page previousPage(final Page page, final TwilioRestClient c return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.TRUNKING.toString()) @@ -98,21 +109,21 @@ public Page nextPage(final Page page, final TwilioRestClient clien } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/trunking/v1/TrunkUpdater.java b/src/main/java/com/twilio/rest/trunking/v1/TrunkUpdater.java index fffe1c21e4..97c921b754 100644 --- a/src/main/java/com/twilio/rest/trunking/v1/TrunkUpdater.java +++ b/src/main/java/com/twilio/rest/trunking/v1/TrunkUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.trunking.v1; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -24,12 +25,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.net.URI; +public class TrunkUpdater extends Updater { - -public class TrunkUpdater extends Updater{ private String pathSid; private String friendlyName; private String domainName; @@ -40,64 +39,87 @@ public class TrunkUpdater extends Updater{ private Boolean cnamLookupEnabled; private Trunk.TransferCallerId transferCallerId; - public TrunkUpdater(final String pathSid){ + public TrunkUpdater(final String pathSid) { this.pathSid = pathSid; } - public TrunkUpdater setFriendlyName(final String friendlyName){ + public TrunkUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public TrunkUpdater setDomainName(final String domainName){ + + public TrunkUpdater setDomainName(final String domainName) { this.domainName = domainName; return this; } - public TrunkUpdater setDisasterRecoveryUrl(final URI disasterRecoveryUrl){ + + public TrunkUpdater setDisasterRecoveryUrl(final URI disasterRecoveryUrl) { this.disasterRecoveryUrl = disasterRecoveryUrl; return this; } - public TrunkUpdater setDisasterRecoveryUrl(final String disasterRecoveryUrl){ - return setDisasterRecoveryUrl(Promoter.uriFromString(disasterRecoveryUrl)); + public TrunkUpdater setDisasterRecoveryUrl( + final String disasterRecoveryUrl + ) { + return setDisasterRecoveryUrl( + Promoter.uriFromString(disasterRecoveryUrl) + ); } - public TrunkUpdater setDisasterRecoveryMethod(final HttpMethod disasterRecoveryMethod){ + + public TrunkUpdater setDisasterRecoveryMethod( + final HttpMethod disasterRecoveryMethod + ) { this.disasterRecoveryMethod = disasterRecoveryMethod; return this; } - public TrunkUpdater setTransferMode(final Trunk.TransferSetting transferMode){ + + public TrunkUpdater setTransferMode( + final Trunk.TransferSetting transferMode + ) { this.transferMode = transferMode; return this; } - public TrunkUpdater setSecure(final Boolean secure){ + + public TrunkUpdater setSecure(final Boolean secure) { this.secure = secure; return this; } - public TrunkUpdater setCnamLookupEnabled(final Boolean cnamLookupEnabled){ + + public TrunkUpdater setCnamLookupEnabled(final Boolean cnamLookupEnabled) { this.cnamLookupEnabled = cnamLookupEnabled; return this; } - public TrunkUpdater setTransferCallerId(final Trunk.TransferCallerId transferCallerId){ + + public TrunkUpdater setTransferCallerId( + final Trunk.TransferCallerId transferCallerId + ) { this.transferCallerId = transferCallerId; return this; } @Override - public Trunk update(final TwilioRestClient client){ + public Trunk update(final TwilioRestClient client) { String path = "/v1/Trunks/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.TRUNKING.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Trunk update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Trunk update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -106,38 +128,43 @@ public Trunk update(final TwilioRestClient client){ return Trunk.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (domainName != null) { request.addPostParam("DomainName", domainName); - } if (disasterRecoveryUrl != null) { - request.addPostParam("DisasterRecoveryUrl", disasterRecoveryUrl.toString()); - + request.addPostParam( + "DisasterRecoveryUrl", + disasterRecoveryUrl.toString() + ); } if (disasterRecoveryMethod != null) { - request.addPostParam("DisasterRecoveryMethod", disasterRecoveryMethod.toString()); - + request.addPostParam( + "DisasterRecoveryMethod", + disasterRecoveryMethod.toString() + ); } if (transferMode != null) { request.addPostParam("TransferMode", transferMode.toString()); - } if (secure != null) { request.addPostParam("Secure", secure.toString()); - } if (cnamLookupEnabled != null) { - request.addPostParam("CnamLookupEnabled", cnamLookupEnabled.toString()); - + request.addPostParam( + "CnamLookupEnabled", + cnamLookupEnabled.toString() + ); } if (transferCallerId != null) { - request.addPostParam("TransferCallerId", transferCallerId.toString()); - + request.addPostParam( + "TransferCallerId", + transferCallerId.toString() + ); } } } diff --git a/src/main/java/com/twilio/rest/trunking/v1/trunk/CredentialList.java b/src/main/java/com/twilio/rest/trunking/v1/trunk/CredentialList.java index 11e2450a0a..7f3e4774fd 100644 --- a/src/main/java/com/twilio/rest/trunking/v1/trunk/CredentialList.java +++ b/src/main/java/com/twilio/rest/trunking/v1/trunk/CredentialList.java @@ -23,49 +23,57 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class CredentialList extends Resource { + private static final long serialVersionUID = 198091197266991L; - public static CredentialListCreator creator(final String pathTrunkSid, final String credentialListSid){ + public static CredentialListCreator creator( + final String pathTrunkSid, + final String credentialListSid + ) { return new CredentialListCreator(pathTrunkSid, credentialListSid); } - public static CredentialListDeleter deleter(final String pathTrunkSid, final String pathSid){ + public static CredentialListDeleter deleter( + final String pathTrunkSid, + final String pathSid + ) { return new CredentialListDeleter(pathTrunkSid, pathSid); } - public static CredentialListFetcher fetcher(final String pathTrunkSid, final String pathSid){ + public static CredentialListFetcher fetcher( + final String pathTrunkSid, + final String pathSid + ) { return new CredentialListFetcher(pathTrunkSid, pathSid); } - public static CredentialListReader reader(final String pathTrunkSid){ + public static CredentialListReader reader(final String pathTrunkSid) { return new CredentialListReader(pathTrunkSid); } /** - * Converts a JSON String into a CredentialList object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return CredentialList object represented by the provided JSON - */ - public static CredentialList fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a CredentialList object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return CredentialList object represented by the provided JSON + */ + public static CredentialList fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, CredentialList.class); @@ -77,14 +85,17 @@ public static CredentialList fromJson(final String json, final ObjectMapper obje } /** - * Converts a JSON InputStream into a CredentialList object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return CredentialList object represented by the provided JSON - */ - public static CredentialList fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a CredentialList object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return CredentialList object represented by the provided JSON + */ + public static CredentialList fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, CredentialList.class); @@ -105,26 +116,13 @@ public static CredentialList fromJson(final InputStream json, final ObjectMapper @JsonCreator private CredentialList( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("trunk_sid") - final String trunkSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("sid") final String sid, + @JsonProperty("trunk_sid") final String trunkSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url ) { this.accountSid = accountSid; this.sid = sid; @@ -135,31 +133,37 @@ private CredentialList( this.url = url; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getSid() { - return this.sid; - } - public final String getTrunkSid() { - return this.trunkSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getSid() { + return this.sid; + } + + public final String getTrunkSid() { + return this.trunkSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -169,13 +173,27 @@ public boolean equals(final Object o) { CredentialList other = (CredentialList) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(sid, other.sid) && Objects.equals(trunkSid, other.trunkSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(sid, other.sid) && + Objects.equals(trunkSid, other.trunkSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, sid, trunkSid, friendlyName, dateCreated, dateUpdated, url); + return Objects.hash( + accountSid, + sid, + trunkSid, + friendlyName, + dateCreated, + dateUpdated, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/trunking/v1/trunk/CredentialListCreator.java b/src/main/java/com/twilio/rest/trunking/v1/trunk/CredentialListCreator.java index c2709a5a5c..c3139c8222 100644 --- a/src/main/java/com/twilio/rest/trunking/v1/trunk/CredentialListCreator.java +++ b/src/main/java/com/twilio/rest/trunking/v1/trunk/CredentialListCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.trunking.v1.trunk; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,53 +25,70 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class CredentialListCreator extends Creator { - - -public class CredentialListCreator extends Creator{ private String pathTrunkSid; private String credentialListSid; - public CredentialListCreator(final String pathTrunkSid, final String credentialListSid) { + public CredentialListCreator( + final String pathTrunkSid, + final String credentialListSid + ) { this.pathTrunkSid = pathTrunkSid; this.credentialListSid = credentialListSid; } - public CredentialListCreator setCredentialListSid(final String credentialListSid){ + public CredentialListCreator setCredentialListSid( + final String credentialListSid + ) { this.credentialListSid = credentialListSid; return this; } @Override - public CredentialList create(final TwilioRestClient client){ + public CredentialList create(final TwilioRestClient client) { String path = "/v1/Trunks/{TrunkSid}/CredentialLists"; - path = path.replace("{"+"TrunkSid"+"}", this.pathTrunkSid.toString()); - path = path.replace("{"+"CredentialListSid"+"}", this.credentialListSid.toString()); + path = + path.replace("{" + "TrunkSid" + "}", this.pathTrunkSid.toString()); + path = + path.replace( + "{" + "CredentialListSid" + "}", + this.credentialListSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.TRUNKING.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("CredentialList creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "CredentialList creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return CredentialList.fromJson(response.getStream(), client.getObjectMapper()); + return CredentialList.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (credentialListSid != null) { request.addPostParam("CredentialListSid", credentialListSid); - } } } diff --git a/src/main/java/com/twilio/rest/trunking/v1/trunk/CredentialListDeleter.java b/src/main/java/com/twilio/rest/trunking/v1/trunk/CredentialListDeleter.java index 438dfbfc5f..7c20bdee5c 100644 --- a/src/main/java/com/twilio/rest/trunking/v1/trunk/CredentialListDeleter.java +++ b/src/main/java/com/twilio/rest/trunking/v1/trunk/CredentialListDeleter.java @@ -24,24 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class CredentialListDeleter extends Deleter { + private String pathTrunkSid; private String pathSid; - public CredentialListDeleter(final String pathTrunkSid, final String pathSid){ + public CredentialListDeleter( + final String pathTrunkSid, + final String pathSid + ) { this.pathTrunkSid = pathTrunkSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Trunks/{TrunkSid}/CredentialLists/{Sid}"; - path = path.replace("{"+"TrunkSid"+"}", this.pathTrunkSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace("{" + "TrunkSid" + "}", this.pathTrunkSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +53,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("CredentialList delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "CredentialList delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/trunking/v1/trunk/CredentialListFetcher.java b/src/main/java/com/twilio/rest/trunking/v1/trunk/CredentialListFetcher.java index 0d81eb2536..b1f2b0709f 100644 --- a/src/main/java/com/twilio/rest/trunking/v1/trunk/CredentialListFetcher.java +++ b/src/main/java/com/twilio/rest/trunking/v1/trunk/CredentialListFetcher.java @@ -24,25 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class CredentialListFetcher extends Fetcher { + private String pathTrunkSid; private String pathSid; - public CredentialListFetcher(final String pathTrunkSid, final String pathSid){ + public CredentialListFetcher( + final String pathTrunkSid, + final String pathSid + ) { this.pathTrunkSid = pathTrunkSid; this.pathSid = pathSid; } - @Override public CredentialList fetch(final TwilioRestClient client) { String path = "/v1/Trunks/{TrunkSid}/CredentialLists/{Sid}"; - path = path.replace("{"+"TrunkSid"+"}", this.pathTrunkSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace("{" + "TrunkSid" + "}", this.pathTrunkSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,15 +53,23 @@ public CredentialList fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("CredentialList fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "CredentialList fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return CredentialList.fromJson(response.getStream(), client.getObjectMapper()); + return CredentialList.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/trunking/v1/trunk/CredentialListReader.java b/src/main/java/com/twilio/rest/trunking/v1/trunk/CredentialListReader.java index e12cda3227..ee786e995d 100644 --- a/src/main/java/com/twilio/rest/trunking/v1/trunk/CredentialListReader.java +++ b/src/main/java/com/twilio/rest/trunking/v1/trunk/CredentialListReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.trunking.v1.trunk; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,19 +25,17 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class CredentialListReader extends Reader { + private String pathTrunkSid; private Integer pageSize; - public CredentialListReader(final String pathTrunkSid){ + public CredentialListReader(final String pathTrunkSid) { this.pathTrunkSid = pathTrunkSid; } - public CredentialListReader setPageSize(final Integer pageSize){ + public CredentialListReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -48,7 +47,8 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Trunks/{TrunkSid}/CredentialLists"; - path = path.replace("{"+"TrunkSid"+"}", this.pathTrunkSid.toString()); + path = + path.replace("{" + "TrunkSid" + "}", this.pathTrunkSid.toString()); Request request = new Request( HttpMethod.GET, @@ -60,13 +60,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("CredentialList read failed: Unable to connect to server"); + throw new ApiConnectionException( + "CredentialList read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +90,10 @@ private Page pageForRequest(final TwilioRestClient client, final } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.TRUNKING.toString()) @@ -90,9 +101,11 @@ public Page previousPage(final Page page, final return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.TRUNKING.toString()) @@ -101,21 +114,21 @@ public Page nextPage(final Page page, final Twil } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/trunking/v1/trunk/IpAccessControlList.java b/src/main/java/com/twilio/rest/trunking/v1/trunk/IpAccessControlList.java index aee53331f5..a354c2de69 100644 --- a/src/main/java/com/twilio/rest/trunking/v1/trunk/IpAccessControlList.java +++ b/src/main/java/com/twilio/rest/trunking/v1/trunk/IpAccessControlList.java @@ -23,49 +23,60 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class IpAccessControlList extends Resource { + private static final long serialVersionUID = 198091197266991L; - public static IpAccessControlListCreator creator(final String pathTrunkSid, final String ipAccessControlListSid){ - return new IpAccessControlListCreator(pathTrunkSid, ipAccessControlListSid); + public static IpAccessControlListCreator creator( + final String pathTrunkSid, + final String ipAccessControlListSid + ) { + return new IpAccessControlListCreator( + pathTrunkSid, + ipAccessControlListSid + ); } - public static IpAccessControlListDeleter deleter(final String pathTrunkSid, final String pathSid){ + public static IpAccessControlListDeleter deleter( + final String pathTrunkSid, + final String pathSid + ) { return new IpAccessControlListDeleter(pathTrunkSid, pathSid); } - public static IpAccessControlListFetcher fetcher(final String pathTrunkSid, final String pathSid){ + public static IpAccessControlListFetcher fetcher( + final String pathTrunkSid, + final String pathSid + ) { return new IpAccessControlListFetcher(pathTrunkSid, pathSid); } - public static IpAccessControlListReader reader(final String pathTrunkSid){ + public static IpAccessControlListReader reader(final String pathTrunkSid) { return new IpAccessControlListReader(pathTrunkSid); } /** - * Converts a JSON String into a IpAccessControlList object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return IpAccessControlList object represented by the provided JSON - */ - public static IpAccessControlList fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a IpAccessControlList object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return IpAccessControlList object represented by the provided JSON + */ + public static IpAccessControlList fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, IpAccessControlList.class); @@ -77,14 +88,17 @@ public static IpAccessControlList fromJson(final String json, final ObjectMapper } /** - * Converts a JSON InputStream into a IpAccessControlList object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return IpAccessControlList object represented by the provided JSON - */ - public static IpAccessControlList fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a IpAccessControlList object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return IpAccessControlList object represented by the provided JSON + */ + public static IpAccessControlList fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, IpAccessControlList.class); @@ -105,26 +119,13 @@ public static IpAccessControlList fromJson(final InputStream json, final ObjectM @JsonCreator private IpAccessControlList( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("trunk_sid") - final String trunkSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("sid") final String sid, + @JsonProperty("trunk_sid") final String trunkSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url ) { this.accountSid = accountSid; this.sid = sid; @@ -135,31 +136,37 @@ private IpAccessControlList( this.url = url; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getSid() { - return this.sid; - } - public final String getTrunkSid() { - return this.trunkSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getSid() { + return this.sid; + } + + public final String getTrunkSid() { + return this.trunkSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -169,13 +176,27 @@ public boolean equals(final Object o) { IpAccessControlList other = (IpAccessControlList) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(sid, other.sid) && Objects.equals(trunkSid, other.trunkSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(sid, other.sid) && + Objects.equals(trunkSid, other.trunkSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, sid, trunkSid, friendlyName, dateCreated, dateUpdated, url); + return Objects.hash( + accountSid, + sid, + trunkSid, + friendlyName, + dateCreated, + dateUpdated, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/trunking/v1/trunk/IpAccessControlListCreator.java b/src/main/java/com/twilio/rest/trunking/v1/trunk/IpAccessControlListCreator.java index 0c59adb0a7..f993a64f71 100644 --- a/src/main/java/com/twilio/rest/trunking/v1/trunk/IpAccessControlListCreator.java +++ b/src/main/java/com/twilio/rest/trunking/v1/trunk/IpAccessControlListCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.trunking.v1.trunk; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,53 +25,73 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class IpAccessControlListCreator extends Creator { - - -public class IpAccessControlListCreator extends Creator{ private String pathTrunkSid; private String ipAccessControlListSid; - public IpAccessControlListCreator(final String pathTrunkSid, final String ipAccessControlListSid) { + public IpAccessControlListCreator( + final String pathTrunkSid, + final String ipAccessControlListSid + ) { this.pathTrunkSid = pathTrunkSid; this.ipAccessControlListSid = ipAccessControlListSid; } - public IpAccessControlListCreator setIpAccessControlListSid(final String ipAccessControlListSid){ + public IpAccessControlListCreator setIpAccessControlListSid( + final String ipAccessControlListSid + ) { this.ipAccessControlListSid = ipAccessControlListSid; return this; } @Override - public IpAccessControlList create(final TwilioRestClient client){ + public IpAccessControlList create(final TwilioRestClient client) { String path = "/v1/Trunks/{TrunkSid}/IpAccessControlLists"; - path = path.replace("{"+"TrunkSid"+"}", this.pathTrunkSid.toString()); - path = path.replace("{"+"IpAccessControlListSid"+"}", this.ipAccessControlListSid.toString()); + path = + path.replace("{" + "TrunkSid" + "}", this.pathTrunkSid.toString()); + path = + path.replace( + "{" + "IpAccessControlListSid" + "}", + this.ipAccessControlListSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.TRUNKING.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("IpAccessControlList creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "IpAccessControlList creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return IpAccessControlList.fromJson(response.getStream(), client.getObjectMapper()); + return IpAccessControlList.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (ipAccessControlListSid != null) { - request.addPostParam("IpAccessControlListSid", ipAccessControlListSid); - + request.addPostParam( + "IpAccessControlListSid", + ipAccessControlListSid + ); } } } diff --git a/src/main/java/com/twilio/rest/trunking/v1/trunk/IpAccessControlListDeleter.java b/src/main/java/com/twilio/rest/trunking/v1/trunk/IpAccessControlListDeleter.java index f20ccef83f..f2ae63ac1d 100644 --- a/src/main/java/com/twilio/rest/trunking/v1/trunk/IpAccessControlListDeleter.java +++ b/src/main/java/com/twilio/rest/trunking/v1/trunk/IpAccessControlListDeleter.java @@ -24,24 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class IpAccessControlListDeleter extends Deleter { + private String pathTrunkSid; private String pathSid; - public IpAccessControlListDeleter(final String pathTrunkSid, final String pathSid){ + public IpAccessControlListDeleter( + final String pathTrunkSid, + final String pathSid + ) { this.pathTrunkSid = pathTrunkSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Trunks/{TrunkSid}/IpAccessControlLists/{Sid}"; - path = path.replace("{"+"TrunkSid"+"}", this.pathTrunkSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace("{" + "TrunkSid" + "}", this.pathTrunkSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +53,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("IpAccessControlList delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "IpAccessControlList delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/trunking/v1/trunk/IpAccessControlListFetcher.java b/src/main/java/com/twilio/rest/trunking/v1/trunk/IpAccessControlListFetcher.java index f31723fadd..161394ab1e 100644 --- a/src/main/java/com/twilio/rest/trunking/v1/trunk/IpAccessControlListFetcher.java +++ b/src/main/java/com/twilio/rest/trunking/v1/trunk/IpAccessControlListFetcher.java @@ -24,25 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class IpAccessControlListFetcher extends Fetcher { + private String pathTrunkSid; private String pathSid; - public IpAccessControlListFetcher(final String pathTrunkSid, final String pathSid){ + public IpAccessControlListFetcher( + final String pathTrunkSid, + final String pathSid + ) { this.pathTrunkSid = pathTrunkSid; this.pathSid = pathSid; } - @Override public IpAccessControlList fetch(final TwilioRestClient client) { String path = "/v1/Trunks/{TrunkSid}/IpAccessControlLists/{Sid}"; - path = path.replace("{"+"TrunkSid"+"}", this.pathTrunkSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace("{" + "TrunkSid" + "}", this.pathTrunkSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,15 +53,23 @@ public IpAccessControlList fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("IpAccessControlList fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "IpAccessControlList fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return IpAccessControlList.fromJson(response.getStream(), client.getObjectMapper()); + return IpAccessControlList.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/trunking/v1/trunk/IpAccessControlListReader.java b/src/main/java/com/twilio/rest/trunking/v1/trunk/IpAccessControlListReader.java index ab17d4a91d..6943b5ec36 100644 --- a/src/main/java/com/twilio/rest/trunking/v1/trunk/IpAccessControlListReader.java +++ b/src/main/java/com/twilio/rest/trunking/v1/trunk/IpAccessControlListReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.trunking.v1.trunk; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,31 +25,32 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class IpAccessControlListReader extends Reader { + private String pathTrunkSid; private Integer pageSize; - public IpAccessControlListReader(final String pathTrunkSid){ + public IpAccessControlListReader(final String pathTrunkSid) { this.pathTrunkSid = pathTrunkSid; } - public IpAccessControlListReader setPageSize(final Integer pageSize){ + public IpAccessControlListReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @Override - public ResourceSet read(final TwilioRestClient client) { + public ResourceSet read( + final TwilioRestClient client + ) { return new ResourceSet<>(this, client, firstPage(client)); } public Page firstPage(final TwilioRestClient client) { String path = "/v1/Trunks/{TrunkSid}/IpAccessControlLists"; - path = path.replace("{"+"TrunkSid"+"}", this.pathTrunkSid.toString()); + path = + path.replace("{" + "TrunkSid" + "}", this.pathTrunkSid.toString()); Request request = new Request( HttpMethod.GET, @@ -60,13 +62,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("IpAccessControlList read failed: Unable to connect to server"); + throw new ApiConnectionException( + "IpAccessControlList read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +92,10 @@ private Page pageForRequest(final TwilioRestClient client, } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.TRUNKING.toString()) @@ -90,9 +103,11 @@ public Page previousPage(final Page pa return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.TRUNKING.toString()) @@ -101,21 +116,21 @@ public Page nextPage(final Page page, } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/trunking/v1/trunk/OriginationUrl.java b/src/main/java/com/twilio/rest/trunking/v1/trunk/OriginationUrl.java index 1489e1c8f1..6b330365c8 100644 --- a/src/main/java/com/twilio/rest/trunking/v1/trunk/OriginationUrl.java +++ b/src/main/java/com/twilio/rest/trunking/v1/trunk/OriginationUrl.java @@ -23,53 +23,75 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class OriginationUrl extends Resource { + private static final long serialVersionUID = 133388691973992L; - public static OriginationUrlCreator creator(final String pathTrunkSid, final Integer weight, final Integer priority, final Boolean enabled, final String friendlyName, final URI sipUrl){ - return new OriginationUrlCreator(pathTrunkSid, weight, priority, enabled, friendlyName, sipUrl); + public static OriginationUrlCreator creator( + final String pathTrunkSid, + final Integer weight, + final Integer priority, + final Boolean enabled, + final String friendlyName, + final URI sipUrl + ) { + return new OriginationUrlCreator( + pathTrunkSid, + weight, + priority, + enabled, + friendlyName, + sipUrl + ); } - public static OriginationUrlDeleter deleter(final String pathTrunkSid, final String pathSid){ + public static OriginationUrlDeleter deleter( + final String pathTrunkSid, + final String pathSid + ) { return new OriginationUrlDeleter(pathTrunkSid, pathSid); } - public static OriginationUrlFetcher fetcher(final String pathTrunkSid, final String pathSid){ + public static OriginationUrlFetcher fetcher( + final String pathTrunkSid, + final String pathSid + ) { return new OriginationUrlFetcher(pathTrunkSid, pathSid); } - public static OriginationUrlReader reader(final String pathTrunkSid){ + public static OriginationUrlReader reader(final String pathTrunkSid) { return new OriginationUrlReader(pathTrunkSid); } - public static OriginationUrlUpdater updater(final String pathTrunkSid, final String pathSid){ + public static OriginationUrlUpdater updater( + final String pathTrunkSid, + final String pathSid + ) { return new OriginationUrlUpdater(pathTrunkSid, pathSid); } /** - * Converts a JSON String into a OriginationUrl object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return OriginationUrl object represented by the provided JSON - */ - public static OriginationUrl fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a OriginationUrl object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return OriginationUrl object represented by the provided JSON + */ + public static OriginationUrl fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, OriginationUrl.class); @@ -81,14 +103,17 @@ public static OriginationUrl fromJson(final String json, final ObjectMapper obje } /** - * Converts a JSON InputStream into a OriginationUrl object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return OriginationUrl object represented by the provided JSON - */ - public static OriginationUrl fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a OriginationUrl object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return OriginationUrl object represented by the provided JSON + */ + public static OriginationUrl fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, OriginationUrl.class); @@ -113,38 +138,17 @@ public static OriginationUrl fromJson(final InputStream json, final ObjectMapper @JsonCreator private OriginationUrl( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("trunk_sid") - final String trunkSid, - - @JsonProperty("weight") - final Integer weight, - - @JsonProperty("enabled") - final Boolean enabled, - - @JsonProperty("sip_url") - final URI sipUrl, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("priority") - final Integer priority, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("sid") final String sid, + @JsonProperty("trunk_sid") final String trunkSid, + @JsonProperty("weight") final Integer weight, + @JsonProperty("enabled") final Boolean enabled, + @JsonProperty("sip_url") final URI sipUrl, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("priority") final Integer priority, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url ) { this.accountSid = accountSid; this.sid = sid; @@ -159,43 +163,53 @@ private OriginationUrl( this.url = url; } - public final String getAccountSid() { - return this.accountSid; - } - public final String getSid() { - return this.sid; - } - public final String getTrunkSid() { - return this.trunkSid; - } - public final Integer getWeight() { - return this.weight; - } - public final Boolean getEnabled() { - return this.enabled; - } - public final URI getSipUrl() { - return this.sipUrl; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final Integer getPriority() { - return this.priority; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final String getSid() { + return this.sid; + } + + public final String getTrunkSid() { + return this.trunkSid; + } + + public final Integer getWeight() { + return this.weight; + } + + public final Boolean getEnabled() { + return this.enabled; + } + + public final URI getSipUrl() { + return this.sipUrl; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final Integer getPriority() { + return this.priority; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -205,13 +219,35 @@ public boolean equals(final Object o) { OriginationUrl other = (OriginationUrl) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(sid, other.sid) && Objects.equals(trunkSid, other.trunkSid) && Objects.equals(weight, other.weight) && Objects.equals(enabled, other.enabled) && Objects.equals(sipUrl, other.sipUrl) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(priority, other.priority) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(sid, other.sid) && + Objects.equals(trunkSid, other.trunkSid) && + Objects.equals(weight, other.weight) && + Objects.equals(enabled, other.enabled) && + Objects.equals(sipUrl, other.sipUrl) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(priority, other.priority) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, sid, trunkSid, weight, enabled, sipUrl, friendlyName, priority, dateCreated, dateUpdated, url); + return Objects.hash( + accountSid, + sid, + trunkSid, + weight, + enabled, + sipUrl, + friendlyName, + priority, + dateCreated, + dateUpdated, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/trunking/v1/trunk/OriginationUrlCreator.java b/src/main/java/com/twilio/rest/trunking/v1/trunk/OriginationUrlCreator.java index 607a86c43e..b2c2384d29 100644 --- a/src/main/java/com/twilio/rest/trunking/v1/trunk/OriginationUrlCreator.java +++ b/src/main/java/com/twilio/rest/trunking/v1/trunk/OriginationUrlCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.trunking.v1.trunk; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -25,12 +26,10 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.net.URI; - - - import java.net.URI; -public class OriginationUrlCreator extends Creator{ +public class OriginationUrlCreator extends Creator { + private String pathTrunkSid; private Integer weight; private Integer priority; @@ -38,7 +37,14 @@ public class OriginationUrlCreator extends Creator{ private String friendlyName; private URI sipUrl; - public OriginationUrlCreator(final String pathTrunkSid, final Integer weight, final Integer priority, final Boolean enabled, final String friendlyName, final URI sipUrl) { + public OriginationUrlCreator( + final String pathTrunkSid, + final Integer weight, + final Integer priority, + final Boolean enabled, + final String friendlyName, + final URI sipUrl + ) { this.pathTrunkSid = pathTrunkSid; this.weight = weight; this.priority = priority; @@ -47,81 +53,95 @@ public OriginationUrlCreator(final String pathTrunkSid, final Integer weight, fi this.sipUrl = sipUrl; } - public OriginationUrlCreator setWeight(final Integer weight){ + public OriginationUrlCreator setWeight(final Integer weight) { this.weight = weight; return this; } - public OriginationUrlCreator setPriority(final Integer priority){ + + public OriginationUrlCreator setPriority(final Integer priority) { this.priority = priority; return this; } - public OriginationUrlCreator setEnabled(final Boolean enabled){ + + public OriginationUrlCreator setEnabled(final Boolean enabled) { this.enabled = enabled; return this; } - public OriginationUrlCreator setFriendlyName(final String friendlyName){ + + public OriginationUrlCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public OriginationUrlCreator setSipUrl(final URI sipUrl){ + + public OriginationUrlCreator setSipUrl(final URI sipUrl) { this.sipUrl = sipUrl; return this; } - public OriginationUrlCreator setSipUrl(final String sipUrl){ + public OriginationUrlCreator setSipUrl(final String sipUrl) { return setSipUrl(Promoter.uriFromString(sipUrl)); } @Override - public OriginationUrl create(final TwilioRestClient client){ + public OriginationUrl create(final TwilioRestClient client) { String path = "/v1/Trunks/{TrunkSid}/OriginationUrls"; - path = path.replace("{"+"TrunkSid"+"}", this.pathTrunkSid.toString()); - path = path.replace("{"+"Weight"+"}", this.weight.toString()); - path = path.replace("{"+"Priority"+"}", this.priority.toString()); - path = path.replace("{"+"Enabled"+"}", this.enabled.toString()); - path = path.replace("{"+"FriendlyName"+"}", this.friendlyName.toString()); - path = path.replace("{"+"SipUrl"+"}", this.sipUrl.toString()); + path = + path.replace("{" + "TrunkSid" + "}", this.pathTrunkSid.toString()); + path = path.replace("{" + "Weight" + "}", this.weight.toString()); + path = path.replace("{" + "Priority" + "}", this.priority.toString()); + path = path.replace("{" + "Enabled" + "}", this.enabled.toString()); + path = + path.replace( + "{" + "FriendlyName" + "}", + this.friendlyName.toString() + ); + path = path.replace("{" + "SipUrl" + "}", this.sipUrl.toString()); Request request = new Request( HttpMethod.POST, Domains.TRUNKING.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("OriginationUrl creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "OriginationUrl creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return OriginationUrl.fromJson(response.getStream(), client.getObjectMapper()); + return OriginationUrl.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (weight != null) { request.addPostParam("Weight", weight.toString()); - } if (priority != null) { request.addPostParam("Priority", priority.toString()); - } if (enabled != null) { request.addPostParam("Enabled", enabled.toString()); - } if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (sipUrl != null) { request.addPostParam("SipUrl", sipUrl.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/trunking/v1/trunk/OriginationUrlDeleter.java b/src/main/java/com/twilio/rest/trunking/v1/trunk/OriginationUrlDeleter.java index d473ef2749..6bade0e436 100644 --- a/src/main/java/com/twilio/rest/trunking/v1/trunk/OriginationUrlDeleter.java +++ b/src/main/java/com/twilio/rest/trunking/v1/trunk/OriginationUrlDeleter.java @@ -24,24 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class OriginationUrlDeleter extends Deleter { + private String pathTrunkSid; private String pathSid; - public OriginationUrlDeleter(final String pathTrunkSid, final String pathSid){ + public OriginationUrlDeleter( + final String pathTrunkSid, + final String pathSid + ) { this.pathTrunkSid = pathTrunkSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Trunks/{TrunkSid}/OriginationUrls/{Sid}"; - path = path.replace("{"+"TrunkSid"+"}", this.pathTrunkSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace("{" + "TrunkSid" + "}", this.pathTrunkSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +53,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("OriginationUrl delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "OriginationUrl delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/trunking/v1/trunk/OriginationUrlFetcher.java b/src/main/java/com/twilio/rest/trunking/v1/trunk/OriginationUrlFetcher.java index c574496f4b..f8ddfd8a9d 100644 --- a/src/main/java/com/twilio/rest/trunking/v1/trunk/OriginationUrlFetcher.java +++ b/src/main/java/com/twilio/rest/trunking/v1/trunk/OriginationUrlFetcher.java @@ -24,25 +24,26 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class OriginationUrlFetcher extends Fetcher { + private String pathTrunkSid; private String pathSid; - public OriginationUrlFetcher(final String pathTrunkSid, final String pathSid){ + public OriginationUrlFetcher( + final String pathTrunkSid, + final String pathSid + ) { this.pathTrunkSid = pathTrunkSid; this.pathSid = pathSid; } - @Override public OriginationUrl fetch(final TwilioRestClient client) { String path = "/v1/Trunks/{TrunkSid}/OriginationUrls/{Sid}"; - path = path.replace("{"+"TrunkSid"+"}", this.pathTrunkSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace("{" + "TrunkSid" + "}", this.pathTrunkSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,15 +53,23 @@ public OriginationUrl fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("OriginationUrl fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "OriginationUrl fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return OriginationUrl.fromJson(response.getStream(), client.getObjectMapper()); + return OriginationUrl.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/trunking/v1/trunk/OriginationUrlReader.java b/src/main/java/com/twilio/rest/trunking/v1/trunk/OriginationUrlReader.java index 1d49d533e1..6280d4fb59 100644 --- a/src/main/java/com/twilio/rest/trunking/v1/trunk/OriginationUrlReader.java +++ b/src/main/java/com/twilio/rest/trunking/v1/trunk/OriginationUrlReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.trunking.v1.trunk; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,19 +25,17 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class OriginationUrlReader extends Reader { + private String pathTrunkSid; private Integer pageSize; - public OriginationUrlReader(final String pathTrunkSid){ + public OriginationUrlReader(final String pathTrunkSid) { this.pathTrunkSid = pathTrunkSid; } - public OriginationUrlReader setPageSize(final Integer pageSize){ + public OriginationUrlReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -48,7 +47,8 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Trunks/{TrunkSid}/OriginationUrls"; - path = path.replace("{"+"TrunkSid"+"}", this.pathTrunkSid.toString()); + path = + path.replace("{" + "TrunkSid" + "}", this.pathTrunkSid.toString()); Request request = new Request( HttpMethod.GET, @@ -60,13 +60,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("OriginationUrl read failed: Unable to connect to server"); + throw new ApiConnectionException( + "OriginationUrl read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +90,10 @@ private Page pageForRequest(final TwilioRestClient client, final } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.TRUNKING.toString()) @@ -90,9 +101,11 @@ public Page previousPage(final Page page, final return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.TRUNKING.toString()) @@ -101,21 +114,21 @@ public Page nextPage(final Page page, final Twil } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/trunking/v1/trunk/OriginationUrlUpdater.java b/src/main/java/com/twilio/rest/trunking/v1/trunk/OriginationUrlUpdater.java index a7a9632265..56bc413ba3 100644 --- a/src/main/java/com/twilio/rest/trunking/v1/trunk/OriginationUrlUpdater.java +++ b/src/main/java/com/twilio/rest/trunking/v1/trunk/OriginationUrlUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.trunking.v1.trunk; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -24,12 +25,10 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.net.URI; +public class OriginationUrlUpdater extends Updater { - -public class OriginationUrlUpdater extends Updater{ private String pathTrunkSid; private String pathSid; private Integer weight; @@ -38,82 +37,95 @@ public class OriginationUrlUpdater extends Updater{ private String friendlyName; private URI sipUrl; - public OriginationUrlUpdater(final String pathTrunkSid, final String pathSid){ + public OriginationUrlUpdater( + final String pathTrunkSid, + final String pathSid + ) { this.pathTrunkSid = pathTrunkSid; this.pathSid = pathSid; } - public OriginationUrlUpdater setWeight(final Integer weight){ + public OriginationUrlUpdater setWeight(final Integer weight) { this.weight = weight; return this; } - public OriginationUrlUpdater setPriority(final Integer priority){ + + public OriginationUrlUpdater setPriority(final Integer priority) { this.priority = priority; return this; } - public OriginationUrlUpdater setEnabled(final Boolean enabled){ + + public OriginationUrlUpdater setEnabled(final Boolean enabled) { this.enabled = enabled; return this; } - public OriginationUrlUpdater setFriendlyName(final String friendlyName){ + + public OriginationUrlUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public OriginationUrlUpdater setSipUrl(final URI sipUrl){ + + public OriginationUrlUpdater setSipUrl(final URI sipUrl) { this.sipUrl = sipUrl; return this; } - public OriginationUrlUpdater setSipUrl(final String sipUrl){ + public OriginationUrlUpdater setSipUrl(final String sipUrl) { return setSipUrl(Promoter.uriFromString(sipUrl)); } @Override - public OriginationUrl update(final TwilioRestClient client){ + public OriginationUrl update(final TwilioRestClient client) { String path = "/v1/Trunks/{TrunkSid}/OriginationUrls/{Sid}"; - path = path.replace("{"+"TrunkSid"+"}", this.pathTrunkSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace("{" + "TrunkSid" + "}", this.pathTrunkSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.TRUNKING.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("OriginationUrl update failed: Unable to connect to server"); + throw new ApiConnectionException( + "OriginationUrl update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return OriginationUrl.fromJson(response.getStream(), client.getObjectMapper()); + return OriginationUrl.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (weight != null) { request.addPostParam("Weight", weight.toString()); - } if (priority != null) { request.addPostParam("Priority", priority.toString()); - } if (enabled != null) { request.addPostParam("Enabled", enabled.toString()); - } if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (sipUrl != null) { request.addPostParam("SipUrl", sipUrl.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/trunking/v1/trunk/PhoneNumber.java b/src/main/java/com/twilio/rest/trunking/v1/trunk/PhoneNumber.java index f2bf44e160..7b05a76ec3 100644 --- a/src/main/java/com/twilio/rest/trunking/v1/trunk/PhoneNumber.java +++ b/src/main/java/com/twilio/rest/trunking/v1/trunk/PhoneNumber.java @@ -24,52 +24,60 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; import com.twilio.http.HttpMethod; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class PhoneNumber extends Resource { + private static final long serialVersionUID = 92972440584956L; - public static PhoneNumberCreator creator(final String pathTrunkSid, final String phoneNumberSid){ + public static PhoneNumberCreator creator( + final String pathTrunkSid, + final String phoneNumberSid + ) { return new PhoneNumberCreator(pathTrunkSid, phoneNumberSid); } - public static PhoneNumberDeleter deleter(final String pathTrunkSid, final String pathSid){ + public static PhoneNumberDeleter deleter( + final String pathTrunkSid, + final String pathSid + ) { return new PhoneNumberDeleter(pathTrunkSid, pathSid); } - public static PhoneNumberFetcher fetcher(final String pathTrunkSid, final String pathSid){ + public static PhoneNumberFetcher fetcher( + final String pathTrunkSid, + final String pathSid + ) { return new PhoneNumberFetcher(pathTrunkSid, pathSid); } - public static PhoneNumberReader reader(final String pathTrunkSid){ + public static PhoneNumberReader reader(final String pathTrunkSid) { return new PhoneNumberReader(pathTrunkSid); } /** - * Converts a JSON String into a PhoneNumber object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return PhoneNumber object represented by the provided JSON - */ - public static PhoneNumber fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a PhoneNumber object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return PhoneNumber object represented by the provided JSON + */ + public static PhoneNumber fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, PhoneNumber.class); @@ -81,14 +89,17 @@ public static PhoneNumber fromJson(final String json, final ObjectMapper objectM } /** - * Converts a JSON InputStream into a PhoneNumber object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return PhoneNumber object represented by the provided JSON - */ - public static PhoneNumber fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a PhoneNumber object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return PhoneNumber object represented by the provided JSON + */ + public static PhoneNumber fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, PhoneNumber.class); @@ -98,6 +109,7 @@ public static PhoneNumber fromJson(final InputStream json, final ObjectMapper ob throw new ApiConnectionException(e.getMessage(), e); } } + public enum AddressRequirement { NONE("none"), ANY("any"), @@ -149,83 +161,42 @@ public static AddressRequirement forValue(final String value) { @JsonCreator private PhoneNumber( - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("address_requirements") - final PhoneNumber.AddressRequirement addressRequirements, - - @JsonProperty("api_version") - final String apiVersion, - - @JsonProperty("beta") - final Boolean beta, - - @JsonProperty("capabilities") - final Map capabilities, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("links") - final Map links, - - @JsonProperty("phone_number") - final com.twilio.type.PhoneNumber phoneNumber, - - @JsonProperty("sid") - final String sid, - - @JsonProperty("sms_application_sid") - final String smsApplicationSid, - - @JsonProperty("sms_fallback_method") - final HttpMethod smsFallbackMethod, - - @JsonProperty("sms_fallback_url") - final URI smsFallbackUrl, - - @JsonProperty("sms_method") - final HttpMethod smsMethod, - - @JsonProperty("sms_url") - final URI smsUrl, - - @JsonProperty("status_callback") - final URI statusCallback, - - @JsonProperty("status_callback_method") - final HttpMethod statusCallbackMethod, - - @JsonProperty("trunk_sid") - final String trunkSid, - - @JsonProperty("url") - final URI url, - - @JsonProperty("voice_application_sid") - final String voiceApplicationSid, - - @JsonProperty("voice_caller_id_lookup") - final Boolean voiceCallerIdLookup, - - @JsonProperty("voice_fallback_method") - final HttpMethod voiceFallbackMethod, - - @JsonProperty("voice_fallback_url") - final URI voiceFallbackUrl, - - @JsonProperty("voice_method") - final HttpMethod voiceMethod, - - @JsonProperty("voice_url") - final URI voiceUrl + @JsonProperty("account_sid") final String accountSid, + @JsonProperty( + "address_requirements" + ) final PhoneNumber.AddressRequirement addressRequirements, + @JsonProperty("api_version") final String apiVersion, + @JsonProperty("beta") final Boolean beta, + @JsonProperty("capabilities") final Map capabilities, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("links") final Map links, + @JsonProperty( + "phone_number" + ) final com.twilio.type.PhoneNumber phoneNumber, + @JsonProperty("sid") final String sid, + @JsonProperty("sms_application_sid") final String smsApplicationSid, + @JsonProperty("sms_fallback_method") final HttpMethod smsFallbackMethod, + @JsonProperty("sms_fallback_url") final URI smsFallbackUrl, + @JsonProperty("sms_method") final HttpMethod smsMethod, + @JsonProperty("sms_url") final URI smsUrl, + @JsonProperty("status_callback") final URI statusCallback, + @JsonProperty( + "status_callback_method" + ) final HttpMethod statusCallbackMethod, + @JsonProperty("trunk_sid") final String trunkSid, + @JsonProperty("url") final URI url, + @JsonProperty("voice_application_sid") final String voiceApplicationSid, + @JsonProperty( + "voice_caller_id_lookup" + ) final Boolean voiceCallerIdLookup, + @JsonProperty( + "voice_fallback_method" + ) final HttpMethod voiceFallbackMethod, + @JsonProperty("voice_fallback_url") final URI voiceFallbackUrl, + @JsonProperty("voice_method") final HttpMethod voiceMethod, + @JsonProperty("voice_url") final URI voiceUrl ) { this.accountSid = accountSid; this.addressRequirements = addressRequirements; @@ -255,88 +226,113 @@ private PhoneNumber( this.voiceUrl = voiceUrl; } - public final String getAccountSid() { - return this.accountSid; - } - public final PhoneNumber.AddressRequirement getAddressRequirements() { - return this.addressRequirements; - } - public final String getApiVersion() { - return this.apiVersion; - } - public final Boolean getBeta() { - return this.beta; - } - public final Map getCapabilities() { - return this.capabilities; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final Map getLinks() { - return this.links; - } - public final com.twilio.type.PhoneNumber getPhoneNumber() { - return this.phoneNumber; - } - public final String getSid() { - return this.sid; - } - public final String getSmsApplicationSid() { - return this.smsApplicationSid; - } - public final HttpMethod getSmsFallbackMethod() { - return this.smsFallbackMethod; - } - public final URI getSmsFallbackUrl() { - return this.smsFallbackUrl; - } - public final HttpMethod getSmsMethod() { - return this.smsMethod; - } - public final URI getSmsUrl() { - return this.smsUrl; - } - public final URI getStatusCallback() { - return this.statusCallback; - } - public final HttpMethod getStatusCallbackMethod() { - return this.statusCallbackMethod; - } - public final String getTrunkSid() { - return this.trunkSid; - } - public final URI getUrl() { - return this.url; - } - public final String getVoiceApplicationSid() { - return this.voiceApplicationSid; - } - public final Boolean getVoiceCallerIdLookup() { - return this.voiceCallerIdLookup; - } - public final HttpMethod getVoiceFallbackMethod() { - return this.voiceFallbackMethod; - } - public final URI getVoiceFallbackUrl() { - return this.voiceFallbackUrl; - } - public final HttpMethod getVoiceMethod() { - return this.voiceMethod; - } - public final URI getVoiceUrl() { - return this.voiceUrl; - } + public final String getAccountSid() { + return this.accountSid; + } + + public final PhoneNumber.AddressRequirement getAddressRequirements() { + return this.addressRequirements; + } + + public final String getApiVersion() { + return this.apiVersion; + } + + public final Boolean getBeta() { + return this.beta; + } + + public final Map getCapabilities() { + return this.capabilities; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final Map getLinks() { + return this.links; + } + + public final com.twilio.type.PhoneNumber getPhoneNumber() { + return this.phoneNumber; + } + + public final String getSid() { + return this.sid; + } + + public final String getSmsApplicationSid() { + return this.smsApplicationSid; + } + + public final HttpMethod getSmsFallbackMethod() { + return this.smsFallbackMethod; + } + + public final URI getSmsFallbackUrl() { + return this.smsFallbackUrl; + } + + public final HttpMethod getSmsMethod() { + return this.smsMethod; + } + + public final URI getSmsUrl() { + return this.smsUrl; + } + + public final URI getStatusCallback() { + return this.statusCallback; + } + + public final HttpMethod getStatusCallbackMethod() { + return this.statusCallbackMethod; + } + + public final String getTrunkSid() { + return this.trunkSid; + } + + public final URI getUrl() { + return this.url; + } + + public final String getVoiceApplicationSid() { + return this.voiceApplicationSid; + } + + public final Boolean getVoiceCallerIdLookup() { + return this.voiceCallerIdLookup; + } + + public final HttpMethod getVoiceFallbackMethod() { + return this.voiceFallbackMethod; + } + + public final URI getVoiceFallbackUrl() { + return this.voiceFallbackUrl; + } + + public final HttpMethod getVoiceMethod() { + return this.voiceMethod; + } + + public final URI getVoiceUrl() { + return this.voiceUrl; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -346,13 +342,65 @@ public boolean equals(final Object o) { PhoneNumber other = (PhoneNumber) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(addressRequirements, other.addressRequirements) && Objects.equals(apiVersion, other.apiVersion) && Objects.equals(beta, other.beta) && Objects.equals(capabilities, other.capabilities) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(links, other.links) && Objects.equals(phoneNumber, other.phoneNumber) && Objects.equals(sid, other.sid) && Objects.equals(smsApplicationSid, other.smsApplicationSid) && Objects.equals(smsFallbackMethod, other.smsFallbackMethod) && Objects.equals(smsFallbackUrl, other.smsFallbackUrl) && Objects.equals(smsMethod, other.smsMethod) && Objects.equals(smsUrl, other.smsUrl) && Objects.equals(statusCallback, other.statusCallback) && Objects.equals(statusCallbackMethod, other.statusCallbackMethod) && Objects.equals(trunkSid, other.trunkSid) && Objects.equals(url, other.url) && Objects.equals(voiceApplicationSid, other.voiceApplicationSid) && Objects.equals(voiceCallerIdLookup, other.voiceCallerIdLookup) && Objects.equals(voiceFallbackMethod, other.voiceFallbackMethod) && Objects.equals(voiceFallbackUrl, other.voiceFallbackUrl) && Objects.equals(voiceMethod, other.voiceMethod) && Objects.equals(voiceUrl, other.voiceUrl) ; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(addressRequirements, other.addressRequirements) && + Objects.equals(apiVersion, other.apiVersion) && + Objects.equals(beta, other.beta) && + Objects.equals(capabilities, other.capabilities) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(links, other.links) && + Objects.equals(phoneNumber, other.phoneNumber) && + Objects.equals(sid, other.sid) && + Objects.equals(smsApplicationSid, other.smsApplicationSid) && + Objects.equals(smsFallbackMethod, other.smsFallbackMethod) && + Objects.equals(smsFallbackUrl, other.smsFallbackUrl) && + Objects.equals(smsMethod, other.smsMethod) && + Objects.equals(smsUrl, other.smsUrl) && + Objects.equals(statusCallback, other.statusCallback) && + Objects.equals(statusCallbackMethod, other.statusCallbackMethod) && + Objects.equals(trunkSid, other.trunkSid) && + Objects.equals(url, other.url) && + Objects.equals(voiceApplicationSid, other.voiceApplicationSid) && + Objects.equals(voiceCallerIdLookup, other.voiceCallerIdLookup) && + Objects.equals(voiceFallbackMethod, other.voiceFallbackMethod) && + Objects.equals(voiceFallbackUrl, other.voiceFallbackUrl) && + Objects.equals(voiceMethod, other.voiceMethod) && + Objects.equals(voiceUrl, other.voiceUrl) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, addressRequirements, apiVersion, beta, capabilities, dateCreated, dateUpdated, friendlyName, links, phoneNumber, sid, smsApplicationSid, smsFallbackMethod, smsFallbackUrl, smsMethod, smsUrl, statusCallback, statusCallbackMethod, trunkSid, url, voiceApplicationSid, voiceCallerIdLookup, voiceFallbackMethod, voiceFallbackUrl, voiceMethod, voiceUrl); + return Objects.hash( + accountSid, + addressRequirements, + apiVersion, + beta, + capabilities, + dateCreated, + dateUpdated, + friendlyName, + links, + phoneNumber, + sid, + smsApplicationSid, + smsFallbackMethod, + smsFallbackUrl, + smsMethod, + smsUrl, + statusCallback, + statusCallbackMethod, + trunkSid, + url, + voiceApplicationSid, + voiceCallerIdLookup, + voiceFallbackMethod, + voiceFallbackUrl, + voiceMethod, + voiceUrl + ); } - } - diff --git a/src/main/java/com/twilio/rest/trunking/v1/trunk/PhoneNumberCreator.java b/src/main/java/com/twilio/rest/trunking/v1/trunk/PhoneNumberCreator.java index cdbeceed95..99747fedd2 100644 --- a/src/main/java/com/twilio/rest/trunking/v1/trunk/PhoneNumberCreator.java +++ b/src/main/java/com/twilio/rest/trunking/v1/trunk/PhoneNumberCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.trunking.v1.trunk; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,53 +25,68 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class PhoneNumberCreator extends Creator { - - -public class PhoneNumberCreator extends Creator{ private String pathTrunkSid; private String phoneNumberSid; - public PhoneNumberCreator(final String pathTrunkSid, final String phoneNumberSid) { + public PhoneNumberCreator( + final String pathTrunkSid, + final String phoneNumberSid + ) { this.pathTrunkSid = pathTrunkSid; this.phoneNumberSid = phoneNumberSid; } - public PhoneNumberCreator setPhoneNumberSid(final String phoneNumberSid){ + public PhoneNumberCreator setPhoneNumberSid(final String phoneNumberSid) { this.phoneNumberSid = phoneNumberSid; return this; } @Override - public PhoneNumber create(final TwilioRestClient client){ + public PhoneNumber create(final TwilioRestClient client) { String path = "/v1/Trunks/{TrunkSid}/PhoneNumbers"; - path = path.replace("{"+"TrunkSid"+"}", this.pathTrunkSid.toString()); - path = path.replace("{"+"PhoneNumberSid"+"}", this.phoneNumberSid.toString()); + path = + path.replace("{" + "TrunkSid" + "}", this.pathTrunkSid.toString()); + path = + path.replace( + "{" + "PhoneNumberSid" + "}", + this.phoneNumberSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.TRUNKING.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("PhoneNumber creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "PhoneNumber creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return PhoneNumber.fromJson(response.getStream(), client.getObjectMapper()); + return PhoneNumber.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (phoneNumberSid != null) { request.addPostParam("PhoneNumberSid", phoneNumberSid); - } } } diff --git a/src/main/java/com/twilio/rest/trunking/v1/trunk/PhoneNumberDeleter.java b/src/main/java/com/twilio/rest/trunking/v1/trunk/PhoneNumberDeleter.java index 63a70c9085..be1b10c6ef 100644 --- a/src/main/java/com/twilio/rest/trunking/v1/trunk/PhoneNumberDeleter.java +++ b/src/main/java/com/twilio/rest/trunking/v1/trunk/PhoneNumberDeleter.java @@ -24,24 +24,23 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class PhoneNumberDeleter extends Deleter { + private String pathTrunkSid; private String pathSid; - public PhoneNumberDeleter(final String pathTrunkSid, final String pathSid){ + public PhoneNumberDeleter(final String pathTrunkSid, final String pathSid) { this.pathTrunkSid = pathTrunkSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/Trunks/{TrunkSid}/PhoneNumbers/{Sid}"; - path = path.replace("{"+"TrunkSid"+"}", this.pathTrunkSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace("{" + "TrunkSid" + "}", this.pathTrunkSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +50,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("PhoneNumber delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "PhoneNumber delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/trunking/v1/trunk/PhoneNumberFetcher.java b/src/main/java/com/twilio/rest/trunking/v1/trunk/PhoneNumberFetcher.java index 49fe8b4041..ada7dd7a79 100644 --- a/src/main/java/com/twilio/rest/trunking/v1/trunk/PhoneNumberFetcher.java +++ b/src/main/java/com/twilio/rest/trunking/v1/trunk/PhoneNumberFetcher.java @@ -24,25 +24,23 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class PhoneNumberFetcher extends Fetcher { + private String pathTrunkSid; private String pathSid; - public PhoneNumberFetcher(final String pathTrunkSid, final String pathSid){ + public PhoneNumberFetcher(final String pathTrunkSid, final String pathSid) { this.pathTrunkSid = pathTrunkSid; this.pathSid = pathSid; } - @Override public PhoneNumber fetch(final TwilioRestClient client) { String path = "/v1/Trunks/{TrunkSid}/PhoneNumbers/{Sid}"; - path = path.replace("{"+"TrunkSid"+"}", this.pathTrunkSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace("{" + "TrunkSid" + "}", this.pathTrunkSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,15 +50,23 @@ public PhoneNumber fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("PhoneNumber fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "PhoneNumber fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return PhoneNumber.fromJson(response.getStream(), client.getObjectMapper()); + return PhoneNumber.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/trunking/v1/trunk/PhoneNumberReader.java b/src/main/java/com/twilio/rest/trunking/v1/trunk/PhoneNumberReader.java index 7094c79082..a2f8d7ab34 100644 --- a/src/main/java/com/twilio/rest/trunking/v1/trunk/PhoneNumberReader.java +++ b/src/main/java/com/twilio/rest/trunking/v1/trunk/PhoneNumberReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.trunking.v1.trunk; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,19 +25,17 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class PhoneNumberReader extends Reader { + private String pathTrunkSid; private Integer pageSize; - public PhoneNumberReader(final String pathTrunkSid){ + public PhoneNumberReader(final String pathTrunkSid) { this.pathTrunkSid = pathTrunkSid; } - public PhoneNumberReader setPageSize(final Integer pageSize){ + public PhoneNumberReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -48,7 +47,8 @@ public ResourceSet read(final TwilioRestClient client) { public Page firstPage(final TwilioRestClient client) { String path = "/v1/Trunks/{TrunkSid}/PhoneNumbers"; - path = path.replace("{"+"TrunkSid"+"}", this.pathTrunkSid.toString()); + path = + path.replace("{" + "TrunkSid" + "}", this.pathTrunkSid.toString()); Request request = new Request( HttpMethod.GET, @@ -60,13 +60,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("PhoneNumber read failed: Unable to connect to server"); + throw new ApiConnectionException( + "PhoneNumber read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +90,10 @@ private Page pageForRequest(final TwilioRestClient client, final Re } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.TRUNKING.toString()) @@ -90,9 +101,11 @@ public Page previousPage(final Page page, final Twilio return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.TRUNKING.toString()) @@ -101,21 +114,21 @@ public Page nextPage(final Page page, final TwilioRest } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/trunking/v1/trunk/Recording.java b/src/main/java/com/twilio/rest/trunking/v1/trunk/Recording.java index 2cc240c376..5cb163059f 100644 --- a/src/main/java/com/twilio/rest/trunking/v1/trunk/Recording.java +++ b/src/main/java/com/twilio/rest/trunking/v1/trunk/Recording.java @@ -23,39 +23,38 @@ import com.twilio.base.Resource; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Recording extends Resource { + private static final long serialVersionUID = 230784342010429L; - public static RecordingFetcher fetcher(final String pathTrunkSid){ + public static RecordingFetcher fetcher(final String pathTrunkSid) { return new RecordingFetcher(pathTrunkSid); } - public static RecordingUpdater updater(final String pathTrunkSid){ + public static RecordingUpdater updater(final String pathTrunkSid) { return new RecordingUpdater(pathTrunkSid); } /** - * Converts a JSON String into a Recording object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Recording object represented by the provided JSON - */ - public static Recording fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Recording object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Recording object represented by the provided JSON + */ + public static Recording fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Recording.class); @@ -67,14 +66,17 @@ public static Recording fromJson(final String json, final ObjectMapper objectMap } /** - * Converts a JSON InputStream into a Recording object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Recording object represented by the provided JSON - */ - public static Recording fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Recording object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Recording object represented by the provided JSON + */ + public static Recording fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Recording.class); @@ -84,6 +86,7 @@ public static Recording fromJson(final InputStream json, final ObjectMapper obje throw new ApiConnectionException(e.getMessage(), e); } } + public enum RecordingMode { DO_NOT_RECORD("do-not-record"), RECORD_FROM_RINGING("record-from-ringing"), @@ -106,6 +109,7 @@ public static RecordingMode forValue(final String value) { return Promoter.enumFromString(value, RecordingMode.values()); } } + public enum RecordingTrim { TRIM_SILENCE("trim-silence"), DO_NOT_TRIM("do-not-trim"); @@ -131,26 +135,24 @@ public static RecordingTrim forValue(final String value) { @JsonCreator private Recording( - @JsonProperty("mode") - final Recording.RecordingMode mode, - - @JsonProperty("trim") - final Recording.RecordingTrim trim + @JsonProperty("mode") final Recording.RecordingMode mode, + @JsonProperty("trim") final Recording.RecordingTrim trim ) { this.mode = mode; this.trim = trim; } - public final Recording.RecordingMode getMode() { - return this.mode; - } - public final Recording.RecordingTrim getTrim() { - return this.trim; - } + public final Recording.RecordingMode getMode() { + return this.mode; + } + + public final Recording.RecordingTrim getTrim() { + return this.trim; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -160,13 +162,13 @@ public boolean equals(final Object o) { Recording other = (Recording) o; - return Objects.equals(mode, other.mode) && Objects.equals(trim, other.trim) ; + return ( + Objects.equals(mode, other.mode) && Objects.equals(trim, other.trim) + ); } @Override public int hashCode() { return Objects.hash(mode, trim); } - } - diff --git a/src/main/java/com/twilio/rest/trunking/v1/trunk/RecordingFetcher.java b/src/main/java/com/twilio/rest/trunking/v1/trunk/RecordingFetcher.java index 1e4f02abf4..5de9e28cc5 100644 --- a/src/main/java/com/twilio/rest/trunking/v1/trunk/RecordingFetcher.java +++ b/src/main/java/com/twilio/rest/trunking/v1/trunk/RecordingFetcher.java @@ -24,22 +24,20 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class RecordingFetcher extends Fetcher { + private String pathTrunkSid; - public RecordingFetcher(final String pathTrunkSid){ + public RecordingFetcher(final String pathTrunkSid) { this.pathTrunkSid = pathTrunkSid; } - @Override public Recording fetch(final TwilioRestClient client) { String path = "/v1/Trunks/{TrunkSid}/Recording"; - path = path.replace("{"+"TrunkSid"+"}", this.pathTrunkSid.toString()); + path = + path.replace("{" + "TrunkSid" + "}", this.pathTrunkSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,15 +47,23 @@ public Recording fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Recording fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Recording fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Recording.fromJson(response.getStream(), client.getObjectMapper()); + return Recording.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/trunking/v1/trunk/RecordingUpdater.java b/src/main/java/com/twilio/rest/trunking/v1/trunk/RecordingUpdater.java index 17a6da14d7..54098d2569 100644 --- a/src/main/java/com/twilio/rest/trunking/v1/trunk/RecordingUpdater.java +++ b/src/main/java/com/twilio/rest/trunking/v1/trunk/RecordingUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.trunking.v1.trunk; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,60 +25,68 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class RecordingUpdater extends Updater { - - -public class RecordingUpdater extends Updater{ private String pathTrunkSid; private Recording.RecordingMode mode; private Recording.RecordingTrim trim; - public RecordingUpdater(final String pathTrunkSid){ + public RecordingUpdater(final String pathTrunkSid) { this.pathTrunkSid = pathTrunkSid; } - public RecordingUpdater setMode(final Recording.RecordingMode mode){ + public RecordingUpdater setMode(final Recording.RecordingMode mode) { this.mode = mode; return this; } - public RecordingUpdater setTrim(final Recording.RecordingTrim trim){ + + public RecordingUpdater setTrim(final Recording.RecordingTrim trim) { this.trim = trim; return this; } @Override - public Recording update(final TwilioRestClient client){ + public Recording update(final TwilioRestClient client) { String path = "/v1/Trunks/{TrunkSid}/Recording"; - path = path.replace("{"+"TrunkSid"+"}", this.pathTrunkSid.toString()); + path = + path.replace("{" + "TrunkSid" + "}", this.pathTrunkSid.toString()); Request request = new Request( HttpMethod.POST, Domains.TRUNKING.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Recording update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Recording update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Recording.fromJson(response.getStream(), client.getObjectMapper()); + return Recording.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (mode != null) { request.addPostParam("Mode", mode.toString()); - } if (trim != null) { request.addPostParam("Trim", trim.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/trusthub/v1/CustomerProfiles.java b/src/main/java/com/twilio/rest/trusthub/v1/CustomerProfiles.java index e86a8dcee5..ec4b7805ae 100644 --- a/src/main/java/com/twilio/rest/trusthub/v1/CustomerProfiles.java +++ b/src/main/java/com/twilio/rest/trusthub/v1/CustomerProfiles.java @@ -24,55 +24,58 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class CustomerProfiles extends Resource { + private static final long serialVersionUID = 110971930651423L; - public static CustomerProfilesCreator creator(final String friendlyName, final String email, final String policySid){ + public static CustomerProfilesCreator creator( + final String friendlyName, + final String email, + final String policySid + ) { return new CustomerProfilesCreator(friendlyName, email, policySid); } - public static CustomerProfilesDeleter deleter(final String pathSid){ + public static CustomerProfilesDeleter deleter(final String pathSid) { return new CustomerProfilesDeleter(pathSid); } - public static CustomerProfilesFetcher fetcher(final String pathSid){ + public static CustomerProfilesFetcher fetcher(final String pathSid) { return new CustomerProfilesFetcher(pathSid); } - public static CustomerProfilesReader reader(){ + public static CustomerProfilesReader reader() { return new CustomerProfilesReader(); } - public static CustomerProfilesUpdater updater(final String pathSid){ + public static CustomerProfilesUpdater updater(final String pathSid) { return new CustomerProfilesUpdater(pathSid); } /** - * Converts a JSON String into a CustomerProfiles object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return CustomerProfiles object represented by the provided JSON - */ - public static CustomerProfiles fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a CustomerProfiles object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return CustomerProfiles object represented by the provided JSON + */ + public static CustomerProfiles fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, CustomerProfiles.class); @@ -84,14 +87,17 @@ public static CustomerProfiles fromJson(final String json, final ObjectMapper ob } /** - * Converts a JSON InputStream into a CustomerProfiles object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return CustomerProfiles object represented by the provided JSON - */ - public static CustomerProfiles fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a CustomerProfiles object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return CustomerProfiles object represented by the provided JSON + */ + public static CustomerProfiles fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, CustomerProfiles.class); @@ -101,6 +107,7 @@ public static CustomerProfiles fromJson(final InputStream json, final ObjectMapp throw new ApiConnectionException(e.getMessage(), e); } } + public enum Status { DRAFT("draft"), PENDING_REVIEW("pending-review"), @@ -139,41 +146,18 @@ public static Status forValue(final String value) { @JsonCreator private CustomerProfiles( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("policy_sid") - final String policySid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("status") - final CustomerProfiles.Status status, - - @JsonProperty("valid_until") - final String validUntil, - - @JsonProperty("email") - final String email, - - @JsonProperty("status_callback") - final URI statusCallback, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("policy_sid") final String policySid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("status") final CustomerProfiles.Status status, + @JsonProperty("valid_until") final String validUntil, + @JsonProperty("email") final String email, + @JsonProperty("status_callback") final URI statusCallback, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.sid = sid; this.accountSid = accountSid; @@ -189,46 +173,57 @@ private CustomerProfiles( this.links = links; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getPolicySid() { - return this.policySid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final CustomerProfiles.Status getStatus() { - return this.status; - } - public final ZonedDateTime getValidUntil() { - return this.validUntil; - } - public final String getEmail() { - return this.email; - } - public final URI getStatusCallback() { - return this.statusCallback; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getPolicySid() { + return this.policySid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final CustomerProfiles.Status getStatus() { + return this.status; + } + + public final ZonedDateTime getValidUntil() { + return this.validUntil; + } + + public final String getEmail() { + return this.email; + } + + public final URI getStatusCallback() { + return this.statusCallback; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -238,13 +233,37 @@ public boolean equals(final Object o) { CustomerProfiles other = (CustomerProfiles) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(policySid, other.policySid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(status, other.status) && Objects.equals(validUntil, other.validUntil) && Objects.equals(email, other.email) && Objects.equals(statusCallback, other.statusCallback) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(policySid, other.policySid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(status, other.status) && + Objects.equals(validUntil, other.validUntil) && + Objects.equals(email, other.email) && + Objects.equals(statusCallback, other.statusCallback) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, policySid, friendlyName, status, validUntil, email, statusCallback, dateCreated, dateUpdated, url, links); + return Objects.hash( + sid, + accountSid, + policySid, + friendlyName, + status, + validUntil, + email, + statusCallback, + dateCreated, + dateUpdated, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/trusthub/v1/CustomerProfilesCreator.java b/src/main/java/com/twilio/rest/trusthub/v1/CustomerProfilesCreator.java index 474eac9fd9..c855f1269d 100644 --- a/src/main/java/com/twilio/rest/trusthub/v1/CustomerProfilesCreator.java +++ b/src/main/java/com/twilio/rest/trusthub/v1/CustomerProfilesCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.trusthub.v1; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -25,87 +26,104 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.net.URI; - - - import java.net.URI; -public class CustomerProfilesCreator extends Creator{ +public class CustomerProfilesCreator extends Creator { + private String friendlyName; private String email; private String policySid; private URI statusCallback; - public CustomerProfilesCreator(final String friendlyName, final String email, final String policySid) { + public CustomerProfilesCreator( + final String friendlyName, + final String email, + final String policySid + ) { this.friendlyName = friendlyName; this.email = email; this.policySid = policySid; } - public CustomerProfilesCreator setFriendlyName(final String friendlyName){ + public CustomerProfilesCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public CustomerProfilesCreator setEmail(final String email){ + + public CustomerProfilesCreator setEmail(final String email) { this.email = email; return this; } - public CustomerProfilesCreator setPolicySid(final String policySid){ + + public CustomerProfilesCreator setPolicySid(final String policySid) { this.policySid = policySid; return this; } - public CustomerProfilesCreator setStatusCallback(final URI statusCallback){ + + public CustomerProfilesCreator setStatusCallback(final URI statusCallback) { this.statusCallback = statusCallback; return this; } - public CustomerProfilesCreator setStatusCallback(final String statusCallback){ + public CustomerProfilesCreator setStatusCallback( + final String statusCallback + ) { return setStatusCallback(Promoter.uriFromString(statusCallback)); } @Override - public CustomerProfiles create(final TwilioRestClient client){ + public CustomerProfiles create(final TwilioRestClient client) { String path = "/v1/CustomerProfiles"; - path = path.replace("{"+"FriendlyName"+"}", this.friendlyName.toString()); - path = path.replace("{"+"Email"+"}", this.email.toString()); - path = path.replace("{"+"PolicySid"+"}", this.policySid.toString()); + path = + path.replace( + "{" + "FriendlyName" + "}", + this.friendlyName.toString() + ); + path = path.replace("{" + "Email" + "}", this.email.toString()); + path = path.replace("{" + "PolicySid" + "}", this.policySid.toString()); Request request = new Request( HttpMethod.POST, Domains.TRUSTHUB.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("CustomerProfiles creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "CustomerProfiles creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return CustomerProfiles.fromJson(response.getStream(), client.getObjectMapper()); + return CustomerProfiles.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (email != null) { request.addPostParam("Email", email); - } if (policySid != null) { request.addPostParam("PolicySid", policySid); - } if (statusCallback != null) { request.addPostParam("StatusCallback", statusCallback.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/trusthub/v1/CustomerProfilesDeleter.java b/src/main/java/com/twilio/rest/trusthub/v1/CustomerProfilesDeleter.java index bfd9794544..6c72abe644 100644 --- a/src/main/java/com/twilio/rest/trusthub/v1/CustomerProfilesDeleter.java +++ b/src/main/java/com/twilio/rest/trusthub/v1/CustomerProfilesDeleter.java @@ -24,21 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class CustomerProfilesDeleter extends Deleter { + private String pathSid; - public CustomerProfilesDeleter(final String pathSid){ + public CustomerProfilesDeleter(final String pathSid) { this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/CustomerProfiles/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -48,9 +46,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("CustomerProfiles delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "CustomerProfiles delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/trusthub/v1/CustomerProfilesFetcher.java b/src/main/java/com/twilio/rest/trusthub/v1/CustomerProfilesFetcher.java index 9498dc59f6..aaf9950289 100644 --- a/src/main/java/com/twilio/rest/trusthub/v1/CustomerProfilesFetcher.java +++ b/src/main/java/com/twilio/rest/trusthub/v1/CustomerProfilesFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class CustomerProfilesFetcher extends Fetcher { + private String pathSid; - public CustomerProfilesFetcher(final String pathSid){ + public CustomerProfilesFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public CustomerProfiles fetch(final TwilioRestClient client) { String path = "/v1/CustomerProfiles/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,15 +46,23 @@ public CustomerProfiles fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("CustomerProfiles fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "CustomerProfiles fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return CustomerProfiles.fromJson(response.getStream(), client.getObjectMapper()); + return CustomerProfiles.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/trusthub/v1/CustomerProfilesReader.java b/src/main/java/com/twilio/rest/trusthub/v1/CustomerProfilesReader.java index b7c493fabd..877c0c429b 100644 --- a/src/main/java/com/twilio/rest/trusthub/v1/CustomerProfilesReader.java +++ b/src/main/java/com/twilio/rest/trusthub/v1/CustomerProfilesReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.trusthub.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,32 +25,34 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class CustomerProfilesReader extends Reader { + private CustomerProfiles.Status status; private String friendlyName; private String policySid; private Integer pageSize; - public CustomerProfilesReader(){ - } + public CustomerProfilesReader() {} - public CustomerProfilesReader setStatus(final CustomerProfiles.Status status){ + public CustomerProfilesReader setStatus( + final CustomerProfiles.Status status + ) { this.status = status; return this; } - public CustomerProfilesReader setFriendlyName(final String friendlyName){ + + public CustomerProfilesReader setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public CustomerProfilesReader setPolicySid(final String policySid){ + + public CustomerProfilesReader setPolicySid(final String policySid) { this.policySid = policySid; return this; } - public CustomerProfilesReader setPageSize(final Integer pageSize){ + + public CustomerProfilesReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -72,13 +75,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("CustomerProfiles read failed: Unable to connect to server"); + throw new ApiConnectionException( + "CustomerProfiles read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -94,7 +105,10 @@ private Page pageForRequest(final TwilioRestClient client, fin } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.TRUSTHUB.toString()) @@ -102,9 +116,11 @@ public Page previousPage(final Page page, fi return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.TRUSTHUB.toString()) @@ -113,33 +129,30 @@ public Page nextPage(final Page page, final } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (status != null) { - request.addQueryParam("Status", status.toString()); } if (friendlyName != null) { - request.addQueryParam("FriendlyName", friendlyName); } if (policySid != null) { - request.addQueryParam("PolicySid", policySid); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/trusthub/v1/CustomerProfilesUpdater.java b/src/main/java/com/twilio/rest/trusthub/v1/CustomerProfilesUpdater.java index 99037a3019..43756da375 100644 --- a/src/main/java/com/twilio/rest/trusthub/v1/CustomerProfilesUpdater.java +++ b/src/main/java/com/twilio/rest/trusthub/v1/CustomerProfilesUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.trusthub.v1; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -24,84 +25,95 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.net.URI; +public class CustomerProfilesUpdater extends Updater { - -public class CustomerProfilesUpdater extends Updater{ private String pathSid; private CustomerProfiles.Status status; private URI statusCallback; private String friendlyName; private String email; - public CustomerProfilesUpdater(final String pathSid){ + public CustomerProfilesUpdater(final String pathSid) { this.pathSid = pathSid; } - public CustomerProfilesUpdater setStatus(final CustomerProfiles.Status status){ + public CustomerProfilesUpdater setStatus( + final CustomerProfiles.Status status + ) { this.status = status; return this; } - public CustomerProfilesUpdater setStatusCallback(final URI statusCallback){ + + public CustomerProfilesUpdater setStatusCallback(final URI statusCallback) { this.statusCallback = statusCallback; return this; } - public CustomerProfilesUpdater setStatusCallback(final String statusCallback){ + public CustomerProfilesUpdater setStatusCallback( + final String statusCallback + ) { return setStatusCallback(Promoter.uriFromString(statusCallback)); } - public CustomerProfilesUpdater setFriendlyName(final String friendlyName){ + + public CustomerProfilesUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public CustomerProfilesUpdater setEmail(final String email){ + + public CustomerProfilesUpdater setEmail(final String email) { this.email = email; return this; } @Override - public CustomerProfiles update(final TwilioRestClient client){ + public CustomerProfiles update(final TwilioRestClient client) { String path = "/v1/CustomerProfiles/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.TRUSTHUB.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("CustomerProfiles update failed: Unable to connect to server"); + throw new ApiConnectionException( + "CustomerProfiles update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return CustomerProfiles.fromJson(response.getStream(), client.getObjectMapper()); + return CustomerProfiles.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (status != null) { request.addPostParam("Status", status.toString()); - } if (statusCallback != null) { request.addPostParam("StatusCallback", statusCallback.toString()); - } if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (email != null) { request.addPostParam("Email", email); - } } } diff --git a/src/main/java/com/twilio/rest/trusthub/v1/EndUser.java b/src/main/java/com/twilio/rest/trusthub/v1/EndUser.java index c641ae1c0a..01ca7832c3 100644 --- a/src/main/java/com/twilio/rest/trusthub/v1/EndUser.java +++ b/src/main/java/com/twilio/rest/trusthub/v1/EndUser.java @@ -23,55 +23,57 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class EndUser extends Resource { + private static final long serialVersionUID = 90504447987573L; - public static EndUserCreator creator(final String friendlyName, final String type){ + public static EndUserCreator creator( + final String friendlyName, + final String type + ) { return new EndUserCreator(friendlyName, type); } - public static EndUserDeleter deleter(final String pathSid){ + public static EndUserDeleter deleter(final String pathSid) { return new EndUserDeleter(pathSid); } - public static EndUserFetcher fetcher(final String pathSid){ + public static EndUserFetcher fetcher(final String pathSid) { return new EndUserFetcher(pathSid); } - public static EndUserReader reader(){ + public static EndUserReader reader() { return new EndUserReader(); } - public static EndUserUpdater updater(final String pathSid){ + public static EndUserUpdater updater(final String pathSid) { return new EndUserUpdater(pathSid); } /** - * Converts a JSON String into a EndUser object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return EndUser object represented by the provided JSON - */ - public static EndUser fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a EndUser object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return EndUser object represented by the provided JSON + */ + public static EndUser fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, EndUser.class); @@ -83,14 +85,17 @@ public static EndUser fromJson(final String json, final ObjectMapper objectMappe } /** - * Converts a JSON InputStream into a EndUser object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return EndUser object represented by the provided JSON - */ - public static EndUser fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a EndUser object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return EndUser object represented by the provided JSON + */ + public static EndUser fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, EndUser.class); @@ -112,29 +117,14 @@ public static EndUser fromJson(final InputStream json, final ObjectMapper object @JsonCreator private EndUser( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("type") - final String type, - - @JsonProperty("attributes") - final Map attributes, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("type") final String type, + @JsonProperty("attributes") final Map attributes, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url ) { this.sid = sid; this.accountSid = accountSid; @@ -146,34 +136,41 @@ private EndUser( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getType() { - return this.type; - } - public final Map getAttributes() { - return this.attributes; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getType() { + return this.type; + } + + public final Map getAttributes() { + return this.attributes; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -183,13 +180,29 @@ public boolean equals(final Object o) { EndUser other = (EndUser) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(type, other.type) && Objects.equals(attributes, other.attributes) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(type, other.type) && + Objects.equals(attributes, other.attributes) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, friendlyName, type, attributes, dateCreated, dateUpdated, url); + return Objects.hash( + sid, + accountSid, + friendlyName, + type, + attributes, + dateCreated, + dateUpdated, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/trusthub/v1/EndUserCreator.java b/src/main/java/com/twilio/rest/trusthub/v1/EndUserCreator.java index ef3a5914ed..5de9c0eb33 100644 --- a/src/main/java/com/twilio/rest/trusthub/v1/EndUserCreator.java +++ b/src/main/java/com/twilio/rest/trusthub/v1/EndUserCreator.java @@ -15,8 +15,10 @@ package com.twilio.rest.trusthub.v1; import com.twilio.base.Creator; -import com.twilio.exception.ApiConnectionException; +import com.twilio.constant.EnumConstants; +import com.twilio.converter.Converter; import com.twilio.converter.Converter; +import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; @@ -25,13 +27,10 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.util.Map; -import com.twilio.converter.Converter; - import java.util.Map; +public class EndUserCreator extends Creator { - -public class EndUserCreator extends Creator{ private String friendlyName; private String type; private Map attributes; @@ -41,37 +40,49 @@ public EndUserCreator(final String friendlyName, final String type) { this.type = type; } - public EndUserCreator setFriendlyName(final String friendlyName){ + public EndUserCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public EndUserCreator setType(final String type){ + + public EndUserCreator setType(final String type) { this.type = type; return this; } - public EndUserCreator setAttributes(final Map attributes){ + + public EndUserCreator setAttributes(final Map attributes) { this.attributes = attributes; return this; } @Override - public EndUser create(final TwilioRestClient client){ + public EndUser create(final TwilioRestClient client) { String path = "/v1/EndUsers"; - path = path.replace("{"+"FriendlyName"+"}", this.friendlyName.toString()); - path = path.replace("{"+"Type"+"}", this.type.toString()); + path = + path.replace( + "{" + "FriendlyName" + "}", + this.friendlyName.toString() + ); + path = path.replace("{" + "Type" + "}", this.type.toString()); Request request = new Request( HttpMethod.POST, Domains.TRUSTHUB.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("EndUser creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "EndUser creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -80,18 +91,16 @@ public EndUser create(final TwilioRestClient client){ return EndUser.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (type != null) { request.addPostParam("Type", type); - } if (attributes != null) { - request.addPostParam("Attributes", Converter.mapToJson(attributes)); - + request.addPostParam("Attributes", Converter.mapToJson(attributes)); } } } diff --git a/src/main/java/com/twilio/rest/trusthub/v1/EndUserDeleter.java b/src/main/java/com/twilio/rest/trusthub/v1/EndUserDeleter.java index af64c13bd4..de5a573ea6 100644 --- a/src/main/java/com/twilio/rest/trusthub/v1/EndUserDeleter.java +++ b/src/main/java/com/twilio/rest/trusthub/v1/EndUserDeleter.java @@ -24,21 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class EndUserDeleter extends Deleter { + private String pathSid; - public EndUserDeleter(final String pathSid){ + public EndUserDeleter(final String pathSid) { this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/EndUsers/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -48,9 +46,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("EndUser delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "EndUser delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/trusthub/v1/EndUserFetcher.java b/src/main/java/com/twilio/rest/trusthub/v1/EndUserFetcher.java index 47b0542da7..fbf326a704 100644 --- a/src/main/java/com/twilio/rest/trusthub/v1/EndUserFetcher.java +++ b/src/main/java/com/twilio/rest/trusthub/v1/EndUserFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class EndUserFetcher extends Fetcher { + private String pathSid; - public EndUserFetcher(final String pathSid){ + public EndUserFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public EndUser fetch(final TwilioRestClient client) { String path = "/v1/EndUsers/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,9 +46,14 @@ public EndUser fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("EndUser fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "EndUser fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/trusthub/v1/EndUserReader.java b/src/main/java/com/twilio/rest/trusthub/v1/EndUserReader.java index 6bb258b33d..d6a36687ca 100644 --- a/src/main/java/com/twilio/rest/trusthub/v1/EndUserReader.java +++ b/src/main/java/com/twilio/rest/trusthub/v1/EndUserReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.trusthub.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,17 +25,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class EndUserReader extends Reader { + private Integer pageSize; - public EndUserReader(){ - } + public EndUserReader() {} - public EndUserReader setPageSize(final Integer pageSize){ + public EndUserReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -57,13 +55,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("EndUser read failed: Unable to connect to server"); + throw new ApiConnectionException( + "EndUser read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -79,7 +85,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reques } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.TRUSTHUB.toString()) @@ -87,9 +96,11 @@ public Page previousPage(final Page page, final TwilioRestClie return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.TRUSTHUB.toString()) @@ -98,21 +109,21 @@ public Page nextPage(final Page page, final TwilioRestClient c } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/trusthub/v1/EndUserType.java b/src/main/java/com/twilio/rest/trusthub/v1/EndUserType.java index 071ead95c3..79b4a51626 100644 --- a/src/main/java/com/twilio/rest/trusthub/v1/EndUserType.java +++ b/src/main/java/com/twilio/rest/trusthub/v1/EndUserType.java @@ -22,43 +22,42 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.List; import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class EndUserType extends Resource { + private static final long serialVersionUID = 67038001521206L; - public static EndUserTypeFetcher fetcher(final String pathSid){ + public static EndUserTypeFetcher fetcher(final String pathSid) { return new EndUserTypeFetcher(pathSid); } - public static EndUserTypeReader reader(){ + public static EndUserTypeReader reader() { return new EndUserTypeReader(); } /** - * Converts a JSON String into a EndUserType object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return EndUserType object represented by the provided JSON - */ - public static EndUserType fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a EndUserType object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return EndUserType object represented by the provided JSON + */ + public static EndUserType fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, EndUserType.class); @@ -70,14 +69,17 @@ public static EndUserType fromJson(final String json, final ObjectMapper objectM } /** - * Converts a JSON InputStream into a EndUserType object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return EndUserType object represented by the provided JSON - */ - public static EndUserType fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a EndUserType object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return EndUserType object represented by the provided JSON + */ + public static EndUserType fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, EndUserType.class); @@ -96,20 +98,11 @@ public static EndUserType fromJson(final InputStream json, final ObjectMapper ob @JsonCreator private EndUserType( - @JsonProperty("sid") - final String sid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("machine_name") - final String machineName, - - @JsonProperty("fields") - final List> fields, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("machine_name") final String machineName, + @JsonProperty("fields") final List> fields, + @JsonProperty("url") final URI url ) { this.sid = sid; this.friendlyName = friendlyName; @@ -118,25 +111,29 @@ private EndUserType( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getMachineName() { - return this.machineName; - } - public final List> getFields() { - return this.fields; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getMachineName() { + return this.machineName; + } + + public final List> getFields() { + return this.fields; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -146,13 +143,17 @@ public boolean equals(final Object o) { EndUserType other = (EndUserType) o; - return Objects.equals(sid, other.sid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(machineName, other.machineName) && Objects.equals(fields, other.fields) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(machineName, other.machineName) && + Objects.equals(fields, other.fields) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { return Objects.hash(sid, friendlyName, machineName, fields, url); } - } - diff --git a/src/main/java/com/twilio/rest/trusthub/v1/EndUserTypeFetcher.java b/src/main/java/com/twilio/rest/trusthub/v1/EndUserTypeFetcher.java index 12644cd0ce..b9c7852a89 100644 --- a/src/main/java/com/twilio/rest/trusthub/v1/EndUserTypeFetcher.java +++ b/src/main/java/com/twilio/rest/trusthub/v1/EndUserTypeFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class EndUserTypeFetcher extends Fetcher { + private String pathSid; - public EndUserTypeFetcher(final String pathSid){ + public EndUserTypeFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public EndUserType fetch(final TwilioRestClient client) { String path = "/v1/EndUserTypes/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,15 +46,23 @@ public EndUserType fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("EndUserType fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "EndUserType fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return EndUserType.fromJson(response.getStream(), client.getObjectMapper()); + return EndUserType.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/trusthub/v1/EndUserTypeReader.java b/src/main/java/com/twilio/rest/trusthub/v1/EndUserTypeReader.java index 4c19b947c7..5d06bce085 100644 --- a/src/main/java/com/twilio/rest/trusthub/v1/EndUserTypeReader.java +++ b/src/main/java/com/twilio/rest/trusthub/v1/EndUserTypeReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.trusthub.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,17 +25,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class EndUserTypeReader extends Reader { + private Integer pageSize; - public EndUserTypeReader(){ - } + public EndUserTypeReader() {} - public EndUserTypeReader setPageSize(final Integer pageSize){ + public EndUserTypeReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -57,13 +55,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("EndUserType read failed: Unable to connect to server"); + throw new ApiConnectionException( + "EndUserType read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -79,7 +85,10 @@ private Page pageForRequest(final TwilioRestClient client, final Re } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.TRUSTHUB.toString()) @@ -87,9 +96,11 @@ public Page previousPage(final Page page, final Twilio return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.TRUSTHUB.toString()) @@ -98,21 +109,21 @@ public Page nextPage(final Page page, final TwilioRest } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/trusthub/v1/EndUserUpdater.java b/src/main/java/com/twilio/rest/trusthub/v1/EndUserUpdater.java index 48370bcd10..9be6bb08ac 100644 --- a/src/main/java/com/twilio/rest/trusthub/v1/EndUserUpdater.java +++ b/src/main/java/com/twilio/rest/trusthub/v1/EndUserUpdater.java @@ -15,8 +15,9 @@ package com.twilio.rest.trusthub.v1; import com.twilio.base.Updater; -import com.twilio.exception.ApiConnectionException; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Converter; +import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; @@ -24,46 +25,51 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - import java.util.Map; +public class EndUserUpdater extends Updater { -public class EndUserUpdater extends Updater{ private String pathSid; private String friendlyName; private Map attributes; - public EndUserUpdater(final String pathSid){ + public EndUserUpdater(final String pathSid) { this.pathSid = pathSid; } - public EndUserUpdater setFriendlyName(final String friendlyName){ + public EndUserUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public EndUserUpdater setAttributes(final Map attributes){ + + public EndUserUpdater setAttributes(final Map attributes) { this.attributes = attributes; return this; } @Override - public EndUser update(final TwilioRestClient client){ + public EndUser update(final TwilioRestClient client) { String path = "/v1/EndUsers/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.TRUSTHUB.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("EndUser update failed: Unable to connect to server"); + throw new ApiConnectionException( + "EndUser update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -72,14 +78,13 @@ public EndUser update(final TwilioRestClient client){ return EndUser.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (attributes != null) { - request.addPostParam("Attributes", Converter.mapToJson(attributes)); - + request.addPostParam("Attributes", Converter.mapToJson(attributes)); } } } diff --git a/src/main/java/com/twilio/rest/trusthub/v1/Policies.java b/src/main/java/com/twilio/rest/trusthub/v1/Policies.java index 38139bd436..e9fec1bf84 100644 --- a/src/main/java/com/twilio/rest/trusthub/v1/Policies.java +++ b/src/main/java/com/twilio/rest/trusthub/v1/Policies.java @@ -22,42 +22,41 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Policies extends Resource { + private static final long serialVersionUID = 142613922631852L; - public static PoliciesFetcher fetcher(final String pathSid){ + public static PoliciesFetcher fetcher(final String pathSid) { return new PoliciesFetcher(pathSid); } - public static PoliciesReader reader(){ + public static PoliciesReader reader() { return new PoliciesReader(); } /** - * Converts a JSON String into a Policies object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Policies object represented by the provided JSON - */ - public static Policies fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Policies object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Policies object represented by the provided JSON + */ + public static Policies fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Policies.class); @@ -69,14 +68,17 @@ public static Policies fromJson(final String json, final ObjectMapper objectMapp } /** - * Converts a JSON InputStream into a Policies object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Policies object represented by the provided JSON - */ - public static Policies fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Policies object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Policies object represented by the provided JSON + */ + public static Policies fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Policies.class); @@ -94,17 +96,10 @@ public static Policies fromJson(final InputStream json, final ObjectMapper objec @JsonCreator private Policies( - @JsonProperty("sid") - final String sid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("requirements") - final Map requirements, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("requirements") final Map requirements, + @JsonProperty("url") final URI url ) { this.sid = sid; this.friendlyName = friendlyName; @@ -112,22 +107,25 @@ private Policies( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final Map getRequirements() { - return this.requirements; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final Map getRequirements() { + return this.requirements; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -137,13 +135,16 @@ public boolean equals(final Object o) { Policies other = (Policies) o; - return Objects.equals(sid, other.sid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(requirements, other.requirements) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(requirements, other.requirements) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { return Objects.hash(sid, friendlyName, requirements, url); } - } - diff --git a/src/main/java/com/twilio/rest/trusthub/v1/PoliciesFetcher.java b/src/main/java/com/twilio/rest/trusthub/v1/PoliciesFetcher.java index 7e8ab578be..5bc583b17b 100644 --- a/src/main/java/com/twilio/rest/trusthub/v1/PoliciesFetcher.java +++ b/src/main/java/com/twilio/rest/trusthub/v1/PoliciesFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class PoliciesFetcher extends Fetcher { + private String pathSid; - public PoliciesFetcher(final String pathSid){ + public PoliciesFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public Policies fetch(final TwilioRestClient client) { String path = "/v1/Policies/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,15 +46,23 @@ public Policies fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Policies fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Policies fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Policies.fromJson(response.getStream(), client.getObjectMapper()); + return Policies.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/trusthub/v1/PoliciesReader.java b/src/main/java/com/twilio/rest/trusthub/v1/PoliciesReader.java index f6b2e84af8..e179fd410b 100644 --- a/src/main/java/com/twilio/rest/trusthub/v1/PoliciesReader.java +++ b/src/main/java/com/twilio/rest/trusthub/v1/PoliciesReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.trusthub.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,17 +25,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class PoliciesReader extends Reader { + private Integer pageSize; - public PoliciesReader(){ - } + public PoliciesReader() {} - public PoliciesReader setPageSize(final Integer pageSize){ + public PoliciesReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -57,13 +55,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Policies read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Policies read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -79,7 +85,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reque } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.TRUSTHUB.toString()) @@ -87,9 +96,11 @@ public Page previousPage(final Page page, final TwilioRestCl return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.TRUSTHUB.toString()) @@ -98,21 +109,21 @@ public Page nextPage(final Page page, final TwilioRestClient } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/trusthub/v1/SupportingDocument.java b/src/main/java/com/twilio/rest/trusthub/v1/SupportingDocument.java index 5339a146fe..2a73525f49 100644 --- a/src/main/java/com/twilio/rest/trusthub/v1/SupportingDocument.java +++ b/src/main/java/com/twilio/rest/trusthub/v1/SupportingDocument.java @@ -24,55 +24,57 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class SupportingDocument extends Resource { + private static final long serialVersionUID = 13014832865593L; - public static SupportingDocumentCreator creator(final String friendlyName, final String type){ + public static SupportingDocumentCreator creator( + final String friendlyName, + final String type + ) { return new SupportingDocumentCreator(friendlyName, type); } - public static SupportingDocumentDeleter deleter(final String pathSid){ + public static SupportingDocumentDeleter deleter(final String pathSid) { return new SupportingDocumentDeleter(pathSid); } - public static SupportingDocumentFetcher fetcher(final String pathSid){ + public static SupportingDocumentFetcher fetcher(final String pathSid) { return new SupportingDocumentFetcher(pathSid); } - public static SupportingDocumentReader reader(){ + public static SupportingDocumentReader reader() { return new SupportingDocumentReader(); } - public static SupportingDocumentUpdater updater(final String pathSid){ + public static SupportingDocumentUpdater updater(final String pathSid) { return new SupportingDocumentUpdater(pathSid); } /** - * Converts a JSON String into a SupportingDocument object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return SupportingDocument object represented by the provided JSON - */ - public static SupportingDocument fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a SupportingDocument object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return SupportingDocument object represented by the provided JSON + */ + public static SupportingDocument fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SupportingDocument.class); @@ -84,14 +86,17 @@ public static SupportingDocument fromJson(final String json, final ObjectMapper } /** - * Converts a JSON InputStream into a SupportingDocument object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return SupportingDocument object represented by the provided JSON - */ - public static SupportingDocument fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a SupportingDocument object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return SupportingDocument object represented by the provided JSON + */ + public static SupportingDocument fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SupportingDocument.class); @@ -101,6 +106,7 @@ public static SupportingDocument fromJson(final InputStream json, final ObjectMa throw new ApiConnectionException(e.getMessage(), e); } } + public enum Status { DRAFT("draft"), PENDING_REVIEW("pending-review"), @@ -138,35 +144,16 @@ public static Status forValue(final String value) { @JsonCreator private SupportingDocument( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("mime_type") - final String mimeType, - - @JsonProperty("status") - final SupportingDocument.Status status, - - @JsonProperty("type") - final String type, - - @JsonProperty("attributes") - final Map attributes, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("mime_type") final String mimeType, + @JsonProperty("status") final SupportingDocument.Status status, + @JsonProperty("type") final String type, + @JsonProperty("attributes") final Map attributes, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url ) { this.sid = sid; this.accountSid = accountSid; @@ -180,40 +167,49 @@ private SupportingDocument( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getMimeType() { - return this.mimeType; - } - public final SupportingDocument.Status getStatus() { - return this.status; - } - public final String getType() { - return this.type; - } - public final Map getAttributes() { - return this.attributes; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getMimeType() { + return this.mimeType; + } + + public final SupportingDocument.Status getStatus() { + return this.status; + } + + public final String getType() { + return this.type; + } + + public final Map getAttributes() { + return this.attributes; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -223,13 +219,33 @@ public boolean equals(final Object o) { SupportingDocument other = (SupportingDocument) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(mimeType, other.mimeType) && Objects.equals(status, other.status) && Objects.equals(type, other.type) && Objects.equals(attributes, other.attributes) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(mimeType, other.mimeType) && + Objects.equals(status, other.status) && + Objects.equals(type, other.type) && + Objects.equals(attributes, other.attributes) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, friendlyName, mimeType, status, type, attributes, dateCreated, dateUpdated, url); + return Objects.hash( + sid, + accountSid, + friendlyName, + mimeType, + status, + type, + attributes, + dateCreated, + dateUpdated, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/trusthub/v1/SupportingDocumentCreator.java b/src/main/java/com/twilio/rest/trusthub/v1/SupportingDocumentCreator.java index 5d7739f7a5..7928f8d015 100644 --- a/src/main/java/com/twilio/rest/trusthub/v1/SupportingDocumentCreator.java +++ b/src/main/java/com/twilio/rest/trusthub/v1/SupportingDocumentCreator.java @@ -15,8 +15,10 @@ package com.twilio.rest.trusthub.v1; import com.twilio.base.Creator; -import com.twilio.exception.ApiConnectionException; +import com.twilio.constant.EnumConstants; +import com.twilio.converter.Converter; import com.twilio.converter.Converter; +import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; @@ -25,73 +27,90 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.util.Map; -import com.twilio.converter.Converter; - import java.util.Map; +public class SupportingDocumentCreator extends Creator { - -public class SupportingDocumentCreator extends Creator{ private String friendlyName; private String type; private Map attributes; - public SupportingDocumentCreator(final String friendlyName, final String type) { + public SupportingDocumentCreator( + final String friendlyName, + final String type + ) { this.friendlyName = friendlyName; this.type = type; } - public SupportingDocumentCreator setFriendlyName(final String friendlyName){ + public SupportingDocumentCreator setFriendlyName( + final String friendlyName + ) { this.friendlyName = friendlyName; return this; } - public SupportingDocumentCreator setType(final String type){ + + public SupportingDocumentCreator setType(final String type) { this.type = type; return this; } - public SupportingDocumentCreator setAttributes(final Map attributes){ + + public SupportingDocumentCreator setAttributes( + final Map attributes + ) { this.attributes = attributes; return this; } @Override - public SupportingDocument create(final TwilioRestClient client){ + public SupportingDocument create(final TwilioRestClient client) { String path = "/v1/SupportingDocuments"; - path = path.replace("{"+"FriendlyName"+"}", this.friendlyName.toString()); - path = path.replace("{"+"Type"+"}", this.type.toString()); + path = + path.replace( + "{" + "FriendlyName" + "}", + this.friendlyName.toString() + ); + path = path.replace("{" + "Type" + "}", this.type.toString()); Request request = new Request( HttpMethod.POST, Domains.TRUSTHUB.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SupportingDocument creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "SupportingDocument creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return SupportingDocument.fromJson(response.getStream(), client.getObjectMapper()); + return SupportingDocument.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (type != null) { request.addPostParam("Type", type); - } if (attributes != null) { - request.addPostParam("Attributes", Converter.mapToJson(attributes)); - + request.addPostParam("Attributes", Converter.mapToJson(attributes)); } } } diff --git a/src/main/java/com/twilio/rest/trusthub/v1/SupportingDocumentDeleter.java b/src/main/java/com/twilio/rest/trusthub/v1/SupportingDocumentDeleter.java index fdf11da398..49a962967f 100644 --- a/src/main/java/com/twilio/rest/trusthub/v1/SupportingDocumentDeleter.java +++ b/src/main/java/com/twilio/rest/trusthub/v1/SupportingDocumentDeleter.java @@ -24,21 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class SupportingDocumentDeleter extends Deleter { + private String pathSid; - public SupportingDocumentDeleter(final String pathSid){ + public SupportingDocumentDeleter(final String pathSid) { this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/SupportingDocuments/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -48,9 +46,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SupportingDocument delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "SupportingDocument delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/trusthub/v1/SupportingDocumentFetcher.java b/src/main/java/com/twilio/rest/trusthub/v1/SupportingDocumentFetcher.java index 6915633f35..da0c0e389e 100644 --- a/src/main/java/com/twilio/rest/trusthub/v1/SupportingDocumentFetcher.java +++ b/src/main/java/com/twilio/rest/trusthub/v1/SupportingDocumentFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class SupportingDocumentFetcher extends Fetcher { + private String pathSid; - public SupportingDocumentFetcher(final String pathSid){ + public SupportingDocumentFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public SupportingDocument fetch(final TwilioRestClient client) { String path = "/v1/SupportingDocuments/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,15 +46,23 @@ public SupportingDocument fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SupportingDocument fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "SupportingDocument fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return SupportingDocument.fromJson(response.getStream(), client.getObjectMapper()); + return SupportingDocument.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/trusthub/v1/SupportingDocumentReader.java b/src/main/java/com/twilio/rest/trusthub/v1/SupportingDocumentReader.java index a4c3074a0c..eba013f633 100644 --- a/src/main/java/com/twilio/rest/trusthub/v1/SupportingDocumentReader.java +++ b/src/main/java/com/twilio/rest/trusthub/v1/SupportingDocumentReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.trusthub.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,17 +25,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class SupportingDocumentReader extends Reader { + private Integer pageSize; - public SupportingDocumentReader(){ - } + public SupportingDocumentReader() {} - public SupportingDocumentReader setPageSize(final Integer pageSize){ + public SupportingDocumentReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -57,13 +55,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SupportingDocument read failed: Unable to connect to server"); + throw new ApiConnectionException( + "SupportingDocument read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -79,7 +85,10 @@ private Page pageForRequest(final TwilioRestClient client, f } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.TRUSTHUB.toString()) @@ -87,9 +96,11 @@ public Page previousPage(final Page page return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.TRUSTHUB.toString()) @@ -98,21 +109,21 @@ public Page nextPage(final Page page, fi } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/trusthub/v1/SupportingDocumentType.java b/src/main/java/com/twilio/rest/trusthub/v1/SupportingDocumentType.java index 0b356fba3b..4e5429cfd7 100644 --- a/src/main/java/com/twilio/rest/trusthub/v1/SupportingDocumentType.java +++ b/src/main/java/com/twilio/rest/trusthub/v1/SupportingDocumentType.java @@ -22,43 +22,42 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.List; import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class SupportingDocumentType extends Resource { + private static final long serialVersionUID = 67038001521206L; - public static SupportingDocumentTypeFetcher fetcher(final String pathSid){ + public static SupportingDocumentTypeFetcher fetcher(final String pathSid) { return new SupportingDocumentTypeFetcher(pathSid); } - public static SupportingDocumentTypeReader reader(){ + public static SupportingDocumentTypeReader reader() { return new SupportingDocumentTypeReader(); } /** - * Converts a JSON String into a SupportingDocumentType object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return SupportingDocumentType object represented by the provided JSON - */ - public static SupportingDocumentType fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a SupportingDocumentType object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return SupportingDocumentType object represented by the provided JSON + */ + public static SupportingDocumentType fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SupportingDocumentType.class); @@ -70,14 +69,17 @@ public static SupportingDocumentType fromJson(final String json, final ObjectMap } /** - * Converts a JSON InputStream into a SupportingDocumentType object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return SupportingDocumentType object represented by the provided JSON - */ - public static SupportingDocumentType fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a SupportingDocumentType object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return SupportingDocumentType object represented by the provided JSON + */ + public static SupportingDocumentType fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SupportingDocumentType.class); @@ -96,20 +98,11 @@ public static SupportingDocumentType fromJson(final InputStream json, final Obje @JsonCreator private SupportingDocumentType( - @JsonProperty("sid") - final String sid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("machine_name") - final String machineName, - - @JsonProperty("fields") - final List> fields, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("machine_name") final String machineName, + @JsonProperty("fields") final List> fields, + @JsonProperty("url") final URI url ) { this.sid = sid; this.friendlyName = friendlyName; @@ -118,25 +111,29 @@ private SupportingDocumentType( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final String getMachineName() { - return this.machineName; - } - public final List> getFields() { - return this.fields; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getMachineName() { + return this.machineName; + } + + public final List> getFields() { + return this.fields; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -146,13 +143,17 @@ public boolean equals(final Object o) { SupportingDocumentType other = (SupportingDocumentType) o; - return Objects.equals(sid, other.sid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(machineName, other.machineName) && Objects.equals(fields, other.fields) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(machineName, other.machineName) && + Objects.equals(fields, other.fields) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { return Objects.hash(sid, friendlyName, machineName, fields, url); } - } - diff --git a/src/main/java/com/twilio/rest/trusthub/v1/SupportingDocumentTypeFetcher.java b/src/main/java/com/twilio/rest/trusthub/v1/SupportingDocumentTypeFetcher.java index 335e858dcc..63e01f5211 100644 --- a/src/main/java/com/twilio/rest/trusthub/v1/SupportingDocumentTypeFetcher.java +++ b/src/main/java/com/twilio/rest/trusthub/v1/SupportingDocumentTypeFetcher.java @@ -24,22 +24,20 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class SupportingDocumentTypeFetcher + extends Fetcher { - - -public class SupportingDocumentTypeFetcher extends Fetcher { private String pathSid; - public SupportingDocumentTypeFetcher(final String pathSid){ + public SupportingDocumentTypeFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public SupportingDocumentType fetch(final TwilioRestClient client) { String path = "/v1/SupportingDocumentTypes/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,15 +47,23 @@ public SupportingDocumentType fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SupportingDocumentType fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "SupportingDocumentType fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return SupportingDocumentType.fromJson(response.getStream(), client.getObjectMapper()); + return SupportingDocumentType.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/trusthub/v1/SupportingDocumentTypeReader.java b/src/main/java/com/twilio/rest/trusthub/v1/SupportingDocumentTypeReader.java index 8fe12a56f7..f509e71625 100644 --- a/src/main/java/com/twilio/rest/trusthub/v1/SupportingDocumentTypeReader.java +++ b/src/main/java/com/twilio/rest/trusthub/v1/SupportingDocumentTypeReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.trusthub.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,27 +25,29 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - +public class SupportingDocumentTypeReader + extends Reader { -public class SupportingDocumentTypeReader extends Reader { private Integer pageSize; - public SupportingDocumentTypeReader(){ - } + public SupportingDocumentTypeReader() {} - public SupportingDocumentTypeReader setPageSize(final Integer pageSize){ + public SupportingDocumentTypeReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @Override - public ResourceSet read(final TwilioRestClient client) { + public ResourceSet read( + final TwilioRestClient client + ) { return new ResourceSet<>(this, client, firstPage(client)); } - public Page firstPage(final TwilioRestClient client) { + public Page firstPage( + final TwilioRestClient client + ) { String path = "/v1/SupportingDocumentTypes"; Request request = new Request( @@ -57,13 +60,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SupportingDocumentType read failed: Unable to connect to server"); + throw new ApiConnectionException( + "SupportingDocumentType read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -79,7 +90,10 @@ private Page pageForRequest(final TwilioRestClient clien } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.TRUSTHUB.toString()) @@ -87,9 +101,11 @@ public Page previousPage(final Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.TRUSTHUB.toString()) @@ -98,21 +114,21 @@ public Page nextPage(final Page } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/trusthub/v1/SupportingDocumentUpdater.java b/src/main/java/com/twilio/rest/trusthub/v1/SupportingDocumentUpdater.java index ab6ee370c5..1d1ead0fc5 100644 --- a/src/main/java/com/twilio/rest/trusthub/v1/SupportingDocumentUpdater.java +++ b/src/main/java/com/twilio/rest/trusthub/v1/SupportingDocumentUpdater.java @@ -15,8 +15,9 @@ package com.twilio.rest.trusthub.v1; import com.twilio.base.Updater; -import com.twilio.exception.ApiConnectionException; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Converter; +import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; @@ -24,62 +25,73 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - import java.util.Map; +public class SupportingDocumentUpdater extends Updater { -public class SupportingDocumentUpdater extends Updater{ private String pathSid; private String friendlyName; private Map attributes; - public SupportingDocumentUpdater(final String pathSid){ + public SupportingDocumentUpdater(final String pathSid) { this.pathSid = pathSid; } - public SupportingDocumentUpdater setFriendlyName(final String friendlyName){ + public SupportingDocumentUpdater setFriendlyName( + final String friendlyName + ) { this.friendlyName = friendlyName; return this; } - public SupportingDocumentUpdater setAttributes(final Map attributes){ + + public SupportingDocumentUpdater setAttributes( + final Map attributes + ) { this.attributes = attributes; return this; } @Override - public SupportingDocument update(final TwilioRestClient client){ + public SupportingDocument update(final TwilioRestClient client) { String path = "/v1/SupportingDocuments/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.TRUSTHUB.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SupportingDocument update failed: Unable to connect to server"); + throw new ApiConnectionException( + "SupportingDocument update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return SupportingDocument.fromJson(response.getStream(), client.getObjectMapper()); + return SupportingDocument.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (attributes != null) { - request.addPostParam("Attributes", Converter.mapToJson(attributes)); - + request.addPostParam("Attributes", Converter.mapToJson(attributes)); } } } diff --git a/src/main/java/com/twilio/rest/trusthub/v1/TrustProducts.java b/src/main/java/com/twilio/rest/trusthub/v1/TrustProducts.java index de34760b0f..1de357a5c0 100644 --- a/src/main/java/com/twilio/rest/trusthub/v1/TrustProducts.java +++ b/src/main/java/com/twilio/rest/trusthub/v1/TrustProducts.java @@ -24,55 +24,58 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class TrustProducts extends Resource { + private static final long serialVersionUID = 3469588719072L; - public static TrustProductsCreator creator(final String friendlyName, final String email, final String policySid){ + public static TrustProductsCreator creator( + final String friendlyName, + final String email, + final String policySid + ) { return new TrustProductsCreator(friendlyName, email, policySid); } - public static TrustProductsDeleter deleter(final String pathSid){ + public static TrustProductsDeleter deleter(final String pathSid) { return new TrustProductsDeleter(pathSid); } - public static TrustProductsFetcher fetcher(final String pathSid){ + public static TrustProductsFetcher fetcher(final String pathSid) { return new TrustProductsFetcher(pathSid); } - public static TrustProductsReader reader(){ + public static TrustProductsReader reader() { return new TrustProductsReader(); } - public static TrustProductsUpdater updater(final String pathSid){ + public static TrustProductsUpdater updater(final String pathSid) { return new TrustProductsUpdater(pathSid); } /** - * Converts a JSON String into a TrustProducts object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return TrustProducts object represented by the provided JSON - */ - public static TrustProducts fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a TrustProducts object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return TrustProducts object represented by the provided JSON + */ + public static TrustProducts fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, TrustProducts.class); @@ -84,14 +87,17 @@ public static TrustProducts fromJson(final String json, final ObjectMapper objec } /** - * Converts a JSON InputStream into a TrustProducts object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return TrustProducts object represented by the provided JSON - */ - public static TrustProducts fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a TrustProducts object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return TrustProducts object represented by the provided JSON + */ + public static TrustProducts fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, TrustProducts.class); @@ -101,6 +107,7 @@ public static TrustProducts fromJson(final InputStream json, final ObjectMapper throw new ApiConnectionException(e.getMessage(), e); } } + public enum Status { DRAFT("draft"), PENDING_REVIEW("pending-review"), @@ -139,41 +146,18 @@ public static Status forValue(final String value) { @JsonCreator private TrustProducts( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("policy_sid") - final String policySid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("status") - final TrustProducts.Status status, - - @JsonProperty("valid_until") - final String validUntil, - - @JsonProperty("email") - final String email, - - @JsonProperty("status_callback") - final URI statusCallback, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("policy_sid") final String policySid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("status") final TrustProducts.Status status, + @JsonProperty("valid_until") final String validUntil, + @JsonProperty("email") final String email, + @JsonProperty("status_callback") final URI statusCallback, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.sid = sid; this.accountSid = accountSid; @@ -189,46 +173,57 @@ private TrustProducts( this.links = links; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getPolicySid() { - return this.policySid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final TrustProducts.Status getStatus() { - return this.status; - } - public final ZonedDateTime getValidUntil() { - return this.validUntil; - } - public final String getEmail() { - return this.email; - } - public final URI getStatusCallback() { - return this.statusCallback; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getPolicySid() { + return this.policySid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final TrustProducts.Status getStatus() { + return this.status; + } + + public final ZonedDateTime getValidUntil() { + return this.validUntil; + } + + public final String getEmail() { + return this.email; + } + + public final URI getStatusCallback() { + return this.statusCallback; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -238,13 +233,37 @@ public boolean equals(final Object o) { TrustProducts other = (TrustProducts) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(policySid, other.policySid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(status, other.status) && Objects.equals(validUntil, other.validUntil) && Objects.equals(email, other.email) && Objects.equals(statusCallback, other.statusCallback) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(policySid, other.policySid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(status, other.status) && + Objects.equals(validUntil, other.validUntil) && + Objects.equals(email, other.email) && + Objects.equals(statusCallback, other.statusCallback) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, policySid, friendlyName, status, validUntil, email, statusCallback, dateCreated, dateUpdated, url, links); + return Objects.hash( + sid, + accountSid, + policySid, + friendlyName, + status, + validUntil, + email, + statusCallback, + dateCreated, + dateUpdated, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/trusthub/v1/TrustProductsCreator.java b/src/main/java/com/twilio/rest/trusthub/v1/TrustProductsCreator.java index c7f6a34a21..1ade8273fb 100644 --- a/src/main/java/com/twilio/rest/trusthub/v1/TrustProductsCreator.java +++ b/src/main/java/com/twilio/rest/trusthub/v1/TrustProductsCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.trusthub.v1; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -25,87 +26,102 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; import java.net.URI; - - - import java.net.URI; -public class TrustProductsCreator extends Creator{ +public class TrustProductsCreator extends Creator { + private String friendlyName; private String email; private String policySid; private URI statusCallback; - public TrustProductsCreator(final String friendlyName, final String email, final String policySid) { + public TrustProductsCreator( + final String friendlyName, + final String email, + final String policySid + ) { this.friendlyName = friendlyName; this.email = email; this.policySid = policySid; } - public TrustProductsCreator setFriendlyName(final String friendlyName){ + public TrustProductsCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public TrustProductsCreator setEmail(final String email){ + + public TrustProductsCreator setEmail(final String email) { this.email = email; return this; } - public TrustProductsCreator setPolicySid(final String policySid){ + + public TrustProductsCreator setPolicySid(final String policySid) { this.policySid = policySid; return this; } - public TrustProductsCreator setStatusCallback(final URI statusCallback){ + + public TrustProductsCreator setStatusCallback(final URI statusCallback) { this.statusCallback = statusCallback; return this; } - public TrustProductsCreator setStatusCallback(final String statusCallback){ + public TrustProductsCreator setStatusCallback(final String statusCallback) { return setStatusCallback(Promoter.uriFromString(statusCallback)); } @Override - public TrustProducts create(final TwilioRestClient client){ + public TrustProducts create(final TwilioRestClient client) { String path = "/v1/TrustProducts"; - path = path.replace("{"+"FriendlyName"+"}", this.friendlyName.toString()); - path = path.replace("{"+"Email"+"}", this.email.toString()); - path = path.replace("{"+"PolicySid"+"}", this.policySid.toString()); + path = + path.replace( + "{" + "FriendlyName" + "}", + this.friendlyName.toString() + ); + path = path.replace("{" + "Email" + "}", this.email.toString()); + path = path.replace("{" + "PolicySid" + "}", this.policySid.toString()); Request request = new Request( HttpMethod.POST, Domains.TRUSTHUB.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("TrustProducts creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "TrustProducts creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return TrustProducts.fromJson(response.getStream(), client.getObjectMapper()); + return TrustProducts.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (email != null) { request.addPostParam("Email", email); - } if (policySid != null) { request.addPostParam("PolicySid", policySid); - } if (statusCallback != null) { request.addPostParam("StatusCallback", statusCallback.toString()); - } } } diff --git a/src/main/java/com/twilio/rest/trusthub/v1/TrustProductsDeleter.java b/src/main/java/com/twilio/rest/trusthub/v1/TrustProductsDeleter.java index e68ac2dccf..86d1024657 100644 --- a/src/main/java/com/twilio/rest/trusthub/v1/TrustProductsDeleter.java +++ b/src/main/java/com/twilio/rest/trusthub/v1/TrustProductsDeleter.java @@ -24,21 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class TrustProductsDeleter extends Deleter { + private String pathSid; - public TrustProductsDeleter(final String pathSid){ + public TrustProductsDeleter(final String pathSid) { this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v1/TrustProducts/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -48,9 +46,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("TrustProducts delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "TrustProducts delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/trusthub/v1/TrustProductsFetcher.java b/src/main/java/com/twilio/rest/trusthub/v1/TrustProductsFetcher.java index 5445a88b01..5f74a39715 100644 --- a/src/main/java/com/twilio/rest/trusthub/v1/TrustProductsFetcher.java +++ b/src/main/java/com/twilio/rest/trusthub/v1/TrustProductsFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class TrustProductsFetcher extends Fetcher { + private String pathSid; - public TrustProductsFetcher(final String pathSid){ + public TrustProductsFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public TrustProducts fetch(final TwilioRestClient client) { String path = "/v1/TrustProducts/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,15 +46,23 @@ public TrustProducts fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("TrustProducts fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "TrustProducts fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return TrustProducts.fromJson(response.getStream(), client.getObjectMapper()); + return TrustProducts.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/trusthub/v1/TrustProductsReader.java b/src/main/java/com/twilio/rest/trusthub/v1/TrustProductsReader.java index 9e57e24244..c04da6a84d 100644 --- a/src/main/java/com/twilio/rest/trusthub/v1/TrustProductsReader.java +++ b/src/main/java/com/twilio/rest/trusthub/v1/TrustProductsReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.trusthub.v1; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,32 +25,32 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class TrustProductsReader extends Reader { + private TrustProducts.Status status; private String friendlyName; private String policySid; private Integer pageSize; - public TrustProductsReader(){ - } + public TrustProductsReader() {} - public TrustProductsReader setStatus(final TrustProducts.Status status){ + public TrustProductsReader setStatus(final TrustProducts.Status status) { this.status = status; return this; } - public TrustProductsReader setFriendlyName(final String friendlyName){ + + public TrustProductsReader setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public TrustProductsReader setPolicySid(final String policySid){ + + public TrustProductsReader setPolicySid(final String policySid) { this.policySid = policySid; return this; } - public TrustProductsReader setPageSize(final Integer pageSize){ + + public TrustProductsReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -72,13 +73,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("TrustProducts read failed: Unable to connect to server"); + throw new ApiConnectionException( + "TrustProducts read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -94,7 +103,10 @@ private Page pageForRequest(final TwilioRestClient client, final } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.TRUSTHUB.toString()) @@ -102,9 +114,11 @@ public Page previousPage(final Page page, final Tw return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.TRUSTHUB.toString()) @@ -113,33 +127,30 @@ public Page nextPage(final Page page, final Twilio } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (status != null) { - request.addQueryParam("Status", status.toString()); } if (friendlyName != null) { - request.addQueryParam("FriendlyName", friendlyName); } if (policySid != null) { - request.addQueryParam("PolicySid", policySid); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/trusthub/v1/TrustProductsUpdater.java b/src/main/java/com/twilio/rest/trusthub/v1/TrustProductsUpdater.java index eae17d2799..dd705ab3b2 100644 --- a/src/main/java/com/twilio/rest/trusthub/v1/TrustProductsUpdater.java +++ b/src/main/java/com/twilio/rest/trusthub/v1/TrustProductsUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.trusthub.v1; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; @@ -24,84 +25,91 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - import java.net.URI; +public class TrustProductsUpdater extends Updater { - -public class TrustProductsUpdater extends Updater{ private String pathSid; private TrustProducts.Status status; private URI statusCallback; private String friendlyName; private String email; - public TrustProductsUpdater(final String pathSid){ + public TrustProductsUpdater(final String pathSid) { this.pathSid = pathSid; } - public TrustProductsUpdater setStatus(final TrustProducts.Status status){ + public TrustProductsUpdater setStatus(final TrustProducts.Status status) { this.status = status; return this; } - public TrustProductsUpdater setStatusCallback(final URI statusCallback){ + + public TrustProductsUpdater setStatusCallback(final URI statusCallback) { this.statusCallback = statusCallback; return this; } - public TrustProductsUpdater setStatusCallback(final String statusCallback){ + public TrustProductsUpdater setStatusCallback(final String statusCallback) { return setStatusCallback(Promoter.uriFromString(statusCallback)); } - public TrustProductsUpdater setFriendlyName(final String friendlyName){ + + public TrustProductsUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public TrustProductsUpdater setEmail(final String email){ + + public TrustProductsUpdater setEmail(final String email) { this.email = email; return this; } @Override - public TrustProducts update(final TwilioRestClient client){ + public TrustProducts update(final TwilioRestClient client) { String path = "/v1/TrustProducts/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.TRUSTHUB.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("TrustProducts update failed: Unable to connect to server"); + throw new ApiConnectionException( + "TrustProducts update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return TrustProducts.fromJson(response.getStream(), client.getObjectMapper()); + return TrustProducts.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (status != null) { request.addPostParam("Status", status.toString()); - } if (statusCallback != null) { request.addPostParam("StatusCallback", statusCallback.toString()); - } if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (email != null) { request.addPostParam("Email", email); - } } } diff --git a/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesChannelEndpointAssignment.java b/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesChannelEndpointAssignment.java index e220937f33..dc153515de 100644 --- a/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesChannelEndpointAssignment.java +++ b/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesChannelEndpointAssignment.java @@ -23,52 +23,78 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class CustomerProfilesChannelEndpointAssignment extends Resource { + private static final long serialVersionUID = 18267773562551L; - public static CustomerProfilesChannelEndpointAssignmentCreator creator(final String pathCustomerProfileSid, final String channelEndpointType, final String channelEndpointSid){ - return new CustomerProfilesChannelEndpointAssignmentCreator(pathCustomerProfileSid, channelEndpointType, channelEndpointSid); + public static CustomerProfilesChannelEndpointAssignmentCreator creator( + final String pathCustomerProfileSid, + final String channelEndpointType, + final String channelEndpointSid + ) { + return new CustomerProfilesChannelEndpointAssignmentCreator( + pathCustomerProfileSid, + channelEndpointType, + channelEndpointSid + ); } - public static CustomerProfilesChannelEndpointAssignmentDeleter deleter(final String pathCustomerProfileSid, final String pathSid){ - return new CustomerProfilesChannelEndpointAssignmentDeleter(pathCustomerProfileSid, pathSid); + public static CustomerProfilesChannelEndpointAssignmentDeleter deleter( + final String pathCustomerProfileSid, + final String pathSid + ) { + return new CustomerProfilesChannelEndpointAssignmentDeleter( + pathCustomerProfileSid, + pathSid + ); } - public static CustomerProfilesChannelEndpointAssignmentFetcher fetcher(final String pathCustomerProfileSid, final String pathSid){ - return new CustomerProfilesChannelEndpointAssignmentFetcher(pathCustomerProfileSid, pathSid); + public static CustomerProfilesChannelEndpointAssignmentFetcher fetcher( + final String pathCustomerProfileSid, + final String pathSid + ) { + return new CustomerProfilesChannelEndpointAssignmentFetcher( + pathCustomerProfileSid, + pathSid + ); } - public static CustomerProfilesChannelEndpointAssignmentReader reader(final String pathCustomerProfileSid){ - return new CustomerProfilesChannelEndpointAssignmentReader(pathCustomerProfileSid); + public static CustomerProfilesChannelEndpointAssignmentReader reader( + final String pathCustomerProfileSid + ) { + return new CustomerProfilesChannelEndpointAssignmentReader( + pathCustomerProfileSid + ); } /** - * Converts a JSON String into a CustomerProfilesChannelEndpointAssignment object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return CustomerProfilesChannelEndpointAssignment object represented by the provided JSON - */ - public static CustomerProfilesChannelEndpointAssignment fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a CustomerProfilesChannelEndpointAssignment object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return CustomerProfilesChannelEndpointAssignment object represented by the provided JSON + */ + public static CustomerProfilesChannelEndpointAssignment fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, CustomerProfilesChannelEndpointAssignment.class); + return objectMapper.readValue( + json, + CustomerProfilesChannelEndpointAssignment.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -77,17 +103,23 @@ public static CustomerProfilesChannelEndpointAssignment fromJson(final String js } /** - * Converts a JSON InputStream into a CustomerProfilesChannelEndpointAssignment object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return CustomerProfilesChannelEndpointAssignment object represented by the provided JSON - */ - public static CustomerProfilesChannelEndpointAssignment fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a CustomerProfilesChannelEndpointAssignment object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return CustomerProfilesChannelEndpointAssignment object represented by the provided JSON + */ + public static CustomerProfilesChannelEndpointAssignment fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, CustomerProfilesChannelEndpointAssignment.class); + return objectMapper.readValue( + json, + CustomerProfilesChannelEndpointAssignment.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -105,26 +137,13 @@ public static CustomerProfilesChannelEndpointAssignment fromJson(final InputStre @JsonCreator private CustomerProfilesChannelEndpointAssignment( - @JsonProperty("sid") - final String sid, - - @JsonProperty("customer_profile_sid") - final String customerProfileSid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("channel_endpoint_type") - final String channelEndpointType, - - @JsonProperty("channel_endpoint_sid") - final String channelEndpointSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("customer_profile_sid") final String customerProfileSid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("channel_endpoint_type") final String channelEndpointType, + @JsonProperty("channel_endpoint_sid") final String channelEndpointSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("url") final URI url ) { this.sid = sid; this.customerProfileSid = customerProfileSid; @@ -135,31 +154,37 @@ private CustomerProfilesChannelEndpointAssignment( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getCustomerProfileSid() { - return this.customerProfileSid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getChannelEndpointType() { - return this.channelEndpointType; - } - public final String getChannelEndpointSid() { - return this.channelEndpointSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getCustomerProfileSid() { + return this.customerProfileSid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getChannelEndpointType() { + return this.channelEndpointType; + } + + public final String getChannelEndpointSid() { + return this.channelEndpointSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -167,15 +192,30 @@ public boolean equals(final Object o) { return false; } - CustomerProfilesChannelEndpointAssignment other = (CustomerProfilesChannelEndpointAssignment) o; - - return Objects.equals(sid, other.sid) && Objects.equals(customerProfileSid, other.customerProfileSid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(channelEndpointType, other.channelEndpointType) && Objects.equals(channelEndpointSid, other.channelEndpointSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(url, other.url) ; + CustomerProfilesChannelEndpointAssignment other = + (CustomerProfilesChannelEndpointAssignment) o; + + return ( + Objects.equals(sid, other.sid) && + Objects.equals(customerProfileSid, other.customerProfileSid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(channelEndpointType, other.channelEndpointType) && + Objects.equals(channelEndpointSid, other.channelEndpointSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, customerProfileSid, accountSid, channelEndpointType, channelEndpointSid, dateCreated, url); + return Objects.hash( + sid, + customerProfileSid, + accountSid, + channelEndpointType, + channelEndpointSid, + dateCreated, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesChannelEndpointAssignmentCreator.java b/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesChannelEndpointAssignmentCreator.java index ed6a4fd4fc..9d715bdb25 100644 --- a/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesChannelEndpointAssignmentCreator.java +++ b/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesChannelEndpointAssignmentCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.trusthub.v1.customerprofiles; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,64 +25,95 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class CustomerProfilesChannelEndpointAssignmentCreator + extends Creator { - - -public class CustomerProfilesChannelEndpointAssignmentCreator extends Creator{ private String pathCustomerProfileSid; private String channelEndpointType; private String channelEndpointSid; - public CustomerProfilesChannelEndpointAssignmentCreator(final String pathCustomerProfileSid, final String channelEndpointType, final String channelEndpointSid) { + public CustomerProfilesChannelEndpointAssignmentCreator( + final String pathCustomerProfileSid, + final String channelEndpointType, + final String channelEndpointSid + ) { this.pathCustomerProfileSid = pathCustomerProfileSid; this.channelEndpointType = channelEndpointType; this.channelEndpointSid = channelEndpointSid; } - public CustomerProfilesChannelEndpointAssignmentCreator setChannelEndpointType(final String channelEndpointType){ + public CustomerProfilesChannelEndpointAssignmentCreator setChannelEndpointType( + final String channelEndpointType + ) { this.channelEndpointType = channelEndpointType; return this; } - public CustomerProfilesChannelEndpointAssignmentCreator setChannelEndpointSid(final String channelEndpointSid){ + + public CustomerProfilesChannelEndpointAssignmentCreator setChannelEndpointSid( + final String channelEndpointSid + ) { this.channelEndpointSid = channelEndpointSid; return this; } @Override - public CustomerProfilesChannelEndpointAssignment create(final TwilioRestClient client){ - String path = "/v1/CustomerProfiles/{CustomerProfileSid}/ChannelEndpointAssignments"; + public CustomerProfilesChannelEndpointAssignment create( + final TwilioRestClient client + ) { + String path = + "/v1/CustomerProfiles/{CustomerProfileSid}/ChannelEndpointAssignments"; - path = path.replace("{"+"CustomerProfileSid"+"}", this.pathCustomerProfileSid.toString()); - path = path.replace("{"+"ChannelEndpointType"+"}", this.channelEndpointType.toString()); - path = path.replace("{"+"ChannelEndpointSid"+"}", this.channelEndpointSid.toString()); + path = + path.replace( + "{" + "CustomerProfileSid" + "}", + this.pathCustomerProfileSid.toString() + ); + path = + path.replace( + "{" + "ChannelEndpointType" + "}", + this.channelEndpointType.toString() + ); + path = + path.replace( + "{" + "ChannelEndpointSid" + "}", + this.channelEndpointSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.TRUSTHUB.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("CustomerProfilesChannelEndpointAssignment creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "CustomerProfilesChannelEndpointAssignment creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return CustomerProfilesChannelEndpointAssignment.fromJson(response.getStream(), client.getObjectMapper()); + return CustomerProfilesChannelEndpointAssignment.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (channelEndpointType != null) { request.addPostParam("ChannelEndpointType", channelEndpointType); - } if (channelEndpointSid != null) { request.addPostParam("ChannelEndpointSid", channelEndpointSid); - } } } diff --git a/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesChannelEndpointAssignmentDeleter.java b/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesChannelEndpointAssignmentDeleter.java index 0f7c5b0125..a1ff764f55 100644 --- a/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesChannelEndpointAssignmentDeleter.java +++ b/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesChannelEndpointAssignmentDeleter.java @@ -24,24 +24,31 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class CustomerProfilesChannelEndpointAssignmentDeleter + extends Deleter { - -public class CustomerProfilesChannelEndpointAssignmentDeleter extends Deleter { private String pathCustomerProfileSid; private String pathSid; - public CustomerProfilesChannelEndpointAssignmentDeleter(final String pathCustomerProfileSid, final String pathSid){ + public CustomerProfilesChannelEndpointAssignmentDeleter( + final String pathCustomerProfileSid, + final String pathSid + ) { this.pathCustomerProfileSid = pathCustomerProfileSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/v1/CustomerProfiles/{CustomerProfileSid}/ChannelEndpointAssignments/{Sid}"; + String path = + "/v1/CustomerProfiles/{CustomerProfileSid}/ChannelEndpointAssignments/{Sid}"; - path = path.replace("{"+"CustomerProfileSid"+"}", this.pathCustomerProfileSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "CustomerProfileSid" + "}", + this.pathCustomerProfileSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +58,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("CustomerProfilesChannelEndpointAssignment delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "CustomerProfilesChannelEndpointAssignment delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesChannelEndpointAssignmentFetcher.java b/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesChannelEndpointAssignmentFetcher.java index 28e80a9df8..e18601ddb9 100644 --- a/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesChannelEndpointAssignmentFetcher.java +++ b/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesChannelEndpointAssignmentFetcher.java @@ -24,25 +24,33 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class CustomerProfilesChannelEndpointAssignmentFetcher + extends Fetcher { - - -public class CustomerProfilesChannelEndpointAssignmentFetcher extends Fetcher { private String pathCustomerProfileSid; private String pathSid; - public CustomerProfilesChannelEndpointAssignmentFetcher(final String pathCustomerProfileSid, final String pathSid){ + public CustomerProfilesChannelEndpointAssignmentFetcher( + final String pathCustomerProfileSid, + final String pathSid + ) { this.pathCustomerProfileSid = pathCustomerProfileSid; this.pathSid = pathSid; } - @Override - public CustomerProfilesChannelEndpointAssignment fetch(final TwilioRestClient client) { - String path = "/v1/CustomerProfiles/{CustomerProfileSid}/ChannelEndpointAssignments/{Sid}"; + public CustomerProfilesChannelEndpointAssignment fetch( + final TwilioRestClient client + ) { + String path = + "/v1/CustomerProfiles/{CustomerProfileSid}/ChannelEndpointAssignments/{Sid}"; - path = path.replace("{"+"CustomerProfileSid"+"}", this.pathCustomerProfileSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "CustomerProfileSid" + "}", + this.pathCustomerProfileSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,15 +60,23 @@ public CustomerProfilesChannelEndpointAssignment fetch(final TwilioRestClient cl Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("CustomerProfilesChannelEndpointAssignment fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "CustomerProfilesChannelEndpointAssignment fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return CustomerProfilesChannelEndpointAssignment.fromJson(response.getStream(), client.getObjectMapper()); + return CustomerProfilesChannelEndpointAssignment.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesChannelEndpointAssignmentReader.java b/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesChannelEndpointAssignmentReader.java index de20b49295..04bb70e1e0 100644 --- a/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesChannelEndpointAssignmentReader.java +++ b/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesChannelEndpointAssignmentReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.trusthub.v1.customerprofiles; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,41 +25,59 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - +public class CustomerProfilesChannelEndpointAssignmentReader + extends Reader { -public class CustomerProfilesChannelEndpointAssignmentReader extends Reader { private String pathCustomerProfileSid; private String channelEndpointSid; private String channelEndpointSids; private Integer pageSize; - public CustomerProfilesChannelEndpointAssignmentReader(final String pathCustomerProfileSid){ + public CustomerProfilesChannelEndpointAssignmentReader( + final String pathCustomerProfileSid + ) { this.pathCustomerProfileSid = pathCustomerProfileSid; } - public CustomerProfilesChannelEndpointAssignmentReader setChannelEndpointSid(final String channelEndpointSid){ + public CustomerProfilesChannelEndpointAssignmentReader setChannelEndpointSid( + final String channelEndpointSid + ) { this.channelEndpointSid = channelEndpointSid; return this; } - public CustomerProfilesChannelEndpointAssignmentReader setChannelEndpointSids(final String channelEndpointSids){ + + public CustomerProfilesChannelEndpointAssignmentReader setChannelEndpointSids( + final String channelEndpointSids + ) { this.channelEndpointSids = channelEndpointSids; return this; } - public CustomerProfilesChannelEndpointAssignmentReader setPageSize(final Integer pageSize){ + + public CustomerProfilesChannelEndpointAssignmentReader setPageSize( + final Integer pageSize + ) { this.pageSize = pageSize; return this; } @Override - public ResourceSet read(final TwilioRestClient client) { + public ResourceSet read( + final TwilioRestClient client + ) { return new ResourceSet<>(this, client, firstPage(client)); } - public Page firstPage(final TwilioRestClient client) { - String path = "/v1/CustomerProfiles/{CustomerProfileSid}/ChannelEndpointAssignments"; - path = path.replace("{"+"CustomerProfileSid"+"}", this.pathCustomerProfileSid.toString()); + public Page firstPage( + final TwilioRestClient client + ) { + String path = + "/v1/CustomerProfiles/{CustomerProfileSid}/ChannelEndpointAssignments"; + path = + path.replace( + "{" + "CustomerProfileSid" + "}", + this.pathCustomerProfileSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -70,13 +89,21 @@ public Page firstPage(final TwilioRes return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("CustomerProfilesChannelEndpointAssignment read failed: Unable to connect to server"); + throw new ApiConnectionException( + "CustomerProfilesChannelEndpointAssignment read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -92,7 +119,10 @@ private Page pageForRequest(final Twi } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.TRUSTHUB.toString()) @@ -100,9 +130,11 @@ public Page previousPage(final Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.TRUSTHUB.toString()) @@ -111,29 +143,27 @@ public Page nextPage(final Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (channelEndpointSid != null) { - request.addQueryParam("ChannelEndpointSid", channelEndpointSid); } if (channelEndpointSids != null) { - request.addQueryParam("ChannelEndpointSids", channelEndpointSids); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesEntityAssignments.java b/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesEntityAssignments.java index 98780b014d..144f6b10ee 100644 --- a/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesEntityAssignments.java +++ b/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesEntityAssignments.java @@ -23,52 +23,76 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class CustomerProfilesEntityAssignments extends Resource { + private static final long serialVersionUID = 178139363614511L; - public static CustomerProfilesEntityAssignmentsCreator creator(final String pathCustomerProfileSid, final String objectSid){ - return new CustomerProfilesEntityAssignmentsCreator(pathCustomerProfileSid, objectSid); + public static CustomerProfilesEntityAssignmentsCreator creator( + final String pathCustomerProfileSid, + final String objectSid + ) { + return new CustomerProfilesEntityAssignmentsCreator( + pathCustomerProfileSid, + objectSid + ); } - public static CustomerProfilesEntityAssignmentsDeleter deleter(final String pathCustomerProfileSid, final String pathSid){ - return new CustomerProfilesEntityAssignmentsDeleter(pathCustomerProfileSid, pathSid); + public static CustomerProfilesEntityAssignmentsDeleter deleter( + final String pathCustomerProfileSid, + final String pathSid + ) { + return new CustomerProfilesEntityAssignmentsDeleter( + pathCustomerProfileSid, + pathSid + ); } - public static CustomerProfilesEntityAssignmentsFetcher fetcher(final String pathCustomerProfileSid, final String pathSid){ - return new CustomerProfilesEntityAssignmentsFetcher(pathCustomerProfileSid, pathSid); + public static CustomerProfilesEntityAssignmentsFetcher fetcher( + final String pathCustomerProfileSid, + final String pathSid + ) { + return new CustomerProfilesEntityAssignmentsFetcher( + pathCustomerProfileSid, + pathSid + ); } - public static CustomerProfilesEntityAssignmentsReader reader(final String pathCustomerProfileSid){ - return new CustomerProfilesEntityAssignmentsReader(pathCustomerProfileSid); + public static CustomerProfilesEntityAssignmentsReader reader( + final String pathCustomerProfileSid + ) { + return new CustomerProfilesEntityAssignmentsReader( + pathCustomerProfileSid + ); } /** - * Converts a JSON String into a CustomerProfilesEntityAssignments object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return CustomerProfilesEntityAssignments object represented by the provided JSON - */ - public static CustomerProfilesEntityAssignments fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a CustomerProfilesEntityAssignments object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return CustomerProfilesEntityAssignments object represented by the provided JSON + */ + public static CustomerProfilesEntityAssignments fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, CustomerProfilesEntityAssignments.class); + return objectMapper.readValue( + json, + CustomerProfilesEntityAssignments.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -77,17 +101,23 @@ public static CustomerProfilesEntityAssignments fromJson(final String json, fina } /** - * Converts a JSON InputStream into a CustomerProfilesEntityAssignments object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return CustomerProfilesEntityAssignments object represented by the provided JSON - */ - public static CustomerProfilesEntityAssignments fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a CustomerProfilesEntityAssignments object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return CustomerProfilesEntityAssignments object represented by the provided JSON + */ + public static CustomerProfilesEntityAssignments fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, CustomerProfilesEntityAssignments.class); + return objectMapper.readValue( + json, + CustomerProfilesEntityAssignments.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -104,23 +134,12 @@ public static CustomerProfilesEntityAssignments fromJson(final InputStream json, @JsonCreator private CustomerProfilesEntityAssignments( - @JsonProperty("sid") - final String sid, - - @JsonProperty("customer_profile_sid") - final String customerProfileSid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("object_sid") - final String objectSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("customer_profile_sid") final String customerProfileSid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("object_sid") final String objectSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("url") final URI url ) { this.sid = sid; this.customerProfileSid = customerProfileSid; @@ -130,28 +149,33 @@ private CustomerProfilesEntityAssignments( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getCustomerProfileSid() { - return this.customerProfileSid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getObjectSid() { - return this.objectSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getCustomerProfileSid() { + return this.customerProfileSid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getObjectSid() { + return this.objectSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -159,15 +183,28 @@ public boolean equals(final Object o) { return false; } - CustomerProfilesEntityAssignments other = (CustomerProfilesEntityAssignments) o; - - return Objects.equals(sid, other.sid) && Objects.equals(customerProfileSid, other.customerProfileSid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(objectSid, other.objectSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(url, other.url) ; + CustomerProfilesEntityAssignments other = + (CustomerProfilesEntityAssignments) o; + + return ( + Objects.equals(sid, other.sid) && + Objects.equals(customerProfileSid, other.customerProfileSid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(objectSid, other.objectSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, customerProfileSid, accountSid, objectSid, dateCreated, url); + return Objects.hash( + sid, + customerProfileSid, + accountSid, + objectSid, + dateCreated, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesEntityAssignmentsCreator.java b/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesEntityAssignmentsCreator.java index 3e9c1c6a24..cb4e392542 100644 --- a/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesEntityAssignmentsCreator.java +++ b/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesEntityAssignmentsCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.trusthub.v1.customerprofiles; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,53 +25,73 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class CustomerProfilesEntityAssignmentsCreator + extends Creator { - - -public class CustomerProfilesEntityAssignmentsCreator extends Creator{ private String pathCustomerProfileSid; private String objectSid; - public CustomerProfilesEntityAssignmentsCreator(final String pathCustomerProfileSid, final String objectSid) { + public CustomerProfilesEntityAssignmentsCreator( + final String pathCustomerProfileSid, + final String objectSid + ) { this.pathCustomerProfileSid = pathCustomerProfileSid; this.objectSid = objectSid; } - public CustomerProfilesEntityAssignmentsCreator setObjectSid(final String objectSid){ + public CustomerProfilesEntityAssignmentsCreator setObjectSid( + final String objectSid + ) { this.objectSid = objectSid; return this; } @Override - public CustomerProfilesEntityAssignments create(final TwilioRestClient client){ - String path = "/v1/CustomerProfiles/{CustomerProfileSid}/EntityAssignments"; + public CustomerProfilesEntityAssignments create( + final TwilioRestClient client + ) { + String path = + "/v1/CustomerProfiles/{CustomerProfileSid}/EntityAssignments"; - path = path.replace("{"+"CustomerProfileSid"+"}", this.pathCustomerProfileSid.toString()); - path = path.replace("{"+"ObjectSid"+"}", this.objectSid.toString()); + path = + path.replace( + "{" + "CustomerProfileSid" + "}", + this.pathCustomerProfileSid.toString() + ); + path = path.replace("{" + "ObjectSid" + "}", this.objectSid.toString()); Request request = new Request( HttpMethod.POST, Domains.TRUSTHUB.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("CustomerProfilesEntityAssignments creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "CustomerProfilesEntityAssignments creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return CustomerProfilesEntityAssignments.fromJson(response.getStream(), client.getObjectMapper()); + return CustomerProfilesEntityAssignments.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (objectSid != null) { request.addPostParam("ObjectSid", objectSid); - } } } diff --git a/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesEntityAssignmentsDeleter.java b/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesEntityAssignmentsDeleter.java index 947a802aa0..71b2d0d68b 100644 --- a/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesEntityAssignmentsDeleter.java +++ b/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesEntityAssignmentsDeleter.java @@ -24,24 +24,31 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class CustomerProfilesEntityAssignmentsDeleter + extends Deleter { - -public class CustomerProfilesEntityAssignmentsDeleter extends Deleter { private String pathCustomerProfileSid; private String pathSid; - public CustomerProfilesEntityAssignmentsDeleter(final String pathCustomerProfileSid, final String pathSid){ + public CustomerProfilesEntityAssignmentsDeleter( + final String pathCustomerProfileSid, + final String pathSid + ) { this.pathCustomerProfileSid = pathCustomerProfileSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/v1/CustomerProfiles/{CustomerProfileSid}/EntityAssignments/{Sid}"; + String path = + "/v1/CustomerProfiles/{CustomerProfileSid}/EntityAssignments/{Sid}"; - path = path.replace("{"+"CustomerProfileSid"+"}", this.pathCustomerProfileSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "CustomerProfileSid" + "}", + this.pathCustomerProfileSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +58,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("CustomerProfilesEntityAssignments delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "CustomerProfilesEntityAssignments delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesEntityAssignmentsFetcher.java b/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesEntityAssignmentsFetcher.java index 51643bab56..6edb193676 100644 --- a/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesEntityAssignmentsFetcher.java +++ b/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesEntityAssignmentsFetcher.java @@ -24,25 +24,33 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class CustomerProfilesEntityAssignmentsFetcher + extends Fetcher { - - -public class CustomerProfilesEntityAssignmentsFetcher extends Fetcher { private String pathCustomerProfileSid; private String pathSid; - public CustomerProfilesEntityAssignmentsFetcher(final String pathCustomerProfileSid, final String pathSid){ + public CustomerProfilesEntityAssignmentsFetcher( + final String pathCustomerProfileSid, + final String pathSid + ) { this.pathCustomerProfileSid = pathCustomerProfileSid; this.pathSid = pathSid; } - @Override - public CustomerProfilesEntityAssignments fetch(final TwilioRestClient client) { - String path = "/v1/CustomerProfiles/{CustomerProfileSid}/EntityAssignments/{Sid}"; + public CustomerProfilesEntityAssignments fetch( + final TwilioRestClient client + ) { + String path = + "/v1/CustomerProfiles/{CustomerProfileSid}/EntityAssignments/{Sid}"; - path = path.replace("{"+"CustomerProfileSid"+"}", this.pathCustomerProfileSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "CustomerProfileSid" + "}", + this.pathCustomerProfileSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,15 +60,23 @@ public CustomerProfilesEntityAssignments fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("CustomerProfilesEntityAssignments fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "CustomerProfilesEntityAssignments fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return CustomerProfilesEntityAssignments.fromJson(response.getStream(), client.getObjectMapper()); + return CustomerProfilesEntityAssignments.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesEntityAssignmentsReader.java b/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesEntityAssignmentsReader.java index e240cc1142..867a88c20c 100644 --- a/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesEntityAssignmentsReader.java +++ b/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesEntityAssignmentsReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.trusthub.v1.customerprofiles; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,31 +25,43 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; +public class CustomerProfilesEntityAssignmentsReader + extends Reader { - -public class CustomerProfilesEntityAssignmentsReader extends Reader { private String pathCustomerProfileSid; private Integer pageSize; - public CustomerProfilesEntityAssignmentsReader(final String pathCustomerProfileSid){ + public CustomerProfilesEntityAssignmentsReader( + final String pathCustomerProfileSid + ) { this.pathCustomerProfileSid = pathCustomerProfileSid; } - public CustomerProfilesEntityAssignmentsReader setPageSize(final Integer pageSize){ + public CustomerProfilesEntityAssignmentsReader setPageSize( + final Integer pageSize + ) { this.pageSize = pageSize; return this; } @Override - public ResourceSet read(final TwilioRestClient client) { + public ResourceSet read( + final TwilioRestClient client + ) { return new ResourceSet<>(this, client, firstPage(client)); } - public Page firstPage(final TwilioRestClient client) { - String path = "/v1/CustomerProfiles/{CustomerProfileSid}/EntityAssignments"; - path = path.replace("{"+"CustomerProfileSid"+"}", this.pathCustomerProfileSid.toString()); + public Page firstPage( + final TwilioRestClient client + ) { + String path = + "/v1/CustomerProfiles/{CustomerProfileSid}/EntityAssignments"; + path = + path.replace( + "{" + "CustomerProfileSid" + "}", + this.pathCustomerProfileSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -60,13 +73,21 @@ public Page firstPage(final TwilioRestClient return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("CustomerProfilesEntityAssignments read failed: Unable to connect to server"); + throw new ApiConnectionException( + "CustomerProfilesEntityAssignments read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +103,10 @@ private Page pageForRequest(final TwilioRestC } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.TRUSTHUB.toString()) @@ -90,9 +114,11 @@ public Page previousPage(final Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.TRUSTHUB.toString()) @@ -101,21 +127,21 @@ public Page nextPage(final Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesEvaluations.java b/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesEvaluations.java index be16d8cc20..7d8c22992f 100644 --- a/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesEvaluations.java +++ b/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesEvaluations.java @@ -24,51 +24,67 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.List; import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class CustomerProfilesEvaluations extends Resource { + private static final long serialVersionUID = 45516903020077L; - public static CustomerProfilesEvaluationsCreator creator(final String pathCustomerProfileSid, final String policySid){ - return new CustomerProfilesEvaluationsCreator(pathCustomerProfileSid, policySid); + public static CustomerProfilesEvaluationsCreator creator( + final String pathCustomerProfileSid, + final String policySid + ) { + return new CustomerProfilesEvaluationsCreator( + pathCustomerProfileSid, + policySid + ); } - public static CustomerProfilesEvaluationsFetcher fetcher(final String pathCustomerProfileSid, final String pathSid){ - return new CustomerProfilesEvaluationsFetcher(pathCustomerProfileSid, pathSid); + public static CustomerProfilesEvaluationsFetcher fetcher( + final String pathCustomerProfileSid, + final String pathSid + ) { + return new CustomerProfilesEvaluationsFetcher( + pathCustomerProfileSid, + pathSid + ); } - public static CustomerProfilesEvaluationsReader reader(final String pathCustomerProfileSid){ + public static CustomerProfilesEvaluationsReader reader( + final String pathCustomerProfileSid + ) { return new CustomerProfilesEvaluationsReader(pathCustomerProfileSid); } /** - * Converts a JSON String into a CustomerProfilesEvaluations object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return CustomerProfilesEvaluations object represented by the provided JSON - */ - public static CustomerProfilesEvaluations fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a CustomerProfilesEvaluations object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return CustomerProfilesEvaluations object represented by the provided JSON + */ + public static CustomerProfilesEvaluations fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, CustomerProfilesEvaluations.class); + return objectMapper.readValue( + json, + CustomerProfilesEvaluations.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -77,23 +93,30 @@ public static CustomerProfilesEvaluations fromJson(final String json, final Obje } /** - * Converts a JSON InputStream into a CustomerProfilesEvaluations object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return CustomerProfilesEvaluations object represented by the provided JSON - */ - public static CustomerProfilesEvaluations fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a CustomerProfilesEvaluations object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return CustomerProfilesEvaluations object represented by the provided JSON + */ + public static CustomerProfilesEvaluations fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, CustomerProfilesEvaluations.class); + return objectMapper.readValue( + json, + CustomerProfilesEvaluations.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { throw new ApiConnectionException(e.getMessage(), e); } } + public enum Status { COMPLIANT("compliant"), NONCOMPLIANT("noncompliant"); @@ -125,29 +148,14 @@ public static Status forValue(final String value) { @JsonCreator private CustomerProfilesEvaluations( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("policy_sid") - final String policySid, - - @JsonProperty("customer_profile_sid") - final String customerProfileSid, - - @JsonProperty("status") - final CustomerProfilesEvaluations.Status status, - - @JsonProperty("results") - final List> results, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("policy_sid") final String policySid, + @JsonProperty("customer_profile_sid") final String customerProfileSid, + @JsonProperty("status") final CustomerProfilesEvaluations.Status status, + @JsonProperty("results") final List> results, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("url") final URI url ) { this.sid = sid; this.accountSid = accountSid; @@ -159,34 +167,41 @@ private CustomerProfilesEvaluations( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getPolicySid() { - return this.policySid; - } - public final String getCustomerProfileSid() { - return this.customerProfileSid; - } - public final CustomerProfilesEvaluations.Status getStatus() { - return this.status; - } - public final List> getResults() { - return this.results; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getPolicySid() { + return this.policySid; + } + + public final String getCustomerProfileSid() { + return this.customerProfileSid; + } + + public final CustomerProfilesEvaluations.Status getStatus() { + return this.status; + } + + public final List> getResults() { + return this.results; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -196,13 +211,29 @@ public boolean equals(final Object o) { CustomerProfilesEvaluations other = (CustomerProfilesEvaluations) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(policySid, other.policySid) && Objects.equals(customerProfileSid, other.customerProfileSid) && Objects.equals(status, other.status) && Objects.equals(results, other.results) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(policySid, other.policySid) && + Objects.equals(customerProfileSid, other.customerProfileSid) && + Objects.equals(status, other.status) && + Objects.equals(results, other.results) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, policySid, customerProfileSid, status, results, dateCreated, url); + return Objects.hash( + sid, + accountSid, + policySid, + customerProfileSid, + status, + results, + dateCreated, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesEvaluationsCreator.java b/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesEvaluationsCreator.java index 40c743b7cf..c64af22515 100644 --- a/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesEvaluationsCreator.java +++ b/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesEvaluationsCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.trusthub.v1.customerprofiles; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,53 +25,70 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class CustomerProfilesEvaluationsCreator + extends Creator { - - -public class CustomerProfilesEvaluationsCreator extends Creator{ private String pathCustomerProfileSid; private String policySid; - public CustomerProfilesEvaluationsCreator(final String pathCustomerProfileSid, final String policySid) { + public CustomerProfilesEvaluationsCreator( + final String pathCustomerProfileSid, + final String policySid + ) { this.pathCustomerProfileSid = pathCustomerProfileSid; this.policySid = policySid; } - public CustomerProfilesEvaluationsCreator setPolicySid(final String policySid){ + public CustomerProfilesEvaluationsCreator setPolicySid( + final String policySid + ) { this.policySid = policySid; return this; } @Override - public CustomerProfilesEvaluations create(final TwilioRestClient client){ + public CustomerProfilesEvaluations create(final TwilioRestClient client) { String path = "/v1/CustomerProfiles/{CustomerProfileSid}/Evaluations"; - path = path.replace("{"+"CustomerProfileSid"+"}", this.pathCustomerProfileSid.toString()); - path = path.replace("{"+"PolicySid"+"}", this.policySid.toString()); + path = + path.replace( + "{" + "CustomerProfileSid" + "}", + this.pathCustomerProfileSid.toString() + ); + path = path.replace("{" + "PolicySid" + "}", this.policySid.toString()); Request request = new Request( HttpMethod.POST, Domains.TRUSTHUB.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("CustomerProfilesEvaluations creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "CustomerProfilesEvaluations creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return CustomerProfilesEvaluations.fromJson(response.getStream(), client.getObjectMapper()); + return CustomerProfilesEvaluations.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (policySid != null) { request.addPostParam("PolicySid", policySid); - } } } diff --git a/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesEvaluationsFetcher.java b/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesEvaluationsFetcher.java index 9e34aaeae4..5c1e7539f0 100644 --- a/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesEvaluationsFetcher.java +++ b/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesEvaluationsFetcher.java @@ -24,25 +24,31 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class CustomerProfilesEvaluationsFetcher + extends Fetcher { - - -public class CustomerProfilesEvaluationsFetcher extends Fetcher { private String pathCustomerProfileSid; private String pathSid; - public CustomerProfilesEvaluationsFetcher(final String pathCustomerProfileSid, final String pathSid){ + public CustomerProfilesEvaluationsFetcher( + final String pathCustomerProfileSid, + final String pathSid + ) { this.pathCustomerProfileSid = pathCustomerProfileSid; this.pathSid = pathSid; } - @Override public CustomerProfilesEvaluations fetch(final TwilioRestClient client) { - String path = "/v1/CustomerProfiles/{CustomerProfileSid}/Evaluations/{Sid}"; + String path = + "/v1/CustomerProfiles/{CustomerProfileSid}/Evaluations/{Sid}"; - path = path.replace("{"+"CustomerProfileSid"+"}", this.pathCustomerProfileSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "CustomerProfileSid" + "}", + this.pathCustomerProfileSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,15 +58,23 @@ public CustomerProfilesEvaluations fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("CustomerProfilesEvaluations fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "CustomerProfilesEvaluations fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return CustomerProfilesEvaluations.fromJson(response.getStream(), client.getObjectMapper()); + return CustomerProfilesEvaluations.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesEvaluationsReader.java b/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesEvaluationsReader.java index 708e15b626..fc5d1779a8 100644 --- a/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesEvaluationsReader.java +++ b/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesEvaluationsReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.trusthub.v1.customerprofiles; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,31 +25,42 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; +public class CustomerProfilesEvaluationsReader + extends Reader { - -public class CustomerProfilesEvaluationsReader extends Reader { private String pathCustomerProfileSid; private Integer pageSize; - public CustomerProfilesEvaluationsReader(final String pathCustomerProfileSid){ + public CustomerProfilesEvaluationsReader( + final String pathCustomerProfileSid + ) { this.pathCustomerProfileSid = pathCustomerProfileSid; } - public CustomerProfilesEvaluationsReader setPageSize(final Integer pageSize){ + public CustomerProfilesEvaluationsReader setPageSize( + final Integer pageSize + ) { this.pageSize = pageSize; return this; } @Override - public ResourceSet read(final TwilioRestClient client) { + public ResourceSet read( + final TwilioRestClient client + ) { return new ResourceSet<>(this, client, firstPage(client)); } - public Page firstPage(final TwilioRestClient client) { + public Page firstPage( + final TwilioRestClient client + ) { String path = "/v1/CustomerProfiles/{CustomerProfileSid}/Evaluations"; - path = path.replace("{"+"CustomerProfileSid"+"}", this.pathCustomerProfileSid.toString()); + path = + path.replace( + "{" + "CustomerProfileSid" + "}", + this.pathCustomerProfileSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -60,13 +72,21 @@ public Page firstPage(final TwilioRestClient client return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("CustomerProfilesEvaluations read failed: Unable to connect to server"); + throw new ApiConnectionException( + "CustomerProfilesEvaluations read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +102,10 @@ private Page pageForRequest(final TwilioRestClient } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.TRUSTHUB.toString()) @@ -90,9 +113,11 @@ public Page previousPage(final Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.TRUSTHUB.toString()) @@ -101,21 +126,21 @@ public Page nextPage(final Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsChannelEndpointAssignment.java b/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsChannelEndpointAssignment.java index c69cb0afdc..bd2dc17915 100644 --- a/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsChannelEndpointAssignment.java +++ b/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsChannelEndpointAssignment.java @@ -23,52 +23,78 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class TrustProductsChannelEndpointAssignment extends Resource { + private static final long serialVersionUID = 19553243454529L; - public static TrustProductsChannelEndpointAssignmentCreator creator(final String pathTrustProductSid, final String channelEndpointType, final String channelEndpointSid){ - return new TrustProductsChannelEndpointAssignmentCreator(pathTrustProductSid, channelEndpointType, channelEndpointSid); + public static TrustProductsChannelEndpointAssignmentCreator creator( + final String pathTrustProductSid, + final String channelEndpointType, + final String channelEndpointSid + ) { + return new TrustProductsChannelEndpointAssignmentCreator( + pathTrustProductSid, + channelEndpointType, + channelEndpointSid + ); } - public static TrustProductsChannelEndpointAssignmentDeleter deleter(final String pathTrustProductSid, final String pathSid){ - return new TrustProductsChannelEndpointAssignmentDeleter(pathTrustProductSid, pathSid); + public static TrustProductsChannelEndpointAssignmentDeleter deleter( + final String pathTrustProductSid, + final String pathSid + ) { + return new TrustProductsChannelEndpointAssignmentDeleter( + pathTrustProductSid, + pathSid + ); } - public static TrustProductsChannelEndpointAssignmentFetcher fetcher(final String pathTrustProductSid, final String pathSid){ - return new TrustProductsChannelEndpointAssignmentFetcher(pathTrustProductSid, pathSid); + public static TrustProductsChannelEndpointAssignmentFetcher fetcher( + final String pathTrustProductSid, + final String pathSid + ) { + return new TrustProductsChannelEndpointAssignmentFetcher( + pathTrustProductSid, + pathSid + ); } - public static TrustProductsChannelEndpointAssignmentReader reader(final String pathTrustProductSid){ - return new TrustProductsChannelEndpointAssignmentReader(pathTrustProductSid); + public static TrustProductsChannelEndpointAssignmentReader reader( + final String pathTrustProductSid + ) { + return new TrustProductsChannelEndpointAssignmentReader( + pathTrustProductSid + ); } /** - * Converts a JSON String into a TrustProductsChannelEndpointAssignment object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return TrustProductsChannelEndpointAssignment object represented by the provided JSON - */ - public static TrustProductsChannelEndpointAssignment fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a TrustProductsChannelEndpointAssignment object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return TrustProductsChannelEndpointAssignment object represented by the provided JSON + */ + public static TrustProductsChannelEndpointAssignment fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, TrustProductsChannelEndpointAssignment.class); + return objectMapper.readValue( + json, + TrustProductsChannelEndpointAssignment.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -77,17 +103,23 @@ public static TrustProductsChannelEndpointAssignment fromJson(final String json, } /** - * Converts a JSON InputStream into a TrustProductsChannelEndpointAssignment object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return TrustProductsChannelEndpointAssignment object represented by the provided JSON - */ - public static TrustProductsChannelEndpointAssignment fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a TrustProductsChannelEndpointAssignment object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return TrustProductsChannelEndpointAssignment object represented by the provided JSON + */ + public static TrustProductsChannelEndpointAssignment fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, TrustProductsChannelEndpointAssignment.class); + return objectMapper.readValue( + json, + TrustProductsChannelEndpointAssignment.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -105,26 +137,13 @@ public static TrustProductsChannelEndpointAssignment fromJson(final InputStream @JsonCreator private TrustProductsChannelEndpointAssignment( - @JsonProperty("sid") - final String sid, - - @JsonProperty("trust_product_sid") - final String trustProductSid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("channel_endpoint_type") - final String channelEndpointType, - - @JsonProperty("channel_endpoint_sid") - final String channelEndpointSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("trust_product_sid") final String trustProductSid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("channel_endpoint_type") final String channelEndpointType, + @JsonProperty("channel_endpoint_sid") final String channelEndpointSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("url") final URI url ) { this.sid = sid; this.trustProductSid = trustProductSid; @@ -135,31 +154,37 @@ private TrustProductsChannelEndpointAssignment( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getTrustProductSid() { - return this.trustProductSid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getChannelEndpointType() { - return this.channelEndpointType; - } - public final String getChannelEndpointSid() { - return this.channelEndpointSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getTrustProductSid() { + return this.trustProductSid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getChannelEndpointType() { + return this.channelEndpointType; + } + + public final String getChannelEndpointSid() { + return this.channelEndpointSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -167,15 +192,30 @@ public boolean equals(final Object o) { return false; } - TrustProductsChannelEndpointAssignment other = (TrustProductsChannelEndpointAssignment) o; - - return Objects.equals(sid, other.sid) && Objects.equals(trustProductSid, other.trustProductSid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(channelEndpointType, other.channelEndpointType) && Objects.equals(channelEndpointSid, other.channelEndpointSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(url, other.url) ; + TrustProductsChannelEndpointAssignment other = + (TrustProductsChannelEndpointAssignment) o; + + return ( + Objects.equals(sid, other.sid) && + Objects.equals(trustProductSid, other.trustProductSid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(channelEndpointType, other.channelEndpointType) && + Objects.equals(channelEndpointSid, other.channelEndpointSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, trustProductSid, accountSid, channelEndpointType, channelEndpointSid, dateCreated, url); + return Objects.hash( + sid, + trustProductSid, + accountSid, + channelEndpointType, + channelEndpointSid, + dateCreated, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsChannelEndpointAssignmentCreator.java b/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsChannelEndpointAssignmentCreator.java index b9783f16bf..cc928c7ef9 100644 --- a/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsChannelEndpointAssignmentCreator.java +++ b/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsChannelEndpointAssignmentCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.trusthub.v1.trustproducts; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,64 +25,95 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class TrustProductsChannelEndpointAssignmentCreator + extends Creator { - - -public class TrustProductsChannelEndpointAssignmentCreator extends Creator{ private String pathTrustProductSid; private String channelEndpointType; private String channelEndpointSid; - public TrustProductsChannelEndpointAssignmentCreator(final String pathTrustProductSid, final String channelEndpointType, final String channelEndpointSid) { + public TrustProductsChannelEndpointAssignmentCreator( + final String pathTrustProductSid, + final String channelEndpointType, + final String channelEndpointSid + ) { this.pathTrustProductSid = pathTrustProductSid; this.channelEndpointType = channelEndpointType; this.channelEndpointSid = channelEndpointSid; } - public TrustProductsChannelEndpointAssignmentCreator setChannelEndpointType(final String channelEndpointType){ + public TrustProductsChannelEndpointAssignmentCreator setChannelEndpointType( + final String channelEndpointType + ) { this.channelEndpointType = channelEndpointType; return this; } - public TrustProductsChannelEndpointAssignmentCreator setChannelEndpointSid(final String channelEndpointSid){ + + public TrustProductsChannelEndpointAssignmentCreator setChannelEndpointSid( + final String channelEndpointSid + ) { this.channelEndpointSid = channelEndpointSid; return this; } @Override - public TrustProductsChannelEndpointAssignment create(final TwilioRestClient client){ - String path = "/v1/TrustProducts/{TrustProductSid}/ChannelEndpointAssignments"; + public TrustProductsChannelEndpointAssignment create( + final TwilioRestClient client + ) { + String path = + "/v1/TrustProducts/{TrustProductSid}/ChannelEndpointAssignments"; - path = path.replace("{"+"TrustProductSid"+"}", this.pathTrustProductSid.toString()); - path = path.replace("{"+"ChannelEndpointType"+"}", this.channelEndpointType.toString()); - path = path.replace("{"+"ChannelEndpointSid"+"}", this.channelEndpointSid.toString()); + path = + path.replace( + "{" + "TrustProductSid" + "}", + this.pathTrustProductSid.toString() + ); + path = + path.replace( + "{" + "ChannelEndpointType" + "}", + this.channelEndpointType.toString() + ); + path = + path.replace( + "{" + "ChannelEndpointSid" + "}", + this.channelEndpointSid.toString() + ); Request request = new Request( HttpMethod.POST, Domains.TRUSTHUB.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("TrustProductsChannelEndpointAssignment creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "TrustProductsChannelEndpointAssignment creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return TrustProductsChannelEndpointAssignment.fromJson(response.getStream(), client.getObjectMapper()); + return TrustProductsChannelEndpointAssignment.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (channelEndpointType != null) { request.addPostParam("ChannelEndpointType", channelEndpointType); - } if (channelEndpointSid != null) { request.addPostParam("ChannelEndpointSid", channelEndpointSid); - } } } diff --git a/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsChannelEndpointAssignmentDeleter.java b/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsChannelEndpointAssignmentDeleter.java index 37093581c4..b2586bb395 100644 --- a/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsChannelEndpointAssignmentDeleter.java +++ b/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsChannelEndpointAssignmentDeleter.java @@ -24,24 +24,31 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class TrustProductsChannelEndpointAssignmentDeleter + extends Deleter { - -public class TrustProductsChannelEndpointAssignmentDeleter extends Deleter { private String pathTrustProductSid; private String pathSid; - public TrustProductsChannelEndpointAssignmentDeleter(final String pathTrustProductSid, final String pathSid){ + public TrustProductsChannelEndpointAssignmentDeleter( + final String pathTrustProductSid, + final String pathSid + ) { this.pathTrustProductSid = pathTrustProductSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/v1/TrustProducts/{TrustProductSid}/ChannelEndpointAssignments/{Sid}"; + String path = + "/v1/TrustProducts/{TrustProductSid}/ChannelEndpointAssignments/{Sid}"; - path = path.replace("{"+"TrustProductSid"+"}", this.pathTrustProductSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "TrustProductSid" + "}", + this.pathTrustProductSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +58,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("TrustProductsChannelEndpointAssignment delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "TrustProductsChannelEndpointAssignment delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsChannelEndpointAssignmentFetcher.java b/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsChannelEndpointAssignmentFetcher.java index d93a287136..3833e0d8de 100644 --- a/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsChannelEndpointAssignmentFetcher.java +++ b/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsChannelEndpointAssignmentFetcher.java @@ -24,25 +24,33 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class TrustProductsChannelEndpointAssignmentFetcher + extends Fetcher { - - -public class TrustProductsChannelEndpointAssignmentFetcher extends Fetcher { private String pathTrustProductSid; private String pathSid; - public TrustProductsChannelEndpointAssignmentFetcher(final String pathTrustProductSid, final String pathSid){ + public TrustProductsChannelEndpointAssignmentFetcher( + final String pathTrustProductSid, + final String pathSid + ) { this.pathTrustProductSid = pathTrustProductSid; this.pathSid = pathSid; } - @Override - public TrustProductsChannelEndpointAssignment fetch(final TwilioRestClient client) { - String path = "/v1/TrustProducts/{TrustProductSid}/ChannelEndpointAssignments/{Sid}"; + public TrustProductsChannelEndpointAssignment fetch( + final TwilioRestClient client + ) { + String path = + "/v1/TrustProducts/{TrustProductSid}/ChannelEndpointAssignments/{Sid}"; - path = path.replace("{"+"TrustProductSid"+"}", this.pathTrustProductSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "TrustProductSid" + "}", + this.pathTrustProductSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,15 +60,23 @@ public TrustProductsChannelEndpointAssignment fetch(final TwilioRestClient clien Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("TrustProductsChannelEndpointAssignment fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "TrustProductsChannelEndpointAssignment fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return TrustProductsChannelEndpointAssignment.fromJson(response.getStream(), client.getObjectMapper()); + return TrustProductsChannelEndpointAssignment.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsChannelEndpointAssignmentReader.java b/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsChannelEndpointAssignmentReader.java index 17cd919d98..2bae5b4590 100644 --- a/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsChannelEndpointAssignmentReader.java +++ b/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsChannelEndpointAssignmentReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.trusthub.v1.trustproducts; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,41 +25,59 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - +public class TrustProductsChannelEndpointAssignmentReader + extends Reader { -public class TrustProductsChannelEndpointAssignmentReader extends Reader { private String pathTrustProductSid; private String channelEndpointSid; private String channelEndpointSids; private Integer pageSize; - public TrustProductsChannelEndpointAssignmentReader(final String pathTrustProductSid){ + public TrustProductsChannelEndpointAssignmentReader( + final String pathTrustProductSid + ) { this.pathTrustProductSid = pathTrustProductSid; } - public TrustProductsChannelEndpointAssignmentReader setChannelEndpointSid(final String channelEndpointSid){ + public TrustProductsChannelEndpointAssignmentReader setChannelEndpointSid( + final String channelEndpointSid + ) { this.channelEndpointSid = channelEndpointSid; return this; } - public TrustProductsChannelEndpointAssignmentReader setChannelEndpointSids(final String channelEndpointSids){ + + public TrustProductsChannelEndpointAssignmentReader setChannelEndpointSids( + final String channelEndpointSids + ) { this.channelEndpointSids = channelEndpointSids; return this; } - public TrustProductsChannelEndpointAssignmentReader setPageSize(final Integer pageSize){ + + public TrustProductsChannelEndpointAssignmentReader setPageSize( + final Integer pageSize + ) { this.pageSize = pageSize; return this; } @Override - public ResourceSet read(final TwilioRestClient client) { + public ResourceSet read( + final TwilioRestClient client + ) { return new ResourceSet<>(this, client, firstPage(client)); } - public Page firstPage(final TwilioRestClient client) { - String path = "/v1/TrustProducts/{TrustProductSid}/ChannelEndpointAssignments"; - path = path.replace("{"+"TrustProductSid"+"}", this.pathTrustProductSid.toString()); + public Page firstPage( + final TwilioRestClient client + ) { + String path = + "/v1/TrustProducts/{TrustProductSid}/ChannelEndpointAssignments"; + path = + path.replace( + "{" + "TrustProductSid" + "}", + this.pathTrustProductSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -70,13 +89,21 @@ public Page firstPage(final TwilioRestCl return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("TrustProductsChannelEndpointAssignment read failed: Unable to connect to server"); + throw new ApiConnectionException( + "TrustProductsChannelEndpointAssignment read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -92,7 +119,10 @@ private Page pageForRequest(final Twilio } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.TRUSTHUB.toString()) @@ -100,9 +130,11 @@ public Page previousPage(final Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.TRUSTHUB.toString()) @@ -111,29 +143,27 @@ public Page nextPage(final Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (channelEndpointSid != null) { - request.addQueryParam("ChannelEndpointSid", channelEndpointSid); } if (channelEndpointSids != null) { - request.addQueryParam("ChannelEndpointSids", channelEndpointSids); } if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsEntityAssignments.java b/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsEntityAssignments.java index 08f48901e0..7b65213d7e 100644 --- a/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsEntityAssignments.java +++ b/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsEntityAssignments.java @@ -23,52 +23,74 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class TrustProductsEntityAssignments extends Resource { + private static final long serialVersionUID = 11655766001892L; - public static TrustProductsEntityAssignmentsCreator creator(final String pathTrustProductSid, final String objectSid){ - return new TrustProductsEntityAssignmentsCreator(pathTrustProductSid, objectSid); + public static TrustProductsEntityAssignmentsCreator creator( + final String pathTrustProductSid, + final String objectSid + ) { + return new TrustProductsEntityAssignmentsCreator( + pathTrustProductSid, + objectSid + ); } - public static TrustProductsEntityAssignmentsDeleter deleter(final String pathTrustProductSid, final String pathSid){ - return new TrustProductsEntityAssignmentsDeleter(pathTrustProductSid, pathSid); + public static TrustProductsEntityAssignmentsDeleter deleter( + final String pathTrustProductSid, + final String pathSid + ) { + return new TrustProductsEntityAssignmentsDeleter( + pathTrustProductSid, + pathSid + ); } - public static TrustProductsEntityAssignmentsFetcher fetcher(final String pathTrustProductSid, final String pathSid){ - return new TrustProductsEntityAssignmentsFetcher(pathTrustProductSid, pathSid); + public static TrustProductsEntityAssignmentsFetcher fetcher( + final String pathTrustProductSid, + final String pathSid + ) { + return new TrustProductsEntityAssignmentsFetcher( + pathTrustProductSid, + pathSid + ); } - public static TrustProductsEntityAssignmentsReader reader(final String pathTrustProductSid){ + public static TrustProductsEntityAssignmentsReader reader( + final String pathTrustProductSid + ) { return new TrustProductsEntityAssignmentsReader(pathTrustProductSid); } /** - * Converts a JSON String into a TrustProductsEntityAssignments object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return TrustProductsEntityAssignments object represented by the provided JSON - */ - public static TrustProductsEntityAssignments fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a TrustProductsEntityAssignments object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return TrustProductsEntityAssignments object represented by the provided JSON + */ + public static TrustProductsEntityAssignments fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, TrustProductsEntityAssignments.class); + return objectMapper.readValue( + json, + TrustProductsEntityAssignments.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -77,17 +99,23 @@ public static TrustProductsEntityAssignments fromJson(final String json, final O } /** - * Converts a JSON InputStream into a TrustProductsEntityAssignments object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return TrustProductsEntityAssignments object represented by the provided JSON - */ - public static TrustProductsEntityAssignments fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a TrustProductsEntityAssignments object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return TrustProductsEntityAssignments object represented by the provided JSON + */ + public static TrustProductsEntityAssignments fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, TrustProductsEntityAssignments.class); + return objectMapper.readValue( + json, + TrustProductsEntityAssignments.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -104,23 +132,12 @@ public static TrustProductsEntityAssignments fromJson(final InputStream json, fi @JsonCreator private TrustProductsEntityAssignments( - @JsonProperty("sid") - final String sid, - - @JsonProperty("trust_product_sid") - final String trustProductSid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("object_sid") - final String objectSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("trust_product_sid") final String trustProductSid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("object_sid") final String objectSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("url") final URI url ) { this.sid = sid; this.trustProductSid = trustProductSid; @@ -130,28 +147,33 @@ private TrustProductsEntityAssignments( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getTrustProductSid() { - return this.trustProductSid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getObjectSid() { - return this.objectSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getTrustProductSid() { + return this.trustProductSid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getObjectSid() { + return this.objectSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -159,15 +181,28 @@ public boolean equals(final Object o) { return false; } - TrustProductsEntityAssignments other = (TrustProductsEntityAssignments) o; - - return Objects.equals(sid, other.sid) && Objects.equals(trustProductSid, other.trustProductSid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(objectSid, other.objectSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(url, other.url) ; + TrustProductsEntityAssignments other = + (TrustProductsEntityAssignments) o; + + return ( + Objects.equals(sid, other.sid) && + Objects.equals(trustProductSid, other.trustProductSid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(objectSid, other.objectSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, trustProductSid, accountSid, objectSid, dateCreated, url); + return Objects.hash( + sid, + trustProductSid, + accountSid, + objectSid, + dateCreated, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsEntityAssignmentsCreator.java b/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsEntityAssignmentsCreator.java index 801b0d0729..a57bc8b113 100644 --- a/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsEntityAssignmentsCreator.java +++ b/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsEntityAssignmentsCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.trusthub.v1.trustproducts; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,53 +25,72 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class TrustProductsEntityAssignmentsCreator + extends Creator { - - -public class TrustProductsEntityAssignmentsCreator extends Creator{ private String pathTrustProductSid; private String objectSid; - public TrustProductsEntityAssignmentsCreator(final String pathTrustProductSid, final String objectSid) { + public TrustProductsEntityAssignmentsCreator( + final String pathTrustProductSid, + final String objectSid + ) { this.pathTrustProductSid = pathTrustProductSid; this.objectSid = objectSid; } - public TrustProductsEntityAssignmentsCreator setObjectSid(final String objectSid){ + public TrustProductsEntityAssignmentsCreator setObjectSid( + final String objectSid + ) { this.objectSid = objectSid; return this; } @Override - public TrustProductsEntityAssignments create(final TwilioRestClient client){ + public TrustProductsEntityAssignments create( + final TwilioRestClient client + ) { String path = "/v1/TrustProducts/{TrustProductSid}/EntityAssignments"; - path = path.replace("{"+"TrustProductSid"+"}", this.pathTrustProductSid.toString()); - path = path.replace("{"+"ObjectSid"+"}", this.objectSid.toString()); + path = + path.replace( + "{" + "TrustProductSid" + "}", + this.pathTrustProductSid.toString() + ); + path = path.replace("{" + "ObjectSid" + "}", this.objectSid.toString()); Request request = new Request( HttpMethod.POST, Domains.TRUSTHUB.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("TrustProductsEntityAssignments creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "TrustProductsEntityAssignments creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return TrustProductsEntityAssignments.fromJson(response.getStream(), client.getObjectMapper()); + return TrustProductsEntityAssignments.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (objectSid != null) { request.addPostParam("ObjectSid", objectSid); - } } } diff --git a/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsEntityAssignmentsDeleter.java b/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsEntityAssignmentsDeleter.java index 642ceab9c3..fbcb4d2549 100644 --- a/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsEntityAssignmentsDeleter.java +++ b/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsEntityAssignmentsDeleter.java @@ -24,24 +24,31 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class TrustProductsEntityAssignmentsDeleter + extends Deleter { - -public class TrustProductsEntityAssignmentsDeleter extends Deleter { private String pathTrustProductSid; private String pathSid; - public TrustProductsEntityAssignmentsDeleter(final String pathTrustProductSid, final String pathSid){ + public TrustProductsEntityAssignmentsDeleter( + final String pathTrustProductSid, + final String pathSid + ) { this.pathTrustProductSid = pathTrustProductSid; this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { - String path = "/v1/TrustProducts/{TrustProductSid}/EntityAssignments/{Sid}"; + String path = + "/v1/TrustProducts/{TrustProductSid}/EntityAssignments/{Sid}"; - path = path.replace("{"+"TrustProductSid"+"}", this.pathTrustProductSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "TrustProductSid" + "}", + this.pathTrustProductSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -51,9 +58,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("TrustProductsEntityAssignments delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "TrustProductsEntityAssignments delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsEntityAssignmentsFetcher.java b/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsEntityAssignmentsFetcher.java index 253069839c..bf7507c528 100644 --- a/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsEntityAssignmentsFetcher.java +++ b/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsEntityAssignmentsFetcher.java @@ -24,25 +24,31 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class TrustProductsEntityAssignmentsFetcher + extends Fetcher { - - -public class TrustProductsEntityAssignmentsFetcher extends Fetcher { private String pathTrustProductSid; private String pathSid; - public TrustProductsEntityAssignmentsFetcher(final String pathTrustProductSid, final String pathSid){ + public TrustProductsEntityAssignmentsFetcher( + final String pathTrustProductSid, + final String pathSid + ) { this.pathTrustProductSid = pathTrustProductSid; this.pathSid = pathSid; } - @Override public TrustProductsEntityAssignments fetch(final TwilioRestClient client) { - String path = "/v1/TrustProducts/{TrustProductSid}/EntityAssignments/{Sid}"; + String path = + "/v1/TrustProducts/{TrustProductSid}/EntityAssignments/{Sid}"; - path = path.replace("{"+"TrustProductSid"+"}", this.pathTrustProductSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "TrustProductSid" + "}", + this.pathTrustProductSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,15 +58,23 @@ public TrustProductsEntityAssignments fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("TrustProductsEntityAssignments fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "TrustProductsEntityAssignments fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return TrustProductsEntityAssignments.fromJson(response.getStream(), client.getObjectMapper()); + return TrustProductsEntityAssignments.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsEntityAssignmentsReader.java b/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsEntityAssignmentsReader.java index 821287d19b..72d623bcbc 100644 --- a/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsEntityAssignmentsReader.java +++ b/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsEntityAssignmentsReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.trusthub.v1.trustproducts; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,31 +25,42 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; +public class TrustProductsEntityAssignmentsReader + extends Reader { - -public class TrustProductsEntityAssignmentsReader extends Reader { private String pathTrustProductSid; private Integer pageSize; - public TrustProductsEntityAssignmentsReader(final String pathTrustProductSid){ + public TrustProductsEntityAssignmentsReader( + final String pathTrustProductSid + ) { this.pathTrustProductSid = pathTrustProductSid; } - public TrustProductsEntityAssignmentsReader setPageSize(final Integer pageSize){ + public TrustProductsEntityAssignmentsReader setPageSize( + final Integer pageSize + ) { this.pageSize = pageSize; return this; } @Override - public ResourceSet read(final TwilioRestClient client) { + public ResourceSet read( + final TwilioRestClient client + ) { return new ResourceSet<>(this, client, firstPage(client)); } - public Page firstPage(final TwilioRestClient client) { + public Page firstPage( + final TwilioRestClient client + ) { String path = "/v1/TrustProducts/{TrustProductSid}/EntityAssignments"; - path = path.replace("{"+"TrustProductSid"+"}", this.pathTrustProductSid.toString()); + path = + path.replace( + "{" + "TrustProductSid" + "}", + this.pathTrustProductSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -60,13 +72,21 @@ public Page firstPage(final TwilioRestClient cli return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("TrustProductsEntityAssignments read failed: Unable to connect to server"); + throw new ApiConnectionException( + "TrustProductsEntityAssignments read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +102,10 @@ private Page pageForRequest(final TwilioRestClie } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.TRUSTHUB.toString()) @@ -90,9 +113,11 @@ public Page previousPage(final Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.TRUSTHUB.toString()) @@ -101,21 +126,21 @@ public Page nextPage(final Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsEvaluations.java b/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsEvaluations.java index 48a40ff937..9f28463b0e 100644 --- a/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsEvaluations.java +++ b/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsEvaluations.java @@ -24,48 +24,61 @@ import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.List; import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class TrustProductsEvaluations extends Resource { + private static final long serialVersionUID = 86634042597263L; - public static TrustProductsEvaluationsCreator creator(final String pathTrustProductSid, final String policySid){ - return new TrustProductsEvaluationsCreator(pathTrustProductSid, policySid); + public static TrustProductsEvaluationsCreator creator( + final String pathTrustProductSid, + final String policySid + ) { + return new TrustProductsEvaluationsCreator( + pathTrustProductSid, + policySid + ); } - public static TrustProductsEvaluationsFetcher fetcher(final String pathTrustProductSid, final String pathSid){ - return new TrustProductsEvaluationsFetcher(pathTrustProductSid, pathSid); + public static TrustProductsEvaluationsFetcher fetcher( + final String pathTrustProductSid, + final String pathSid + ) { + return new TrustProductsEvaluationsFetcher( + pathTrustProductSid, + pathSid + ); } - public static TrustProductsEvaluationsReader reader(final String pathTrustProductSid){ + public static TrustProductsEvaluationsReader reader( + final String pathTrustProductSid + ) { return new TrustProductsEvaluationsReader(pathTrustProductSid); } /** - * Converts a JSON String into a TrustProductsEvaluations object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return TrustProductsEvaluations object represented by the provided JSON - */ - public static TrustProductsEvaluations fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a TrustProductsEvaluations object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return TrustProductsEvaluations object represented by the provided JSON + */ + public static TrustProductsEvaluations fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, TrustProductsEvaluations.class); @@ -77,14 +90,17 @@ public static TrustProductsEvaluations fromJson(final String json, final ObjectM } /** - * Converts a JSON InputStream into a TrustProductsEvaluations object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return TrustProductsEvaluations object represented by the provided JSON - */ - public static TrustProductsEvaluations fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a TrustProductsEvaluations object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return TrustProductsEvaluations object represented by the provided JSON + */ + public static TrustProductsEvaluations fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, TrustProductsEvaluations.class); @@ -94,6 +110,7 @@ public static TrustProductsEvaluations fromJson(final InputStream json, final Ob throw new ApiConnectionException(e.getMessage(), e); } } + public enum Status { COMPLIANT("compliant"), NONCOMPLIANT("noncompliant"); @@ -125,29 +142,14 @@ public static Status forValue(final String value) { @JsonCreator private TrustProductsEvaluations( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("policy_sid") - final String policySid, - - @JsonProperty("trust_product_sid") - final String trustProductSid, - - @JsonProperty("status") - final TrustProductsEvaluations.Status status, - - @JsonProperty("results") - final List> results, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("policy_sid") final String policySid, + @JsonProperty("trust_product_sid") final String trustProductSid, + @JsonProperty("status") final TrustProductsEvaluations.Status status, + @JsonProperty("results") final List> results, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("url") final URI url ) { this.sid = sid; this.accountSid = accountSid; @@ -159,34 +161,41 @@ private TrustProductsEvaluations( this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getPolicySid() { - return this.policySid; - } - public final String getTrustProductSid() { - return this.trustProductSid; - } - public final TrustProductsEvaluations.Status getStatus() { - return this.status; - } - public final List> getResults() { - return this.results; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getPolicySid() { + return this.policySid; + } + + public final String getTrustProductSid() { + return this.trustProductSid; + } + + public final TrustProductsEvaluations.Status getStatus() { + return this.status; + } + + public final List> getResults() { + return this.results; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -196,13 +205,29 @@ public boolean equals(final Object o) { TrustProductsEvaluations other = (TrustProductsEvaluations) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(policySid, other.policySid) && Objects.equals(trustProductSid, other.trustProductSid) && Objects.equals(status, other.status) && Objects.equals(results, other.results) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(policySid, other.policySid) && + Objects.equals(trustProductSid, other.trustProductSid) && + Objects.equals(status, other.status) && + Objects.equals(results, other.results) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, policySid, trustProductSid, status, results, dateCreated, url); + return Objects.hash( + sid, + accountSid, + policySid, + trustProductSid, + status, + results, + dateCreated, + url + ); } - } - diff --git a/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsEvaluationsCreator.java b/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsEvaluationsCreator.java index 3605a21730..3be3b59e1b 100644 --- a/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsEvaluationsCreator.java +++ b/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsEvaluationsCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.trusthub.v1.trustproducts; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,53 +25,70 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class TrustProductsEvaluationsCreator + extends Creator { - - -public class TrustProductsEvaluationsCreator extends Creator{ private String pathTrustProductSid; private String policySid; - public TrustProductsEvaluationsCreator(final String pathTrustProductSid, final String policySid) { + public TrustProductsEvaluationsCreator( + final String pathTrustProductSid, + final String policySid + ) { this.pathTrustProductSid = pathTrustProductSid; this.policySid = policySid; } - public TrustProductsEvaluationsCreator setPolicySid(final String policySid){ + public TrustProductsEvaluationsCreator setPolicySid( + final String policySid + ) { this.policySid = policySid; return this; } @Override - public TrustProductsEvaluations create(final TwilioRestClient client){ + public TrustProductsEvaluations create(final TwilioRestClient client) { String path = "/v1/TrustProducts/{TrustProductSid}/Evaluations"; - path = path.replace("{"+"TrustProductSid"+"}", this.pathTrustProductSid.toString()); - path = path.replace("{"+"PolicySid"+"}", this.policySid.toString()); + path = + path.replace( + "{" + "TrustProductSid" + "}", + this.pathTrustProductSid.toString() + ); + path = path.replace("{" + "PolicySid" + "}", this.policySid.toString()); Request request = new Request( HttpMethod.POST, Domains.TRUSTHUB.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("TrustProductsEvaluations creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "TrustProductsEvaluations creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return TrustProductsEvaluations.fromJson(response.getStream(), client.getObjectMapper()); + return TrustProductsEvaluations.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (policySid != null) { request.addPostParam("PolicySid", policySid); - } } } diff --git a/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsEvaluationsFetcher.java b/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsEvaluationsFetcher.java index 3706150334..4b5c969df5 100644 --- a/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsEvaluationsFetcher.java +++ b/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsEvaluationsFetcher.java @@ -24,25 +24,30 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class TrustProductsEvaluationsFetcher + extends Fetcher { - - -public class TrustProductsEvaluationsFetcher extends Fetcher { private String pathTrustProductSid; private String pathSid; - public TrustProductsEvaluationsFetcher(final String pathTrustProductSid, final String pathSid){ + public TrustProductsEvaluationsFetcher( + final String pathTrustProductSid, + final String pathSid + ) { this.pathTrustProductSid = pathTrustProductSid; this.pathSid = pathSid; } - @Override public TrustProductsEvaluations fetch(final TwilioRestClient client) { String path = "/v1/TrustProducts/{TrustProductSid}/Evaluations/{Sid}"; - path = path.replace("{"+"TrustProductSid"+"}", this.pathTrustProductSid.toString()); - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = + path.replace( + "{" + "TrustProductSid" + "}", + this.pathTrustProductSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -52,15 +57,23 @@ public TrustProductsEvaluations fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("TrustProductsEvaluations fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "TrustProductsEvaluations fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return TrustProductsEvaluations.fromJson(response.getStream(), client.getObjectMapper()); + return TrustProductsEvaluations.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsEvaluationsReader.java b/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsEvaluationsReader.java index 0ef0d8de56..f096eb5f58 100644 --- a/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsEvaluationsReader.java +++ b/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsEvaluationsReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.trusthub.v1.trustproducts; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,31 +25,38 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; +public class TrustProductsEvaluationsReader + extends Reader { - -public class TrustProductsEvaluationsReader extends Reader { private String pathTrustProductSid; private Integer pageSize; - public TrustProductsEvaluationsReader(final String pathTrustProductSid){ + public TrustProductsEvaluationsReader(final String pathTrustProductSid) { this.pathTrustProductSid = pathTrustProductSid; } - public TrustProductsEvaluationsReader setPageSize(final Integer pageSize){ + public TrustProductsEvaluationsReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @Override - public ResourceSet read(final TwilioRestClient client) { + public ResourceSet read( + final TwilioRestClient client + ) { return new ResourceSet<>(this, client, firstPage(client)); } - public Page firstPage(final TwilioRestClient client) { + public Page firstPage( + final TwilioRestClient client + ) { String path = "/v1/TrustProducts/{TrustProductSid}/Evaluations"; - path = path.replace("{"+"TrustProductSid"+"}", this.pathTrustProductSid.toString()); + path = + path.replace( + "{" + "TrustProductSid" + "}", + this.pathTrustProductSid.toString() + ); Request request = new Request( HttpMethod.GET, @@ -60,13 +68,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("TrustProductsEvaluations read failed: Unable to connect to server"); + throw new ApiConnectionException( + "TrustProductsEvaluations read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -82,7 +98,10 @@ private Page pageForRequest(final TwilioRestClient cli } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.TRUSTHUB.toString()) @@ -90,9 +109,11 @@ public Page previousPage(final Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.TRUSTHUB.toString()) @@ -101,21 +122,21 @@ public Page nextPage(final Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/verify/v2/Form.java b/src/main/java/com/twilio/rest/verify/v2/Form.java index 36c1f6bc71..85b9ebec6a 100644 --- a/src/main/java/com/twilio/rest/verify/v2/Form.java +++ b/src/main/java/com/twilio/rest/verify/v2/Form.java @@ -23,38 +23,37 @@ import com.twilio.base.Resource; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Form extends Resource { + private static final long serialVersionUID = 202517967097226L; - public static FormFetcher fetcher(final Form.FormTypes formType){ + public static FormFetcher fetcher(final Form.FormTypes formType) { return new FormFetcher(formType); } /** - * Converts a JSON String into a Form object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Form object represented by the provided JSON - */ - public static Form fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Form object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Form object represented by the provided JSON + */ + public static Form fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Form.class); @@ -66,14 +65,17 @@ public static Form fromJson(final String json, final ObjectMapper objectMapper) } /** - * Converts a JSON InputStream into a Form object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Form object represented by the provided JSON - */ - public static Form fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Form object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Form object represented by the provided JSON + */ + public static Form fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Form.class); @@ -83,6 +85,7 @@ public static Form fromJson(final InputStream json, final ObjectMapper objectMap throw new ApiConnectionException(e.getMessage(), e); } } + public enum FormTypes { FORM_PUSH("form-push"); @@ -109,17 +112,10 @@ public static FormTypes forValue(final String value) { @JsonCreator private Form( - @JsonProperty("form_type") - final Form.FormTypes formType, - - @JsonProperty("forms") - final Map forms, - - @JsonProperty("form_meta") - final Map formMeta, - - @JsonProperty("url") - final URI url + @JsonProperty("form_type") final Form.FormTypes formType, + @JsonProperty("forms") final Map forms, + @JsonProperty("form_meta") final Map formMeta, + @JsonProperty("url") final URI url ) { this.formType = formType; this.forms = forms; @@ -127,22 +123,25 @@ private Form( this.url = url; } - public final Form.FormTypes getFormType() { - return this.formType; - } - public final Map getForms() { - return this.forms; - } - public final Map getFormMeta() { - return this.formMeta; - } - public final URI getUrl() { - return this.url; - } + public final Form.FormTypes getFormType() { + return this.formType; + } + + public final Map getForms() { + return this.forms; + } + + public final Map getFormMeta() { + return this.formMeta; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -152,13 +151,16 @@ public boolean equals(final Object o) { Form other = (Form) o; - return Objects.equals(formType, other.formType) && Objects.equals(forms, other.forms) && Objects.equals(formMeta, other.formMeta) && Objects.equals(url, other.url) ; + return ( + Objects.equals(formType, other.formType) && + Objects.equals(forms, other.forms) && + Objects.equals(formMeta, other.formMeta) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { return Objects.hash(formType, forms, formMeta, url); } - } - diff --git a/src/main/java/com/twilio/rest/verify/v2/FormFetcher.java b/src/main/java/com/twilio/rest/verify/v2/FormFetcher.java index 5bf224354d..b9f62cdf8e 100644 --- a/src/main/java/com/twilio/rest/verify/v2/FormFetcher.java +++ b/src/main/java/com/twilio/rest/verify/v2/FormFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class FormFetcher extends Fetcher
{ + private Form.FormTypes formType; - public FormFetcher(final Form.FormTypes formType){ + public FormFetcher(final Form.FormTypes formType) { this.formType = formType; } - @Override public Form fetch(final TwilioRestClient client) { String path = "/v2/Forms/{FormType}"; - path = path.replace("{"+"FormType"+"}", this.formType.toString()); + path = path.replace("{" + "FormType" + "}", this.formType.toString()); Request request = new Request( HttpMethod.GET, @@ -49,9 +46,14 @@ public Form fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Form fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Form fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/verify/v2/Safelist.java b/src/main/java/com/twilio/rest/verify/v2/Safelist.java index 200e41e3f2..2e675aecab 100644 --- a/src/main/java/com/twilio/rest/verify/v2/Safelist.java +++ b/src/main/java/com/twilio/rest/verify/v2/Safelist.java @@ -22,44 +22,43 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; - import java.util.Objects; - - +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Safelist extends Resource { + private static final long serialVersionUID = 83566412587236L; - public static SafelistCreator creator(final String phoneNumber){ + public static SafelistCreator creator(final String phoneNumber) { return new SafelistCreator(phoneNumber); } - public static SafelistDeleter deleter(final String pathPhoneNumber){ + public static SafelistDeleter deleter(final String pathPhoneNumber) { return new SafelistDeleter(pathPhoneNumber); } - public static SafelistFetcher fetcher(final String pathPhoneNumber){ + public static SafelistFetcher fetcher(final String pathPhoneNumber) { return new SafelistFetcher(pathPhoneNumber); } /** - * Converts a JSON String into a Safelist object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Safelist object represented by the provided JSON - */ - public static Safelist fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Safelist object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Safelist object represented by the provided JSON + */ + public static Safelist fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Safelist.class); @@ -71,14 +70,17 @@ public static Safelist fromJson(final String json, final ObjectMapper objectMapp } /** - * Converts a JSON InputStream into a Safelist object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Safelist object represented by the provided JSON - */ - public static Safelist fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Safelist object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Safelist object represented by the provided JSON + */ + public static Safelist fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Safelist.class); @@ -95,33 +97,30 @@ public static Safelist fromJson(final InputStream json, final ObjectMapper objec @JsonCreator private Safelist( - @JsonProperty("sid") - final String sid, - - @JsonProperty("phone_number") - final String phoneNumber, - - @JsonProperty("url") - final URI url + @JsonProperty("sid") final String sid, + @JsonProperty("phone_number") final String phoneNumber, + @JsonProperty("url") final URI url ) { this.sid = sid; this.phoneNumber = phoneNumber; this.url = url; } - public final String getSid() { - return this.sid; - } - public final String getPhoneNumber() { - return this.phoneNumber; - } - public final URI getUrl() { - return this.url; - } + public final String getSid() { + return this.sid; + } + + public final String getPhoneNumber() { + return this.phoneNumber; + } + + public final URI getUrl() { + return this.url; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -131,13 +130,15 @@ public boolean equals(final Object o) { Safelist other = (Safelist) o; - return Objects.equals(sid, other.sid) && Objects.equals(phoneNumber, other.phoneNumber) && Objects.equals(url, other.url) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(phoneNumber, other.phoneNumber) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { return Objects.hash(sid, phoneNumber, url); } - } - diff --git a/src/main/java/com/twilio/rest/verify/v2/SafelistCreator.java b/src/main/java/com/twilio/rest/verify/v2/SafelistCreator.java index 31ab639f83..366e4b27e2 100644 --- a/src/main/java/com/twilio/rest/verify/v2/SafelistCreator.java +++ b/src/main/java/com/twilio/rest/verify/v2/SafelistCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.verify.v2; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,50 +25,61 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class SafelistCreator extends Creator { - - -public class SafelistCreator extends Creator{ private String phoneNumber; public SafelistCreator(final String phoneNumber) { this.phoneNumber = phoneNumber; } - public SafelistCreator setPhoneNumber(final String phoneNumber){ + public SafelistCreator setPhoneNumber(final String phoneNumber) { this.phoneNumber = phoneNumber; return this; } @Override - public Safelist create(final TwilioRestClient client){ + public Safelist create(final TwilioRestClient client) { String path = "/v2/SafeList/Numbers"; - path = path.replace("{"+"PhoneNumber"+"}", this.phoneNumber.toString()); + path = + path.replace( + "{" + "PhoneNumber" + "}", + this.phoneNumber.toString() + ); Request request = new Request( HttpMethod.POST, Domains.VERIFY.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Safelist creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Safelist creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Safelist.fromJson(response.getStream(), client.getObjectMapper()); + return Safelist.fromJson( + response.getStream(), + client.getObjectMapper() + ); } + private void addPostParams(final Request request) { if (phoneNumber != null) { request.addPostParam("PhoneNumber", phoneNumber); - } } } diff --git a/src/main/java/com/twilio/rest/verify/v2/SafelistDeleter.java b/src/main/java/com/twilio/rest/verify/v2/SafelistDeleter.java index c33ebae8bd..63aa55dfdb 100644 --- a/src/main/java/com/twilio/rest/verify/v2/SafelistDeleter.java +++ b/src/main/java/com/twilio/rest/verify/v2/SafelistDeleter.java @@ -24,21 +24,23 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class SafelistDeleter extends Deleter { + private String pathPhoneNumber; - public SafelistDeleter(final String pathPhoneNumber){ + public SafelistDeleter(final String pathPhoneNumber) { this.pathPhoneNumber = pathPhoneNumber; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v2/SafeList/Numbers/{PhoneNumber}"; - path = path.replace("{"+"PhoneNumber"+"}", this.pathPhoneNumber.toString()); + path = + path.replace( + "{" + "PhoneNumber" + "}", + this.pathPhoneNumber.toString() + ); Request request = new Request( HttpMethod.DELETE, @@ -48,9 +50,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Safelist delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Safelist delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/verify/v2/SafelistFetcher.java b/src/main/java/com/twilio/rest/verify/v2/SafelistFetcher.java index abbbac91bd..1033aec1fc 100644 --- a/src/main/java/com/twilio/rest/verify/v2/SafelistFetcher.java +++ b/src/main/java/com/twilio/rest/verify/v2/SafelistFetcher.java @@ -24,22 +24,23 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class SafelistFetcher extends Fetcher { + private String pathPhoneNumber; - public SafelistFetcher(final String pathPhoneNumber){ + public SafelistFetcher(final String pathPhoneNumber) { this.pathPhoneNumber = pathPhoneNumber; } - @Override public Safelist fetch(final TwilioRestClient client) { String path = "/v2/SafeList/Numbers/{PhoneNumber}"; - path = path.replace("{"+"PhoneNumber"+"}", this.pathPhoneNumber.toString()); + path = + path.replace( + "{" + "PhoneNumber" + "}", + this.pathPhoneNumber.toString() + ); Request request = new Request( HttpMethod.GET, @@ -49,15 +50,23 @@ public Safelist fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Safelist fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Safelist fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } throw new ApiException(restException); } - return Safelist.fromJson(response.getStream(), client.getObjectMapper()); + return Safelist.fromJson( + response.getStream(), + client.getObjectMapper() + ); } } diff --git a/src/main/java/com/twilio/rest/verify/v2/Service.java b/src/main/java/com/twilio/rest/verify/v2/Service.java index 5efd1b6ba5..17fa76b9aa 100644 --- a/src/main/java/com/twilio/rest/verify/v2/Service.java +++ b/src/main/java/com/twilio/rest/verify/v2/Service.java @@ -23,55 +23,54 @@ import com.twilio.base.Resource; import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.time.ZonedDateTime; - import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Service extends Resource { + private static final long serialVersionUID = 9486445456747L; - public static ServiceCreator creator(final String friendlyName){ + public static ServiceCreator creator(final String friendlyName) { return new ServiceCreator(friendlyName); } - public static ServiceDeleter deleter(final String pathSid){ + public static ServiceDeleter deleter(final String pathSid) { return new ServiceDeleter(pathSid); } - public static ServiceFetcher fetcher(final String pathSid){ + public static ServiceFetcher fetcher(final String pathSid) { return new ServiceFetcher(pathSid); } - public static ServiceReader reader(){ + public static ServiceReader reader() { return new ServiceReader(); } - public static ServiceUpdater updater(final String pathSid){ + public static ServiceUpdater updater(final String pathSid) { return new ServiceUpdater(pathSid); } /** - * Converts a JSON String into a Service object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Service object represented by the provided JSON - */ - public static Service fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Service object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Service object represented by the provided JSON + */ + public static Service fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Service.class); @@ -83,14 +82,17 @@ public static Service fromJson(final String json, final ObjectMapper objectMappe } /** - * Converts a JSON InputStream into a Service object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Service object represented by the provided JSON - */ - public static Service fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Service object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Service object represented by the provided JSON + */ + public static Service fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Service.class); @@ -122,59 +124,26 @@ public static Service fromJson(final InputStream json, final ObjectMapper object @JsonCreator private Service( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("code_length") - final Integer codeLength, - - @JsonProperty("lookup_enabled") - final Boolean lookupEnabled, - - @JsonProperty("psd2_enabled") - final Boolean psd2Enabled, - - @JsonProperty("skip_sms_to_landlines") - final Boolean skipSmsToLandlines, - - @JsonProperty("dtmf_input_required") - final Boolean dtmfInputRequired, - - @JsonProperty("tts_name") - final String ttsName, - - @JsonProperty("do_not_share_warning_enabled") - final Boolean doNotShareWarningEnabled, - - @JsonProperty("custom_code_enabled") - final Boolean customCodeEnabled, - - @JsonProperty("push") - final Map push, - - @JsonProperty("totp") - final Map totp, - - @JsonProperty("default_template_sid") - final String defaultTemplateSid, - - @JsonProperty("date_created") - final String dateCreated, - - @JsonProperty("date_updated") - final String dateUpdated, - - @JsonProperty("url") - final URI url, - - @JsonProperty("links") - final Map links + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("code_length") final Integer codeLength, + @JsonProperty("lookup_enabled") final Boolean lookupEnabled, + @JsonProperty("psd2_enabled") final Boolean psd2Enabled, + @JsonProperty("skip_sms_to_landlines") final Boolean skipSmsToLandlines, + @JsonProperty("dtmf_input_required") final Boolean dtmfInputRequired, + @JsonProperty("tts_name") final String ttsName, + @JsonProperty( + "do_not_share_warning_enabled" + ) final Boolean doNotShareWarningEnabled, + @JsonProperty("custom_code_enabled") final Boolean customCodeEnabled, + @JsonProperty("push") final Map push, + @JsonProperty("totp") final Map totp, + @JsonProperty("default_template_sid") final String defaultTemplateSid, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("url") final URI url, + @JsonProperty("links") final Map links ) { this.sid = sid; this.accountSid = accountSid; @@ -196,64 +165,81 @@ private Service( this.links = links; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final Integer getCodeLength() { - return this.codeLength; - } - public final Boolean getLookupEnabled() { - return this.lookupEnabled; - } - public final Boolean getPsd2Enabled() { - return this.psd2Enabled; - } - public final Boolean getSkipSmsToLandlines() { - return this.skipSmsToLandlines; - } - public final Boolean getDtmfInputRequired() { - return this.dtmfInputRequired; - } - public final String getTtsName() { - return this.ttsName; - } - public final Boolean getDoNotShareWarningEnabled() { - return this.doNotShareWarningEnabled; - } - public final Boolean getCustomCodeEnabled() { - return this.customCodeEnabled; - } - public final Map getPush() { - return this.push; - } - public final Map getTotp() { - return this.totp; - } - public final String getDefaultTemplateSid() { - return this.defaultTemplateSid; - } - public final ZonedDateTime getDateCreated() { - return this.dateCreated; - } - public final ZonedDateTime getDateUpdated() { - return this.dateUpdated; - } - public final URI getUrl() { - return this.url; - } - public final Map getLinks() { - return this.links; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final Integer getCodeLength() { + return this.codeLength; + } + + public final Boolean getLookupEnabled() { + return this.lookupEnabled; + } + + public final Boolean getPsd2Enabled() { + return this.psd2Enabled; + } + + public final Boolean getSkipSmsToLandlines() { + return this.skipSmsToLandlines; + } + + public final Boolean getDtmfInputRequired() { + return this.dtmfInputRequired; + } + + public final String getTtsName() { + return this.ttsName; + } + + public final Boolean getDoNotShareWarningEnabled() { + return this.doNotShareWarningEnabled; + } + + public final Boolean getCustomCodeEnabled() { + return this.customCodeEnabled; + } + + public final Map getPush() { + return this.push; + } + + public final Map getTotp() { + return this.totp; + } + + public final String getDefaultTemplateSid() { + return this.defaultTemplateSid; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final URI getUrl() { + return this.url; + } + + public final Map getLinks() { + return this.links; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -263,13 +249,52 @@ public boolean equals(final Object o) { Service other = (Service) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(codeLength, other.codeLength) && Objects.equals(lookupEnabled, other.lookupEnabled) && Objects.equals(psd2Enabled, other.psd2Enabled) && Objects.equals(skipSmsToLandlines, other.skipSmsToLandlines) && Objects.equals(dtmfInputRequired, other.dtmfInputRequired) && Objects.equals(ttsName, other.ttsName) && Objects.equals(doNotShareWarningEnabled, other.doNotShareWarningEnabled) && Objects.equals(customCodeEnabled, other.customCodeEnabled) && Objects.equals(push, other.push) && Objects.equals(totp, other.totp) && Objects.equals(defaultTemplateSid, other.defaultTemplateSid) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && Objects.equals(url, other.url) && Objects.equals(links, other.links) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(codeLength, other.codeLength) && + Objects.equals(lookupEnabled, other.lookupEnabled) && + Objects.equals(psd2Enabled, other.psd2Enabled) && + Objects.equals(skipSmsToLandlines, other.skipSmsToLandlines) && + Objects.equals(dtmfInputRequired, other.dtmfInputRequired) && + Objects.equals(ttsName, other.ttsName) && + Objects.equals( + doNotShareWarningEnabled, + other.doNotShareWarningEnabled + ) && + Objects.equals(customCodeEnabled, other.customCodeEnabled) && + Objects.equals(push, other.push) && + Objects.equals(totp, other.totp) && + Objects.equals(defaultTemplateSid, other.defaultTemplateSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) && + Objects.equals(links, other.links) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, friendlyName, codeLength, lookupEnabled, psd2Enabled, skipSmsToLandlines, dtmfInputRequired, ttsName, doNotShareWarningEnabled, customCodeEnabled, push, totp, defaultTemplateSid, dateCreated, dateUpdated, url, links); + return Objects.hash( + sid, + accountSid, + friendlyName, + codeLength, + lookupEnabled, + psd2Enabled, + skipSmsToLandlines, + dtmfInputRequired, + ttsName, + doNotShareWarningEnabled, + customCodeEnabled, + push, + totp, + defaultTemplateSid, + dateCreated, + dateUpdated, + url, + links + ); } - } - diff --git a/src/main/java/com/twilio/rest/verify/v2/ServiceCreator.java b/src/main/java/com/twilio/rest/verify/v2/ServiceCreator.java index 678d86a3ca..c75fd4811f 100644 --- a/src/main/java/com/twilio/rest/verify/v2/ServiceCreator.java +++ b/src/main/java/com/twilio/rest/verify/v2/ServiceCreator.java @@ -15,6 +15,7 @@ package com.twilio.rest.verify.v2; import com.twilio.base.Creator; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class ServiceCreator extends Creator { - - -public class ServiceCreator extends Creator{ private String friendlyName; private Integer codeLength; private Boolean lookupEnabled; @@ -50,92 +49,132 @@ public ServiceCreator(final String friendlyName) { this.friendlyName = friendlyName; } - public ServiceCreator setFriendlyName(final String friendlyName){ + public ServiceCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public ServiceCreator setCodeLength(final Integer codeLength){ + + public ServiceCreator setCodeLength(final Integer codeLength) { this.codeLength = codeLength; return this; } - public ServiceCreator setLookupEnabled(final Boolean lookupEnabled){ + + public ServiceCreator setLookupEnabled(final Boolean lookupEnabled) { this.lookupEnabled = lookupEnabled; return this; } - public ServiceCreator setSkipSmsToLandlines(final Boolean skipSmsToLandlines){ + + public ServiceCreator setSkipSmsToLandlines( + final Boolean skipSmsToLandlines + ) { this.skipSmsToLandlines = skipSmsToLandlines; return this; } - public ServiceCreator setDtmfInputRequired(final Boolean dtmfInputRequired){ + + public ServiceCreator setDtmfInputRequired( + final Boolean dtmfInputRequired + ) { this.dtmfInputRequired = dtmfInputRequired; return this; } - public ServiceCreator setTtsName(final String ttsName){ + + public ServiceCreator setTtsName(final String ttsName) { this.ttsName = ttsName; return this; } - public ServiceCreator setPsd2Enabled(final Boolean psd2Enabled){ + + public ServiceCreator setPsd2Enabled(final Boolean psd2Enabled) { this.psd2Enabled = psd2Enabled; return this; } - public ServiceCreator setDoNotShareWarningEnabled(final Boolean doNotShareWarningEnabled){ + + public ServiceCreator setDoNotShareWarningEnabled( + final Boolean doNotShareWarningEnabled + ) { this.doNotShareWarningEnabled = doNotShareWarningEnabled; return this; } - public ServiceCreator setCustomCodeEnabled(final Boolean customCodeEnabled){ + + public ServiceCreator setCustomCodeEnabled( + final Boolean customCodeEnabled + ) { this.customCodeEnabled = customCodeEnabled; return this; } - public ServiceCreator setPushIncludeDate(final Boolean pushIncludeDate){ + + public ServiceCreator setPushIncludeDate(final Boolean pushIncludeDate) { this.pushIncludeDate = pushIncludeDate; return this; } - public ServiceCreator setPushApnCredentialSid(final String pushApnCredentialSid){ + + public ServiceCreator setPushApnCredentialSid( + final String pushApnCredentialSid + ) { this.pushApnCredentialSid = pushApnCredentialSid; return this; } - public ServiceCreator setPushFcmCredentialSid(final String pushFcmCredentialSid){ + + public ServiceCreator setPushFcmCredentialSid( + final String pushFcmCredentialSid + ) { this.pushFcmCredentialSid = pushFcmCredentialSid; return this; } - public ServiceCreator setTotpIssuer(final String totpIssuer){ + + public ServiceCreator setTotpIssuer(final String totpIssuer) { this.totpIssuer = totpIssuer; return this; } - public ServiceCreator setTotpTimeStep(final Integer totpTimeStep){ + + public ServiceCreator setTotpTimeStep(final Integer totpTimeStep) { this.totpTimeStep = totpTimeStep; return this; } - public ServiceCreator setTotpCodeLength(final Integer totpCodeLength){ + + public ServiceCreator setTotpCodeLength(final Integer totpCodeLength) { this.totpCodeLength = totpCodeLength; return this; } - public ServiceCreator setTotpSkew(final Integer totpSkew){ + + public ServiceCreator setTotpSkew(final Integer totpSkew) { this.totpSkew = totpSkew; return this; } - public ServiceCreator setDefaultTemplateSid(final String defaultTemplateSid){ + + public ServiceCreator setDefaultTemplateSid( + final String defaultTemplateSid + ) { this.defaultTemplateSid = defaultTemplateSid; return this; } @Override - public Service create(final TwilioRestClient client){ + public Service create(final TwilioRestClient client) { String path = "/v2/Services"; - path = path.replace("{"+"FriendlyName"+"}", this.friendlyName.toString()); + path = + path.replace( + "{" + "FriendlyName" + "}", + this.friendlyName.toString() + ); Request request = new Request( HttpMethod.POST, Domains.VERIFY.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service creation failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service creation failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -144,74 +183,73 @@ public Service create(final TwilioRestClient client){ return Service.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (codeLength != null) { request.addPostParam("CodeLength", codeLength.toString()); - } if (lookupEnabled != null) { request.addPostParam("LookupEnabled", lookupEnabled.toString()); - } if (skipSmsToLandlines != null) { - request.addPostParam("SkipSmsToLandlines", skipSmsToLandlines.toString()); - + request.addPostParam( + "SkipSmsToLandlines", + skipSmsToLandlines.toString() + ); } if (dtmfInputRequired != null) { - request.addPostParam("DtmfInputRequired", dtmfInputRequired.toString()); - + request.addPostParam( + "DtmfInputRequired", + dtmfInputRequired.toString() + ); } if (ttsName != null) { request.addPostParam("TtsName", ttsName); - } if (psd2Enabled != null) { request.addPostParam("Psd2Enabled", psd2Enabled.toString()); - } if (doNotShareWarningEnabled != null) { - request.addPostParam("DoNotShareWarningEnabled", doNotShareWarningEnabled.toString()); - + request.addPostParam( + "DoNotShareWarningEnabled", + doNotShareWarningEnabled.toString() + ); } if (customCodeEnabled != null) { - request.addPostParam("CustomCodeEnabled", customCodeEnabled.toString()); - + request.addPostParam( + "CustomCodeEnabled", + customCodeEnabled.toString() + ); } if (pushIncludeDate != null) { - request.addPostParam("Push.IncludeDate", pushIncludeDate.toString()); - + request.addPostParam( + "Push.IncludeDate", + pushIncludeDate.toString() + ); } if (pushApnCredentialSid != null) { request.addPostParam("Push.ApnCredentialSid", pushApnCredentialSid); - } if (pushFcmCredentialSid != null) { request.addPostParam("Push.FcmCredentialSid", pushFcmCredentialSid); - } if (totpIssuer != null) { request.addPostParam("Totp.Issuer", totpIssuer); - } if (totpTimeStep != null) { request.addPostParam("Totp.TimeStep", totpTimeStep.toString()); - } if (totpCodeLength != null) { request.addPostParam("Totp.CodeLength", totpCodeLength.toString()); - } if (totpSkew != null) { request.addPostParam("Totp.Skew", totpSkew.toString()); - } if (defaultTemplateSid != null) { request.addPostParam("DefaultTemplateSid", defaultTemplateSid); - } } } diff --git a/src/main/java/com/twilio/rest/verify/v2/ServiceDeleter.java b/src/main/java/com/twilio/rest/verify/v2/ServiceDeleter.java index 580a4ca0ca..71fff0ee9d 100644 --- a/src/main/java/com/twilio/rest/verify/v2/ServiceDeleter.java +++ b/src/main/java/com/twilio/rest/verify/v2/ServiceDeleter.java @@ -24,21 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - public class ServiceDeleter extends Deleter { + private String pathSid; - public ServiceDeleter(final String pathSid){ + public ServiceDeleter(final String pathSid) { this.pathSid = pathSid; } - @Override public boolean delete(final TwilioRestClient client) { String path = "/v2/Services/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.DELETE, @@ -48,9 +46,14 @@ public boolean delete(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service delete failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service delete failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/verify/v2/ServiceFetcher.java b/src/main/java/com/twilio/rest/verify/v2/ServiceFetcher.java index f056cfd1f3..b1b2173f5c 100644 --- a/src/main/java/com/twilio/rest/verify/v2/ServiceFetcher.java +++ b/src/main/java/com/twilio/rest/verify/v2/ServiceFetcher.java @@ -24,22 +24,19 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - - - public class ServiceFetcher extends Fetcher { + private String pathSid; - public ServiceFetcher(final String pathSid){ + public ServiceFetcher(final String pathSid) { this.pathSid = pathSid; } - @Override public Service fetch(final TwilioRestClient client) { String path = "/v2/Services/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, @@ -49,9 +46,14 @@ public Service fetch(final TwilioRestClient client) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service fetch failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service fetch failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } diff --git a/src/main/java/com/twilio/rest/verify/v2/ServiceReader.java b/src/main/java/com/twilio/rest/verify/v2/ServiceReader.java index 602513680e..dd0a354c1b 100644 --- a/src/main/java/com/twilio/rest/verify/v2/ServiceReader.java +++ b/src/main/java/com/twilio/rest/verify/v2/ServiceReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.verify.v2; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,17 +25,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class ServiceReader extends Reader { + private Integer pageSize; - public ServiceReader(){ - } + public ServiceReader() {} - public ServiceReader setPageSize(final Integer pageSize){ + public ServiceReader setPageSize(final Integer pageSize) { this.pageSize = pageSize; return this; } @@ -57,13 +55,21 @@ public Page firstPage(final TwilioRestClient client) { return pageForRequest(client, request); } - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service read failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service read failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -79,7 +85,10 @@ private Page pageForRequest(final TwilioRestClient client, final Reques } @Override - public Page previousPage(final Page page, final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getPreviousPageUrl(Domains.VERIFY.toString()) @@ -87,9 +96,11 @@ public Page previousPage(final Page page, final TwilioRestClie return pageForRequest(client, request); } - @Override - public Page nextPage(final Page page, final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, page.getNextPageUrl(Domains.VERIFY.toString()) @@ -98,21 +109,21 @@ public Page nextPage(final Page page, final TwilioRestClient c } @Override - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + Request request = new Request(HttpMethod.GET, targetUrl); return pageForRequest(client, request); } + private void addQueryParams(final Request request) { if (pageSize != null) { - request.addQueryParam("PageSize", pageSize.toString()); } - if(getPageSize() != null) { + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } diff --git a/src/main/java/com/twilio/rest/verify/v2/ServiceUpdater.java b/src/main/java/com/twilio/rest/verify/v2/ServiceUpdater.java index 58fd5d35b3..7c0aeb408e 100644 --- a/src/main/java/com/twilio/rest/verify/v2/ServiceUpdater.java +++ b/src/main/java/com/twilio/rest/verify/v2/ServiceUpdater.java @@ -15,6 +15,7 @@ package com.twilio.rest.verify.v2; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -24,10 +25,8 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +public class ServiceUpdater extends Updater { - - -public class ServiceUpdater extends Updater{ private String pathSid; private String friendlyName; private Integer codeLength; @@ -47,96 +46,132 @@ public class ServiceUpdater extends Updater{ private Integer totpSkew; private String defaultTemplateSid; - public ServiceUpdater(final String pathSid){ + public ServiceUpdater(final String pathSid) { this.pathSid = pathSid; } - public ServiceUpdater setFriendlyName(final String friendlyName){ + public ServiceUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - public ServiceUpdater setCodeLength(final Integer codeLength){ + + public ServiceUpdater setCodeLength(final Integer codeLength) { this.codeLength = codeLength; return this; } - public ServiceUpdater setLookupEnabled(final Boolean lookupEnabled){ + + public ServiceUpdater setLookupEnabled(final Boolean lookupEnabled) { this.lookupEnabled = lookupEnabled; return this; } - public ServiceUpdater setSkipSmsToLandlines(final Boolean skipSmsToLandlines){ + + public ServiceUpdater setSkipSmsToLandlines( + final Boolean skipSmsToLandlines + ) { this.skipSmsToLandlines = skipSmsToLandlines; return this; } - public ServiceUpdater setDtmfInputRequired(final Boolean dtmfInputRequired){ + + public ServiceUpdater setDtmfInputRequired( + final Boolean dtmfInputRequired + ) { this.dtmfInputRequired = dtmfInputRequired; return this; } - public ServiceUpdater setTtsName(final String ttsName){ + + public ServiceUpdater setTtsName(final String ttsName) { this.ttsName = ttsName; return this; } - public ServiceUpdater setPsd2Enabled(final Boolean psd2Enabled){ + + public ServiceUpdater setPsd2Enabled(final Boolean psd2Enabled) { this.psd2Enabled = psd2Enabled; return this; } - public ServiceUpdater setDoNotShareWarningEnabled(final Boolean doNotShareWarningEnabled){ + + public ServiceUpdater setDoNotShareWarningEnabled( + final Boolean doNotShareWarningEnabled + ) { this.doNotShareWarningEnabled = doNotShareWarningEnabled; return this; } - public ServiceUpdater setCustomCodeEnabled(final Boolean customCodeEnabled){ + + public ServiceUpdater setCustomCodeEnabled( + final Boolean customCodeEnabled + ) { this.customCodeEnabled = customCodeEnabled; return this; } - public ServiceUpdater setPushIncludeDate(final Boolean pushIncludeDate){ + + public ServiceUpdater setPushIncludeDate(final Boolean pushIncludeDate) { this.pushIncludeDate = pushIncludeDate; return this; } - public ServiceUpdater setPushApnCredentialSid(final String pushApnCredentialSid){ + + public ServiceUpdater setPushApnCredentialSid( + final String pushApnCredentialSid + ) { this.pushApnCredentialSid = pushApnCredentialSid; return this; } - public ServiceUpdater setPushFcmCredentialSid(final String pushFcmCredentialSid){ + + public ServiceUpdater setPushFcmCredentialSid( + final String pushFcmCredentialSid + ) { this.pushFcmCredentialSid = pushFcmCredentialSid; return this; } - public ServiceUpdater setTotpIssuer(final String totpIssuer){ + + public ServiceUpdater setTotpIssuer(final String totpIssuer) { this.totpIssuer = totpIssuer; return this; } - public ServiceUpdater setTotpTimeStep(final Integer totpTimeStep){ + + public ServiceUpdater setTotpTimeStep(final Integer totpTimeStep) { this.totpTimeStep = totpTimeStep; return this; } - public ServiceUpdater setTotpCodeLength(final Integer totpCodeLength){ + + public ServiceUpdater setTotpCodeLength(final Integer totpCodeLength) { this.totpCodeLength = totpCodeLength; return this; } - public ServiceUpdater setTotpSkew(final Integer totpSkew){ + + public ServiceUpdater setTotpSkew(final Integer totpSkew) { this.totpSkew = totpSkew; return this; } - public ServiceUpdater setDefaultTemplateSid(final String defaultTemplateSid){ + + public ServiceUpdater setDefaultTemplateSid( + final String defaultTemplateSid + ) { this.defaultTemplateSid = defaultTemplateSid; return this; } @Override - public Service update(final TwilioRestClient client){ + public Service update(final TwilioRestClient client) { String path = "/v2/Services/{Sid}"; - path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.POST, Domains.VERIFY.toString(), path ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service update failed: Unable to connect to server"); + throw new ApiConnectionException( + "Service update failed: Unable to connect to server" + ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); if (restException == null) { throw new ApiException("Server Error, no content"); } @@ -145,74 +180,73 @@ public Service update(final TwilioRestClient client){ return Service.fromJson(response.getStream(), client.getObjectMapper()); } + private void addPostParams(final Request request) { if (friendlyName != null) { request.addPostParam("FriendlyName", friendlyName); - } if (codeLength != null) { request.addPostParam("CodeLength", codeLength.toString()); - } if (lookupEnabled != null) { request.addPostParam("LookupEnabled", lookupEnabled.toString()); - } if (skipSmsToLandlines != null) { - request.addPostParam("SkipSmsToLandlines", skipSmsToLandlines.toString()); - + request.addPostParam( + "SkipSmsToLandlines", + skipSmsToLandlines.toString() + ); } if (dtmfInputRequired != null) { - request.addPostParam("DtmfInputRequired", dtmfInputRequired.toString()); - + request.addPostParam( + "DtmfInputRequired", + dtmfInputRequired.toString() + ); } if (ttsName != null) { request.addPostParam("TtsName", ttsName); - } if (psd2Enabled != null) { request.addPostParam("Psd2Enabled", psd2Enabled.toString()); - } if (doNotShareWarningEnabled != null) { - request.addPostParam("DoNotShareWarningEnabled", doNotShareWarningEnabled.toString()); - + request.addPostParam( + "DoNotShareWarningEnabled", + doNotShareWarningEnabled.toString() + ); } if (customCodeEnabled != null) { - request.addPostParam("CustomCodeEnabled", customCodeEnabled.toString()); - + request.addPostParam( + "CustomCodeEnabled", + customCodeEnabled.toString() + ); } if (pushIncludeDate != null) { - request.addPostParam("Push.IncludeDate", pushIncludeDate.toString()); - + request.addPostParam( + "Push.IncludeDate", + pushIncludeDate.toString() + ); } if (pushApnCredentialSid != null) { request.addPostParam("Push.ApnCredentialSid", pushApnCredentialSid); - } if (pushFcmCredentialSid != null) { request.addPostParam("Push.FcmCredentialSid", pushFcmCredentialSid); - } if (totpIssuer != null) { request.addPostParam("Totp.Issuer", totpIssuer); - } if (totpTimeStep != null) { request.addPostParam("Totp.TimeStep", totpTimeStep.toString()); - } if (totpCodeLength != null) { request.addPostParam("Totp.CodeLength", totpCodeLength.toString()); - } if (totpSkew != null) { request.addPostParam("Totp.Skew", totpSkew.toString()); - } if (defaultTemplateSid != null) { request.addPostParam("DefaultTemplateSid", defaultTemplateSid); - } } } diff --git a/src/main/java/com/twilio/rest/verify/v2/Template.java b/src/main/java/com/twilio/rest/verify/v2/Template.java index a99744f504..5bf3b5da29 100644 --- a/src/main/java/com/twilio/rest/verify/v2/Template.java +++ b/src/main/java/com/twilio/rest/verify/v2/Template.java @@ -22,38 +22,37 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; - import com.twilio.exception.ApiException; - -import lombok.ToString; - import java.io.IOException; import java.io.InputStream; - import java.util.List; import java.util.Map; -import java.util.Objects; - - import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Template extends Resource { + private static final long serialVersionUID = 229000530855919L; - public static TemplateReader reader(){ + public static TemplateReader reader() { return new TemplateReader(); } /** - * Converts a JSON String into a Template object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Template object represented by the provided JSON - */ - public static Template fromJson(final String json, final ObjectMapper objectMapper) { + * Converts a JSON String into a Template object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Template object represented by the provided JSON + */ + public static Template fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Template.class); @@ -65,14 +64,17 @@ public static Template fromJson(final String json, final ObjectMapper objectMapp } /** - * Converts a JSON InputStream into a Template object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Template object represented by the provided JSON - */ - public static Template fromJson(final InputStream json, final ObjectMapper objectMapper) { + * Converts a JSON InputStream into a Template object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Template object represented by the provided JSON + */ + public static Template fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Template.class); @@ -91,20 +93,11 @@ public static Template fromJson(final InputStream json, final ObjectMapper objec @JsonCreator private Template( - @JsonProperty("sid") - final String sid, - - @JsonProperty("account_sid") - final String accountSid, - - @JsonProperty("friendly_name") - final String friendlyName, - - @JsonProperty("channels") - final List channels, - - @JsonProperty("translations") - final Map translations + @JsonProperty("sid") final String sid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("channels") final List channels, + @JsonProperty("translations") final Map translations ) { this.sid = sid; this.accountSid = accountSid; @@ -113,25 +106,29 @@ private Template( this.translations = translations; } - public final String getSid() { - return this.sid; - } - public final String getAccountSid() { - return this.accountSid; - } - public final String getFriendlyName() { - return this.friendlyName; - } - public final List getChannels() { - return this.channels; - } - public final Map getTranslations() { - return this.translations; - } + public final String getSid() { + return this.sid; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final List getChannels() { + return this.channels; + } + + public final Map getTranslations() { + return this.translations; + } @Override public boolean equals(final Object o) { - if (this==o) { + if (this == o) { return true; } @@ -141,13 +138,23 @@ public boolean equals(final Object o) { Template other = (Template) o; - return Objects.equals(sid, other.sid) && Objects.equals(accountSid, other.accountSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(channels, other.channels) && Objects.equals(translations, other.translations) ; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(channels, other.channels) && + Objects.equals(translations, other.translations) + ); } @Override public int hashCode() { - return Objects.hash(sid, accountSid, friendlyName, channels, translations); + return Objects.hash( + sid, + accountSid, + friendlyName, + channels, + translations + ); } - } - diff --git a/src/main/java/com/twilio/rest/verify/v2/TemplateReader.java b/src/main/java/com/twilio/rest/verify/v2/TemplateReader.java index 77fff6d266..51c4c8136a 100644 --- a/src/main/java/com/twilio/rest/verify/v2/TemplateReader.java +++ b/src/main/java/com/twilio/rest/verify/v2/TemplateReader.java @@ -14,6 +14,7 @@ package com.twilio.rest.verify.v2; +import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; import com.twilio.exception.ApiConnectionException; @@ -24,22 +25,20 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.base.Page; - - public class TemplateReader extends Reader